From auriocus at gmx.de Fri Jul 1 00:58:58 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 1 Jul 2016 06:58:58 +0200 Subject: Controlling the Mac OSX GUI via Python? In-Reply-To: <7d144305-e228-4241-90d6-86677ef713b7@googlegroups.com> References: <68044aa3-8a3c-47cd-b6d0-aaa0e3f1fc62@googlegroups.com> <09315fbb-05b1-4c4e-a6f7-7cfda79a1286@googlegroups.com> <7d144305-e228-4241-90d6-86677ef713b7@googlegroups.com> Message-ID: Am 01.07.16 um 01:12 schrieb Lawrence D?Oliveiro: > On Friday, July 1, 2016 at 10:35:42 AM UTC+12, Chris Angelico wrote: >> >> On Fri, Jul 1, 2016 at 8:27 AM, Lawrence D?Oliveiro wrote: >>> >>> GUIs, by their nature, are not designed to be automated. >> >> Doesn't mean they can't be! > > It?s more trouble than it?s worth. Different (even minor) versions of > the program will move UI elements around. Things that look and behave > like buttons might have underlying code that is not quite the same as > that for buttons. There will be subtle timing issues, where something > doesn?t quite get enabled in time for your script to click on it. You > will suffer mysterious intermittent problems, where a sequence works > one time but not another time. I think you misunderstood the request. Yes, simulating mouse clicks with fixed coordinates etc. is prone to such failure, but there are better methods. These mouse clicks and keyboard events usually trigger a method call inside the GUI program. If there are any means to call that method directly, you are independent from the graphics itself. These bindings then usually call some higher-level functions. Many applications export their internal structure via some general communications mechanism. On Windows, COM is such a mechanism, CORBA is another one, and on the Mac that are Apple Events. AppleScript is a Mac-specific (strange) language which allows you to send arbitrary Apple events to applications. This has nothing to do with simulating mouse clicks. A deprecated Python package is found here: http://appscript.sourceforge.net/py-appscript/ If you look at the first example: app('TextEdit').documents['ReadMe'].paragraphs[1].get() its immediately clear that this is on a very different level than simulating Copy/Paste using the mouse to get the first paragraph. According to my Google-Fu, howver, py-appscript stopped working with some OSX update. One possibility would be to send the equivalent applescript to the "osascript" program via subprocess. > Again: GUIs are for manual operations to be performed by humans. For > automation, you need a function-based scripting API and a command > line. Yes and no. Sometimes GUIs export an API which is just not obvious to the user, sometimes they have an internal structure which can be exploited. Christian From kliateni at gmail.com Fri Jul 1 01:11:11 2016 From: kliateni at gmail.com (Karim) Date: Fri, 1 Jul 2016 07:11:11 +0200 Subject: Find a file In-Reply-To: <8bc66008-4607-4aa4-91db-64cb8ea07a56@googlegroups.com> References: <8bc66008-4607-4aa4-91db-64cb8ea07a56@googlegroups.com> Message-ID: <5775FB6F.7020703@gmail.com> On 01/07/2016 02:51, tdsperth at gmail.com wrote: > Hi All > > I have a web app that allows me to choose a file - the file name is returned but I need > to find the path to the file so I can add it as an attachment to a email. > > The files I am returning could be in different folders/directories. > > Thanks for any help. > > Cheers > > Colin > Hello, I did this almost equivalent unix find command in python it is documented, it is a generator. If it could help you: import os from os.path import join as jp, normpath as np def find(dirs, filenames=None, exts=None, exclude_dirs=None, exclude_filenames=None, followlinks=False): """ Equivalent to the unix/linux find shell command. @param dirs the top directories where to search. Could be a simple string. Default to current directory '.'. @param filenames the searched file names. Could be a simple string. @param exts an additional parameter to search files by its extension. Could be cumulative with the filenames @param exclude_dirs a filter to exclude given top directories from the search process. Coud be a simple string. @param exclude_filenames a filter to bypass certain files by its name. Useful when using a search by file extension. Could be a simple string. @param followlinks a boolean to specify whether to follow symbolic links to subdirectories. Defaulted to False. @return a generator data which provides the found file one after another. """ if not filenames and not exts: raise ValueError('The list of searched files and the list of searched file extensions could not be both empty!') if filenames is None: filenames = '' if exts is None: exts = '' if exclude_dirs is None: exclude_dirs = '' if exclude_filenames is None: exclude_filenames = '' # Default value if not dirs: dirs = tuple(('.',)) if isinstance(dirs, str): dirs = tuple((dirs,)) if isinstance(filenames, str): filenames = tuple((filenames,)) if isinstance(exts, str): exts = tuple((exts,)) if isinstance(exclude_dirs, str): exclude_dirs = tuple((exclude_dirs,)) if isinstance(exclude_filenames, str): exclude_filenames = tuple((exclude_filenames,)) # The search. for d in dirs: for dirpath, dirnames, fnames in os.walk(d, followlinks=followlinks): # Filtering unwanted top directories. for d in exclude_dirs: if d in dirnames: dirnames.remove(d) # Search for file names or extensions for f in fnames: file_extension = os.path.splitext(f)[-1][1:] # extension without the dot! if f in filenames or (file_extension in exts and f not in exclude_filenames): yield jp(dirpath, f) if __name__ == '__main__': #print(np('\n'.join(find(dirs='.', exts='li', exclude_filenames='cds.li')))) # Test l = tuple(find(dirs='.', filenames='cds.lib')) print('\n'.join(l)) Cheers Karim From auriocus at gmx.de Fri Jul 1 01:41:27 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 1 Jul 2016 07:41:27 +0200 Subject: Were is a great place to Share your finished projects? In-Reply-To: References: <857fd6uogt.fsf@benfinney.id.au> Message-ID: Am 01.07.16 um 03:38 schrieb Ben Finney: > Christian Gollwitzer writes: > >> The best place these days to publish software is on github. > > For what value of ?best?? The question was about visibility of a project for a single beginner developer. > If one wants to avoid vendor lock-in, Github is not best: the workflow > tools (other than Git itself) are completely closed and not available > for implementation on another vendor's servers. Yes, but that is relevant only if the workflow (i.e. pull requests) are an important part of the history. The code history is just git and that is independent from github. For projects which rely on a single developer, there is no issue. Additionally I wanted to point out that "finishing" a project is the wrong idea, at least in open source terms. > If one wants to communicate equally with Git repositories elsewhere, > GitHub is not best: federation between hosts is actively discouraged by > the lock-in. I don't understand what that means. I can git pull my local repo from somewhere else and then git push it to github. What do you mean by federation between hosts? > If one wants to teach newcomers with tools that will still be working > even when GitHub goes out of business, GitHub is not best. ? git will not stop working > If one wants to grow software freedom, Github is not best > . > > Convenience is not a reliable measure of how good something is, so it is > not the best measure of ?best?. Then please propose an alternative instead of just arguing. Make sure you try to understand the OPs objectives and background. Christian From auriocus at gmx.de Fri Jul 1 01:53:46 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 1 Jul 2016 07:53:46 +0200 Subject: Were is a great place to Share your finished projects? In-Reply-To: References: <1467328589.3641801.653665465.08E70649@webmail.messagingengine.com> Message-ID: Am 01.07.16 um 01:16 schrieb Random832: > On Thu, Jun 30, 2016, at 19:06, Lawrence D?Oliveiro wrote: >> On Friday, July 1, 2016 at 1:09:31 AM UTC+12, Christian Gollwitzer wrote: >>> Github makes that extremely easy, just create an account, create a repo, >>> "git pull" and start working. Your incremental changes will be updated >>> with each "git push". >> >> I start with ?git init? and never pull, only push. >> >> I do use ?git fetch && git rebase origin/master master? to copy from >> upstream repos to mine. > > In context, I assume that by "pull" he actually meant "clone". Yes, sorry, I meant clone. Christian From jussi.piitulainen at helsinki.fi Fri Jul 1 02:42:50 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 01 Jul 2016 09:42:50 +0300 Subject: Creating a calculator References: Message-ID: DFS writes: > Here's a related program that doesn't require you to tell it what type > of operation to perform. Just enter 'num1 operator num2' and hit > Enter, and it will parse the entry and do the math. > > ----------------------------------------------- > ui=raw_input('Enter calculation to perform: ') > n1=float(ui.split(' ')[0]) > op=ui.split(' ')[1] > n2=float(ui.split(' ')[2]) > if op=='+':c=n1+n2 > if op=='-':c=n1-n2 > if op=='*':c=n1*n2 > if op=='/':c=n1/n2 > print(ui+' = '+str(c)) > ----------------------------------------------- I use multiple assignment a lot, like this: n1, op, n2 = ui.split() It's not only compact, it also crashes if there are more elements than expected, and I want it to crash when that happens. Or rather, I prefer a crash to silence when input is bad. For the calculator, it may be better to split on any whitespace and discard empty strings, which is what ui.split() does. Splitting on a single space seems unnecessarily strict in a calculator (whereas splitting on a single tab is what I very much do in my work - the data formats are such). I think multiple assignment is good even for a beginner. Perhaps do it a second time straight away: n1, op, n2 = ui.split() n1, n2 = float(n1), float(n2) But it's only with the split where it really pays. n1, op, n2 = ui.split() n1 = float(n1) n2 = float(n2) The latter might be even preferable. Hm. n1, n2 = map(float, (n1, n2)) :) From lawrencedo99 at gmail.com Fri Jul 1 02:51:32 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 30 Jun 2016 23:51:32 -0700 (PDT) Subject: Were is a great place to Share your finished projects? In-Reply-To: References: <857fd6uogt.fsf@benfinney.id.au> Message-ID: On Friday, July 1, 2016 at 1:39:04 PM UTC+12, Ben Finney wrote: > Christian Gollwitzer writes: > >> The best place these days to publish software is on github. > > For what value of ?best?? > > If one wants to avoid vendor lock-in, Github is not best: the workflow > tools (other than Git itself) are completely closed and not available > for implementation on another vendor's servers. That?s (mostly) OK. Git is what I mainly want it for anyway. > If one wants to communicate equally with Git repositories elsewhere, > GitHub is not best: federation between hosts is actively discouraged by > the lock-in. I can add as many remotes to my Git repos as I like, pointing to servers wherever I like, so I guess it?s not that bad. From dieter at handshake.de Fri Jul 1 03:04:50 2016 From: dieter at handshake.de (dieter) Date: Fri, 01 Jul 2016 09:04:50 +0200 Subject: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions References: <85mvm5vrbw.fsf@benfinney.id.au> <0690f476-95ad-4dec-87e5-42ecee07fdcd@googlegroups.com> Message-ID: <87poqx96ul.fsf@handshake.de> Peter Otten <__peter__ at web.de> writes: > Lawrence D?Oliveiro wrote: > >> On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: >> >>> I would like to see a more Pythonic, more explicit and expressive >>> replacement with its component parts easily understood. >> >> I don?t know why this fear and suspicion of lambdas is so widespread among >> Python users ... former Java/C# programmers, perhaps? Maybe, it's the name ("lambda"). In Javascript, anonymous functions are widespread (and extensively used for e.g. callback definitions) - but it uses the much more familiar "function" (rather than "lambda") for this purpose. From kwpolska at gmail.com Fri Jul 1 04:57:11 2016 From: kwpolska at gmail.com (Chris Warrick) Date: Fri, 1 Jul 2016 10:57:11 +0200 Subject: Creating a calculator In-Reply-To: References: Message-ID: On 1 July 2016 at 05:08, Elizabeth Weiss wrote: > while True: > print("Options:") > print("Enter 'add' to add two numbers") > print("Enter 'subtract' to subtract two numbers") > print("Enter 'multiply' to multiply two numbers") > print("Enter 'divide' to divide two numbers") > print("Enter 'quit' to end the program") > user_input=input(":") > if user_input=="quit": > break > elif user_input=="add": > num1=float(input("Enter a number")) > num2=float(input("Enter another number")) > result=str(num1+num2) > print("The answer is"+ result) > elif user_input=="subtract": > num1=float(input("Enter a number")) > num2=float(input("Enter another number")) > result=str(num1-num2) > print("The answer is"+result) > > Two questions: > 1. Why do I need to put ' ' around the words add, subtract, multiply, quit, etc. when it is already in quotes in print()? When the calculator asks me which option I would like to choose I do not write 'add'- I only write add. This is used for display. The single quotes will be displayed as part of the string. This is so that people notice the commands, for example. >>> print("Enter 'add' to add two numbers") Enter 'add' to add two numbers >>> print("Enter add to add two numbers") Enter add to add two numbers >>> print('Enter "add" to add two numbers') Enter "add" to add two numbers > 2. The program I am using to help me learn python mentions that the output line could be put outside the if statements to omit repetition of code. What does this mean and how would I write the code differently according to this? Look at your current code. The following three lines appear twice (and will appear 4 times if you add multiplication and division): > num1=float(input("Enter a number")) > num2=float(input("Enter another number")) > print("The answer is"+ result) This is code repetition. It?s discouraged, because if you have 4 copies of a longer segment, and you want to change something, you would have to remember to change it in 4 places. In this case, you can avoid code reuse like this: 1. Check if user said 'quit', and if yes, break from the loop. (Ignore invalid input for now) 2. Ask the user for two numbers. 3. Make an if/elif/else structure to calculate the result. 4. Print out the result outside of `if`. Example for 3. and 4.: if user_input == 'add': result = num1 + num2 # no need to call str() if you use commas in print() elif user_input == 'subtract': result = num1 - num2 # other elif clauses go here print("The result is", result) -- Chris Warrick PGP: 5EAAEA16 From pdorange at pas-de-pub-merci.mac.com Fri Jul 1 05:34:40 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Fri, 1 Jul 2016 11:34:40 +0200 Subject: Creating a calculator References: Message-ID: <1mpph6r.u6n05219srlzsN%pdorange@pas-de-pub-merci.mac.com> DFS wrote: > Here's a related program that doesn't require you to tell it what type > of operation to perform. Just enter 'num1 operator num2' and hit Enter, > and it will parse the entry and do the math. > > ----------------------------------------------- > ui=raw_input('Enter calculation to perform: ') > n1=float(ui.split(' ')[0]) > op=ui.split(' ')[1] > n2=float(ui.split(' ')[2]) > if op=='+':c=n1+n2 > if op=='-':c=n1-n2 > if op=='*':c=n1*n2 > if op=='/':c=n1/n2 > print(ui+' = '+str(c)) > ----------------------------------------------- More reduced : ---------------------------------- u=raw_input('Enter calculation:") print eval(u) ---------------------------------- works and compute : 1+2+3+4-1+4*2 2+3.0/2-0.5 Perform better and shorter, but less educationnal of course... -- Pierre-Alain Dorange Moof Ce message est sous licence Creative Commons "by-nc-sa-2.0" From archana.sonavane at gmail.com Fri Jul 1 06:26:22 2016 From: archana.sonavane at gmail.com (Archana Sonavane) Date: Fri, 1 Jul 2016 03:26:22 -0700 (PDT) Subject: Need help in python program Message-ID: <2144eabe-bf8f-4fa8-833d-e41b0efdc932@googlegroups.com> Hello Everyone, I am doing python code by using API. My first API giving fields - Itemid, clock and value second API giving fields - Itemid, key, units and delay using for loops for both API. Could you please tell me how to compare both id by using equal operator. My output should be : Itemid, clock, value, key, units and delay From kwpolska at gmail.com Fri Jul 1 07:39:39 2016 From: kwpolska at gmail.com (Chris Warrick) Date: Fri, 1 Jul 2016 13:39:39 +0200 Subject: Creating a calculator In-Reply-To: <1mpph6r.u6n05219srlzsN%pdorange@pas-de-pub-merci.mac.com> References: <1mpph6r.u6n05219srlzsN%pdorange@pas-de-pub-merci.mac.com> Message-ID: On 1 July 2016 at 11:34, Pierre-Alain Dorange wrote: > DFS wrote: > >> Here's a related program that doesn't require you to tell it what type >> of operation to perform. Just enter 'num1 operator num2' and hit Enter, >> and it will parse the entry and do the math. >> >> ----------------------------------------------- >> ui=raw_input('Enter calculation to perform: ') >> n1=float(ui.split(' ')[0]) >> op=ui.split(' ')[1] >> n2=float(ui.split(' ')[2]) >> if op=='+':c=n1+n2 >> if op=='-':c=n1-n2 >> if op=='*':c=n1*n2 >> if op=='/':c=n1/n2 >> print(ui+' = '+str(c)) >> ----------------------------------------------- > > More reduced : > ---------------------------------- > u=raw_input('Enter calculation:") > print eval(u) > ---------------------------------- > works and compute : > 1+2+3+4-1+4*2 > 2+3.0/2-0.5 > > Perform better and shorter, but less educationnal of course... No, this is awful. It?s a great way to compromise your system?s security. Never use eval() for any reason, especially with user input ? if you were to type in __import__('os').system('?') with some particularly dangerous command (rm, format, ?), you would kill your system. -- Chris Warrick PGP: 5EAAEA16 From Joaquin.Alzola at lebara.com Fri Jul 1 08:19:11 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Fri, 1 Jul 2016 12:19:11 +0000 Subject: JAR files into python Message-ID: Hi Guys I have the following script which will be used in Spark. #!/usr/bin/env python3 from pyspark_cassandra import CassandraSparkContext, Row from pyspark import SparkContext, SparkConf from pyspark.sql import SQLContext import os os.environ['CLASSPATH']="/mnt/spark/lib" conf = SparkConf().setAppName("test").setMaster("spark://192.168.23.31:7077").set("spark.cassandra.connection.host", "192.168.23.31") sc = CassandraSparkContext(conf=conf) sqlContext = SQLContext(sc) df = sqlContext.read.format("org.apache.spark.sql.cassandra").options(keyspace="lebara_diameter_codes", table="nl_lebara_diameter_codes").load() list = df.select("errorcode2001").where("errorcode2001 > 1200").collect() list2 = df.select("date").collect() print([i for i in list[0]]) print(type(list[0])) The error that it throws is the following one (which is logical because I do not load the jar files): py4j.protocol.Py4JJavaError: An error occurred while calling o29.load. : java.lang.ClassNotFoundException: Failed to find data source: org.apache.spark.sql.cassandra. Please find packages at http://spark-packages.org Is there a way to load those jar files into python or the classpath when calling sqlContext.read.format("org.apache.spark.sql.cassandra")? BR Joaquin This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From christopher_reimer at icloud.com Fri Jul 1 08:25:58 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Fri, 01 Jul 2016 05:25:58 -0700 Subject: Creating a calculator In-Reply-To: References: Message-ID: <0E77E5BC-E8CC-4951-B520-37BF2E596D3A@icloud.com> > On Jun 30, 2016, at 11:42 PM, Jussi Piitulainen wrote: > > DFS writes: > >> Here's a related program that doesn't require you to tell it what type >> of operation to perform. Just enter 'num1 operator num2' and hit >> Enter, and it will parse the entry and do the math. >> >> ----------------------------------------------- >> ui=raw_input('Enter calculation to perform: ') >> n1=float(ui.split(' ')[0]) >> op=ui.split(' ')[1] >> n2=float(ui.split(' ')[2]) >> if op=='+':c=n1+n2 >> if op=='-':c=n1-n2 >> if op=='*':c=n1*n2 >> if op=='/':c=n1/n2 >> print(ui+' = '+str(c)) >> ----------------------------------------------- > > I use multiple assignment a lot, like this: > > n1, op, n2 = ui.split() > > It's not only compact, it also crashes if there are more elements than > expected, and I want it to crash when that happens. Or rather, I prefer > a crash to silence when input is bad. > > For the calculator, it may be better to split on any whitespace and > discard empty strings, which is what ui.split() does. Splitting on a > single space seems unnecessarily strict in a calculator (whereas > splitting on a single tab is what I very much do in my work - the data > formats are such). > > I think multiple assignment is good even for a beginner. Perhaps do it a > second time straight away: > > n1, op, n2 = ui.split() > n1, n2 = float(n1), float(n2) > > But it's only with the split where it really pays. > > n1, op, n2 = ui.split() > n1 = float(n1) > n2 = float(n2) > > The latter might be even preferable. Hm. > > n1, n2 = map(float, (n1, n2)) > > :) For my BASIC interpreter, each line of BASIC is broken this way into tokens. line_number, keyword, *expression = line.split(' ', 2) For a line like 10 PRINT "HELLO, WORLD!", this works as expected. For a line like 20 END, which doesn't have a third element for expression, an empty list is assigned. By using * to unpack the split line, my program no longer crashes and no try/except block is needed to work around the crash. A later line of code will test the expression, ignore if empty or run regex if full. Chris R. From jussi.piitulainen at helsinki.fi Fri Jul 1 08:46:03 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 01 Jul 2016 15:46:03 +0300 Subject: Creating a calculator References: <0E77E5BC-E8CC-4951-B520-37BF2E596D3A@icloud.com> Message-ID: Christopher Reimer writes: > For my BASIC interpreter, each line of BASIC is broken this way into > tokens. > > line_number, keyword, *expression = line.split(' ', 2) > > For a line like 10 PRINT "HELLO, WORLD!", this works as expected. > > For a line like 20 END, which doesn't have a third element for > expression, an empty list is assigned. > > By using * to unpack the split line, my program no longer crashes and > no try/except block is needed to work around the crash. A later line > of code will test the expression, ignore if empty or run regex if > full. Yes. Consider line.split(None, 2) or line.split(maxsplit=2). You may still need to strip the third component, but at least it will *be* the third component even if the user happens to type extra spaces like this: 10 PRINT "Hello, world." And you won't get a spurious third component if the user types this: 20 END (There's trailing spaces.) From pdorange at pas-de-pub-merci.mac.com Fri Jul 1 09:03:19 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Fri, 1 Jul 2016 15:03:19 +0200 Subject: Creating a calculator References: <1mpph6r.u6n05219srlzsN%pdorange@pas-de-pub-merci.mac.com> Message-ID: <1mppott.nlnf47ya08hzN%pdorange@pas-de-pub-merci.mac.com> Chris Warrick wrote: > > More reduced : > > ---------------------------------- > > u=raw_input('Enter calculation:") > > print eval(u) > > ---------------------------------- > > works and compute : > > 1+2+3+4-1+4*2 > > 2+3.0/2-0.5 > > > > Perform better and shorter, but less educationnal of course... > > No, this is awful. It's a great way to compromise your system's > security. Never use eval() for any reason, especially with user input > ? if you were to type in __import__('os').system('?') with some > particularly dangerous command (rm, format, ?), you would kill your > system. Yes you're right, eval can be really dangerous. You could make it (a little) safer using env ; but a hacker could always break things with eval. ------------------------------------- env={} env["__builtins__"] = None u=raw_input('Enter calculation:") print eval(u,env) ------------------------------------- -- Pierre-Alain Dorange Moof Ce message est sous licence Creative Commons "by-nc-sa-2.0" From christopher_reimer at icloud.com Fri Jul 1 09:19:00 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Fri, 01 Jul 2016 06:19:00 -0700 Subject: Creating a calculator In-Reply-To: References: <0E77E5BC-E8CC-4951-B520-37BF2E596D3A@icloud.com> Message-ID: <81839B88-3F2B-4E28-9E59-F4B1AAAF058D@icloud.com> > On Jul 1, 2016, at 5:46 AM, Jussi Piitulainen wrote: > > Christopher Reimer writes: > >> For my BASIC interpreter, each line of BASIC is broken this way into >> tokens. >> >> line_number, keyword, *expression = line.split(' ', 2) >> >> For a line like 10 PRINT "HELLO, WORLD!", this works as expected. >> >> For a line like 20 END, which doesn't have a third element for >> expression, an empty list is assigned. >> >> By using * to unpack the split line, my program no longer crashes and >> no try/except block is needed to work around the crash. A later line >> of code will test the expression, ignore if empty or run regex if >> full. > > Yes. > > Consider line.split(None, 2) or line.split(maxsplit=2). You may still > need to strip the third component, but at least it will *be* the third > component even if the user happens to type extra spaces like this: > > 10 PRINT "Hello, world." > > And you won't get a spurious third component if the user types this: > > 20 END > > (There's trailing spaces.) This is a BASIC interpreter. Any extra spaces for line_number or keyword will raise an incomprehensible syntax error, as the line number must convert to an integer and the keyword much match the KEYWORDS list. As for trailing spaces for expression, regex will keep them whole if enclosed in double quotes or convert them to a list element. Depending on the keyword grammar, extra spaces are likely to be ignored. A C interpreter would be more difficult as the same line of code could be written several different ways and be valid. FILE *source FILE * source FILE* source FILE*source The first line is how I normally see this statement written. The last line I found in a 1991 book with a strange dialect of C that I've never seen before and doesn't always compile correctly without modification. Writing a C interpreter is not on my to do list. Chris R. From jussi.piitulainen at helsinki.fi Fri Jul 1 09:35:41 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 01 Jul 2016 16:35:41 +0300 Subject: Creating a calculator References: <0E77E5BC-E8CC-4951-B520-37BF2E596D3A@icloud.com> <81839B88-3F2B-4E28-9E59-F4B1AAAF058D@icloud.com> Message-ID: Christopher Reimer writes: >> On Jul 1, 2016, at 5:46 AM, Jussi Piitulainen wrote: >> >> Christopher Reimer writes: >> >>> For my BASIC interpreter, each line of BASIC is broken this way into >>> tokens. >>> >>> line_number, keyword, *expression = line.split(' ', 2) >>> >>> For a line like 10 PRINT "HELLO, WORLD!", this works as expected. >>> >>> For a line like 20 END, which doesn't have a third element for >>> expression, an empty list is assigned. >>> >>> By using * to unpack the split line, my program no longer crashes and >>> no try/except block is needed to work around the crash. A later line >>> of code will test the expression, ignore if empty or run regex if >>> full. >> >> Yes. >> >> Consider line.split(None, 2) or line.split(maxsplit=2). You may still >> need to strip the third component, but at least it will *be* the third >> component even if the user happens to type extra spaces like this: >> >> 10 PRINT "Hello, world." >> >> And you won't get a spurious third component if the user types this: >> >> 20 END >> >> (There's trailing spaces.) > > This is a BASIC interpreter. Any extra spaces for line_number or > keyword will raise an incomprehensible syntax error, as the line > number must convert to an integer and the keyword much match the > KEYWORDS list. As for trailing spaces for expression, regex will keep > them whole if enclosed in double quotes or convert them to a list > element. Depending on the keyword grammar, extra spaces are likely to > be ignored. You get to decide! (But if you split on whitespace as I suggested, there won't be any extra spaces in the line number or keyword. While if you split on every single space, the first and second component of the split may not even contain the intended line number and keyword. Try it. Then do what you like.) > A C interpreter would be more difficult as the same line of code could > be written several different ways and be valid. > > FILE *source > FILE * source > FILE* source > FILE*source > > The first line is how I normally see this statement written. The last > line I found in a 1991 book with a strange dialect of C that I've > never seen before and doesn't always compile correctly without > modification. Writing a C interpreter is not on my to do list. C syntax is not line-oriented anyway. It's semicolon-oriented. Good luck with your BASIC interpreter. (No sarcasm or anything like that. I think it's a nice project.) From steve at pearwood.info Fri Jul 1 09:52:45 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 01 Jul 2016 23:52:45 +1000 Subject: Creating a calculator References: <0E77E5BC-E8CC-4951-B520-37BF2E596D3A@icloud.com> Message-ID: <577675ae$0$1604$c3e8da3$5496439d@news.astraweb.com> On Fri, 1 Jul 2016 10:25 pm, Christopher Reimer wrote: > For my BASIC interpreter, each line of BASIC is broken this way into > tokens. [...] > By using * to unpack the split line, my program no longer crashes and no > try/except block is needed to work around the crash. A later line of code > will test the expression, ignore if empty or run regex if full. I wish you wouldn't describe this as "crash". The Python interpreter should never crash. That would be a segmentation fault, and that is considered to be a very serious bug. But *raising an exception* is another story. Raising exceptions is not a crash, it is the interpreter working as expected. This statement: line_number, keyword, expr = "20 END".split(' ', 2) is SUPPOSED to raise an exception, if it didn't, the interpreter would be broken. To call that a "crash" is horribly misleading. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Fri Jul 1 10:13:42 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 02 Jul 2016 00:13:42 +1000 Subject: Namespaces are one honking great idea Message-ID: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> The Zen of Python says: Namespaces are one honking great idea -- let's do more of those! Proposal ========= Add a new "namespace" object to Python. Rationale ========== Sometimes we have a group of related functions and variables that belong together, but are not sufficiently unrelated to the rest of the module that we want to split them out into another file. Python allows us to group related chunks of code in three levels of grouping: - the class, containing one of more variable and/or function (method); - the module, containing one or more classes and/or functions; - the package, containing one or more modules. But classes are not like the others: they must be instantiated before they can be used, and they are more than just a mere namespace grouping related entities. Classes support inheritance. Classes should be used for "is-a" relationships, not "has-a" relationships. Although classes (and instances) are namespaces, they provide fundamentally different kind of behaviour than modules and packages. Sometimes we have a group of related functions which belongs together, but they are more closely related to each other than they are to the rest of the module, but not so distantly unrelated that they should be split off into a separate module. Nor do they belong as a class -- there's nothing analogous to an instance, and no need for inheritance. Perhaps the functions have some name clashes, e.g. two different functions that deserve the same name, or perhaps they're just conceptually related. What is needed is a module inside a module, but without the necessity of refactoring the code into a package and splitting the code out into a separate file. In other words, something rather like C++ namespaces: https://msdn.microsoft.com/en-us/library/5cb46ksf.aspx Proof of concept ================= Here's a proof of concept. I use a class with a custom metaclass like this: # Python 3 version class ExampleNS(metaclass=Namespace): x = 1 y = [] def spam(n): return 'spam'*n z = spam(3).upper() def ham(n): return spam(n).replace('sp', 'H') def test(): global x x += 1 y.append(1) return x, y And a demonstration of its use: py> Example.spam(5) 'spamspamspamspamspam' py> Example.ham(5) 'HamHamHamHamHam' py> Example.test() (2, [1]) py> Example.test() (3, [1, 1]) py> print(Example.x, Example.y, Example.z) 3 [1, 1] SPAMSPAMSPAM Despite the "class" statement (a limitation of Python's lack of dedicated syntax for namespaces), the Example namespace behaves like (in fact, *is*) a module embedded inside a module. Notice that the functions are not methods and don't require a "self" parameter. Being functions, they can be used inside the body of the namespace, including inside other functions. Outside the namespace, access is via dotted attribute: Example.spam. But inside it, functions can refer to each other without knowing the name of their namespace. Especially note that inside the namespace, the global statement makes a name refer to the namespace scope. Implementation =============== Here's a simplified implementation: from types import FunctionType, ModuleType class NamespaceType(ModuleType): def __repr__(self): return 'namespace <%s>' % self.__name__ class Namespace(type): def __new__(meta, name, bases, ns): if bases != (): raise RuntimeError("namespaces cannot inherit") module = NamespaceType(name) globals_ = module.__dict__ if '__builtins__' not in globals_: globals_['__builtins__'] = globals()['__builtins__'] for name, obj in ns.items(): if type(obj) is FunctionType: ns[name] = meta._copy_and_inject(obj, globals_) module.__dict__.update(ns) return module @classmethod def _copy_and_inject(meta, func, globals): """Return a new function object with the given globals.""" assert type(func) is FunctionType f = FunctionType( func.__code__, globals, func.__name__, func.__defaults__, func.__closure__) f.__dict__ = func.__dict__ # Next two lines are Python 3 only. f.__kwdefaults__ = func.__kwdefaults__ f.__annotations__ = func.__annotations__ return f The namespace object itself is actually a module (to be precise, a subclass of ModuleType). The Namespace metaclass returns a new module object, containing all the names I defined inside the class, after modifying any function objects to treat the new module object as their globals. Unresolved questions ===================== Would a decorator be better than a metaclass? @namespace class Example: ... How about a mechanism to exclude functions from having their globals changed? Some limitations ================= The simplified implementation shown doesn't allow functions inside the namespace to access names outside of the namespace easily. In practice, the user might want the name resolution order inside the namespace to be: local variables nonlocal variables namespace globals module globals builtins The biggest limitation is that I have to abuse the class statement to do this. In an ideal world, there would be syntactic support and a keyword: namespace Example: x = 0 y = [] def test(n): ... although others might argue that *not* needing a dedicated keyword is, in fact, better. Disadvantages ============== Those unfamiliar with the namespace concept may be confused by a class that doesn't get instantiated. Alternatives ============= At the moment, Python gives us four existing solutions: (1) Split the functions into a separate file, whether they deserve it or not. That's the smallest grouping Python supports so you're stuck with it. The obvious disadvantage is that what is conceptually a single file must be split into two, making more work for the developer. (2) Don't split the functions into their own namespace, keep them in the enclosing module namespace, but give them a "virtual namespace" by prefixing their names: def foods_spam(a, b): ... def foods_eggs(a): ... def advertising_spam(a, b, c): ... This requires the reader to see the "_" as a "virtual dot", rather than as a word separator as underscores are normally used as. It also fails to visually group the functions together, and requires functions to refer to each other using their full "virtual" dotted name. (3) Pretend you're in the Kingdom of Nouns[1]. Put the functions in a class, turn them into methods, and create an instance just so you can use them: class Foods: def spam(self, a, b): ... def eggs(self, a): ... class Advertising: def spam(self, a, b, c): ... foods = Foods() advertising = Advertising() optionally making each instance a singleton. Sometimes the class is deleted to discourage subclassing. This solution is often an anti-pattern, as it violates expectations about classes. The class should not be subclassed, nor should it be instantiated more than once. The class doesn't represent an "is-a" relationship, nor does the instance represent a real-world object. (4) Put them in a class, but use staticmethod (or classmethod) to avoid needing an instance: class foods: @staticmethod def spam(a, b): ... @staticmethod def eggs(a): ... class advertising: @staticmethod def spam(a, b, c): ... This has the disadvantage that functions in the class cannot call each other directly, but must use the dotted names. This is the Python equivalent of the "Java utility class" pattern, or arguably anti-pattern[2], where you create a class with little or no state and populate it with a number of static methods. [1] http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html [2] http://www.yegor256.com/2014/05/05/oop-alternative-to-utility-classes.html -- Steven From christopher_reimer at icloud.com Fri Jul 1 10:15:19 2016 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Fri, 01 Jul 2016 07:15:19 -0700 Subject: Creating a calculator In-Reply-To: <577675ae$0$1604$c3e8da3$5496439d@news.astraweb.com> References: <0E77E5BC-E8CC-4951-B520-37BF2E596D3A@icloud.com> <577675ae$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: > On Jul 1, 2016, at 6:52 AM, Steven D'Aprano wrote: > >> On Fri, 1 Jul 2016 10:25 pm, Christopher Reimer wrote: >> >> For my BASIC interpreter, each line of BASIC is broken this way into >> tokens. > [...] >> By using * to unpack the split line, my program no longer crashes and no >> try/except block is needed to work around the crash. A later line of code >> will test the expression, ignore if empty or run regex if full. > > I wish you wouldn't describe this as "crash". > > The Python interpreter should never crash. That would be a segmentation > fault, and that is considered to be a very serious bug. > > But *raising an exception* is another story. Raising exceptions is not a > crash, it is the interpreter working as expected. This statement: > > line_number, keyword, expr = "20 END".split(' ', 2) > > is SUPPOSED to raise an exception, if it didn't, the interpreter would be > broken. To call that a "crash" is horribly misleading. Where did I write that the Python interpreter had "crashed"? I wrote that *my program* crashed and I found an elegant solution to prevent the crashing from happening in the first place that doesn't require a try/except block. Chris R. From rustompmody at gmail.com Fri Jul 1 10:19:25 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 1 Jul 2016 07:19:25 -0700 (PDT) Subject: Can math.atan2 return INF? In-Reply-To: <57755efb$0$1604$c3e8da3$5496439d@news.astraweb.com> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <57739650$0$1601$c3e8da3$5496439d@news.astraweb.com> <87mvm4uux1.fsf@elektro.pacujo.net> <5774d75d$0$1617$c3e8da3$5496439d@news.astraweb.com> <0765346e-42a1-48b7-8b7d-e134f4165ce4@googlegroups.com> <57755efb$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7b1b0a49-86ac-4d9e-8113-35c8f56500cc@googlegroups.com> On Thursday, June 30, 2016 at 11:33:58 PM UTC+5:30, Steven D'Aprano wrote: > On Fri, 1 Jul 2016 01:28 am, Rustom Mody wrote: > > > On Thursday, June 30, 2016 at 1:55:18 PM UTC+5:30, Steven D'Aprano wrote: > > > >> you state that Turing "believes in souls" and that he "wishes to > >> put the soul into the machine" -- what do his religious beliefs have to > >> do with his work? > > > > Bizarre question -- becomes more patently ridiculous when put into general > > form "What does what I do have to do with what I believe?" > > Lots of people do things that go against their beliefs, or their beliefs (at > least, their professed beliefs) go against what they do. But I'll ask > again: in what way does Turing's supposed beliefs about souls have anything > to do with his mathematical work? > > Let's be concrete: > > In what way does the Halting Problem depend on the existence (or > non-existence) of the soul? Lets change your question -- ever so slightly, given the Turing-context: In what way does the Turing Test depend on the existence (or non-existence) of the soul? > > How was his work on breaking German military codes during World War 2 > reliant on these supposed souls? (In the sense of a separate, non-material > spirit, not in the figurative sense that all people are "souls".) When you say "soul" you (seem to?) mean what has been called with justifiable derision, "dualistic notion of soul" - something for which Christianity gets bad press though its the invention of Descartes http://www.iep.utm.edu/descmind/ - something which caught on because of Descartes huge reputation as a scientist There are other more reasonable non-religious non-dualistic notions of soul possible: http://www.bu.edu/agni/poetry/print/2002/56-szymborska.html You are missing the point -- its not about specific numbers its about cardinality not adding up - Cantor theory points to uncountably many real numbers - All the sets upto algebraic are countable - So the uncountable fellas need to be transcendental - We only know two blessed guys -- ? and e Where are all the others hiding?? And dont try saying that if e is transcendental so is 2e 3e 4e... And no use trying more such tricks -- they only multiply these two countably infinite times And you may produce a few more, more esoteric transcendentals --- a very finite set! Nor is it much good saying this is not much relevance to our field: https://en.wikipedia.org/wiki/Cantor%27s_diagonal_argument So our (computer scientists') predicament in short - our field is opposed to Cantor's non-constructivist *outlook* - At the foundation of CS are *methods* that.... come from Cantor... OOPS! From alister.ware at ntlworld.com Fri Jul 1 10:21:43 2016 From: alister.ware at ntlworld.com (alister) Date: Fri, 01 Jul 2016 14:21:43 GMT Subject: Creating a calculator References: <0E77E5BC-E8CC-4951-B520-37BF2E596D3A@icloud.com> <577675ae$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 01 Jul 2016 23:52:45 +1000, Steven D'Aprano wrote: > On Fri, 1 Jul 2016 10:25 pm, Christopher Reimer wrote: > >> For my BASIC interpreter, each line of BASIC is broken this way into >> tokens. > [...] >> By using * to unpack the split line, my program no longer crashes and >> no try/except block is needed to work around the crash. A later line of >> code will test the expression, ignore if empty or run regex if full. > > I wish you wouldn't describe this as "crash". > > The Python interpreter should never crash. That would be a segmentation > fault, and that is considered to be a very serious bug. > > But *raising an exception* is another story. Raising exceptions is not a > crash, it is the interpreter working as expected. This statement: > > line_number, keyword, expr = "20 END".split(' ', 2) > > is SUPPOSED to raise an exception, if it didn't, the interpreter would > be broken. To call that a "crash" is horribly misleading. i think this one is a matter of symantics you are correct that the Python interpreter has not crashed but the op could also be considered correct is saying that HIS program has crashed. As a child I had many programs "crash" in this way on my Commodore 64 without killing the basic interpreter (at-least not until I started to include machine code ;-) ) -- Technology is dominated by those who manage what they do not understand. From vek.m1234 at gmail.com Fri Jul 1 10:24:51 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Fri, 01 Jul 2016 19:54:51 +0530 Subject: super and mix-in class: how exactly is the search order altered? Message-ID: I had posted this on StackOverflow - it's an excellent example of why SO sucks (don't want that happening here so please read carefully): http://stackoverflow.com/questions/38145818/super-and-mix-in-class-how-exactly-is-the-search-order-altered?noredirect=1#comment63722336_38145818 I'm reading this article: https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ He's trying to explain the purpose of a 'mix-in class' and he says We did not alter the source code for LoggingDict. Instead we built a subclass whose only logic is to compose two existing classes and control their search order. class LoggingOD(LoggingDict, collections.OrderedDict): pass My question is this: in the above article context, is he talking about the LoggingDict's search order that is being manipulated? Or he is talking about manipulating the LoggingOD search order? He says very clearly "not alter the source code for LoggingDict" so clearly he means that somehow, magically - the search order for super().__setitem__ in class LoggingDict(dict): def __setitem__(self, key, value): logging.info('Settingto %r' % (key, value)) super().__setitem__(key, value) is being altered/influenced, but how? Could someone clarify what exactly is going on here? Far as I can make of it, the tree looks like this: http://i.stack.imgur.com/3foOB.jpg Here's the code: import collections class LoggingDict(dict): def __setitem__(self, key, value): logging.info('Settingto %r' % (key, value)) super().__setitem__(key, value) class LoggingOD(LoggingDict, collections.OrderedDict): pass x = LoggingDict() print LoggingDict.__mro__ print LoggingOD.__mro__ as you can see.. selfstudy at deathstar:~$ python 29.mro.py (, , ) (, , , , ) selfstudy at deathstar:~$ From random832 at fastmail.com Fri Jul 1 10:40:08 2016 From: random832 at fastmail.com (Random832) Date: Fri, 01 Jul 2016 10:40:08 -0400 Subject: Namespaces are one honking great idea In-Reply-To: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1467384008.3405105.654263993.05341F8A@webmail.messagingengine.com> On Fri, Jul 1, 2016, at 10:13, Steven D'Aprano wrote: > The biggest limitation is that I have to abuse the class statement to do > this. In an ideal world, there would be syntactic support and a keyword: > > namespace Example: > x = 0 > y = [] > def test(n): ... > > although others might argue that *not* needing a dedicated keyword is, in > fact, better. What might be nice would be a single syntax that isn't specific to classes or your "namespaces". namespace(type) Name: "equivalent to class Name:" namespace(whatever) Name: "equivalent to class Name(metaclass=whatever)" From bc at freeuk.com Fri Jul 1 10:49:15 2016 From: bc at freeuk.com (BartC) Date: Fri, 1 Jul 2016 15:49:15 +0100 Subject: Namespaces are one honking great idea In-Reply-To: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/07/2016 15:13, Steven D'Aprano wrote: > Sometimes we have a group of related functions and variables that belong > together, but are not sufficiently unrelated to the rest of the module that > we want to split them out into another file. > Here's a proof of concept. I use a class with a custom metaclass like this: > > > # Python 3 version > class ExampleNS(metaclass=Namespace): > x = 1 > y = [] > > def spam(n): > return 'spam'*n > py> Example.spam(5) > 'spamspamspamspamspam' Why not just extend the capabilities of a class? I actually thought this would work until I tried it and it didn't: class C(): def fn(): print ("Hi!") C.fn() The error message suggests Python knows what's going on. So why not just make it work? (The main issue would be, if an instance X of C /was/ created, then X.fn() wouldn't work as there is no 'self' parameter for fn.) -- Bartc From marko at pacujo.net Fri Jul 1 11:20:11 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 01 Jul 2016 18:20:11 +0300 Subject: Can math.atan2 return INF? References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <57739650$0$1601$c3e8da3$5496439d@news.astraweb.com> <87mvm4uux1.fsf@elektro.pacujo.net> <5774d75d$0$1617$c3e8da3$5496439d@news.astraweb.com> <0765346e-42a1-48b7-8b7d-e134f4165ce4@googlegroups.com> <57755efb$0$1604$c3e8da3$5496439d@news.astraweb.com> <7b1b0a49-86ac-4d9e-8113-35c8f56500cc@googlegroups.com> Message-ID: <87oa6hl710.fsf@elektro.pacujo.net> Rustom Mody : > There are other more reasonable non-religious non-dualistic notions of > soul possible: Software engineers should have an easy time understanding what a soul is: a sufficiently sophisticated software system in execution. I'd say the minimum requirement for a soul is the capacity to suffer. I don't think anything built by humans has yet reached that level of sophistication, but insects probably can feel pain as authentically as humans. > - Cantor theory points to uncountably many real numbers > - All the sets upto algebraic are countable > - So the uncountable fellas need to be transcendental > - We only know two blessed guys -- ? and e > > Where are all the others hiding?? Here: . > And dont try saying that if e is transcendental so is 2e 3e 4e... And > no use trying more such tricks -- they only multiply these two > countably infinite times And you may produce a few more, more esoteric > transcendentals --- a very finite set! The banal way of putting it that we can express only countably many individual items. The more philosophical point of view is that mathematics failed at circumscribing all of philosophy and is condemned to counting beans. Naive set theory was a Grand Unified Theory of Everything, but of course inconsistent. The bottom-up set theories are sane but completely fail at being the ultimate metalevel. Marko From ethan at stoneleaf.us Fri Jul 1 12:00:44 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 01 Jul 2016 09:00:44 -0700 Subject: Namespaces are one honking great idea In-Reply-To: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <577693AC.6090807@stoneleaf.us> On 07/01/2016 07:13 AM, Steven D'Aprano wrote: I like the idea, but I have a couple questions about the design choices. Comments below. > The Zen of Python says: > > Namespaces are one honking great idea -- let's do more of those! > Proposal > ========= > > Add a new "namespace" object to Python. > Proof of concept > ================= > > Here's a proof of concept. I use a class with a custom metaclass like this: > > > # Python 3 version > class ExampleNS(metaclass=Namespace): > x = 1 > y = [] > > def spam(n): > return 'spam'*n > > z = spam(3).upper() > > def ham(n): > return spam(n).replace('sp', 'H') > > def test(): > global x > x += 1 > y.append(1) > return x, y > > Despite the "class" statement (a limitation of Python's lack of dedicated > syntax for namespaces), the Example namespace behaves like (in fact, *is*) > a module embedded inside a module. So the idea is to have several "mini-modules" inside a single file? Can a mini-module function access a different mini-module's function? Can a mini-module function access/interact with the module's global scope? > Especially note that inside the namespace, the global statement makes a name > refer to the namespace scope. Interesting. :) > Unresolved questions > ===================== > > Would a decorator be better than a metaclass? I think a decorator may provide more of a clue that something interesting is happening -- whether a decorator is feasible depends on whether you need the __prepare__ magic of metaclasses. > @namespace > class Example: > ... I believe Python already has a NameSpace type, so a different name is probably better. How about minimodule? ;) > Some limitations > ================= > > The simplified implementation shown doesn't allow functions inside the > namespace to access names outside of the namespace easily. How not-easy is it? > In practice, the > user might want the name resolution order inside the namespace to be: > > local variables > nonlocal variables > namespace globals > module globals > builtins That would be ideal, I think. How close can we get to that? > The biggest limitation is that I have to abuse the class statement to do > this. In an ideal world, there would be syntactic support and a keyword: > > namespace Example: > x = 0 > y = [] > def test(n): ... > > although others might argue that *not* needing a dedicated keyword is, in > fact, better. Metaclasses for the win! > Disadvantages > ============== > > Those unfamiliar with the namespace concept may be confused by a class that > doesn't get instantiated. A well-named decorator/base-class should help with that. Did you mean for this to go to -Ideas? -- ~Ethan~ From topic2k at googlemail.com Fri Jul 1 12:50:38 2016 From: topic2k at googlemail.com (topic2k at googlemail.com) Date: Fri, 1 Jul 2016 09:50:38 -0700 (PDT) Subject: [ANN] pygcgen (github changelog generator) Message-ID: <2a74109e-3839-4782-90b3-6198d4a9b2fd@googlegroups.com> Hello, maybe you know "GitHub Changelog Generator" (https://github.com/skywinder/github-changelog-generator). As i came across it, i liked to try it, but wasn't able to get it running. The script is written in Ruby. As i don't know Ruby, i had the idea to convert it to Python. After a few days of trial and error, learning a bit of Ruby and debugging, i finally had a working version: https://github.com/topic2k/pygcgen . Now i wanna ask you, if you would like to try pygcgen (as i called my version) and give me some feedback. I already tried some options, but the more people test it, the better can get it. :) Currently it's only written to be compatible with Python 2.7. Any help in making it compatible with 2.7 and 3.5 would be appreciated. From steve at pearwood.info Fri Jul 1 13:10:05 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 02 Jul 2016 03:10:05 +1000 Subject: Namespaces are one honking great idea References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> Message-ID: <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Jul 2016 02:00 am, Ethan Furman wrote: > On 07/01/2016 07:13 AM, Steven D'Aprano wrote: > > I like the idea, but I have a couple questions about the design choices. Thanks! > Comments below. [...] >> Despite the "class" statement (a limitation of Python's lack of dedicated >> syntax for namespaces), the Example namespace behaves like (in fact, >> *is*) a module embedded inside a module. > > So the idea is to have several "mini-modules" inside a single file? That would certainly be possible. > Can a mini-module function access a different mini-module's function? Yes, via the dotted attribute name, just as you might say "math.sin". The only difference is that you don't use import to get access to the (mini-)module. It's just there, defined in your own file. > Can a mini-module function access/interact with the module's global scope? Yes. I'm still experimenting with different implementations, but I have a proof of concept working. >> Especially note that inside the namespace, the global statement makes a >> name refer to the namespace scope. > > Interesting. :) > > >> Unresolved questions >> ===================== >> >> Would a decorator be better than a metaclass? > > I think a decorator may provide more of a clue that something > interesting is happening -- whether a decorator is feasible depends on > whether you need the __prepare__ magic of metaclasses. I don't think __prepare__ is needed. >> @namespace >> class Example: >> ... > > I believe Python already has a NameSpace type, so a different name is > probably better. How about minimodule? ;) I think you are thinking of "SimpleNamespace". In any case, so long as my namespace lives in a different, er, namespace as the other namespace, there's no conflict :-) In the long term, I think my namespace (if accepted into the stdlib) would belong in functools, collections or types. Perhaps even its own module. I don't think this needs to be a built-in. >> Some limitations >> ================= >> >> The simplified implementation shown doesn't allow functions inside the >> namespace to access names outside of the namespace easily. > > How not-easy is it? Not that hard now. I have an implementation working. It actually turned out to be easy. (Thanks Raymond for ChainMap!) >> In practice, the >> user might want the name resolution order inside the namespace to be: >> >> local variables >> nonlocal variables >> namespace globals >> module globals >> builtins > > That would be ideal, I think. How close can we get to that? I now have that working, for some definition of working. Its not extensively tested, so there might be some bugs or issues I haven't thought of, but the basic concept is working: inside the namespace/mini-module object, functions see namespace globals ahead of module globals, which are ahead of builtins. [...] > Did you mean for this to go to -Ideas? Not yet. I wanted some initial feedback to see if anyone else liked the idea before taking it to Bikeshedding Central :-) Besides, I expect Python-Ideas will say it needs to be a package on PpPI first. Although I am kinda considering sneaking this into the std lib as an undocumented internal feature, like simplegeneric in pkgutil. (Don't tell anyone I said that *wink* ) -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Fri Jul 1 13:13:21 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jul 2016 03:13:21 +1000 Subject: Namespaces are one honking great idea In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jul 2, 2016 at 12:49 AM, BartC wrote: > Why not just extend the capabilities of a class? I actually thought this > would work until I tried it and it didn't: > > class C(): > def fn(): > print ("Hi!") > > C.fn() > > The error message suggests Python knows what's going on. So why not just > make it work? rosuav at sikorsky:~$ python3 Python 3.6.0a2+ (default:57f3514564f6, Jun 29 2016, 16:27:34) [GCC 5.3.1 20160528] on linux Type "help", "copyright", "credits" or "license" for more information. >>> class C(): ... def fn(): ... print ("Hi!") ... >>> C.fn() Hi! >>> But if you have two such functions, they can't call each other without the namespace marker. ChrisA From jussi.piitulainen at helsinki.fi Fri Jul 1 13:44:26 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 01 Jul 2016 20:44:26 +0300 Subject: Creating a calculator References: <0E77E5BC-E8CC-4951-B520-37BF2E596D3A@icloud.com> <577675ae$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Fri, 1 Jul 2016 10:25 pm, Christopher Reimer wrote: > >> For my BASIC interpreter, each line of BASIC is broken this way into >> tokens. > [...] >> By using * to unpack the split line, my program no longer crashes and no >> try/except block is needed to work around the crash. A later line of code >> will test the expression, ignore if empty or run regex if full. > > I wish you wouldn't describe this as "crash". > > The Python interpreter should never crash. That would be a segmentation > fault, and that is considered to be a very serious bug. > > But *raising an exception* is another story. Raising exceptions is not a > crash, it is the interpreter working as expected. This statement: > > line_number, keyword, expr = "20 END".split(' ', 2) > > is SUPPOSED to raise an exception, if it didn't, the interpreter would > be broken. To call that a "crash" is horribly misleading. I think Christopher merely echoed my use of the word, so let me take the blame. But it's quite different to say "my program crashed" (didn't handle an exception - fix program, or fix the input) and "the Python interpreter crashed" (uh oh). From steve at pearwood.info Fri Jul 1 13:46:40 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 02 Jul 2016 03:46:40 +1000 Subject: Namespaces are one honking great idea References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5776ac82$0$1622$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Jul 2016 12:49 am, BartC wrote: > On 01/07/2016 15:13, Steven D'Aprano wrote: > >> Sometimes we have a group of related functions and variables that belong >> together, but are not sufficiently unrelated to the rest of the module >> that we want to split them out into another file. > >> Here's a proof of concept. I use a class with a custom metaclass like >> this: >> >> >> # Python 3 version >> class ExampleNS(metaclass=Namespace): >> x = 1 >> y = [] >> >> def spam(n): >> return 'spam'*n > >> py> Example.spam(5) >> 'spamspamspamspamspam' > > > Why not just extend the capabilities of a class? The usual ways to change the behaviour of classes from Python code is via decorator, which lets you modify the class after it is created, a metaclass, which lets you modify it before it is created, or by using descriptors to customize attribute access. I'm using a metaclass. When you write: class K: ... that is syntactic sugar for calling the default metaclass (`type`) with some arguments, and `type` then returns the new class K. But if you use a metaclass (usually, but not necessarily a subclass of `type`) you can customize the creation of the new class, or even return a completely different object altogether. That's what I'm doing. Why am I returning a module instead of a class? Because (1) conceptually a namespace (in the C++ sense) is like a module; (2) classes have a whole lot of expectations that aren't relevant to namespaces (like inheritance, instantiation, "is-a", etc); and (3) it's easy to use a module, which already provides most of the behaviour I want. > I actually thought this > would work until I tried it and it didn't: > > class C(): > def fn(): > print ("Hi!") > > C.fn() That actually will work in Python 3. (I had forgotten that.) In Python 2, you have to inherit C from object, AND decorate fn with staticmethod: class C(object): @staticmethod def fn(): print ("Hi!") But for my use, that's not enough. I want this to work: class Foo: def f(): return g().upper() def g(): return "hi!" That is, Foo should behave as if it were a module imported from a file, except without actually being imported from a file. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From dagar.basant2 at gmail.com Fri Jul 1 14:00:03 2016 From: dagar.basant2 at gmail.com (Basant Dagar) Date: Fri, 1 Jul 2016 11:00:03 -0700 (PDT) Subject: what the heck this code is doing? Message-ID: <3bbddafc-dcd6-4d5c-84f4-94077b5bccc8@googlegroups.com> #See below code: def lookup(d, keyval): found = False for child in d: if found : return child.text if child.tag == 'key' and child.text == keyval : found = True return None trackID = lookup(entry, 'Track ID') Below is the main part of input xml file data, it passes to lookup function: Track ID369 what I don't get is. How in the world it returns value 369 for the variable 'trackID'?? From gordon at panix.com Fri Jul 1 14:06:15 2016 From: gordon at panix.com (John Gordon) Date: Fri, 1 Jul 2016 18:06:15 +0000 (UTC) Subject: what the heck this code is doing? References: <3bbddafc-dcd6-4d5c-84f4-94077b5bccc8@googlegroups.com> Message-ID: In <3bbddafc-dcd6-4d5c-84f4-94077b5bccc8 at googlegroups.com> Basant Dagar writes: > def lookup(d, keyval): > found = False > for child in d: > if found : return child.text > if child.tag == 'key' and child.text == keyval : > found = True > return None > trackID = lookup(entry, 'Track ID') > Below is the main part of input xml file data, it passes to lookup function: > Track ID369 > what I don't get is. How in the world it returns value 369 for the variable 'trackID'?? It loops through the child items in entry, looking for one with a 'key' value of 'Track ID'. If it finds one, it sets found=True and loops one more time, returning the text of the *next* child element. It depends on the 'key' element being directly followed by the 'integer' element within entry. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From dagar.basant2 at gmail.com Fri Jul 1 14:13:46 2016 From: dagar.basant2 at gmail.com (Basant Dagar) Date: Fri, 1 Jul 2016 11:13:46 -0700 (PDT) Subject: what the heck this code is doing? In-Reply-To: References: <3bbddafc-dcd6-4d5c-84f4-94077b5bccc8@googlegroups.com> Message-ID: <42b4a251-668d-4d1a-b5b9-9356bc4ea5ba@googlegroups.com> On Friday, July 1, 2016 at 2:06:28 PM UTC-4, John Gordon wrote: > In <3bbddafc-dcd6-4d5c-84f4-94077b5bccc8 at googlegroups.com> Basant Dagar writes: > > > def lookup(d, keyval): > > found = False > > for child in d: > > if found : return child.text > > if child.tag == 'key' and child.text == keyval : > > found = True > > return None > > > trackID = lookup(entry, 'Track ID') > > > Below is the main part of input xml file data, it passes to lookup function: > > > Track ID369 > > > what I don't get is. How in the world it returns value 369 for the variable 'trackID'?? > > It loops through the child items in entry, looking for one with a > 'key' value of 'Track ID'. If it finds one, it sets found=True and > loops one more time, returning the text of the *next* child element. > > It depends on the 'key' element being directly followed by the 'integer' > element within entry. > > -- > John Gordon A is for Amy, who fell down the stairs > gordon at panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" Awesome. Thank you John for the prompt response. From dagar.basant2 at gmail.com Fri Jul 1 14:15:12 2016 From: dagar.basant2 at gmail.com (Basant Dagar) Date: Fri, 1 Jul 2016 11:15:12 -0700 (PDT) Subject: what the heck this code is doing? In-Reply-To: References: <3bbddafc-dcd6-4d5c-84f4-94077b5bccc8@googlegroups.com> Message-ID: <764fd2c6-c2c5-404f-adb0-4a7d5af1cd04@googlegroups.com> Awesome. Thank you John for the prompt response. From bgailer at gmail.com Fri Jul 1 14:39:14 2016 From: bgailer at gmail.com (Bob Gailer) Date: Fri, 1 Jul 2016 14:39:14 -0400 Subject: Need help in python program In-Reply-To: References: <2144eabe-bf8f-4fa8-833d-e41b0efdc932@googlegroups.com> Message-ID: On Jul 1, 2016 6:30 AM, "Archana Sonavane" wrote: > > Hello Everyone, > > I am doing python code by using API. > > My first API giving fields - Itemid, clock and value > second API giving fields - Itemid, key, units and delay > > using for loops for both API. > > Could you please tell me how to compare both id by using equal operator. > > My output should be : > > Itemid, clock, value, key, units and delay Please provide some sample input and the corresponding output. What do you mean by API? From auriocus at gmx.de Fri Jul 1 15:22:57 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 1 Jul 2016 21:22:57 +0200 Subject: Need help in python program In-Reply-To: <2144eabe-bf8f-4fa8-833d-e41b0efdc932@googlegroups.com> References: <2144eabe-bf8f-4fa8-833d-e41b0efdc932@googlegroups.com> Message-ID: Am 01.07.16 um 12:26 schrieb Archana Sonavane: > Hello Everyone, > > I am doing python code by using API. > > My first API giving fields - Itemid, clock and value > second API giving fields - Itemid, key, units and delay > > using for loops for both API. > > Could you please tell me how to compare both id by using equal operator. > > My output should be : > > Itemid, clock, value, key, units and delay > I think you want a "join" operation from relational algebra. pandas can do that: http://pandas.pydata.org/pandas-docs/stable/merging.html#database-style-dataframe-joining-merging or you just store the one table in a dict with Itemd as the key and loop over the second, while looking up corresponding values from the dict. Christin From ethan at stoneleaf.us Fri Jul 1 15:29:40 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 01 Jul 2016 12:29:40 -0700 Subject: Namespaces are one honking great idea In-Reply-To: <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5776C4A4.5000407@stoneleaf.us> On 07/01/2016 10:10 AM, Steven D'Aprano wrote: > On Sat, 2 Jul 2016 02:00 am, Ethan Furman wrote: >> Did you mean for this to go to -Ideas? > > Not yet. I wanted some initial feedback to see if anyone else liked the idea > before taking it to Bikeshedding Central :-) > > Besides, I expect Python-Ideas will say it needs to be a package on PpPI > first. Although I am kinda considering sneaking this into the std lib as an > undocumented internal feature, like simplegeneric in pkgutil. (Don't tell > anyone I said that *wink* ) Are there good use-cases for this in the stdlib? -- ~Ethan~ From ben.usenet at bsb.me.uk Fri Jul 1 16:25:48 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Fri, 01 Jul 2016 21:25:48 +0100 Subject: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions References: <85mvm5vrbw.fsf@benfinney.id.au> <0690f476-95ad-4dec-87e5-42ecee07fdcd@googlegroups.com> <87poqx96ul.fsf@handshake.de> Message-ID: <87bn2h85rn.fsf@bsb.me.uk> dieter writes: >> Lawrence D?Oliveiro wrote: >>> I don?t know why this fear and suspicion of lambdas is so widespread among >>> Python users ... former Java/C# programmers, perhaps? By replying I'm not accepting the premise -- I have no idea if there is widespread fear and suspicion of lambdas among Python users but it seems unlikely. > Maybe, it's the name ("lambda"). > > In Javascript, anonymous functions are widespread (and extensively > used for e.g. callback definitions) Yes, but in Python they are restricted to a single expression. It's therefore quite likely that programmers who want the semantics of an anonymous function just define a named function and use that instead. That saves you from having to decide, up front, if an expression is going to be enough or from having to change it later if you find that it isn't. > - but it uses the much more familiar > "function" (rather than "lambda") for this purpose. ... or the new arrow notation. -- Ben. From lawrencedo99 at gmail.com Fri Jul 1 18:08:22 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 1 Jul 2016 15:08:22 -0700 (PDT) Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: References: <85mvm5vrbw.fsf@benfinney.id.au> Message-ID: <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: > There is a clever one-line decorator that has been copy-pasted without > explanation in many code bases for many years:: > > decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda func: decorator(func, *args, **kwargs) > For those who want docstrings, I?ll give you docstrings: def decorator_with_args(decorator) : "given function decorator(func, *args, **kwargs), returns a decorator which," \ " given func, returns the result of decorator(func, *args, **kwargs)." def decorate(*args, **kwargs) : def generated_decorator(func) : return \ decorator(func, *args, **kwargs) #end generated_decorator #begin decorate generated_decorator.__name__ = "decorator_{}".format(decorator.__name__) generated_decorator.__doc__ = "decorator which applies {} to the previously-specified arguments".format(decorator.__name__) return \ generated_decorator #end decorate #begin decorator_with_args decorate.__name__ = "decorate_with_{}".format(decorator.__name__) decorate.__doc__ = "generates a decorator which applies {} to the given arguments".format(decorator.__name__) return \ decorate #end decorator_with_args From steve at pearwood.info Fri Jul 1 21:07:17 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 02 Jul 2016 11:07:17 +1000 Subject: Namespaces are one honking great idea References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> Message-ID: <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Jul 2016 05:29 am, Ethan Furman wrote: > On 07/01/2016 10:10 AM, Steven D'Aprano wrote: >> On Sat, 2 Jul 2016 02:00 am, Ethan Furman wrote: > >>> Did you mean for this to go to -Ideas? >> >> Not yet. I wanted some initial feedback to see if anyone else liked the >> idea before taking it to Bikeshedding Central :-) >> >> Besides, I expect Python-Ideas will say it needs to be a package on PpPI >> first. Although I am kinda considering sneaking this into the std lib as >> an undocumented internal feature, like simplegeneric in pkgutil. (Don't >> tell anyone I said that *wink* ) > > Are there good use-cases for this in the stdlib? I have at least one. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From kevinjacobconway at gmail.com Fri Jul 1 21:50:24 2016 From: kevinjacobconway at gmail.com (Kevin Conway) Date: Sat, 02 Jul 2016 01:50:24 +0000 Subject: Namespaces are one honking great idea In-Reply-To: <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: I believe the namespace object you are referring to is exactly a class. IIRC, classes came about as a "module in a module". Regardless, all use cases you've listed are already satisfied by use of the static and class method decorators. Methods decorated with these do not require an instance initialization to use. On Fri, Jul 1, 2016, 20:17 Steven D'Aprano wrote: > On Sat, 2 Jul 2016 05:29 am, Ethan Furman wrote: > > > On 07/01/2016 10:10 AM, Steven D'Aprano wrote: > >> On Sat, 2 Jul 2016 02:00 am, Ethan Furman wrote: > > > >>> Did you mean for this to go to -Ideas? > >> > >> Not yet. I wanted some initial feedback to see if anyone else liked the > >> idea before taking it to Bikeshedding Central :-) > >> > >> Besides, I expect Python-Ideas will say it needs to be a package on PpPI > >> first. Although I am kinda considering sneaking this into the std lib as > >> an undocumented internal feature, like simplegeneric in pkgutil. (Don't > >> tell anyone I said that *wink* ) > > > > Are there good use-cases for this in the stdlib? > > I have at least one. > > > > -- > Steven > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Fri Jul 1 21:52:07 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 02 Jul 2016 11:52:07 +1000 Subject: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions References: <85mvm5vrbw.fsf@benfinney.id.au> <0690f476-95ad-4dec-87e5-42ecee07fdcd@googlegroups.com> <87poqx96ul.fsf@handshake.de> <87bn2h85rn.fsf@bsb.me.uk> Message-ID: <8537nsvmbc.fsf@benfinney.id.au> Ben Bacarisse writes: > By replying I'm not accepting the premise -- I have no idea if there > is widespread fear and suspicion of lambdas among Python users but it > seems unlikely. I can testify, as the person who started this thread, that there is no fear or suspicion of lambda here. I use it quite frequently without qualm for creating self-explanatory functions that need no name. Rather, the motivation was that a complex thing, with many moving parts, has an unexplained implementation: a nested set of functions without names to explain their part in the pattern. That these are then immediately bound to a name, to me defeats the purpose of using lambda in the first place. If you want a named function, lambda is not the tool to reach for; we have the ?def? statement for that. But by using ?lambda? the author avoided one of the more important parts of publishing the code: making it readable and self-explanatory. If they'd chosen a name for each function, that would at least have prompted them to explain what they're doing. So ?lambda? is great, and I use it without worry for creating simple self-explanatory nameless functions. But it's not the right tool for this job: This is not self-explanatory, and the component functions should not be nameless. -- \ ?It is forbidden to steal hotel towels. Please if you are not | `\ person to do such is please not to read notice.? ?hotel, | _o__) Kowloon, Hong Kong | Ben Finney From rustompmody at gmail.com Fri Jul 1 22:26:06 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 1 Jul 2016 19:26:06 -0700 (PDT) Subject: Namespaces are one honking great idea In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0b47df98-7f96-4791-aa5d-ef3cdbca1c47@googlegroups.com> On Friday, July 1, 2016 at 8:19:36 PM UTC+5:30, BartC wrote: > On 01/07/2016 15:13, Steven D'Aprano wrote: > > > Sometimes we have a group of related functions and variables that belong > > together, but are not sufficiently unrelated to the rest of the module that > > we want to split them out into another file. > > > Here's a proof of concept. I use a class with a custom metaclass like this: > > > > > > # Python 3 version > > class ExampleNS(metaclass=Namespace): > > x = 1 > > y = [] > > > > def spam(n): > > return 'spam'*n > > > py> Example.spam(5) > > 'spamspamspamspamspam' > > > Why not just extend the capabilities of a class? I actually thought this > would work until I tried it and it didn't: Well I also thought similarly -- sure a normal (instance) method cannot be used without an instance but sure this is what class/static methods are for? ie Steven's option 4. Then I remembered that python's LEGB rule is bizarre: Outer scopes are added outside inner scopes ... except for classes From lawrencedo99 at gmail.com Fri Jul 1 22:55:13 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 1 Jul 2016 19:55:13 -0700 (PDT) Subject: Namespaces are one honking great idea In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: <82a50740-9e24-449c-ac7b-23a46a01a787@googlegroups.com> On Saturday, July 2, 2016 at 1:50:56 PM UTC+12, Kevin Conway wrote: > Regardless, all use cases you've listed are already satisfied by use of the > static and class method decorators. Except for the need to decorate every such function inside the class. How about: import types def namespace(inclass) : "decorator which turns a class into a module." outclass = types.ModuleType \ ( name = inclass.__name__, doc = inclass.__doc__, ) for attr in dir(inclass) : if not attr.startswith("__") or attr in ("__package__",) : setattr(outclass, attr, getattr(inclass, attr)) #end if #end for return \ outclass #end namespace Example use: @namespace class try_it : "try it!" val = "some text" def func() : print("func got called") #end func #end try_it From lawrencedo99 at gmail.com Fri Jul 1 23:16:19 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 1 Jul 2016 20:16:19 -0700 (PDT) Subject: Controlling the Mac OSX GUI via Python? In-Reply-To: References: <68044aa3-8a3c-47cd-b6d0-aaa0e3f1fc62@googlegroups.com> <09315fbb-05b1-4c4e-a6f7-7cfda79a1286@googlegroups.com> <7d144305-e228-4241-90d6-86677ef713b7@googlegroups.com> Message-ID: On Friday, July 1, 2016 at 4:59:11 PM UTC+12, Christian Gollwitzer wrote: > Yes, simulating mouse clicks with > fixed coordinates etc. is prone to such failure, but there are better > methods. These mouse clicks and keyboard events usually trigger a method > call inside the GUI program. If there are any means to call that method > directly, you are independent from the graphics itself. Even if you could get it working reliably, scripting a GUI is going to be slow. GUIs are only designed to work at human speeds, after all. From vek.m1234 at gmail.com Fri Jul 1 23:35:30 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Sat, 02 Jul 2016 09:05:30 +0530 Subject: why x is changed in the following program? References: Message-ID: maurice.charbit at telecom-paristech.fr wrote: > from numpy import random > x=random.randn(6) > y=x > y[0]=12 > print x[0] > > > random.rand returns a list. x is a label to this list (container). y=x creates another label to the same container/list. y[0[ = 12 alters the 0th position of the container. print x[0], uses a different label 'x' to change the same container. use: y = list(x) to do a 'shallow copy' of x into a new list container From vek.m1234 at gmail.com Fri Jul 1 23:43:24 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Sat, 02 Jul 2016 09:13:24 +0530 Subject: subprocess startup error References: Message-ID: Shweta Dinnimani wrote: > hi > > hello, I'm begineer to python programming.. I had installed python > 3.5.1 version on my windows 7 system. I was fine earlier and now when > i was trying the programs on string i'm facing the subprocess startup > error. IDLE is not connecting. And python shell is also not opening. I > tried uninstalling and installing the python shell but Im facing the > problem.Please do help me > You need to post/screen-capture the whole error message/traceback. From vek.m1234 at gmail.com Fri Jul 1 23:46:49 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Sat, 02 Jul 2016 09:16:49 +0530 Subject: problem using pickle References: Message-ID: Nicky Mac wrote: > Dear Python team, > I have studied the excellent documentation, and attempted to make use > of pickle thus: > > filename = 'my_saved_adventure' > import pickle > class object: > def __init__(self,i,.........t) : > self.id = i > ..... > > class world: > def __init__(self): > self.object > > class object: > def __init__(self,i, > > .....then Object instances of object are created ........ > > myworld = world; > myworld.Object = Object > fileobj = open(filename,'wb') > pickle.dump(myworld,fileobj); fileobj.close() > result = "saved your game to " + filename > > fileobj = open(filename,'rb') > myworld = pickle.load(fileobj); fileobj.close() > Object = myworld.Object > result = "restored your game from " + filename > > > The proecedures execute without error > but a file of only 21b is created containing " ?c__main__world q . > altho there are several k of object instance data. > class Foo(object): pass object is a keyword and you're using it as an identifier From rustompmody at gmail.com Sat Jul 2 00:05:24 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 1 Jul 2016 21:05:24 -0700 (PDT) Subject: problem using pickle In-Reply-To: References: Message-ID: <7e4ba6e5-eb3f-4c07-8c3a-6c3c24991ca0@googlegroups.com> On Saturday, July 2, 2016 at 9:17:01 AM UTC+5:30, Veek. M wrote: > object is a keyword and you're using it as an identifier keyword and builtin are different In this case though the advice remains the same In general maybe not... Just sayin' From vek.m1234 at gmail.com Sat Jul 2 00:27:41 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Sat, 02 Jul 2016 09:57:41 +0530 Subject: Descriptor: class name precedence over instance name Message-ID: Trying to make sense of this para: -------------------------------------------------- Also, the attribute name used by the class to hold a descriptor takes prece- dence over attributes stored on instances. In the previous example, this is why the descriptor object takes a name parameter and why the name is changed slightly by inserting a leading underscore. In order for the descriptor to store a value on the instance, it has to pick a name that is different than that being used by the descriptor itself --------------------------------------------- Under normal circumstances, when I do an attribute lookup: x = Foo() x.a he will first check 'x' then Foo. Is he say that Descriptors are a special case where Foo is checked first, then what - Base classes..? or does he hop back to look in the instance? How is C3 Linearization altered? Additionally, class Foo: def __init__(self, name, value): self.name = name cannot be done because x = Foo('bar', 10) x.bar will..? attribute in class takes precedence.. great, isn't that what we want? From ben+python at benfinney.id.au Sat Jul 2 00:29:22 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 02 Jul 2016 14:29:22 +1000 Subject: problem using pickle References: Message-ID: <85wpl4u0gt.fsf@benfinney.id.au> "Veek. M" writes: > class Foo(object): > pass > > object is a keyword and you're using it as an identifier Python does not have ?object? as a keyword. ?and? is a keyword. Here's the difference:: >>> object >>> object = "Lorem ipsum" >>> object 'Lorem ipsum' >>> and File "", line 1 and ^ SyntaxError: invalid syntax >>> and = "Lorem ipsum" File "", line 1 and = "Lorem ipsum" ^ SyntaxError: invalid syntax Here is how you can test whether a word is a Python keyword:: >>> import keyword >>> keyword.iskeyword('object') False >>> keyword.iskeyword('and') True The set of keywords in Python is quite small. >>> len(keyword.kwlist) 33 -- \ ?The best in us does not require the worst in us: Our love of | `\ other human beings does not need to be nurtured by delusion.? | _o__) ?Sam Harris, at _Beyond Belief 2006_ | Ben Finney From ian.g.kelly at gmail.com Sat Jul 2 00:51:08 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 1 Jul 2016 22:51:08 -0600 Subject: Descriptor: class name precedence over instance name In-Reply-To: References: Message-ID: On Fri, Jul 1, 2016 at 10:27 PM, Veek. M wrote: > Trying to make sense of this para: > > -------------------------------------------------- > Also, the attribute name used by the class to hold a descriptor takes > prece- dence over attributes stored on instances. > > In the previous example, > this is why the descriptor object takes a name parameter and why the > name is changed slightly by inserting a leading underscore. In order > for the descriptor to store a value on the instance, it has to pick a > name that is different than that being used by the descriptor itself > --------------------------------------------- > Under normal circumstances, when I do an attribute lookup: > x = Foo() > x.a > he will first check 'x' then Foo. > > Is he say that Descriptors are a special case where Foo is checked > first, It depends whether it's a "data descriptor" or not. A data descriptor is one that defines at least one of __set__ or __delete__, not just __get__. Data descriptors take precendence over instance attributes. Instance attributes take precedence over non-data descriptors. > then what - Base classes..? Checking base classes is part of checking the class. If a base class has a data descriptor, that will likewise take precedence over the instance attribute, which will likewise take precedence over non-data descriptors in the base class. > or does he hop back to look in the > instance? How is C3 Linearization altered? It's not. > Additionally, > class Foo: > def __init__(self, name, value): > self.name = name > > cannot be done because > x = Foo('bar', 10) > > x.bar will..? attribute in class takes precedence.. great, isn't that > what we want? I don't understand what you're asking here or what this example has to do with descriptors. From ben+python at benfinney.id.au Sat Jul 2 00:52:34 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 02 Jul 2016 14:52:34 +1000 Subject: Descriptor: class name precedence over instance name References: Message-ID: <85shvstze5.fsf@benfinney.id.au> "Veek. M" writes: > Trying to make sense of this para: At the risk of being ruse, I am trying to make sense of some paragraphs in the messages you write here. Could you take a little more time to write clearly, as a way of communicating in this forum? > Is he say that Descriptors are a special case where Foo is checked > first, then what - Base classes..? or does he hop back to look in the > instance? How is C3 Linearization altered? I really have no idea what this paragraph means. Can you please write again assuming we don't know already what you are trying to say? -- \ ?[I]t is impossible for anyone to begin to learn that which he | `\ thinks he already knows.? ?Epictetus, _Discourses_ | _o__) | Ben Finney From JBailey at emerytelcom.com Sat Jul 2 00:54:14 2016 From: JBailey at emerytelcom.com (Jason Bailey) Date: Sat, 2 Jul 2016 04:54:14 +0000 Subject: View committed code via gitpython Message-ID: Hi all, I'm trying to essentially replicate "gift grep" functionality with gitpython and am not quite sure how to pull the committed code from the repo using gitpython. I am successfully listing all the commits, so now all I need to do is view the code in each commit to do some regex matching on it. Anyone savvy with this module that could steer me in the right direction??? Thanks Jason From random832 at fastmail.com Sat Jul 2 00:59:53 2016 From: random832 at fastmail.com (Random832) Date: Sat, 02 Jul 2016 00:59:53 -0400 Subject: Namespaces are one honking great idea In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> On Fri, Jul 1, 2016, at 21:50, Kevin Conway wrote: > I believe the namespace object you are referring to is exactly a > class. IIRC, classes came about as a "module in a module". No, because classes have instances. And conceptually they seem like they *should* have instances. Just using the term "class" carries expectations. More to the point, what modules do that classes do not is provide a global namespace for functions defined within them, so that variables within them can be used (well, read - writing them requires a declaration) by the functions without extra qualification. > Regardless, all use cases you've listed are already satisfied by use > of the static and class method decorators. Methods decorated with > these do not require an instance initialization to use. staticmethod isn't technically required to use a method through the class (or subclasses), it simply provides the appropriate magic to allow it to be called through instances. From JBailey at emerytelcom.com Sat Jul 2 01:04:31 2016 From: JBailey at emerytelcom.com (Jason Bailey) Date: Sat, 2 Jul 2016 05:04:31 +0000 Subject: View committed code via gitpython Message-ID: <8CA2692E-0B46-4F10-A692-F1584C6A0FB5@emerytelcom.com> Hi all, I'm trying to essentially replicate "gift grep" functionality with gitpython and am not quite sure how to pull the committed code from the repo using gitpython. I am successfully listing all the commits, so now all I need to do is view the code in each commit to do some regex matching on it. Anyone savvy with this module that could steer me in the right direction??? Thanks Jason From ian.g.kelly at gmail.com Sat Jul 2 01:09:10 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 1 Jul 2016 23:09:10 -0600 Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> Message-ID: On Fri, Jul 1, 2016 at 4:08 PM, Lawrence D?Oliveiro wrote: > On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: >> There is a clever one-line decorator that has been copy-pasted without >> explanation in many code bases for many years:: >> >> decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda func: decorator(func, *args, **kwargs) >> > > For those who want docstrings, I?ll give you docstrings: > > def decorator_with_args(decorator) : > "given function decorator(func, *args, **kwargs), returns a decorator which," \ > " given func, returns the result of decorator(func, *args, **kwargs)." > > def decorate(*args, **kwargs) : > > def generated_decorator(func) : > return \ > decorator(func, *args, **kwargs) > #end generated_decorator > > #begin decorate > generated_decorator.__name__ = "decorator_{}".format(decorator.__name__) > generated_decorator.__doc__ = "decorator which applies {} to the previously-specified arguments".format(decorator.__name__) > return \ > generated_decorator > #end decorate > > #begin decorator_with_args > decorate.__name__ = "decorate_with_{}".format(decorator.__name__) > decorate.__doc__ = "generates a decorator which applies {} to the given arguments".format(decorator.__name__) You should use functools.wraps instead of clobbering the decorated function's name and docstring: @functools.wraps(decorator) def decorate(*args, **kwargs): ... > return \ > decorate Just to satisfy my own curiosity, do you have something against putting the return keyword and the returned expression on the same line? From ben+python at benfinney.id.au Sat Jul 2 01:32:12 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 02 Jul 2016 15:32:12 +1000 Subject: Meta decorator with parameters, defined in explicit functions References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> Message-ID: <85oa6gtxk3.fsf@benfinney.id.au> Ian Kelly writes: > You should use functools.wraps instead of clobbering the decorated > function's name and docstring: > > @functools.wraps(decorator) > def decorate(*args, **kwargs): > ... Thanks. Can you write the full implementation with that, so I can be sure of where you expect that to go? -- \ ?I knew things were changing when my Fraternity Brothers threw | `\ a guy out of the house for mocking me because I'm gay.? | _o__) ?postsecret.com, 2010-01-19 | Ben Finney From ian.g.kelly at gmail.com Sat Jul 2 01:53:15 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 1 Jul 2016 23:53:15 -0600 Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: <85oa6gtxk3.fsf@benfinney.id.au> References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <85oa6gtxk3.fsf@benfinney.id.au> Message-ID: On Fri, Jul 1, 2016 at 11:32 PM, Ben Finney wrote: > Ian Kelly writes: > >> You should use functools.wraps instead of clobbering the decorated >> function's name and docstring: >> >> @functools.wraps(decorator) >> def decorate(*args, **kwargs): >> ... > > Thanks. Can you write the full implementation with that, so I can be > sure of where you expect that to go? def decorator_with_args(decorator): """Given function decorator(func, *args, **kwargs), returns a wrapper that accepts args and kwargs separately from func. """ @functools.wraps(decorator) def apply(*args, **kwargs): # inner_decorator is transient, so its name and docstring # are unimportant. def inner_decorator(func): return decorator(func, *args, **kwargs) return inner_decorator return apply From auriocus at gmx.de Sat Jul 2 02:30:26 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 2 Jul 2016 08:30:26 +0200 Subject: Controlling the Mac OSX GUI via Python? In-Reply-To: References: <68044aa3-8a3c-47cd-b6d0-aaa0e3f1fc62@googlegroups.com> <09315fbb-05b1-4c4e-a6f7-7cfda79a1286@googlegroups.com> <7d144305-e228-4241-90d6-86677ef713b7@googlegroups.com> Message-ID: Am 02.07.16 um 05:16 schrieb Lawrence D?Oliveiro: > On Friday, July 1, 2016 at 4:59:11 PM UTC+12, Christian Gollwitzer wrote: >> Yes, simulating mouse clicks with >> fixed coordinates etc. is prone to such failure, but there are better >> methods. These mouse clicks and keyboard events usually trigger a method >> call inside the GUI program. If there are any means to call that method >> directly, you are independent from the graphics itself. > > Even if you could get it working reliably, scripting a GUI is going to be slow. > > GUIs are only designed to work at human speeds, after all. > It might be slow, but look at his request in the OP "automatically arranging windows, periodically refreshing applications across multiple desktops". A button which arranges three programs in a row could be useful for some users. Or an automatic reload of a status website inside the browser, where you can't change the website to embed autorefresh code. I've got a tool running which can remap special keys (ctrl, fn) to ordinary chars. Also sometimes a complex functionality is buried in a GUI. Consider a server converting MS Word files into PDF. The only method which reliably works is COM to drive MS Office, yes it's clumsy, but unless you persuade MS to release Office as a Python library you have no other option. Speed is not of any concern here. If execution speed would be important, why use Python at all? Christian From lawrencedo99 at gmail.com Sat Jul 2 02:40:02 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 1 Jul 2016 23:40:02 -0700 (PDT) Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> Message-ID: On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: > You should use functools.wraps instead of clobbering the decorated > function's name and docstring: Where am I doing that? > Just to satisfy my own curiosity, do you have something against > putting the return keyword and the returned expression on the same > line? Yes. From dieter at handshake.de Sat Jul 2 02:57:09 2016 From: dieter at handshake.de (dieter) Date: Sat, 02 Jul 2016 08:57:09 +0200 Subject: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions References: <85mvm5vrbw.fsf@benfinney.id.au> <0690f476-95ad-4dec-87e5-42ecee07fdcd@googlegroups.com> <87poqx96ul.fsf@handshake.de> <87bn2h85rn.fsf@bsb.me.uk> <8537nsvmbc.fsf@benfinney.id.au> Message-ID: <87fursil2y.fsf@handshake.de> Ben Finney writes: > ... > Rather, the motivation was that a complex thing, with many moving parts, > has an unexplained implementation: a nested set of functions without > names to explain their part in the pattern. In a previous reply, I have tried to explain (apparently without success) that the "thing" is not "complex" at all but a simple signature transform for a decorator definitition and that the nested function implementation is natural for this purpose. From dieter at handshake.de Sat Jul 2 03:30:12 2016 From: dieter at handshake.de (dieter) Date: Sat, 02 Jul 2016 09:30:12 +0200 Subject: super and mix-in class: how exactly is the search order altered? References: Message-ID: <87bn2gijjv.fsf@handshake.de> "Veek. M" writes: > ... > I'm reading this article: > https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ > > He's trying to explain the purpose of a 'mix-in class' and he says > > We did not alter the source code for LoggingDict. Instead we built a > subclass whose only logic is to compose two existing classes and control > their search order. > > class LoggingOD(LoggingDict, collections.OrderedDict): > pass > > My question is this: in the above article context, is he talking about > the LoggingDict's search order that is being manipulated? Or he is > talking about manipulating the LoggingOD search order? Likely, his language has been a bit sloppy. Likely, his setup is as follows: * He has an existing class ("collections.OrderDict") which the base functionality he needs * He has an additional requirement (over that of "collections.OrderDict") -- logging modifications * He wants to implement his requirements (the base ones and the the additional one) without modifying the existing class in any way * His idea to implement the additional requirement is to define a derived class ("LoggingOD") and lets its modifying methods perform the logging and then call the corresponding methods of the base class. * He recognizes that this logging feature might be interesting not only for "collections.OrderDict" but also for other dictionary like base classes. Therefore, instead of implementing it directly in "LoggingOD", he implements it in the mixin class "LoggingDict". * Because "LoggingDict" was explicitely designed to be used as mixin class to enhance a base class, it knows that some methods ("__setitem__") of the base class need to be called in its own implementation of the corresponding method. * The integrator (the one combining "LoggingDict" with the base class) must ensure (by an appropriate inheritance order) that the combining class ("LoggingOD" in the example) calls the "LoggingDict"'s methods (which know about that of the base class) rather than the base class's methods (which do not know about the mixin class's methods). Therefore, he uses the inheritance order "LoggingDict" followed by the base class (and not vice versa). Python clearly defines in what order attributes of an object and of the construct "super(,)" are looked up. The essential concept is the so called "MRO" ("method resolution order") (in fact, it is an attribute resolution order). In simple cases (no common base classes), the MRO of a definition "class C(B_1, ..., B_n): ..." is defined by a left to right lookup: i.e. first in "C", then "B_1", then "B_2", ... The rules are a bit more complicated when the "B_i" have a (or more) common base classes. From dieter at handshake.de Sat Jul 2 03:37:07 2016 From: dieter at handshake.de (dieter) Date: Sat, 02 Jul 2016 09:37:07 +0200 Subject: JAR files into python References: Message-ID: <877fd4ij8c.fsf@handshake.de> Joaquin Alzola writes: > ... > The error that it throws is the following one (which is logical because I do not load the jar files): > py4j.protocol.Py4JJavaError: An error occurred while calling o29.load. > : java.lang.ClassNotFoundException: Failed to find data source: org.apache.spark.sql.cassandra. Please find packages at http://spark-packages.org > > Is there a way to load those jar files into python or the classpath when calling sqlContext.read.format("org.apache.spark.sql.cassandra")? Apparently, you are using a Python-Java bridge (looks like "pyspark" is such a thing). I expect that such a bridge provides ways to make JAR files known to the activated Java runtime. Consult its documentation. From ben+python at benfinney.id.au Sat Jul 2 04:00:47 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 02 Jul 2016 18:00:47 +1000 Subject: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions References: <85mvm5vrbw.fsf@benfinney.id.au> <0690f476-95ad-4dec-87e5-42ecee07fdcd@googlegroups.com> <87poqx96ul.fsf@handshake.de> <87bn2h85rn.fsf@bsb.me.uk> <8537nsvmbc.fsf@benfinney.id.au> <87fursil2y.fsf@handshake.de> Message-ID: <85mvm0wjtc.fsf@benfinney.id.au> dieter writes: > Ben Finney writes: > > ... Rather, the motivation was that a complex thing, with many > > moving parts, has an unexplained implementation: a nested set of > > functions without names to explain their part in the pattern. > > In a previous reply, I have tried to explain (apparently without > success) that the "thing" is not "complex" at all Your explanation was clear. I disagree with it; the code is not at all obvious in its intention or operation. Naming the parts descriptively, and writing a brief synopsis docstring for each function, is a way to address that. Which is my motivation for this thread. > but a simple signature transform for a decorator definitition You're making my case for me: To anyone who doesn't already know exactly what's going on, that is not at all obvious from the code as presented in the first message. > and that the nested function implementation is natural for this > purpose. The nested function implementation is not the problem, as I hope I've made clear elsewhere in this thread. -- \ ?People's Front To Reunite Gondwanaland: Stop the Laurasian | `\ Separatist Movement!? ?wiredog, http://kuro5hin.org/ | _o__) | Ben Finney From vek.m1234 at gmail.com Sat Jul 2 05:34:46 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Sat, 02 Jul 2016 15:04:46 +0530 Subject: Descriptor: class name precedence over instance name References: <85shvstze5.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > "Veek. M" writes: > >> Trying to make sense of this para: > > At the risk of being ruse, I am trying to make sense of some > paragraphs in the messages you write here. Could you take a little > more time to write clearly, as a way of communicating in this forum? > >> Is he say that Descriptors are a special case where Foo is checked >> first, then what - Base classes..? or does he hop back to look in the >> instance? How is C3 Linearization altered? > > I really have no idea what this paragraph means. Can you please write > again assuming we don't know already what you are trying to say? > Sorry about that, I found it hard to read too (when I came back to it). I was trying to figure out the order in which attributes are looked up. Beazley's a great book, but sometimes he kills me and mounts my head on a pike - page 127 - Descriptors section, last para. He says that descriptor-attribute-names in a class, take precedence in a attribute lookup wrt instance attributes. When you do an x.a, python goes on a hunt for 'a' - the whole binding idea; typically, that is, Instance Name Space -> Class NS -> BaseClasses (C3 Linearization algorithm) Therefore, I was wondering how he could start the search at the instance-Class, instead of the instance. When you print __mro__ you get a list of classes that are traversed but there's no explicit mention within the __mro__ that the instance is searched first. So I wanted to know if there was any implications to C3/__mro__ So essentially from what Ian said: data_descriptor_in_instance -> instance_attribute -> non- data_descriptor_in_instance -->__mro__ is how the search takes place. Correct? ------------------------------ Regarding part2 of the Q, :) Ian hasn't explained it, so I'm not sure how to explain it better :) but i'll try given that he has clarified part of the answer. Basically Beazley has a TypedProperty descriptor class, and in class Foo he instantiates: name = TypedProperty Then he does f = Foo() Thanks to Ian, we now know that any lookup on 'f' eg: f.name would cause.. well.. the f.name(TypedProperty-descriptor) to gain precedence thus hiding the f.name attribute! Therefore he needs to name-decorate or in this example append an '_' for whatever stupid reason. I think i've got the jist down pat so :p Here's the image: http://storage1.static.itmages.com/i/16/0702/h_1467451175_7972040_b5037f6b46.png (thanks Ian) From nulla.epistola at web.de Sat Jul 2 06:08:33 2016 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sat, 2 Jul 2016 12:08:33 +0200 Subject: Getting back into PyQt and not loving it. In-Reply-To: <473ee4eb-0d1c-4864-ad44-b9c1928e2267@googlegroups.com> References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> <473ee4eb-0d1c-4864-ad44-b9c1928e2267@googlegroups.com> Message-ID: Am 27.06.2016 um 22:14 schrieb codewizard at gmail.com: > On Sunday, June 26, 2016 at 5:45:18 PM UTC-4, Michael Torrie wrote: >> >> Qt's a fantastic toolkit, and the most mature of any of them, and the >> most portable, but man the bindings are not Pythonic at all. > > Enaml feels pretty Pythonic to me: > > https://github.com/nucleic/enaml > But: Enaml is a Python framework and requires a supported Python runtime. Enaml currently supports Python 2.6 and Python 2.7. Python 3.x support may be added in the future, but is not currently a high priority item. http://nucleic.github.io/enaml/docs/get_started/installation.html From nulla.epistola at web.de Sat Jul 2 06:08:33 2016 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sat, 2 Jul 2016 12:08:33 +0200 Subject: Getting back into PyQt and not loving it. In-Reply-To: <473ee4eb-0d1c-4864-ad44-b9c1928e2267@googlegroups.com> References: <7583145f-fa2a-6846-3cd9-9814c7006fdd@gmail.com> <473ee4eb-0d1c-4864-ad44-b9c1928e2267@googlegroups.com> Message-ID: Am 27.06.2016 um 22:14 schrieb codewizard at gmail.com: > On Sunday, June 26, 2016 at 5:45:18 PM UTC-4, Michael Torrie wrote: >> >> Qt's a fantastic toolkit, and the most mature of any of them, and the >> most portable, but man the bindings are not Pythonic at all. > > Enaml feels pretty Pythonic to me: > > https://github.com/nucleic/enaml > But: Enaml is a Python framework and requires a supported Python runtime. Enaml currently supports Python 2.6 and Python 2.7. Python 3.x support may be added in the future, but is not currently a high priority item. http://nucleic.github.io/enaml/docs/get_started/installation.html From ankush.thakur53 at gmail.com Sat Jul 2 07:27:49 2016 From: ankush.thakur53 at gmail.com (Ankush Thakur) Date: Sat, 2 Jul 2016 04:27:49 -0700 (PDT) Subject: Lost in descriptor land In-Reply-To: References: Message-ID: On Friday, July 1, 2016 at 7:07:09 AM UTC+5:30, Ian wrote: > First of all, do you understand what descriptors are? This is a fairly > advanced Python concept. For a general tutorial, I would point you to > https://docs.python.org/3/howto/descriptor.html I understand what descriptors try to accomplish, but that link is pretty scary! :P I found your explanation to be much better. The other tutorials would simply ignore "owner", offer no explanation, and provide complete working programs -- this made me go crazy! > The owner argument is the class that this Celsius instance is a > descriptor of. Normally that is just type(instance); however it is > possible to invoke the __get__ method on the class object itself > rather than on an instance, in which case owner is (still) the class > object but instance is None. This is the golden explanation I will always be thankful for! :) > It's not clear to me what alternative you're proposing. The reason > celsius is declared on the class is because it's a descriptor, and > descriptors implement properties of classes. Setting an instance > attribute to a descriptor won't accomplish anything. The alternative I'm proposing is indeed what you said: Make `celcius` a per-object attribute and set it up in __init__(). Why will it not accomplish the same thing as setting it on a class-level? Please bear with me a little more and explain. :P From ankush.thakur53 at gmail.com Sat Jul 2 07:30:50 2016 From: ankush.thakur53 at gmail.com (Ankush Thakur) Date: Sat, 2 Jul 2016 04:30:50 -0700 (PDT) Subject: Lost in descriptor land In-Reply-To: <3deac09a-3bfb-45d2-bce3-eb269c6b7d90@googlegroups.com> References: <3deac09a-3bfb-45d2-bce3-eb269c6b7d90@googlegroups.com> Message-ID: <025d6263-0f27-4d9c-80ba-5b42efc666be@googlegroups.com> On Friday, July 1, 2016 at 9:03:44 AM UTC+5:30, Lawrence D?Oliveiro wrote: > Every time I feel unsure, I go back to the horse?s mouth: here is GvR himself with all the details on ?new-style? classes, including the clearest explanation I have come across about descriptors. Well, that's certainly a very interesting link (and blog!) but my current priority is to just understand this damn thing! :D From ankush.thakur53 at gmail.com Sat Jul 2 07:32:22 2016 From: ankush.thakur53 at gmail.com (Ankush Thakur) Date: Sat, 2 Jul 2016 04:32:22 -0700 (PDT) Subject: Lost in descriptor land In-Reply-To: <5a7b6360-5b9b-465c-8401-9a0079048931@googlegroups.com> References: <5a7b6360-5b9b-465c-8401-9a0079048931@googlegroups.com> Message-ID: <7b72a3a0-f0c0-429a-b383-5c3dbfdedba5@googlegroups.com> On Friday, July 1, 2016 at 9:13:19 AM UTC+5:30, Lawrence D?Oliveiro wrote: > > > Shouldn't we be instead using self.celcius in, say, __init__() and then > > everything will work fine? > > I guess it might. But this way, using descriptors, all the setup is done once at class definition, rather then every time in class instantiation. So you're saying the (sole) reason to instantiate descriptor classes at class-level is performance? From jonas at wielicki.name Sat Jul 2 09:42:51 2016 From: jonas at wielicki.name (Jonas Wielicki) Date: Sat, 02 Jul 2016 15:42:51 +0200 Subject: [ANN] aioxmpp 0.6 released Message-ID: <3547150.NSfJzjJVcu@sinistra> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 Dear subscribers, I am pleased to announce the release of aioxmpp 0.6. The current release can be obtained from GitHub [1] (check out the v0.6.0 tag or the master branch) or PyPI [2]. The HTML documentation can be found at [3]. Examples can be found in the GitHub repository, in the examples subdirectory. aioxmpp is a Python library based on asyncio. It implements the client side of the XMPP protocol (RFC 6120 and others). For a more detailed description of the package, please review the README of the package on GitHub [1] or on PyPI [2]. For more information on XMPP, please see [10]. It is licensed under the terms of the General Public License Version 3.0. Highlights of this release include partial Publish/Subscribe support [XEP-0060], several bugfixes in the existing Multi-User-Chat implementation [XEP-0045], increased robustness against broken servers and clients, as well as support for XMPP-over-TLS (in addition to the existing STARTTLS support) [XEP-0368]. Also to mention are the two new dependencies, multidict [4] and optionally aioopenssl [5]. The latter has been extracted from aioxmpp by request of a user. aioxmpp however ships with its own version of aioopenssl which it uses when aioopenssl is not installed. Bugs, feature requests, patches and questions can be directed to either the aioxmpp mailing list [6], the GitHub issue tracker [7] or the XMPP Multi-User chat [8], whatever floats your boat. Please direct security-relevant issue reports directly to me (jonas at wielicki.name), preferrably encrypted using my GPG public key [9]. best regards and happy-asyncio-ing, Jonas Wielicki [1]: https://github.com/horazont/aioxmpp [2]: https://pypi.python.org/pypi/aioxmpp [3]: https://docs.zombofant.net/aioxmpp/0.6/ [4]: https://github.com/aio-libs/multidict/ [5]: https://github.com/horazont/aioopenssl [6]: https://lists.zombofant.net/mailman/listinfo/aioxmpp-devel [7]: https://github.com/horazont/aioxmpp/issues [8]: aioxmpp at conference.zombofant.net [9]: https://sks-keyservers.net/pks/lookup?op=get&search=0xE5EDE5AC679E300F AA5A 78FF 508D 8CF4 F355 F682 E5ED E5AC 679E 300F [10]: https://xmpp.org/ [XEP-0045]: https://xmpp.org/extensions/xep-0045.html [XEP-0060]: https://xmpp.org/extensions/xep-0060.html [XEP-0368]: https://xmpp.org/extensions/xep-0368.html -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCgAGBQJXd8TbAAoJEMBiAyWXYliKUnoP/0mEvfNrk+kL9scljIKyjSHF 47gkQBgvNMPAEUMSi5UVMkXworeVDKEpCB+P3kE4Z7XsRLxFgFSUGywYN7WL0w/s rpiUnJrOzPrsKiqmPTu2eOGDeuKNCz/ZSZqyl1Ic8Mj42cS9DjGh+PUwEpWBnskS Dg4onj4clWpDsZGizR8YXkFkc8rmsUhHwvqQt29tOZ89qQnmOY4pCKyoTbxYLQKv UerfiNG4AWFFuyetZJFUORdVhWEgFvivqJuES5g7NijgRmEOZV8tcYj0YAtggEP0 GQX5mE/KqHzHErR1/AAVnv2hXlqBBxc3diSXT6k+95wLkXz0n2YmPFCFPSl235Ru uiUiW0xbQqJgjJ+B20NsuIMd+t1M/lnDw4cZgLkMUCsl6gsZEhL0mUf5iK9UDCH9 HbXsoMuz71t+Z8XN8GnibxDFPvCBERNqvIU+onjt63rT/yB/i/7XTbS4zQExCGhF z4qVF8dY2q+d4EsIvd1dxLkP7dRFW7VK1FxiuutS5OTNEBsocROaXPDOjRyzdXGx mSH3P/IuXxEil9kKHkXNZRQwSgl6J4PvAeySn58d3bpmHi8hu2J83ZoeFLdxHMoe qOhkBB/v4QRbEgjXIqF8OmtGtNO9hXlM7EN6ouc9pvCJ1XGnBU9Z9FX4AkQMQUu/ AfDKZ8VFptxvQh1dtCD1 =ir6C -----END PGP SIGNATURE----- From ian.g.kelly at gmail.com Sat Jul 2 09:55:02 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 2 Jul 2016 07:55:02 -0600 Subject: Descriptor: class name precedence over instance name In-Reply-To: References: <85shvstze5.fsf@benfinney.id.au> Message-ID: On Sat, Jul 2, 2016 at 3:34 AM, Veek. M wrote: > So essentially from what Ian said: > data_descriptor_in_instance -> instance_attribute -> non- > data_descriptor_in_instance -->__mro__ > > is how the search takes place. Correct? Close, but I would write it as: data_descriptor_in_class_including_mro -> instance_attribute -> non_data_descriptor_or_class_attribute_including_mro In either case the class dict search is in __mro__ order. You can find the actual implementation here: https://hg.python.org/cpython/file/30099abdb3a4/Objects/object.c#l1326 Roughly, the algorithm is this: tp = type(obj) # This call searches the MRO. descr = _PyType_Lookup(tp, name) if descr != NULL and is_data_descriptor(descr): return descr.__get__(obj, tp) if name in obj.__dict__: return obj.__dict__[name] if descr != NULL and is_non_data_descriptor(descr): return descr.__get__(obj, tp) if descr != NULL: return descr raise AttributeError(name) > ------------------------------ > > Regarding part2 of the Q, :) Ian hasn't explained it, so I'm not sure > how to explain it better :) but i'll try given that he has clarified > part of the answer. > > Basically Beazley has a TypedProperty descriptor class, and in class Foo > he instantiates: > name = TypedProperty > Then he does f = Foo() > > Thanks to Ian, we now know that any lookup on 'f' eg: f.name would Not *any* lookup, only one for which there is a declared descriptor. So in this example f.name or f.num would resolve according to the descriptor's __get__ method, but any other attribute lookup would just return whatever value is set on the instance (if any). > cause.. well.. the f.name(TypedProperty-descriptor) to gain precedence > thus hiding the f.name attribute! Therefore he needs to name-decorate or > in this example append an '_' for whatever stupid reason. Right, if the "name" descriptor tried to store the value in the unmangled "name" instance attribute, then its getattr call would just recur back to the descriptor and you'd have an infinite loop. In my opinion the mangling should be a bit heavier than what's done in this example, to avoid collisions between the descriptor and the class that's using it. I like to follow the pattern of __foo name mangling, so I would have instead used: self.name = "_TypedProperty__" + name From stefan_ml at behnel.de Sat Jul 2 10:03:56 2016 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 2 Jul 2016 16:03:56 +0200 Subject: Which one is the best XML-parser? In-Reply-To: <1466773773.502497.647387441.16AAD74F@webmail.messagingengine.com> References: <1312978293.949108.1466715441953.JavaMail.yahoo.ref@mail.yahoo.com> <1312978293.949108.1466715441953.JavaMail.yahoo@mail.yahoo.com> <87r3bnrsy4.fsf@handshake.de> <1466773773.502497.647387441.16AAD74F@webmail.messagingengine.com> Message-ID: Random832 schrieb am 24.06.2016 um 15:09: > On Fri, Jun 24, 2016, at 02:39, dieter wrote: >> You want an incremental parser if the XML documents are so huge that >> you must process them incrementally rather than have a data structure >> representing the whole document (in memory). Incremental parsers >> for XML are usually called "SAX" parsers. > > You know what would be really nice? A "semi-incremental" parser that can > e.g. yield (whether through an event or through the iterator protocol) a > fully formed element (preferably one that can be queried with xpath) at > a time for each record of a document representing a list of objects. > Does anything like that exist? http://lxml.de/parsing.html#incremental-event-parsing https://docs.python.org/3/library/xml.etree.elementtree.html#pull-api-for-non-blocking-parsing Stefan From kevinjacobconway at gmail.com Sat Jul 2 11:34:08 2016 From: kevinjacobconway at gmail.com (Kevin Conway) Date: Sat, 02 Jul 2016 15:34:08 +0000 Subject: Namespaces are one honking great idea In-Reply-To: <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> Message-ID: > staticmethod isn't technically required to use a method through the class (or subclasses), it simply provides the appropriate magic to allow it to be called through instances. For example, the following code covers all described use cases of the proposed namespace. Methods are invoked without creating instances and state is managed on the class object directly. class CustomNs: stateful_data = 1 @staticmethod def echo(text): print(text) @classmethod def mutate(cls): cls.stateful_data += 1 print(cls.stateful_data) CustomNs.echo("test") print(CustomNs.stateful_data) CustomNs.mutate() print(CustomNs.stateful_data) For the proponents of namespace, what is deficient in the above example that necessitates a language change? On Sat, Jul 2, 2016, 00:02 Random832 wrote: > On Fri, Jul 1, 2016, at 21:50, Kevin Conway wrote: > > I believe the namespace object you are referring to is exactly a > > class. IIRC, classes came about as a "module in a module". > > No, because classes have instances. And conceptually they seem like they > *should* have instances. Just using the term "class" carries > expectations. > > More to the point, what modules do that classes do not is provide a > global namespace for functions defined within them, so that variables > within them can be used (well, read - writing them requires a > declaration) by the functions without extra qualification. > > > Regardless, all use cases you've listed are already satisfied by use > > of the static and class method decorators. Methods decorated with > > these do not require an instance initialization to use. > > staticmethod isn't technically required to use a method through the > class (or subclasses), it simply provides the appropriate magic to allow > it to be called through instances. > -- > https://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Sat Jul 2 15:29:11 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 2 Jul 2016 15:29:11 -0400 Subject: subprocess startup error In-Reply-To: References: Message-ID: On 7/1/2016 11:43 PM, Veek. M wrote: > Shweta Dinnimani wrote: > >> hi >> >> hello, I'm begineer to python programming.. I had installed python >> 3.5.1 version on my windows 7 system. I was fine earlier and now when >> i was trying the programs on string i'm facing the subprocess startup >> error. IDLE is not connecting. And python shell is also not opening. I >> tried uninstalling and installing the python shell but Im facing the >> problem.Please do help me In my answer to https://stackoverflow.com/questions/37997715/idles-subprocess-didnt-make-a-connection-either-idle-cant-start-or-personal/38001829#38001829 I list all the possible reasons I know of. A file of yours with the same name as a stdlib file is at least as common reason as antivirus/firewall software. > You need to post/screen-capture the whole error message/traceback. If you start IDLE from Command Prompt with 'python -m idlelib', you might get more information. -- Terry Jan Reedy From craigwahawick7 at gmail.com Sat Jul 2 17:13:16 2016 From: craigwahawick7 at gmail.com (CHM Lyrics) Date: Sat, 2 Jul 2016 14:13:16 -0700 (PDT) Subject: Starting Out and Need Help with Basics. Message-ID: <18f1fc40-e6f5-4bfe-8601-746c7b826c66@googlegroups.com> I am in fifth year at secondary school (senior years in high school). We've been doing basic programs in Python at school, but we're now on a 6 week holiday (Summer Holidays). So I decided I would try and download Python and learn a bit more while I'm not doing anything. I have now downloaded it, however, I have immediately noticed something. For example, what I know is, is that if you were to type: print "Welcome to Python!" And nothing else, it would ask you to save the program, which I'd do, but then it just says there's an invalid syntax. I've tried adding a colon after 'print' and I've tried adding brackets around "Welcome to Python!". But nothing is working, can someone give me a hand please. From matej123cekk at gmail.com Sat Jul 2 17:14:33 2016 From: matej123cekk at gmail.com (matej123cekk at gmail.com) Date: Sat, 2 Jul 2016 14:14:33 -0700 (PDT) Subject: subprocess startup error In-Reply-To: References: Message-ID: try to download pywin (i think that pywin will working ok) url to download https://sourceforge.net/projects/pywin32/files/pywin32/ From rosuav at gmail.com Sat Jul 2 17:17:26 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jul 2016 07:17:26 +1000 Subject: Starting Out and Need Help with Basics. In-Reply-To: <18f1fc40-e6f5-4bfe-8601-746c7b826c66@googlegroups.com> References: <18f1fc40-e6f5-4bfe-8601-746c7b826c66@googlegroups.com> Message-ID: On Sun, Jul 3, 2016 at 7:13 AM, CHM Lyrics wrote: > I am in fifth year at secondary school (senior years in high school). We've been doing basic programs in Python at school, but we're now on a 6 week holiday (Summer Holidays). So I decided I would try and download Python and learn a bit more while I'm not doing anything. I have now downloaded it, however, I have immediately noticed something. > > For example, what I know is, is that if you were to type: > print "Welcome to Python!" > And nothing else, it would ask you to save the program, which I'd do, but then it just says there's an invalid syntax. I've tried adding a colon after 'print' and I've tried adding brackets around "Welcome to Python!". But nothing is working, can someone give me a hand please. > Did you use the right brackets? It should look like this: print("Welcome to Python!") ChrisA From ian.g.kelly at gmail.com Sat Jul 2 19:06:47 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 2 Jul 2016 17:06:47 -0600 Subject: Lost in descriptor land In-Reply-To: <7b72a3a0-f0c0-429a-b383-5c3dbfdedba5@googlegroups.com> References: <5a7b6360-5b9b-465c-8401-9a0079048931@googlegroups.com> <7b72a3a0-f0c0-429a-b383-5c3dbfdedba5@googlegroups.com> Message-ID: On Sat, Jul 2, 2016 at 5:32 AM, Ankush Thakur wrote: > On Friday, July 1, 2016 at 9:13:19 AM UTC+5:30, Lawrence D?Oliveiro wrote: >> >> > Shouldn't we be instead using self.celcius in, say, __init__() and then >> > everything will work fine? >> >> I guess it might. But this way, using descriptors, all the setup is done once at class definition, rather then every time in class instantiation. > > So you're saying the (sole) reason to instantiate descriptor classes at class-level is performance? Performance might be part of it (it also saves some checks when looking up attributes), but in my opinion a big reason for it is separation of responsibilities. Classes define object behavior; instances contain object state. For example, you can't define a method on an instance (though you can certainly store a function there and call it). From ethan at stoneleaf.us Sat Jul 2 19:28:12 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 02 Jul 2016 16:28:12 -0700 Subject: Namespaces are one honking great idea In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> Message-ID: <57784E0C.1080203@stoneleaf.us> On 07/02/2016 08:34 AM, Kevin Conway wrote: > For the proponents of namespace, what is deficient in the above example > that necessitates a language change? Adding a new widget is not changing the language. -- ~Ethan~ From cadenmrice at gmail.com Sat Jul 2 20:58:34 2016 From: cadenmrice at gmail.com (cadenmrice at gmail.com) Date: Sat, 2 Jul 2016 17:58:34 -0700 (PDT) Subject: Help with subclasses and classes Message-ID: When i run the code I get this error : Traceback (most recent call last): File "C:/Python25/chapter2", line 18, in bank=InterestAccount(5,1000,0.5) NameError: name 'InterestAccount' is not defined I can't find the issue, any help? class BankAccount: def __init__(self,numb,bal): self.numb = numb self.bal = bal def showbal(self): print "Your balance is", self.bal def withdraw(self,wa): self.bal-=wa print("Your balance is now", self.bal) def deposit(self,da): bal+=da print("Your balance is now", self.bal) class InterestAccount(): def BankAccount__init__(self,numb,bal,intrate): self.intrate=intrate def addintrest(self): self.bal = self.bal * self.intrate bank=InterestAccount(5,1000,0.5) bank.addintrest() bank.showbal() From lawrencedo99 at gmail.com Sat Jul 2 21:02:40 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 2 Jul 2016 18:02:40 -0700 (PDT) Subject: Lost in descriptor land In-Reply-To: <025d6263-0f27-4d9c-80ba-5b42efc666be@googlegroups.com> References: <3deac09a-3bfb-45d2-bce3-eb269c6b7d90@googlegroups.com> <025d6263-0f27-4d9c-80ba-5b42efc666be@googlegroups.com> Message-ID: <23cc01f7-9076-4ae3-9332-a2ec75f5a629@googlegroups.com> On Saturday, July 2, 2016 at 11:31:02 PM UTC+12, Ankush Thakur wrote: > On Friday, July 1, 2016 at 9:03:44 AM UTC+5:30, Lawrence D?Oliveiro wrote: >> Every time I feel unsure, I go back to the horse?s mouth: here >> >> is GvR himself with all the details on ?new-style? classes, including the >> clearest explanation I have come across about descriptors. > > Well, that's certainly a very interesting link (and blog!) but my current > priority is to just understand this damn thing! :D Haste makes waste, as they say. At least read the relevant part of the article. From bgailer at gmail.com Sat Jul 2 21:39:37 2016 From: bgailer at gmail.com (Bob Gailer) Date: Sat, 2 Jul 2016 21:39:37 -0400 Subject: Help with subclasses and classes In-Reply-To: References: Message-ID: On Jul 2, 2016 9:00 PM, wrote: > > When i run the code I get this error : > Traceback (most recent call last): > File "C:/Python25/chapter2", line 18, in > bank=InterestAccount(5,1000,0.5) > NameError: name 'InterestAccount' is not defined > > I can't find the issue, any help? Following is voice dictated therefore not actually correct but you'll get the point . interest account is a nested class inside of class bank account you're trying to refer to it outside of class > > > class BankAccount: > def __init__(self,numb,bal): > self.numb = numb > self.bal = bal > def showbal(self): > print "Your balance is", self.bal > def withdraw(self,wa): > self.bal-=wa > print("Your balance is now", self.bal) > def deposit(self,da): > bal+=da > print("Your balance is now", self.bal) > class InterestAccount(): > def BankAccount__init__(self,numb,bal,intrate): > self.intrate=intrate > def addintrest(self): > self.bal = self.bal * self.intrate > bank=InterestAccount(5,1000,0.5) > bank.addintrest() > bank.showbal() > > -- > https://mail.python.org/mailman/listinfo/python-list From steve at pearwood.info Sat Jul 2 23:22:25 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 03 Jul 2016 13:22:25 +1000 Subject: Namespaces are one honking great idea References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: <577884f2$0$1600$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Jul 2016 11:50 am, Kevin Conway wrote: > I believe the namespace object you are referring to is exactly a class. Yes, a namespace is exactly like a class, minus inheritance, instantiation, the implied "is-a" relationship, and the whole Java "utility class" anti-pattern. In other words, exactly not like a class *wink* Classes and modules are both namespaces: "an abstract container or environment created to hold a logical grouping of unique identifiers or symbols (i.e. names)", to quote Wikipedia: https://en.wikipedia.org/wiki/Namespace But classes provide much more functionality, over and above mere namespace: inheritance, instantiation, etc. I'm not anti-classes or opposed to OOP, these features are great when they are wanted. But when they aren't wanted, they're a nuisance. Modules also provide more than just an abstract namespace: they provide scope, but that's exactly what I want for my Namespace entity: it should be a namespace, and it should be a scope for functions. In other words, it should be a module. I just don't want to have to place the source code in a separate file, because sometimes that's annoying and overkill. Modules are good for information hiding and encapsulation, just like classes, but without inheritance etc. But because you cannot put more than one module inside a single file, the developer has to make a choice between information hiding and encapsulation: (1) You can keep your functions encapsulated inside a single module/file, but you cannot hide some of them from parts of the module that don't care about them. (2) You can hide those functions from the parts of the module that don't care about them, but only by breaking encapsulation, moving them to another file, and exposing another name in the file system namespace. The "namespace" feature offers an alternative. Namespaces in C#, C++ and PHP: https://msdn.microsoft.com/en-us/library/z2kcy19k.aspx https://msdn.microsoft.com/en-us/library/5cb46ksf.aspx http://php.net/manual/en/language.namespaces.php > IIRC, classes came about as a "module in a module". I'm pretty sure they did not. Object oriented programming (and hence classes) came about from simulating real world objects, hence the name: http://www.exforsys.com/tutorials/oops-concepts/the-history-of-object-oriented-programming.html In languages like Pascal, you can nest functions and procedures inside others, providing something like a namespace functionality, except that Pascal strictly enforces information hiding. There's no way for code to peer inside a Pascal function and see nested functions. > Regardless, all use cases you've listed are already satisfied by use of > the static and class method decorators. Methods decorated with these do > not require an instance initialization to use. And are significantly less easy to use, as the functions MUST refer to each other by their dotted names. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Sat Jul 2 23:44:46 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 03 Jul 2016 13:44:46 +1000 Subject: Namespaces are one honking great idea References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> Message-ID: <57788a2f$0$22141$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Jul 2016 01:34 am, Kevin Conway wrote: > staticmethod isn't technically required to use a method through the class > (or subclasses), it simply provides the appropriate magic to allow it to > be called through instances. > > For example, the following code covers all described use cases of the > proposed namespace. It really doesn't. Here's your class: > Methods are invoked without creating instances and > state is managed on the class object directly. > > class CustomNs: > > stateful_data = 1 > > @staticmethod > def echo(text): > print(text) > > @classmethod > def mutate(cls): > cls.stateful_data += 1 > print(cls.stateful_data) The class scope is not "first class" (pun intended), as you cannot refer to class-level variables without prefixing them with the class, even from within the class. Although the class *may* be used without instantiating, this violates the user's expectations and may be confusing. I acknowledge that my own namespace has a similar problem, as it uses the class keyword, but the use of an explicit Namespace decorator or metaclass gives a hint that something is different. And if you try calling the Namespace, as if to instantiate it, you get a TypeError. [...] > For the proponents of namespace, what is deficient in the above example > that necessitates a language change? It's not a language change. Although I'd like a new keyword, to avoid the "but it looks like a class" problem, its not necessary. Try getting this behaviour from within a class: class Food(metaclass=Namespace): # (1) no special decorators required def spam(n): return ' '.join(['spam']*n) # (2) can call functions from inside the namespace breakfast = spam(5) # (3) no "cls" or "self" argument def lunch(): # (4) can access variables using their undotted name return breakfast + ' and eggs' def supper(): # (5) likewise functions (a special case of #4) return lunch() + ' and a fried slice of spam' def mutate(n): # global inside the namespace refers to the namespace, # not the surrounding module global breakfast breakfast = spam(5) Everything written inside the namespace object could have started as top level module code. I select the code, hit my editor's "Indent" command, and insert a single line at the top to turn it into a namespace. If I decide to move the code into a separate file, I just copy the block, excluding the "class ... metaclass" header line, past into a new file, select all, and Dedent. Done. Can you do all of that with an ordinary class? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From lawrencedo99 at gmail.com Sun Jul 3 00:31:45 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 2 Jul 2016 21:31:45 -0700 (PDT) Subject: Making Classes Subclassable Message-ID: Some of the classes in Qahirah, my Cairo binding I found handy to reuse elsewhere, for example in my binding for Pixman . Subclassing is easy, but then you need to ensure that operations inherited from the superclass return instances of the right class. This means that superclass methods must never refer directly to the class by name for constructing new objects; they need to obtain the current class by more indirect means. (?isinstance? checks on the superclass name are fine, since they will succeed on subclasses as well.) For example, consider the qahirah.Matrix class. Here is how I define the multiplication operator: def __mul__(m1, m2) : "returns concatenation with another Matrix, or mapping of a Vector." if isinstance(m2, Matrix) : result = m1.__class__ \ ( xx = m1.xx * m2.xx + m1.xy * m2.yx, yx = m1.yx * m2.xx + m1.yy * m2.yx, xy = m1.xx * m2.xy + m1.xy * m2.yy, yy = m1.yx * m2.xy + m1.yy * m2.yy, x0 = m1.xx * m2.x0 + m1.xy * m2.y0 + m1.x0, y0 = m1.yx * m2.x0 + m1.yy * m2.y0 + m1.y0, ) elif isinstance(m2, Vector) : result = m2.__class__ \ ( x = m2.x * m1.xx + m2.y * m1.xy + m1.x0, y = m2.x * m1.yx + m2.y * m1.yy + m1.y0 ) else : result = NotImplemented #end if return \ result #end __mul__ The idea behind this is that you can do ?matrix * matrix? to do matrix multiplication, or ?matrix * vector? to transform a Vector by a Matrix. In Pixman, the corresponding class names are Transform instead of Matrix, and Point instead of Vector (following the usual pixman terminology). But the inherited multiplication operation still works on them. For another example, consider the qahirah.Vector.from_tuple method, which allows easy passing of a simple pair of (x, y) coordinates wherever a Vector is wanted, with only a little extra work: @classmethod def from_tuple(celf, v) : "converts a tuple of 2 numbers to a Vector. Can be used to ensure that" \ " v is a Vector." if not isinstance(v, celf) : v = celf(*v) #end if return \ v #end from_tuple The key thing here is to avoid staticmethods and use classmethods instead, so you get passed the class object and can use it to construct new instances. From ian.g.kelly at gmail.com Sun Jul 3 00:48:11 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 2 Jul 2016 22:48:11 -0600 Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> Message-ID: On Sat, Jul 2, 2016 at 12:40 AM, Lawrence D?Oliveiro wrote: > On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: >> You should use functools.wraps instead of clobbering the decorated >> function's name and docstring: > > Where am I doing that? Using the implementation you posted: >>> @decorator_with_args ... def my_decorator(func, *args, **kwargs): ... """Returns func unmodified.""" ... return func ... >>> my_decorator.__doc__ 'generates a decorator which applies my_decorator to the given arguments' From tdsperth at gmail.com Sun Jul 3 00:57:28 2016 From: tdsperth at gmail.com (tdsperth at gmail.com) Date: Sat, 2 Jul 2016 21:57:28 -0700 (PDT) Subject: Find a file In-Reply-To: <8bc66008-4607-4aa4-91db-64cb8ea07a56@googlegroups.com> References: <8bc66008-4607-4aa4-91db-64cb8ea07a56@googlegroups.com> Message-ID: Hi Thanks for your suggestions - I did get it to work with some os.path calls and using flask get files. Cheers Colin From ethan at stoneleaf.us Sun Jul 3 01:14:37 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 02 Jul 2016 22:14:37 -0700 Subject: Namespaces are one honking great idea In-Reply-To: <57788a2f$0$22141$c3e8da3$5496439d@news.astraweb.com> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> <57788a2f$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57789F3D.7000809@stoneleaf.us> On 07/02/2016 08:44 PM, Steven D'Aprano wrote: > Try getting this behaviour from within a class: > > > class Food(metaclass=Namespace): > > # (1) no special decorators required > def spam(n): > return ' '.join(['spam']*n) > > # (2) can call functions from inside the namespace > breakfast = spam(5) > > # (3) no "cls" or "self" argument > def lunch(): > # (4) can access variables using their undotted name > return breakfast + ' and eggs' > > def supper(): > # (5) likewise functions (a special case of #4) > return lunch() + ' and a fried slice of spam' > > def mutate(n): > # global inside the namespace refers to the namespace, > # not the surrounding module > global breakfast > breakfast = spam(5) > Can you do all of that with an ordinary class? You can get #2 already, but not the rest (without your spiffy code ;) : Python 3.5.1+ (3.5:f840608f79da, Apr 14 2016, 12:29:06) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> class Huh: ... def blah(text): ... print('blah blah %s blah blah blah' % text) ... blah('whatever') ... blah blah whatever blah blah blah -- ~Ethan~ From lawrencedo99 at gmail.com Sun Jul 3 01:37:16 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 2 Jul 2016 22:37:16 -0700 (PDT) Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> Message-ID: <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> On Sunday, July 3, 2016 at 4:49:15 PM UTC+12, Ian wrote: > > On Sat, Jul 2, 2016 at 12:40 AM, Lawrence D?Oliveiro wrote: >> >> On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: >>> >>> You should use functools.wraps instead of clobbering the decorated >>> function's name and docstring: >> >> Where am I doing that? > > Using the implementation you posted: > >>>> @decorator_with_args > ... def my_decorator(func, *args, **kwargs): > ... """Returns func unmodified.""" > ... return func > ... >>>> my_decorator.__doc__ > 'generates a decorator which applies my_decorator to the given arguments' That is a function that I am generating, so naturally I want to give it a useful docstring. Am I ?clobbering? any objects passed in by the caller, or returned by the caller? No, I am not. From tjreedy at udel.edu Sun Jul 3 02:30:00 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 3 Jul 2016 02:30:00 -0400 Subject: Help with subclasses and classes In-Reply-To: References: Message-ID: On 7/2/2016 8:58 PM, cadenmrice at gmail.com wrote: > When i run the code I get this error : > Traceback (most recent call last): > File "C:/Python25/chapter2", line 18, in > bank=InterestAccount(5,1000,0.5) > NameError: name 'InterestAccount' is not defined > > I can't find the issue, any help? > > > class BankAccount: > def __init__(self,numb,bal): > self.numb = numb > self.bal = bal > def showbal(self): > print "Your balance is", self.bal > def withdraw(self,wa): > self.bal-=wa > print("Your balance is now", self.bal) > def deposit(self,da): > bal+=da > print("Your balance is now", self.bal) > class InterestAccount(): > def BankAccount__init__(self,numb,bal,intrate): > self.intrate=intrate > def addintrest(self): > self.bal = self.bal * self.intrate InterestAccount should not be nested. It should subclass BankAccount. You should write the subclass init as shown. Do put spaces after commas. class InterestAccount(BankAccount): def __init__(self, numb, bal, intrate): BankAccount(self, numb, bal) self.intrate=intrate def addintrest(self): self.bal = self.bal * self.intrate > bank=InterestAccount(5, 1000, 0.5) > bank.addintrest() > bank.showbal() I believe the above will not do as you expect. -- Terry Jan Reedy From john_ladasky at sbcglobal.net Sun Jul 3 02:58:56 2016 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sat, 2 Jul 2016 23:58:56 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of Message-ID: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> A while back, I shared my love for using Greek letters as variable names in my Python (3.4) code -- when, and only when, they are warranted for improved readability. For example, I like to see the following: from math import pi as ? c = 2 * ? * r When I am copying mathematical formulas from publications, and Greek letters are used in that publication, I prefer to follow the text exactly as written. Up until today, every character I've tried has been accepted by the Python interpreter as a legitimate character for inclusion in a variable name. Now I'm copying a formula which defines a gradient. The nabla symbol (?) is used in the naming of gradients. Python isn't having it. The interpreter throws a "SyntaxError: invalid character in identifier" when it encounters the ?. I am now wondering what constitutes a valid character for an identifier, and how they were chosen. Obviously, the Western alphabet and standard Greek letters work. I just tried a few very weird characters from the Latin Extended range, and some Cyrillic characters. These are also fine. A philosophical question. Why should any character be excluded from a variable name, besides the fact that it might also be an operator? This might be a problem I can solve, I'm not sure. Is there a file that the Python interpreter refers to which defines the accepted variable name characters? Perhaps I could just add ?. From lawrencedo99 at gmail.com Sun Jul 3 03:07:24 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 00:07:24 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: On Sunday, July 3, 2016 at 6:59:14 PM UTC+12, John Ladasky wrote: > from math import pi as ? > > c = 2 * ? * r ldo at theon:~> python3 Python 3.5.1+ (default, Jun 10 2016, 09:03:40) [GCC 5.4.0 20160603] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from math import pi as ? >>> >>> c = 2 * ? * r Traceback (most recent call last): File "", line 1, in NameError: name 'r' is not defined It wasn?t the ??? it was complaining about... From marko at pacujo.net Sun Jul 3 03:26:51 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 03 Jul 2016 10:26:51 +0300 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: <8760sni3lw.fsf@elektro.pacujo.net> Lawrence D?Oliveiro : > It wasn?t the ??? it was complaining about... The question is why ? is accepted but ? is not. The immediate reason is that ? is a letter while ? is not. But the question, then, is why bother excluding nonletters from identifiers. Personally, I don't think even ? should be used in identifiers. Mathematicians and physicists have a questionable tradition of using single-character identifiers in their formulas. That shouldn't be transported to programming. Marko From rustompmody at gmail.com Sun Jul 3 03:26:55 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Jul 2016 00:26:55 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: <973c1175-8636-4af3-8028-ff4662b9daaa@googlegroups.com> On Sunday, July 3, 2016 at 12:29:14 PM UTC+5:30, John Ladasky wrote: > A while back, I shared my love for using Greek letters as variable names in my Python (3.4) code -- when, and only when, they are warranted for improved readability. For example, I like to see the following: > > > from math import pi as ? > > c = 2 * ? * r > > > When I am copying mathematical formulas from publications, and Greek letters are used in that publication, I prefer to follow the text exactly as written. > > Up until today, every character I've tried has been accepted by the Python interpreter as a legitimate character for inclusion in a variable name. Now I'm copying a formula which defines a gradient. The nabla symbol (?) is used in the naming of gradients. Python isn't having it. The interpreter throws a "SyntaxError: invalid character in identifier" when it encounters the ?. > > I am now wondering what constitutes a valid character for an identifier, and how they were chosen. Obviously, the Western alphabet and standard Greek letters work. I just tried a few very weird characters from the Latin Extended range, and some Cyrillic characters. These are also fine. https://docs.python.org/3.5/reference/lexical_analysis.html points to https://www.dcl.hpi.uni-potsdam.de/home/loewis/table-3131.html Quite hardwired > > A philosophical question. Why should any character be excluded from a variable name, besides the fact that it might also be an operator? > > This might be a problem I can solve, I'm not sure. Is there a file that the Python interpreter refers to which defines the accepted variable name characters? Perhaps I could just add ?. You need to try something like >>> import unicodedata as ud >>> ud.category("?") 'Sm' >>> ud.category("A") 'Lu' >>> ud.category("?") 'Ll' >>> ud.category("a") 'Ll' followed by figuring out why/what etc from (say) https://en.wikipedia.org/wiki/Unicode_character_property This is the way it IS Not saying it SHOULD BE? From jussi.piitulainen at helsinki.fi Sun Jul 3 03:29:40 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Sun, 03 Jul 2016 10:29:40 +0300 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: John Ladasky writes: [- -] > The nabla symbol (?) is used in the naming of gradients. Python isn't > having it. The interpreter throws a "SyntaxError: invalid character > in identifier" when it encounters the ?. > > I am now wondering what constitutes a valid character for an > identifier, and how they were chosen. Obviously, the Western alphabet > and standard Greek letters work. I just tried a few very weird > characters from the Latin Extended range, and some Cyrillic > characters. These are also fine. I think they merely extended the identifier syntax to Unicode: one or more letters, underscores and digits, not starting with a digit. The nabla symbol is not classified as a letter in Unicode, so it's not allowed under this rule, and there is no other rule to allow it. (Hm. Python seems to understand that the character occurs in what is intended to be an identifier. Perhaps that's a default error message.) From rosuav at gmail.com Sun Jul 3 03:41:59 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jul 2016 17:41:59 +1000 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: On Sun, Jul 3, 2016 at 4:58 PM, John Ladasky wrote: > Up until today, every character I've tried has been accepted by the Python interpreter as a legitimate character for inclusion in a variable name. Now I'm copying a formula which defines a gradient. The nabla symbol (?) is used in the naming of gradients. Python isn't having it. The interpreter throws a "SyntaxError: invalid character in identifier" when it encounters the ?. > > I am now wondering what constitutes a valid character for an identifier, and how they were chosen. Obviously, the Western alphabet and standard Greek letters work. I just tried a few very weird characters from the Latin Extended range, and some Cyrillic characters. These are also fine. > Very good question! The detaily answer is here: https://docs.python.org/3/reference/lexical_analysis.html#identifiers > A philosophical question. Why should any character be excluded from a variable name, besides the fact that it might also be an operator? > In a way, that's exactly what's happening here. Python permits certain categories of character as identifiers, leaving other categories available for operators. Even though there aren't any non-ASCII operators in a vanilla CPython, it's plausible that someone could create a Python-based language with more operators (eg ? NOT EQUAL TO as an alternative to !=), and I'm sure you'd agree that saying "? = 1" is nonsensical. > This might be a problem I can solve, I'm not sure. Is there a file that the Python interpreter refers to which defines the accepted variable name characters? Perhaps I could just add ?. > The key here is its Unicode category: >>> unicodedata.category("?") 'Sm' You could probably hack CPython to include Sm, and maybe Sc, Sk, and So, as valid identifier characters. I'm not sure where, though, and I've just spent a good bit of time delving (it's based on the XID_Start and XID_Continue derived properties, but I have no idea where they're defined - Tools/unicode/makeunicodedata.py looks promising, but even there, I can't find it). And - or maybe instead - you could appeal to the core devs to have the category/ies in question added to the official Python spec. Symbols like that are a bit of a grey area, so you may find that you're starting a huge debate :) Have fun. ChrisA From lawrencedo99 at gmail.com Sun Jul 3 04:38:52 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 01:38:52 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <8760sni3lw.fsf@elektro.pacujo.net> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <8760sni3lw.fsf@elektro.pacujo.net> Message-ID: <8312c969-dce3-4612-8c03-ddb5d58431e4@googlegroups.com> On Sunday, July 3, 2016 at 7:27:04 PM UTC+12, Marko Rauhamaa wrote: > Personally, I don't think even ? should be used in identifiers. Why not? Python already has all the other single-character constants in what probably the most fundamental identity in all of mathematics: $$e^{i \pi} + 1 = 0$$ From marko at pacujo.net Sun Jul 3 05:01:51 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 03 Jul 2016 12:01:51 +0300 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <8760sni3lw.fsf@elektro.pacujo.net> <8312c969-dce3-4612-8c03-ddb5d58431e4@googlegroups.com> Message-ID: <871t3bhz7k.fsf@elektro.pacujo.net> Lawrence D?Oliveiro : > On Sunday, July 3, 2016 at 7:27:04 PM UTC+12, Marko Rauhamaa wrote: > >> Personally, I don't think even ? should be used in identifiers. > > Why not? 1. It can't be typed easily. 2. It can look like an n. 3. Single-character identifiers should not be promoted, especially with a global scope. > Python already has all the other single-character constants in what > probably the most fundamental identity in all of mathematics: > > $$e^{i \pi} + 1 = 0$$ Mathematics and physics have run into trouble with single-character identifiers already. They have run out of letters and have had to reuse them. Programmers used to have the same problem until they realized it's ok to use descriptive names. Just say, >>> import cmath >>> cmath.e ** (1j * cmath.pi) + 1 1.2246467991473532e-16j Marko From robert.kern at gmail.com Sun Jul 3 05:16:59 2016 From: robert.kern at gmail.com (Robert Kern) Date: Sun, 3 Jul 2016 10:16:59 +0100 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: On 2016-07-03 08:29, Jussi Piitulainen wrote: > (Hm. Python seems to understand that the character occurs in what is > intended to be an identifier. Perhaps that's a default error message.) I suspect that "identifier" is the final catch-all token in the lexer. Comments and strings are clearly delimited. Keywords, operators, and [{(braces)}] are all explicitly whitelisted from finite lists. Well, I guess it could have been intended by the user to be a numerical literal, but I suspect that's attempted before identifier. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From alain at universite-de-strasbourg.fr.invalid Sun Jul 3 05:53:18 2016 From: alain at universite-de-strasbourg.fr.invalid (Alain Ketterlin) Date: Sun, 03 Jul 2016 11:53:18 +0200 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: <87inwndp4h.fsf@universite-de-strasbourg.fr.invalid> John Ladasky writes: > from math import pi as ? > [...] > c = 2 * ? * r > Up until today, every character I've tried has been accepted by the > Python interpreter as a legitimate character for inclusion in a > variable name. Now I'm copying a formula which defines a gradient. The > nabla symbol (?) is used in the naming of gradients. Python isn't > having it. The interpreter throws a "SyntaxError: invalid character in > identifier" when it encounters the ?. The rules are at https://docs.python.org/3.5/reference/lexical_analysis.html#identifiers To me it makes a lot of sense to *not* include category Sm characters in identifiers, since they are usually used to denote operators (like +). It would be very confusing to have a variable named ?f, as confusing as naming a variable a+b or ?x. -- Alain. From marko at pacujo.net Sun Jul 3 07:01:56 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 03 Jul 2016 14:01:56 +0300 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <87inwndp4h.fsf@universite-de-strasbourg.fr.invalid> Message-ID: <87r3bbgf2z.fsf@elektro.pacujo.net> Alain Ketterlin : > It would be very confusing to have a variable named ?f, as confusing > as naming a variable a+b or ?x. Scheme allows *any* characters whatsoever in identifiers. Marko From auriocus at gmx.de Sun Jul 3 07:16:38 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 3 Jul 2016 13:16:38 +0200 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <87r3bbgf2z.fsf@elektro.pacujo.net> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <87inwndp4h.fsf@universite-de-strasbourg.fr.invalid> <87r3bbgf2z.fsf@elektro.pacujo.net> Message-ID: Am 03.07.16 um 13:01 schrieb Marko Rauhamaa: > Alain Ketterlin : > >> It would be very confusing to have a variable named ?f, as confusing >> as naming a variable a+b or ?x. > > Scheme allows *any* characters whatsoever in identifiers. Parentheses? Christian From marko at pacujo.net Sun Jul 3 07:22:34 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 03 Jul 2016 14:22:34 +0300 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <87inwndp4h.fsf@universite-de-strasbourg.fr.invalid> <87r3bbgf2z.fsf@elektro.pacujo.net> Message-ID: <87lh1jge4l.fsf@elektro.pacujo.net> Christian Gollwitzer : > Am 03.07.16 um 13:01 schrieb Marko Rauhamaa: >> Alain Ketterlin : >> >>> It would be very confusing to have a variable named ?f, as confusing >>> as naming a variable a+b or ?x. >> >> Scheme allows *any* characters whatsoever in identifiers. > > Parentheses? Yes. Hint: Python allows *any* characters whatsoever in strings. Marko From bc at freeuk.com Sun Jul 3 07:50:35 2016 From: bc at freeuk.com (BartC) Date: Sun, 3 Jul 2016 12:50:35 +0100 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <87r3bbgf2z.fsf@elektro.pacujo.net> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <87inwndp4h.fsf@universite-de-strasbourg.fr.invalid> <87r3bbgf2z.fsf@elektro.pacujo.net> Message-ID: On 03/07/2016 12:01, Marko Rauhamaa wrote: > Alain Ketterlin : > >> It would be very confusing to have a variable named ?f, as confusing >> as naming a variable a+b or ?x. > > Scheme allows *any* characters whatsoever in identifiers. I think it's one of those languages that has already dispensed with most syntax anyway. Including distinctions between names and symbols. Some people think that extra syntax rules including enforcing such distinctions and having restrictions can improve readability. Otherwise you can be looking at: a b c d e f g h (not Scheme) and wondering which are names and which are operators. -- Bartc From ian.g.kelly at gmail.com Sun Jul 3 07:52:47 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 3 Jul 2016 05:52:47 -0600 Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> Message-ID: On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D?Oliveiro wrote: > On Sunday, July 3, 2016 at 4:49:15 PM UTC+12, Ian wrote: >> >> On Sat, Jul 2, 2016 at 12:40 AM, Lawrence D?Oliveiro wrote: >>> >>> On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: >>>> >>>> You should use functools.wraps instead of clobbering the decorated >>>> function's name and docstring: >>> >>> Where am I doing that? >> >> Using the implementation you posted: >> >>>>> @decorator_with_args >> ... def my_decorator(func, *args, **kwargs): >> ... """Returns func unmodified.""" >> ... return func >> ... >>>>> my_decorator.__doc__ >> 'generates a decorator which applies my_decorator to the given arguments' > > That is a function that I am generating, so naturally I want to give it a useful docstring. Am I ?clobbering? any objects passed in by the caller, or returned by the caller? No, I am not. It isn't useful, though. If somebody writes a docstring for a function, it's because they want that to be the docstring for the function, not some arbitrary and vague docstring assigned by a decorator. If I type "help(my_decorator)" in the interactive interpreter, I should see what my_decorator actually does, not "generates a decorator which applies my_decorator", which just confuses with its recursiveness. The only way to find out what my_decorator actually does from the interactive interpreter would be to realize that it's been opaquely decorated and type out something like this: >>> my_decorator.__closure__[0].cell_contents.__doc__ 'Returns func unmodified.' That's far too obscure. Alternatively, one could go read the source. But if you have to go read the source to understand what a function does, then you've lost the purpose of having a docstring in the first place. From ankush.thakur53 at gmail.com Sun Jul 3 09:27:36 2016 From: ankush.thakur53 at gmail.com (Ankush Thakur) Date: Sun, 3 Jul 2016 06:27:36 -0700 (PDT) Subject: Lost in descriptor land In-Reply-To: References: <5a7b6360-5b9b-465c-8401-9a0079048931@googlegroups.com> <7b72a3a0-f0c0-429a-b383-5c3dbfdedba5@googlegroups.com> Message-ID: <7c28c991-3d81-45b8-bfe0-b425dd33b049@googlegroups.com> On Sunday, July 3, 2016 at 4:37:49 AM UTC+5:30, Ian wrote: > Classes define object behavior; > instances contain object state. For example, you can't define a method > on an instance (though you can certainly store a function there and > call it). Nice! Thanks for clearing that up. :) From ankush.thakur53 at gmail.com Sun Jul 3 09:29:18 2016 From: ankush.thakur53 at gmail.com (Ankush Thakur) Date: Sun, 3 Jul 2016 06:29:18 -0700 (PDT) Subject: Lost in descriptor land In-Reply-To: <23cc01f7-9076-4ae3-9332-a2ec75f5a629@googlegroups.com> References: <3deac09a-3bfb-45d2-bce3-eb269c6b7d90@googlegroups.com> <025d6263-0f27-4d9c-80ba-5b42efc666be@googlegroups.com> <23cc01f7-9076-4ae3-9332-a2ec75f5a629@googlegroups.com> Message-ID: <6f371e21-190d-49fe-a961-c5e55c195347@googlegroups.com> On Sunday, July 3, 2016 at 6:32:56 AM UTC+5:30, Lawrence D?Oliveiro wrote: > Haste makes waste, as they say. At least read the relevant part of the article. I really feel like I've been pushed into studying its genetics while I only wanted to pluck the fruit. Why do descriptors have to be so overwhelming?! . . . Okay, I guess I'll read at least the descriptor part of the article, but then I'm leaving the whole subject for another day. From auriocus at gmx.de Sun Jul 3 10:05:11 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 3 Jul 2016 16:05:11 +0200 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <87lh1jge4l.fsf@elektro.pacujo.net> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <87inwndp4h.fsf@universite-de-strasbourg.fr.invalid> <87r3bbgf2z.fsf@elektro.pacujo.net> <87lh1jge4l.fsf@elektro.pacujo.net> Message-ID: Am 03.07.16 um 13:22 schrieb Marko Rauhamaa: > Christian Gollwitzer : > >> Am 03.07.16 um 13:01 schrieb Marko Rauhamaa: >>> Alain Ketterlin : >>> >>>> It would be very confusing to have a variable named ?f, as confusing >>>> as naming a variable a+b or ?x. >>> >>> Scheme allows *any* characters whatsoever in identifiers. >> >> Parentheses? > > Yes. > > Hint: Python allows *any* characters whatsoever in strings. My knowledge of Scheme is rusty. How do you do that? Consider (define x 'hello) then the x is the identifier, isn't it? How can you include a metacharacter like space, ', or ( in it? I'm using https://repl.it/languages/scheme to try it out. Another language which allows any characters in identifiers is Tcl. Here you can quote identifiers: set {a b} c creates a variable "a b" with a space in it, because there is no distinction between quoted/unquoted. Metacharacters can be included by \-escapes. How does that work in Scheme? Christian From marko at pacujo.net Sun Jul 3 10:39:00 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 03 Jul 2016 17:39:00 +0300 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <87inwndp4h.fsf@universite-de-strasbourg.fr.invalid> <87r3bbgf2z.fsf@elektro.pacujo.net> <87lh1jge4l.fsf@elektro.pacujo.net> Message-ID: <87furqhjln.fsf@elektro.pacujo.net> Christian Gollwitzer : > Am 03.07.16 um 13:22 schrieb Marko Rauhamaa: >> Christian Gollwitzer : >>> Am 03.07.16 um 13:01 schrieb Marko Rauhamaa: >>>> Scheme allows *any* characters whatsoever in identifiers. >>> Parentheses? >> Yes. > > My knowledge of Scheme is rusty. How do you do that? Moreover, all characters whose Unicode scalar values are greater than 127 and whose Unicode category is Lu, Ll, Lt, Lm, Lo, Mn, Mc, Me, Nd, Nl, No, Pd, Pc, Po, Sc, Sm, Sk, So, or Co can be used within identifiers. In addition, any character can be used within an identifier when specified via an . For example, the identifier H\x65;llo is the same as the identifier Hello, and the identifier \x3BB; is the same as the identifier ?. Guile doesn't support the R6RS inline hex escape notation. Instead, it natively supports a notation of its own: #{foo bar}# #{what ever}# #{4242}# Or the R7RS notation: |foo bar| |\x3BB; is a greek lambda| |\| is a vertical bar| Marko From upendra.k14 at iiits.in Sun Jul 3 10:48:22 2016 From: upendra.k14 at iiits.in (Upendra Kumar) Date: Sun, 3 Jul 2016 22:48:22 +0800 Subject: Tkinter based GUI for PIP : Needed Feedback Message-ID: Hello everyone, We have made a preliminary version of GUI for PIP. This project is a part of GSoC 2016. This project is intended to provide a GUI version for "pip". ( target audience for the project : beginners in Python ). The project idea is discussed on these issues : 1. Issue #23551 : IDLE to provide menu link to PIP gui. 2. Issue #27051 : Create PIP GUI The GitHub repo of the project : https://github.com/upendra-k14/pip_gui Therefore, we would like to have feedback on this project so that we can improve the GUI and other features to it. Please post as many issues and suggestions here : https://github.com/upendra-k14/pip_gui/issues. From vek.m1234 at gmail.com Sun Jul 3 10:49:51 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Sun, 03 Jul 2016 20:19:51 +0530 Subject: Descriptor: class name precedence over instance name References: <85shvstze5.fsf@benfinney.id.au> Message-ID: Ian Kelly wrote: > On Sat, Jul 2, 2016 at 3:34 AM, Veek. M wrote: >> So essentially from what Ian said: >> data_descriptor_in_instance -> instance_attribute -> non- >> data_descriptor_in_instance -->__mro__ >> >> is how the search takes place. Correct? > > Close, but I would write it as: > data_descriptor_in_class_including_mro -> instance_attribute -> > non_data_descriptor_or_class_attribute_including_mro > > In either case the class dict search is in __mro__ order. You can find > the actual implementation here: > > https://hg.python.org/cpython/file/30099abdb3a4/Objects/object.c#l1326 > > Roughly, the algorithm is this: > > tp = type(obj) > > # This call searches the MRO. > descr = _PyType_Lookup(tp, name) > > if descr != NULL and is_data_descriptor(descr): > return descr.__get__(obj, tp) > > if name in obj.__dict__: > return obj.__dict__[name] > > if descr != NULL and is_non_data_descriptor(descr): > return descr.__get__(obj, tp) > > if descr != NULL: > return descr > > raise AttributeError(name) > >> ------------------------------ >> >> Regarding part2 of the Q, :) Ian hasn't explained it, so I'm not sure >> how to explain it better :) but i'll try given that he has clarified >> part of the answer. >> >> Basically Beazley has a TypedProperty descriptor class, and in class >> Foo he instantiates: >> name = TypedProperty >> Then he does f = Foo() >> >> Thanks to Ian, we now know that any lookup on 'f' eg: f.name would > > Not *any* lookup, only one for which there is a declared descriptor. > So in this example f.name or f.num would resolve according to the > descriptor's __get__ method, but any other attribute lookup would just > return whatever value is set on the instance (if any). > >> cause.. well.. the f.name(TypedProperty-descriptor) to gain >> precedence thus hiding the f.name attribute! Therefore he needs to >> name-decorate or in this example append an '_' for whatever stupid >> reason. > > Right, if the "name" descriptor tried to store the value in the > unmangled "name" instance attribute, then its getattr call would just > recur back to the descriptor and you'd have an infinite loop. > > In my opinion the mangling should be a bit heavier than what's done in > this example, to avoid collisions between the descriptor and the class > that's using it. I like to follow the pattern of __foo name mangling, > so I would have instead used: > > self.name = "_TypedProperty__" + name Ouch - that's above my skill level (Python types, especially PyType_Lookup has no docs but i did find https://docs.python.org/3/c-api/index.html) and I got side tracked into reading the PCIe spec so today went down the drain. I'm putting this on hold as totally not understood and requiring much more reading. I'll drag it up later if everyones okay with it. From vek.m1234 at gmail.com Sun Jul 3 10:52:44 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Sun, 03 Jul 2016 20:22:44 +0530 Subject: super and mix-in class: how exactly is the search order altered? References: <87bn2gijjv.fsf@handshake.de> Message-ID: dieter wrote: > "Veek. M" writes: >> ... >> I'm reading this article: >> https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ >> >> He's trying to explain the purpose of a 'mix-in class' and he says >> >> We did not alter the source code for LoggingDict. Instead we >> built a >> subclass whose only logic is to compose two existing classes and >> control their search order. >> >> class LoggingOD(LoggingDict, collections.OrderedDict): >> pass >> >> My question is this: in the above article context, is he talking >> about the LoggingDict's search order that is being manipulated? Or he >> is talking about manipulating the LoggingOD search order? > > Likely, his language has been a bit sloppy. > > Likely, his setup is as follows: > > * He has an existing class ("collections.OrderDict") > which the base functionality he needs > > * He has an additional requirement (over that of > "collections.OrderDict") > -- logging modifications > > * He wants to implement his requirements (the base ones and the > the additional one) without modifying the existing class in any way > > * His idea to implement the additional requirement is to define > a derived class ("LoggingOD") and lets its modifying methods > perform the logging and then call the corresponding methods of the > base class. > > * He recognizes that this logging feature might be interesting > not only for "collections.OrderDict" but also for other > dictionary like base classes. > Therefore, instead of implementing it directly in > "LoggingOD", he implements it in the mixin class "LoggingDict". > > * Because "LoggingDict" was explicitely designed to be used > as mixin class to enhance a base class, it knows that > some methods ("__setitem__") of the base class need to be called > in its own implementation of the corresponding method. > > * The integrator (the one combining "LoggingDict" with the base > class) must ensure (by an appropriate inheritance order) > that the combining class ("LoggingOD" in the example) > calls the "LoggingDict"'s methods (which know about that of the > base class) rather than the base class's methods (which do not > know about the mixin class's methods). > > Therefore, he uses the inheritance order "LoggingDict" followed > by the base class (and not vice versa). > > > Python clearly defines in what order attributes of an object > and of the construct "super(,)" are looked up. > > The essential concept is the so called "MRO" ("method resolution > order") (in fact, it is an attribute resolution order). > > In simple cases (no common base classes), the MRO of > a definition "class C(B_1, ..., B_n): ..." > is defined by a left to right lookup: i.e. first in "C", then "B_1", > then "B_2", ... > > The rules are a bit more complicated when the "B_i" have a (or more) > common base classes. Hey Dieter, I'll need some time to read this and get back on it - hope that's okay. But yeah, I think he's explaining it badly and extremely misleading (imho). From rosuav at gmail.com Sun Jul 3 11:14:00 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jul 2016 01:14:00 +1000 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <871t3bhz7k.fsf@elektro.pacujo.net> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <8760sni3lw.fsf@elektro.pacujo.net> <8312c969-dce3-4612-8c03-ddb5d58431e4@googlegroups.com> <871t3bhz7k.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 3, 2016 at 7:01 PM, Marko Rauhamaa wrote: > Lawrence D?Oliveiro : > >> On Sunday, July 3, 2016 at 7:27:04 PM UTC+12, Marko Rauhamaa wrote: >> >>> Personally, I don't think even ? should be used in identifiers. >> >> Why not? > > 1. It can't be typed easily. > > 2. It can look like an n. > > 3. Single-character identifiers should not be promoted, especially with > a global scope. None of these is a language-level concern. You can't type it? That's your problem - and you can choose not to use it. But Python lets you, if you want to. Remember, some people speak Greek natively, and for those people, typing Greek text is as natural as typing Latin text is for us. Similarly, Cyrillic text is the most natural language for Russian speakers. Why should Python block them? Your other concerns might be a case for linters, but definitely not the language. ChrisA From steve at pearwood.info Sun Jul 3 11:32:43 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 04 Jul 2016 01:32:43 +1000 Subject: Lost in descriptor land References: <5a7b6360-5b9b-465c-8401-9a0079048931@googlegroups.com> <7b72a3a0-f0c0-429a-b383-5c3dbfdedba5@googlegroups.com> Message-ID: <5779301d$0$1600$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Jul 2016 09:06 am, Ian Kelly wrote: > you can't define a method > on an instance (though you can certainly store a function there and > call it). Yes -- the difference is that Python doesn't apply the descriptor protocol to attributes attached to the instance. So the function remains a function and is not converted to a method, which means it doesn't automatically get the special "self" argument: class Test(object): pass instance = Test() def method(self): print("method called from self", self) instance.method = method If you try to call the "method", you get an error: py> instance.method() Traceback (most recent call last): File "", line 1, in TypeError: method() missing 1 required positional argument: 'self' But if you prepare the method ahead of time, it works: from types import MethodType instance.method = MethodType(method, instance) Now calling it works fine: py> instance.method() method called from self <__main__.Test object at 0xb79fcf14> -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From laurent.pointal at free.fr Sun Jul 3 11:42:26 2016 From: laurent.pointal at free.fr (Laurent Pointal) Date: Sun, 03 Jul 2016 17:42:26 +0200 Subject: I need a pure python module from PyPI without additional packages on my OS. References: <3b88728b-463e-4a00-b2d9-23d1ae7ab570@googlegroups.com> Message-ID: <57793262$0$23774$426a74cc@news.free.fr> Seti Volkylany wrote: > I heard about cairo, but it required installed on my computer before. Some precision would be wellcome. Do you need any pure Python module from PyPI ? Do you need a "cairo compatible" pure Python module from PyPI ? A+ L.P. From laurent.pointal at free.fr Sun Jul 3 11:46:37 2016 From: laurent.pointal at free.fr (Laurent Pointal) Date: Sun, 03 Jul 2016 17:46:37 +0200 Subject: What the deal with python3.5m.so and python3.5.so ?? References: <577256A6.7030509@chello.at> Message-ID: <5779335d$0$23774$426a74cc@news.free.fr> Steven Truppe wrote: > Hi all, > > can someone tell me the difference between python3.5m.so and python3.5.so > ?? The 'm' tagged version is for a Python compiled with PyMalloc: https://www.python.org/dev/peps/pep-3149/ (found it with Blender's bundled Python) > > Tanks in advance, > Steven Truppe A+ L.P. From steve at pearwood.info Sun Jul 3 12:02:23 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 04 Jul 2016 02:02:23 +1000 Subject: Special attributes added to classes on creation Message-ID: <57793711$0$1611$c3e8da3$5496439d@news.astraweb.com> I have some code which can preprocess (using a metaclass) or postprocess (using a decorator) a class: @process class K: pass class K(metaclass=process): pass Both should give the same result, but I have found that the results are slightly different because the dict passed to process as a metaclass is different from the the class dict seen by the decorator. I can demonstrate the difference in Python 3.6 by using this metaclass/decorator: class process(type): def __new__(meta, *args): if len(args) == 1: # decorator usage cls = args[0] d = cls.__dict__ elif len(args) == 3: # metaclass usage name, bases, d = args cls = super().__new__(meta, *args) print(sorted(d.keys())) return cls If I then try it against two identical (apart from their names) classes, I get these results: py> @process ... class K: ... x = 1 ... ['__dict__', '__doc__', '__module__', '__weakref__', 'x'] py> class Q(metaclass=process): ... x = 1 ... ['__module__', '__qualname__', 'x'] Now if I check the newly created Q, I see the same keys K has: py> sorted(Q.__dict__.keys()) ['__dict__', '__doc__', '__module__', '__weakref__', 'x'] Is there any documentation for exactly what keys are added to classes when? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From john_ladasky at sbcglobal.net Sun Jul 3 12:24:17 2016 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sun, 3 Jul 2016 09:24:17 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: Lawrence, I trust you understand that I didn't post a complete working program, just a few lines showing the intended usage? From ian.g.kelly at gmail.com Sun Jul 3 12:58:00 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 3 Jul 2016 10:58:00 -0600 Subject: Special attributes added to classes on creation In-Reply-To: <57793711$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <57793711$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 3, 2016 at 10:02 AM, Steven D'Aprano wrote: > If I then try it against two identical (apart from their names) classes, I > get these results: > > > py> @process > ... class K: > ... x = 1 > ... > ['__dict__', '__doc__', '__module__', '__weakref__', 'x'] > py> class Q(metaclass=process): > ... x = 1 > ... > ['__module__', '__qualname__', 'x'] > Now if I check the newly created Q, I see the same keys K has: > > py> sorted(Q.__dict__.keys()) > ['__dict__', '__doc__', '__module__', '__weakref__', 'x'] > > > Is there any documentation for exactly what keys are added to classes when? I'm only aware of the sequence defined at https://docs.python.org/3/reference/datamodel.html#customizing-class-creation. Based on that, I'm surprised to even see __module__ and __qualname__ in there at the point when the metaclass is handling it. From john_ladasky at sbcglobal.net Sun Jul 3 14:39:20 2016 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sun, 3 Jul 2016 11:39:20 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: <28f1731b-438b-47a4-be7b-ef9ab6314394@googlegroups.com> On Sunday, July 3, 2016 at 12:42:14 AM UTC-7, Chris Angelico wrote: > On Sun, Jul 3, 2016 at 4:58 PM, John Ladasky wrote: > Very good question! The detaily answer is here: > > https://docs.python.org/3/reference/lexical_analysis.html#identifiers > > > A philosophical question. Why should any character be excluded from a variable name, besides the fact that it might also be an operator? > > In a way, that's exactly what's happening here. Python permits certain > categories of character as identifiers, leaving other categories > available for operators. Even though there aren't any non-ASCII > operators in a vanilla CPython, it's plausible that someone could > create a Python-based language with more operators (eg ? NOT EQUAL TO > as an alternative to !=), and I'm sure you'd agree that saying "? = 1" > is nonsensical. I agree that there are some characters in the Unicode definition that could (should?) be operators and, as such, disallowed in identifiers. "?", "?" and "?" come to mind. I don't know whether the Unicode "character properties" are assigned to the characters in a way that would be satisfying to the needs of programmers. I'll do some reading. > Symbols like that are a bit of a > grey area, so you may find that you're starting a huge debate :) Oh, I can see that debate coming. I know that not all of these characters are easily TYPED, and so I have to reach for a Unicode table to cut and paste them. But once but and pasted, they are easily READ, and that's a big plus. Here's another worm for the can. Would you rather read this... d = sqrt(x**2 + y**2) ...or this? d = ?(x? + y?) From python at mrabarnett.plus.com Sun Jul 3 15:41:48 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 3 Jul 2016 20:41:48 +0100 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <28f1731b-438b-47a4-be7b-ef9ab6314394@googlegroups.com> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <28f1731b-438b-47a4-be7b-ef9ab6314394@googlegroups.com> Message-ID: On 2016-07-03 19:39, John Ladasky wrote: > On Sunday, July 3, 2016 at 12:42:14 AM UTC-7, Chris Angelico wrote: >> On Sun, Jul 3, 2016 at 4:58 PM, John Ladasky wrote: > >> Very good question! The detaily answer is here: >> >> https://docs.python.org/3/reference/lexical_analysis.html#identifiers >> >> > A philosophical question. Why should any character be excluded from a variable name, besides the fact that it might also be an operator? >> >> In a way, that's exactly what's happening here. Python permits certain >> categories of character as identifiers, leaving other categories >> available for operators. Even though there aren't any non-ASCII >> operators in a vanilla CPython, it's plausible that someone could >> create a Python-based language with more operators (eg ? NOT EQUAL TO >> as an alternative to !=), and I'm sure you'd agree that saying "? = 1" >> is nonsensical. > > I agree that there are some characters in the Unicode definition that could (should?) be operators and, as such, disallowed in identifiers. "?", "?" and "?" come to mind. I don't know whether the Unicode "character properties" are assigned to the characters in a way that would be satisfying to the needs of programmers. I'll do some reading. > >> Symbols like that are a bit of a >> grey area, so you may find that you're starting a huge debate :) > > Oh, I can see that debate coming. I know that not all of these characters are easily TYPED, and so I have to reach for a Unicode table to cut and paste them. But once but and pasted, they are easily READ, and that's a big plus. > > Here's another worm for the can. Would you rather read this... > > d = sqrt(x**2 + y**2) > > ...or this? > > d = ?(x? + y?) > It's easy to read something as simple like that, but it's harder when the exponent is more than a number or a variable. And what about a**b**c? Not to mention the limited number of superscript codepoints available... From random832 at fastmail.com Sun Jul 3 16:49:09 2016 From: random832 at fastmail.com (Random832) Date: Sun, 03 Jul 2016 16:49:09 -0400 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <87lh1jge4l.fsf@elektro.pacujo.net> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <87inwndp4h.fsf@universite-de-strasbourg.fr.invalid> <87r3bbgf2z.fsf@elektro.pacujo.net> <87lh1jge4l.fsf@elektro.pacujo.net> Message-ID: <1467578949.2994620.655791441.55D98FA3@webmail.messagingengine.com> On Sun, Jul 3, 2016, at 07:22, Marko Rauhamaa wrote: > Christian Gollwitzer : > > Am 03.07.16 um 13:01 schrieb Marko Rauhamaa: > >> Scheme allows *any* characters whatsoever in identifiers. > > > > Parentheses? > > Yes. > > Hint: Python allows *any* characters whatsoever in strings. Being able to put any character in a symbol doesn't make those strings identifiers, any more than passing them to getattr/setattr (or __import__, something's __name__, etc) does in Python. From lawrencedo99 at gmail.com Sun Jul 3 17:17:03 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 14:17:03 -0700 (PDT) Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> Message-ID: On Sunday, July 3, 2016 at 11:53:46 PM UTC+12, Ian wrote: > On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D?Oliveiro wrote: >> That is a function that I am generating, so naturally I want to give it a >> useful docstring. Am I ?clobbering? any objects passed in by the caller, >> or returned by the caller? No, I am not. > > It isn't useful, though. If somebody writes a docstring for a > function, it's because they want that to be the docstring for the > function ... Which I am not ?clobbering? at all. Do you get that yet? My docstrings apply to *my* functions, not those supplied or generated by the caller. From lawrencedo99 at gmail.com Sun Jul 3 17:21:56 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 14:21:56 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <871t3bhz7k.fsf@elektro.pacujo.net> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <8760sni3lw.fsf@elektro.pacujo.net> <8312c969-dce3-4612-8c03-ddb5d58431e4@googlegroups.com> <871t3bhz7k.fsf@elektro.pacujo.net> Message-ID: <03bf8c52-5b1e-4fb8-8aad-e09d00076781@googlegroups.com> On Sunday, July 3, 2016 at 9:02:05 PM UTC+12, Marko Rauhamaa wrote: > Lawrence D?Oliveiro: > >> On Sunday, July 3, 2016 at 7:27:04 PM UTC+12, Marko Rauhamaa wrote: >> >>> Personally, I don't think even ? should be used in identifiers. >> > > Why not? > > 1. It can't be typed easily. I have a custom .XCompose, so it?s just ?compose-p-i?. Easy to type, easy to remember. > 2. It can look like an n. Only to someone accustomed to using just one alphabet. :) > 3. Single-character identifiers should not be promoted, especially with > a global scope. It?s no more ?global? than ?math.e?. And what about ?1j?? (That completes the triumvirate of single-letter names from the Euler identity.) From marko at pacujo.net Sun Jul 3 17:25:24 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 04 Jul 2016 00:25:24 +0300 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <87inwndp4h.fsf@universite-de-strasbourg.fr.invalid> <87r3bbgf2z.fsf@elektro.pacujo.net> <87lh1jge4l.fsf@elektro.pacujo.net> <1467578949.2994620.655791441.55D98FA3@webmail.messagingengine.com> Message-ID: <8737nqh0sb.fsf@elektro.pacujo.net> Random832 : > Being able to put any character in a symbol doesn't make those strings > identifiers, any more than passing them to getattr/setattr (or > __import__, something's __name__, etc) does in Python. >From R7RS, the newest Scheme standard (p. 61-62): 7.1.1. Lexical structure [...] ?vertical line? ? | [...] ?identifier? ? ?initial? ?subsequent?* | ?vertical line? ?symbol element?* ?vertical line? | ?peculiar identifier? ?initial? ? ?letter? | ?special initial? ?letter? ? a | b | c | ... | z | A | B | C | ... | Z ?special initial? ? ! | $ | % | & | * | / | : | < | = | > | ? | ^ | _ | ~ ?subsequent? ? ?initial? | ?digit? | ?special subsequent? ?digit? ? 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ?hex digit? ? ?digit? | a | b | c | d | e | f ?explicit sign? ? + | - ?special subsequent? ? ?explicit sign? | . | @ ?inline hex escape? ? \x?hex scalar value?; ?hex scalar value? ? ?hex digit? + ?mnemonic escape? ? \a | \b | \t | \n | \r ?peculiar identifier? ? ?explicit sign? | ?explicit sign? ?sign subsequent? ?subsequent?* | ?explicit sign? . ?dot subsequent? ?subsequent?* | . ?dot subsequent? ?subsequent?* ?dot subsequent? ? ?sign subsequent? | . ?sign subsequent? ? ?initial? | ?explicit sign? | @ ?symbol element? ? ?any character other than ?vertical line?or \? | ?inline hex escape? | ?mnemonic escape? | \| Marko From lawrencedo99 at gmail.com Sun Jul 3 17:26:51 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 14:26:51 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <87inwndp4h.fsf@universite-de-strasbourg.fr.invalid> <87r3bbgf2z.fsf@elektro.pacujo.net> Message-ID: On Sunday, July 3, 2016 at 11:50:52 PM UTC+12, BartC wrote: > Otherwise you can be looking at: > > a b c d e f g h > > (not Scheme) and wondering which are names and which are operators. I did a language design for my MSc thesis where all ?functions? were operators. So a construct like ?f(a, b, c)? was really a monadic operator ?f? followed by a single argument, a record constructor ?(a, b, c)?. From lawrencedo99 at gmail.com Sun Jul 3 17:28:27 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 14:28:27 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <28f1731b-438b-47a4-be7b-ef9ab6314394@googlegroups.com> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <28f1731b-438b-47a4-be7b-ef9ab6314394@googlegroups.com> Message-ID: <557e5dc1-b78e-4b6f-8464-b1b43e777e9f@googlegroups.com> On Monday, July 4, 2016 at 6:39:45 AM UTC+12, John Ladasky wrote: > Here's another worm for the can. Would you rather read this... > > d = sqrt(x**2 + y**2) > > ...or this? > > d = ?(x? + y?) Neither. I would rather see d = math.hypot(x, y) Much simpler, don?t you think? From kevinjacobconway at gmail.com Sun Jul 3 18:02:27 2016 From: kevinjacobconway at gmail.com (Kevin Conway) Date: Sun, 03 Jul 2016 22:02:27 +0000 Subject: Namespaces are one honking great idea In-Reply-To: <57789F3D.7000809@stoneleaf.us> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> <57788a2f$0$22141$c3e8da3$5496439d@news.astraweb.com> <57789F3D.7000809@stoneleaf.us> Message-ID: >> Regardless, all use cases you've listed are already satisfied by use of >> the static and class method decorators. Methods decorated with these do >> not require an instance initialization to use. > And are significantly less easy to use, as the functions MUST refer to each > other by their dotted names. My response to this may come off as a bit glib, but it isn't intended that way. If the problem with using classes to satisfy the namespace need is that it's unwieldy to use dot qualified paths then isn't that quite similar to saying namespaces are unwieldy? Leveraging classes as a nested module creates a de-facto internal namespace of "cls" for self reference and I'm unsure of why that is unwanted but "module.namespace.blah" is wanted. I suppose my issue is not so much that namespace objects are a bad idea as that the proposal does little to express why the existing tools are deficient enough to require a new concept. > For the proponents of namespace, what is deficient in the above example > that necessitates a language change? >> It's not a language change. Perhaps. My argument is that anything that introduces a new class-like construct and set of lexical scoping rules is a language change. For example, if this change went into 2.7.13 would Jython suddenly be broken because it hasn't implemented the new scoping rules? >> IIRC, classes came about as a "module in a module". > I'm pretty sure they did not. Object oriented programming (and hence > classes) came about from simulating real world objects, hence the > name: I realize my statement was ambiguous. I didn't mean to suggest that classes, as an idea and OOP tool, were derived from the concept of a namespace. I meant to say that the Python implementation of classes is quite similar to the implementation of modules in the cPython code. The commit messages from the earlier days (ref: ab5db02) don't carry much detail so I'm mostly basing my belief of the implementation similarities and anecdotes from the community. Right or wrong, I don't believe it has much weight in the namespace discussion and I shouldn't have brought it up. On Sun, Jul 3, 2016, 00:17 Ethan Furman wrote: > On 07/02/2016 08:44 PM, Steven D'Aprano wrote: > > > Try getting this behaviour from within a class: > > > > > > class Food(metaclass=Namespace): > > > > # (1) no special decorators required > > def spam(n): > > return ' '.join(['spam']*n) > > > > # (2) can call functions from inside the namespace > > breakfast = spam(5) > > > > # (3) no "cls" or "self" argument > > def lunch(): > > # (4) can access variables using their undotted name > > return breakfast + ' and eggs' > > > > def supper(): > > # (5) likewise functions (a special case of #4) > > return lunch() + ' and a fried slice of spam' > > > > def mutate(n): > > # global inside the namespace refers to the namespace, > > # not the surrounding module > > global breakfast > > breakfast = spam(5) > > > Can you do all of that with an ordinary class? > > You can get #2 already, but not the rest (without your spiffy code ;) : > > Python 3.5.1+ (3.5:f840608f79da, Apr 14 2016, 12:29:06) > [GCC 4.8.2] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> class Huh: > ... def blah(text): > ... print('blah blah %s blah blah blah' % text) > ... blah('whatever') > ... > blah blah whatever blah blah blah > > -- > ~Ethan~ > -- > https://mail.python.org/mailman/listinfo/python-list > From ian.g.kelly at gmail.com Sun Jul 3 18:38:33 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 3 Jul 2016 16:38:33 -0600 Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> Message-ID: On Sun, Jul 3, 2016 at 3:17 PM, Lawrence D?Oliveiro wrote: > On Sunday, July 3, 2016 at 11:53:46 PM UTC+12, Ian wrote: >> On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D?Oliveiro wrote: >>> That is a function that I am generating, so naturally I want to give it a >>> useful docstring. Am I ?clobbering? any objects passed in by the caller, >>> or returned by the caller? No, I am not. >> >> It isn't useful, though. If somebody writes a docstring for a >> function, it's because they want that to be the docstring for the >> function ... > > Which I am not ?clobbering? at all. Do you get that yet? My docstrings apply to *my* functions, not those supplied or generated by the caller. Sorry, but you're the one who doesn't seem to get it. Because it's a decorator, "your" function is replacing the caller's function in the caller's namespace. If the docstring written in the code for function m.f is x, but the value of m.f.__doc__ is actually y, then the docstring x is, for all practical purposes, clobbered. That you're not actually modifying the original function is irrelevant. For the purpose of the built-in help, it's the value of m.f.__doc__ that counts. For the purpose of documentation built with pydoc, it's the value of m.f.__doc__ that counts. If the documentation for every decorator in a module just reads "generates a decorator which applies to the given arguments", that's useless documentation. Which brings me to the other half of the point I was trying to make: your decorator_with_args doesn't even *need* a docstring. It's not part of the public interface. As a nested function that doesn't have its own name within the module, help() or pydoc won't even include it in their output. If you want to put something in the code to explain what it does, that's fine, but use a comment for that. The docstring doesn't add any value. From eryksun at gmail.com Sun Jul 3 19:07:53 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 3 Jul 2016 23:07:53 +0000 Subject: Special attributes added to classes on creation In-Reply-To: <57793711$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <57793711$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 3, 2016 at 4:02 PM, Steven D'Aprano wrote: > Is there any documentation for exactly what keys are added to classes when? It should be documented that the namespace that's passed to the metaclass contains __module__ and __qualname__, and optionally __doc__ if the class has a docstring. These names are also available as local variables while executing the class body: >>> class C: ... 'eggs and spam' ... print('__module__:', __module__) ... print('__qualname__:', __qualname__) ... print('__doc__:', __doc__) ... __module__: __main__ __qualname__: C __doc__: eggs and spam This is potentially an (unlikely) issue because the class body preamble overwrites whatever custom values of these attributes were added by the metaclass __prepare__ method. For example: class Meta(type): @classmethod def __prepare__(mcls, name, bases, **kwds): return {'__module__': 'spam', '__qualname__': 'eggs.spam.' + name, '__doc__': 'spam spam spam', 'x': 42} class C(metaclass=Meta): 'docstring' >>> C.__module__ '__main__' >>> C.__qualname__ 'C' >>> C.__doc__ 'docstring' >>> C.x 42 I don't think additional documentation is required for the __dict__ and __weakref__ descriptors. They're described with respect to __slots__. They can't be added until after the metaclass processes __slots__, if present. You can begin unraveling how CPython 3.x class creation works by disassembling the bytecode for the following example: def f(): class Q(Base, metaclass=Meta): 'example class' x = 1 def method(self): __class__ # or use super() The initial work of defining a class is implemented via builtins.__build_class__, which is referenced by the bytecode instruction LOAD_BUILD_CLASS. This built-in function takes two required positional arguments: the argumentless function that implements the class body and the class name. Optionally, the base class(es) are passed as the remaining positional arguments, and the metaclass is passed as a keyword argument. Additional keyword arguments can be passed in the class statement, but this requires a custom metaclass with __new__ and __init__ methods that accept the extra arguments. The metaclass __prepare__ method also gets passed the name, bases and extra keyword arguments. Here's the bytecode setup to call __build_class__ for the above example: >>> dis.dis(f) 2 0 LOAD_BUILD_CLASS 2 LOAD_CONST 1 () 4 LOAD_CONST 2 ('Q') 6 MAKE_FUNCTION 0 8 LOAD_CONST 2 ('Q') 10 LOAD_GLOBAL 0 (Base) 12 LOAD_CONST 3 ('metaclass') 14 LOAD_GLOBAL 1 (Meta) 16 EXTENDED_ARG 1 18 CALL_FUNCTION 259 (3 positional, 1 keyword pair) 20 STORE_FAST 0 (Q) 22 LOAD_CONST 0 (None) 24 RETURN_VALUE The locals mapping for the class body comes from the metaclass __prepare__ method, if defined, and is otherwise an empty dict. There's a default type.__prepare__, which returns an empty dict: >>> type.__prepare__(1, 2, 3, spam='whatever') {} The code for the class body defines the __module__, __qualname__, and __doc__ attributes. It also defines the __class__ closure when a class has methods that use super() or reference __class__. The return value of the class body is either the __class__ cell object, if defined, or None. Returning the __class__ closure cell allows __build_class__ to set the new class as the value of the cell. Here's the bytecode for the body of class Q: >>> dis.dis(f.__code__.co_consts[1]) 2 0 LOAD_NAME 0 (__name__) 2 STORE_NAME 1 (__module__) 4 LOAD_CONST 0 ('f..Q') 6 STORE_NAME 2 (__qualname__) 3 8 LOAD_CONST 1 ('example class') 10 STORE_NAME 3 (__doc__) 4 12 LOAD_CONST 2 (1) 14 STORE_NAME 4 (x) 5 16 LOAD_CLOSURE 0 (__class__) 18 BUILD_TUPLE 1 20 LOAD_CONST 3 () 22 LOAD_CONST 4 ('f..Q.method') 24 MAKE_FUNCTION 8 26 STORE_NAME 5 (method) 28 LOAD_CLOSURE 0 (__class__) 30 RETURN_VALUE >>> f.__code__.co_consts[1].co_cellvars ('__class__',) The rest of the process is all written in C. compiler_class, which compiles a class statement to the above bytecode: https://hg.python.org/cpython/file/v3.6.0a2/Python/compile.c#l1809 builtins.__build_class__: https://hg.python.org/cpython/file/v3.6.0a2/Python/bltinmodule.c#l53 type.__new__: https://hg.python.org/cpython/file/v3.6.0a2/Objects/typeobject.c#l2268 In type_new, the class dict gets initialized starting on line 2516. __module__, if not already set, is the value of __name__ in the current globals. __qualname__, if not already set, defaults to the class name. The getset descriptors for __dict__ and __wreakref__, if present, are added to the class on line 2625, but they're not added to the class dict until the type is made ready via PyType_Ready. On line 4886, add_getset is called to add them. The names "__dict__" and "__weakref__" are defined by subtype_getsets_full, etc, starting on line 2154. Also in PyType_Ready, on line 4937, __doc__ is added if it's not already present in the class dict. From lawrencedo99 at gmail.com Sun Jul 3 19:21:16 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 16:21:16 -0700 (PDT) Subject: Namespaces are one honking great idea In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> <57788a2f$0$22141$c3e8da3$5496439d@news.astraweb.com> <57789F3D.7000809@stoneleaf.us> Message-ID: On Monday, July 4, 2016 at 10:02:59 AM UTC+12, Kevin Conway wrote: > If the problem with using classes to satisfy the namespace need is > that it's unwieldy to use dot qualified paths then isn't that quite similar > to saying namespaces are unwieldy? Python has a simple solution to that: a = mod.a b = mod.b etc From lawrencedo99 at gmail.com Sun Jul 3 19:25:27 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 16:25:27 -0700 (PDT) Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> Message-ID: <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> On Monday, July 4, 2016 at 10:39:30 AM UTC+12, Ian wrote: > Sorry, but you're the one who doesn't seem to get it. Because it's a > decorator, "your" function is replacing the caller's function in the > caller's namespace. No it is not. The replacement happens here: def generated_decorator(func) : return \ decorator(func, *args, **kwargs) #end generated_decorator As you can see, the function being called, ?decorator?, is supplied by the caller. The function being decorated, ?func?, is supplied by the caller (along with the additional *args and **kwargs). And the returned function is returned *as-is*, so whatever docstring was assigned by the caller is *NOT* ?clobbered?. Once again, the only docstrings I am setting are the ones for functions that *I* generate. Do you understand that yet? From rosuav at gmail.com Sun Jul 3 19:39:35 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jul 2016 09:39:35 +1000 Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> Message-ID: On Mon, Jul 4, 2016 at 9:25 AM, Lawrence D?Oliveiro wrote: > On Monday, July 4, 2016 at 10:39:30 AM UTC+12, Ian wrote: >> Sorry, but you're the one who doesn't seem to get it. Because it's a >> decorator, "your" function is replacing the caller's function in the >> caller's namespace. > > No it is not. The replacement happens here: > > def generated_decorator(func) : > return \ > decorator(func, *args, **kwargs) > #end generated_decorator > > As you can see, the function being called, ?decorator?, is supplied by the caller. The function being decorated, ?func?, is supplied by the caller (along with the additional *args and **kwargs). And the returned function is returned *as-is*, so whatever docstring was assigned by the caller is *NOT* ?clobbered?. > > Once again, the only docstrings I am setting are the ones for functions that *I* generate. > > Do you understand that yet? Yes, in a technical sense, you are correct. It's also technically correct to say that str.upper() doesn't convert its argument to uppercase - it constructs a completely new string of all uppercase letters. But in normal usage, people expect "x = x.upper()" to return *the same string, uppercased*. In the same way, people expect "f = deco(f)" to return *the same function, decorated*. Technically it's generally going to be a new function, because functions are immutable (more-or-less), but it should broadly be the same function. def require_login(f): def modified(*a, **kw): if not logged_in: return "You must be logged in to do this." return f(*a, **kw) return modified @require_login def fire_ze_missiles(): raise Exhausted @require_login def reboot_server(server): """Reboot the specified server""" server.send_command("sudo reboot") Tell me, should the docstring for reboot_server be "Reboot the specified server", or not? If not, why not? ChrisA From eryksun at gmail.com Sun Jul 3 19:46:26 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 3 Jul 2016 23:46:26 +0000 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: On Sun, Jul 3, 2016 at 6:58 AM, John Ladasky wrote: > The nabla symbol (?) is used in the naming of gradients. Python isn't having it. > The interpreter throws a "SyntaxError: invalid character in identifier" when it > encounters the ?. Del is a mathematical operator to take the gradient. It's not part of the name. For `?f`, the operator is `?` and the function name is `f`. Python lacks a mechanism to add user-defined operators. (R has this capability.) Maybe this feature could be added. To make parsing simple, user-defined operators could be limited to non-ASCII symbol characters (math and other -- Sm, So). That simple option is off the table if we allow symbol characters in names. Adding an operator to the language itself requires a PEP. Recently PEP 465 added an `@` operator for matrix products. For example: >>> x = np.array([1j, 1]) >>> x @ x 0j >>> x @ x.conj() # Hermitian inner product (2+0j) Note that using a non-ASCII operator was ruled out: http://legacy.python.org/dev/peps/pep-0465/#choice-of-operator From eryksun at gmail.com Sun Jul 3 19:59:09 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 3 Jul 2016 23:59:09 +0000 Subject: Lost in descriptor land In-Reply-To: <5779301d$0$1600$c3e8da3$5496439d@news.astraweb.com> References: <5a7b6360-5b9b-465c-8401-9a0079048931@googlegroups.com> <7b72a3a0-f0c0-429a-b383-5c3dbfdedba5@googlegroups.com> <5779301d$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 3, 2016 at 3:32 PM, Steven D'Aprano wrote: > > But if you prepare the method ahead of time, it works: > > from types import MethodType > instance.method = MethodType(method, instance) That's a fine way to bind a method, but in the context of this "descriptor land" topic, I think it's more insightful to call the function's __get__ method: >>> type(method) >>> instance.method = method.__get__(instance) >>> type(instance.method) >>> instance.method.__self__ is instance True >>> instance.method.__func__ is method True >>> instance.method() method called from self <__main__.Test object at 0x7faf51d1a198> From lawrencedo99 at gmail.com Sun Jul 3 19:59:26 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 16:59:26 -0700 (PDT) Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> Message-ID: <0b85cc58-0552-41b3-8729-0f037e33c183@googlegroups.com> On Monday, July 4, 2016 at 11:39:56 AM UTC+12, Chris Angelico wrote: > In the same way, people expect "f = deco(f)" to return *the same function, > decorated*. I am not changing that in anyway. The decorated function generated by the caller is returned *unchanged*. Once again, the only docstrings I am setting are for the intermediate functions *I* generate. Suppose we have the following: def try_func(func, arg) : "sample function to be turned into a decorator." def result() : "returns func unchanged." return \ func() #end result #begin try_func result.__name__ = func.__name__ result.__doc__ = func.__doc__ return \ result #end try_func then: >>> f = decorator_with_args(try_func) >>> help(f) Help on function decorate_with_try_func in module decorator_try: decorate_with_try_func(*args, **kwargs) generates a decorator which applies try_func to the given arguments >>> @f(None) ... def g() : ... "my docstring--should be unchanged." ... return \ ... 1 ... #end g ... >>> help(g) Help on function g in module decorator_try: g() my docstring--should be unchanged. Do you understand now? From lawrencedo99 at gmail.com Sun Jul 3 20:00:22 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 17:00:22 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: On Monday, July 4, 2016 at 11:47:26 AM UTC+12, eryk sun wrote: > Python lacks a mechanism to add user-defined operators. (R has this > capability.) Maybe this feature could be added. That would be neat. But remember, you would have to define the operator precedence as well. So you could no longer use a recursive-descent parser. From ian.g.kelly at gmail.com Sun Jul 3 20:01:21 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 3 Jul 2016 18:01:21 -0600 Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> Message-ID: On Sun, Jul 3, 2016 at 5:25 PM, Lawrence D?Oliveiro wrote: > On Monday, July 4, 2016 at 10:39:30 AM UTC+12, Ian wrote: >> Sorry, but you're the one who doesn't seem to get it. Because it's a >> decorator, "your" function is replacing the caller's function in the >> caller's namespace. > > No it is not. The replacement happens here: > > def generated_decorator(func) : > return \ > decorator(func, *args, **kwargs) > #end generated_decorator > > As you can see, the function being called, ?decorator?, is supplied by the caller. The function being decorated, ?func?, is supplied by the caller (along with the additional *args and **kwargs). And the returned function is returned *as-is*, so whatever docstring was assigned by the caller is *NOT* ?clobbered?. I'm talking about the docstring of the *decorator*, not func. I agree that whatever docstring func has is entirely up to func and the decorator, not your code. Here again is the example I posted earlier: >>> @decorator_with_args ... def my_decorator(func, *args, **kwargs): ... """Returns func unmodified.""" ... return func ... >>> my_decorator.__doc__ 'generates a decorator which applies my_decorator to the given arguments' I never made any claim about the docstring of the decorated func. From rosuav at gmail.com Sun Jul 3 20:06:06 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jul 2016 10:06:06 +1000 Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: <0b85cc58-0552-41b3-8729-0f037e33c183@googlegroups.com> References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> <0b85cc58-0552-41b3-8729-0f037e33c183@googlegroups.com> Message-ID: On Mon, Jul 4, 2016 at 9:59 AM, Lawrence D?Oliveiro wrote: > #begin try_func > result.__name__ = func.__name__ > result.__doc__ = func.__doc__ > return \ > result > #end try_func This is the bit we're talking about. You're doing manually what functools.wraps does for you (and it does other stuff too, to make help() more useful), and you weren't doing this before. Your original docstring on result() is completely ignored. ChrisA From lawrencedo99 at gmail.com Sun Jul 3 20:06:19 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 17:06:19 -0700 (PDT) Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> Message-ID: <19025b2c-ba2e-4683-af50-ff208d1e9a49@googlegroups.com> On Monday, July 4, 2016 at 12:02:23 PM UTC+12, Ian wrote: > I'm talking about the docstring of the *decorator*, not func. *Sigh*. Originally somebody was complaining that the lambda version didn?t allow for good (or any) docstrings. So I posted my version, and I went to all the effort of ensuring that every generated function had a good docstring. And now you are trying to knock me down for that? What the hell is wrong with you people?!? From bc at freeuk.com Sun Jul 3 20:17:32 2016 From: bc at freeuk.com (BartC) Date: Mon, 4 Jul 2016 01:17:32 +0100 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: On 04/07/2016 01:00, Lawrence D?Oliveiro wrote: > On Monday, July 4, 2016 at 11:47:26 AM UTC+12, eryk sun wrote: >> Python lacks a mechanism to add user-defined operators. (R has this >> capability.) Maybe this feature could be added. > > That would be neat. But remember, you would have to define the operator precedence as well. So you could no longer use a recursive-descent parser. That wouldn't be a problem provided the new operator symbol and its precedence is known at a compile time, and defined before use. -- Bartc From bc at freeuk.com Sun Jul 3 20:19:34 2016 From: bc at freeuk.com (BartC) Date: Mon, 4 Jul 2016 01:19:34 +0100 Subject: Namespaces are one honking great idea In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> <57788a2f$0$22141$c3e8da3$5496439d@news.astraweb.com> <57789F3D.7000809@stoneleaf.us> Message-ID: On 04/07/2016 00:21, Lawrence D?Oliveiro wrote: > On Monday, July 4, 2016 at 10:02:59 AM UTC+12, Kevin Conway wrote: >> If the problem with using classes to satisfy the namespace need is >> that it's unwieldy to use dot qualified paths then isn't that quite similar >> to saying namespaces are unwieldy? > > Python has a simple solution to that: > > a = mod.a > b = mod.b Except that then a = 0 doesn't do the same thing as: mod.a = 0 But it'll probably work for things that are not assigned to. -- Bartc From ian.g.kelly at gmail.com Sun Jul 3 20:20:12 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 3 Jul 2016 18:20:12 -0600 Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: <19025b2c-ba2e-4683-af50-ff208d1e9a49@googlegroups.com> References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> <19025b2c-ba2e-4683-af50-ff208d1e9a49@googlegroups.com> Message-ID: On Sun, Jul 3, 2016 at 6:06 PM, Lawrence D?Oliveiro wrote: > On Monday, July 4, 2016 at 12:02:23 PM UTC+12, Ian wrote: >> I'm talking about the docstring of the *decorator*, not func. > > *Sigh*. Originally somebody was complaining that the lambda version didn?t allow for good (or any) docstrings. So I posted my version, and I went to all the effort of ensuring that every generated function had a good docstring. And now you are trying to knock me down for that? > > What the hell is wrong with you people?!? Sorry. I don't know who that was or what they wrote, because your post is the first mention of docstrings that I see in this thread. Maybe you're thinking of some other thread. I don't read more than a fraction of what gets posted to this list. But I read your post and I saw a way to improve the code in it, so I suggested it. Next time I won't bother. From lawrencedo99 at gmail.com Sun Jul 3 20:23:45 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 17:23:45 -0700 (PDT) Subject: Meta decorator with parameters, defined in explicit functions In-Reply-To: References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> <0b85cc58-0552-41b3-8729-0f037e33c183@googlegroups.com> Message-ID: On Monday, July 4, 2016 at 12:06:21 PM UTC+12, Chris Angelico wrote: > On Mon, Jul 4, 2016 at 9:59 AM, Lawrence D?Oliveiro wrote: >> #begin try_func >> result.__name__ = func.__name__ >> result.__doc__ = func.__doc__ >> return \ >> result >> #end try_func > > This is the bit we're talking about. This isn?t part of my decoration mechanism, this is just an example of it in use. From lawrencedo99 at gmail.com Sun Jul 3 20:24:57 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 17:24:57 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: <55f1891c-55bc-474a-9d74-ab3efceb5ca1@googlegroups.com> On Monday, July 4, 2016 at 12:17:47 PM UTC+12, BartC wrote: > > On 04/07/2016 01:00, Lawrence D?Oliveiro wrote: >> >> On Monday, July 4, 2016 at 11:47:26 AM UTC+12, eryk sun wrote: >>> >>> Python lacks a mechanism to add user-defined operators. (R has this >>> capability.) Maybe this feature could be added. >> >> That would be neat. But remember, you would have to define the operator >> precedence as well. So you could no longer use a recursive-descent parser. > > That wouldn't be a problem provided the new operator symbol and its > precedence is known at a compile time, and defined before use. That is how it is normally done. (E.g. Algol 68.) But you still couldn?t use a recursive-descent parser. From bc at freeuk.com Sun Jul 3 20:39:58 2016 From: bc at freeuk.com (BartC) Date: Mon, 4 Jul 2016 01:39:58 +0100 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <55f1891c-55bc-474a-9d74-ab3efceb5ca1@googlegroups.com> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <55f1891c-55bc-474a-9d74-ab3efceb5ca1@googlegroups.com> Message-ID: On 04/07/2016 01:24, Lawrence D?Oliveiro wrote: > On Monday, July 4, 2016 at 12:17:47 PM UTC+12, BartC wrote: >> >> On 04/07/2016 01:00, Lawrence D?Oliveiro wrote: >>> >>> On Monday, July 4, 2016 at 11:47:26 AM UTC+12, eryk sun wrote: >>>> >>>> Python lacks a mechanism to add user-defined operators. (R has this >>>> capability.) Maybe this feature could be added. >>> >>> That would be neat. But remember, you would have to define the operator >>> precedence as well. So you could no longer use a recursive-descent parser. >> >> That wouldn't be a problem provided the new operator symbol and its >> precedence is known at a compile time, and defined before use. > > That is how it is normally done. (E.g. Algol 68.) > > But you still couldn?t use a recursive-descent parser. Why not? The structure of such a parser doesn't need to exactly match the grammar with a dedicated block of code for each operator precedence. It can be table-driven so that an operator precedence value is just an attribute. -- Bartc From lawrencedo99 at gmail.com Sun Jul 3 21:15:24 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 3 Jul 2016 18:15:24 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <55f1891c-55bc-474a-9d74-ab3efceb5ca1@googlegroups.com> Message-ID: <61a5c745-91a1-41ab-9681-c122e700dd85@googlegroups.com> On Monday, July 4, 2016 at 12:40:14 PM UTC+12, BartC wrote: > The structure of such a parser doesn't need to exactly match the grammar > with a dedicated block of code for each operator precedence. It can be > table-driven so that an operator precedence value is just an attribute. Of course. But that?s not a recursive-descent parser any more. From steve at pearwood.info Sun Jul 3 21:56:11 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 04 Jul 2016 11:56:11 +1000 Subject: Lost in descriptor land References: <5a7b6360-5b9b-465c-8401-9a0079048931@googlegroups.com> <7b72a3a0-f0c0-429a-b383-5c3dbfdedba5@googlegroups.com> <5779301d$0$1600$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5779c23c$0$1608$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Jul 2016 09:59 am, eryk sun wrote: > On Sun, Jul 3, 2016 at 3:32 PM, Steven D'Aprano > wrote: >> >> But if you prepare the method ahead of time, it works: >> >> from types import MethodType >> instance.method = MethodType(method, instance) > > That's a fine way to bind a method, but in the context of this > "descriptor land" topic, I think it's more insightful to call the > function's __get__ method: Sure, so long as you remember that in real code you shouldn't be calling dunder methods directly. I don't know whether Python does any pre- or post-processing of a descriptor's __get__ method, but it could (if not now, but in the future). -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From random832 at fastmail.com Sun Jul 3 22:16:27 2016 From: random832 at fastmail.com (Random832) Date: Sun, 03 Jul 2016 22:16:27 -0400 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: <1467598587.3816323.655944881.304DB95A@webmail.messagingengine.com> On Sun, Jul 3, 2016, at 20:00, Lawrence D?Oliveiro wrote: > That would be neat. But remember, you would have to define the operator > precedence as well. So you could no longer use a recursive-descent > parser. You could use a recursive-descent parser if you monkey-patch the parser when adding a new operator. From random832 at fastmail.com Sun Jul 3 22:20:50 2016 From: random832 at fastmail.com (Random832) Date: Sun, 03 Jul 2016 22:20:50 -0400 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <61a5c745-91a1-41ab-9681-c122e700dd85@googlegroups.com> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <55f1891c-55bc-474a-9d74-ab3efceb5ca1@googlegroups.com> <61a5c745-91a1-41ab-9681-c122e700dd85@googlegroups.com> Message-ID: <1467598850.3816797.655945753.22F6A744@webmail.messagingengine.com> On Sun, Jul 3, 2016, at 21:15, Lawrence D?Oliveiro wrote: > On Monday, July 4, 2016 at 12:40:14 PM UTC+12, BartC wrote: > > The structure of such a parser doesn't need to exactly match the grammar > > with a dedicated block of code for each operator precedence. It can be > > table-driven so that an operator precedence value is just an attribute. > > Of course. But that?s not a recursive-descent parser any more. It's still recursive descent if it, for example, calls the _same_ block of code recursively with arguments to tell it which operator is being considered. This would be analogous to, in Python, implementing a recursive-descent parser with arbitrary callable objects instead of simple functions. From steve at pearwood.info Sun Jul 3 22:30:42 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 04 Jul 2016 12:30:42 +1000 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> Message-ID: <5779ca54$0$1590$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Jul 2016 10:17 am, BartC wrote: > On 04/07/2016 01:00, Lawrence D?Oliveiro wrote: >> On Monday, July 4, 2016 at 11:47:26 AM UTC+12, eryk sun wrote: >>> Python lacks a mechanism to add user-defined operators. (R has this >>> capability.) Maybe this feature could be added. >> >> That would be neat. But remember, you would have to define the operator >> precedence as well. So you could no longer use a recursive-descent >> parser. > > That wouldn't be a problem provided the new operator symbol and its > precedence is known at a compile time, and defined before use. You're still having problems with the whole Python-as-a-dynamic-language thing, aren't you? :-) In full generality, you would want to be able to define unary prefix, unary suffix and binary infix operators, and set their precedence and whether they associate to the left or the right. That's probably a bit much to expect. But if we limit ourselves to the boring case of binary infix operators of a single precedence and associtivity, there's a simple approach: the parser can allow any unicode code point of category "Sm" as a legal operator, e.g. x ? y. Pre-defined operators like + - * etc continue to call the same dunder methods they already do, but anything else tries calling: x.__oper__('?', y) y.__roper__('?', x) and if neither of those exist and return a result other than NotImplemented, then finally raise a runtime TypeError('undefined operator ?'). But I don't think this will ever be part of Python. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Sun Jul 3 22:33:35 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 04 Jul 2016 12:33:35 +1000 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <28f1731b-438b-47a4-be7b-ef9ab6314394@googlegroups.com> <557e5dc1-b78e-4b6f-8464-b1b43e777e9f@googlegroups.com> Message-ID: <5779caff$0$1590$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Jul 2016 07:28 am, Lawrence D?Oliveiro wrote: > On Monday, July 4, 2016 at 6:39:45 AM UTC+12, John Ladasky wrote: >> Here's another worm for the can. Would you rather read this... >> >> d = sqrt(x**2 + y**2) >> >> ...or this? >> >> d = ?(x? + y?) > > Neither. I would rather see > > d = math.hypot(x, y) > > Much simpler, don?t you think? Only if you think of x and y as the sides of a triangle, and remember that "hypot" is a Unix-like abbreviation for hypotenuse (rather than, say, "hypothesis". And it doesn't help you one bit when it comes to: a = ?(4x?y - 3xy? + 2xy - 1) Personally, I'm not convinced about using the very limited number of superscript code points to represent exponentiation. Using ? as an unary operator looks cute, but I don't know that it adds enough to the language to justify the addition. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ethan at stoneleaf.us Mon Jul 4 00:01:42 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 03 Jul 2016 21:01:42 -0700 Subject: Namespaces are one honking great idea In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577693AC.6090807@stoneleaf.us> <5776a3ef$0$1608$c3e8da3$5496439d@news.astraweb.com> <5776C4A4.5000407@stoneleaf.us> <577713c6$0$1587$c3e8da3$5496439d@news.astraweb.com> <1467435593.1705568.654776673.4D901A33@webmail.messagingengine.com> <57788a2f$0$22141$c3e8da3$5496439d@news.astraweb.com> <57789F3D.7000809@stoneleaf.us> Message-ID: <5779DFA6.9080300@stoneleaf.us> On 07/03/2016 03:02 PM, Kevin Conway wrote: >At some point earlier Ethan Furman declared: >> It's not a language change. > > Perhaps. My argument is that anything that introduces a new class-like > construct and set of lexical scoping rules is a language change. For > example, if this change went into 2.7.13 would Jython suddenly be broken > because it hasn't implemented the new scoping rules? It's not a language change*. There is nothing for Jython, IronPython, Brython, etc., to implement. No scoping rule changes, nothing. The magic in Steven's name space is implemented by the metaclass by (presumably) rebuilding all the functions -- and that is how he manages the effective scoping rules. -- ~Ethan~ *Okay, it is not a language change the same way the addition of Enum was not a language change. On the other hand, asyncio did have some language changes (await, async, etc.). From Brandon.Owen at ga.gov.au Mon Jul 4 00:16:12 2016 From: Brandon.Owen at ga.gov.au (Owen Brandon) Date: Mon, 4 Jul 2016 04:16:12 +0000 Subject: Gzip module does not support Unix compressed .Z files [SEC=UNOFFICIAL] Message-ID: <83cd4362560d4a4aa88bd71eb9c8ce78@win-exch-prod02.prod.lan> Hello, I have a query regarding the support of decompression for Unix compressed .Z files in Python's gzip module. The gzip system utility supports this using the '-d' switch, but the python module does not. Obviously this isn't an actual bug, as the Python module is an implementation of the zlib library (which does not actually specify .Z file decompression). But I'd rather not have to shell out to decompress files if possible - as there currently don't seem to be any core python modules which can decompress .Z files. What are the chances of this functionality being included in a core module at some point? Sorry if this is not the correct forum for questions like this - any help would be appreciated. Kind Regards Brandon Owen GNSS Network Operator | Geodesy and Seismic Monitoring Group Community Safety and Earth Monitoring Division | GEOSCIENCE AUSTRALIA ____________________________________________________________ Phone: +61 2 6249 9192 Fax: +61 2 6249 9999 Email: Brandon.Owen at ga.gov.au Web: www.ga.gov.au Cnr Jerrabomberra Avenue and Hindmarsh Drive Symonston ACT GPO Box 378 Canberra ACT 2601 Australia Applying geoscience to Australia's most important challenges Geoscience Australia Disclaimer: This e-mail (and files transmitted with it) is intended only for the person or entity to which it is addressed. If you are not the intended recipient, then you have received this e-mail by mistake and any use, dissemination, forwarding, printing or copying of this e-mail and its file attachments is prohibited. The security of emails transmitted cannot be guaranteed; by forwarding or replying to this email, you acknowledge and accept these risks. ------------------------------------------------------------------------------------------------------------------------- From rustompmody at gmail.com Mon Jul 4 01:14:45 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Jul 2016 22:14:45 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <5779caff$0$1590$c3e8da3$5496439d@news.astraweb.com> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <28f1731b-438b-47a4-be7b-ef9ab6314394@googlegroups.com> <557e5dc1-b78e-4b6f-8464-b1b43e777e9f@googlegroups.com> <5779caff$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: <242950b0-5bee-43b4-9d6f-08e08cbe6804@googlegroups.com> On Monday, July 4, 2016 at 8:03:47 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 4 Jul 2016 07:28 am, Lawrence D?Oliveiro wrote: > > > On Monday, July 4, 2016 at 6:39:45 AM UTC+12, John Ladasky wrote: > >> Here's another worm for the can. Would you rather read this... > >> > >> d = sqrt(x**2 + y**2) > >> > >> ...or this? > >> > >> d = ?(x? + y?) > > > > Neither. I would rather see > > > > d = math.hypot(x, y) > > > > Much simpler, don?t you think? > > Only if you think of x and y as the sides of a triangle, and remember > that "hypot" is a Unix-like abbreviation for hypotenuse (rather than, > say, "hypothesis". And it doesn't help you one bit when it comes to: > > a = ?(4x?y - 3xy? + 2xy - 1) In math typically one would write a = ?4x?y - 3xy? + 2xy - 1 with the radical sign running along upto and slightly beyond the 1 My unicode prowess is not upto doing that Though experts may be able to use macrons/overlines > > > Personally, I'm not convinced about using the very limited number of > superscript code points to represent exponentiation. Using ? as an unary > operator looks cute, but I don't know that it adds enough to the language > to justify the addition. I guess I am more or less in agreement (on THIS/THESE) ie ? and superscripts is probably not worth the headache Subscripts OTOH as part of identifier-lexemes doesn't seem to have any issues Python3 >>> a? = 1 File "", line 1 a? = 1 ^ SyntaxError: invalid character in identifier Haskell already has it Prelude> let a? = 1 Prelude> a? 1 Prelude> Haskell allows the same for superscripts: Prelude> let a? = 1 Prelude> a? 1 which is probably not such a great idea! Prelude> a? + a? 2 Prelude> My main point being unicode gives a wide repertory -- thats good It also gives char-classification -- thats a start But its not enough for designing a (modern) programming Of course one can stay with ASCII Like "There are many ways to skin a cat" the modern version would be "There are many ways to be a Luddite" From jussi.piitulainen at helsinki.fi Mon Jul 4 02:08:37 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 04 Jul 2016 09:08:37 +0300 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <28f1731b-438b-47a4-be7b-ef9ab6314394@googlegroups.com> <557e5dc1-b78e-4b6f-8464-b1b43e777e9f@googlegroups.com> <5779caff$0$1590$c3e8da3$5496439d@news.astraweb.com> <242950b0-5bee-43b4-9d6f-08e08cbe6804@googlegroups.com> Message-ID: Rustom Mody writes: > Subscripts OTOH as part of identifier-lexemes doesn't seem to have any > issues They have the general issue that one might *want* them interpreted as indexes, so that a? would mean the same as a[1]. Mathematical symbols face similar issues. One would not *want* them all be binary operators; a specific level of precedence would not be good for all uses; and some uses of some symbols need chaining and then parentheses do not help. Just for the starters. > My main point being unicode gives a wide repertory -- thats good > It also gives char-classification -- thats a start > But its not enough for designing a (modern) programming So I agree. Something could be done, but if the intention is to allow mathematical notation, it needs to be done with care. (And no, I'm not saying Python needs to do anything at this time, and I do not express any opinion on how likely Python is to do anything about Unicode math at this time or ever, and so on. Just that I would not be happy to have all those symbols available in a way that is not usable for the intended purpose so please do take care.) From dieter at handshake.de Mon Jul 4 03:57:27 2016 From: dieter at handshake.de (dieter) Date: Mon, 04 Jul 2016 09:57:27 +0200 Subject: Making Classes Subclassable References: Message-ID: <87eg79q1i0.fsf@handshake.de> Lawrence D?Oliveiro writes: > Some of the classes in Qahirah, my Cairo binding I found handy to reuse elsewhere, for example in my binding for Pixman . Subclassing is easy, but then you need to ensure that operations inherited from the superclass return instances of the right class. This means that superclass methods must never refer directly to the class by name for constructing new objects; they need to obtain the current class by more indirect means. --> "type(obj)" or "obj.__class__" (there are small differences) give you the type/class of "obj". From dieter at handshake.de Mon Jul 4 04:00:58 2016 From: dieter at handshake.de (dieter) Date: Mon, 04 Jul 2016 10:00:58 +0200 Subject: Gzip module does not support Unix compressed .Z files [SEC=UNOFFICIAL] References: <83cd4362560d4a4aa88bd71eb9c8ce78@win-exch-prod02.prod.lan> Message-ID: <87a8hxq1c5.fsf@handshake.de> "Owen Brandon" writes: > I have a query regarding the support of decompression for Unix compressed .Z files in Python's gzip module. The gzip system utility supports this using the '-d' switch, but the python module does not. When I am right, then the "zipfile" module handles ".Z" compressed files. From lawrencedo99 at gmail.com Mon Jul 4 04:11:35 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 4 Jul 2016 01:11:35 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <28f1731b-438b-47a4-be7b-ef9ab6314394@googlegroups.com> <557e5dc1-b78e-4b6f-8464-b1b43e777e9f@googlegroups.com> <5779caff$0$1590$c3e8da3$5496439d@news.astraweb.com> <242950b0-5bee-43b4-9d6f-08e08cbe6804@googlegroups.com> Message-ID: <4b69d754-51d7-4e2a-b841-f244757b0566@googlegroups.com> On Monday, July 4, 2016 at 6:08:51 PM UTC+12, Jussi Piitulainen wrote: > Something could be done, but if the intention is to allow > mathematical notation, it needs to be done with care. Mathematics uses single-character variable names so that multiplication can be implicit. An old, stillborn language design from the 1960s called CPL* had two syntaxes for variable names: * a single lowercase letter, optionally followed by any number of primes ?'?; * an uppercase letter followed by letters or digits. It also allowed implicit multiplication; single-letter identifiers could be run together without spaces, but multi-character ones needed to be delimited by spaces or non-identifier characters. E.g. Sqrt(bb - 4ac) Area ? Length Width *It was never fully implemented, but a cut-down derivative named BCPL did get some use. Some researchers at Bell Labs took it as their starting point, first creating a language called ?B?, then another one called ?C? ... well, the rest is history. From lawrencedo99 at gmail.com Mon Jul 4 04:34:02 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 4 Jul 2016 01:34:02 -0700 (PDT) Subject: Making Classes Subclassable In-Reply-To: References: <87eg79q1i0.fsf@handshake.de> Message-ID: <337f8071-ef4a-4ac5-867b-a5320c684730@googlegroups.com> On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: > --> "type(obj)" or "obj.__class__" (there are small differences) > give you the type/class of "obj". When would it not be the same? From marko at pacujo.net Mon Jul 4 05:04:27 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 04 Jul 2016 12:04:27 +0300 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <28f1731b-438b-47a4-be7b-ef9ab6314394@googlegroups.com> <557e5dc1-b78e-4b6f-8464-b1b43e777e9f@googlegroups.com> <5779caff$0$1590$c3e8da3$5496439d@news.astraweb.com> <242950b0-5bee-43b4-9d6f-08e08cbe6804@googlegroups.com> <4b69d754-51d7-4e2a-b841-f244757b0566@googlegroups.com> Message-ID: <87d1mtvko4.fsf@elektro.pacujo.net> Lawrence D?Oliveiro : > Mathematics uses single-character variable names so that > multiplication can be implicit. I don't think anybody developed mathematical notation systematically. Rather, over the centuries, various masters came up with personal abbreviations and shorthand, which spread among admirers and students through emulation. The resulting two-dimensional hodgepodge needs to be supplemented by much natural-language handwaving. Rigorous treatment needs to use a formal language, eg: . Anyway, most programming has little use for mathematics. Thus, a general-purpose programming language shouldn't bend over backwards to placate that particular application domain. Marko From info at egenix.com Mon Jul 4 05:45:20 2016 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 4 Jul 2016 11:45:20 +0200 Subject: =?UTF-8?Q?ANN:_Python_Meeting_D=c3=bcsseldorf_-_06.07.2016?= Message-ID: <577A3030.2050205@egenix.com> [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG Python Meeting D?sseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Mittwoch, 06.07.2016, 18:15 Uhr Raum 1, 2.OG im B?rgerhaus Stadtteilzentrum Bilk D?sseldorfer Arcaden, Bachstr. 145, 40217 D?sseldorf Diese Nachricht ist auch online verf?gbar: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2016-07-06 ________________________________________________________________________ NEUIGKEITEN * Bereits angemeldete Vortr?ge: Stefan Richthofer "JyNI ? Native CPython-Extensions in Jython" Marc-Andre Lemburg "Stand-Alone Applikationen mit eGenix PyRun" Charlie Clark "Eine kurze Einf?hrung in SQLAlchemy: Was es ist und wie man es benutzen kann" Jens Diemer "PyLucid ? ein Open Source CMS auf Django Basis" Weitere Vortr?ge k?nnen gerne noch angemeldet werden: info at pyddf.de * Startzeit und Ort: Wir treffen uns um 18:15 Uhr im B?rgerhaus in den D?sseldorfer Arcaden. Das B?rgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet sich an der Seite der Tiefgarageneinfahrt der D?sseldorfer Arcaden. ?ber dem Eingang steht ein gro?es "Schwimm' in Bilk" Logo. Hinter der T?r direkt links zu den zwei Aufz?gen, dann in den 2. Stock hochfahren. Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt. Google Street View: http://bit.ly/11sCfiw ________________________________________________________________________ EINLEITUNG Das Python Meeting D?sseldorf ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: * http://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus Open Space und Lightning Talks, wobei die Gewitter bei uns auch schon mal 20 Minuten dauern k?nnen ;-). Lightning Talks k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit XGA Aufl?sung steht zur Verf?gung. Lightning Talk Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ KOSTENBETEILIGUNG Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Um die Kosten zumindest teilweise zu refinanzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst, Sch?ler und Studenten zahlen EUR 5,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ________________________________________________________________________ ANMELDUNG Da wir nur f?r ca. 20 Personen Sitzpl?tze haben, m?chten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: http://pyddf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Jul 04 2016) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/ From pdorange at pas-de-pub-merci.mac.com Mon Jul 4 05:50:25 2016 From: pdorange at pas-de-pub-merci.mac.com (Pierre-Alain Dorange) Date: Mon, 4 Jul 2016 11:50:25 +0200 Subject: Creating a calculator References: <1mpph6r.u6n05219srlzsN%pdorange@pas-de-pub-merci.mac.com> Message-ID: <1mpuual.1m44kff1kknqueN%pdorange@pas-de-pub-merci.mac.com> DFS wrote: > > 2 lines? Love it! > > But apparently eval==evil. > > http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html > > I bet you get hammered about it here on clp. It was a software to be deploy, it was just for educational purpose. -- Pierre-Alain Dorange Moof Ce message est sous licence Creative Commons "by-nc-sa-2.0" From bc at freeuk.com Mon Jul 4 06:05:03 2016 From: bc at freeuk.com (BartC) Date: Mon, 4 Jul 2016 11:05:03 +0100 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <5779ca54$0$1590$c3e8da3$5496439d@news.astraweb.com> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <5779ca54$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/07/2016 03:30, Steven D'Aprano wrote: > On Mon, 4 Jul 2016 10:17 am, BartC wrote: > >> On 04/07/2016 01:00, Lawrence D?Oliveiro wrote: >>> On Monday, July 4, 2016 at 11:47:26 AM UTC+12, eryk sun wrote: >>>> Python lacks a mechanism to add user-defined operators. (R has this >>>> capability.) Maybe this feature could be added. >>> >>> That would be neat. But remember, you would have to define the operator >>> precedence as well. So you could no longer use a recursive-descent >>> parser. >> >> That wouldn't be a problem provided the new operator symbol and its >> precedence is known at a compile time, and defined before use. > > You're still having problems with the whole Python-as-a-dynamic-language > thing, aren't you? :-) Well it isn't completely dynamic, not unless code only exists as a eval or exec argument string (and even there, any changes will only be seen on calling eval or exec again on the same string). Most Pythons seem to pre-compile code before executing the result. That pre-compilation requires that operators and precedences are known in advance and the resulting instructions are then hard-coded before execution. > In full generality, you would want to be able to define unary prefix, unary > suffix and binary infix operators, and set their precedence and whether > they associate to the left or the right. That's probably a bit much to > expect. No, that's all possible. Maybe that's even how some language implementations work, defining all the set of standard operators at the start. > But if we limit ourselves to the boring case of binary infix operators of a > single precedence and associtivity, there's a simple approach: the parser > can allow any unicode code point of category "Sm" as a legal operator, e.g. > x ? y. Pre-defined operators like + - * etc continue to call the same > dunder methods they already do, but anything else tries calling: > > x.__oper__('?', y) > y.__roper__('?', x) > > and if neither of those exist and return a result other than NotImplemented, > then finally raise a runtime TypeError('undefined operator ?'). A simpler approach is to treat user-defined operators as aliases for functions: def myadd(a,b): return a+b operator ?: (myadd,2,+3) # map to myadd, 2 operands, prio 3, LTR x = y ? z is then equivalent to: x = myadd(y,z) However you will usually want to be able overload the same operator for different operand types. That means mapping the operator to one of several methods. Maybe even allowing the operator to have either one or two operands. Trickier but still doable I think. -- Bartc From jussi.piitulainen at helsinki.fi Mon Jul 4 06:10:36 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 04 Jul 2016 13:10:36 +0300 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <28f1731b-438b-47a4-be7b-ef9ab6314394@googlegroups.com> <557e5dc1-b78e-4b6f-8464-b1b43e777e9f@googlegroups.com> <5779caff$0$1590$c3e8da3$5496439d@news.astraweb.com> <242950b0-5bee-43b4-9d6f-08e08cbe6804@googlegroups.com> <4b69d754-51d7-4e2a-b841-f244757b0566@googlegroups.com> Message-ID: Lawrence D?Oliveiro writes: > On Monday, July 4, 2016 at 6:08:51 PM UTC+12, Jussi Piitulainen wrote: >> Something could be done, but if the intention is to allow >> mathematical notation, it needs to be done with care. > > Mathematics uses single-character variable names so that > multiplication can be implicit. Certainly on topic, though independent of Unicode. I was thinking of different classes of operator symbols. > An old, stillborn language design from the 1960s called CPL* had two > syntaxes for variable names: > * a single lowercase letter, optionally followed by any number of primes ?'?; > * an uppercase letter followed by letters or digits. > > It also allowed implicit multiplication; single-letter identifiers > could be run together without spaces, but multi-character ones needed > to be delimited by spaces or non-identifier characters. E.g. > > Sqrt(bb - 4ac) > Area ? Length Width > > *It was never fully implemented, but a cut-down derivative named BCPL > did get some use. Some researchers at Bell Labs took it as their > starting point, first creating a language called ?B?, then another one > called ?C? ... well, the rest is history. There's been at least D, F, J, K (APL family), R, S (_before_ R), T (a Lisp), X (the window system), Z (some specification language). Any single-letter non-ASCII names yet? Spelled-out like Lambda and Omega don't count. From zhangyangyu0614 at gmail.com Mon Jul 4 06:22:47 2016 From: zhangyangyu0614 at gmail.com (Xiang Zhang) Date: Mon, 4 Jul 2016 03:22:47 -0700 (PDT) Subject: Special attributes added to classes on creation In-Reply-To: <57793711$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <57793711$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, July 4, 2016 at 12:02:41 AM UTC+8, Steven D'Aprano wrote: > I have some code which can preprocess (using a metaclass) or postprocess > (using a decorator) a class: > > @process > class K: > pass > > > class K(metaclass=process): > pass > > > Both should give the same result, but I have found that the results are > slightly different because the dict passed to process as a metaclass is > different from the the class dict seen by the decorator. I can demonstrate > the difference in Python 3.6 by using this metaclass/decorator: > > class process(type): > def __new__(meta, *args): > if len(args) == 1: > # decorator usage > cls = args[0] > d = cls.__dict__ > elif len(args) == 3: > # metaclass usage > name, bases, d = args > cls = super().__new__(meta, *args) > print(sorted(d.keys())) > return cls > > > If I then try it against two identical (apart from their names) classes, I > get these results: > > > py> @process > ... class K: > ... x = 1 > ... > ['__dict__', '__doc__', '__module__', '__weakref__', 'x'] > py> class Q(metaclass=process): > ... x = 1 > ... > ['__module__', '__qualname__', 'x'] > > > > Now if I check the newly created Q, I see the same keys K has: > > py> sorted(Q.__dict__.keys()) > ['__dict__', '__doc__', '__module__', '__weakref__', 'x'] > > > Is there any documentation for exactly what keys are added to classes when? > > > > > -- > Steven > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. eryk sun has a very good explanation. I want to add two points: 1. __qualname__ though passed in class creation, but it won't appear in the class.__dict__ since it is deliberately deleted from __dict__ in type_new. 2. __dict__ and __weakref__ are possible to be added even when there is not __slots__. __dict__ can be added when the base class's dictoffset == 0 and __weakref__ can be added when the base class's weakrefoffset == 0 && tp_itemsize == 0. An example is: In [2]: class T(int): ...: pass ...: In [3]: T.__dict__ Out[3]: mappingproxy({'__module__': '__main__', '__dict__': , '__doc__': None}) I think this is a nice design in attribute searching. BTW, I think this is a implementation detail. If you rely on it, it may easily break in the future. From bc at freeuk.com Mon Jul 4 06:26:27 2016 From: bc at freeuk.com (BartC) Date: Mon, 4 Jul 2016 11:26:27 +0100 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <61a5c745-91a1-41ab-9681-c122e700dd85@googlegroups.com> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <55f1891c-55bc-474a-9d74-ab3efceb5ca1@googlegroups.com> <61a5c745-91a1-41ab-9681-c122e700dd85@googlegroups.com> Message-ID: On 04/07/2016 02:15, Lawrence D?Oliveiro wrote: > On Monday, July 4, 2016 at 12:40:14 PM UTC+12, BartC wrote: >> The structure of such a parser doesn't need to exactly match the grammar >> with a dedicated block of code for each operator precedence. It can be >> table-driven so that an operator precedence value is just an attribute. > > Of course. But that?s not a recursive-descent parser any more. > All the parsers I write work the same way. If I can't describe them as recursive descent, then I don't know what they are. This is just recognising that a bunch of specialised functions that are very similar can be reduced to one or two more generalised ones. -- bartc From jussi.piitulainen at helsinki.fi Mon Jul 4 06:26:35 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 04 Jul 2016 13:26:35 +0300 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <5779ca54$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: BartC writes: > A simpler approach is to treat user-defined operators as aliases for > functions: > > def myadd(a,b): > return a+b > > operator ?: > (myadd,2,+3) # map to myadd, 2 operands, prio 3, LTR > > x = y ? z > > is then equivalent to: > > x = myadd(y,z) > > However you will usually want to be able overload the same operator > for different operand types. That means mapping the operator to one of > several methods. Maybe even allowing the operator to have either one > or two operands. > > Trickier but still doable I think. Julia does something like that. The parser knows a number of symbols that it treats as operators, some of them are aliases for ASCII names, all operators correspond to generic functions, and the programmer can add methods for their own types (or for pre-existing types) to these functions. Prolog opens its precedence table for the programmer. I don't know if there's been any Unicode activity, or any activity, in recent years, but there are actually two different issues here: what is parsed as an identifier, and what identifiers are treated as operator symbols (with what precedence and associativity). From antoon.pardon at rece.vub.ac.be Mon Jul 4 06:32:31 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 4 Jul 2016 12:32:31 +0200 Subject: Creating a calculator In-Reply-To: <577675ae$0$1604$c3e8da3$5496439d@news.astraweb.com> References: <0E77E5BC-E8CC-4951-B520-37BF2E596D3A@icloud.com> <577675ae$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <577A3B3F.7030708@rece.vub.ac.be> Op 01-07-16 om 15:52 schreef Steven D'Aprano: > On Fri, 1 Jul 2016 10:25 pm, Christopher Reimer wrote: > >> For my BASIC interpreter, each line of BASIC is broken this way into >> tokens. > [...] >> By using * to unpack the split line, my program no longer crashes and no >> try/except block is needed to work around the crash. A later line of code >> will test the expression, ignore if empty or run regex if full. > I wish you wouldn't describe this as "crash". I wish you wouldn't mix semantic levels. > > The Python interpreter should never crash. That would be a segmentation > fault, and that is considered to be a very serious bug. But in that case your computer didn't crash. That would be a your computer freezing, or rebooting. > > But *raising an exception* is another story. Raising exceptions is not a > crash, it is the interpreter working as expected. This statement: A segment violation is not a crash either, your computer/os will just carry on. > > line_number, keyword, expr = "20 END".split(' ', 2) > > is SUPPOSED to raise an exception, if it didn't, the interpreter would be > broken. To call that a "crash" is horribly misleading. Supposed by whom? The line may be supposed to raise an exception by the languager designer, that doesn't mean the programmer meant to write an instruction that would raise an exception. So the programmer can correctly assert the line was not supposed to raise an exception. -- Antoon. From jeanmichel at sequans.com Mon Jul 4 07:23:17 2016 From: jeanmichel at sequans.com (jmp) Date: Mon, 04 Jul 2016 13:23:17 +0200 Subject: Namespaces are one honking great idea In-Reply-To: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07/01/2016 04:13 PM, Steven D'Aprano wrote: > But classes are not like the others: they must be instantiated before they > can be used, and they are more than just a mere namespace grouping related > entities. Classes support inheritance. Classes should be used for "is-a" > relationships, not "has-a" relationships. Although classes (and instances) > are namespaces, they provide fundamentally different kind of behaviour than > modules and packages. A namespace would not hurt but I really don't get why you don't consider classes a valid and rather helpful namespace. 1/ classes do not have to be instantiated. 2/ the fact that classes are more than a namespace is not an argument. Almost any object in python is able to do more than what you are actually using. 3/ Classes are used as much as 'is-a' than 'has-a', class instances *have* a state usually described by attributes 4/ "Although classes (and instances) are namespaces, ". You seem to contradict yourself. It was probably a rhetorical construct but it's rather confusing. jm From jornws0718 at xs4all.nl Mon Jul 4 07:24:22 2016 From: jornws0718 at xs4all.nl (Oscar) Date: 04 Jul 2016 11:24:22 GMT Subject: Spot the bug: getoptquestion.py Message-ID: <577a4766$0$5839$e4fe514c@news.xs4all.nl> Is this: a) a bug in getopt.getopt b) a bug in my code c) a great way to keep me busy for a while d) all of the above? #!/usr/bin/python from __future__ import print_function from getopt import getopt, GetoptError import sys try: opts, args = getopt(sys.argv[1:], 'b', ['bug ']) except GetoptError as err: print('Caught:', repr(err)) else: if opts: for opt, arg in opts: if opt in ('-b', '--bug'): print ("Ceci n'est pas un bug!") else: #print ('Missed option: "{0}"'.format(opt)) print ('Missed option:', opt) else: print('Usage:', sys.argv[0],'-b|--bug') -- [J|O|R] <- .signature.gz From rosuav at gmail.com Mon Jul 4 07:36:13 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jul 2016 21:36:13 +1000 Subject: Spot the bug: getoptquestion.py In-Reply-To: <577a4766$0$5839$e4fe514c@news.xs4all.nl> References: <577a4766$0$5839$e4fe514c@news.xs4all.nl> Message-ID: On Mon, Jul 4, 2016 at 9:24 PM, Oscar wrote: > Is this: > > a) a bug in getopt.getopt > b) a bug in my code > c) a great way to keep me busy for a while > d) all of the above? > > > #!/usr/bin/python > > from __future__ import print_function > from getopt import getopt, GetoptError > import sys > > try: > opts, args = getopt(sys.argv[1:], 'b', ['bug ']) > > except GetoptError as err: > print('Caught:', repr(err)) > > else: > if opts: > for opt, arg in opts: > > if opt in ('-b', '--bug'): > print ("Ceci n'est pas un bug!") > else: > #print ('Missed option: "{0}"'.format(opt)) > print ('Missed option:', opt) > else: > print('Usage:', sys.argv[0],'-b|--bug') Well, first thing I'd do is wipe out your try/except. It's not really achieving much (you effectively catch an exception to print it to the console and terminate). But then what I'm seeing is that you have 'bug ' (with a trailing space) in your list of long options, so getopt returns '--bug ' as a long option. Is that a bug? I dunno. Why do you have the trailing space? In any case, it's pretty easy to see if you change one line of your code to: print('Missed option: %r' % opt) ChrisA From rosuav at gmail.com Mon Jul 4 07:37:28 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jul 2016 21:37:28 +1000 Subject: Namespaces are one honking great idea In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jul 4, 2016 at 9:23 PM, jmp wrote: > On 07/01/2016 04:13 PM, Steven D'Aprano wrote: >> >> But classes are not like the others: they must be instantiated before they >> can be used, and they are more than just a mere namespace grouping related >> entities. Classes support inheritance. Classes should be used for "is-a" >> relationships, not "has-a" relationships. Although classes (and instances) >> are namespaces, they provide fundamentally different kind of behaviour >> than >> modules and packages. > > > A namespace would not hurt but I really don't get why you don't consider > classes a valid and rather helpful namespace. > > 1/ classes do not have to be instantiated. > 2/ the fact that classes are more than a namespace is not an argument. > Almost any object in python is able to do more than what you are actually > using. > 3/ Classes are used as much as 'is-a' than 'has-a', class instances *have* a > state usually described by attributes > 4/ "Although classes (and instances) are namespaces, ". You seem to > contradict yourself. It was probably a rhetorical construct but it's rather > confusing. Functions within the namespace can't call other functions within the same namespace using unqualified names. This was a stated requirement. ChrisA From rustompmody at gmail.com Mon Jul 4 08:16:33 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Jul 2016 05:16:33 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <55f1891c-55bc-474a-9d74-ab3efceb5ca1@googlegroups.com> <61a5c745-91a1-41ab-9681-c122e700dd85@googlegroups.com> Message-ID: <7cafb1f4-9914-4820-b76b-453d6f598886@googlegroups.com> On Monday, July 4, 2016 at 3:56:43 PM UTC+5:30, BartC wrote: > On 04/07/2016 02:15, Lawrence D?Oliveiro wrote: > > On Monday, July 4, 2016 at 12:40:14 PM UTC+12, BartC wrote: > >> The structure of such a parser doesn't need to exactly match the grammar > >> with a dedicated block of code for each operator precedence. It can be > >> table-driven so that an operator precedence value is just an attribute. > > > > Of course. But that?s not a recursive-descent parser any more. > > > > All the parsers I write work the same way. If I can't describe them as > recursive descent, then I don't know what they are. > > This is just recognising that a bunch of specialised functions that are > very similar can be reduced to one or two more generalised ones. In gofer (likewise Haskell) one can concoct any operator and give it a precedence and associativity -- l,r,non Internals of Haskell I do not know, but of gofer I can say the following: Implementation is in C. Uses yacc to parse all operators left-assoc, same precedence Then post-processes the tree with an elegant little shift-reduce parser based on specified precedences and associativities. I sometimes teach this to my kids as an example of how FP-style comments can clarify arcane imperative code: Mark Jones (gofer author) original version + My version made executable http://blog.languager.org/2016/07/a-little-functional-parser.html From jornws0718 at xs4all.nl Mon Jul 4 08:38:17 2016 From: jornws0718 at xs4all.nl (Oscar) Date: 04 Jul 2016 12:38:17 GMT Subject: Spot the bug: getoptquestion.py References: <577a4766$0$5839$e4fe514c@news.xs4all.nl> Message-ID: <577a58b9$0$5902$e4fe514c@news.xs4all.nl> In article , Chris Angelico wrote: >On Mon, Jul 4, 2016 at 9:24 PM, Oscar wrote: >> Is this: >> >> a) a bug in getopt.getopt >> b) a bug in my code >> c) a great way to keep me busy for a while >> d) all of the above? >> >> >> #!/usr/bin/python >> >> from __future__ import print_function >> from getopt import getopt, GetoptError >> import sys >> >> try: >> opts, args = getopt(sys.argv[1:], 'b', ['bug ']) >> >> except GetoptError as err: >> print('Caught:', repr(err)) >> >> else: >> if opts: >> for opt, arg in opts: >> >> if opt in ('-b', '--bug'): >> print ("Ceci n'est pas un bug!") >> else: >> #print ('Missed option: "{0}"'.format(opt)) >> print ('Missed option:', opt) >> else: >> print('Usage:', sys.argv[0],'-b|--bug') > >Well, first thing I'd do is wipe out your try/except. It's not really >achieving much (you effectively catch an exception to print it to the >console and terminate). It does something: it shows that --bug on my commandline did not throw an GetoptError. I could post the whole 400 line script, but decided to cut it down to a demonstration of a subtle bug that i introduced in my script. So far, answers b) and c) certainly do apply. >But then what I'm seeing is that you have 'bug ' (with a trailing >space) in your list of long options, so getopt returns '--bug ' as a >long option. You found it much faster than I did! ;-) As i learned now, --b and --bu will also match '--bug ', as they are not ambigous. So, of course '--bug' also returns '--bug ' in opts. But it took me quite a while before I found my logic wasn't working further down the script, just because I somehow introduced a space character somewhere where it shouldn't have been. > Is that a bug? I dunno. Why do you have the trailing >space? Because I'm stupid. It should not have been there at all. I've been readjusting and reformatting my long 'getopt' line all day long and somewhere my thumb must have hit my spacebar when I wasn't paying attention. So a hard-to-find bug (for me at least) was introduced. Now I also did not spot the trailing space in the loop where I was evaluating the options when I added some debug statements. This sure got me scratching my head. The option is there, why doesn't my code do what it's supposed to do? I sure was looking in the wrong place. I better use repr() for debugging purposes next time. Thanks for the tip. But is this not at least a bit unexpected behaviour from getopt? On one hand, if I want to have trailing spaces in my longoptions, why not just play along and allow them? On the other hand, a space is a delimiter on the commandline. Does it make sense to allow it as a parameter to getopt()? And if getopt would silently strip it, would that be a bug? I agree that it's hard to debate wheter it is a bug, but I wanted to share this experience anyway... ;-) > In any case, it's pretty easy to see if you change one line of >your code to: >print('Missed option: %r' % opt) Or uncomment my hint in the OP. But repr() is even better indeed. -- [J|O|R] <- .signature.gz From ned at nedbatchelder.com Mon Jul 4 08:47:59 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 4 Jul 2016 05:47:59 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <5779ca54$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, July 4, 2016 at 6:05:20 AM UTC-4, BartC wrote: > On 04/07/2016 03:30, Steven D'Aprano wrote: > > On Mon, 4 Jul 2016 10:17 am, BartC wrote: > > > >> On 04/07/2016 01:00, Lawrence D?Oliveiro wrote: > >>> On Monday, July 4, 2016 at 11:47:26 AM UTC+12, eryk sun wrote: > >>>> Python lacks a mechanism to add user-defined operators. (R has this > >>>> capability.) Maybe this feature could be added. > >>> > >>> That would be neat. But remember, you would have to define the operator > >>> precedence as well. So you could no longer use a recursive-descent > >>> parser. > >> > >> That wouldn't be a problem provided the new operator symbol and its > >> precedence is known at a compile time, and defined before use. > > > > You're still having problems with the whole Python-as-a-dynamic-language > > thing, aren't you? :-) > > Well it isn't completely dynamic, not unless code only exists as a eval > or exec argument string (and even there, any changes will only be seen > on calling eval or exec again on the same string). > > Most Pythons seem to pre-compile code before executing the result. That > pre-compilation requires that operators and precedences are known in > advance and the resulting instructions are then hard-coded before execution. This is the key but subtle point that all the discussion of parser mechanics are missing: Python today needs no information from imported modules in order to compile a file. When the compiler encounters "import xyzzy" in a file, it doesn't have to do anything to find or read xyzzy.py at compile time. If operators can be invented, they will only be useful if they can be created in modules which you then import and use. But that would mean that imported files would have to be found and read during compilation, not during execution as they are now. This is a huge change. --Ned. From rosuav at gmail.com Mon Jul 4 09:42:25 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Jul 2016 23:42:25 +1000 Subject: Spot the bug: getoptquestion.py In-Reply-To: <577a58b9$0$5902$e4fe514c@news.xs4all.nl> References: <577a4766$0$5839$e4fe514c@news.xs4all.nl> <577a58b9$0$5902$e4fe514c@news.xs4all.nl> Message-ID: On Mon, Jul 4, 2016 at 10:38 PM, Oscar wrote: > But is this not at least a bit unexpected behaviour from getopt? On one > hand, if I want to have trailing spaces in my longoptions, why not just > play along and allow them? On the other hand, a space is a delimiter on > the commandline. Does it make sense to allow it as a parameter to > getopt()? And if getopt would silently strip it, would that be a bug? > This is really the crux of the matter. Honestly, I've no idea. The getopt module is designed to match the C getopt function, which I've never used; for my command-line parsing, I use argparse instead (usually via some wrapper that cuts down the duplication, like clize). ChrisA From omastroi at gmail.com Mon Jul 4 09:46:04 2016 From: omastroi at gmail.com (TM) Date: Mon, 4 Jul 2016 09:46:04 -0400 Subject: Need help compiling Python-devel Message-ID: Hi, I have successfully compiled Python-2.7.12 on AIX 6.1 TL09, using steps below. However I need the python-devel library/headers. How do I compile Python, so that I can use this? # ./configure --with-gcc="gcc" --with-cxx="gcc" --disable-ipv6 # make Any help is greatly appreciated. Thanks, Tony From mal at europython.eu Mon Jul 4 09:48:41 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Mon, 4 Jul 2016 15:48:41 +0200 Subject: EuroPython 2016: Please configure your tickets Message-ID: <577A6939.3060901@europython.eu> The EuroPython website supports buying tickets for other people (friends, colleagues, etc.). As a result, it is necessary to assign the tickets you buy to either yourself or someone else. The assignment process is explained below. Please tell us your preferences ------------------------------- The reason we?re interested in you applying this configuration as soon as possible, is that the tickets include a number of preferences which we need to know about in order to properly prepare the conference. When assigning tickets you will fill some fields, telling us your t-shirt size and cut (women or men style) and your diet preferences. If you don?t provide this information, we cannot assure we?ll have the right t-shirt available for you. Likewise, if you are vegetarian, it is important to mark this in the preferences, so that we can order enough vegetarian food. How to assign tickets to attendees ---------------------------------- First you need to log in and go to your profile and, if you already bought your tickets, you will see something similar to this. Click on "View your tickets". After you have navigated to the tickets, we need you to assign the ticket: simply hover over the ticket and you will see two options. Please select, if the ticket is for you or for someone else. Remember: Before assigning the ticket the other persons, these must be registered on the website. Otherwise, the assignment won?t work. If you have assigned the tickets to someone else, please let them know. The system will send out automatic emails, but it?s safer to send a separate email so that the information doesn?t get lost in a spam filter. How to edit the fields of the tickets ------------------------------------- After assigning the ticket, each attendee will need to fill out the ticket preferences using his/her profile page (don?t forget to click save to store the settings). Some additional help for the preference form: * Tagline: This line will appear after you name. Be original! * Diet: Omnivorous, Vegetarian or Other (we?ll try to provide food for other diets as well) * Python experience: Whats your experience level with Python? You can also enter ?no comment?, if you prefer not to make this information public. * Dates: Which days do you plan to attend. This is not binding in any way, it just helps us to better prepare for the conference. With gravitational regards, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/749960553280528384 Thanks. From robert.kern at gmail.com Mon Jul 4 10:18:25 2016 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 4 Jul 2016 15:18:25 +0100 Subject: Gzip module does not support Unix compressed .Z files [SEC=UNOFFICIAL] In-Reply-To: <87a8hxq1c5.fsf@handshake.de> References: <83cd4362560d4a4aa88bd71eb9c8ce78@win-exch-prod02.prod.lan> <87a8hxq1c5.fsf@handshake.de> Message-ID: On 2016-07-04 09:00, dieter wrote: > "Owen Brandon" writes: > >> I have a query regarding the support of decompression for Unix compressed .Z files in Python's gzip module. The gzip system utility supports this using the '-d' switch, but the python module does not. > > When I am right, then the "zipfile" module handles ".Z" compressed files. No, that handles PKZIP .zip files. There are third-party modules that handle the .Z format, but shelling out to external programs may still be preferable: https://github.com/umeat/unlzw -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From bc at freeuk.com Mon Jul 4 10:36:34 2016 From: bc at freeuk.com (BartC) Date: Mon, 4 Jul 2016 15:36:34 +0100 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <5779ca54$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 04/07/2016 13:47, Ned Batchelder wrote: > On Monday, July 4, 2016 at 6:05:20 AM UTC-4, BartC wrote: >> On 04/07/2016 03:30, Steven D'Aprano wrote: >>> You're still having problems with the whole Python-as-a-dynamic-language >>> thing, aren't you? :-) >> Most Pythons seem to pre-compile code before executing the result. That >> pre-compilation requires that operators and precedences are known in >> advance and the resulting instructions are then hard-coded before execution. > > This is the key but subtle point that all the discussion of parser mechanics > are missing: Python today needs no information from imported modules in > order to compile a file. When the compiler encounters "import xyzzy" in > a file, it doesn't have to do anything to find or read xyzzy.py at compile > time. Yeah, there's that small detail. Anything affecting how source is to be parsed needs to known in advance. > If operators can be invented, they will only be useful if they can be > created in modules which you then import and use. But that would mean that > imported files would have to be found and read during compilation, not > during execution as they are now. > > This is a huge change. I've used a kind of 'weak' import scheme elsewhere, corresponding to C's '#include'. Then the textual contents of that 'imported' module are read by the compiler, and treated as though they occurred in this module. No new namespace is created. I think that could work in Python provided whatever is defined can tolerate having copies redefined in each module that includes the same file. Anything that is defined once and is never assigned to nor modified for example. -- Bartc From ned at nedbatchelder.com Mon Jul 4 10:46:09 2016 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 4 Jul 2016 07:46:09 -0700 (PDT) Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <5779ca54$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: <90b6c6e7-b1b8-4c0b-b29e-7ee0dd2a6983@googlegroups.com> On Monday, July 4, 2016 at 10:36:54 AM UTC-4, BartC wrote: > On 04/07/2016 13:47, Ned Batchelder wrote: > > On Monday, July 4, 2016 at 6:05:20 AM UTC-4, BartC wrote: > >> On 04/07/2016 03:30, Steven D'Aprano wrote: > > >>> You're still having problems with the whole Python-as-a-dynamic-language > >>> thing, aren't you? :-) > > >> Most Pythons seem to pre-compile code before executing the result. That > >> pre-compilation requires that operators and precedences are known in > >> advance and the resulting instructions are then hard-coded before execution. > > > > This is the key but subtle point that all the discussion of parser mechanics > > are missing: Python today needs no information from imported modules in > > order to compile a file. When the compiler encounters "import xyzzy" in > > a file, it doesn't have to do anything to find or read xyzzy.py at compile > > time. > > Yeah, there's that small detail. Anything affecting how source is to be > parsed needs to known in advance. > > > If operators can be invented, they will only be useful if they can be > > created in modules which you then import and use. But that would mean that > > imported files would have to be found and read during compilation, not > > during execution as they are now. > > > > This is a huge change. > > I've used a kind of 'weak' import scheme elsewhere, corresponding to C's > '#include'. > > Then the textual contents of that 'imported' module are read by the > compiler, and treated as though they occurred in this module. No new > namespace is created. > > I think that could work in Python provided whatever is defined can > tolerate having copies redefined in each module that includes the same > file. Anything that is defined once and is never assigned to nor > modified for example. You are hand-waving over huge details of semantics that are very important in Python. For example, it is very important not to have copies of classes. Importing a module must produce the same module object everywhere it is imported, and the classes defined in the module must be defined only once. This is what makes catching exceptions work (because it is based on an exception being an instance of a particular class), and what makes class attributes shared among all the instances of the class. --Ned. From marco.buttu at gmail.com Mon Jul 4 11:48:34 2016 From: marco.buttu at gmail.com (Marco Buttu) Date: Mon, 04 Jul 2016 17:48:34 +0200 Subject: file.seek() and file.tell() look inconsistent to me Message-ID: Hi all, if I open a file in text mode, do you know why file.seek() returns the number of bytes, and file.tell() takes the number of bytes? I was expecting the number of characters, like write() does: >>> f = open('myfile', 'w') >>> f.write('a?') 2 It seems to me not consistent, and maybe could also be error prone: >>> f.seek(2) 2 >>> f.write('c') 1 >>> f.close() >>> open('myfile').read() ... UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3... -- Marco Buttu From jeanmichel at sequans.com Mon Jul 4 11:58:30 2016 From: jeanmichel at sequans.com (jmp) Date: Mon, 04 Jul 2016 17:58:30 +0200 Subject: Namespaces are one honking great idea In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 07/04/2016 01:37 PM, Chris Angelico wrote: > On Mon, Jul 4, 2016 at 9:23 PM, jmp wrote: >> On 07/01/2016 04:13 PM, Steven D'Aprano wrote: >>> >>> But classes are not like the others: they must be instantiated before they >>> can be used, and they are more than just a mere namespace grouping related >>> entities. Classes support inheritance. Classes should be used for "is-a" >>> relationships, not "has-a" relationships. Although classes (and instances) >>> are namespaces, they provide fundamentally different kind of behaviour >>> than >>> modules and packages. >> >> >> A namespace would not hurt but I really don't get why you don't consider >> classes a valid and rather helpful namespace. >> >> 1/ classes do not have to be instantiated. >> 2/ the fact that classes are more than a namespace is not an argument. >> Almost any object in python is able to do more than what you are actually >> using. >> 3/ Classes are used as much as 'is-a' than 'has-a', class instances *have* a >> state usually described by attributes >> 4/ "Although classes (and instances) are namespaces, ". You seem to >> contradict yourself. It was probably a rhetorical construct but it's rather >> confusing. > > Functions within the namespace can't call other functions within the > same namespace using unqualified names. This was a stated requirement. > > ChrisA > Ho, I missed that one. But if it's the only missing requirement, wouldn't be like stating that python instances are not instances because methods cannot call other methods without "self."ed qualified name ? We like explicit qualified stuff in python right ? ("explicit is better than implicit") jm From 8smolen at tds.net Mon Jul 4 12:07:36 2016 From: 8smolen at tds.net (Michael Smolen) Date: Mon, 4 Jul 2016 10:07:36 -0600 Subject: Structure of program development Message-ID: <95C250EE0EE1485FAB159FFB82C178BB@mike> Folks: I am new to this programming adventure. I've gotten past the introductory chapters in 'How to..." books and now want to start developing a much more complicated program that I will use repeated for different applications. When I worked in Perl there was an option to write a program in a text editor, save it, and then run in with Perl. Is such a thing possible in Python? If not, how do I develop a 500+ lines of code? A second question of the basic design. If I write a program, can I move it to a computer that is without any Python software, or does that machine have to download the Python software? Does Python products contain all parts of a developed program or is it a series of 'call' statements? Thanks. Mike From bc at freeuk.com Mon Jul 4 12:16:56 2016 From: bc at freeuk.com (BartC) Date: Mon, 4 Jul 2016 17:16:56 +0100 Subject: Well, I finally ran into a Python Unicode problem, sort of In-Reply-To: <90b6c6e7-b1b8-4c0b-b29e-7ee0dd2a6983@googlegroups.com> References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <5779ca54$0$1590$c3e8da3$5496439d@news.astraweb.com> <90b6c6e7-b1b8-4c0b-b29e-7ee0dd2a6983@googlegroups.com> Message-ID: On 04/07/2016 15:46, Ned Batchelder wrote: > On Monday, July 4, 2016 at 10:36:54 AM UTC-4, BartC wrote: >> On 04/07/2016 13:47, Ned Batchelder wrote: >>> This is a huge change. >> >> I've used a kind of 'weak' import scheme elsewhere, corresponding to C's >> '#include'. >> I think that could work in Python provided whatever is defined can >> tolerate having copies redefined in each module that includes the same >> file. Anything that is defined once and is never assigned to nor >> modified for example. > > You are hand-waving over huge details of semantics that are very important > in Python. For example, it is very important not to have copies of > classes. Importing a module must produce the same module object > everywhere it is imported, and the classes defined in the module must > be defined only once. So that would be something that doesn't tolerate copies. But I think that a bigger change for Python wouldn't be new ways of doing imports, but the concept of having a user-defined anything that is a constant at compile-time. And not part of a conditional statement either. Usually anything that is defined can be changed at run-time so that the compiler can never assume anything. -- Bartc From alanoe at linux.vnet.ibm.com Mon Jul 4 12:40:04 2016 From: alanoe at linux.vnet.ibm.com (Alan Evangelista) Date: Mon, 4 Jul 2016 13:40:04 -0300 Subject: Structure of program development In-Reply-To: <95C250EE0EE1485FAB159FFB82C178BB@mike> References: <95C250EE0EE1485FAB159FFB82C178BB@mike> Message-ID: <577A9164.8030808@linux.vnet.ibm.com> > I am new to this programming adventure. I've gotten past the introductory chapters in 'How to..." books and now want to start developing a much more complicated program that I will use repeated for different applications. When I worked in Perl there was an option to write a program in a text editor, save it, and then run in with Perl. Is such a thing possible in Python? If not, how do I develop a 500+ lines of code? Yes. You can do it for every programming language I know, otherwise development would be impossible. > A second question of the basic design. If I write a program, can I move it to a computer that is without any Python software, or does that machine have to download the Python software? Does Python products contain all parts of a developed program or is it a series of 'call' statements? The target system must have the Python interpreter and standard library, which are always installed together. A software developed in Python must contain the method calls to the Python standard library, 3rd party libraries and/or custom code. It may or not contain the Python runtime environment (interpreter and std library). In Linux, for instance, it is standard to not include dependencies (eg Python runtime environment) in an application, but reuse the one already installed in the target system. Regards From marko at pacujo.net Mon Jul 4 12:44:09 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 04 Jul 2016 19:44:09 +0300 Subject: Well, I finally ran into a Python Unicode problem, sort of References: <0589521b-648a-47c1-8afa-6f746e0fb901@googlegroups.com> <5779ca54$0$1590$c3e8da3$5496439d@news.astraweb.com> <90b6c6e7-b1b8-4c0b-b29e-7ee0dd2a6983@googlegroups.com> Message-ID: <87vb0lfj52.fsf@elektro.pacujo.net> BartC : > Usually anything that is defined can be changed at run-time so that the > compiler can never assume anything. The compiler can't assume anything permanent, but it could heuristically make excellent guesses at runtime. It needs to verify its guesses at the boundaries of compiled code and gradually keep expanding the boundaries. If the guesses end up being wrong, it has to correct its assumptions and recompile the relevant parts of the code. Marko From kwpolska at gmail.com Mon Jul 4 12:55:49 2016 From: kwpolska at gmail.com (Chris Warrick) Date: Mon, 4 Jul 2016 18:55:49 +0200 Subject: Structure of program development In-Reply-To: <95C250EE0EE1485FAB159FFB82C178BB@mike> References: <95C250EE0EE1485FAB159FFB82C178BB@mike> Message-ID: On 4 July 2016 at 18:07, Michael Smolen <8smolen at tds.net> wrote: > Folks: > > I am new to this programming adventure. I've gotten past the introductory chapters in 'How to..." books and now want to start developing a much more complicated program that I will use repeated for different applications. When I worked in Perl there was an option to write a program in a text editor, save it, and then run in with Perl. Is such a thing possible in Python? If not, how do I develop a 500+ lines of code? Yes, the same way it works in Perl. Use the .py file extension and run the `python` interpreter from command line, or use an IDE that would help you with that. > A second question of the basic design. If I write a program, can I move it to a computer that is without any Python software, or does that machine have to download the Python software? Does Python products contain all parts of a developed program or is it a series of 'call' statements? You must either install a Python interpreter on that machine, or distribute one with your program. -- Chris Warrick PGP: 5EAAEA16 From bc at freeuk.com Mon Jul 4 12:56:42 2016 From: bc at freeuk.com (BartC) Date: Mon, 4 Jul 2016 17:56:42 +0100 Subject: Structure of program development In-Reply-To: References: <95C250EE0EE1485FAB159FFB82C178BB@mike> Message-ID: On 04/07/2016 17:07, Michael Smolen wrote: > Folks: > > I am new to this programming adventure. I've gotten past the introductory chapters in 'How to..." books and now want to start developing a much more complicated program that I will use repeated for different applications. When I worked in Perl there was an option to write a program in a text editor, save it, and then run in with Perl. Is such a thing possible in Python? If not, how do I develop a 500+ lines of code? > > A second question of the basic design. If I write a program, can I move it to a computer that is without any Python software, or does that machine have to download the Python software? Does Python products contain all parts of a developed program or is it a series of 'call' statements? It can work the same way. Write the 500-line program in, say, prog.py using any text editor. Then run it using: python prog.py -- Bartc From jussi.piitulainen at helsinki.fi Mon Jul 4 13:20:29 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 04 Jul 2016 20:20:29 +0300 Subject: Structure of program development References: <95C250EE0EE1485FAB159FFB82C178BB@mike> Message-ID: Michael Smolen writes: > Folks: > > I am new to this programming adventure. I've gotten past the > introductory chapters in 'How to..." books and now want to start > developing a much more complicated program that I will use repeated > for different applications. When I worked in Perl there was an option > to write a program in a text editor, save it, and then run in with > Perl. Is such a thing possible in Python? If not, how do I develop a > 500+ lines of code? This is indeed possible. If you can find your way to a command line of your operating system and launch a Python interactive session by typing "python" or "python3" to the command prompt and pressing the enter key, then you have access to the program that can execute your Python code that is in the file that you created with a text editor. All you have to do is, give the name of your file as an argument to python or python3. You get a stack trace, fix your program, and try again. Some text editors understand Python syntax, or can be set to understand Python syntax, just like they support Perl and many other languages. This is merely a convenience. Python need not know what you used to write the code. > A second question of the basic design. If I write a program, can I > move it to a computer that is without any Python software, or does > that machine have to download the Python software? Does Python > products contain all parts of a developed program or is it a series of > 'call' statements? The straightforward thing is to have Python installed. Beyond that, I don't have personal experience, so I won't offer any advice. Others will know. From python at mrabarnett.plus.com Mon Jul 4 13:29:17 2016 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 4 Jul 2016 18:29:17 +0100 Subject: file.seek() and file.tell() look inconsistent to me In-Reply-To: References: Message-ID: <05962f33-353e-99bf-ee62-c55a1e855bfb@mrabarnett.plus.com> On 2016-07-04 16:48, Marco Buttu wrote: > Hi all, > > if I open a file in text mode, do you know why file.seek() returns the > number of bytes, and file.tell() takes the number of bytes? I was > expecting the number of characters, like write() does: > > >>> f = open('myfile', 'w') > >>> f.write('a?') > 2 > > It seems to me not consistent, and maybe could also be error prone: > > >>> f.seek(2) > 2 > >>> f.write('c') > 1 > >>> f.close() > >>> open('myfile').read() > ... > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3... > > Some encodings, such as UTF-8, use a variable number of bytes per character (codepoint, actually), so in order to seek to a certain character position you would need to read from a known position, e.g. the start of the file, until you reached the desired place. Most of the time you're seeking to a position that was previously returned by tell anyway. I think it's a case of "practicality beats purity". From bc at freeuk.com Mon Jul 4 15:50:58 2016 From: bc at freeuk.com (BartC) Date: Mon, 4 Jul 2016 20:50:58 +0100 Subject: Structure of program development In-Reply-To: References: <95C250EE0EE1485FAB159FFB82C178BB@mike> Message-ID: On 04/07/2016 17:55, Chris Warrick wrote: >> A second question of the basic design. If I write a program, can I move it to a computer that is without any Python software, or does that machine have to download the Python software? Does Python products contain all parts of a developed program or is it a series of 'call' statements? > > You must either install a Python interpreter on that machine, or > distribute one with your program. If only it was that simple. My Windows Python 3.4 installation comprises 5200 files over 1300 directories, totalling 100MB. Other Pythons are a bit smaller, so I don't know what extras that includes. Which is part of the problem: you have to employ yet more extras to figure out the files needed to create a tidy distribution. However the Linuxes I've seen tend to have Python pre-installed. Then you can just supply the .py files of the application. -- Bartc From christian at python.org Mon Jul 4 16:45:34 2016 From: christian at python.org (Christian Heimes) Date: Mon, 4 Jul 2016 22:45:34 +0200 Subject: file.seek() and file.tell() look inconsistent to me In-Reply-To: References: Message-ID: On 2016-07-04 17:48, Marco Buttu wrote: > Hi all, > > if I open a file in text mode, do you know why file.seek() returns the > number of bytes, and file.tell() takes the number of bytes? I was > expecting the number of characters, like write() does: Your expectations are not correct. tell() and seek() of a file in binary mode return the current position of the file descriptor. For a file in text mode, tell() and seek() use a opaque number [1]. The number reflects the internal state of the text IO object. You can't draw any conclusion from it. You are only allowed to seek to offsets which you have acquired by tell(), too. [1] https://docs.python.org/3/library/io.html#io.TextIOBase.tell From lawrencedo99 at gmail.com Mon Jul 4 18:09:42 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 4 Jul 2016 15:09:42 -0700 (PDT) Subject: Namespaces are one honking great idea In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, July 4, 2016 at 11:37:44 PM UTC+12, Chris Angelico wrote: > Functions within the namespace can't call other functions within the > same namespace using unqualified names. This was a stated requirement. Doesn?t my @namespace decorator provide that? From lawrencedo99 at gmail.com Mon Jul 4 18:11:16 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 4 Jul 2016 15:11:16 -0700 (PDT) Subject: Namespaces are one honking great idea In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <17c5d75a-f01d-467f-95f8-1e7228403722@googlegroups.com> On Tuesday, July 5, 2016 at 10:10:04 AM UTC+12, I wrote: > > On Monday, July 4, 2016 at 11:37:44 PM UTC+12, Chris Angelico wrote: > > > Functions within the namespace can't call other functions within the > > same namespace using unqualified names. This was a stated requirement. > > Doesn?t my @namespace decorator provide that? No it doesn?t. From Brandon.Owen at ga.gov.au Mon Jul 4 19:10:33 2016 From: Brandon.Owen at ga.gov.au (Owen Brandon) Date: Mon, 4 Jul 2016 23:10:33 +0000 Subject: Gzip module does not support Unix compressed .Z files [SEC=UNOFFICIAL] In-Reply-To: References: <83cd4362560d4a4aa88bd71eb9c8ce78@win-exch-prod02.prod.lan> <87a8hxq1c5.fsf@handshake.de> Message-ID: That's actually the module that I wrote for this purpose (adapted Mark Adler's C code) - I haven't optimised it very much. Brandon Owen GNSS Network Operator? |? Geodesy and Seismic Monitoring Group Community Safety and Earth Monitoring Division? | ?GEOSCIENCE AUSTRALIA ____________________________________________________________ Phone:? +61 2 6249 9192??? Fax:? +61 2 6249 9999 Email:? Brandon.Owen at ga.gov.au??? Web:? www.ga.gov.au Cnr Jerrabomberra Avenue and Hindmarsh Drive Symonston ACT GPO Box 378 Canberra ACT 2601 Australia Applying geoscience to Australia's most important challenges -----Original Message----- From: Python-list [mailto:python-list-bounces+brandon.owen=ga.gov.au at python.org] On Behalf Of Robert Kern Sent: Tuesday, 5 July 2016 12:18 AM To: python-list at python.org Subject: Re: Gzip module does not support Unix compressed .Z files [SEC=UNOFFICIAL] On 2016-07-04 09:00, dieter wrote: > "Owen Brandon" writes: > >> I have a query regarding the support of decompression for Unix compressed .Z files in Python's gzip module. The gzip system utility supports this using the '-d' switch, but the python module does not. > > When I am right, then the "zipfile" module handles ".Z" compressed files. No, that handles PKZIP .zip files. There are third-party modules that handle the .Z format, but shelling out to external programs may still be preferable: https://github.com/umeat/unlzw -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- https://mail.python.org/mailman/listinfo/python-list Geoscience Australia Disclaimer: This e-mail (and files transmitted with it) is intended only for the person or entity to which it is addressed. If you are not the intended recipient, then you have received this e-mail by mistake and any use, dissemination, forwarding, printing or copying of this e-mail and its file attachments is prohibited. The security of emails transmitted cannot be guaranteed; by forwarding or replying to this email, you acknowledge and accept these risks. ------------------------------------------------------------------------------------------------------------------------- From lawrencedo99 at gmail.com Mon Jul 4 19:56:45 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 4 Jul 2016 16:56:45 -0700 (PDT) Subject: Structure of program development In-Reply-To: References: <95C250EE0EE1485FAB159FFB82C178BB@mike> Message-ID: On Tuesday, July 5, 2016 at 7:51:18 AM UTC+12, BartC wrote: > However the Linuxes I've seen tend to have Python pre-installed. Some are even dropping Python 2, and only having Python 3 by default. From rosuav at gmail.com Mon Jul 4 20:02:41 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2016 10:02:41 +1000 Subject: Structure of program development In-Reply-To: References: <95C250EE0EE1485FAB159FFB82C178BB@mike> Message-ID: On Tue, Jul 5, 2016 at 9:56 AM, Lawrence D?Oliveiro wrote: > On Tuesday, July 5, 2016 at 7:51:18 AM UTC+12, BartC wrote: > >> However the Linuxes I've seen tend to have Python pre-installed. > > Some are even dropping Python 2, and only having Python 3 by default. Yes, so your best bet is to aim for Python 3.3+ or 3.4+ compatibility, and start your program like this: #!/usr/bin/env python3 ChrisA From torriem at gmail.com Mon Jul 4 22:32:10 2016 From: torriem at gmail.com (Michael Torrie) Date: Mon, 4 Jul 2016 20:32:10 -0600 Subject: Structure of program development In-Reply-To: References: <95C250EE0EE1485FAB159FFB82C178BB@mike> Message-ID: On 07/04/2016 01:50 PM, BartC wrote: > On 04/07/2016 17:55, Chris Warrick wrote: > >>> A second question of the basic design. If I write a program, can I move it to a computer that is without any Python software, or does that machine have to download the Python software? Does Python products contain all parts of a developed program or is it a series of 'call' statements? >> >> You must either install a Python interpreter on that machine, or >> distribute one with your program. > > If only it was that simple. My Windows Python 3.4 installation comprises > 5200 files over 1300 directories, totalling 100MB. > > Other Pythons are a bit smaller, so I don't know what extras that > includes. Which is part of the problem: you have to employ yet more > extras to figure out the files needed to create a tidy distribution. > > However the Linuxes I've seen tend to have Python pre-installed. Then > you can just supply the .py files of the application. There are various packagers out there that can wrap up your python script with the interpreter and any library files necessary to run it. I would bet the result is far less than 100 MB. I'm sure you could develop a python application that would use all 100 MB of the files that comprise the standard library and the helper libraries if you really tried. I'm not up to date on the latest packagers, but I know at one time folks used py2exe, and some used cx_freeze. From steve at pearwood.info Mon Jul 4 22:34:44 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 12:34:44 +1000 Subject: Namespaces are one honking great idea References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <577b1cc6$0$1584$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Jul 2016 09:23 pm, jmp wrote: > On 07/01/2016 04:13 PM, Steven D'Aprano wrote: >> But classes are not like the others: they must be instantiated before >> they can be used, and they are more than just a mere namespace grouping >> related entities. Classes support inheritance. Classes should be used for >> "is-a" relationships, not "has-a" relationships. Although classes (and >> instances) are namespaces, they provide fundamentally different kind of >> behaviour than modules and packages. > > A namespace would not hurt but I really don't get why you don't consider > classes a valid and rather helpful namespace. I never said that. This is where the term "namespace" can be ambiguous. "Namespace" can refer to any of: - an abstract mapping of symbols (names) to values; - specific kinds of namespaces: * the concrete C++/C#/PHP data type called "namespace"; * Python packages and modules; * classes; * instances of a class; - the implementation (the __dict__ attribute of modules, classes); etc. Now clearly a class is not the same thing as the class __dict__, and a module is not the same as a class, and neither modules nor classes are the same as a C++ namespace. Doesn't mean that classes aren't valid namespaces, just that their semantics, use-cases and behaviour are different to those of modules. > 1/ classes do not have to be instantiated. That's a bit of a sore point to me. Some years ago I wrote here to ask what name is given to a class that is not instantiated before being used. Singleton classes get instantiated once, allowing a single instance. What if you had a class that didn't need instantiating at all, so that the class itself was *effectively* the singleton? What should that be called? Instead of this: class SingletonClass: ... singleton = SingletonClass() singleton.method() what if we had this instead? class singleton: ... singleton.method() I was roundly told that this was crazy talk, that the whole point of classes was that they must be instantiated to use them, that code like the second example would be confusing and very possibly bring about the fall of Western Civilisation. The idea that this might be a legitimate alternative to the singleton design pattern was dismissed. (The Python community is terribly conservative when it comes to code.) And, in a sense, they were right: there are two common ways to get singleton-like behaviour in general, and in Python specifically: - use class that allows only a single instance; - use a module. Using the class itself is unusual and surprising (especially to Java programmers, where classes aren't even first-class values), and more so, it's *inconvenient*. To write a class which is used without instantiation, you should raise an error on instantiation, decorate every method using classmethod or staticmethod, and have methods have to call each other using the dotted name: class Example: var = 999 def __init__(self): raise TypeError('do not instantiate this class') @classmethod def spam(cls, arg): return cls.eggs(arg) + cls.var @classmethod def eggs(cls, arg): return arg*2 *** IF *** you are willing to push the code out into its own separate .py file, you can use a module and write your code in a more natural form: # module example.py var = 999 def spam(arg): return eggs(arg) + var def eggs(arg): return arg*2 What I'm calling a "namespace" is just a module object that lives inside another module, without requiring a separate .py file. It only uses the "class" statement for pragmatic reasons: there's no other statement available that will do the job. > 2/ the fact that classes are more than a namespace is not an argument. > Almost any object in python is able to do more than what you are > actually using. There's one aspect of classes that is a deliberate design feature, but goes against what I'm after: the fact that the class namespace itself is NOT part of the method name resolution rules (except during class construction). Try this: x = 999 class Example: x = 1 print(x) # called during class construction @classmethod def test(cls): print(x) Example.test() This will print 1, then 999. We quite often get people complaining about this. I'm not one of them. I want classes to keep the current rules. But it shows that a class is not the right answer for a module-inside-a-module object. > 3/ Classes are used as much as 'is-a' than 'has-a', class instances > *have* a state usually described by attributes Instances have state, of course, but the relationship I'm talking about is instance to class. class Dog: ... lassie = Dog() Lassie is a dog, not "Lassie has a dog". Lassie has a tail, not "Lassie is a tail". That's why we have IS_instance and HAS_attr builtins. The expectation is that a class represents a model of a physical kind of thing, whether that's a Dog or a HTTPServer or a float. If you want a collection of related functions, classes and variables, put them in a different kind of namespace, namely a module (if using a separate .py file is okay) or a Namespace. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Mon Jul 4 22:58:19 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2016 12:58:19 +1000 Subject: Namespaces are one honking great idea In-Reply-To: <577b1cc6$0$1584$c3e8da3$5496439d@news.astraweb.com> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577b1cc6$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 5, 2016 at 12:34 PM, Steven D'Aprano wrote: > *** IF *** you are willing to push the code out into its own separate .py > file, you can use a module and write your code in a more natural form: > > > # module example.py > var = 999 > > def spam(arg): > return eggs(arg) + var > > def eggs(arg): > return arg*2 > > > What I'm calling a "namespace" is just a module object that lives inside > another module, without requiring a separate .py file. It only uses > the "class" statement for pragmatic reasons: there's no other statement > available that will do the job. If you push your code into a separate .py file, you can reference the original module by importing it. Is that also the normal way to use "outer" functions etc from inside a namespace? # demo.py pi = 3.14 def stupidfib(x): if x < 2: return x return stupidfib(x-1) + stupidfib(x-2) Namespace asdf: # (or class, however it's done) def foo(x): return stupidfib(x * pi) / pi How should foo reference those "even more global" names? "from . import pi, stupidfib" would work if you converted the module into a package ("mv demo.py demo/__init__.py"), and "from demo import pi, stupidfib" would work if you converted the namespace into a peer module. Either could make sense. ChrisA From steve at pearwood.info Mon Jul 4 23:20:06 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 13:20:06 +1000 Subject: Nested class doesn't see class scope Message-ID: <577b2768$0$1606$c3e8da3$5496439d@news.astraweb.com> I got this in Python 3.6: py> class A: ... var = 999 ... print(var) # succeeds ... class B: ... x = var ... 999 Traceback (most recent call last): File "", line 1, in File "", line 3, in A File "", line 4, in B NameError: name 'var' is not defined I expected that `var` would be available during the construction of B, just as it was available inside A, but not to methods inside B. Obviously my expectations are invalid. Can anyone explain the actual behaviour? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Mon Jul 4 23:35:14 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 13:35:14 +1000 Subject: Namespaces are one honking great idea References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577b1cc6$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: <577b2af3$0$1611$c3e8da3$5496439d@news.astraweb.com> On Tue, 5 Jul 2016 12:58 pm, Chris Angelico wrote: > On Tue, Jul 5, 2016 at 12:34 PM, Steven D'Aprano > wrote: >> *** IF *** you are willing to push the code out into its own separate .py >> file, you can use a module and write your code in a more natural form: >> >> >> # module example.py >> var = 999 >> >> def spam(arg): >> return eggs(arg) + var >> >> def eggs(arg): >> return arg*2 >> >> >> What I'm calling a "namespace" is just a module object that lives inside >> another module, without requiring a separate .py file. It only uses >> the "class" statement for pragmatic reasons: there's no other statement >> available that will do the job. > > If you push your code into a separate .py file, you can reference the > original module by importing it. Is that also the normal way to use > "outer" functions etc from inside a namespace? Good question! With the current implementation, importing should work, but it's not necessary. The surrounding module (the real .py module) is inserted into the name resolution path of functions: py> x = 999 py> @namespace.Namespace ... class Test: ... def test(): ... print(x) ... py> Test.test() 999 Of course, the module-global x will be shadowed by any x in the Test namespace (which is the intent), and you cannot assign to them (also a feature). A bare `x = 1` inside the function will make x a local, unless you declare it global first, in which case it should assign to the Test namespace scope instead. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Mon Jul 4 23:37:49 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Jul 2016 20:37:49 -0700 (PDT) Subject: Nested class doesn't see class scope In-Reply-To: <577b2768$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <577b2768$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, July 5, 2016 at 8:50:57 AM UTC+5:30, Steven D'Aprano wrote: > I got this in Python 3.6: > > > py> class A: > ... var = 999 > ... print(var) # succeeds > ... class B: > ... x = var > ... > 999 > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in A > File "", line 4, in B > NameError: name 'var' is not defined > > > I expected that `var` would be available during the construction of B, just > as it was available inside A, but not to methods inside B. Obviously my > expectations are invalid. Can anyone explain the actual behaviour? > Heh! Nice to see you confused by python's ?concave? LEGB rule One of those thing I never get used to? From no.email at nospam.invalid Mon Jul 4 23:42:32 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 04 Jul 2016 20:42:32 -0700 Subject: Nested class doesn't see class scope References: <577b2768$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87y45gg387.fsf@jester.gateway.pace.com> Steven D'Aprano writes: > ... class B: > ... x = var x = A.var From rosuav at gmail.com Mon Jul 4 23:47:41 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2016 13:47:41 +1000 Subject: Namespaces are one honking great idea In-Reply-To: <577b2af3$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577b1cc6$0$1584$c3e8da3$5496439d@news.astraweb.com> <577b2af3$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 5, 2016 at 1:35 PM, Steven D'Aprano wrote: >> If you push your code into a separate .py file, you can reference the >> original module by importing it. Is that also the normal way to use >> "outer" functions etc from inside a namespace? > > Good question! > > With the current implementation, importing should work, but it's not > necessary. The surrounding module (the real .py module) is inserted into > the name resolution path of functions: > > py> x = 999 > py> @namespace.Namespace > ... class Test: > ... def test(): > ... print(x) > ... > py> Test.test() > 999 Ah, fascinating. This does break the "just unindent and move to a new file if you want to break it out" equivalency, but it does make sense - it's a *nested* namespace, which modules (even in a package) are not. So you have the outer namespace acting pretty much the way builtins do. (Do nested namespaces work?) ChrisA From rosuav at gmail.com Tue Jul 5 00:02:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2016 14:02:36 +1000 Subject: How well do you know Python? Message-ID: After some discussion with a Ruby on Rails programmer about where Ruby ends and where Rails begins (and it's definitely not where I'd have expected... Rails does a ton of monkey-patching, including of built-in types, to provide functionality that is strangely absent from the core language), I tried to come up with some somewhat-challenging Python questions. But to make them hard, I had to go a smidge more esoteric than the Ruby questions did.... Anyhow, see how you go. Assume Python 3.x unless stated. 1) Under what circumstances can str.upper() return a string of different length to its input? 2) What exception do you get when you craft an impossible class hierarchy? a. ValueError b. TypeError c. types.ClassInheritanceError d. SyntaxError 3) What does `from __future__ import braces` do? 4) Which operator, removed from Python 3.0, can be reinstated with a 'joke' future directive? 5) What is the difference between the `/` and `//` operators in Python 2.7? In Python 3.x? Got any other tricky questions to add? ChrisA From nagle at animats.com Tue Jul 5 00:06:38 2016 From: nagle at animats.com (John Nagle) Date: Mon, 04 Jul 2016 21:06:38 -0700 Subject: py2exe crashes on simple program Message-ID: I'm trying to create an executable with py2exe. The program runs fine in interpretive mode. But when I try to build an executable, py2exe crashes with an assertion error. See below. This is an all-Python program; no binary modules other than ones that come with the Python 3.5.2 distribution. Running "python setup.py bdist" works, so "setup.py" is sane. What's giving py2exe trouble? U:\>python setup.py py2exe running py2exe running build_py Building shared code archive 'dist\library.zip'. Traceback (most recent call last): File "setup.py", line 14, in packages=['baudotrss'], File "C:\Program Files\Python35\lib\distutils\core.py", line 148, in setup dist.run_commands() File "C:\Program Files\Python35\lib\distutils\dist.py", line 955, in run_commands self.run_command(cmd) File "C:\Program Files\Python35\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Program Files\Python35\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run self._run() File "C:\Program Files\Python35\lib\site-packages\py2exe\distutils_buildexe.py", line 268, in _run builder.build() File "C:\Program Files\Python35\lib\site-packages\py2exe\runtime.py", line 261, in build self.build_archive(libpath, delete_existing_resources=True) File "C:\Program Files\Python35\lib\site-packages\py2exe\runtime.py", line 426, in build_archive assert mod.__file__.endswith(EXTENSION_SUFFIXES[0]) AssertionError Python 3.5.2 / Win7 / AMD64. John Nagle From ian.g.kelly at gmail.com Tue Jul 5 00:37:15 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 4 Jul 2016 22:37:15 -0600 Subject: Nested class doesn't see class scope In-Reply-To: <87y45gg387.fsf@jester.gateway.pace.com> References: <577b2768$0$1606$c3e8da3$5496439d@news.astraweb.com> <87y45gg387.fsf@jester.gateway.pace.com> Message-ID: On Mon, Jul 4, 2016 at 9:42 PM, Paul Rubin wrote: > Steven D'Aprano writes: >> ... class B: >> ... x = var > > x = A.var Nope. A doesn't exist yet at this point. From ian.g.kelly at gmail.com Tue Jul 5 00:41:16 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 4 Jul 2016 22:41:16 -0600 Subject: Nested class doesn't see class scope In-Reply-To: <577b2768$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <577b2768$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jul 4, 2016 at 9:20 PM, Steven D'Aprano wrote: > I got this in Python 3.6: > > > py> class A: > ... var = 999 > ... print(var) # succeeds > ... class B: > ... x = var > ... > 999 > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in A > File "", line 4, in B > NameError: name 'var' is not defined > > > I expected that `var` would be available during the construction of B, just > as it was available inside A, but not to methods inside B. Obviously my > expectations are invalid. Can anyone explain the actual behaviour? Class definitions don't create closures like functions do. When Python executes a class definition, the metaclass creates a dict, and then the interpreter execs the class body using that dict as the locals. The body of class A has one locals dict, and the body of class B has a completely separate locals dict. The only way to share variables between them (prior to the class objects actually being constructed) is via globals. From ian.g.kelly at gmail.com Tue Jul 5 00:43:44 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 4 Jul 2016 22:43:44 -0600 Subject: Nested class doesn't see class scope In-Reply-To: References: <577b2768$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jul 4, 2016 at 10:41 PM, Ian Kelly wrote: > On Mon, Jul 4, 2016 at 9:20 PM, Steven D'Aprano wrote: >> I got this in Python 3.6: >> >> >> py> class A: >> ... var = 999 >> ... print(var) # succeeds >> ... class B: >> ... x = var >> ... >> 999 >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 3, in A >> File "", line 4, in B >> NameError: name 'var' is not defined >> >> >> I expected that `var` would be available during the construction of B, just >> as it was available inside A, but not to methods inside B. Obviously my >> expectations are invalid. Can anyone explain the actual behaviour? > > Class definitions don't create closures like functions do. When Python > executes a class definition, the metaclass creates a dict, and then > the interpreter execs the class body using that dict as the locals. > The body of class A has one locals dict, and the body of class B has a > completely separate locals dict. The only way to share variables > between them (prior to the class objects actually being constructed) > is via globals. Or I suppose one could write a metaclass that does something fancy when creating the dicts. From michael.selik at gmail.com Tue Jul 5 01:26:29 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 05 Jul 2016 05:26:29 +0000 Subject: Making Classes Subclassable In-Reply-To: <337f8071-ef4a-4ac5-867b-a5320c684730@googlegroups.com> References: <87eg79q1i0.fsf@handshake.de> <337f8071-ef4a-4ac5-867b-a5320c684730@googlegroups.com> Message-ID: On Mon, Jul 4, 2016, 4:36 AM Lawrence D?Oliveiro wrote: > On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: > > --> "type(obj)" or "obj.__class__" (there are small differences) > > give you the type/class of "obj". > > When would it not be the same? > Old-style classes. > From steve+comp.lang.python at pearwood.info Tue Jul 5 01:40:23 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 15:40:23 +1000 Subject: Nested class doesn't see class scope References: <577b2768$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <577b4848$0$2763$c3e8da3$76491128@news.astraweb.com> On Tuesday 05 July 2016 14:41, Ian Kelly wrote: > Class definitions don't create closures like functions do. When Python > executes a class definition, the metaclass creates a dict, and then > the interpreter execs the class body using that dict as the locals. > The body of class A has one locals dict, and the body of class B has a > completely separate locals dict. The only way to share variables > between them (prior to the class objects actually being constructed) > is via globals. So, like nested functions in Python before "from __future__ import nested_scopes". Okay, that's reasonable. -- Steve From steve+comp.lang.python at pearwood.info Tue Jul 5 02:05:20 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 16:05:20 +1000 Subject: How well do you know Python? References: Message-ID: <577b4e22$0$2752$c3e8da3$76491128@news.astraweb.com> On Tuesday 05 July 2016 14:02, Chris Angelico wrote: > After some discussion with a Ruby on Rails programmer about where Ruby > ends and where Rails begins (and it's definitely not where I'd have > expected... Rails does a ton of monkey-patching, including of built-in > types, to provide functionality that is strangely absent from the core > language), I tried to come up with some somewhat-challenging Python > questions. But to make them hard, I had to go a smidge more esoteric > than the Ruby questions did.... Anyhow, see how you go. Assume Python > 3.x unless stated. S P O I L E R S P A C E A N D A B I T M O R E > 1) Under what circumstances can str.upper() return a string of > different length to its input? Potentially any string might uppercase to a different length, depending on the content of the string and the case conversion rules for letters from that script. For Europeans, the simplest example is probably the German eszett, or \N{LATIN SMALL LETTER SHARP S}. There's an uppercase version, \N{LATIN CAPITAL LETTER SHARP S} but for historical reasons (and the idiosyncrasies of German) "?" uppercases to "SS". > 2) What exception do you get when you craft an impossible class hierarchy? > a. ValueError b. TypeError c. types.ClassInheritanceError d. SyntaxError Without checking, I would expect TypeError (90% confident) or SyntaxError (unlikely). > 3) What does `from __future__ import braces` do? Report your IP address and username to a secret database of people who will be sent to the gulags for re-education when the revolution comes. Or at least, they would be, if the Python Secret Underground, which most definitely doesn't exist, existed, which it doesn't. Otherwise it prints the final word on the question of braces in Python. > 4) Which operator, removed from Python 3.0, can be reinstated with a > 'joke' future directive? The <> not-equal operator. > 5) What is the difference between the `/` and `//` operators in Python > 2.7? In Python 3.x? In Python 3, / means "true division" (i.e. what a calculator will do), and // means "integer division". E.g. 11/2 gives 5.5, while 11//2 gives 5. In 2.7, there are two cases: with, or without "from __future__ import division". With the __future__ directive, they mean the same as in Python 3. Without, // means "integer division", but / depends on its arguments. If both arguments are ints, it performs integer division. If at least one is a float, it performs "true division" like a calculator. Although to be pedantic, in all cases it depends on operator overloading :-) -- Steve From steve+comp.lang.python at pearwood.info Tue Jul 5 02:09:09 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 16:09:09 +1000 Subject: Namespaces are one honking great idea References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577b1cc6$0$1584$c3e8da3$5496439d@news.astraweb.com> <577b2af3$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <577b4f06$0$2752$c3e8da3$76491128@news.astraweb.com> On Tuesday 05 July 2016 13:47, Chris Angelico wrote: > On Tue, Jul 5, 2016 at 1:35 PM, Steven D'Aprano wrote: >>> If you push your code into a separate .py file, you can reference the >>> original module by importing it. Is that also the normal way to use >>> "outer" functions etc from inside a namespace? >> >> Good question! >> >> With the current implementation, importing should work, but it's not >> necessary. The surrounding module (the real .py module) is inserted into >> the name resolution path of functions: >> >> py> x = 999 >> py> @namespace.Namespace >> ... class Test: >> ... def test(): >> ... print(x) >> ... >> py> Test.test() >> 999 > > Ah, fascinating. This does break the "just unindent and move to a new > file if you want to break it out" equivalency, but it does make sense > - it's a *nested* namespace, which modules (even in a package) are > not. So you have the outer namespace acting pretty much the way > builtins do. (Do nested namespaces work?) I haven't got that far, but I expect that nested namespaces will be nested in name only, like nested functions in Python 1.5. There's only so far I can go without support from the compiler. If you nest a class inside another class, the inner class doesn't see variables in the outer class even during construction. So I'm pretty sure my namespace metaclass will inherit the same limitation. -- Steve From steve+comp.lang.python at pearwood.info Tue Jul 5 02:13:51 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 16:13:51 +1000 Subject: py2exe crashes on simple program References: Message-ID: <577b5020$0$2752$c3e8da3$76491128@news.astraweb.com> On Tuesday 05 July 2016 14:06, John Nagle wrote: > I'm trying to create an executable with py2exe. > The program runs fine in interpretive mode. But > when I try to build an executable, py2exe crashes with > an assertion error. See below. [...] > Building shared code archive 'dist\library.zip'. [...] > assert mod.__file__.endswith(EXTENSION_SUFFIXES[0]) > AssertionError To me, that looks like you're trying to build something called "library.zip" and .zip isn't an allowed file type extension. If you change it to "library.exe" does it work? Also, I consider this a bug in py2exe: - it's an abuse of assert, using it to check user-supplied input; - it's a failing assertion, which by definition is a bug. -- Steve From steve+comp.lang.python at pearwood.info Tue Jul 5 02:33:26 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 16:33:26 +1000 Subject: How well do you know Python? References: Message-ID: <577b54b8$0$1589$c3e8da3$5496439d@news.astraweb.com> On Tuesday 05 July 2016 14:02, Chris Angelico wrote: > After some discussion with a Ruby on Rails programmer about where Ruby > ends and where Rails begins (and it's definitely not where I'd have > expected... Rails does a ton of monkey-patching, including of built-in > types, to provide functionality that is strangely absent from the core > language), I tried to come up with some somewhat-challenging Python > questions. But to make them hard, I had to go a smidge more esoteric [...] > Got any other tricky questions to add? Explain metaclasses, descriptors, the mro, multiple inheritance, and the interaction between them. Why is the mro needed? obj.spam is a property. How do you get access to the underlying property object itself? Why doesn't the property decorator work inside a Python 2 classic class? Explain Python scoping rules, in particular with respect to nested classes and nested functions (or even nested classes inside nested functions). Explain attribute lookup rules. When does an instance attribute take priority over a class attribute? When is locals() writable? When is locals() writable, AND the effect shows up in the local scope? Explain how exec works inside a function, and the interaction with locals(). Name all the falsey builtins. Apart from exceptions, list the builtins, from memory. You can list the exceptions as well. An easy one: list the Python keywords. What happens in this code snippet? L = [1] t = (L,) t[0] += 1 Explain what value t has, and why. Explain what "yield from it" does and how it is different from: for item in it: yield item -- Steve From rosuav at gmail.com Tue Jul 5 02:38:38 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2016 16:38:38 +1000 Subject: How well do you know Python? In-Reply-To: <577b54b8$0$1589$c3e8da3$5496439d@news.astraweb.com> References: <577b54b8$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 5, 2016 at 4:33 PM, Steven D'Aprano wrote: > What happens in this code snippet? > > L = [1] > t = (L,) > t[0] += 1 > > Explain what value t has, and why. Not sure you have that question right, because it simply gives a TypeError. You can't add an integer to a list. ChrisA From lawrencedo99 at gmail.com Tue Jul 5 03:08:28 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 5 Jul 2016 00:08:28 -0700 (PDT) Subject: Making Classes Subclassable In-Reply-To: References: <87eg79q1i0.fsf@handshake.de> <337f8071-ef4a-4ac5-867b-a5320c684730@googlegroups.com> Message-ID: On Tuesday, July 5, 2016 at 5:27:01 PM UTC+12, Michael Selik wrote: > On Mon, Jul 4, 2016, 4:36 AM Lawrence D?Oliveiro wrote: > >> On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: >>> >>> --> "type(obj)" or "obj.__class__" (there are small differences) >>> give you the type/class of "obj". >> >> When would it not be the same? > > Old-style classes. Which don?t exist any more. From dieter at handshake.de Tue Jul 5 03:55:52 2016 From: dieter at handshake.de (dieter) Date: Tue, 05 Jul 2016 09:55:52 +0200 Subject: Making Classes Subclassable References: <87eg79q1i0.fsf@handshake.de> <337f8071-ef4a-4ac5-867b-a5320c684730@googlegroups.com> Message-ID: <874m84jz7b.fsf@handshake.de> Lawrence D?Oliveiro writes: > On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: >> --> "type(obj)" or "obj.__class__" (there are small differences) >> give you the type/class of "obj". > > When would it not be the same? Special proxy objects, i.e. objects that try to behave as much as possible like another object. For those objects, you may either want the class of the proxy itself (--> "type(obj)") or the class of the proxied object (--> "obj.__class__"). Moreover, you might have special descriptors installed which may affect how "obj.__class__" is resolved. From dieter at handshake.de Tue Jul 5 04:04:25 2016 From: dieter at handshake.de (dieter) Date: Tue, 05 Jul 2016 10:04:25 +0200 Subject: Need help compiling Python-devel References: Message-ID: <87zipwik8m.fsf@handshake.de> TM writes: > I have successfully compiled Python-2.7.12 on AIX 6.1 TL09, using steps > below. However I need the python-devel library/headers. How do I compile > Python, so that I can use this? The distinction between "python" and "python-devel" is not a Python notion but one of package management systems. "Usual" users of a package do in fact not need the complete package but only part (the binary part) of it. Only "special" users need more parts (especially headers, maybe libraries). Therefore, many package management systems have for most packages two variants "XXX" (for "typical" users) and "XXX-dev[el]" (for "special" users). When you compile Python yourself, you get the full Python: binaries, headers and libraries. I.e. you in fact compile "python-devel" (not "python"). From steve+comp.lang.python at pearwood.info Tue Jul 5 04:22:48 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 18:22:48 +1000 Subject: How well do you know Python? References: <577b54b8$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: <577b6e59$0$1517$c3e8da3$5496439d@news.astraweb.com> On Tuesday 05 July 2016 16:38, Chris Angelico wrote: > On Tue, Jul 5, 2016 at 4:33 PM, Steven D'Aprano > wrote: >> What happens in this code snippet? >> >> L = [1] >> t = (L,) >> t[0] += 1 >> >> Explain what value t has, and why. > > Not sure you have that question right, because it simply gives a > TypeError. You can't add an integer to a list. D'oh! Try this instead: t = ([0],) t[0] += [1] -- Steve From steve+comp.lang.python at pearwood.info Tue Jul 5 04:31:58 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 18:31:58 +1000 Subject: Making Classes Subclassable References: <87eg79q1i0.fsf@handshake.de> <337f8071-ef4a-4ac5-867b-a5320c684730@googlegroups.com> Message-ID: <577b707f$0$2917$c3e8da3$76491128@news.astraweb.com> On Monday 04 July 2016 18:34, Lawrence D?Oliveiro wrote: > On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: >> --> "type(obj)" or "obj.__class__" (there are small differences) >> give you the type/class of "obj". > > When would it not be the same? class X(object): def __getattribute__(self, name): if __name__ == '__class__': return int return super().__getattribute__(name) -- Steve From __peter__ at web.de Tue Jul 5 04:36:04 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 05 Jul 2016 10:36:04 +0200 Subject: How well do you know Python? References: Message-ID: Chris Angelico wrote: > After some discussion with a Ruby on Rails programmer about where Ruby > ends and where Rails begins (and it's definitely not where I'd have > expected... Rails does a ton of monkey-patching, including of built-in > types, to provide functionality that is strangely absent from the core > language), I tried to come up with some somewhat-challenging Python > questions. But to make them hard, I had to go a smidge more esoteric > than the Ruby questions did.... Anyhow, see how you go. Assume Python > 3.x unless stated. > > 1) Under what circumstances can str.upper() return a string of > different length to its input? > 2) What exception do you get when you craft an impossible class hierarchy? > a. ValueError b. TypeError c. types.ClassInheritanceError d. > SyntaxError > 3) What does `from __future__ import braces` do? > 4) Which operator, removed from Python 3.0, can be reinstated with a > 'joke' future directive? > 5) What is the difference between the `/` and `//` operators in Python > 2.7? In Python 3.x? > > Got any other tricky questions to add? What will $ cat foo.py import foo class A: pass print(isinstance(foo.A(), A)) $ python -c 'import foo' ... $ python foo.py ... print? It looks like $ python3 -c 'print({1, 2})' {1, 2} $ python3 -c 'print({2, 1})' {1, 2} will always print the same output. Can you construct a set from two small integers where this is not the case? What's the difference? What happens if you replace the ints with strings? Why? From greg.ewing at canterbury.ac.nz Tue Jul 5 05:10:15 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 05 Jul 2016 21:10:15 +1200 Subject: A nestedmodule decorator (Re: Namespaces are one honking great idea) In-Reply-To: <577b4f06$0$2752$c3e8da3$76491128@news.astraweb.com> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577b1cc6$0$1584$c3e8da3$5496439d@news.astraweb.com> <577b2af3$0$1611$c3e8da3$5496439d@news.astraweb.com> <577b4f06$0$2752$c3e8da3$76491128@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > There's only so far I can go without support from the compiler. It turns out one can go surprisingly far. Here's something I cooked up that seems to meet almost all the requirements. The only shortcoming I can think of is that a nestedmodule inside another nestedmodule won't be able to see the names in the outer nestedmodule directly (much like nested classes). % python3 test_nestedmodule.py 0.7071067811865475 #------------------------------------------ # # test_nestedmodule.py # #------------------------------------------ from math import pi, sin from nestedmodule import nestedmodule def f(x): return x**2 @nestedmodule def test(): def g(x): return f(x) * pi def h(x): return sin(g(x)) y = test.h(0.5) print(y) #------------------------------------------ # # nestedmodule.py # #------------------------------------------ from types import CodeType, ModuleType def hack_code(f): """Hack 'return locals()' onto the end of the bytecode of f.""" code1 = f.__code__ bytes1 = code1.co_code names1 = code1.co_names n = len(names1) names2 = names1 + ('locals',) bytes2 = bytes1[:-4] + bytes([116, n, 0, 131, 0, 0, 83]) code2 = CodeType(code1.co_argcount, code1.co_kwonlyargcount, code1.co_nlocals, code1.co_stacksize, code1.co_flags, bytes2, code1.co_consts, names2, code1.co_varnames, code1.co_filename, code1.co_name, code1.co_firstlineno, code1.co_lnotab, code1.co_freevars, code1.co_cellvars) return code2 def nestedmodule(f): c = hack_code(f) l = eval(c, f.__globals__) m = ModuleType(f.__name__) m.__dict__.update(l) return m From auriocus at gmx.de Tue Jul 5 05:13:44 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 5 Jul 2016 11:13:44 +0200 Subject: How well do you know Python? In-Reply-To: <577b6e59$0$1517$c3e8da3$5496439d@news.astraweb.com> References: <577b54b8$0$1589$c3e8da3$5496439d@news.astraweb.com> <577b6e59$0$1517$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 05.07.16 um 10:22 schrieb Steven D'Aprano: > On Tuesday 05 July 2016 16:38, Chris Angelico wrote: > >> On Tue, Jul 5, 2016 at 4:33 PM, Steven D'Aprano >> wrote: >>> What happens in this code snippet? >>> >>> L = [1] >>> t = (L,) >>> t[0] += 1 >>> >>> Explain what value t has, and why. >> >> Not sure you have that question right, because it simply gives a >> TypeError. You can't add an integer to a list. > > D'oh! > > > Try this instead: > > t = ([0],) > t[0] += [1] > and after that, try: >>> a=[0] >>> t=(a,) >>> a+=[1] Christian From rosuav at gmail.com Tue Jul 5 05:17:17 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2016 19:17:17 +1000 Subject: How well do you know Python? In-Reply-To: <577b54b8$0$1589$c3e8da3$5496439d@news.astraweb.com> References: <577b54b8$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 5, 2016 at 4:33 PM, Steven D'Aprano wrote: > > Got any other tricky questions to add? S P O I L E R S P A C E A N D A B I T M O R E [Thanks Steven, I just copied and pasted your space. See? You can copy and paste blank space and use it over and over. Could be a useful tip for the people who can't find enough newlines to space out their code or readability.] > Explain metaclasses, descriptors, the mro, multiple inheritance, and the > interaction between them. Why is the mro needed? A metaclass is simply the type of the type of something. By default, that's type, but if you type "metaclass=X" in a class definition, you can make your class a type of something else. (Can I use the word "type" in any other senses? I couldn't work "font" into the above.) Descriptors are objects stored in the class which, when referenced from an instance, return something other than themselves. The most common example is functions; a function in a class becomes a bound method on an instance, thus proving that descriptors make Python better than JavaScript. The MRO is simply the class hierarchy, starting from the current class and ending with 'object', flattened out into a line. In a pure single-inheritance situation, this is just the line of parents; when multiple inheritance comes into play, the MRO becomes more complicated, but still follows straight-forward rules (children before parents, and parents in the order they're listed). The MRO's job is twofold: attributes of classes earlier in the list will shadow those later, and super() means "next in the MRO". > obj.spam is a property. How do you get access to the underlying property object > itself? Presumably you mean that obj.spam returns the result of calling the property function, something like this: class X: @property def spam(self): return "something" obj = X() In that case, type(obj).spam is the property object, and type(obj).spam.{fget,fset,fdel} are the three functions (of which two will be None in my example). > Why doesn't the property decorator work inside a Python 2 classic class? Guido put an explicit check in to prevent you from doing so. Attempting it will automatically download the latest Python 3.x, point your web browser to a porting tutorial, and raise SyntaxError("Please learn to use Python 3."). Or: Instances of classic classes are all actually instances of Instance(), so the property would have to be attached to Instance. Or: It does. rosuav at sikorsky:~$ python2 Python 2.7.11+ (default, Jun 2 2016, 19:34:15) [GCC 5.3.1 20160528] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class X: ... @property ... def spam(self): ... print("Spamming") ... return "Hello"*5 ... >>> x=X() >>> x <__main__.X instance at 0x7f06e44fad88> >>> x.spam Spamming 'HelloHelloHelloHelloHello' Take your pick. > Explain Python scoping rules, in particular with respect to nested classes and > nested functions (or even nested classes inside nested functions). If you have an explicit global or nonlocal directive, the listed name(s) are looked up in that scope only. Otherwise, Python looks in local names, then in enclosing function scopes, then the module globals, and finally the built-ins. While executing a class or function body, local scope is that class/function. Enclosing class scopes are not searched. > Explain attribute lookup rules. When does an instance attribute take priority > over a class attribute? With simple attributes, an instance attribute always takes priority, and then class attributes in method resolution order. With descriptors... I'd have to go look it up. I've never done any shadowing of descriptors, at least not deliberately/consciously. > When is locals() writable? When is locals() writable, AND the effect shows up > in the local scope? Explain how exec works inside a function, and the > interaction with locals(). In CPython, locals() is always writable. It's just a dictionary. I'm not sure whether this is a language guarantee or not. When does the effect show up in local scope? When locals() is globals(). Otherwise, the answer has to be "undefined" or at best "implementation defined". To go further than that, I have to actually experiment, rather than going from memory. rosuav at sikorsky:~$ python3 Python 3.6.0a2+ (default:57f3514564f6, Jun 29 2016, 16:27:34) [GCC 5.3.1 20160528] on linux Type "help", "copyright", "credits" or "license" for more information. >>> def f(): ... x = 1 ... print(id(locals()), id(globals())) ... locals()["x"] = 2 ... print(x) ... >>> f() 140191368813960 140191369099208 1 >>> Same is true of CPython 2.7, PyPy 5.1 (including PyPy.js), Jython 2.5, MicroPython (although this has its own bizarrenesses - locals() is globals(), somehow), but NOT of Brython. In Brython, locals and globals have distinct ids, and mutating locals *does* change the local name binding. And this is legal, according to the docs. End of experimentation, now back to doing stuff from memory. In Python 3, I don't think exec() can interact with locals() in any way. It's a perfectly ordinary function; you can give it a reference to locals() if you like, but it's no different from other mutations of locals. In Python 2... I don't use exec inside functions. So I'd have to look it up or experiment. But I'd rather just stick to Py3. > Name all the falsey builtins. Fred, Joe, Stanley, Margaret, and Louise. I don't think there are actually any falsey builtins. Most builtins are either classes (object types like int/str/range, and the exceptions) or functions (next, ascii, eval). None and False are keywords, so they don't count. Literals like (), 0, 0.0, 0.0j, u"", b"" aren't builtins either. And [] and {} aren't literals OR builtins, they're special forms of constructor that return falsey objects. > Apart from exceptions, list the builtins, from memory. You can list the > exceptions as well. Oh great. Uhh... there's a lot of them. int, bool, str, bytes, list, tuple, set, dict, object, type, float, complex, next, ascii, eval, exec, range, sorted, super, zip, map, enumerate, len, iter, repr, locals, globals, id... I'm stopping there. > An easy one: list the Python keywords. Not that easy actually. I'm far from sure that I got them all. True, False, None, if, elif, else, for, while, break, continue, try, except, finally, raise, with, as, async, def, return, and, or, not, is, in, class, pass, yield, global, nonlocal, yield, from, import How many have I missed? > What happens in this code snippet? > > L = [1] > t = (L,) > t[0] += 1 > > Explain what value t has, and why. Correction from other post: Last line becomes "t[0] += [1]" t has the same value it had before - the same tuple. That tuple references L, which has just been extended and is now [1, 1]. So if you print out t, you'll see ([1, 1],) - but it's still the same value it was. Also, you'll have seen a TypeError at the moment when you attempted to mutate the tuple, which is a violation of the Guildpact, subsection... whatever. The same one that says that coffee is an acceptable substitute for rest for the Living Guildpact. > Explain what "yield from it" does and how it is different from: > > for item in it: > yield item If 'it' is another generator, 'yield from' also passes along any values sent, or any exception thrown in. With non-generator iterators, I believe it's functionally identical to the above for loop. ChrisA From rosuav at gmail.com Tue Jul 5 05:21:47 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2016 19:21:47 +1000 Subject: How well do you know Python? In-Reply-To: References: Message-ID: On Tue, Jul 5, 2016 at 6:36 PM, Peter Otten <__peter__ at web.de> wrote: > What will > > $ cat foo.py > import foo > class A: pass > print(isinstance(foo.A(), A)) > $ python -c 'import foo' > ... > $ python foo.py > ... > > print? I refuse to play around with isinstance and old-style classes. Particularly when circular imports are involved. Run this under Python 3 and/or explicitly subclass object, and then I'd consider it. :) > It looks like > > $ python3 -c 'print({1, 2})' > {1, 2} > $ python3 -c 'print({2, 1})' > {1, 2} > > will always print the same output. Can you construct a set from two small > integers where this is not the case? What's the difference? Given that the display (iteration) order of sets is arbitrary, I'm not sure what the significance would ever be, but my guess is that the display order would be the same for any given set, if constructed this way. But it sounds as if you know of a set that behaves differently. > What happens if you replace the ints with strings? Why? Then hash randomization kicks in, and you can run the exact same line of code multiple times and get different results. It's a coin toss. rosuav at sikorsky:~$ python3 -c 'print({"1", "2"})' {'1', '2'} rosuav at sikorsky:~$ python3 -c 'print({"1", "2"})' {'1', '2'} rosuav at sikorsky:~$ python3 -c 'print({"1", "2"})' {'1', '2'} rosuav at sikorsky:~$ python3 -c 'print({"1", "2"})' {'2', '1'} rosuav at sikorsky:~$ python3 -c 'print({"1", "2"})' {'2', '1'} rosuav at sikorsky:~$ python3 -c 'print({"1", "2"})' {'1', '2'} rosuav at sikorsky:~$ python3 -c 'print({"1", "2"})' {'2', '1'} rosuav at sikorsky:~$ python3 -c 'print({"1", "2"})' {'1', '2'} rosuav at sikorsky:~$ python3 -c 'print({"1", "2"})' {'2', '1'} rosuav at sikorsky:~$ python3 -c 'print({"1", "2"})' {'1', '2'} rosuav at sikorsky:~$ python3 -c 'print({"1", "2"})' {'1', '2'} ChrisA From greg.ewing at canterbury.ac.nz Tue Jul 5 05:31:52 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 05 Jul 2016 21:31:52 +1200 Subject: Improved nestedmodule decorator implementation In-Reply-To: References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577b1cc6$0$1584$c3e8da3$5496439d@news.astraweb.com> <577b2af3$0$1611$c3e8da3$5496439d@news.astraweb.com> <577b4f06$0$2752$c3e8da3$76491128@news.astraweb.com> Message-ID: I wrote: > The only shortcoming I can think of is that a nestedmodule > inside another nestedmodule won't be able to see the names > in the outer nestedmodule Actually, that's not correct -- the version I posted before actually crashes if you try to refer to a name in an outer nestedmodule from an inner nestedmodule. Here's an improved version that fully supports nesting to any depth. % python3 test_nested_nested.py foo blarg #------------------------------------------ # # test_nested_nested.py # #------------------------------------------ from nestedmodule import nestedmodule @nestedmodule def m1(): def foo(): print("foo") @nestedmodule def m2(): def blarg(): foo() print("blarg") m1.m2.blarg() #------------------------------------------ # # nestedmodule.py # #------------------------------------------ from types import CodeType, FunctionType, ModuleType from dis import dis def hack_code(f): """Hack 'return locals()' onto the end of the bytecode of f.""" code1 = f.__code__ bytes1 = code1.co_code names1 = code1.co_names n = len(names1) names2 = names1 + ('locals',) bytes2 = bytes1[:-4] + bytes([116, n, 0, 131, 0, 0, 83]) code2 = CodeType(code1.co_argcount, code1.co_kwonlyargcount, code1.co_nlocals, code1.co_stacksize, code1.co_flags, bytes2, code1.co_consts, names2, code1.co_varnames, code1.co_filename, code1.co_name, code1.co_firstlineno, code1.co_lnotab, code1.co_freevars, code1.co_cellvars) f2 = FunctionType(code2, f.__globals__, f.__name__, f.__kwdefaults__, f.__closure__) return f2 def nestedmodule(f): f2 = hack_code(f) l = f2() m = ModuleType(f.__name__) m.__dict__.update(l) return m From jussi.piitulainen at helsinki.fi Tue Jul 5 05:51:07 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 05 Jul 2016 12:51:07 +0300 Subject: How well do you know Python? References: Message-ID: Chris Angelico writes: > On Tue, Jul 5, 2016 at 6:36 PM, Peter Otten wrote: >> It looks like >> >> $ python3 -c 'print({1, 2})' >> {1, 2} >> $ python3 -c 'print({2, 1})' >> {1, 2} >> >> will always print the same output. Can you construct a set from two small >> integers where this is not the case? What's the difference? > > Given that the display (iteration) order of sets is arbitrary, I'm not > sure what the significance would ever be, but my guess is that the > display order would be the same for any given set, if constructed this > way. But it sounds as if you know of a set that behaves differently. The first thing that came to mind, {-1,-2} and {-2,-1}. But I haven't a clue. It doesn't happen with -1 and -3, or with another pair that I tried, and it doesn't seem to be about object identity. >> What happens if you replace the ints with strings? Why? > > Then hash randomization kicks in, and you can run the exact same line > of code multiple times and get different results. It's a coin toss. Oh, nice, a new way to generate random bits in shell scripts. From steve at pearwood.info Tue Jul 5 06:35:45 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 20:35:45 +1000 Subject: How well do you know Python? References: Message-ID: <577b8d83$0$1607$c3e8da3$5496439d@news.astraweb.com> On Tue, 5 Jul 2016 06:36 pm, Peter Otten wrote: > It looks like > > $ python3 -c 'print({1, 2})' > {1, 2} > $ python3 -c 'print({2, 1})' > {1, 2} > > will always print the same output. Can you construct a set from two small > integers where this is not the case? What's the difference? Define "small". According to some mathematicians, any number you can write down counts as small :-) > What happens if you replace the ints with strings? Why? Depends on the version of Python. Recent versions have hash randomisation turned on, so the order of identical sets/dicts running in identical code will vary from one run to another. [steve at ando 3.6]$ ./python -c "print({'a', 'b', 'c', 'd'})" {'c', 'b', 'd', 'a'} [steve at ando 3.6]$ ./python -c "print({'a', 'b', 'c', 'd'})" {'b', 'c', 'a', 'd'} [steve at ando 3.6]$ ./python -c "print({'a', 'b', 'c', 'd'})" {'c', 'a', 'd', 'b'} -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Tue Jul 5 06:46:30 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 20:46:30 +1000 Subject: How well do you know Python? References: Message-ID: <577b9008$0$22141$c3e8da3$5496439d@news.astraweb.com> On Tue, 5 Jul 2016 07:51 pm, Jussi Piitulainen wrote: > Chris Angelico writes: > >> On Tue, Jul 5, 2016 at 6:36 PM, Peter Otten wrote: >>> It looks like >>> >>> $ python3 -c 'print({1, 2})' >>> {1, 2} >>> $ python3 -c 'print({2, 1})' >>> {1, 2} >>> >>> will always print the same output. Can you construct a set from two >>> small integers where this is not the case? What's the difference? >> >> Given that the display (iteration) order of sets is arbitrary, I'm not >> sure what the significance would ever be, but my guess is that the >> display order would be the same for any given set, if constructed this >> way. But it sounds as if you know of a set that behaves differently. > > The first thing that came to mind, {-1,-2} and {-2,-1}. > > But I haven't a clue. It doesn't happen with -1 and -3, or with another > pair that I tried, and it doesn't seem to be about object identity. The hash of most small ints is equal to the int itself: py> for i in range(100): ... assert hash(i) == i ... py> With one exception: py> hash(-2) -2 py> hash(-1) -2 That's because in the C implementation of hash, -1 is used to indicate an error. >>> What happens if you replace the ints with strings? Why? >> >> Then hash randomization kicks in, and you can run the exact same line >> of code multiple times and get different results. It's a coin toss. > > Oh, nice, a new way to generate random bits in shell scripts. O_o You're joking, right? I'll just leave this here... https://docs.python.org/3.6/library/secrets.html -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Tue Jul 5 06:54:00 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 05 Jul 2016 20:54:00 +1000 Subject: Improved nestedmodule decorator implementation References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> <577b1cc6$0$1584$c3e8da3$5496439d@news.astraweb.com> <577b2af3$0$1611$c3e8da3$5496439d@news.astraweb.com> <577b4f06$0$2752$c3e8da3$76491128@news.astraweb.com> Message-ID: <577b91ca$0$1620$c3e8da3$5496439d@news.astraweb.com> On Tue, 5 Jul 2016 07:31 pm, Gregory Ewing wrote: > I wrote: >> The only shortcoming I can think of is that a nestedmodule >> inside another nestedmodule won't be able to see the names >> in the outer nestedmodule > > Actually, that's not correct -- the version I posted before > actually crashes if you try to refer to a name in an outer > nestedmodule from an inner nestedmodule. > > Here's an improved version that fully supports nesting to > any depth. That's impressive. And scary. And I fear not portable, since it uses byte-code hacking. But still nicely done. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From __peter__ at web.de Tue Jul 5 07:33:42 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 05 Jul 2016 13:33:42 +0200 Subject: How well do you know Python? References: Message-ID: Chris Angelico wrote: > On Tue, Jul 5, 2016 at 6:36 PM, Peter Otten <__peter__ at web.de> wrote: >> What will >> >> $ cat foo.py >> import foo >> class A: pass >> print(isinstance(foo.A(), A)) >> $ python -c 'import foo' >> ... >> $ python foo.py >> ... >> >> print? > > I refuse to play around with isinstance and old-style classes. > Particularly when circular imports are involved. Run this under Python > 3 and/or explicitly subclass object, and then I'd consider it. :) The intended lesson was that there may be two distinct classes __main__.A and foo.A Even though not just classes, but every object created in the script is affected this seems to cause the most subtle bugs. Maybe the setup can be simplified or the question rephrased to make this clearer. From rosuav at gmail.com Tue Jul 5 07:50:31 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Jul 2016 21:50:31 +1000 Subject: How well do you know Python? In-Reply-To: References: Message-ID: On Tue, Jul 5, 2016 at 9:33 PM, Peter Otten <__peter__ at web.de> wrote: > Chris Angelico wrote: > >> On Tue, Jul 5, 2016 at 6:36 PM, Peter Otten <__peter__ at web.de> wrote: >>> What will >>> >>> $ cat foo.py >>> import foo >>> class A: pass >>> print(isinstance(foo.A(), A)) >>> $ python -c 'import foo' >>> ... >>> $ python foo.py >>> ... >>> >>> print? >> >> I refuse to play around with isinstance and old-style classes. >> Particularly when circular imports are involved. Run this under Python >> 3 and/or explicitly subclass object, and then I'd consider it. :) > > The intended lesson was that there may be two distinct classes > > __main__.A and foo.A > > Even though not just classes, but every object created in the script is > affected this seems to cause the most subtle bugs. > > Maybe the setup can be simplified or the question rephrased to make this > clearer. Like I said, change the commands to "python3", or explicitly subclass object "class A(object): pass", and then it'll be using new-style classes. The two distinct classes problem is a very real one, and comes of circular (or not-technically-circular, as in the second case) imports. ChrisA From eryksun at gmail.com Tue Jul 5 08:45:41 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 5 Jul 2016 12:45:41 +0000 Subject: Nested class doesn't see class scope In-Reply-To: <577b4848$0$2763$c3e8da3$76491128@news.astraweb.com> References: <577b2768$0$1606$c3e8da3$5496439d@news.astraweb.com> <577b4848$0$2763$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Jul 5, 2016 at 5:40 AM, Steven D'Aprano wrote: > On Tuesday 05 July 2016 14:41, Ian Kelly wrote: > >> Class definitions don't create closures like functions do. When Python >> executes a class definition, the metaclass creates a dict, and then >> the interpreter execs the class body using that dict as the locals. >> The body of class A has one locals dict, and the body of class B has a >> completely separate locals dict. The only way to share variables >> between them (prior to the class objects actually being constructed) >> is via globals. > > > So, like nested functions in Python before "from __future__ import > nested_scopes". In Python 3.4+, the code for a class body does participate in closures. The CPython compiler implements this using the LOAD_CLASSDEREF instruction. However, classes don't create closures and default to storing to the locals dict (as class attributes), unless a name is declared global or nonlocal. Obviously writing to a global or nonlocal won't create a class attribute. For example: def f(): y = 0 class C: global x nonlocal y x = 1 y = 2 z = 3 return types.SimpleNamespace(**locals()) >>> ns = f() >>> x 1 >>> ns.y 2 >>> ns.C.z 3 >>> sorted(vars(ns.C)) ['__dict__', '__doc__', '__module__', '__weakref__', 'z'] From ian.g.kelly at gmail.com Tue Jul 5 10:41:44 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 5 Jul 2016 08:41:44 -0600 Subject: Making Classes Subclassable In-Reply-To: <577b707f$0$2917$c3e8da3$76491128@news.astraweb.com> References: <87eg79q1i0.fsf@handshake.de> <337f8071-ef4a-4ac5-867b-a5320c684730@googlegroups.com> <577b707f$0$2917$c3e8da3$76491128@news.astraweb.com> Message-ID: On Tue, Jul 5, 2016 at 2:31 AM, Steven D'Aprano wrote: > On Monday 04 July 2016 18:34, Lawrence D?Oliveiro wrote: > >> On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: >>> --> "type(obj)" or "obj.__class__" (there are small differences) >>> give you the type/class of "obj". >> >> When would it not be the same? > > > class X(object): > def __getattribute__(self, name): > if __name__ == '__class__': > return int > return super().__getattribute__(name) Did you actually test that? py> class X(object): ... def __getattribute__(self, name): ... if __name__ == '__class__': ... return int ... return super().__getattribute__(name) ... py> x = X() py> x.__class__ Certain attributes like __class__ and __dict__ are special. From steve at pearwood.info Tue Jul 5 10:46:21 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2016 00:46:21 +1000 Subject: Two curious errors when function globals are manipulated Message-ID: <577bc83f$0$1583$c3e8da3$5496439d@news.astraweb.com> I've come across two curious behaviours of a function using custom globals. In both cases, I have a function where __globals__ is set to a ChainMap. In the first, the builtin __import__ appears to both exist and not-exist at the same time: I can see the __import__ builtin, but the `import` statement fails with: ImportError: __import__ not found In the second, I can use `global` to declare a name in the global scope, apparently assign to it, but then the name doesn't exist. Attached is a single demo script which demonstrates the problems, for Python 3. I think both of these are bugs, or at least they are bugs if function.__globals__ is allowed to be set to something other than the module globals. Have I missed something? Is there documentation that says I shouldn't replace __globals__ with another dict? Is there a bug in my code? If not, I think these are both bugs. Does anyone disagree? -- Steven From ian.g.kelly at gmail.com Tue Jul 5 10:52:16 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 5 Jul 2016 08:52:16 -0600 Subject: Making Classes Subclassable In-Reply-To: <87eg79q1i0.fsf@handshake.de> References: <87eg79q1i0.fsf@handshake.de> Message-ID: On Mon, Jul 4, 2016 at 1:57 AM, dieter wrote: > Lawrence D?Oliveiro writes: > >> Some of the classes in Qahirah, my Cairo binding I found handy to reuse elsewhere, for example in my binding for Pixman . Subclassing is easy, but then you need to ensure that operations inherited from the superclass return instances of the right class. This means that superclass methods must never refer directly to the class by name for constructing new objects; they need to obtain the current class by more indirect means. > > --> "type(obj)" or "obj.__class__" (there are small differences) > give you the type/class of "obj". Another option is a classmethod factory: class X: @classmethod def new(cls, *args, **kwargs): return cls(*args, **kwargs) def method(self): return self.new() class Y(X): pass Y().method() will return a new Y instance. There's not a lot of reason to prefer this over type(self)(), but by overriding the classmethod you can have subclasses that use different signatures in the constructor but still support the same signature in the factory for compatibility with the base class. You can also make the classmethod private, if you wish. From ian.g.kelly at gmail.com Tue Jul 5 11:02:22 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 5 Jul 2016 09:02:22 -0600 Subject: Making Classes Subclassable In-Reply-To: <337f8071-ef4a-4ac5-867b-a5320c684730@googlegroups.com> References: <87eg79q1i0.fsf@handshake.de> <337f8071-ef4a-4ac5-867b-a5320c684730@googlegroups.com> Message-ID: On Mon, Jul 4, 2016 at 2:34 AM, Lawrence D?Oliveiro wrote: > On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: >> --> "type(obj)" or "obj.__class__" (there are small differences) >> give you the type/class of "obj". > > When would it not be the same? I think the only remaining difference in Python 3 is that obj.__class__ is assignable and type(obj) is not. For most uses, type(obj) would be preferred though, in the same way that len(obj) is preferable to obj.__len__(). From eryksun at gmail.com Tue Jul 5 11:27:15 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 5 Jul 2016 15:27:15 +0000 Subject: Two curious errors when function globals are manipulated In-Reply-To: <577bc83f$0$1583$c3e8da3$5496439d@news.astraweb.com> References: <577bc83f$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 5, 2016 at 2:46 PM, Steven D'Aprano wrote: > I've come across two curious behaviours of a function using custom globals. > In both cases, I have a function where __globals__ is set to a ChainMap. ChainMap implements the MutableMapping abstract base class. But CPython needs globals to be a dict. In the current implementation, LOAD_GLOBAL calls _PyDict_LoadGlobal, and STORE_GLOBAL calls PyDict_SetItem. They don't fall back on the abstract object APIs. OTOH, when executing unoptimized code in a class, locals can be an arbitrary mapping, e.g. as returned from a metaclass __prepare__ method. In this case, CPython LOAD_NAME and STORE_NAME fall back on the abstract APIs PyObject_GetItem and PyObject_SetItem. I don't see this documented in the execution and data models (maybe I overlooked it), but it's definitely documented for exec(): If only globals is provided, it must be a dictionary, which will be used for both the global and the local variables. If globals and locals are given, they are used for the global and local variables, respectively. If provided, locals can be any mapping object. https://docs.python.org/3/library/functions.html?highlight=globals#exec For example: >>> m = collections.ChainMap() >>> exec('x = 1', m) Traceback (most recent call last): File "", line 1, in TypeError: exec() globals must be a dict, not ChainMap >>> exec('x = 1', {}, m) >>> m['x'] 1 From steve at pearwood.info Tue Jul 5 11:33:13 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2016 01:33:13 +1000 Subject: Making Classes Subclassable References: <87eg79q1i0.fsf@handshake.de> <337f8071-ef4a-4ac5-867b-a5320c684730@googlegroups.com> <577b707f$0$2917$c3e8da3$76491128@news.astraweb.com> Message-ID: <577bd33a$0$1609$c3e8da3$5496439d@news.astraweb.com> On Wed, 6 Jul 2016 12:41 am, Ian Kelly wrote: > On Tue, Jul 5, 2016 at 2:31 AM, Steven D'Aprano > wrote: >> On Monday 04 July 2016 18:34, Lawrence D?Oliveiro wrote: >> >>> On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: >>>> --> "type(obj)" or "obj.__class__" (there are small differences) >>>> give you the type/class of "obj". >>> >>> When would it not be the same? >> >> >> class X(object): >> def __getattribute__(self, name): >> if __name__ == '__class__': >> return int >> return super().__getattribute__(name) > > Did you actually test that? Er, no, because if I had, I would have discovered the silly typo: __name__ instead of name, which screws up the whole thing... Trying again: py> class X(object): ... def __getattribute__(self, name): ... if name == '__class__': # NOTE SPELLING ... return int ... return super().__getattribute__(name) ... py> x = X() py> x.__class__ [...] > Certain attributes like __class__ and __dict__ are special. Indeed they are, but __class__ is not *that* special :-) -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From eryksun at gmail.com Tue Jul 5 11:37:42 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 5 Jul 2016 15:37:42 +0000 Subject: Two curious errors when function globals are manipulated In-Reply-To: References: <577bc83f$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 5, 2016 at 3:27 PM, eryk sun wrote: > ChainMap implements the MutableMapping abstract base class. But > CPython needs globals to be a dict. In the current implementation, > LOAD_GLOBAL calls _PyDict_LoadGlobal, and STORE_GLOBAL calls > PyDict_SetItem. They don't fall back on the abstract object APIs. Sorry, I was replying from memory, but partly mixed up 2.x and 3.x. In CPython 3.6, LOAD_GLOBAL does fall back on PyObject_GetItem, but STORE_GLOBAL still does not. The latter is short enough to quote: TARGET(STORE_GLOBAL) { PyObject *name = GETITEM(names, oparg); PyObject *v = POP(); int err; err = PyDict_SetItem(f->f_globals, name, v); Py_DECREF(v); if (err != 0) goto error; DISPATCH(); } From steve at pearwood.info Tue Jul 5 11:41:49 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2016 01:41:49 +1000 Subject: Making Classes Subclassable References: <87eg79q1i0.fsf@handshake.de> <337f8071-ef4a-4ac5-867b-a5320c684730@googlegroups.com> Message-ID: <577bd53e$0$1602$c3e8da3$5496439d@news.astraweb.com> On Wed, 6 Jul 2016 01:02 am, Ian Kelly wrote: > On Mon, Jul 4, 2016 at 2:34 AM, Lawrence D?Oliveiro > wrote: >> On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: >>> --> "type(obj)" or "obj.__class__" (there are small differences) >>> give you the type/class of "obj". >> >> When would it not be the same? > > I think the only remaining difference in Python 3 is that > obj.__class__ is assignable and type(obj) is not. For most uses, > type(obj) would be preferred though, in the same way that len(obj) is > preferable to obj.__len__(). Assigning to __class__ will change the result of type(obj). py> class A(object): ... pass ... py> class B(object): ... pass ... py> a = A() py> type(a) py> a.__class__ = B py> type(a) This is a deliberate design feature! Provided your classes are designed to be compatible, you can safely change an instance of class A into an instance of class B, and then have a.method() correctly call B.method. (Objective C makes *extensive* use of this technique in Cocoa's standard library functions, but entirely behind the scenes. Apple's semi-official stance on this is that they are allowed to do it because the know what they're doing, but anyone else who tries it is a muppet.) I don't know what this technique is called, but I'm going to call it adoption (as opposed to adaption) -- your A instance gets adopted by class B, after which it behaves like any other B instance. Again, I stress that A and B must be compatible (and written in Python, you can't do it with classes written in C), otherwise their methods won't find the attributes they expect. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Tue Jul 5 11:50:07 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2016 01:50:07 +1000 Subject: Two curious errors when function globals are manipulated References: <577bc83f$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: <577bd730$0$1615$c3e8da3$5496439d@news.astraweb.com> On Wed, 6 Jul 2016 01:27 am, eryk sun wrote: > On Tue, Jul 5, 2016 at 2:46 PM, Steven D'Aprano > wrote: >> I've come across two curious behaviours of a function using custom >> globals. In both cases, I have a function where __globals__ is set to a >> ChainMap. > > ChainMap implements the MutableMapping abstract base class. But > CPython needs globals to be a dict. In the current implementation, > LOAD_GLOBAL calls _PyDict_LoadGlobal, and STORE_GLOBAL calls > PyDict_SetItem. They don't fall back on the abstract object APIs. Which is why I use ChainDict, a subclass of ChainMap and dict. It's enough to allow the FunctionType constructor to accept the argument, and the assignment *appears* to take place. If PyDict_SetItem expects an actual dict (accept no substitutes or subclasses), why is there no error? I would have expected a segfault at worst or at least an exception. It works with exec: py> from collections import ChainMap py> class ChainDict(ChainMap, dict): ... pass ... py> m = ChainDict() py> exec("x = 1", m, m) py> m['x'] 1 (Tested in both 3.3 and 3.6.) -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From eryksun at gmail.com Tue Jul 5 12:01:47 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 5 Jul 2016 16:01:47 +0000 Subject: Two curious errors when function globals are manipulated In-Reply-To: References: <577bc83f$0$1583$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 5, 2016 at 3:37 PM, eryk sun wrote: > In CPython 3.6, LOAD_GLOBAL does fall back on PyObject_GetItem I did some digging to find when this changed in 3.3: https://hg.python.org/cpython/diff/e3ab8aa0216c/Python/ceval.c Notice in the last comment on issue 14385 that Martijn wanted to updated the docs for exec() to say that globals no longer has to be a dict, but that would be wrong since STORE_GLOBAL and DELETE_GLOBAL weren't updated. I don't know why it falls back on the abstract PyObject_GetItem for LOAD_GLOBAL considering the other opcodes weren't updated as well. It's pointless. From carl at oddbird.net Tue Jul 5 12:04:10 2016 From: carl at oddbird.net (Carl Meyer) Date: Tue, 5 Jul 2016 10:04:10 -0600 Subject: How well do you know Python? In-Reply-To: References: Message-ID: <577BDA7A.4090803@oddbird.net> On 07/05/2016 05:50 AM, Chris Angelico wrote: > On Tue, Jul 5, 2016 at 9:33 PM, Peter Otten <__peter__ at web.de> wrote: >> Chris Angelico wrote: >> >>> On Tue, Jul 5, 2016 at 6:36 PM, Peter Otten <__peter__ at web.de> wrote: >>>> What will >>>> >>>> $ cat foo.py >>>> import foo >>>> class A: pass >>>> print(isinstance(foo.A(), A)) >>>> $ python -c 'import foo' >>>> ... >>>> $ python foo.py >>>> ... >>>> >>>> print? [snip] >> The intended lesson was that there may be two distinct classes >> >> __main__.A and foo.A [snip] > The two distinct classes problem is a very real one, and comes of > circular (or not-technically-circular, as in the second case) imports. It can also come of pathological setups where a path and its parent are both on sys.path, so all import paths have an "optional" prefix (but you actually get a different copy of the module depending on whether you use that prefix). Carl -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: OpenPGP digital signature URL: From random832 at fastmail.com Tue Jul 5 12:12:11 2016 From: random832 at fastmail.com (Random832) Date: Tue, 05 Jul 2016 12:12:11 -0400 Subject: Two curious errors when function globals are manipulated In-Reply-To: <577bd730$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <577bc83f$0$1583$c3e8da3$5496439d@news.astraweb.com> <577bd730$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1467735131.1723094.657480257.65821B90@webmail.messagingengine.com> On Tue, Jul 5, 2016, at 11:50, Steven D'Aprano wrote: > If PyDict_SetItem expects an actual dict (accept no substitutes or > subclasses), why is there no error? I would have expected a segfault at > worst or at least an exception. Subclasses are fine. Sort of. In general if you pass a *subclass* of [say] dict to a built-in method that is expecting a real dict, the effect is that the assignments will go straight through to the real dict, and never call any overridden method. I.e. it's as if you called dict.__setitem__(self, key, value). Something your own __setitem__ method may have done [directly or via super()] anyway... or may not have. So any special logic in your own __setitem__, which may have included e.g. copying it to an alternate place, changing the key or value, or simply refusing to add the item to the dictionary at all, will be ignored, and your object may end up in an inconsistent state. From eryksun at gmail.com Tue Jul 5 12:13:59 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 5 Jul 2016 16:13:59 +0000 Subject: Two curious errors when function globals are manipulated In-Reply-To: <577bd730$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <577bc83f$0$1583$c3e8da3$5496439d@news.astraweb.com> <577bd730$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 5, 2016 at 3:50 PM, Steven D'Aprano wrote: > It works with exec: > > py> from collections import ChainMap > py> class ChainDict(ChainMap, dict): > ... pass > ... > py> m = ChainDict() > py> exec("x = 1", m, m) > py> m['x'] > 1 > > (Tested in both 3.3 and 3.6.) No, actually it doesn't work. Remember that when you store to a variable, it's implicitly a local variable, for which CPython uses STORE_NAME in unoptimized code. To test this properly you need to declare the variable as global, so that it uses STORE_GLOBAL: import dis from collections import ChainMap class ChainDict(ChainMap, dict): pass m = ChainDict() code = compile(r''' global x x, y = 1, 2 ''', '', 'exec') >>> dis.dis(code) 3 0 LOAD_CONST 3 ((1, 2)) 2 UNPACK_SEQUENCE 2 4 STORE_GLOBAL 0 (x) 6 STORE_NAME 1 (y) 8 LOAD_CONST 2 (None) 10 RETURN_VALUE >>> exec(code, m) >>> m ChainDict({'y': 2}) From eryksun at gmail.com Tue Jul 5 12:33:36 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 5 Jul 2016 16:33:36 +0000 Subject: Two curious errors when function globals are manipulated In-Reply-To: <1467735131.1723094.657480257.65821B90@webmail.messagingengine.com> References: <577bc83f$0$1583$c3e8da3$5496439d@news.astraweb.com> <577bd730$0$1615$c3e8da3$5496439d@news.astraweb.com> <1467735131.1723094.657480257.65821B90@webmail.messagingengine.com> Message-ID: On Tue, Jul 5, 2016 at 4:12 PM, Random832 wrote: > So any special logic in your own __setitem__, which may have > included e.g. copying it to an alternate place, changing the key or > value, or simply refusing to add the item to the dictionary at all, will > be ignored, and your object may end up in an inconsistent state. In this case, here's the value added by STORE_NAME using PyObject_SetItem, which calls __setitem__: >>> sorted(m) ['y'] Here are the values added by STORE_GLOBAL using PyDict_SetItem, which doesn't call __setitem__: >>> sorted(dict(m)) ['__builtins__', 'x'] ChainMap implements the following __setitem__: def __setitem__(self, key, value): self.maps[0][key] = value The item is never actually added to `self` (the dict instance). Then for __getitem__, we're again only seeing the items from `self.maps` instead of from `self`: def __getitem__(self, key): for mapping in self.maps: try: return mapping[key] except KeyError: pass return self.__missing__(key) From omastroi at gmail.com Tue Jul 5 12:35:37 2016 From: omastroi at gmail.com (TM) Date: Tue, 5 Jul 2016 12:35:37 -0400 Subject: Need help compiling Python-devel In-Reply-To: <22395.56426.786330.894837@localhost.localdomain> References: <87zipwik8m.fsf@handshake.de> <22395.56426.786330.894837@localhost.localdomain> Message-ID: This option is not straight forward. There are too many dependencies. Easier in Linux not so easy in AIX. Is it possible to copy the python executable (ie the code below)? # cp -p python python-devel Thanks, Tony On Tue, Jul 5, 2016 at 12:12 PM, Dieter Maurer wrote: > TM wrote at 2016-7-5 11:42 -0400: > Please stay on the mailin list (where others, too, can help you). > > >Thanks for the response. The reason for my install of python was, so I > >could compile samba from source. > > > >If what you say is true then why do I get the error below when I try to > >compile samba. > > > >Checking for custom code > > : *Could not find the python development headers* > >/usr/local/samba-4.4.4/wscript:106: error: the configuration failed (see > >'/usr/local/samba-4.4.4/bin/config.log') > > Likely, because it looks at a different place than you where your > locally compiled Python has placed it. > > > Likely, the easiest thing to do is installing the package > "python-dev" (or "python-devel" or similarly named) with you > operating system packageing tool. > > > > -- > Dieter > From harsh.mkg at gmail.com Tue Jul 5 16:10:25 2016 From: harsh.mkg at gmail.com (Harsh Gupta) Date: Tue, 5 Jul 2016 13:10:25 -0700 (PDT) Subject: Help: Python unit testing Message-ID: Hello All, I have been trying to write a test framework for a pretty simple command server application in python. I have not been able to figure out how to test the socket server. I would really appreciate if you could help me out in testing this application using unittest. I'm new to this. Please find the commandserver.py file . ''' import socket import time supported_commands = {'loopback', 'print', 'close'} class CommandServer: def __init__(self, ip='localhost', port=5000): self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server.bind((ip, port)) print "Server running" self.is_running = True def start_listening(self, num_connections=2): self.server.listen(num_connections) self._accept() def is_running(self): return self.is_running def _accept(self): self.client, self.remote_addr = self.server.accept() print "Received connection from %s" % (self.remote_addr,) self.is_connected = True def _get_data(self, bufsize=32): try: return self.client.recv(bufsize) except KeyboardInterrupt: self.close() def wait_for_commands(self): while self.is_connected: cmd = self._get_data() if cmd: if cmd not in supported_commands: print "Received unsupported command" continue if cmd in ("loopback", "print"): payload = self._get_data(512) if cmd == "loopback": self.client.sendall(payload) elif cmd == "print": print payload elif cmd == "close": self.close() def close(self): self.client.close() self.server.close() self.is_connected = False print "Connection closed" if __name__ == '__main__': cmd_server = CommandServer() cmd_server.start_listening() cmd_server.wait_for_commands() ''' The tests cases I came up with are: 1. Start the server 2. Establish connection with client 3. Test the server by sending 3 commands - loopback command should send all payload. - print command should print payload - close command should close the connection between server and client. 4. Raise error if any other command is send other than listed 3 commands Other nominal cases 1. Check if both the server and client are closed. It might happen that only one is closed. 2. Go to sleep/Cancel the connection if no command is received after a certain period of time. Thank You Harsh From harsh.mkg at gmail.com Tue Jul 5 16:15:05 2016 From: harsh.mkg at gmail.com (Harsh Gupta) Date: Tue, 5 Jul 2016 13:15:05 -0700 (PDT) Subject: Help: Python socket unit test framework Message-ID: Hello All, I have been trying to write a test framework for a pretty simple command server application in python. I have not been able to figure out how to test the socket server. I would really appreciate if you could help me out in testing this application using unittest. Please kindly review it. The tests cases I came up with are: 1. Start the server 2. Establish connection with client 3. Test the server by sending 3 commands - loopback command should send all payload. - print command should print payload - close command should close the connection between server and client. 4. Raise error if any other command is send other than listed 3 commands Other nominal cases 1. Check if both the server and client are closed. It might happen that only one is closed. 2. Go to sleep/Cancel the connection if no command is received after a certain period of time. '''' import socket import time supported_commands = {'loopback', 'print', 'close'} class CommandServer: def __init__(self, ip='localhost', port=5000): self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.server.bind((ip, port)) print "Server running" self.is_running = True def start_listening(self, num_connections=2): self.server.listen(num_connections) self._accept() def is_running(self): return self.is_running def _accept(self): self.client, self.remote_addr = self.server.accept() print "Received connection from %s" % (self.remote_addr,) self.is_connected = True def _get_data(self, bufsize=32): try: return self.client.recv(bufsize) except KeyboardInterrupt: self.close() def wait_for_commands(self): while self.is_connected: cmd = self._get_data() if cmd: if cmd not in supported_commands: print "Received unsupported command" continue if cmd in ("loopback", "print"): payload = self._get_data(512) if cmd == "loopback": self.client.sendall(payload) elif cmd == "print": print payload elif cmd == "close": self.close() def close(self): self.client.close() self.server.close() self.is_connected = False print "Connection closed" if __name__ == '__main__': cmd_server = CommandServer() cmd_server.start_listening() cmd_server.wait_for_commands() '''' Thank You H From nagle at animats.com Tue Jul 5 17:30:13 2016 From: nagle at animats.com (John Nagle) Date: Tue, 05 Jul 2016 14:30:13 -0700 Subject: py2exe crashes on simple program In-Reply-To: <577b5020$0$2752$c3e8da3$76491128@news.astraweb.com> References: <577b5020$0$2752$c3e8da3$76491128@news.astraweb.com> Message-ID: On 7/4/2016 11:13 PM, Steven D'Aprano wrote: > If you change it to "library.exe" does it work? Also, I consider this > a bug in py2exe: - it's an abuse of assert, using it to check > user-supplied input; - it's a failing assertion, which by definition > is a bug. I'm not trying to build "library.zip". That's a work file py2exe created. If I delete it, it's re-created by py2exe. The problem seems to be that my "setup.py" file didn't include a "console" entry, which tells py2exe the build target. Apparently, without that py2exe tries to build something bogus and blows up. After fixing that, the next error is Building 'dist\baudotrss.exe'. error: [Errno 2] No such file or directory: 'C:\\Program Files\\Python35\\lib\\site-packages\\py2exe\\run-py3.5-win-amd64.exe' Looks like Pip installed (yesterday) a version of py2exe that doesn't support Python 3.5. The py2exe directory contains "run-py3.3-win-amd64.exe" and "run-py3.4-win-amd64.exe", but not 3.5 versions. That's what PyPi says at "https://pypi.python.org/pypi/py2exe". The last version of py2exe was uploaded two years ago (2014-05-09) and is for Python 3.4. So of course it doesn't have the 3.5 binary executable it needs. Known problem. Stack Overflow reports py2exe is now broken for Python 3.5. Apparently it's a non-trivial fix, too. http://stackoverflow.com/questions/32963057/is-there-a-py2exe-version-thats-compatible-with-python-3-5 cx_freeze has been suggested as an alternative, but its own documents indicate it's only been tested through Python 3.4. Someone reported success with a development version. I guess people don't create Python executables much. John Nagle From Seymore4Head at Hotmail.invalid Tue Jul 5 18:05:24 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 05 Jul 2016 18:05:24 -0400 Subject: Appending an asterisk to the end of each line Message-ID: import os f_in = open('win.txt', 'r') f_out = open('win_new.txt', 'w') for line in f_in.read().splitlines(): f_out.write(line + " *\n") f_in.close() f_out.close() os.rename('win.txt', 'win_old.txt') os.rename('win_new.txt', 'win.txt') I just tried to reuse this program that was posted several months ago. I am using a text flie that is about 200 lines long and have named it win.txt. The file it creates when I run the program is win_new.txt but it's empty. From joel.goldstick at gmail.com Tue Jul 5 18:27:25 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 5 Jul 2016 18:27:25 -0400 Subject: Appending an asterisk to the end of each line In-Reply-To: References: Message-ID: On Tue, Jul 5, 2016 at 6:05 PM, Seymore4Head wrote: > import os > > f_in = open('win.txt', 'r') > f_out = open('win_new.txt', 'w') > > for line in f_in.read().splitlines(): > f_out.write(line + " *\n") > > f_in.close() > f_out.close() > > os.rename('win.txt', 'win_old.txt') > os.rename('win_new.txt', 'win.txt') > > > I just tried to reuse this program that was posted several months ago. > I am using a text flie that is about 200 lines long and have named it > win.txt. The file it creates when I run the program is win_new.txt > but it's empty. > > > -- > https://mail.python.org/mailman/listinfo/python-list Are you running program in same folder as text file? -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From Seymore4Head at Hotmail.invalid Tue Jul 5 18:29:26 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 05 Jul 2016 18:29:26 -0400 Subject: Appending an asterisk to the end of each line References: Message-ID: On Tue, 5 Jul 2016 18:27:25 -0400, Joel Goldstick wrote: >On Tue, Jul 5, 2016 at 6:05 PM, Seymore4Head > wrote: >> import os >> >> f_in = open('win.txt', 'r') >> f_out = open('win_new.txt', 'w') >> >> for line in f_in.read().splitlines(): >> f_out.write(line + " *\n") >> >> f_in.close() >> f_out.close() >> >> os.rename('win.txt', 'win_old.txt') >> os.rename('win_new.txt', 'win.txt') >> >> >> I just tried to reuse this program that was posted several months ago. >> I am using a text flie that is about 200 lines long and have named it >> win.txt. The file it creates when I run the program is win_new.txt >> but it's empty. >> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > >Are you running program in same folder as text file? Yes. I just reinstalled Python. Python is not installed in the same folder and I don't remember if it needs to have path entered. From joel.goldstick at gmail.com Tue Jul 5 18:40:51 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 5 Jul 2016 18:40:51 -0400 Subject: Appending an asterisk to the end of each line In-Reply-To: References: Message-ID: On Tue, Jul 5, 2016 at 6:29 PM, Seymore4Head wrote: > On Tue, 5 Jul 2016 18:27:25 -0400, Joel Goldstick > wrote: > >>On Tue, Jul 5, 2016 at 6:05 PM, Seymore4Head >> wrote: >>> import os >>> >>> f_in = open('win.txt', 'r') >>> f_out = open('win_new.txt', 'w') >>> >>> for line in f_in.read().splitlines(): >>> f_out.write(line + " *\n") >>> >>> f_in.close() >>> f_out.close() >>> >>> os.rename('win.txt', 'win_old.txt') >>> os.rename('win_new.txt', 'win.txt') >>> >>> >>> I just tried to reuse this program that was posted several months ago. >>> I am using a text flie that is about 200 lines long and have named it >>> win.txt. The file it creates when I run the program is win_new.txt >>> but it's empty. >>> >>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >> >>Are you running program in same folder as text file? > > Yes. I just reinstalled Python. Python is not installed in the same > folder and I don't remember if it needs to have path entered. > > > -- > https://mail.python.org/mailman/listinfo/python-list So, if you type python, do you enter the python shell? -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From python at mrabarnett.plus.com Tue Jul 5 19:03:29 2016 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 6 Jul 2016 00:03:29 +0100 Subject: Appending an asterisk to the end of each line In-Reply-To: References: Message-ID: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> On 2016-07-05 23:05, Seymore4Head wrote: > import os > > f_in = open('win.txt', 'r') > f_out = open('win_new.txt', 'w') > > for line in f_in.read().splitlines(): > f_out.write(line + " *\n") > > f_in.close() > f_out.close() > > os.rename('win.txt', 'win_old.txt') > os.rename('win_new.txt', 'win.txt') > > > I just tried to reuse this program that was posted several months ago. > I am using a text flie that is about 200 lines long and have named it > win.txt. The file it creates when I run the program is win_new.txt > but it's empty. > Although it creates a file called "win_new.txt", it then renames it to "win.txt", so "win_new.txt" shouldn't exist. Of course, if there's already a file called "win_old.txt", then the first rename will raise an exception, and you'll have "win_new.txt" and the original "win.txt". From Seymore4Head at Hotmail.invalid Tue Jul 5 19:04:33 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 05 Jul 2016 19:04:33 -0400 Subject: Appending an asterisk to the end of each line References: Message-ID: On Tue, 5 Jul 2016 18:40:51 -0400, Joel Goldstick wrote: >On Tue, Jul 5, 2016 at 6:29 PM, Seymore4Head > wrote: >> On Tue, 5 Jul 2016 18:27:25 -0400, Joel Goldstick >> wrote: >> >>>On Tue, Jul 5, 2016 at 6:05 PM, Seymore4Head >>> wrote: >>>> import os >>>> >>>> f_in = open('win.txt', 'r') >>>> f_out = open('win_new.txt', 'w') >>>> >>>> for line in f_in.read().splitlines(): >>>> f_out.write(line + " *\n") >>>> >>>> f_in.close() >>>> f_out.close() >>>> >>>> os.rename('win.txt', 'win_old.txt') >>>> os.rename('win_new.txt', 'win.txt') >>>> >>>> >>>> I just tried to reuse this program that was posted several months ago. >>>> I am using a text flie that is about 200 lines long and have named it >>>> win.txt. The file it creates when I run the program is win_new.txt >>>> but it's empty. >>>> >>>> >>>> -- >>>> https://mail.python.org/mailman/listinfo/python-list >>> >>>Are you running program in same folder as text file? >> >> Yes. I just reinstalled Python. Python is not installed in the same >> folder and I don't remember if it needs to have path entered. >> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > >So, if you type python, do you enter the python shell? I am using XP and launching the program from another drive/folder than the boot drive. The program has .py extension and the icon shows it is associated with Python. I tried "start run" and then typed python and it did show the dos box with c:\python34/python.exe and the python shell. From torriem at gmail.com Tue Jul 5 19:08:37 2016 From: torriem at gmail.com (Michael Torrie) Date: Tue, 5 Jul 2016 17:08:37 -0600 Subject: Need help compiling Python-devel In-Reply-To: References: <87zipwik8m.fsf@handshake.de> <22395.56426.786330.894837@localhost.localdomain> Message-ID: <7ba512a4-7ea2-a746-55b5-a365550201a1@gmail.com> On 07/05/2016 10:35 AM, TM wrote: > This option is not straight forward. There are too many dependencies. > Easier in Linux not so easy in AIX. > > Is it possible to copy the python executable (ie the code below)? > # cp -p python python-devel What is this python-devel thing? You said you wanted the libraries and header files. Those are part of the python source distribution. If you have Python compiled and running, then the libraries are already there since python needs them to run, and, if you installed from source, you should already have the header files. I'm unclear as to why you would copy the python binary to python-devel. From lawrencedo99 at gmail.com Tue Jul 5 19:11:39 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 5 Jul 2016 16:11:39 -0700 (PDT) Subject: Need help compiling Python-devel In-Reply-To: References: <87zipwik8m.fsf@handshake.de> <22395.56426.786330.894837@localhost.localdomain> Message-ID: <58f3a0e4-353e-42ad-80db-ea81677d9d0d@googlegroups.com> On Wednesday, July 6, 2016 at 4:35:54 AM UTC+12, TM wrote: > > This option is not straight forward. There are too many dependencies. > Easier in Linux not so easy in AIX. POWER hardware? It might be easier and quicker to get Linux running on the machine, and figure it out there, than to try it under AIX... From Seymore4Head at Hotmail.invalid Tue Jul 5 19:15:13 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 05 Jul 2016 19:15:13 -0400 Subject: Appending an asterisk to the end of each line References: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> Message-ID: <7pfonb5k9h6uahq8ncfhrat411rjld6k63@4ax.com> On Wed, 6 Jul 2016 00:03:29 +0100, MRAB wrote: >On 2016-07-05 23:05, Seymore4Head wrote: >> import os >> >> f_in = open('win.txt', 'r') >> f_out = open('win_new.txt', 'w') >> >> for line in f_in.read().splitlines(): >> f_out.write(line + " *\n") >> >> f_in.close() >> f_out.close() >> >> os.rename('win.txt', 'win_old.txt') >> os.rename('win_new.txt', 'win.txt') >> >> >> I just tried to reuse this program that was posted several months ago. >> I am using a text flie that is about 200 lines long and have named it >> win.txt. The file it creates when I run the program is win_new.txt >> but it's empty. >> >Although it creates a file called "win_new.txt", it then renames it to >"win.txt", so "win_new.txt" shouldn't exist. > >Of course, if there's already a file called "win_old.txt", then the >first rename will raise an exception, and you'll have "win_new.txt" and >the original "win.txt". When I run the program it creates a file called win_new.txt and win.txt remains unchanged. From joel.goldstick at gmail.com Tue Jul 5 19:15:23 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 5 Jul 2016 19:15:23 -0400 Subject: Appending an asterisk to the end of each line In-Reply-To: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> References: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> Message-ID: On Tue, Jul 5, 2016 at 7:03 PM, MRAB wrote: > On 2016-07-05 23:05, Seymore4Head wrote: >> >> import os >> >> f_in = open('win.txt', 'r') >> f_out = open('win_new.txt', 'w') >> >> for line in f_in.read().splitlines(): >> f_out.write(line + " *\n") >> >> f_in.close() >> f_out.close() >> >> os.rename('win.txt', 'win_old.txt') >> os.rename('win_new.txt', 'win.txt') >> >> >> I just tried to reuse this program that was posted several months ago. >> I am using a text flie that is about 200 lines long and have named it >> win.txt. The file it creates when I run the program is win_new.txt >> but it's empty. >> > Although it creates a file called "win_new.txt", it then renames it to > "win.txt", so "win_new.txt" shouldn't exist. > > Of course, if there's already a file called "win_old.txt", then the first > rename will raise an exception, and you'll have "win_new.txt" and the > original "win.txt". > > -- > https://mail.python.org/mailman/listinfo/python-list Why don't you comment out the renames, and see what happens? -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From Seymore4Head at Hotmail.invalid Tue Jul 5 19:29:21 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 05 Jul 2016 19:29:21 -0400 Subject: Appending an asterisk to the end of each line References: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> Message-ID: <7ggonbtg4vhul20v11qvsiufcks1dvouop@4ax.com> On Tue, 5 Jul 2016 19:15:23 -0400, Joel Goldstick wrote: >On Tue, Jul 5, 2016 at 7:03 PM, MRAB wrote: >> On 2016-07-05 23:05, Seymore4Head wrote: >>> >>> import os >>> >>> f_in = open('win.txt', 'r') >>> f_out = open('win_new.txt', 'w') >>> >>> for line in f_in.read().splitlines(): >>> f_out.write(line + " *\n") >>> >>> f_in.close() >>> f_out.close() >>> >>> os.rename('win.txt', 'win_old.txt') >>> os.rename('win_new.txt', 'win.txt') >>> >>> >>> I just tried to reuse this program that was posted several months ago. >>> I am using a text flie that is about 200 lines long and have named it >>> win.txt. The file it creates when I run the program is win_new.txt >>> but it's empty. >>> >> Although it creates a file called "win_new.txt", it then renames it to >> "win.txt", so "win_new.txt" shouldn't exist. >> >> Of course, if there's already a file called "win_old.txt", then the first >> rename will raise an exception, and you'll have "win_new.txt" and the >> original "win.txt". >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > >Why don't you comment out the renames, and see what happens? I really don't care if the filename gets renamed or not. I commented out the renames, but I still get a new file called win_new.txt and it is empty. The original is unchanged. From rosuav at gmail.com Tue Jul 5 19:38:47 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2016 09:38:47 +1000 Subject: Appending an asterisk to the end of each line In-Reply-To: References: Message-ID: On Wed, Jul 6, 2016 at 9:04 AM, Seymore4Head wrote: > I am using XP and launching the program from another drive/folder than > the boot drive. > > The program has .py extension and the icon shows it is associated with > Python. > > I tried "start run" and then typed python and it did show the dos box > with c:\python34/python.exe and the python shell. Okay. Step 1: Get a better operating system than Windows XP. Either upgrade to a newer version of Windows, or (my recommended option) switch to something like Debian Linux. Step 2, whether or not you do step 1: Become familiar with the command line. If you're staying with Windows, that means Start, Run, cmd.exe. Run your program from the terminal, and (this is the most important part) *copy and paste* its output into your next email asking for help. My suspicion is that your script is terminating with an exception somewhere, and you're not seeing it because the Windows association system gives you a Python that comes up and then disappears promptly when the program terminates. Step 3: If the above hasn't trivially solved your problem, now it's time for actual debugging work. Pepper your code with print() calls, showing the values of various things, until you figure out what's going on. Have fun! ChrisA From Seymore4Head at Hotmail.invalid Tue Jul 5 19:45:52 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 05 Jul 2016 19:45:52 -0400 Subject: Appending an asterisk to the end of each line References: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> <7ggonbtg4vhul20v11qvsiufcks1dvouop@4ax.com> Message-ID: On Tue, 05 Jul 2016 19:29:21 -0400, Seymore4Head wrote: >On Tue, 5 Jul 2016 19:15:23 -0400, Joel Goldstick > wrote: > >>On Tue, Jul 5, 2016 at 7:03 PM, MRAB wrote: >>> On 2016-07-05 23:05, Seymore4Head wrote: >>>> >>>> import os >>>> >>>> f_in = open('win.txt', 'r') >>>> f_out = open('win_new.txt', 'w') >>>> >>>> for line in f_in.read().splitlines(): >>>> f_out.write(line + " *\n") >>>> >>>> f_in.close() >>>> f_out.close() >>>> >>>> os.rename('win.txt', 'win_old.txt') >>>> os.rename('win_new.txt', 'win.txt') >>>> >>>> >>>> I just tried to reuse this program that was posted several months ago. >>>> I am using a text flie that is about 200 lines long and have named it >>>> win.txt. The file it creates when I run the program is win_new.txt >>>> but it's empty. >>>> >>> Although it creates a file called "win_new.txt", it then renames it to >>> "win.txt", so "win_new.txt" shouldn't exist. >>> >>> Of course, if there's already a file called "win_old.txt", then the first >>> rename will raise an exception, and you'll have "win_new.txt" and the >>> original "win.txt". >>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >> >>Why don't you comment out the renames, and see what happens? > >I really don't care if the filename gets renamed or not. I commented >out the renames, but I still get a new file called win_new.txt and it >is empty. > >The original is unchanged. I just tried this on a 3 line text file and it works. I am looking through the text file and have found at least two suspicious characters. One is a German letter and the other is a characters that has been replaced by a square symbol. From Seymore4Head at Hotmail.invalid Tue Jul 5 19:49:30 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 05 Jul 2016 19:49:30 -0400 Subject: Appending an asterisk to the end of each line References: Message-ID: On Wed, 6 Jul 2016 09:38:47 +1000, Chris Angelico wrote: >On Wed, Jul 6, 2016 at 9:04 AM, Seymore4Head > wrote: >> I am using XP and launching the program from another drive/folder than >> the boot drive. >> >> The program has .py extension and the icon shows it is associated with >> Python. >> >> I tried "start run" and then typed python and it did show the dos box >> with c:\python34/python.exe and the python shell. > >Okay. Step 1: Get a better operating system than Windows XP. Either >upgrade to a newer version of Windows, or (my recommended option) >switch to something like Debian Linux. > >Step 2, whether or not you do step 1: Become familiar with the command >line. If you're staying with Windows, that means Start, Run, cmd.exe. >Run your program from the terminal, and (this is the most important >part) *copy and paste* its output into your next email asking for >help. My suspicion is that your script is terminating with an >exception somewhere, and you're not seeing it because the Windows >association system gives you a Python that comes up and then >disappears promptly when the program terminates. > >Step 3: If the above hasn't trivially solved your problem, now it's >time for actual debugging work. Pepper your code with print() calls, >showing the values of various things, until you figure out what's >going on. > >Have fun! > >ChrisA Thanks for the suggestions. From python at mrabarnett.plus.com Tue Jul 5 20:05:12 2016 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 6 Jul 2016 01:05:12 +0100 Subject: Appending an asterisk to the end of each line In-Reply-To: References: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> <7ggonbtg4vhul20v11qvsiufcks1dvouop@4ax.com> Message-ID: On 2016-07-06 00:45, Seymore4Head wrote: > On Tue, 05 Jul 2016 19:29:21 -0400, Seymore4Head > wrote: > >>On Tue, 5 Jul 2016 19:15:23 -0400, Joel Goldstick >> wrote: >> >>>On Tue, Jul 5, 2016 at 7:03 PM, MRAB wrote: >>>> On 2016-07-05 23:05, Seymore4Head wrote: >>>>> >>>>> import os >>>>> >>>>> f_in = open('win.txt', 'r') >>>>> f_out = open('win_new.txt', 'w') >>>>> >>>>> for line in f_in.read().splitlines(): >>>>> f_out.write(line + " *\n") >>>>> >>>>> f_in.close() >>>>> f_out.close() >>>>> >>>>> os.rename('win.txt', 'win_old.txt') >>>>> os.rename('win_new.txt', 'win.txt') >>>>> >>>>> >>>>> I just tried to reuse this program that was posted several months ago. >>>>> I am using a text flie that is about 200 lines long and have named it >>>>> win.txt. The file it creates when I run the program is win_new.txt >>>>> but it's empty. >>>>> >>>> Although it creates a file called "win_new.txt", it then renames it to >>>> "win.txt", so "win_new.txt" shouldn't exist. >>>> >>>> Of course, if there's already a file called "win_old.txt", then the first >>>> rename will raise an exception, and you'll have "win_new.txt" and the >>>> original "win.txt". >>>> >>>> -- >>>> https://mail.python.org/mailman/listinfo/python-list >>> >>>Why don't you comment out the renames, and see what happens? >> >>I really don't care if the filename gets renamed or not. I commented >>out the renames, but I still get a new file called win_new.txt and it >>is empty. >> >>The original is unchanged. > > I just tried this on a 3 line text file and it works. > > I am looking through the text file and have found at least two > suspicious characters. One is a German letter and the other is a > characters that has been replaced by a square symbol. > That suggests to me that it's an encoding problem (the traceback would've indicated that). Specify an encoding when you open the files: f_in = open('win.txt', 'r', encoding='utf-8') f_out = open('win_new.txt', 'w', encoding='utf-8') assuming that 'win.txt' is indeed encoded in UTF-8. (It might be something like ISO-8859-1 instead.) From Seymore4Head at Hotmail.invalid Tue Jul 5 20:05:20 2016 From: Seymore4Head at Hotmail.invalid (Seymore4Head) Date: Tue, 05 Jul 2016 20:05:20 -0400 Subject: Appending an asterisk to the end of each line References: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> <7ggonbtg4vhul20v11qvsiufcks1dvouop@4ax.com> Message-ID: On Wed, 6 Jul 2016 01:05:12 +0100, MRAB wrote: >On 2016-07-06 00:45, Seymore4Head wrote: >> On Tue, 05 Jul 2016 19:29:21 -0400, Seymore4Head >> wrote: >> >>>On Tue, 5 Jul 2016 19:15:23 -0400, Joel Goldstick >>> wrote: >>> >>>>On Tue, Jul 5, 2016 at 7:03 PM, MRAB wrote: >>>>> On 2016-07-05 23:05, Seymore4Head wrote: >>>>>> >>>>>> import os >>>>>> >>>>>> f_in = open('win.txt', 'r') >>>>>> f_out = open('win_new.txt', 'w') >>>>>> >>>>>> for line in f_in.read().splitlines(): >>>>>> f_out.write(line + " *\n") >>>>>> >>>>>> f_in.close() >>>>>> f_out.close() >>>>>> >>>>>> os.rename('win.txt', 'win_old.txt') >>>>>> os.rename('win_new.txt', 'win.txt') >>>>>> >>>>>> >>>>>> I just tried to reuse this program that was posted several months ago. >>>>>> I am using a text flie that is about 200 lines long and have named it >>>>>> win.txt. The file it creates when I run the program is win_new.txt >>>>>> but it's empty. >>>>>> >>>>> Although it creates a file called "win_new.txt", it then renames it to >>>>> "win.txt", so "win_new.txt" shouldn't exist. >>>>> >>>>> Of course, if there's already a file called "win_old.txt", then the first >>>>> rename will raise an exception, and you'll have "win_new.txt" and the >>>>> original "win.txt". >>>>> >>>>> -- >>>>> https://mail.python.org/mailman/listinfo/python-list >>>> >>>>Why don't you comment out the renames, and see what happens? >>> >>>I really don't care if the filename gets renamed or not. I commented >>>out the renames, but I still get a new file called win_new.txt and it >>>is empty. >>> >>>The original is unchanged. >> >> I just tried this on a 3 line text file and it works. >> >> I am looking through the text file and have found at least two >> suspicious characters. One is a German letter and the other is a >> characters that has been replaced by a square symbol. >> >That suggests to me that it's an encoding problem (the traceback >would've indicated that). > >Specify an encoding when you open the files: > >f_in = open('win.txt', 'r', encoding='utf-8') >f_out = open('win_new.txt', 'w', encoding='utf-8') > >assuming that 'win.txt' is indeed encoded in UTF-8. (It might be >something like ISO-8859-1 instead.) Thanks. It is working now that I removed those two characters. From bc at freeuk.com Tue Jul 5 20:53:36 2016 From: bc at freeuk.com (BartC) Date: Wed, 6 Jul 2016 01:53:36 +0100 Subject: Creating a calculator In-Reply-To: References: <1mpph6r.u6n05219srlzsN%pdorange@pas-de-pub-merci.mac.com> Message-ID: On 02/07/2016 01:16, DFS wrote: > On 7/1/2016 5:34 AM, Pierre-Alain Dorange wrote: > > >> More reduced : >> ---------------------------------- >> u=raw_input('Enter calculation:") >> print eval(u) >> ---------------------------------- >> works and compute : >> 1+2+3+4-1+4*2 >> 2+3.0/2-0.5 >> >> Perform better and shorter, but less educationnal of course... > > > 2 lines? Love it! That's not really implementing a calculator. It's just feeding the input to Python to execute immediately. I can reduce it to zero lines: start Python so that the >>> prompt appears. Then type in: >>> 2+3.0/2-0.5 and so on. No other Python code is needed. -- Bartc From python at mrabarnett.plus.com Tue Jul 5 22:15:08 2016 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 6 Jul 2016 03:15:08 +0100 Subject: Appending an asterisk to the end of each line In-Reply-To: References: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> <7ggonbtg4vhul20v11qvsiufcks1dvouop@4ax.com> Message-ID: <497a7e9e-7f5b-62a6-7f2a-af85e3d0dcc0@mrabarnett.plus.com> On 2016-07-06 01:05, Seymore4Head wrote: > On Wed, 6 Jul 2016 01:05:12 +0100, MRAB > wrote: > >>On 2016-07-06 00:45, Seymore4Head wrote: >>> On Tue, 05 Jul 2016 19:29:21 -0400, Seymore4Head >>> wrote: >>> >>>>On Tue, 5 Jul 2016 19:15:23 -0400, Joel Goldstick >>>> wrote: >>>> >>>>>On Tue, Jul 5, 2016 at 7:03 PM, MRAB wrote: >>>>>> On 2016-07-05 23:05, Seymore4Head wrote: >>>>>>> >>>>>>> import os >>>>>>> >>>>>>> f_in = open('win.txt', 'r') >>>>>>> f_out = open('win_new.txt', 'w') >>>>>>> >>>>>>> for line in f_in.read().splitlines(): >>>>>>> f_out.write(line + " *\n") >>>>>>> >>>>>>> f_in.close() >>>>>>> f_out.close() >>>>>>> >>>>>>> os.rename('win.txt', 'win_old.txt') >>>>>>> os.rename('win_new.txt', 'win.txt') >>>>>>> >>>>>>> >>>>>>> I just tried to reuse this program that was posted several months ago. >>>>>>> I am using a text flie that is about 200 lines long and have named it >>>>>>> win.txt. The file it creates when I run the program is win_new.txt >>>>>>> but it's empty. >>>>>>> >>>>>> Although it creates a file called "win_new.txt", it then renames it to >>>>>> "win.txt", so "win_new.txt" shouldn't exist. >>>>>> >>>>>> Of course, if there's already a file called "win_old.txt", then the first >>>>>> rename will raise an exception, and you'll have "win_new.txt" and the >>>>>> original "win.txt". >>>>>> >>>>>> -- >>>>>> https://mail.python.org/mailman/listinfo/python-list >>>>> >>>>>Why don't you comment out the renames, and see what happens? >>>> >>>>I really don't care if the filename gets renamed or not. I commented >>>>out the renames, but I still get a new file called win_new.txt and it >>>>is empty. >>>> >>>>The original is unchanged. >>> >>> I just tried this on a 3 line text file and it works. >>> >>> I am looking through the text file and have found at least two >>> suspicious characters. One is a German letter and the other is a >>> characters that has been replaced by a square symbol. >>> >>That suggests to me that it's an encoding problem (the traceback >>would've indicated that). >> >>Specify an encoding when you open the files: >> >>f_in = open('win.txt', 'r', encoding='utf-8') >>f_out = open('win_new.txt', 'w', encoding='utf-8') >> >>assuming that 'win.txt' is indeed encoded in UTF-8. (It might be >>something like ISO-8859-1 instead.) > > Thanks. > > It is working now that I removed those two characters. > So, you didn't really fix it, you just changed the input to what your program is able to handle... :-) From lawrencedo99 at gmail.com Tue Jul 5 22:31:07 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 5 Jul 2016 19:31:07 -0700 (PDT) Subject: Making Classes Subclassable In-Reply-To: References: <87eg79q1i0.fsf@handshake.de> <337f8071-ef4a-4ac5-867b-a5320c684730@googlegroups.com> Message-ID: <998c5088-027a-478b-993d-99fef00edf13@googlegroups.com> On Wednesday, July 6, 2016 at 3:03:26 AM UTC+12, Ian wrote: > > On Mon, Jul 4, 2016 at 2:34 AM, Lawrence D?Oliveiro wrote: >> >> On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: >>> --> "type(obj)" or "obj.__class__" (there are small differences) >>> give you the type/class of "obj". >> >> When would it not be the same? > > I think the only remaining difference in Python 3 is that > obj.__class__ is assignable and type(obj) is not. For most uses, > type(obj) would be preferred though, in the same way that len(obj) is > preferable to obj.__len__(). OK, I think that makes sense. From steve at pearwood.info Tue Jul 5 22:35:00 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2016 12:35:00 +1000 Subject: Appending an asterisk to the end of each line References: <72a10a7f-c2a1-fb09-21cb-d6204d9a4f0a@mrabarnett.plus.com> <7ggonbtg4vhul20v11qvsiufcks1dvouop@4ax.com> Message-ID: <577c6e56$0$1586$c3e8da3$5496439d@news.astraweb.com> On Wed, 6 Jul 2016 10:05 am, Seymore4Head wrote: > On Wed, 6 Jul 2016 01:05:12 +0100, MRAB > wrote: >>That suggests to me that it's an encoding problem (the traceback >>would've indicated that). >> >>Specify an encoding when you open the files: >> >>f_in = open('win.txt', 'r', encoding='utf-8') >>f_out = open('win_new.txt', 'w', encoding='utf-8') >> >>assuming that 'win.txt' is indeed encoded in UTF-8. (It might be >>something like ISO-8859-1 instead.) > > Thanks. > > It is working now that I removed those two characters. And it will break again next time you use the script, if the input file contains "those characters" (which, I stress, are perfectly reasonable characters for a text file to contain). What you should take from this is Chris' advice to learn better debugging skills: I am absolutely certain that Python will have displayed a traceback hinting what went wrong, which you could then use to solve the problem for good rather than just cover it up. If you're not seeing that traceback, your ability to program is crippled. You'll be like somebody trying to assemble a jigsaw puzzle in the dark, wearing thick mittens. So you're first priority ought to be to work out how to run Python code without the tracebacks disappearing. (Either that, or make sure your code is perfect, first time, every time.) At the moment, you're in the situation of a car manufacturer that has just discovered a defect in their cars: "If you drive through a puddle with the rear left wheel at high speed, water splashes up into the body, causes a short in the electronics, and the gas tank catches fire." "That's okay, we can just pave over the factory grounds and get rid of the puddles." Your script "catches fire" when given input containing non-ASCII characters. You don't really know why, and you haven't fixed it, but you've "solved" the problem by "paving over the puddles". Except not really -- the problem is still there, and if your script ever gets used on a puddle you've missed, it will catch fire again. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Tue Jul 5 23:00:20 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 06 Jul 2016 13:00:20 +1000 Subject: Two curious errors when function globals are manipulated References: <577bc83f$0$1583$c3e8da3$5496439d@news.astraweb.com> <577bd730$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <577c7445$0$1598$c3e8da3$5496439d@news.astraweb.com> On Wed, 6 Jul 2016 02:13 am, eryk sun wrote: > On Tue, Jul 5, 2016 at 3:50 PM, Steven D'Aprano > wrote: >> It works with exec: [...] > No, actually it doesn't work. Remember that when you store to a > variable, it's implicitly a local variable, for which CPython uses > STORE_NAME in unoptimized code. To test this properly you need to > declare the variable as global, so that it uses STORE_GLOBAL: /face-palm Of course you're right, I knew that. Sorry for the noise. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From lawrencedo99 at gmail.com Tue Jul 5 23:04:25 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 5 Jul 2016 20:04:25 -0700 (PDT) Subject: Making Classes Subclassable In-Reply-To: References: <87eg79q1i0.fsf@handshake.de> Message-ID: On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote: > > Lawrence D?Oliveiro writes: > > > Some of the classes in Qahirah, my Cairo binding > I found handy to reuse elsewhere, for > example in my binding for Pixman . > Subclassing is easy, but then you need to ensure that operations inherited > from the superclass return instances of the right class. This means that > superclass methods must never refer directly to the class by name for > constructing new objects; they need to obtain the current class by more > indirect means. > > --> "type(obj)" or "obj.__class__" (there are small differences) > give you the type/class of "obj". OK, both updated. Funny how you find other bugs when revisiting code after a while. :) From lawrencedo99 at gmail.com Tue Jul 5 23:08:51 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 5 Jul 2016 20:08:51 -0700 (PDT) Subject: How well do you know Python? In-Reply-To: References: Message-ID: <1578346e-738a-4ce8-b1c5-63dbdbe9a678@googlegroups.com> On Tuesday, July 5, 2016 at 9:51:21 PM UTC+12, Jussi Piitulainen wrote: > > Chris Angelico writes: > >> Then hash randomization kicks in, and you can run the exact same line >> of code multiple times and get different results. It's a coin toss. > > Oh, nice, a new way to generate random bits in shell scripts. Please, don?t do that... From lawrencedo99 at gmail.com Wed Jul 6 00:04:39 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 5 Jul 2016 21:04:39 -0700 (PDT) Subject: Spot the bug: getoptquestion.py In-Reply-To: References: <577a4766$0$5839$e4fe514c@news.xs4all.nl> <577a58b9$0$5902$e4fe514c@news.xs4all.nl> Message-ID: On Tuesday, July 5, 2016 at 1:42:42 AM UTC+12, Chris Angelico wrote: > The getopt module is designed to match the C getopt function, which I've > never used; for my command-line parsing, I use argparse instead > (usually via some wrapper that cuts down the duplication, like clize). getopt seems so much simpler. From rosuav at gmail.com Wed Jul 6 00:14:47 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jul 2016 14:14:47 +1000 Subject: Spot the bug: getoptquestion.py In-Reply-To: References: <577a4766$0$5839$e4fe514c@news.xs4all.nl> <577a58b9$0$5902$e4fe514c@news.xs4all.nl> Message-ID: On Wed, Jul 6, 2016 at 2:04 PM, Lawrence D?Oliveiro wrote: > On Tuesday, July 5, 2016 at 1:42:42 AM UTC+12, Chris Angelico wrote: > >> The getopt module is designed to match the C getopt function, which I've >> never used; for my command-line parsing, I use argparse instead >> (usually via some wrapper that cuts down the duplication, like clize). > > getopt seems so much simpler. Look at clize: https://github.com/Rosuav/LetMeKnow/blob/master/letmeknow.py I just put docstrings on my functions, slap "@command" above them, and with minimal boilerplate, I have a fully-working command line interface. It's a wrapper around argparse. ChrisA From orgnut at yahoo.com Wed Jul 6 00:37:09 2016 From: orgnut at yahoo.com (Larry Hudson) Date: Tue, 5 Jul 2016 21:37:09 -0700 Subject: Appending an asterisk to the end of each line In-Reply-To: References: Message-ID: On 07/05/2016 03:05 PM, Seymore4Head wrote: > import os > > f_in = open('win.txt', 'r') > f_out = open('win_new.txt', 'w') > > for line in f_in.read().splitlines(): > f_out.write(line + " *\n") > > f_in.close() > f_out.close() > > os.rename('win.txt', 'win_old.txt') > os.rename('win_new.txt', 'win.txt') > > > I just tried to reuse this program that was posted several months ago. > I am using a text flie that is about 200 lines long and have named it > win.txt. The file it creates when I run the program is win_new.txt > but it's empty. > > Not your problem, but you can simplify your read/write loop to: for line in f_in: f_out.write(line[:-1] + ' *\n') The 'line[:-1]' expression gives you the line up to but not including the trailing newline. Alternately, use: f_out.write(line.rstrip() + ' *\n') -- -=- Larry -=- From cs at zip.com.au Wed Jul 6 01:35:13 2016 From: cs at zip.com.au (cs at zip.com.au) Date: Wed, 6 Jul 2016 15:35:13 +1000 Subject: Appending an asterisk to the end of each line In-Reply-To: References: Message-ID: <20160706053513.GA3675@cskk.homeip.net> On 05Jul2016 21:37, Python List wrote: >On 07/05/2016 03:05 PM, Seymore4Head wrote: >>import os >> >>f_in = open('win.txt', 'r') >>f_out = open('win_new.txt', 'w') >> >>for line in f_in.read().splitlines(): >> f_out.write(line + " *\n") >> >>f_in.close() >>f_out.close() >> >>os.rename('win.txt', 'win_old.txt') >>os.rename('win_new.txt', 'win.txt') >> >>I just tried to reuse this program that was posted several months ago. >>I am using a text flie that is about 200 lines long and have named it >>win.txt. The file it creates when I run the program is win_new.txt >>but it's empty. Put a counter in your loop: count = 0 for line in f_in.read().splitlines(): f_out.write(line + " *\n") count += 1 print("count =", count) Check that it says 200 (or whatever number you expect). >Not your problem, but you can simplify your read/write loop to: > >for line in f_in: > f_out.write(line[:-1] + ' *\n') > >The 'line[:-1]' expression gives you the line up to but not including the trailing newline. >Alternately, use: f_out.write(line.rstrip() + ' *\n') Importantly for this version, every line _MUST_ have a trailing newline. Personally that is what I require of my text files anyway, but some dubious tools (and, IMO, dubious people) make text files with no final newline. For such a file the above code would eat the last character because we don't check that a newline is there. I take a hard line on such files and usually write programs that look like this: for line in f_in: if not line.endswith('\n'): raise ValueError("missing final newline on file, last line is: %r" (line,)) f_out.write(line[:-1] + ' *\n') Then one can proceed secure in the knowledge that the data are well formed. I consider the final newline something of a termination record; without it I have no faith that the file wasn't rudely truncated somehow. In other words, I consider a text file to consist of newline-terminated lines, not newline-separated lines. Cheers, Cameron Simpson From jussi.piitulainen at helsinki.fi Wed Jul 6 02:19:07 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 06 Jul 2016 09:19:07 +0300 Subject: How well do you know Python? References: <577b9008$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Tue, 5 Jul 2016 07:51 pm, Jussi Piitulainen wrote: > >> Chris Angelico writes: >> >>> On Tue, Jul 5, 2016 at 6:36 PM, Peter Otten wrote: >>>> It looks like >>>> >>>> $ python3 -c 'print({1, 2})' >>>> {1, 2} >>>> $ python3 -c 'print({2, 1})' >>>> {1, 2} >>>> >>>> will always print the same output. Can you construct a set from two >>>> small integers where this is not the case? What's the difference? >>> >>> Given that the display (iteration) order of sets is arbitrary, I'm not >>> sure what the significance would ever be, but my guess is that the >>> display order would be the same for any given set, if constructed this >>> way. But it sounds as if you know of a set that behaves differently. >> >> The first thing that came to mind, {-1,-2} and {-2,-1}. >> >> But I haven't a clue. It doesn't happen with -1 and -3, or with another >> pair that I tried, and it doesn't seem to be about object identity. > > The hash of most small ints is equal to the int itself: > > py> for i in range(100): > ... assert hash(i) == i > ... > py> > > With one exception: > > py> hash(-2) > -2 > py> hash(-1) > -2 Thanks. That must be the explanation. I tried object identity but I did not think of comparing hashes directly. Amusing that I didn't know this, yet I happened to think of just this one pair of numbers. Literally the first thing that I thought to try, and it turns out to be the only thing. > That's because in the C implementation of hash, -1 is used to indicate > an error. > >>>> What happens if you replace the ints with strings? Why? >>> >>> Then hash randomization kicks in, and you can run the exact same >>> line of code multiple times and get different results. It's a coin >>> toss. >> >> Oh, nice, a new way to generate random bits in shell scripts. > > O_o > > You're joking, right? Er, ok, better not escalate this: Of course I am. > I'll just leave this here... > > https://docs.python.org/3.6/library/secrets.html Ok. From trieuquanganh at gmail.com Wed Jul 6 02:33:07 2016 From: trieuquanganh at gmail.com (Leo Trieu) Date: Tue, 5 Jul 2016 23:33:07 -0700 (PDT) Subject: Learn Python + Swift 3 by creating a comprehensive system with web app and iOS app Message-ID: <61eb9b3c-55ad-496d-b52f-b317dfa693e1@googlegroups.com> Guys, we're from Code4Startup team and we're running a KickStarter campaign for the next awesome course to bring best value to Python and Swift community. In this course, you will learn how to use Python and Swift 3 by cloning cool startup apps like UberEats, Doordash or Postmates. In case you're interested and want to learn more, check it out here: http://kck.st/29NjAtR Feel free to comment here with any questions. Leo From jennifer.greeen at gmail.com Wed Jul 6 06:25:09 2016 From: jennifer.greeen at gmail.com (jennifer.greeen at gmail.com) Date: Wed, 6 Jul 2016 03:25:09 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: I don't know anything about editors for coding, but as a writer that often use text editors (and I have seen them a lot!) I'd suggest you browsing this review site where you can find some cool apps besttexteditor.com From jennifer.greeen at gmail.com Wed Jul 6 06:27:13 2016 From: jennifer.greeen at gmail.com (jennifer.greeen at gmail.com) Date: Wed, 6 Jul 2016 03:27:13 -0700 (PDT) Subject: best text editor for programming Python on a Mac In-Reply-To: References: Message-ID: <11882431-dc45-433f-8455-0aa9d455a8ca@googlegroups.com> ??????, 18 ?????? 2016 ?. 02:52:35 UTC+3 ?????????? Chris ???????: > I have been trying to write a simple Hello World script on my Mac at work with TextEdit. However, I keep getting this error message: > > SyntaxError: Non-ASCII character '\xe2' in hello_world.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details > > I am using TextEdit in plain text mode. The document was saved in UTF-8, and I still get the error message. I tried switching to Western ASCII encoding, but once I start typing, I get a message stating that the document can no longer be saved using its original Western (ASCII) encoding. > > Any suggestions for a good open source text editor for the Mac out there? For now, I am going to stick with vim. I don't know anything about editors for coding, but as a writer that often use text editors (and I have seen them a lot!) I'd suggest you browsing this review site where you can find some cool apps besttexteditor.com From nir36g at gmail.com Wed Jul 6 14:43:15 2016 From: nir36g at gmail.com (Nir Cohen) Date: Wed, 6 Jul 2016 11:43:15 -0700 (PDT) Subject: Packaging multiple wheels in the same package Message-ID: <0310c596-2f5b-4cca-8059-6e6a81acc35f@googlegroups.com> Hey all, As part of working on Cloudify (http://github.com/cloudify-cosmo) we've had to provide a way for customers to install our plugins in an environment where PyPI isn't accessible. These plugins are sets of Python packages which necessarily depend on one another (i.e. a regular python package with dependencies). We decided that we want to package sets of wheels together created or downloaded by `pip wheel`, add relevant metadata, package them together into a single archive (tar.gz or zip) and use the same tool which packs them up to install them later on, on the destination hosts. We came up with a tool (http://github.com/cloudify-cosmo/wagon) to do just that and that's what we currently use to create and install our plugins. While wheel solves the problem of generating wheels, there is no single, standard method for taking an entire set of dependencies packaged in a single location and installing them in a different location. We thought it would be a good idea to propose a PEP for that and wanted to get your feedback before we start writing the proposal. The logic behind the PEP is that there's a standard for creating a single python package and we would like to propose a layer above it to package multiple python packages either for offline environments or any other requirement a user may have. We're currently working on a new rearchitected version of that tool to make it more pythonic and clean but the base stays the same. We would greatly appreciate your feedback on this. Thanks! P.S. We encourage you to take a look at the repo (see the `rearchitecture` branch) and read the README. From ethan at stoneleaf.us Wed Jul 6 15:08:43 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 06 Jul 2016 12:08:43 -0700 Subject: Packaging multiple wheels in the same package In-Reply-To: <0310c596-2f5b-4cca-8059-6e6a81acc35f@googlegroups.com> References: <0310c596-2f5b-4cca-8059-6e6a81acc35f@googlegroups.com> Message-ID: <577D573B.9040102@stoneleaf.us> On 07/06/2016 11:43 AM, Nir Cohen wrote: > We decided that we want to package sets of wheels together created or downloaded > by `pip wheel`, add relevant metadata, package them together into a single archive > (tar.gz or zip) and use the same tool which packs them up to install them later on, > on the destination hosts. > > We came up with a tool (http://github.com/cloudify-cosmo/wagon) to do just that > and that's what we currently use to create and install our plugins. Sounds like a great idea! Once you have your feed-back from here you'll want to take your PEP over to the dist-utils sig: https://mail.python.org/mailman/listinfo/distutils-sig -- ~Ethan~ From nickpetros32 at gmail.com Wed Jul 6 15:28:19 2016 From: nickpetros32 at gmail.com (nickpetros32 at gmail.com) Date: Wed, 6 Jul 2016 12:28:19 -0700 (PDT) Subject: the best online course Message-ID: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> Hello, i am totaly beginner and i want to learn python. I have see that there is many course in codeacademy, udemy, treehouse etc but i not know who is the best. Can you please give me some advice? I want to be easy and not bored so i can learn python. Thank you and sorry for my bad english From rosuav at gmail.com Wed Jul 6 17:04:32 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jul 2016 07:04:32 +1000 Subject: the best online course In-Reply-To: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> Message-ID: On Thu, Jul 7, 2016 at 5:28 AM, wrote: > i am totaly beginner and i want to learn python. > I have see that there is many course in codeacademy, udemy, treehouse etc but i not know who is the best. > Can you please give me some advice? > I want to be easy and not bored so i can learn python. > Thank you and sorry for my bad english Unfortunately, 'best' is hard to define. What are you looking for? There are courses you pay money for, and there are courses you can do for free; there are intensive courses for those who want to seriously knuckle down and learn, and there are casual courses for those who want to fit it around other things; and so on. ChrisA From jayryan.thompson at gmail.com Wed Jul 6 17:11:45 2016 From: jayryan.thompson at gmail.com (Jay Thompson) Date: Wed, 6 Jul 2016 14:11:45 -0700 Subject: the best online course In-Reply-To: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> Message-ID: There are a ton of great resources on https://wiki.python.org/moin/BeginnersGuide . The resource I generally recommend to people first is "Learn Python The Hard Way" @ http://learnpythonthehardway.org/ . The course is $29.95 and worth every penny but if you can't afford it the author has made the course available for free. Just scroll to the bottom of the page to find the link. On Wed, Jul 6, 2016 at 12:28 PM, wrote: > Hello, > i am totaly beginner and i want to learn python. > I have see that there is many course in codeacademy, udemy, treehouse etc > but i not know who is the best. > Can you please give me some advice? > I want to be easy and not bored so i can learn python. > Thank you and sorry for my bad english > > -- > https://mail.python.org/mailman/listinfo/python-list > -- "It's quite difficult to remind people that all this stuff was here for a million years before people. So the idea that we are required to manage it is ridiculous. What we are having to manage is us." ...Bill Ballantine. From lawrencedo99 at gmail.com Wed Jul 6 20:50:35 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 6 Jul 2016 17:50:35 -0700 (PDT) Subject: the best online course In-Reply-To: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> Message-ID: <0d0401de-8841-41a7-9831-0478bff5e689@googlegroups.com> On Thursday, July 7, 2016 at 7:28:38 AM UTC+12, nickpe... at gmail.com wrote: > i am totaly beginner and i want to learn python. Write code. > I want to be easy and not bored so i can learn python. There is no Royal Road, nothing is going to be handed to you on a plate. From torriem at gmail.com Wed Jul 6 23:07:49 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 6 Jul 2016 21:07:49 -0600 Subject: the best online course In-Reply-To: <0d0401de-8841-41a7-9831-0478bff5e689@googlegroups.com> References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> <0d0401de-8841-41a7-9831-0478bff5e689@googlegroups.com> Message-ID: <5f0110ae-1dc0-e487-af0c-7498c3067780@gmail.com> On 07/06/2016 06:50 PM, Lawrence D?Oliveiro wrote: >> I want to be easy and not bored so i can learn python. > > There is no Royal Road, nothing is going to be handed to you on a plate. Seconded. If he gets bored easily, he will not be very successful at learning Python or any other programming language. The challenge of programming by itself should be enough to give fulfillment if he's to be successful at it. From nir36g at gmail.com Thu Jul 7 00:47:07 2016 From: nir36g at gmail.com (Nir Cohen) Date: Wed, 6 Jul 2016 21:47:07 -0700 (PDT) Subject: Packaging multiple wheels in the same package In-Reply-To: References: <0310c596-2f5b-4cca-8059-6e6a81acc35f@googlegroups.com> <577D573B.9040102@stoneleaf.us> Message-ID: On Wednesday, July 6, 2016 at 10:09:01 PM UTC+3, Ethan Furman wrote: > On 07/06/2016 11:43 AM, Nir Cohen wrote: > > > We decided that we want to package sets of wheels together created or downloaded > > by `pip wheel`, add relevant metadata, package them together into a > single archive > > (tar.gz or zip) and use the same tool which packs them up to install > them later on, > > on the destination hosts. > > > > We came up with a tool (http://github.com/cloudify-cosmo/wagon) to do just that > > and that's what we currently use to create and install our plugins. > > Sounds like a great idea! > > Once you have your feed-back from here you'll want to take your PEP over > to the dist-utils sig: > > https://mail.python.org/mailman/listinfo/distutils-sig > > -- > ~Ethan~ Happy to hear :) btw, pull requests are certainly welcome to make whichever changes required to make Wagon PEP-worthy. From mal at europython.eu Thu Jul 7 03:35:54 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 7 Jul 2016 09:35:54 +0200 Subject: EuroPython 2016: Last day to get tickets at regular rate Message-ID: <577E065A.5050905@europython.eu> We will be switching to the on-desk rates for tickets tomorrow, so today is your last chance to get tickets at the regular rate, which is about 30% less than the on-desk rate: EuroPython 2016 Registration *** https://ep2016.europython.eu/registration/ *** Day Passes ---------- As in the past, we will also sell day passes at the conference venue. To make things more affordable especially for students and other people who want to attend the Beginners? Day or the sprints, we have split the day pass prices into ones valid from Monday-Friday for the main conference days and ones for the weekend days. Day passes for the first Sunday (Beginners? Day) and the sprints weekend (valid for the day when they are purchased): * Student weekend day pass: EUR 25.00 * Personal weekend day pass: EUR 70.00 * Business weekend day pass: EUR 110.00 Day passes for the main conference (valid for the day when they are purchased): * Student conference day pass: EUR 50.00 * Personal conference day pass: EUR 140.00 * Business conference day pass: EUR 225.00 All prices include 10% Spanish VAT. Please see the registration page for full details of what is included in the ticket price. With gravitational regards, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/750955219975016448 Thanks. From jornws0718 at xs4all.nl Thu Jul 7 07:30:46 2016 From: jornws0718 at xs4all.nl (Oscar) Date: 07 Jul 2016 11:30:46 GMT Subject: Spot the bug: getoptquestion.py References: <577a4766$0$5839$e4fe514c@news.xs4all.nl> Message-ID: <577e3d66$0$5816$e4fe514c@news.xs4all.nl> In article , Chris Angelico wrote: >On Wed, Jul 6, 2016 at 2:04 PM, Lawrence D???Oliveiro > wrote: >> On Tuesday, July 5, 2016 at 1:42:42 AM UTC+12, Chris Angelico wrote: >> >>> The getopt module is designed to match the C getopt function, which I've >>> never used; for my command-line parsing, I use argparse instead >>> (usually via some wrapper that cuts down the duplication, like clize). >> >> getopt seems so much simpler. > >Look at clize: Okay: | >>> import clize | Traceback (most recent call last): | File "", line 1, in | ImportError: No module named clize Mmm... nope. I'm not going to learn a new tool and introduce an extra dependency just to do something as basic as getopt. But then again, coming from a C background, getopt feels kind of familiar. ;-) Thanks all for the input. I think it all boils down to: "If you don't want a space in your long_option, don't put a space in there". >I just put docstrings on my functions, slap "@command" above them, and >with minimal boilerplate, I have a fully-working command line >interface. It's a wrapper around argparse. Looks neat though! -- [J|O|R] <- .signature.gz From rosuav at gmail.com Thu Jul 7 08:12:37 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jul 2016 22:12:37 +1000 Subject: Spot the bug: getoptquestion.py In-Reply-To: <577e3d66$0$5816$e4fe514c@news.xs4all.nl> References: <577a4766$0$5839$e4fe514c@news.xs4all.nl> <577e3d66$0$5816$e4fe514c@news.xs4all.nl> Message-ID: On Thu, Jul 7, 2016 at 9:30 PM, Oscar wrote: > Thanks all for the input. I think it all boils down to: "If you don't > want a space in your long_option, don't put a space in there". Yeah, I guess, pretty much! > Mmm... nope. I'm not going to learn a new tool and introduce an extra > dependency just to do something as basic as getopt. But then again, > coming from a C background, getopt feels kind of familiar. ;-) >>I just put docstrings on my functions, slap "@command" above them, and >>with minimal boilerplate, I have a fully-working command line >>interface. It's a wrapper around argparse. > > Looks neat though! Yes, it's a third-party dependency. (Sorry, should have mentioned that.) You're welcome to consider that to be too much risk and/or hassle to be worth improving on getopt, but personally, I *really* like the simplicity of just writing docstrings that still read perfectly well as docstrings, and having them create my argparse configs for me. Different strokes for different horses, or something like that. ChrisA From jornws0718 at xs4all.nl Thu Jul 7 08:29:31 2016 From: jornws0718 at xs4all.nl (Oscar) Date: 07 Jul 2016 12:29:31 GMT Subject: Spot the bug: getoptquestion.py References: <577a4766$0$5839$e4fe514c@news.xs4all.nl> <577e3d66$0$5816$e4fe514c@news.xs4all.nl> Message-ID: <577e4b2b$0$5819$e4fe514c@news.xs4all.nl> In article , Chris Angelico wrote: >Yes, it's a third-party dependency. (Sorry, should have mentioned >that.) You're welcome to consider that to be too much risk and/or >hassle to be worth improving on getopt, but personally, I *really* >like the simplicity of just writing docstrings that still read >perfectly well as docstrings, and having them create my argparse >configs for me. Different strokes for different horses, or something >like that. Well, parsing the arguments was not really the problem in my case. But after parsing I had to look at valid combinations and show helpfull messages if required information is missing or conflicting options were given. I doubt if an extra abstraction layer would have helped me. It did make my typo a bit hard to catch, though... -- [J|O|R] <- .signature.gz From tokauf at gmail.com Thu Jul 7 10:04:45 2016 From: tokauf at gmail.com (tokauf at gmail.com) Date: Thu, 7 Jul 2016 07:04:45 -0700 (PDT) Subject: sqlite3 scrapy Message-ID: <3395eb06-2d2b-4596-b762-4604a84d508c@googlegroups.com> Hi, I have a little scrapy-script: scrapy gets the links from a webpage; this works fine. Then I want to write these links in a sqlite3-table. There is no error-note. But in the database are not any records. What is the problem here? My code: # -*- coding: utf-8 -*- 2 3 import scrapy 4 import sqlite3 5 6 class MySpider(scrapy.Spider): 7 8 name = "frisch2" 9 allowed_domains = ["frischblau.de"] 10 start_urls = ["http://www.frischblau.de/",] 11 12 def parse(self, response): 13 14 for href in response.xpath("//ul/li/a/@href"): 15 16 url = response.urljoin(href.extract()) 17 yield scrapy.Request(url, callback=self.parse_dir_contents) 18 19 def parse_dir_contents(self, response): 20 21 sql = u' ' 22 conn = sqlite3.connect('frisch.db') 23 cur = conn.cursor() 24 counter = 3; 25 26 try: 27 cur.execute("SELECT SQLITE_VERSION()") 28 print "-> SQLite version: %s" % cur.fetchone() 29 30 item = response.xpath('//a/@href').extract() 31 for el in item: 32 33 #print("----------> ", type(el)) 34 sql = "INSERT INTO Frisch VALUES(" + unicode(counter) + ", " + "'" + el.strip() + "');" 35 36 print (sql) 37 cur.execute(sql) 38 conn.commit 39 counter = int(counter) 40 counter += 1 41 42 except sqlite3.Error as e: 43 print "Error %s:" % e.args[0] 44 conn.close() 45 Thanks for help. o-o Thomas From rosuav at gmail.com Thu Jul 7 10:26:58 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jul 2016 00:26:58 +1000 Subject: sqlite3 scrapy In-Reply-To: <3395eb06-2d2b-4596-b762-4604a84d508c@googlegroups.com> References: <3395eb06-2d2b-4596-b762-4604a84d508c@googlegroups.com> Message-ID: On Fri, Jul 8, 2016 at 12:04 AM, wrote: > 34 sql = "INSERT INTO Frisch VALUES(" + unicode(counter) + ", " + "'" + el.strip() + "');" Don't ever do this. Instead, use parameterized queries: cur.execute("INSERT INTO Frisch VALUES (?, ?)", (counter, el.strip())) > 38 conn.commit Do you know what this does? > 39 counter = int(counter) This is unnecessary; counter is already an integer. Does anything actually call your code? If not, none of the above will matter. But possibly there's an invocation that I'm not seeing. ChrisA From tokauf at gmail.com Thu Jul 7 10:42:06 2016 From: tokauf at gmail.com (Thomas Kaufmann) Date: Thu, 7 Jul 2016 07:42:06 -0700 (PDT) Subject: sqlite3 scrapy In-Reply-To: <3395eb06-2d2b-4596-b762-4604a84d508c@googlegroups.com> References: <3395eb06-2d2b-4596-b762-4604a84d508c@googlegroups.com> Message-ID: <20c13025-849d-4332-84bc-30ec582d47c3@googlegroups.com> Am Donnerstag, 7. Juli 2016 16:05:14 UTC+2 schrieb Thomas Kaufmann: > Hi, > > I have a little scrapy-script: scrapy gets the links from a webpage; this works fine. Then I want to write these links in a sqlite3-table. There is no error-note. But in the database are not any records. What is the problem here? My code: > > # -*- coding: utf-8 -*- > 2 > 3 import scrapy > 4 import sqlite3 > 5 > 6 class MySpider(scrapy.Spider): > 7 > 8 name = "frisch2" > 9 allowed_domains = ["frischblau.de"] > 10 start_urls = ["http://www.frischblau.de/",] > 11 > 12 def parse(self, response): > 13 > 14 for href in response.xpath("//ul/li/a/@href"): > 15 > 16 url = response.urljoin(href.extract()) > 17 yield scrapy.Request(url, callback=self.parse_dir_contents) > 18 > 19 def parse_dir_contents(self, response): > 20 > 21 sql = u' ' > 22 conn = sqlite3.connect('frisch.db') > 23 cur = conn.cursor() > 24 counter = 3; > 25 > 26 try: > 27 cur.execute("SELECT SQLITE_VERSION()") > 28 print "-> SQLite version: %s" % cur.fetchone() > 29 > 30 item = response.xpath('//a/@href').extract() > 31 for el in item: > 32 > 33 #print("----------> ", type(el)) > 34 sql = "INSERT INTO Frisch VALUES(" + unicode(counter) + ", " + "'" + el.strip() + "');" > 35 > 36 print (sql) > 37 cur.execute(sql) > 38 conn.commit > 39 counter = int(counter) > 40 counter += 1 > 41 > 42 except sqlite3.Error as e: > 43 print "Error %s:" % e.args[0] > 44 conn.close() > 45 > > > Thanks for help. > > o-o > > Thomas Hi Chris, I changed my code in the way you suggested. There is no effect in the db. I start this script on the commandline with: tk at Hamlet:~/myscrapy/tutorial/tutorial/spiders$ scrapy crawl webbot When I call the sql-statement in the db it works. sqlite> INSERT INTO Frisch VALUES(4, '//:?s.chi/hhh\n'); sqlite> SELECT * FROM Frisch; 1|?schi/hhh 2|?schi/hhh\n 3|//:?s.chi/hhh\n 4|//:?s.chi/hhh\n From rosuav at gmail.com Thu Jul 7 10:51:54 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jul 2016 00:51:54 +1000 Subject: sqlite3 scrapy In-Reply-To: <20c13025-849d-4332-84bc-30ec582d47c3@googlegroups.com> References: <3395eb06-2d2b-4596-b762-4604a84d508c@googlegroups.com> <20c13025-849d-4332-84bc-30ec582d47c3@googlegroups.com> Message-ID: On Fri, Jul 8, 2016 at 12:42 AM, Thomas Kaufmann wrote: > I changed my code in the way you suggested. There is no effect in the db. I start this script on the commandline with: > > tk at Hamlet:~/myscrapy/tutorial/tutorial/spiders$ scrapy crawl webbot You have some print calls in your code. Are they happening? Do you see anything on your console? If not, you probably don't have a database issue, you have an invocation issue. If you do, please post the output along with the latest code - it might be revealing. ChrisA From __peter__ at web.de Thu Jul 7 10:56:25 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jul 2016 16:56:25 +0200 Subject: sqlite3 scrapy References: <3395eb06-2d2b-4596-b762-4604a84d508c@googlegroups.com> <20c13025-849d-4332-84bc-30ec582d47c3@googlegroups.com> Message-ID: Thomas Kaufmann wrote: > Am Donnerstag, 7. Juli 2016 16:05:14 UTC+2 schrieb Thomas Kaufmann: >> Hi, >> >> I have a little scrapy-script: scrapy gets the links from a webpage; this >> works fine. Then I want to write these links in a sqlite3-table. There is >> no error-note. But in the database are not any records. What is the >> problem here? My code: >> >> # -*- coding: utf-8 -*- >> 2 >> 3 import scrapy >> 4 import sqlite3 >> 5 >> 6 class MySpider(scrapy.Spider): >> 7 >> 8 name = "frisch2" >> 9 allowed_domains = ["frischblau.de"] >> 10 start_urls = ["http://www.frischblau.de/",] >> 11 >> 12 def parse(self, response): >> 13 >> 14 for href in response.xpath("//ul/li/a/@href"): >> 15 >> 16 url = response.urljoin(href.extract()) >> 17 yield scrapy.Request(url, >> callback=self.parse_dir_contents) 18 >> 19 def parse_dir_contents(self, response): >> 20 >> 21 sql = u' ' >> 22 conn = sqlite3.connect('frisch.db') >> 23 cur = conn.cursor() >> 24 counter = 3; >> 25 >> 26 try: >> 27 cur.execute("SELECT SQLITE_VERSION()") >> 28 print "-> SQLite version: %s" % cur.fetchone() >> 29 >> 30 item = response.xpath('//a/@href').extract() >> 31 for el in item: >> 32 >> 33 #print("----------> ", type(el)) >> 34 sql = "INSERT INTO Frisch VALUES(" + unicode(counter) >> + ", " + "'" + el.strip() + "');" 35 >> 36 print (sql) >> 37 cur.execute(sql) >> 38 conn.commit >> 39 counter = int(counter) >> 40 counter += 1 >> 41 >> 42 except sqlite3.Error as e: >> 43 print "Error %s:" % e.args[0] >> 44 conn.close() >> 45 >> >> >> Thanks for help. >> >> o-o >> >> Thomas > > Hi Chris, > > I changed my code in the way you suggested. > There is no effect in the db. Did you replace the line conn.commit with con.commit() ? If not, can you provide the updated code? > I start this script on the commandline with: > > tk at Hamlet:~/myscrapy/tutorial/tutorial/spiders$ scrapy crawl webbot > > When I call the sql-statement in the db it works. > > sqlite> INSERT INTO Frisch VALUES(4, '//:?s.chi/hhh\n'); > > sqlite> SELECT * FROM Frisch; > 1|?schi/hhh > 2|?schi/hhh\n > 3|//:?s.chi/hhh\n > 4|//:?s.chi/hhh\n > > > > > > > From tokauf at gmail.com Thu Jul 7 11:00:14 2016 From: tokauf at gmail.com (Thomas Kaufmann) Date: Thu, 7 Jul 2016 08:00:14 -0700 (PDT) Subject: sqlite3 scrapy In-Reply-To: References: <3395eb06-2d2b-4596-b762-4604a84d508c@googlegroups.com> <20c13025-849d-4332-84bc-30ec582d47c3@googlegroups.com> Message-ID: <29a46e99-3abc-4533-8d9d-45e7db767a1f@googlegroups.com> Am Donnerstag, 7. Juli 2016 16:52:12 UTC+2 schrieb Chris Angelico: > On Fri, Jul 8, 2016 at 12:42 AM, Thomas Kaufmann wrote: > > I changed my code in the way you suggested. There is no effect in the db. I start this script on the commandline with: > > > > tk at Hamlet:~/myscrapy/tutorial/tutorial/spiders$ scrapy crawl webbot > > You have some print calls in your code. Are they happening? Do you see > anything on your console? If not, you probably don't have a database > issue, you have an invocation issue. If you do, please post the output > along with the latest code - it might be revealing. > > ChrisA Hi Chris, here is my table: sqlite> CREATE TABLE Frisch(id INTEGER PRIMARY KEY NOT NULL, line TEXT NOT NULL); And here is the output from my script on the console: 2016-07-07 16:59:13 [scrapy] DEBUG: Crawled (200) (referer: None) 2016-07-07 16:59:14 [scrapy] DEBUG: Crawled (200) (referer: http://www.frischblau.de/) -> SQLite version: 3.8.2 INSERT INTO Frisch VALUES (?, ?) (2, u'#top') INSERT INTO Frisch VALUES (?, ?) (3, u'mailto:info at frischblau.de') INSERT INTO Frisch VALUES (?, ?) (4, u'http://www.zukunftscharta.de') INSERT INTO Frisch VALUES (?, ?) (5, u'https://www.microsoft.com/de-de/WindowsForBusiness/End-of-IE-support') INSERT INTO Frisch VALUES (?, ?) (6, u'https://contao.org/de/news/screenguide28-platz-1.html') INSERT INTO Frisch VALUES (?, ?) (7, u'http://www.ifmo.de') INSERT INTO Frisch VALUES (?, ?) (8, u'http://www.werksdesign.de') ... From __peter__ at web.de Thu Jul 7 11:02:30 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 07 Jul 2016 17:02:30 +0200 Subject: sqlite3 scrapy References: <3395eb06-2d2b-4596-b762-4604a84d508c@googlegroups.com> <20c13025-849d-4332-84bc-30ec582d47c3@googlegroups.com> Message-ID: Peter Otten wrote: More errors than words :( >> There is no effect in the db. > > Did you replace the line > > conn.commit > > with > > con.commit() Of course the updated code should read conn.commit() > ? If not, can you provide the updated code? and that should have been "If yes, ...", i. e. you only need to provide the updated code if it does *not* work yet. From tokauf at gmail.com Thu Jul 7 11:04:09 2016 From: tokauf at gmail.com (Thomas Kaufmann) Date: Thu, 7 Jul 2016 08:04:09 -0700 (PDT) Subject: sqlite3 scrapy In-Reply-To: References: <3395eb06-2d2b-4596-b762-4604a84d508c@googlegroups.com> <20c13025-849d-4332-84bc-30ec582d47c3@googlegroups.com> Message-ID: <4ab32799-676a-4f4b-9590-4dfec6e4f834@googlegroups.com> Am Donnerstag, 7. Juli 2016 16:56:48 UTC+2 schrieb Peter Otten: > Thomas Kaufmann wrote: > > > Am Donnerstag, 7. Juli 2016 16:05:14 UTC+2 schrieb Thomas Kaufmann: > >> Hi, > >> > >> I have a little scrapy-script: scrapy gets the links from a webpage; this > >> works fine. Then I want to write these links in a sqlite3-table. There is > >> no error-note. But in the database are not any records. What is the > >> problem here? My code: > >> > >> # -*- coding: utf-8 -*- > >> 2 > >> 3 import scrapy > >> 4 import sqlite3 > >> 5 > >> 6 class MySpider(scrapy.Spider): > >> 7 > >> 8 name = "frisch2" > >> 9 allowed_domains = ["frischblau.de"] > >> 10 start_urls = ["http://www.frischblau.de/",] > >> 11 > >> 12 def parse(self, response): > >> 13 > >> 14 for href in response.xpath("//ul/li/a/@href"): > >> 15 > >> 16 url = response.urljoin(href.extract()) > >> 17 yield scrapy.Request(url, > >> callback=self.parse_dir_contents) 18 > >> 19 def parse_dir_contents(self, response): > >> 20 > >> 21 sql = u' ' > >> 22 conn = sqlite3.connect('frisch.db') > >> 23 cur = conn.cursor() > >> 24 counter = 3; > >> 25 > >> 26 try: > >> 27 cur.execute("SELECT SQLITE_VERSION()") > >> 28 print "-> SQLite version: %s" % cur.fetchone() > >> 29 > >> 30 item = response.xpath('//a/@href').extract() > >> 31 for el in item: > >> 32 > >> 33 #print("----------> ", type(el)) > >> 34 sql = "INSERT INTO Frisch VALUES(" + unicode(counter) > >> + ", " + "'" + el.strip() + "');" 35 > >> 36 print (sql) > >> 37 cur.execute(sql) > >> 38 conn.commit > >> 39 counter = int(counter) > >> 40 counter += 1 > >> 41 > >> 42 except sqlite3.Error as e: > >> 43 print "Error %s:" % e.args[0] > >> 44 conn.close() > >> 45 > >> > >> > >> Thanks for help. > >> > >> o-o > >> > >> Thomas > > > > Hi Chris, > > > > I changed my code in the way you suggested. > > There is no effect in the db. > > Did you replace the line > > conn.commit > > with > > con.commit() > > ? If not, can you provide the updated code? > > > > I start this script on the commandline with: > > > > tk at Hamlet:~/myscrapy/tutorial/tutorial/spiders$ scrapy crawl webbot > > > > When I call the sql-statement in the db it works. > > > > sqlite> INSERT INTO Frisch VALUES(4, '//:?s.chi/hhh\n'); > > > > sqlite> SELECT * FROM Frisch; > > 1|?schi/hhh > > 2|?schi/hhh\n > > 3|//:?s.chi/hhh\n > > 4|//:?s.chi/hhh\n > > > > > > > > > > > > > > Thanx a lot Peter. IT WORKS!!! From pcmanticore at gmail.com Thu Jul 7 14:55:20 2016 From: pcmanticore at gmail.com (Claudiu Popa) Date: Thu, 7 Jul 2016 19:55:20 +0100 Subject: Pylint 1.6.0 released Message-ID: Hi folks, I am joyful to announce the release of Pylint 1.6.0. This is the next minor release in the 1.X branch and most probably the last one, since we are preparing the taking off of Pylint 2.0. This release has a couple of small improvements, bug fixes and new checks, comparing to the last one. You can find more about was changed in this release here: https://docs.pylint.org/en/1.6.0/whatsnew/1.6.html https://docs.pylint.org/en/1.6.0/whatsnew/changelog.html#what-s-new-in-pylint-1-6-0 As usual, don't hesitate to report any new bugs you might encounter with this release. We are also looking for new contributors, so if you feel like taking a stab at a bug or a feature you would like in pylint, open up an issue and let's talk! We are also planning to do releases more often from now on and you can see what we are planning for the next releases here: https://github.com/PyCQA/pylint/milestones Thank you and enjoy, Claudiu Popa From rgaddi at highlandtechnology.invalid Thu Jul 7 19:46:45 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Thu, 7 Jul 2016 23:46:45 -0000 (UTC) Subject: Clean Singleton Docstrings Message-ID: I've got a package that contains a global ensmartened dict that allows all the various parts of my program to share state. Things like device handles, information about the application environment, etc. that are inherantly global (i.e. we're not having that debate). Implementation is: class _Registry(UserDict): """Docstring!""" ... Registry = _Registry() So Registry is now a globally accessible mutable object; no reason to complicate things with singletons or borgs or whathave you. From within the interactive console, help(foobar.Registry) gives me the _Registry documentation as expected. >From the (Linux) command line though: $ pydoc3 foobar._Registry [lots of good documentation stuff] $ pydoc3 foobar.Registry no Python documentation found for 'foobar.Registry' Is this a thing that can be fixed with a commensurate amount of effort? Thanks, Rob -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From steve at pearwood.info Thu Jul 7 22:53:41 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 08 Jul 2016 12:53:41 +1000 Subject: Clean Singleton Docstrings References: Message-ID: <577f15b6$0$1620$c3e8da3$5496439d@news.astraweb.com> On Fri, 8 Jul 2016 09:46 am, Rob Gaddi wrote: [...] > So Registry is now a globally accessible mutable object; no reason to > complicate things with singletons or borgs or whathave you. From > within the interactive console, help(foobar.Registry) gives me the > _Registry documentation as expected. > > From the (Linux) command line though: > $ pydoc3 foobar._Registry > [lots of good documentation stuff] > $ pydoc3 foobar.Registry > no Python documentation found for 'foobar.Registry' > > Is this a thing that can be fixed with a commensurate amount of effort? [steve at ando ~]$ python3 -m pydoc --help pydoc - the Python documentation tool pydoc ... Show text documentation on something. may be the name of a Python keyword, topic, function, module, or package, or a dotted reference to A CLASS OR FUNCTION within a module [...] (Emphasis added.) So, no, reading the docstrings from individual objects is not supported by pydoc's command line interface. You could possibly add that functionality, but I don't know how much effort it would be. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From michael.selik at gmail.com Thu Jul 7 23:43:17 2016 From: michael.selik at gmail.com (Michael Selik) Date: Thu, 7 Jul 2016 23:43:17 -0400 Subject: Clean Singleton Docstrings In-Reply-To: References: Message-ID: <2EB2D06F-46A1-4812-A91B-1D2A31440EA6@gmail.com> > On Jul 7, 2016, at 7:46 PM, Rob Gaddi wrote: > > I've got a package that contains a global ensmartened dict that allows > all the various parts of my program to share state. The simplest solution would be to use a module as your singleton. For example, "registry.py" would work. Pydoc will show its docstring, and it will have all the features you had been using, with the added benefit of not needing to enforce its singletonness. From rustompmody at gmail.com Fri Jul 8 02:34:59 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 7 Jul 2016 23:34:59 -0700 (PDT) Subject: the best online course In-Reply-To: References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> <0d0401de-8841-41a7-9831-0478bff5e689@googlegroups.com> <5f0110ae-1dc0-e487-af0c-7498c3067780@gmail.com> Message-ID: On Thursday, July 7, 2016 at 8:38:15 AM UTC+5:30, Michael Torrie wrote: > On 07/06/2016 06:50 PM, Lawrence D?Oliveiro wrote: > >> I want to be easy and not bored so i can learn python. > > > > There is no Royal Road, nothing is going to be handed to you on a plate. > > Seconded. If he gets bored easily, he will not be very successful at > learning Python or any other programming language. The challenge of > programming by itself should be enough to give fulfillment if he's to be > successful at it. Maybe? But Ive noted that when students say ?I?m bored? it often means ?I dont know what the (*&*^%^$#@ is going on? From arsh840 at gmail.com Fri Jul 8 03:21:59 2016 From: arsh840 at gmail.com (Arshpreet Singh) Date: Fri, 8 Jul 2016 00:21:59 -0700 (PDT) Subject: CyberRoam Python Alternative for network security Message-ID: This is question more about product information and less technical but Hope It will be use-able at some context, I use Cyeberoam(https://www.cyberoam.com/) Is there any Python alternative available for that? or If I have to write/implement something like this(https://github.com/netkiller/firewall) should I need to install it inside every computer or I can create a server and all the internet requests will pass through that, But that will be slow down the speed of the internet as well? From __peter__ at web.de Fri Jul 8 03:38:29 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Jul 2016 09:38:29 +0200 Subject: Clean Singleton Docstrings References: Message-ID: Rob Gaddi wrote: > I've got a package that contains a global ensmartened dict that allows > all the various parts of my program to share state. Things like device > handles, information about the application environment, etc. that are > inherantly global (i.e. we're not having that debate). > > Implementation is: > > class _Registry(UserDict): > """Docstring!""" > ... > Registry = _Registry() > > So Registry is now a globally accessible mutable object; no reason to > complicate things with singletons or borgs or whathave you. From > within the interactive console, help(foobar.Registry) gives me the > _Registry documentation as expected. > > From the (Linux) command line though: > $ pydoc3 foobar._Registry > [lots of good documentation stuff] > $ pydoc3 foobar.Registry > no Python documentation found for 'foobar.Registry' > > Is this a thing that can be fixed with a commensurate amount of effort? There is a test if not object: raise ImportError('no Python documentation found for %r' % thing) in the pydoc module. So all you need is to ensure that your Registry evaluates to True in a boolean context, e. g. by putting something into it: $ cat foobar.py from collections import UserDict class _Registry(UserDict): """Docstring!""" Registry = _Registry() Registry["dummy"] = 42 $ pydoc3 foobar.Registry | head -n 10 Help on _Registry in foobar object: foobar.Registry = class _Registry(collections.UserDict) | Docstring! | | Method resolution order: | _Registry | collections.UserDict | collections.abc.MutableMapping | collections.abc.Mapping You might also file a bug report asking to replace if not object: ... with if object is None: ... From __peter__ at web.de Fri Jul 8 03:44:43 2016 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Jul 2016 09:44:43 +0200 Subject: Clean Singleton Docstrings References: Message-ID: 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. From rustompmody at gmail.com Fri Jul 8 04:53:17 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 8 Jul 2016 01:53:17 -0700 (PDT) Subject: Clean Singleton Docstrings In-Reply-To: References: Message-ID: <7ee9c8f5-3059-4f67-a37b-586fd072faaa@googlegroups.com> On Friday, July 8, 2016 at 1:15:04 PM UTC+5:30, Peter Otten wrote [slightly edited] > Peter Otten wrote: > > > You might also file a bug report asking to replace > > if not object: ... > > > > with > > > >if object is None: ... > > I take that back; the problem is fixed in Python 3.5. Hoo boy! And then there are those that claim that bool vs boolishness true vs True is cakewalk From steve at pearwood.info Fri Jul 8 05:20:45 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 08 Jul 2016 19:20:45 +1000 Subject: Clean Singleton Docstrings References: Message-ID: <577f706f$0$1584$c3e8da3$5496439d@news.astraweb.com> On Fri, 8 Jul 2016 05:38 pm, Peter Otten wrote: [...] >> Is this a thing that can be fixed with a commensurate amount of effort? > > There is a test > > if not object: > raise ImportError('no Python documentation found for %r' % thing) > > in the pydoc module. So all you need is to ensure that your Registry > evaluates to True in a boolean context, e. g. by putting something into > it: Nicely spotted! I had seen the test but hadn't realised the implications. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rgaddi at highlandtechnology.invalid Fri Jul 8 12:47:53 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 8 Jul 2016 16:47:53 -0000 (UTC) Subject: Clean Singleton Docstrings References: <577f706f$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 8 Jul 2016 05:38 pm, Peter Otten wrote: > > [...] >>> Is this a thing that can be fixed with a commensurate amount of effort? >> >> There is a test >> >> if not object: >> raise ImportError('no Python documentation found for %r' % thing) >> >> in the pydoc module. So all you need is to ensure that your Registry >> evaluates to True in a boolean context, e. g. by putting something into >> it: > > > Nicely spotted! I had seen the test but hadn't realised the implications. > As speedy problem resolutions go, before I mentioned it is pretty good. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From rgaddi at highlandtechnology.invalid Fri Jul 8 12:57:36 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 8 Jul 2016 16:57:36 -0000 (UTC) Subject: Clean Singleton Docstrings References: <2EB2D06F-46A1-4812-A91B-1D2A31440EA6@gmail.com> Message-ID: Michael Selik wrote: > > >> On Jul 7, 2016, at 7:46 PM, Rob Gaddi wrote: >> >> I've got a package that contains a global ensmartened dict that allows >> all the various parts of my program to share state. > > The simplest solution would be to use a module as your singleton. For example, "registry.py" would work. Pydoc will show its docstring, and it will have all the features you had been using, with the added benefit of not needing to enforce its singletonness. > REALLY needs to be an object, preferably dict-like. For instance, one of the things it does is provide a .getKeyChanged(self, key) method that returns a keyChanged QSignal so that various elements of the program can all register for notifications triggered by __setitem__. That way, when Registry['dut'] gets updated, all of the various GUI elements reliant on information about the dut all dump their old data and find out about the newly connected device. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From ethan at stoneleaf.us Fri Jul 8 16:00:01 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 08 Jul 2016 13:00:01 -0700 Subject: Clean Singleton Docstrings In-Reply-To: References: <2EB2D06F-46A1-4812-A91B-1D2A31440EA6@gmail.com> Message-ID: <57800641.3050904@stoneleaf.us> On 07/08/2016 09:57 AM, Rob Gaddi wrote: > Michael Selik wrote: >> On Jul 7, 2016, at 7:46 PM, Rob Gaddi wrote: >>> I've got a package that contains a global ensmartened dict that allows >>> all the various parts of my program to share state. >> >> The simplest solution would be to use a module as your singleton. For example, "registry.py" would work. Pydoc will show its docstring, and it will have all the features you had been using, with the added benefit of not needing to enforce its singletonness. >> > > REALLY needs to be an object, preferably dict-like. For instance, one > of the things it does is provide a .getKeyChanged(self, key) method that > returns a keyChanged QSignal so that various elements of the program can > all register for notifications triggered by __setitem__. That way, when > Registry['dut'] gets updated, all of the various GUI elements reliant on > information about the dut all dump their old data and find out about the > newly connected device. Get the best of both worlds -- insert your Registry object into sys.modules. It is then importable from anywhere, yet still has all its native object power. Something like this should do the trick: # untested import sys sys.modules['%s.registry' % __name__] = _Register() and then elsewhere: from blah import registery registry.whatever() -- ~Ethan~ From nagle at animats.com Fri Jul 8 19:17:34 2016 From: nagle at animats.com (John Nagle) Date: Fri, 08 Jul 2016 16:17:34 -0700 Subject: input vs. readline Message-ID: If "readline" is imported, "input" gets "readline" capabilities. It also loses the ability to import control characters. It doesn't matter where "readline" is imported; an import in some library module can trigger this. You can try this with a simple test case: print(repr(input())) as a .py file, run in a console. Try typing "aaaESCbbb". On Windows 7, output is "bbb". On Linux, it's "aaa\x1bbbb". So it looks like "readline" is implicitly imported on Windows. I have a multi-threaded Python program which recognizes ESC as a command to stop something. This works on Linux, but not on Windows. Apparently something in Windows land pulls in "readline". What's the best way to get input from the console (not any enclosing shell script) that's cross-platform, cross-version (Python 2.7, 3.x), and doesn't do "readline" processing? (No, I don't want to use signals, a GUI, etc. This is simulating a serial input device while logging messages appear. It's a debug facility to be able to type input in the console window.) John Nagle From cs at zip.com.au Fri Jul 8 19:45:12 2016 From: cs at zip.com.au (cs at zip.com.au) Date: Sat, 9 Jul 2016 09:45:12 +1000 Subject: input vs. readline In-Reply-To: References: Message-ID: <20160708234512.GA99445@cskk.homeip.net> On 08Jul2016 16:17, John Nagle wrote: > If "readline" is imported, "input" gets "readline" capabilities. >It also loses the ability to import control characters. It doesn't >matter where "readline" is imported; an import in some library >module can trigger this. You can try this with a simple test >case: > print(repr(input())) >as a .py file, run in a console. Try typing "aaaESCbbb". >On Windows 7, output is "bbb". On Linux, it's "aaa\x1bbbb". > >So it looks like "readline" is implicitly imported on Windows. _Or_ that the Windows console app does its own input processing. I would be _very_ surprised if Python were behaving differently on the two platforms in this regard, though it is possible. (Disclaimer: I pretty much don't use Windows). Remember that any terminal program does some processing of keystrokes before they reach your program, even if that is "no" processing. On a UNIX system this is called the "line discipline", and doubtless Windows does something of that nature. On a UNIX system in normal circumstances your terminal's line discipline is in "cooked" mode, where various things happen to the raw bytes delivered by the terminal emulator. For example, when you press which sends byte 13, in cooked mode, this is converted the a newline (byte 10) for receipt by the program. Also in cooked mode, backspace (or DEL, depends, see "stty -a") is handled by the line disciple: your program sees the text as it was _after_ you did all the backspacing. And so forth. Perhaps the Windows console is treating ESC specially, apparently as "line erase", discarduing any preceeding text. Hence your results. On a UNIX program the normal thing would be to either to: - accept this, and use the liternal-next kestroke (usually ^V) to tell it not to the bytes special to the line discipline. So you might type ^V^H to get a literal ^H code in your input and so forth. - use termios to turn off all the control keystrokes (erase, kill and so forth) - put the terminal into "raw" mode where keystroke bytes are sent through unchanged (although them you need to hand carriage return yourself, etc) Perhaps Windows has a "literal-next" keystroke line UNIX does. > I have a multi-threaded Python program which recognizes ESC as >a command to stop something. This works on Linux, but not on >Windows. Apparently something in Windows land pulls in "readline". Unlikely. See above. > What's the best way to get input from the console (not any >enclosing shell script) that's cross-platform, cross-version >(Python 2.7, 3.x), and doesn't do "readline" processing? sys.stdin.readline() input() is a conveience function, now very low level. Cheers, Cameron Simpson From tjreedy at udel.edu Fri Jul 8 20:20:18 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 8 Jul 2016 20:20:18 -0400 Subject: input vs. readline In-Reply-To: References: Message-ID: On 7/8/2016 7:17 PM, John Nagle wrote: > If "readline" is imported, "input" gets "readline" capabilities. > It also loses the ability to import control characters. It doesn't > matter where "readline" is imported; an import in some library > module can trigger this. You can try this with a simple test > case: > > print(repr(input())) > > as a .py file, run in a console. Try typing "aaaESCbbb". > On Windows 7, output is "bbb". The escape key erasing input back to the beginning of the line is Command Prompt or cmd.exe behavior. Type anything at a normal command prompt and hit ESC. Input one. It has nothing to do with Python or the readline module. > On Linux, it's "aaa\x1bbbb". The interpretation of control characters is terminal-specific. IDLE's shell uses the same editing keys as the editor window, which depend on OS and user customization. Note that Python statement input is multiline, not single line. It does not try to imitate any particular terminal and does not normally recognize ESC. > What's the best way to get input from the console (not any > enclosing shell script) that's cross-platform, cross-version > (Python 2.7, 3.x), and doesn't do "readline" processing? Run Python in a cross-platform, cross-verson shell. IDLE with a fixed key set would qualifiy except a) inputting literal control chars would not work, and b) normal key sets do not work on both Mac and other systems. I don't know how close other IDEs come. -- Terry Jan Reedy From cs at zip.com.au Fri Jul 8 20:24:33 2016 From: cs at zip.com.au (cs at zip.com.au) Date: Sat, 9 Jul 2016 10:24:33 +1000 Subject: input vs. readline In-Reply-To: <20160708234512.GA99445@cskk.homeip.net> References: <20160708234512.GA99445@cskk.homeip.net> Message-ID: <20160709002433.GA1242@cskk.homeip.net> I was typing in a hurry. There are several unreadable items below. Let me correct myself... On 09Jul2016 09:45, Cameron Simpson wrote: >Perhaps the Windows console is treating ESC specially, apparently as "line >erase", discarduing any preceeding text. Hence your results. [...] >- accept this, and use the liternal-next kestroke (usually ^V) to tell it not >to the bytes special to the line discipline. So you might type ^V^H to get a >literal ^H code in your input and so forth. "literal", not "liternal". "not to the" => "not to treat the". "special" => "specially". >- put the terminal into "raw" mode where keystroke bytes are sent through >unchanged (although them you need to hand carriage return yourself, etc) "then", not "them". "handle", not "hand". Cheers, Cameron Simpson From eryksun at gmail.com Fri Jul 8 21:00:46 2016 From: eryksun at gmail.com (eryk sun) Date: Sat, 9 Jul 2016 01:00:46 +0000 Subject: input vs. readline In-Reply-To: References: Message-ID: On Fri, Jul 8, 2016 at 11:17 PM, John Nagle wrote: > If "readline" is imported, "input" gets "readline" capabilities. > It also loses the ability to import control characters. It doesn't > matter where "readline" is imported; an import in some library > module can trigger this. You can try this with a simple test > case: > > print(repr(input())) > > as a .py file, run in a console. Try typing "aaaESCbbb". > On Windows 7, output is "bbb". On Linux, it's "aaa\x1bbbb". The readline module isn't automatically imported for a script, and it isn't even distributed with Windows Python. You have to install pyreadline to get readline support on Windows. You're seeing the readline-like behavior of a Windows console processed read, i.e. with the console mode ENABLE_PROCESSED_INPUT [1]. The supported command-line editing and history functions are documented for doskey.exe [2], though in modern Windows systems (based on NT), it's actually the console (conhost.exe) that implements all of the doskey functionality. For example, ESC "[c]lears the command from the display". Unfortunately processed input is all or nothing; the console doesn't even process the enter key if processed input is disabled. You'd have to do a lot of lowish-level ctypes or PyWin32 scripting to get something usable, but maybe the CRT's getwche() function is good enough. Try the following: #! /usr/bin/python3 import sys if sys.platform == 'win32': import msvcrt def input(prompt=''): if prompt: print(prompt, end='', flush=True) s = [] while True: c = msvcrt.getwche() if c == '\r': break s.append(c) s = ''.join(s) print(prompt, s, sep='') return s if __name__ == '__main__': print(repr(input('test: '))) [1]: https://msdn.microsoft.com/en-us/library/ms683167 [2]: https://technet.microsoft.com/en-us/library/cc753867 From eryksun at gmail.com Fri Jul 8 21:15:06 2016 From: eryksun at gmail.com (eryk sun) Date: Sat, 9 Jul 2016 01:15:06 +0000 Subject: input vs. readline In-Reply-To: References: Message-ID: On Sat, Jul 9, 2016 at 12:20 AM, Terry Reedy wrote: > The escape key erasing input back to the beginning of the line is Command > Prompt or cmd.exe behavior. cmd.exe is just a shell that uses the console (if the standard handles are console handles). The console window is hosted by conhost.exe. It processes the input buffer for command-line editing, and it maintains command history and a set of aliases (matching at the start of a line) for each attached executable (e.g. cmd.exe, powershell.exe, chcp.com, mode.com, doskey.exe, python.exe, etc). Every Windows process can attach to a single console window via AllocConsole or AttachConsole, and detach via FreeConsole. From carlosjosepita at gmail.com Sat Jul 9 00:08:35 2016 From: carlosjosepita at gmail.com (carlosjosepita at gmail.com) Date: Fri, 8 Jul 2016 21:08:35 -0700 (PDT) Subject: __qualname__ exposed as a local variable: standard? Message-ID: <379ac9d7-f68e-4e36-bb55-ca8b1887962d@googlegroups.com> Hi all, I noticed __qualname__ is exposed by locals() while defining a class. This is handy but I'm not sure about its status: is it standard or just an artifact of the current implementation? (btw, the pycodestyle linter -former pep8- rejects its usage). I was unable to find any reference to this behavior in PEP 3155 nor in the language reference. Thank you in advance -- Carlos From steve at pearwood.info Sat Jul 9 01:26:12 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 09 Jul 2016 15:26:12 +1000 Subject: Quick poll: gmean or geometric_mean Message-ID: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> 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 geometric_mean Remember that the arithmetic mean is just called "mean". http://bugs.python.org/issue27181 -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jussi.piitulainen at helsinki.fi Sat Jul 9 01:43:27 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Sat, 09 Jul 2016 08:43:27 +0300 Subject: Quick poll: gmean or geometric_mean References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > 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 geometric_mean > > > Remember that the arithmetic mean is just called "mean". > > http://bugs.python.org/issue27181 First reaction: hmean and gmean. After reading the issue: hmean and gmean. After a brief glance at the statistics module: hmean and gmean. Or also change pstdev and pvariance to population_stdev and population_variance for consistency. Still: hmean and gmean. From random832 at fastmail.com Sat Jul 9 01:49:46 2016 From: random832 at fastmail.com (Random832) Date: Sat, 09 Jul 2016 01:49:46 -0400 Subject: Quick poll: gmean or geometric_mean In-Reply-To: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1468043386.1292856.661217857.45C882AD@webmail.messagingengine.com> On Sat, Jul 9, 2016, at 01:26, Steven D'Aprano wrote: > hmean and gmean > > harmonic_mean and geometric_mean The latter, definitely. > Remember that the arithmetic mean is just called "mean". so? (also maybe it shouldn't be?) From ethan at stoneleaf.us Sat Jul 9 02:27:02 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 08 Jul 2016 23:27:02 -0700 Subject: Quick poll: gmean or geometric_mean In-Reply-To: <1468043386.1292856.661217857.45C882AD@webmail.messagingengine.com> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <1468043386.1292856.661217857.45C882AD@webmail.messagingengine.com> Message-ID: <57809936.6020303@stoneleaf.us> On 07/08/2016 10:49 PM, Random832 wrote: > On Sat, Jul 9, 2016, at 01:26, Steven D'Aprano wrote: >> hmean and gmean >> >> harmonic_mean and geometric_mean > > The latter, definitely. My preference is also for the latter. However, if the rest of the module is filled with abbreviated names you may as well be consistent with them. -- ~Ethan~ From __peter__ at web.de Sat Jul 9 05:04:21 2016 From: __peter__ at web.de (Peter Otten) Date: Sat, 09 Jul 2016 11:04:21 +0200 Subject: Quick poll: gmean or geometric_mean References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: 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 geometric_mean The long names. Life's too short for abbreviations. > Remember that the arithmetic mean is just called "mean". I think it's a safe bet that a user asking for the unqualified mean wants just that. > http://bugs.python.org/issue27181 From stefan_ml at behnel.de Sat Jul 9 06:23:29 2016 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 9 Jul 2016 12:23:29 +0200 Subject: Quick poll: gmean or geometric_mean In-Reply-To: <57809936.6020303@stoneleaf.us> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <1468043386.1292856.661217857.45C882AD@webmail.messagingengine.com> <57809936.6020303@stoneleaf.us> Message-ID: Ethan Furman schrieb am 09.07.2016 um 08:27: > On 07/08/2016 10:49 PM, Random832 wrote: >> On Sat, Jul 9, 2016, at 01:26, Steven D'Aprano wrote: > >>> hmean and gmean >>> >>> harmonic_mean and geometric_mean >> >> The latter, definitely. > > My preference is also for the latter. However, if the rest of the module > is filled with abbreviated names you may as well be consistent with them. +1 for consistency, but I'm just fine with the short names. It's in the statistics module after all, so the context is very narrow and clear and people who don't know which to use or what the one does that they find in a given piece of code will have to read the docs and maybe fresh up their rusty math memory anyway. Longer names don't help much with that. If further clarity is needed in a given code context that uses a direct name import, renaming the function at the same time is easy enough. I often do that with "os.path.join", for example, which turns into "join_path" on import. Same problem, easy solution. Stefan From ethan at stoneleaf.us Sat Jul 9 09:51:52 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 09 Jul 2016 06:51:52 -0700 Subject: Quick poll: gmean or geometric_mean In-Reply-To: References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <1468043386.1292856.661217857.45C882AD@webmail.messagingengine.com> <57809936.6020303@stoneleaf.us> Message-ID: <57810178.8060500@stoneleaf.us> On 07/09/2016 03:23 AM, Stefan Behnel wrote: > Ethan Furman schrieb am 09.07.2016 um 08:27: >> On 07/08/2016 10:49 PM, Random832 wrote: >>> On Sat, Jul 9, 2016, at 01:26, Steven D'Aprano wrote: >> >>>> hmean and gmean >>>> >>>> harmonic_mean and geometric_mean >>> >>> The latter, definitely. >> >> My preference is also for the latter. However, if the rest of the module >> is filled with abbreviated names you may as well be consistent with them. > > +1 for consistency, but I'm just fine with the short names. It's in the > statistics module after all, so the context is very narrow and clear and > people who don't know which to use or what the one does that they find in a > given piece of code will have to read the docs and maybe fresh up their > rusty math memory anyway. Longer names don't help much with that. > > If further clarity is needed in a given code context that uses a direct > name import, renaming the function at the same time is easy enough. I often > do that with "os.path.join", for example, which turns into "join_path" on > import. Same problem, easy solution. +1 I would definitely need to read the docs, whatever the name. ;) -- ~Ethan~ From carlosjosepita at gmail.com Sat Jul 9 10:05:28 2016 From: carlosjosepita at gmail.com (carlosjosepita at gmail.com) Date: Sat, 9 Jul 2016 07:05:28 -0700 (PDT) Subject: Namespaces are one honking great idea In-Reply-To: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <57767a97$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <221b0501-eeb1-4c93-aa83-6c73854299c4@googlegroups.com> Hi all, although it doesn't fit the bill 100%, I sometimes use this extremely simple function as a decorator: def new(call): return call() For example: @new class MySingleton: x = 2 y = 2 def sum(self, x, y): return x + y @new def my_obj(): x = 2 y = 2 def sum(x, y): return x + y return Bundle(locals()) where Bundle is a simple subclass of dict implementing __xxxattr__ dunder methods. Cheers -- Carlos From jsf80238 at gmail.com Sat Jul 9 10:16:13 2016 From: jsf80238 at gmail.com (Jason Friedman) Date: Sat, 9 Jul 2016 08:16:13 -0600 Subject: Quick poll: gmean or geometric_mean In-Reply-To: References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <1468043386.1292856.661217857.45C882AD@webmail.messagingengine.com> <57809936.6020303@stoneleaf.us> Message-ID: > > +1 for consistency, but I'm just fine with the short names. It's in the > statistics module after all, so the context is very narrow and clear and > people who don't know which to use or what the one does that they find in a > given piece of code will have to read the docs and maybe fresh up their > rusty math memory anyway. Longer names don't help much with that. > > If further clarity is needed in a given code context that uses a direct > name import, renaming the function at the same time is easy enough. I often > do that with "os.path.join", for example, which turns into "join_path" on > import. Same problem, easy solution. +1 From michael.selik at gmail.com Sat Jul 9 12:13:19 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sat, 09 Jul 2016 16:13:19 +0000 Subject: Quick poll: gmean or geometric_mean In-Reply-To: References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <1468043386.1292856.661217857.45C882AD@webmail.messagingengine.com> <57809936.6020303@stoneleaf.us> Message-ID: On Sat, Jul 9, 2016 at 10:17 AM Jason Friedman wrote: > > +1 for consistency > What do other languages use? Even though I generally prefer complete words instead of abbreviations, if an abbreviation is a strong standard across many statistics modules (like "stdev" instead of "standard_deviation"), then it's better to stay consistent with that standard. From robert.kern at gmail.com Sat Jul 9 12:53:42 2016 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 9 Jul 2016 17:53:42 +0100 Subject: Quick poll: gmean or geometric_mean In-Reply-To: References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <1468043386.1292856.661217857.45C882AD@webmail.messagingengine.com> <57809936.6020303@stoneleaf.us> Message-ID: On 2016-07-09 17:13, Michael Selik wrote: > On Sat, Jul 9, 2016 at 10:17 AM Jason Friedman wrote: > >>> +1 for consistency > > What do other languages use? R, the most likely candidate, doesn't have them built-in. scipy.stats uses gmean() and hmean() -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From michael.selik at gmail.com Sat Jul 9 14:31:54 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sat, 09 Jul 2016 18:31:54 +0000 Subject: Quick poll: gmean or geometric_mean In-Reply-To: References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <1468043386.1292856.661217857.45C882AD@webmail.messagingengine.com> <57809936.6020303@stoneleaf.us> Message-ID: On Sat, Jul 9, 2016, 12:57 PM Robert Kern wrote: > On 2016-07-09 17:13, Michael Selik wrote: > > On Sat, Jul 9, 2016 at 10:17 AM Jason Friedman > wrote: > > > >>> +1 for consistency > > > > What do other languages use? > > R, the most likely candidate, doesn't have them built-in. > > scipy.stats uses gmean() and hmean() > SciPy also uses other obscure abbreviations. My least favorite is "eye". My first thought at reading "hmean" might be horizontal mean, especially if there were a vmean. > From eryksun at gmail.com Sat Jul 9 14:52:33 2016 From: eryksun at gmail.com (eryk sun) Date: Sat, 9 Jul 2016 18:52:33 +0000 Subject: __qualname__ exposed as a local variable: standard? In-Reply-To: <379ac9d7-f68e-4e36-bb55-ca8b1887962d@googlegroups.com> References: <379ac9d7-f68e-4e36-bb55-ca8b1887962d@googlegroups.com> Message-ID: On Sat, Jul 9, 2016 at 4:08 AM, wrote: > > I noticed __qualname__ is exposed by locals() while defining a class. This is an undocumented implementation detail used to pass this information to the metaclass. You'll also see __module__ and, if the class has a docstring, __doc__. For CPython, this is implemented in the functions compiler_class (for __module__ and __qualname__) and compiler_body (for __doc__), which you'll find in Python/compile.c. From malik.a.rumi at gmail.com Sat Jul 9 17:37:46 2016 From: malik.a.rumi at gmail.com (Malik Rumi) Date: Sat, 9 Jul 2016 14:37:46 -0700 (PDT) Subject: the best online course In-Reply-To: References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> Message-ID: <71cf6d09-d094-44cc-befc-c66ec35e4ff6@googlegroups.com> I want one of those "knuckle down and learn" classes. But even more than that, I want a class with a real teacher who is available to answer questions and explain things. I've done a lot of books and online video, but there's usually no help. If I search around long enough, I can often find an answer, but this is just way too fragmented for me. Where can I find classes like that - online - paid or free? Thanks. From rosuav at gmail.com Sat Jul 9 17:45:06 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jul 2016 07:45:06 +1000 Subject: Quick poll: gmean or geometric_mean In-Reply-To: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jul 9, 2016 at 3:26 PM, Steven D'Aprano wrote: > I'd like to get a quick show of hands regarding the names. Which do you > prefer? > > hmean and gmean > > harmonic_mean and geometric_mean I'd prefer the shorter names. ChrisA From rosuav at gmail.com Sat Jul 9 17:57:59 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jul 2016 07:57:59 +1000 Subject: the best online course In-Reply-To: <71cf6d09-d094-44cc-befc-c66ec35e4ff6@googlegroups.com> References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> <71cf6d09-d094-44cc-befc-c66ec35e4ff6@googlegroups.com> Message-ID: On Sun, Jul 10, 2016 at 7:37 AM, Malik Rumi wrote: > I want one of those "knuckle down and learn" classes. But even more than that, I want a class with a real teacher who is available to answer questions and explain things. I've done a lot of books and online video, but there's usually no help. If I search around long enough, I can often find an answer, but this is just way too fragmented for me. Where can I find classes like that - online - paid or free? Thanks. > Yes, they definitely exist. I work with a company called Thinkful (www.thinkful.com) which does what you're talking about - you get a personal mentor with whom you meet regularly, plus access to a number of experts. It's a paid course. There are other such courses around, too, but I don't personally know their effectiveness. ChrisA From ethan at stoneleaf.us Sat Jul 9 19:09:28 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 09 Jul 2016 16:09:28 -0700 Subject: the best online course In-Reply-To: References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> <71cf6d09-d094-44cc-befc-c66ec35e4ff6@googlegroups.com> Message-ID: <57818428.7010604@stoneleaf.us> On 07/09/2016 02:57 PM, Chris Angelico wrote: > On Sun, Jul 10, 2016 at 7:37 AM, Malik Rumi wrote: >> I want one of those "knuckle down and learn" classes. But even more >> than that, I want a class with a real teacher who is available to >> answer questions and explain things. I've done a lot of books and >> online video, but there's usually no help. If I search around long >> enough, I can often find an answer, but this is just way too fragmented >> for me. Where can I find classes like that - online - paid or free? Thanks. > > Yes, they definitely exist. I work with a company called Thinkful > (www.thinkful.com) which does what you're talking about - you get a > personal mentor with whom you meet regularly, plus access to a number > of experts. It's a paid course. There are other such courses around, > too, but I don't personally know their effectiveness. Udacity.com is another. They have several free classes, or you can pay and get access to instructors. -- ~Ethan~ From rosuav at gmail.com Sat Jul 9 19:21:55 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jul 2016 09:21:55 +1000 Subject: the best online course In-Reply-To: <57818428.7010604@stoneleaf.us> References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> <71cf6d09-d094-44cc-befc-c66ec35e4ff6@googlegroups.com> <57818428.7010604@stoneleaf.us> Message-ID: On Sun, Jul 10, 2016 at 9:09 AM, Ethan Furman wrote: > On 07/09/2016 02:57 PM, Chris Angelico wrote: >> >> On Sun, Jul 10, 2016 at 7:37 AM, Malik Rumi wrote: > > >>> I want one of those "knuckle down and learn" classes. But even more > >>> than that, I want a class with a real teacher who is available to >>> answer questions and explain things. I've done a lot of books and >>> online video, but there's usually no help. If I search around long >>> enough, I can often find an answer, but this is just way too fragmented >>> for me. Where can I find classes like that - online - paid or free? >>> Thanks. >> >> >> Yes, they definitely exist. I work with a company called Thinkful >> (www.thinkful.com) which does what you're talking about - you get a >> personal mentor with whom you meet regularly, plus access to a number >> of experts. It's a paid course. There are other such courses around, >> too, but I don't personally know their effectiveness. > > > Udacity.com is another. They have several free classes, or you can pay and > get access to instructors. Yes, I hear a lot about Udacity. Has anyone taken any of the pay-for classes? Are the instructors helpful, skilled, etc? Did it seem like good value for money? ChrisA From lawrencedo99 at gmail.com Sun Jul 10 01:54:48 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 9 Jul 2016 22:54:48 -0700 (PDT) Subject: Curious Omission In New-Style Formats Message-ID: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> In printf-style formats, you can specify the number of digits for an integer separately from the field width. E.g. >>> "%#0.5x" % 0x123 '0x00123' but not in new-style formats: >>> "{:#0.5x}".format(0x123) Traceback (most recent call last): File "", line 1, in ValueError: Precision not allowed in integer format specifier The field width itself doesn?t give the right number of digits in this case: >>> "{:#05x}".format(0x123) '0x123' because you lose 2 characters for the ?0x? prefix. From bob.martin at excite.com Sun Jul 10 08:18:49 2016 From: bob.martin at excite.com (Bob Martin) Date: Sun, 10 Jul 2016 08:18:49 BST Subject: the best online course References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> <71cf6d09-d094-44cc-befc-c66ec35e4ff6@googlegroups.com> Message-ID: in 762247 20160709 223746 Malik Rumi wrote: >I want one of those "knuckle down and learn" classes. But even more than th= >at, I want a class with a real teacher who is available to answer questions= >and explain things. I've done a lot of books and online video, but there's= >usually no help. If I search around long enough, I can often find an answe= >r, but this is just way too fragmented for me. Where can I find classes lik= >e that - online - paid or free? Thanks. Having to work for your answer means you are more likely to remember it. From ian.g.kelly at gmail.com Sun Jul 10 03:21:40 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 10 Jul 2016 01:21:40 -0600 Subject: Curious Omission In New-Style Formats In-Reply-To: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> Message-ID: On Sat, Jul 9, 2016 at 11:54 PM, Lawrence D?Oliveiro wrote: > In printf-style formats, you can specify the number of digits for an integer separately from the field width. E.g. > > >>> "%#0.5x" % 0x123 > '0x00123' > > but not in new-style formats: > > >>> "{:#0.5x}".format(0x123) > Traceback (most recent call last): > File "", line 1, in > ValueError: Precision not allowed in integer format specifier > > The field width itself doesn?t give the right number of digits in this case: > > >>> "{:#05x}".format(0x123) > '0x123' > > because you lose 2 characters for the ?0x? prefix. So add 2 to the field width to account for the fixed-size prefix. >>> '{:#07x}'.format(0x123) '0x00123' It's specified in PEP 3101 that the precision is ignored for integer conversions. Apparently that changed from "ignored" to "not allowed" in 3.1, as per the documentation. I'm not sure what the reasoning was, except perhaps that precision doesn't really make sense for integers in the first place. From ian.g.kelly at gmail.com Sun Jul 10 03:28:46 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 10 Jul 2016 01:28:46 -0600 Subject: Quick poll: gmean or geometric_mean In-Reply-To: References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jul 9, 2016 at 3:45 PM, Chris Angelico wrote: > On Sat, Jul 9, 2016 at 3:26 PM, Steven D'Aprano wrote: >> I'd like to get a quick show of hands regarding the names. Which do you >> prefer? >> >> hmean and gmean >> >> harmonic_mean and geometric_mean > > I'd prefer the shorter names. I'd prefer the longer. Anybody who wants gmean can easily type: from statistics import geometric_mean as gmean From rustompmody at gmail.com Sun Jul 10 03:28:47 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Jul 2016 00:28:47 -0700 (PDT) Subject: Quick poll: gmean or geometric_mean In-Reply-To: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, July 9, 2016 at 10:56:27 AM UTC+5:30, 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 geometric_mean > > > Remember that the arithmetic mean is just called "mean". > > http://bugs.python.org/issue27181 >From fuzzy memory of sitting in statistics classes decades ago filled with ?-? etc I'd suggest ? g? h? And before I duck and run let me just tell my dear Chris I was only ?-joking From jussi.piitulainen at helsinki.fi Sun Jul 10 04:01:22 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Sun, 10 Jul 2016 11:01:22 +0300 Subject: Quick poll: gmean or geometric_mean References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: Ian Kelly writes: > On Sat, Jul 9, 2016 at 3:45 PM, Chris Angelico wrote: >> On Sat, Jul 9, 2016 at 3:26 PM, Steven D'Aprano wrote: >>> I'd like to get a quick show of hands regarding the names. Which do you >>> prefer? >>> >>> hmean and gmean >>> >>> harmonic_mean and geometric_mean >> >> I'd prefer the shorter names. > > I'd prefer the longer. Anybody who wants gmean can easily type: > > from statistics import geometric_mean as gmean That argument goes both ways with equal force. Possibly very slightly in favour of the *shorter* names, for those who are happy to import the function with its eventual name as is. I did say "very slightly". From steve at pearwood.info Sun Jul 10 04:51:04 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jul 2016 18:51:04 +1000 Subject: Quick poll: gmean or geometric_mean References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> On Sun, 10 Jul 2016 05:28 pm, Rustom Mody wrote: > From fuzzy memory of sitting in statistics classes decades ago > filled with ?-? etc I'd suggest ? g? h? In all the stats books and references I've seen, ? is always the population mean (implicitly the arithmetic mean). When discussing the different kinds of mean, A, G and H are used for arithmetic, geometric and harmonic means. (Other means are rarely discussed.) I don't think I've ever seen g? or h?. They're sort of backwards... I'd expect ? subscript-g or subscript-h, not the other way. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From michael.selik at gmail.com Sun Jul 10 05:24:10 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sun, 10 Jul 2016 09:24:10 +0000 Subject: Quick poll: gmean or geometric_mean In-Reply-To: <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 10, 2016, 4:56 AM Steven D'Aprano wrote: > On Sun, 10 Jul 2016 05:28 pm, Rustom Mody wrote: > > > From fuzzy memory of sitting in statistics classes decades ago > > filled with ?-? etc I'd suggest ? g? h? > > In all the stats books and references I've seen, ? is always the population > mean (implicitly the arithmetic mean). When discussing the different kinds > of mean, A, G and H are used for arithmetic, geometric and harmonic means. > (Other means are rarely discussed.) > > I don't think I've ever seen g? or h?. They're sort of backwards... I'd > expect ? subscript-g or subscript-h, not the other way. > I'm glad you brought up textbooks as it reminded me to say that most scientific software is still struggling to shake off the legacy of abbreviation. Now even the basic IPython shell has autocomplete :-) > From steve at pearwood.info Sun Jul 10 06:08:41 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 10 Jul 2016 20:08:41 +1000 Subject: Quick poll: gmean or geometric_mean References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> On Sun, 10 Jul 2016 07:24 pm, Michael Selik wrote: > On Sun, Jul 10, 2016, 4:56 AM Steven D'Aprano wrote: > >> On Sun, 10 Jul 2016 05:28 pm, Rustom Mody wrote: >> >> > From fuzzy memory of sitting in statistics classes decades ago >> > filled with ?-? etc I'd suggest ? g? h? >> >> In all the stats books and references I've seen, ? is always the >> population mean (implicitly the arithmetic mean). When discussing the >> different kinds of mean, A, G and H are used for arithmetic, geometric >> and harmonic means. (Other means are rarely discussed.) >> >> I don't think I've ever seen g? or h?. They're sort of backwards... I'd >> expect ? subscript-g or subscript-h, not the other way. >> > > I'm glad you brought up textbooks as it reminded me to say that most > scientific software is still struggling to shake off the legacy of > abbreviation. > > Now even the basic IPython shell has autocomplete :-) Not all shells or editors are IPython, and not all abbreviations are bad. Would you rather print, or write_values_as_strings_to_the_predefined_standard_output_file? :-) -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Jul 10 07:07:20 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jul 2016 21:07:20 +1000 Subject: Quick poll: gmean or geometric_mean In-Reply-To: <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 10, 2016 at 8:08 PM, Steven D'Aprano wrote: >> Now even the basic IPython shell has autocomplete :-) > > Not all shells or editors are IPython, and not all abbreviations are bad. > Would you rather print, or > write_values_as_strings_to_the_predefined_standard_output_file? Also: Interesting that the IPython shell is "basic". I thought the basic Python shell was the one you get when you type "python" with no args. Idle or IPython or anything else is a layer on top of that. ChrisA From rustompmody at gmail.com Sun Jul 10 10:29:46 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Jul 2016 07:29:46 -0700 (PDT) Subject: Quick poll: gmean or geometric_mean In-Reply-To: <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> On Sunday, July 10, 2016 at 3:39:02 PM UTC+5:30, Steven D'Aprano wrote: > On Sun, 10 Jul 2016 07:24 pm, Michael Selik wrote: > > > On Sun, Jul 10, 2016, 4:56 AM Steven D'Aprano wrote: > > > >> On Sun, 10 Jul 2016 05:28 pm, Rustom Mody wrote: > >> > >> > From fuzzy memory of sitting in statistics classes decades ago > >> > filled with ?-? etc I'd suggest ? g? h? > >> > >> In all the stats books and references I've seen, ? is always the > >> population mean (implicitly the arithmetic mean). When discussing the > >> different kinds of mean, A, G and H are used for arithmetic, geometric > >> and harmonic means. (Other means are rarely discussed.) > >> > >> I don't think I've ever seen g? or h?. They're sort of backwards... I'd > >> expect ? subscript-g or subscript-h, not the other way. > >> > > > > I'm glad you brought up textbooks as it reminded me to say that most > > scientific software is still struggling to shake off the legacy of > > abbreviation. > > > > Now even the basic IPython shell has autocomplete :-) > > Not all shells or editors are IPython, and not all abbreviations are bad. > Would you rather print, or > write_values_as_strings_to_the_predefined_standard_output_file? > > :-) Newton's law F = -Gm?m?/r? Better seen in its normal math form: https://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation#Modern_form De-abbreviated Force is given by the negative of the universal_gravitational_constant times the mass_of_first_body times mass_of_second_body divided by the square of the distance_between_the_bodies Cobol anyone? Ok with typical python naming Force = (universal_gravitational_constant * mass_of_first_body * mass_of_second_body) / (distance_between_the_bodies*distance_between_the_bodies) From rustompmody at gmail.com Sun Jul 10 10:44:48 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Jul 2016 07:44:48 -0700 (PDT) Subject: Quick poll: gmean or geometric_mean In-Reply-To: <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> Message-ID: On Sunday, July 10, 2016 at 8:00:00 PM UTC+5:30, Rustom Mody wrote: > Newton's law F = -Gm?m?/r? > > Better seen in its normal math form: > https://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation#Modern_form > > De-abbreviated > > Force is given by the negative of the universal_gravitational_constant times > the mass_of_first_body times mass_of_second_body divided by the square of the distance_between_the_bodies > > Cobol anyone? Actually I do injustice to Cobol. Cobol allowed hyphenated names -- more readable than underscored: Force is given by the negative of the universal-gravitational-constant times the mass-of-first-body times mass-of-second-body divided by the square of the distance-between-the-bodies From ian.g.kelly at gmail.com Sun Jul 10 10:55:28 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 10 Jul 2016 08:55:28 -0600 Subject: Quick poll: gmean or geometric_mean In-Reply-To: <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> Message-ID: On Sun, Jul 10, 2016 at 8:29 AM, Rustom Mody wrote: > Newton's law F = -Gm?m?/r? > > Better seen in its normal math form: > https://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation#Modern_form > > De-abbreviated > > Force is given by the negative of the universal_gravitational_constant times > the mass_of_first_body times mass_of_second_body divided by the square of the distance_between_the_bodies > > Cobol anyone? > > Ok with typical python naming > > Force = (universal_gravitational_constant * mass_of_first_body * mass_of_second_body) / (distance_between_the_bodies*distance_between_the_bodies) That's still excessive by any reasonable standards. Names should be descriptive, but no more verbose than necessary. How about: force_N = -G * mass1_kg * mass2_kg / distance_m ** 2 I'm fine with "G" as is because it's the standard name for the value in physics contexts, and it's presumably defined in the code as a constant. It's every bit as clear as "pi". From marko at pacujo.net Sun Jul 10 11:03:37 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Jul 2016 18:03:37 +0300 Subject: Quick poll: gmean or geometric_mean References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> Message-ID: <87r3b11qnq.fsf@elektro.pacujo.net> Ian Kelly : > That's still excessive by any reasonable standards. Names should be > descriptive, but no more verbose than necessary. How about: > > force_N = -G * mass1_kg * mass2_kg / distance_m ** 2 Why bother with tagging the names with standard units? Somewhat related: Many programming frameworks standardize on milliseconds when expressing durations. Python does the honorable thing and uses the standard unit, the second, for the purpose. For example, coroutine asyncio.wait(futures, *, loop=None, timeout=None, return_when=ALL_COMPLETED) [...] timeout can be used to control the maximum number of seconds to wait before returning. timeout can be an int or float. If timeout is not specified or None, there is no limit to the wait time. Not only is a universal standard followed but the API is future proof as it allows for (almost) arbitrary granularity. Want to timeout after 17 femtoseconds? Just specify timeout=17e-15. Marko From ian.g.kelly at gmail.com Sun Jul 10 11:04:32 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 10 Jul 2016 09:04:32 -0600 Subject: Quick poll: gmean or geometric_mean In-Reply-To: References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 10, 2016 at 2:01 AM, Jussi Piitulainen wrote: > Ian Kelly writes: > >> On Sat, Jul 9, 2016 at 3:45 PM, Chris Angelico wrote: >>> On Sat, Jul 9, 2016 at 3:26 PM, Steven D'Aprano wrote: >>>> I'd like to get a quick show of hands regarding the names. Which do you >>>> prefer? >>>> >>>> hmean and gmean >>>> >>>> harmonic_mean and geometric_mean >>> >>> I'd prefer the shorter names. >> >> I'd prefer the longer. Anybody who wants gmean can easily type: >> >> from statistics import geometric_mean as gmean > > That argument goes both ways with equal force. Possibly very slightly in > favour of the *shorter* names, for those who are happy to import the > function with its eventual name as is. > > I did say "very slightly". No, it doesn't. That the user can alias the name in their own code is not an advantage at all for picking a non-descriptive name. It doesn't change the fact that you have a non-descriptive name for the function in the docs, the examples, and as the default. And do you really think that anybody would ever choose an alias to make the name of a function *longer*? If you start out with the descriptive name though, then you get all the benefits of such, and users who want to can easily shorten it. And then even in code where it's been aliased to be shorter, the full descriptive name is still visible in at least one place -- the import statement -- which is at least somewhat helpful to anybody reading the module who isn't familiar with the "gmean" function. From ganesh1pal at gmail.com Sun Jul 10 11:19:14 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sun, 10 Jul 2016 20:49:14 +0530 Subject: one command on backslash and space for review Message-ID: Hello Team, I am on python 2.7 and Linux , I want to form the below sample command so that I could run it on the shell. Command is --> run_parallel -za1 -s 'daemon -cf xyz; sleep 1' Here is how I formed the command and it seems to look fine and work fine , but I think it could still be better any idea ? >>> cmd = "run_parallel -za" + str(number) + \ ... " -s" + " \'daemon -cf xyz; sleep 1\'" >>> cmd "run_parallel -za1 -s 'daemon -cf xyz; sleep 1'" >>> Looking for thoughts around: 1. If backslash are syntactically correct 2. " -s" , starting with a leading space , may be its not a good idea , other ways 3. Iam running sleep command on the cluster i.e , how could I make it look Python or its fine to have sleep ? Regards, Ganesh From michael.selik at gmail.com Sun Jul 10 11:43:07 2016 From: michael.selik at gmail.com (Michael Selik) Date: Sun, 10 Jul 2016 15:43:07 +0000 Subject: Quick poll: gmean or geometric_mean In-Reply-To: References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 10, 2016, 5:08 AM Chris Angelico wrote: > On Sun, Jul 10, 2016 at 8:08 PM, Steven D'Aprano > wrote: > >> Now even the basic IPython shell has autocomplete :-) > > > > Not all shells or editors are IPython, and not all abbreviations are bad. > > Would you rather print, or > > write_values_as_strings_to_the_predefined_standard_output_file? > > Also: Interesting that the IPython shell is "basic". I thought the > basic Python shell was the one you get when you type "python" with no > args. Idle or IPython or anything else is a layer on top of that. > It is. I meant the basic terminal version of IPython, rather than the QT or Jupyter version. IPython 5 switched from readline to prompt_toolkit, so it gained a few nice features. > From random832 at fastmail.com Sun Jul 10 12:08:17 2016 From: random832 at fastmail.com (Random832) Date: Sun, 10 Jul 2016 12:08:17 -0400 Subject: Quick poll: gmean or geometric_mean In-Reply-To: References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> Message-ID: <1468166897.4099652.662046337.7898C4E9@webmail.messagingengine.com> On Sun, Jul 10, 2016, at 10:55, Ian Kelly wrote: > force_N = -G * mass1_kg * mass2_kg / distance_m ** 2 > > I'm fine with "G" as is because it's the standard name for the value > in physics contexts, and it's presumably defined in the code as a > constant. It's every bit as clear as "pi". Shouldn't it be G_N_m2_per_kg2, given your strategy for identifying the units associated with the other variables? From ethan at stoneleaf.us Sun Jul 10 13:06:33 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 10 Jul 2016 10:06:33 -0700 Subject: the best online course In-Reply-To: References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> <71cf6d09-d094-44cc-befc-c66ec35e4ff6@googlegroups.com> Message-ID: <57828099.4090703@stoneleaf.us> On 07/10/2016 12:18 AM, Bob Martin wrote: > in 762247 20160709 223746 Malik Rumi wrote: >> I want one of those "knuckle down and learn" classes. But even more than th= >> at, I want a class with a real teacher who is available to answer questions= >> and explain things. I've done a lot of books and online video, but there's= >> usually no help. If I search around long enough, I can often find an answe= >> r, but this is just way too fragmented for me. Where can I find classes lik= >> e that - online - paid or free? Thanks. > > Having to work for your answer means you are more likely to remember it. True, but like most things there is a balance -- searching for hours for an answer is frustrating and discouraging, and the thing most likely remembered is not the answer the pain in finding it. -- ~Ethan~ From ian.g.kelly at gmail.com Sun Jul 10 13:15:59 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 10 Jul 2016 11:15:59 -0600 Subject: Quick poll: gmean or geometric_mean In-Reply-To: <87r3b11qnq.fsf@elektro.pacujo.net> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> <87r3b11qnq.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 10, 2016 at 9:03 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> That's still excessive by any reasonable standards. Names should be >> descriptive, but no more verbose than necessary. How about: >> >> force_N = -G * mass1_kg * mass2_kg / distance_m ** 2 > > Why bother with tagging the names with standard units? The point of the example was to demonstrate descriptive names. For local variables I usually wouldn't bother with the units, but in general it's a good practice to help avoid crashing your orbiter into Mars. > Shouldn't it be G_N_m2_per_kg2, given your strategy for identifying the > units associated with the other variables? To me, the use of the standard name implies standard units, so no, "G" is sufficient. YMMV. From ian.g.kelly at gmail.com Sun Jul 10 13:41:28 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 10 Jul 2016 11:41:28 -0600 Subject: one command on backslash and space for review In-Reply-To: References: Message-ID: On Sun, Jul 10, 2016 at 9:19 AM, Ganesh Pal wrote: > Hello Team, > > I am on python 2.7 and Linux , I want to form the below sample > command so that I could run it on the shell. > > Command is --> run_parallel -za1 -s 'daemon -cf xyz; sleep 1' > > Here is how I formed the command and it seems to look fine and work > fine , but I think it could still be better any idea ? > >>>> cmd = "run_parallel -za" + str(number) + \ > ... " -s" + " \'daemon -cf xyz; sleep 1\'" cmd = "run_parallel -za{} -s 'daemon -cf xyz; sleep 1'".format(number) > Looking for thoughts around: > > 1. If backslash are syntactically correct They're correct, but using them before single quotes in a string delimited by double quotes is unnecessary. > 3. Iam running sleep command on the cluster i.e , how could I make it > look Python or its fine to have sleep ? I don't understand the question. From ganesh1pal at gmail.com Sun Jul 10 14:35:57 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Mon, 11 Jul 2016 00:05:57 +0530 Subject: one command on backslash and space for review In-Reply-To: References: Message-ID: On Jul 10, 2016 11:14 PM, "Ian Kelly" wrote: > They're correct, but using them before single quotes in a string > delimited by double quotes is unnecessary. Thanks . > > 3. Iam running sleep command on the cluster i.e , how could I make it > > look Python or its fine to have sleep ? > > I don't understand the question. > Sorry I was in sleep ?? I typed something wrong . Let me explain it. Better In the below command I.e 'run_parallel -za1 -s 'daemon -cf xyz; sleep 1' We have a sleep 1 that's run run as part of abovry shell command . It looks ok but is there a way to use something alternative to sleep was my question. I guess the answer is " no" , because we are executing shell sleep command I think something pythonic like time.sleep is not possible. From rosuav at gmail.com Sun Jul 10 14:45:38 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jul 2016 04:45:38 +1000 Subject: one command on backslash and space for review In-Reply-To: References: Message-ID: On Mon, Jul 11, 2016 at 4:35 AM, Ganesh Pal wrote: > 'run_parallel -za1 -s 'daemon -cf xyz; sleep 1' > > We have a sleep 1 that's run run as part of abovry shell command . It > looks ok but is there a way to use something alternative to sleep was my > question. I guess the answer is " no" , because we are executing shell > sleep command I think something pythonic like time.sleep is not possible. That would be correct. ChrisA From lawrencedo99 at gmail.com Sun Jul 10 20:34:27 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 10 Jul 2016 17:34:27 -0700 (PDT) Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> Message-ID: <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> On Sunday, July 10, 2016 at 7:22:42 PM UTC+12, Ian wrote: > On Sat, Jul 9, 2016 at 11:54 PM, Lawrence D?Oliveiro wrote: >> In printf-style formats, you can specify the number of digits for an >> integer separately from the field width. E.g. >> >> >>> "%#0.5x" % 0x123 >> '0x00123' >> > except perhaps that precision doesn't really make sense for integers > in the first place. Except that it does make sense, as I showed in my example. From rustompmody at gmail.com Sun Jul 10 23:07:13 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Jul 2016 20:07:13 -0700 (PDT) Subject: the best online course In-Reply-To: References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> <71cf6d09-d094-44cc-befc-c66ec35e4ff6@googlegroups.com> <57828099.4090703@stoneleaf.us> Message-ID: <594fb31b-cf34-4f25-8fb4-ec9679d197b2@googlegroups.com> On Sunday, July 10, 2016 at 10:36:39 PM UTC+5:30, Ethan Furman wrote: > On 07/10/2016 12:18 AM, Bob Martin wrote: > > in 762247 20160709 223746 Malik Rumi wrote: > > >> I want one of those "knuckle down and learn" classes. But even more than th= > >> at, I want a class with a real teacher who is available to answer questions= > >> and explain things. I've done a lot of books and online video, but there's= > >> usually no help. If I search around long enough, I can often find an answe= > >> r, but this is just way too fragmented for me. Where can I find classes lik= > >> e that - online - paid or free? Thanks. > > > > Having to work for your answer means you are more likely to remember it. > > True, but like most things there is a balance -- searching for hours for > an answer is frustrating and discouraging, and the thing most likely > remembered is not the answer the pain in finding it. Yes balance is key? Bruno Buchberger formulated the ?blackbox-whitebox principle? : ======================================= Although math software systems, in particular those based on advance symbolic computation techniques, are now heavily considered for improving and supporting math teaching all over the world, there is still a lot of confusion about their appropriate use in math teaching. There seems to exist an unbridgeable disagreement between those who believe that these systems must not be used in teaching in order not to "spoil the abilities of the students" and those who believe that, with the availability of these systems, teaching the mathematical techniques covered by theses systems is not any more necessary and , rather we should confine ourselves to teach how to use of these systems. For bridging this disagreement I introduced, in 1989, the "White-Box / Black-Box Principle" for the didactics of using symbolic computation systems in math teaching: I am advocating that, in the "white-box" phase of teaching a particular mathematical topic (i.e. the phase in which the topic is new to the students), the pertinent parts of the SC systems should not be used, while in the "black-box" phase (in which the students completely master the new topic), it is essential for modern teaching of math to use these systems. The principle is recursive because, what was "white-box" in a particular phase of teaching becomes "black-box" in a later stage and new topics become "white-box" that use earlier "black boxes" as building blocks. ==================================================== This was formulated in 1989 for computer algebra systems http://www.risc.jku.at/people/buchberger/white_box.html Today it applies across the board to anything, any field? Python is good for black-box ? us the ?batteries included? without worrying too much how they are made Scheme, assembly language, Turing machines etc are at the other end of the spectrum People wanting to learn should (IMHO) experience both sides From ethan at stoneleaf.us Mon Jul 11 00:29:24 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 10 Jul 2016 21:29:24 -0700 Subject: the best online course In-Reply-To: References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> <71cf6d09-d094-44cc-befc-c66ec35e4ff6@googlegroups.com> <57818428.7010604@stoneleaf.us> Message-ID: <578320A4.5000702@stoneleaf.us> On 07/09/2016 04:21 PM, Chris Angelico wrote: > Yes, I hear a lot about Udacity. Has anyone taken any of the pay-for > classes? Are the instructors helpful, skilled, etc? Did it seem like > good value for money? Yes. Yes, yes. Yes. :) -- ~Ethan~ From ganesh1pal at gmail.com Mon Jul 11 00:49:06 2016 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Mon, 11 Jul 2016 10:19:06 +0530 Subject: one command on backslash and space for review In-Reply-To: References: Message-ID: > > > > >>>> cmd = "run_parallel -za" + str(number) + \ > > ... " -s" + " \'daemon -cf xyz; sleep 1\'" > > cmd = "run_parallel -za{} -s 'daemon -cf xyz; sleep 1'".format(number) > > How will I format number to strings using .format ?? Example >>> str(num) '100' >>> cmd = "run_parallel -za{} -s 'daemon -cf xyz; sleep 1'".format(str(num)) >>> cmd "run_parallel -za100 -s 'daemon -cf xyz; sleep 1'?. Will Something like format(str(num)) work ? it working though Regards, Ganesh From ben+python at benfinney.id.au Mon Jul 11 01:09:14 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 11 Jul 2016 15:09:14 +1000 Subject: one command on backslash and space for review References: Message-ID: <85r3b0vk05.fsf@benfinney.id.au> Ganesh Pal writes: > How will I format number to strings using .format ?? To make best use of ?str.format?, read its documentation thoroughly . To format numbers to strings, you choose which representation you want; e.g. ?decimal integer?. Then, use the appropriate format syntax for that representation (in that case, the ?d? type specifier). > Example > > >>> str(num) That creates a new string object, by asking the integer object to return its string representation. That gives you no choice in the representation, which is the opposite of what you are asking for. > >>> cmd = "run_parallel -za{} -s 'daemon -cf xyz; sleep 1'".format(str(num)) The ?{}? format string takes all the defaults for that parameter. If you want to customise the format, choose the specification and put it inside the ?{? and ?}? characters. -- \ ?I know when I'm going to die, because my birth certificate has | `\ an expiration date.? ?Steven Wright | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Mon Jul 11 01:33:00 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jul 2016 15:33 +1000 Subject: the best online course References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> <71cf6d09-d094-44cc-befc-c66ec35e4ff6@googlegroups.com> <57828099.4090703@stoneleaf.us> <594fb31b-cf34-4f25-8fb4-ec9679d197b2@googlegroups.com> Message-ID: <57832f8e$0$2784$c3e8da3$76491128@news.astraweb.com> On Monday 11 July 2016 13:07, Rustom Mody wrote: > Python is good for black-box ? us the ?batteries included? without worrying > too much how they are made > Scheme, assembly language, Turing machines etc are at the other end of the > spectrum I would put it the other way. Python is excellent for "white boxes", because the syntax is extremely approachable, easy to read and comprehend. (Although you may wish to avoid some of the more complicated and hairy features if your emphasis is on learning.) It's famous for being "executable pseudo-code" and neither too concise nor too verbose, and lacks the syntactic cruft which can impede understanding (braces, type declarations), which makes it excellent for teaching about algorithms, etc. But for some tasks, at least, it may lack speed and efficiency to be a practical "black box". Scheme, assembly, C, Forth etc are excellent for black boxes, as they are extremely efficient languages, but not so approachable, readable and comprehensible. Turing machines are to be avoided except for academic proofs that a certain feature or language is equivalent to a Turing machine, in which case we know precisely how much power it has, computation-wise. Turing machines are neither efficient enough to be used as black boxes, nor comprehensible enough to be used for white boxes. Take Python's StringIO class. Would you rather *read* the Python version or the C version? Which would you rather *use*? -- Steve From steve+comp.lang.python at pearwood.info Mon Jul 11 01:43:28 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 11 Jul 2016 15:43:28 +1000 Subject: Visualising relationships between packages Message-ID: <57833203$0$1600$c3e8da3$5496439d@news.astraweb.com> https://kozikow.com/2016/07/10/visualizing-relationships-between-python-packages-2/ -- Steve From bob.martin at excite.com Mon Jul 11 07:05:51 2016 From: bob.martin at excite.com (Bob Martin) Date: Mon, 11 Jul 2016 07:05:51 BST Subject: the best online course References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> <71cf6d09-d094-44cc-befc-c66ec35e4ff6@googlegroups.com> <57828099.4090703@stoneleaf.us> <594fb31b-cf34-4f25-8fb4-ec9679d197b2@googlegroups.com> <57832f8e$0$2784$c3e8da3$76491128@news.astraweb.com> Message-ID: in 762282 20160711 063300 Steven D'Aprano wrote: >On Monday 11 July 2016 13:07, Rustom Mody wrote: > >> Python is good for black-box ??? us the ???batteries included??? without worrying >> too much how they are made >> Scheme, assembly language, Turing machines etc are at the other end of the >> spectrum > >I would put it the other way. > >Python is excellent for "white boxes", because the syntax is extremely >approachable, easy to read and comprehend. (Although you may wish to avoid some >of the more complicated and hairy features if your emphasis is on learning.) >It's famous for being "executable pseudo-code" and neither too concise nor too >verbose, and lacks the syntactic cruft which can impede understanding (braces, >type declarations), which makes it excellent for teaching about algorithms, >etc. But for some tasks, at least, it may lack speed and efficiency to be a >practical "black box". > >Scheme, assembly, C, Forth etc are excellent for black boxes, as they are >extremely efficient languages, but not so approachable, readable and >comprehensible. > >Turing machines are to be avoided except for academic proofs that a certain >feature or language is equivalent to a Turing machine, in which case we know >precisely how much power it has, computation-wise. Turing machines are neither >efficient enough to be used as black boxes, nor comprehensible enough to be >used for white boxes. > >Take Python's StringIO class. Would you rather *read* the Python version or the >C version? Which would you rather *use*? The Rexx version :-)) From rustompmody at gmail.com Mon Jul 11 02:40:50 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Jul 2016 23:40:50 -0700 (PDT) Subject: the best online course In-Reply-To: <57832f8e$0$2784$c3e8da3$76491128@news.astraweb.com> References: <4e82aa2a-cb3e-4aec-9148-f7aa4e97d9f7@googlegroups.com> <71cf6d09-d094-44cc-befc-c66ec35e4ff6@googlegroups.com> <57828099.4090703@stoneleaf.us> <594fb31b-cf34-4f25-8fb4-ec9679d197b2@googlegroups.com> <57832f8e$0$2784$c3e8da3$76491128@news.astraweb.com> Message-ID: <25fb60db-fd02-466a-9994-64c6c9183ff6@googlegroups.com> On Monday, July 11, 2016 at 11:03:37 AM UTC+5:30, Steven D'Aprano wrote: > On Monday 11 July 2016 13:07, Rustom Mody wrote: > > > Python is good for black-box ? us the ?batteries included? without worrying > > too much how they are made > > Scheme, assembly language, Turing machines etc are at the other end of the > > spectrum > > I would put it the other way. > > Python is excellent for "white boxes", because the syntax is extremely > approachable, easy to read and comprehend. (Although you may wish to avoid some > of the more complicated and hairy features if your emphasis is on learning.) > It's famous for being "executable pseudo-code" and neither too concise nor too > verbose, and lacks the syntactic cruft which can impede understanding (braces, > type declarations), which makes it excellent for teaching about algorithms, > etc. But for some tasks, at least, it may lack speed and efficiency to be a > practical "black box". > > Scheme, assembly, C, Forth etc are excellent for black boxes, as they are > extremely efficient languages, but not so approachable, readable and > comprehensible. > > Turing machines are to be avoided except for academic proofs that a certain > feature or language is equivalent to a Turing machine, in which case we know > precisely how much power it has, computation-wise. Turing machines are neither > efficient enough to be used as black boxes, nor comprehensible enough to be > used for white boxes. > > Take Python's StringIO class. Would you rather *read* the Python version or the > C version? Which would you rather *use*? Black box and White box are not mutually exclusive ? I think that is one basic point of Buchberger. So your examples are fine [Though I dunno what you mean by scheme is efficient] Here are some examples in the complementary sense Most used python web framework seems to be Django How much python does a Django programmer need to know? Want to play around with a symbolic algebra system? Install sympy and start off. How much python is needed? By contrast, polynomial addition/multiplication (in C) is a typical intermediate data structure project [You can slot python either way on this one] A lisp interpreter in lisp is one page/one hour http://www.paulgraham.com/mcilroy.html gcc in gcc is 15 million lines http://www.phoronix.com/scan.php?page=news_item&px=MTg3OTQ From m.gamberi at gmail.com Mon Jul 11 08:52:34 2016 From: m.gamberi at gmail.com (MG) Date: Mon, 11 Jul 2016 05:52:34 -0700 (PDT) Subject: Dynamic query in mongodb and variable Message-ID: Ciao, I have this function: def lockup_info(refer): info = [] amb = CONN.db.xxxx.find({"reference": refer} for a in amb: print a How can I pass this value { "$exists": False } and tell python to not consider it as a string? var = '{ "$exists": False }' lockup_info(var) The code above doesn't work. A variable so defined is considered a string. Thanks From rustompmody at gmail.com Mon Jul 11 08:55:41 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 11 Jul 2016 05:55:41 -0700 (PDT) Subject: Program outlining Message-ID: <09e4f82e-89b2-40b6-9ac1-95513b4719e8@googlegroups.com> Ive been trying to figure out the best outlining that emacs can give for programs. Outline-mode seems to be more for text than code Outshine mode inspired by above+org-mode seemed promising in that it seems to make org mode's wonderful TAB-behavior work for code. But I couldn?t get it to work So hideshow? But hideshow keystrokes are clumsy Even with the suggestions of http://stackoverflow.com/questions/791539/how-can-i-have-folds-for-c-java-in-emacs to do (add-hook 'c-mode-common-hook (lambda() (local-set-key (kbd "C-c ") 'hs-show-block) (local-set-key (kbd "C-c ") 'hs-hide-block) (local-set-key (kbd "C-c ") 'hs-hide-all) (local-set-key (kbd "C-c ") 'hs-show-all) (hs-minor-mode t))) its better than the builtin defaults but not nearly as neat as org's all-purpose TAB and Shift-TAB. Is it so hard to do org's TAB cycling ie hs-show-block and hs-hide-block on the same key in cycle? From lists at moritzneeb.de Mon Jul 11 08:55:56 2016 From: lists at moritzneeb.de (Moritz Neeb) Date: Mon, 11 Jul 2016 14:55:56 +0200 Subject: EuroPython 2016: Last day to get tickets at regular rate In-Reply-To: <577E065A.5050905@europython.eu> References: <577E065A.5050905@europython.eu> Message-ID: <8f839fc6-04cf-9535-400f-18c11662374a@moritzneeb.de> Actually this was not your last chance! I am offering one spare regular rate student ticket (120,-). Please contact me if interested. Cheers, Moritz On 07/07/2016 09:35 AM, M.-A. Lemburg wrote: > We will be switching to the on-desk rates for tickets tomorrow, so > today is your last chance to get tickets at the regular rate, which is > about 30% less than the on-desk rate: > > > EuroPython 2016 Registration > > *** https://ep2016.europython.eu/registration/ *** > > > > Day Passes > ---------- > > As in the past, we will also sell day passes at the conference venue. > > To make things more affordable especially for students and other > people who want to attend the Beginners? Day or the sprints, we have > split the day pass prices into ones valid from Monday-Friday for the > main conference days and ones for the weekend days. > > Day passes for the first Sunday (Beginners? Day) and the sprints > weekend (valid for the day when they are purchased): > > * Student weekend day pass: EUR 25.00 > * Personal weekend day pass: EUR 70.00 > * Business weekend day pass: EUR 110.00 > > Day passes for the main conference (valid for the day when they are > purchased): > > * Student conference day pass: EUR 50.00 > * Personal conference day pass: EUR 140.00 > * Business conference day pass: EUR 225.00 > > All prices include 10% Spanish VAT. Please see the registration page > for full details of what is included in the ticket price. > > > With gravitational regards, > -- > EuroPython 2016 Team > http://ep2016.europython.eu/ > http://www.europython-society.org/ > > > PS: Please forward or retweet to help us reach all interested parties: > https://twitter.com/europython/status/750955219975016448 > Thanks. > From rustompmody at gmail.com Mon Jul 11 08:56:50 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 11 Jul 2016 05:56:50 -0700 (PDT) Subject: Program outlining In-Reply-To: <09e4f82e-89b2-40b6-9ac1-95513b4719e8@googlegroups.com> References: <09e4f82e-89b2-40b6-9ac1-95513b4719e8@googlegroups.com> Message-ID: On Monday, July 11, 2016 at 6:26:01 PM UTC+5:30, Rustom Mody wrote: > Ive been trying to figure out the best outlining that emacs can give for > programs. Oops sorry! Wrong list!! From rosuav at gmail.com Mon Jul 11 09:01:18 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jul 2016 23:01:18 +1000 Subject: Dynamic query in mongodb and variable In-Reply-To: References: Message-ID: On Mon, Jul 11, 2016 at 10:52 PM, MG wrote: > Ciao, > I have this function: > > > def lockup_info(refer): > info = [] > amb = CONN.db.xxxx.find({"reference": refer} > for a in amb: > print a > > > > How can I pass this value { "$exists": False } and tell python to not consider it as a string? > > var = '{ "$exists": False }' > lockup_info(var) > > > > The code above doesn't work. A variable so defined is considered a string. What do you want it to be, if not a string? Do you want to pass a dictionary? Then do - just pass it in directly. (Side point: I think you mean "lookup_info", not "lockup_info".) ChrisA From ian.g.kelly at gmail.com Mon Jul 11 11:04:22 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2016 09:04:22 -0600 Subject: Curious Omission In New-Style Formats In-Reply-To: <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> Message-ID: On Sun, Jul 10, 2016 at 6:34 PM, Lawrence D?Oliveiro wrote: > On Sunday, July 10, 2016 at 7:22:42 PM UTC+12, Ian wrote: >> On Sat, Jul 9, 2016 at 11:54 PM, Lawrence D?Oliveiro wrote: >>> In printf-style formats, you can specify the number of digits for an >>> integer separately from the field width. E.g. >>> >>> >>> "%#0.5x" % 0x123 >>> '0x00123' >>> >> except perhaps that precision doesn't really make sense for integers >> in the first place. > > Except that it does make sense, as I showed in my example. Your example showed a 3-digit number being formatted with a requested precision of 5 digits. The way this was done was by left-padding the number with 0s until there were 5 digits, but still only 3 digits of precision. If you truly wanted to format the number with a precision of 5 digits, it would look like this: 0x123.00 It may happen to do what you want in the printf-style format, but calling the field "precision" is at best misleading, and there are other ways to accomplish the same result. > Well, str.format does not use the same syntax as printf. From steve at pearwood.info Mon Jul 11 12:28:13 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jul 2016 02:28:13 +1000 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> Message-ID: <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> On Tue, 12 Jul 2016 01:04 am, Ian Kelly wrote: > On Sun, Jul 10, 2016 at 6:34 PM, Lawrence D?Oliveiro > wrote: >> On Sunday, July 10, 2016 at 7:22:42 PM UTC+12, Ian wrote: >>> On Sat, Jul 9, 2016 at 11:54 PM, Lawrence D?Oliveiro wrote: >>>> In printf-style formats, you can specify the number of digits for an >>>> integer separately from the field width. E.g. >>>> >>>> >>> "%#0.5x" % 0x123 >>>> '0x00123' >>>> >>> except perhaps that precision doesn't really make sense for integers >>> in the first place. >> >> Except that it does make sense, as I showed in my example. > > Your example showed a 3-digit number being formatted with a requested > precision of 5 digits. The way this was done was by left-padding the > number with 0s until there were 5 digits, Right. > but still only 3 digits of precision. Er, what? I count *five* digits in "00123", not three. You seem to be assuming that "precision" can only refer to digits after the decimal place, but that's a dubious proposition. That might be the way printf interprets the precision for *floats*, but its not the way it interprets the precision for *ints*, and who is to say that one way is right and the other is wrong? > If you truly wanted to format the number with a precision > of 5 digits, it would look like this: > > 0x123.00 Er, no, because its an integer. Now, if I remember what I was told in my physics class circa 1985 correctly: 12345678 written with a precision of five digits is 12346000; 12345678 written with a precision of five decimal places is 12345678.00000. How should we extrapolate to the case where the precision *in digits* is greater than the number of digits available? Well, for the "decimal places" case, we add zeroes to the right. So for the digits case, we ought to add zeroes to the left, which brings us back to the printf usage: 123 with five digits of precision is "00123". And we can combine that with the overall length to pad the result with spaces as well. It seems to me that it would be reasonable to support this for format() too. > It may happen to do what you want in the printf-style format, but > calling the field "precision" is at best misleading, and there are > other ways to accomplish the same result. Naturally. So why bother to have .format() or % in the first place? There's always other ways to accomplish the same result. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jana1972 at centrum.cz Mon Jul 11 13:21:56 2016 From: jana1972 at centrum.cz (Jahn) Date: Mon, 11 Jul 2016 19:21:56 +0200 Subject: Touch screen development in Python Message-ID: <5783D5B4.28625.382C3B3B@jana1972.centrum.cz> Hi , Does anyone use Python for developping applications that work with a touch screen? --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From ethan at stoneleaf.us Mon Jul 11 13:24:15 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 11 Jul 2016 10:24:15 -0700 Subject: Curious Omission In New-Style Formats In-Reply-To: <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5783D63F.5040307@stoneleaf.us> On 07/11/2016 09:28 AM, Steven D'Aprano wrote: > On Tue, 12 Jul 2016 01:04 am, Ian Kelly wrote: > Er, what? I count *five* digits in "00123", not three. > > You seem to be assuming that "precision" can only refer to digits after the > decimal place, but that's a dubious proposition. I will readily admit to not having a maths degree, and so of course to me saying the integer 123 has a precision of 5, 10, or 99 digits seems like hogwash to me. But I'm always willing to learn. So please explain what 123 with a precision of five integer digits means, and what to do we gain by saying such a thing? -- ~Ethan~ From jonas.thornvall at gmail.com Mon Jul 11 13:52:08 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Mon, 11 Jul 2016 10:52:08 -0700 (PDT) Subject: Compression of random binary data Message-ID: What kind of statistic law or mathematical conjecture or is it even a physical law is violated by compression of random binary data? I only know that Shanon theorised it could not be done, but were there any proof? What is to say that you can not do it if the symbolic representation is richer than the symbolic represenatation of the dataset. Isn't it a fact that the set of squareroots actually depict numbers in a shorter way than their actual representation. Now the inpretator or program must know the rules. And i have very good rules to make it happen. From liik.joonas at gmail.com Mon Jul 11 14:09:18 2016 From: liik.joonas at gmail.com (Joonas Liik) Date: Mon, 11 Jul 2016 21:09:18 +0300 Subject: Compression of random binary data In-Reply-To: References: Message-ID: On 11 July 2016 at 20:52, wrote: > What kind of statistic law or mathematical conjecture or is it even a physical law is violated by compression of random binary data? > > I only know that Shanon theorised it could not be done, but were there any proof? Compression relies on some items in the dataset being more frequent than others, if you have some dataset that is completely random it would be hard to compress as most items have very similar number of occurrances. > What is to say that you can not do it if the symbolic representation is richer than the symbolic represenatation of the dataset. > > Isn't it a fact that the set of squareroots actually depict numbers in a shorter way than their actual representation. A square root may be smaller numerically than a number but it definitely is not smaller in terms of entropy. lets try to compress the number 2 for instance using square roots. sqrt(2) = 1.4142 the square root actually takes more space in this case even tho it is a smaller number. so having the square root would have negative compression in this case. with some rounding back and forth we can probably get around the fact that sqrt(2) would take an infinite amout of memory to accurately represent but that neccesarily means restricting the values we are possible of encoding. for sqrt(2) to not have worse space consumprion than the number 2 itself we basically have to trow away precision so sqrt(2) ~= 1 now i challenge you to get that 2 back out of that 1.. From best_lay at yahoo.com Mon Jul 11 14:13:42 2016 From: best_lay at yahoo.com (Wildman) Date: Mon, 11 Jul 2016 13:13:42 -0500 Subject: Touch screen development in Python References: <5783D5B4.28625.382C3B3B@jana1972.centrum.cz> Message-ID: On Mon, 11 Jul 2016 19:21:56 +0200, Jahn wrote: > Hi , > Does anyone use Python for developping applications that work with a touch screen? > http://www.technolabsz.com/2011/08/how-to-make-touch-screen-user-interface.html -- GNU/Linux user #557453 The cow died so I don't need your bull! From maillist at schwertberger.de Mon Jul 11 14:20:20 2016 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Mon, 11 Jul 2016 20:20:20 +0200 Subject: Touch screen development in Python In-Reply-To: <5783D5B4.28625.382C3B3B@jana1972.centrum.cz> References: <5783D5B4.28625.382C3B3B@jana1972.centrum.cz> Message-ID: <8a12f1bd-f0ee-70bb-01cc-59c6f239afb6@schwertberger.de> On 11.07.2016 19:21, Jahn wrote: > Does anyone use Python for developping applications that work with a touch screen? Yes. You should probably specify the platform and the type of applications that you're interested in. Mobiles (Android, iOS, Sailfish OS)? Windows 10 Tablets? Ubuntu Touch? Embedded systems? Regards, Dietmar From jonas.thornvall at gmail.com Mon Jul 11 14:24:20 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Mon, 11 Jul 2016 11:24:20 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: References: Message-ID: <16db74f7-020d-4358-bc6d-563c3dfc9447@googlegroups.com> Den m?ndag 11 juli 2016 kl. 20:09:39 UTC+2 skrev Waffle: > On 11 July 2016 at 20:52, wrote: > > What kind of statistic law or mathematical conjecture or is it even a physical law is violated by compression of random binary data? > > > > I only know that Shanon theorised it could not be done, but were there any proof? > > Compression relies on some items in the dataset being more frequent > than others, if you have some dataset that is completely random it > would be hard to compress as most items have very similar number of > occurrances. > > > What is to say that you can not do it if the symbolic representation is richer than the symbolic represenatation of the dataset. > > > > Isn't it a fact that the set of squareroots actually depict numbers in a shorter way than their actual representation. > > A square root may be smaller numerically than a number but it > definitely is not smaller in terms of entropy. > > lets try to compress the number 2 for instance using square roots. > sqrt(2) = 1.4142 > the square root actually takes more space in this case even tho it is > a smaller number. so having the square root would have negative > compression in this case. > with some rounding back and forth we can probably get around the fact > that sqrt(2) would take an infinite amout of memory to accurately > represent but that neccesarily means restricting the values we are > possible of encoding. > > for sqrt(2) to not have worse space consumprion than the number 2 > itself we basically have to trow away precision so sqrt(2) ~= 1 > now i challenge you to get that 2 back out of that 1.. Well who it to say different kind of numbers isn't treated differently, i mean all numbers isn't squares. All numbers isn't naturals. From python at mrabarnett.plus.com Mon Jul 11 14:30:39 2016 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 11 Jul 2016 19:30:39 +0100 Subject: Compression of random binary data In-Reply-To: References: Message-ID: <1b63ee29-8fa7-acbe-17b3-b4c8fa7abe8c@mrabarnett.plus.com> On 2016-07-11 18:52, jonas.thornvall at gmail.com wrote: > What kind of statistic law or mathematical conjecture or is it even a physical law is violated by compression of random binary data? > > I only know that Shanon theorised it could not be done, but were there any proof? > > What is to say that you can not do it if the symbolic representation is richer than the symbolic represenatation of the dataset. > > Isn't it a fact that the set of squareroots actually depict numbers in a shorter way than their actual representation. > > Now the inpretator or program must know the rules. And i have very good rules to make it happen. > If you want a challenge: The Enduring Challenge of Compressing Random Data http://www.drdobbs.com/architecture-and-design/the-enduring-challenge-of-compressing-ra/240049914 From jonas.thornvall at gmail.com Mon Jul 11 14:32:13 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Mon, 11 Jul 2016 11:32:13 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: <16db74f7-020d-4358-bc6d-563c3dfc9447@googlegroups.com> References: <16db74f7-020d-4358-bc6d-563c3dfc9447@googlegroups.com> Message-ID: <5e690bb1-340e-44f5-855c-27c7b66a0049@googlegroups.com> Den m?ndag 11 juli 2016 kl. 20:24:37 UTC+2 skrev jonas.t... at gmail.com: > Den m?ndag 11 juli 2016 kl. 20:09:39 UTC+2 skrev Waffle: > > On 11 July 2016 at 20:52, wrote: > > > What kind of statistic law or mathematical conjecture or is it even a physical law is violated by compression of random binary data? > > > > > > I only know that Shanon theorised it could not be done, but were there any proof? > > > > Compression relies on some items in the dataset being more frequent > > than others, if you have some dataset that is completely random it > > would be hard to compress as most items have very similar number of > > occurrances. > > > > > What is to say that you can not do it if the symbolic representation is richer than the symbolic represenatation of the dataset. > > > > > > Isn't it a fact that the set of squareroots actually depict numbers in a shorter way than their actual representation. > > > > A square root may be smaller numerically than a number but it > > definitely is not smaller in terms of entropy. > > > > lets try to compress the number 2 for instance using square roots. > > sqrt(2) = 1.4142 > > the square root actually takes more space in this case even tho it is > > a smaller number. so having the square root would have negative > > compression in this case. > > with some rounding back and forth we can probably get around the fact > > that sqrt(2) would take an infinite amout of memory to accurately > > represent but that neccesarily means restricting the values we are > > possible of encoding. > > > > for sqrt(2) to not have worse space consumprion than the number 2 > > itself we basically have to trow away precision so sqrt(2) ~= 1 > > now i challenge you to get that 2 back out of that 1.. > > Well who it to say different kind of numbers isn't treated differently, i mean all numbers isn't squares. All numbers isn't naturals. But it could be all numbers are foldable. Both the integer parts and the real parts.And be expressed by the folding differences. From steve at pearwood.info Mon Jul 11 14:38:27 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jul 2016 04:38:27 +1000 Subject: Compression of random binary data References: Message-ID: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> On Tue, 12 Jul 2016 03:52 am, jonas.thornvall at gmail.com wrote: > What kind of statistic law or mathematical conjecture or is it even a > physical law is violated by compression of random binary data? The pigeon hole principle. If you have 100 pigeon holes, and 101 pigeons, then clearly at least one pigeon hole must have two pigeons in it. To keep the numbers small and manageable, let's say we are going to compress one byte at a time. Now a byte has eight bits, so there are exactly 256 possible bytes: 0000 0000 0000 0001 0000 0010 ... 1111 1110 1111 1111 Now, suppose I claim that I can LOSSLESSLY (that is, reversibly) compress any random byte to just two bits. The lossless part is important: its not hard to compress random data by irreversibly throwing some of it away, and there's no violation there. So I claim that you can give me any random byte, I will compress it to just two bits: 00 01 10 11 and then be able to decompress it back again to give you the original byte once more. Obviously I'm trying to pull a fast one! There's no way I can do this. I can squeeze 256 pigeons into just four pigeon holes, but only by doubling them up. Suppose I compress these three bytes to 00: 0000 0000 0110 1001 1100 0110 Now when I go to uncompress 00, what should I return? There is no way for me to know which of the three was the original value. (If I'm cunning, I'll have sneakily stored some data *elsewhere*, say, in the file name, or in a database, so that you need this extra hidden data to uncompress the 00 back to a full byte. But then I'm not compressing eight bits down to two. I'm compressing eight bits down to two bits plus who-knows-how-many-bits of hidden data.) So the pigeon hole principle tells us one of two things: (1) If you compress random data, then it must be lossy; I can compress eight bits to two, but then I can't uncompress it back again, at least not without throwing away some data. (2) Or, if the compression is lossless, then some data must be expanded rather than compressed. If you pick data at random, some of it will be expanded. Suppose I have a compression algorithm that infallibly and reversibly compresses as follows: 0000 0000 <--> 00 0000 0001 <--> 01 0000 0010 <--> 10 0000 0011 <--> 11 That part is fine. But what will my algorithm do with the other 252 bytes? At *best* it will leave them untouched: 0000 0100 <--> 0000 0100 ... 1111 1111 <--> 1111 1111 which is no compression at all, but at worst it will actually expand them and make them bigger. (After all, it's likely that my compression format has at least a bit of overhead.) In practice, compression algorithms are designed to look for particular kinds of order or structure in the data, and compress that. That's fine for the sorts of non-random data we care about: pictures are rarely pictures of static, text files are rarely random collections of bits. But if you do throw a random set of bits at a lossless compression algorithm, it will at best not compress it at all, and at worst actually make the file bigger. > What is to say that you can not do it if the symbolic representation is > richer than the symbolic represenatation of the dataset. > > Isn't it a fact that the set of squareroots actually depict numbers in a > shorter way than their actual representation. Sure. But you need to know what ?2 means. It *represents* the number 1.41421356237... but doesn't compress it. There's nothing you can do to the symbol ?2 that will uncompress back to the infinite series of digits. All you can do is look it up somewhere to see what the digits are. > Now the inpretator or program must know the rules. And i have very good > rules to make it happen. Right. How much information is in the rules? More than you save with the "compression". Consider: 1.41421356237 compressed down to ?2, that's 13 characters down to 2. Great! But to *uncompress*, you need to store a rule: ?2=1.41421356237 and that's *sixteen* characters. So your "compression" is: original: 13 compressed to: 2 plus rule: 16 means you have "compressed" 13 characters to 18. Now, this is still worth doing if you need to repeat the ?2 many times, so long as you don't have to repeat the rule. That's useful. But it's not compression. It's more like keeping an index to a database, or a scrap of paper with the title of a book written on it: "See Lord Of The Rings, by J.R.R. Tolkien" That's a lot smaller than the actual book: eight words, instead of who knows how many tens of thousands. But you can't call it compression: you can't sit down with the scrap of paper *and nothing else* and uncompress it back to the entire LOTR trilogy. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ian.g.kelly at gmail.com Mon Jul 11 14:38:36 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2016 12:38:36 -0600 Subject: Curious Omission In New-Style Formats In-Reply-To: <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jul 11, 2016 at 10:28 AM, Steven D'Aprano wrote: > On Tue, 12 Jul 2016 01:04 am, Ian Kelly wrote: >> Your example showed a 3-digit number being formatted with a requested >> precision of 5 digits. The way this was done was by left-padding the >> number with 0s until there were 5 digits, > > Right. > >> but still only 3 digits of precision. > > Er, what? I count *five* digits in "00123", not three. > > You seem to be assuming that "precision" can only refer to digits after the > decimal place, but that's a dubious proposition. That might be the way > printf interprets the precision for *floats*, but its not the way it > interprets the precision for *ints*, and who is to say that one way is > right and the other is wrong? In what way do the leading zeroes in "00123" add to the precision of the number? 00123 is the same quantity as 123 and represents no more precise a measurement. Neither does 0000000123 for "ten" digits of precision. We could just keep adding zeroes ad nauseam and then claim that 123 has infinite precision. Clearly, that's wrong. >> If you truly wanted to format the number with a precision >> of 5 digits, it would look like this: >> >> 0x123.00 > > Er, no, because its an integer. Which is why if you actually want to do this, you should convert it to a decimal or a float first (of course, those don't support hexadecimal output, so if you actually want hexadecimal output *and* digits after the (hexa)decimal point, then I think you would just have to roll your own formatting at that point). >> It may happen to do what you want in the printf-style format, but >> calling the field "precision" is at best misleading, and there are >> other ways to accomplish the same result. > > Naturally. So why bother to have .format() or % in the first place? There's > always other ways to accomplish the same result. I think it's just a case of purity winning out over practicality. As I said before, I don't really know why the decision was made to not support or allow it. What I've written above was my best guess. From tjreedy at udel.edu Mon Jul 11 14:54:34 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Jul 2016 14:54:34 -0400 Subject: Curious Omission In New-Style Formats In-Reply-To: <5783D63F.5040307@stoneleaf.us> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> Message-ID: On 7/11/2016 1:24 PM, Ethan Furman wrote: > On 07/11/2016 09:28 AM, Steven D'Aprano wrote: >> On Tue, 12 Jul 2016 01:04 am, Ian Kelly wrote: > >> Er, what? I count *five* digits in "00123", not three. >> >> You seem to be assuming that "precision" can only refer to digits >> after the >> decimal place, but that's a dubious proposition. > > I will readily admit to not having a maths degree, and so of course to > me saying the integer 123 has a precision of 5, 10, or 99 digits seems > like hogwash to me. I do have an undergraduate degree in math and a career in statistics, and I cannot remember seen 'precision' used in relation to integers. So I would call it a 'non-standard extension' of the notion. > But I'm always willing to learn. So please explain what 123 with a > precision of five integer digits means, What it could mean is that we have an count selected from the range 00000 to 99999 inclusive. But what I just said is the usual way of saying that, as it does not limit the lower and upper limits to 0s and 9s. > and what to do we gain by saying such a thing? Confusion. Precision is usually used in reference to measurement, and while measurement is based on counting, it is not the same thing. If 123 is a count, then its precision is 1 count, not k digits. Or one could say that all digits are precise. What is ambiguous without context is whether counts with trailing 0s, like 120 or 100 are exact or rounded. 100, as a cound, could have a precision of 1, 2, or 3 (significant) digits. Context sometimes says things like 'to the nearest hundred thousand'. In any case, I think it an improvement to say that '0x00123' has a field width of 7 rather than a 'precision' of 5. >>> '{:#07x}'.format(0x123) # specifiy field width '0x00123' >>> "%#0.5x" % 0x123 # specify int precision '0x00123' Thus, my title for a post noting the same change might be "Upgrade in new-style formats". (format and If one want leading 0s, -- Terry Jan Reedy From nobody at nowhere.invalid Mon Jul 11 14:56:09 2016 From: nobody at nowhere.invalid (Nobody) Date: Mon, 11 Jul 2016 19:56:09 +0100 Subject: Compression of random binary data References: Message-ID: On Mon, 11 Jul 2016 10:52:08 -0700, jonas.thornvall wrote: > What kind of statistic law or mathematical conjecture or is it even a > physical law is violated by compression of random binary data? You can't create an invertable mapping between a set with 2^N elements (e.g. the set of all N-bit binary sequences) and any set with fewer than 2^N elements (e.g. the set of all M-bit binary sequences for M References: <1b63ee29-8fa7-acbe-17b3-b4c8fa7abe8c@mrabarnett.plus.com> Message-ID: <382a420e-f211-8897-10a7-817aa5da9760@mrabarnett.plus.com> On 2016-07-11 19:30, MRAB wrote: > On 2016-07-11 18:52, jonas.thornvall at gmail.com wrote: >> What kind of statistic law or mathematical conjecture or is it even a physical law is violated by compression of random binary data? >> >> I only know that Shanon theorised it could not be done, but were there any proof? >> >> What is to say that you can not do it if the symbolic representation is richer than the symbolic represenatation of the dataset. >> >> Isn't it a fact that the set of squareroots actually depict numbers in a shorter way than their actual representation. >> >> Now the inpretator or program must know the rules. And i have very good rules to make it happen. >> > If you want a challenge: > > The Enduring Challenge of Compressing Random Data > http://www.drdobbs.com/architecture-and-design/the-enduring-challenge-of-compressing-ra/240049914 > It turns out there's a newsgroup for compression, and they're used to getting claims about compressing random data. In fact, so much so that it's in their FAQ: comp.compression Frequently Asked Questions (part 1/3) Section - [9] Compression of random data (WEB, Gilbert and others) http://www.faqs.org/faqs/compression-faq/part1/section-8.html From ian.g.kelly at gmail.com Mon Jul 11 15:27:16 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2016 13:27:16 -0600 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> Message-ID: On Mon, Jul 11, 2016 at 12:54 PM, Terry Reedy wrote: > In any case, I think it an improvement to say that '0x00123' has a field > width of 7 rather than a 'precision' of 5. > >>>> '{:#07x}'.format(0x123) # specifiy field width > '0x00123' >>>> "%#0.5x" % 0x123 # specify int precision > '0x00123' It occurs to me now that this does create a challenge if the format is meant to support negative numbers as well: >>> '%#0.5x' % -0x123 '-0x00123' >>> '{:#07x}'.format(-0x123) '-0x0123' From tjreedy at udel.edu Mon Jul 11 15:31:46 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Jul 2016 15:31:46 -0400 Subject: Compression of random binary data In-Reply-To: References: Message-ID: On 7/11/2016 2:09 PM, Joonas Liik wrote: > On 11 July 2016 at 20:52, wrote: >> What kind of statistic law or mathematical conjecture or is it >> even a physical law is violated by compression of random binary >> data? Off-topic, but... It is unclear whether you mean 'random' in the technical sense of 'unpredictable' or the common sense that adds 'of equal probability'. Bell engineers discovered that physical communication channels have a finite information transmission capacity that could be formalized as bits per second. You should be able to find good articles on the web, and I suggest you read some. If every message could be compressed, than every message could be compressed to 0 or 1, which is absurd. >> I only know that Shanon [Shannon] theorised it could not be done, but were >> there any proof? Shannon meant random in the technical sense and explicitly considered unequal probabilities. Random bit streams with unequal probabilities *can* be compressed by recoding. > Compression relies on some items in the dataset being more frequent > than others, Perhaps better to say that compression relies on removing redundancy, *if there is any*. The two ideas are related. > if you have some dataset that is completely random it > would be hard to compress as most items have very similar number of > occurrances. Assuming equal bit probabilities. Uncorrelated bits of unequal probability results in blocks of whatever size having unequal probabilites and redundancy that can be removed by replacing blocks with coded blocks. Huffman encoding does this by replacing blocks of equal size with code blocks of unequal size, with the size related to the probability of the block replaced. -- Terry Jan Reedy From torriem at gmail.com Mon Jul 11 16:06:24 2016 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 Jul 2016 14:06:24 -0600 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> Message-ID: On 07/11/2016 01:27 PM, Ian Kelly wrote: > On Mon, Jul 11, 2016 at 12:54 PM, Terry Reedy wrote: >> In any case, I think it an improvement to say that '0x00123' has a field >> width of 7 rather than a 'precision' of 5. >> >>>>> '{:#07x}'.format(0x123) # specifiy field width >> '0x00123' >>>>> "%#0.5x" % 0x123 # specify int precision >> '0x00123' > > It occurs to me now that this does create a challenge if the format is > meant to support negative numbers as well: > >>>> '%#0.5x' % -0x123 > '-0x00123' >>>> '{:#07x}'.format(-0x123) > '-0x0123' I'm not sure I've ever seen a negative hex number in the wild. Usually when I view a number in hex I am wanting the raw representation. -0x123 with a width of 7 would be 0xFFEDD From random832 at fastmail.com Mon Jul 11 16:34:08 2016 From: random832 at fastmail.com (Random832) Date: Mon, 11 Jul 2016 16:34:08 -0400 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> Message-ID: <1468269248.274024.663251393.519A1DA6@webmail.messagingengine.com> On Mon, Jul 11, 2016, at 16:06, Michael Torrie wrote: > I'm not sure I've ever seen a negative hex number in the wild. Usually > when I view a number in hex I am wanting the raw representation. -0x123 > with a width of 7 would be 0xFFEDD There's nothing "raw" about python int objects. To get what you want, you need to do x & 0xfffff If you have "5" as a parameter, you can get the desired constant as (1 << x*4) - 1. From tjreedy at udel.edu Mon Jul 11 16:52:00 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Jul 2016 16:52:00 -0400 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> Message-ID: On 7/11/2016 3:27 PM, Ian Kelly wrote: > On Mon, Jul 11, 2016 at 12:54 PM, Terry Reedy wrote: >> In any case, I think it an improvement to say that '0x00123' has a field >> width of 7 rather than a 'precision' of 5. >> >>>>> '{:#07x}'.format(0x123) # specifiy field width >> '0x00123' >>>>> "%#0.5x" % 0x123 # specify int precision >> '0x00123' > > It occurs to me now that this does create a challenge if the format is > meant to support negative numbers as well: > >>>> '%#0.5x' % -0x123 > '-0x00123' This expands the field from 7 to 8 chars. In running text, this is alright. In formatted table columns, it is not. >>>> '{:#07x}'.format(-0x123) > '-0x0123' Multiple alternatives >>> '{: #08x} {: #08x}'.format(0x123, -0x123) ' 0x00123 -0x00123' >>> '{:+#08x} {:+#08x}'.format(0x123, -0x123) '+0x00123 -0x00123' >>> '{0:#0{1}x} {2:+#0{3}x}'.format(0x123, 7, -0x123, 8) '0x00123 -0x00123' >>> n1, n2, w = 0x123, -0x123, 7 >>> '{0:#0{1}x} {2:+#0{3}x}'.format(n1, w+(n1<0), n2, w+(n2<0)) '0x00123 -0x00123' In running text, I ight go with '+','-' prefix. -- Terry Jan Reedy From ben+python at benfinney.id.au Mon Jul 11 16:56:10 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 12 Jul 2016 06:56:10 +1000 Subject: What is precision of a number representation? (was: Curious Omission In New-Style Formats) References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> Message-ID: <8560sbvqqd.fsf_-_@benfinney.id.au> Ethan Furman writes: > I will readily admit to not having a maths degree, and so of course to > me saying the integer 123 has a precision of 5, 10, or 99 digits seems > like hogwash to me. Precision is not a property of the number. It is a property of the *representation* of that number. The representation ?1?10?? has a precision of one digit. The representation ?100? has a precision of three digits. The representation ?00100? has a precision of five digits. The representation ?100.00? also has a precision of five digits. Those can all represent the same number; or maybe some of them represent ?one hundred? and others represent ?one hundred and a millionth?. The representation is only an approximation of the actual number, and the precision tells us how fuzzy the approximation is. None of these say how *accurate* the representation is; if those are representations of the number ?seven thousand? they are not very accurate, while they might be passably accurate for the number ?one hundred and seventy?. > But I'm always willing to learn. So please explain what 123 with a > precision of five integer digits means, and what to do we gain by > saying such a thing? We gain clarity of speech: we distinguish the different aspects (how many digits of this representation are actually claimed to represent the number?) communicated by a representation. -- \ ?? no testimony can be admitted which is contrary to reason; | `\ reason is founded on the evidence of our senses.? ?Percy Bysshe | _o__) Shelley, _The Necessity of Atheism_, 1811 | Ben Finney From ethan at stoneleaf.us Mon Jul 11 17:22:03 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 11 Jul 2016 14:22:03 -0700 Subject: What is precision of a number representation? In-Reply-To: <8560sbvqqd.fsf_-_@benfinney.id.au> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> Message-ID: <57840DFB.4000108@stoneleaf.us> On 07/11/2016 01:56 PM, Ben Finney wrote: > Precision is not a property of the number. It is a property of the > *representation* of that number. > > The representation ?1?10?? has a precision of one digit. > The representation ?100? has a precision of three digits. > The representation ?00100? has a precision of five digits. > The representation ?100.00? also has a precision of five digits. Your first, second, and fourth example have zeroes to the right, and I understand them just fine. Your third example has zeroes to the left, and you haven't explained how 00100 is more precise than 100. I mean, if somebody told me that one hundred was closer to one hundred than it was to ten thousand I would have to say "D'oh!" > We gain clarity of speech: we distinguish the different aspects (how > many digits of this representation are actually claimed to represent the > number?) communicated by a representation. Nope, still not clear to me. :( -- ~Ethan~ From laurent.pointal at free.fr Mon Jul 11 17:30:52 2016 From: laurent.pointal at free.fr (Laurent Pointal) Date: Mon, 11 Jul 2016 23:30:52 +0200 Subject: Touch screen development in Python References: <5783D5B4.28625.382C3B3B@jana1972.centrum.cz> Message-ID: <5784100c$0$5421$426a74cc@news.free.fr> Jahn wrote: > Hi , > Does anyone use Python for developping applications that work with a > touch screen? You should take a look at Kivy: https://kivy.org/ A+ L.Pointal. From rosuav at gmail.com Mon Jul 11 17:51:23 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2016 07:51:23 +1000 Subject: What is precision of a number representation? (was: Curious Omission In New-Style Formats) In-Reply-To: <8560sbvqqd.fsf_-_@benfinney.id.au> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> Message-ID: On Tue, Jul 12, 2016 at 6:56 AM, Ben Finney wrote: > Precision is not a property of the number. It is a property of the > *representation* of that number. > > The representation ?1?10?? has a precision of one digit. > The representation ?100? has a precision of three digits. > The representation ?00100? has a precision of five digits. > The representation ?100.00? also has a precision of five digits. > > Those can all represent the same number; or maybe some of them represent > ?one hundred? and others represent ?one hundred and a millionth?. > Yep. Precision is also a property of a measurement, the same way that a unit is. If I pace out the length of the main corridor in my house, I might come up with a result of thirty meters. The number is "30"; the unit is "meters", the precision is two significant digits, and the accuracy depends on how good I am at pacing distance. This is why it's important to be able to record precisions of arbitrary numbers. If I then measure the width of this corridor with a laser, I could get an extremely precise answer - say, 2,147 millimeters, with a precision of four significant digits, and excellent accuracy. But if I multiply those numbers together to establish the floor area of the corridor, the result does NOT have four significant figures. It would be 64 square meters (not 64.41), and the accuracy would be pretty low (effectively, the *in*accuracies of both measurements get combined). But on the other hand, if you want to know whether your new fridge will fit, you could measure it with the same laser and come up with a figure of 1,973 mm (four sig fig), which would mean your clearance is 174mm (four sig fig). How do you record this? Is it 174.0? 0174? "174 with four significant figures"? ChrisA From ethan at stoneleaf.us Mon Jul 11 18:17:13 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 11 Jul 2016 15:17:13 -0700 Subject: What is precision of a number representation? In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> Message-ID: <57841AE9.3090508@stoneleaf.us> On 07/11/2016 02:51 PM, Chris Angelico wrote: > On Tue, Jul 12, 2016 at 6:56 AM, Ben Finney wrote: >> Precision is not a property of the number. It is a property of the >> *representation* of that number. >> >> The representation ?1?10?? has a precision of one digit. >> The representation ?100? has a precision of three digits. >> The representation ?00100? has a precision of five digits. >> The representation ?100.00? also has a precision of five digits. >> >> Those can all represent the same number; or maybe some of them represent >> ?one hundred? and others represent ?one hundred and a millionth?. >> > > Yep. Precision is also a property of a measurement, the same way that > a unit is. If I pace out the length of the main corridor in my house, > I might come up with a result of thirty meters. The number is "30"; > the unit is "meters", the precision is two significant digits, and the > accuracy depends on how good I am at pacing distance. > > This is why it's important to be able to record precisions of > arbitrary numbers. If I then measure the width of this corridor with a > laser, I could get an extremely precise answer - say, 2,147 > millimeters, with a precision of four significant digits, and > excellent accuracy. But if I multiply those numbers together to > establish the floor area of the corridor, the result does NOT have > four significant figures. It would be 64 square meters (not 64.41), > and the accuracy would be pretty low (effectively, the *in*accuracies > of both measurements get combined). But on the other hand, if you want > to know whether your new fridge will fit, you could measure it with > the same laser and come up with a figure of 1,973 mm (four sig fig), > which would mean your clearance is 174mm (four sig fig). How do you > record this? Is it 174.0? 0174? "174 with four significant figures"? 174.0, because those last tenths of a millimeter could be very important, while knowledge that there are no thousands of millimeters is already present. So, so far there is no explanation of why leading zeroes make a number more precise. -- ~Ethan~ From ben.usenet at bsb.me.uk Mon Jul 11 18:28:31 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Mon, 11 Jul 2016 23:28:31 +0100 Subject: What is precision of a number representation? References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> Message-ID: <87oa6324j4.fsf@bsb.me.uk> Ben Finney writes: > Ethan Furman writes: > >> I will readily admit to not having a maths degree, and so of course to >> me saying the integer 123 has a precision of 5, 10, or 99 digits seems >> like hogwash to me. > > Precision is not a property of the number. It is a property of the > *representation* of that number. > > The representation ?1?10?? has a precision of one digit. > The representation ?100? has a precision of three digits. > The representation ?00100? has a precision of five digits. > The representation ?100.00? also has a precision of five digits. What is your source for the third one? I've never seen the term used in this way so I'm curious about how widely it's used. (I disagree with the second one, too, but that's an old argument that does not need resurrecting.) > Those can all represent the same number; or maybe some of them represent > ?one hundred? and others represent ?one hundred and a millionth?. So 00100 represents the range [99.995, 100.005] just like 100.00? That's new to me. It is more than a Python thing? -- Ben. From ethan at stoneleaf.us Mon Jul 11 18:29:42 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 11 Jul 2016 15:29:42 -0700 Subject: What is precision of a number representation? In-Reply-To: <57841AE9.3090508@stoneleaf.us> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> <57841AE9.3090508@stoneleaf.us> Message-ID: <57841DD6.7030405@stoneleaf.us> On 07/11/2016 03:17 PM, Ethan Furman wrote: > So, so far there is no explanation of why leading zeroes make a number > more precise. An example of what I mean: 174 with a precision of 3 tells us that the tenths place could be any of 0-9, or, put another way, the actual number could be anywhere between 174.0 to 174.9 (or maybe 173.5 to 174.5). If we have 174 with four digits of precision, then the representation should be 174.0 and it's the hundreths we are unsure of. So my question is: if we write 174 when could the thousands /ever/ be anything besides 0? -- ~Ethan~ From jenfhaomndgfwutc at murmic.plus.com Mon Jul 11 19:14:52 2016 From: jenfhaomndgfwutc at murmic.plus.com (Jan Coombs) Date: Tue, 12 Jul 2016 00:14:52 +0100 Subject: What is precision of a number representation? (was: Curious Omission In New-Style Formats) References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> Message-ID: <20160712001452.4432d7d0@HP-6550b> On Tue, 12 Jul 2016 07:51:23 +1000 Chris Angelico wrote: [snip] > > Yep. Precision is also a property of a measurement, the same > way that a unit is. If I pace out the length of the main > corridor in my house, I might come up with a result of thirty > meters. The number is "30"; the unit is "meters", the > precision is two significant digits, and the accuracy depends > on how good I am at pacing distance. > > This is why it's important to be able to record precisions of > arbitrary numbers. If I then measure the width of this > corridor with a laser, I could get an extremely precise answer > - say, 2,147 millimeters, with a precision of four significant > digits, and excellent accuracy. But if I multiply those > numbers together to establish the floor area of the corridor, > the result does NOT have four significant figures. It would be > 64 square meters (not 64.41), and the accuracy would be pretty > low (effectively, the *in*accuracies of both measurements get > combined). But on the other hand, if you want to know whether > your new fridge will fit, you could measure it with the same > laser and come up with a figure of 1,973 mm (four sig fig), > which would mean your clearance is 174mm (four sig fig). How > do you record this? Is it 174.0? 0174? "174 with four > significant figures"? Thees all look good, but you may get into trouble if you trust a PC with them! If the language/PC uses floating point representation then it will assign a fixed number of bits for the fractional part, and this will be left aligned in all/most hardware. This fraction might be 52 bits long. Your example number has about 11 bits of precision. The floating point representation will then have ~40 bits appended which imply a precision which does not exist. Your program may still know that only 11 bits are significant, but the representation implies that 52 bits are significant, and provides no indication otherwise. Good news!: Unum is an alternate numeric representation that does indicate the precision of a number [1]. It also resolves other problems of current float representation. Bad news?:In doing so unums becomes incompatible with current hardware floating point engines. Jan Coombs -- [1] slides: http://sites.ieee.org/scv-cs/files/2013/03/Right-SizingPrecision1.pdf RichReport 54 minute interview: https://youtu.be/jN9L7TpMxeA From greg.ewing at canterbury.ac.nz Mon Jul 11 19:26:31 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 12 Jul 2016 11:26:31 +1200 Subject: Curious Omission In New-Style Formats In-Reply-To: <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: I seem to remember Guido stating once that a design principle of the new formatting system was for the part after the colon to be the same as what you would put in an equivalent %-format, to make it easy for people to switch between them. If that principle still stands, then this would seem to be a bug. -- Greg From greg.ewing at canterbury.ac.nz Mon Jul 11 19:47:44 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 12 Jul 2016 11:47:44 +1200 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> Message-ID: Ethan Furman wrote: > I will readily admit to not having a maths degree, and so of course to > me saying the integer 123 has a precision of 5, 10, or 99 digits seems > like hogwash to me. Seems to me insisting that the number after the dot be called "precision" in all cases is imposing a foolish consistency. There's a third thing that %-formats use it for as well: for a string it means the maximum number of characters to include. To my way of thinking, the format string just lets you specify uop to two numbers, the interpratation or wnich is up to toe format concerned. -- Greg From rosuav at gmail.com Mon Jul 11 19:57:44 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2016 09:57:44 +1000 Subject: What is precision of a number representation? (was: Curious Omission In New-Style Formats) In-Reply-To: <20160712001452.4432d7d0@HP-6550b> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> <20160712001452.4432d7d0@HP-6550b> Message-ID: On Tue, Jul 12, 2016 at 9:14 AM, Jan Coombs wrote: > Thees all look good, but you may get into trouble if you trust a > PC with them! > > If the language/PC uses floating point representation then it > will assign a fixed number of bits for the fractional part, and > this will be left aligned in all/most hardware. PCs don't necessarily use floating point. Just check out Python's own decimal.Decimal class, or roll your own if you need to. ChrisA From ethan at stoneleaf.us Mon Jul 11 20:24:24 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 11 Jul 2016 17:24:24 -0700 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> Message-ID: <578438B8.9020902@stoneleaf.us> On 07/11/2016 04:47 PM, Gregory Ewing wrote: > Ethan Furman wrote: >> I will readily admit to not having a maths degree, and so of course to >> me saying the integer 123 has a precision of 5, 10, or 99 digits seems >> like hogwash to me. > > Seems to me insisting that the number after the dot be > called "precision" in all cases is imposing a foolish > consistency. That isn't what I said. > To my way of thinking, the format string just lets you > specify up to two numbers, the interpretation or which > is up to to format concerned. Agreed. -- ~Ethan~ From michael.selik at gmail.com Mon Jul 11 20:36:32 2016 From: michael.selik at gmail.com (Michael Selik) Date: Tue, 12 Jul 2016 00:36:32 +0000 Subject: Compression of random binary data In-Reply-To: References: Message-ID: On Mon, Jul 11, 2016, 10:56 AM wrote: > What kind of statistic law or mathematical conjecture or is it even a > physical law is violated by compression of random binary data? > If you get lucky, you might be able to achieve very good compression. > http://dilbert.com/strip/2001-10-25 Or are you asking about an algorithm that reliably compresses random data by a fairly constant percent? > From ian.g.kelly at gmail.com Mon Jul 11 21:16:03 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Jul 2016 19:16:03 -0600 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> Message-ID: On Mon, Jul 11, 2016 at 5:47 PM, Gregory Ewing wrote: > Ethan Furman wrote: >> >> I will readily admit to not having a maths degree, and so of course to me >> saying the integer 123 has a precision of 5, 10, or 99 digits seems like >> hogwash to me. > > > Seems to me insisting that the number after the dot be > called "precision" in all cases is imposing a foolish > consistency. > > There's a third thing that %-formats use it for as well: > for a string it means the maximum number of characters > to include. > > To my way of thinking, the format string just lets you > specify uop to two numbers, the interpratation or wnich > is up to toe format concerned. The builtin types strive for consistency with each other and with printf-style formats, but ultimately the parsing of the format spec is entirely at the whim of the __format__ method of the type being formatted. You could make it a Turing-complete mini-language if you liked. py> class Foo: ... def __format__(self, spec): ... return str(eval(spec)(self)) ... py> '{:id}'.format(Foo()) '139869336090384' py> '{:repr}'.format(Foo()) '<__main__.Foo object at 0x7f35de17b7b8>' py> '{:lambda x: x == 42}'.format(Foo()) 'False' From rosuav at gmail.com Mon Jul 11 21:57:16 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2016 11:57:16 +1000 Subject: What is precision of a number representation? In-Reply-To: <57841AE9.3090508@stoneleaf.us> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> <57841AE9.3090508@stoneleaf.us> Message-ID: On Tue, Jul 12, 2016 at 8:17 AM, Ethan Furman wrote: >> This is why it's important to be able to record precisions of >> arbitrary numbers. If I then measure the width of this corridor with a >> laser, I could get an extremely precise answer - say, 2,147 >> millimeters, with a precision of four significant digits, and >> excellent accuracy. But if I multiply those numbers together to >> establish the floor area of the corridor, the result does NOT have >> four significant figures. It would be 64 square meters (not 64.41), >> and the accuracy would be pretty low (effectively, the *in*accuracies >> of both measurements get combined). But on the other hand, if you want >> to know whether your new fridge will fit, you could measure it with >> the same laser and come up with a figure of 1,973 mm (four sig fig), >> which would mean your clearance is 174mm (four sig fig). How do you >> record this? Is it 174.0? 0174? "174 with four significant figures"? > > > 174.0, because those last tenths of a millimeter could be very important, > while knowledge that there are no thousands of millimeters is already > present. > But I never measured it to tenths of a millimeter. The display on my laser measurer (I don't actually have one, by the way, so all this is complete fabrication for the sake of the example) displays integer millimeters, with an implicit "+/- 0.5 mm". ChrisA From lawrencedo99 at gmail.com Mon Jul 11 23:01:08 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 11 Jul 2016 20:01:08 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: References: Message-ID: On Tuesday, July 12, 2016 at 5:52:27 AM UTC+12, jonas.t... at gmail.com wrote: > What kind of statistic law or mathematical conjecture or is it even a > physical law is violated by compression of random binary data? Try compressing already-compressed data. Does that answer your question? From vek.m1234 at gmail.com Mon Jul 11 23:20:20 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Tue, 12 Jul 2016 08:50:20 +0530 Subject: subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window Message-ID: Script grabs some image data and runs imagemagick on it to extract some chinese. Then tesseract OCR to get the actual unicode. I then need to get it translated which also works and then display in XTerm using cat. I could cat << named_pipe but I was wondering if this was the only way? Could I juggle fd's instead? #!/usr/bin/python # -*- coding: utf-8 -*- import sys, time import shlex import codecs, subprocess import goslate from textblob.blob import TextBlob def cmd_exec(cmd, wait=True, shell=True): print cmd cmd_line = shlex.split(cmd) retobj = subprocess.Popen(cmd_line, shell, cwd='/tmp', stdin=subprocess.PIPE) if wait: retobj.wait() return retobj def get_text_and_process(skip=False): if skip: return cmd_exec('import /tmp/x.png') cmd_exec('convert /tmp/x.png -resize 200% /tmp/x.resize.png') cmd_exec('tesseract /tmp/x.resize.png /tmp/tao -l chi_sim') get_text_and_process(skip=True) fh = codecs.open('/tmp/tao.txt', encoding='utf-8') fd = cmd_exec('xterm -en utf-8 -geometry 50x20+0+0 -e /bin/bash -c "cat -"', shell=False, wait=False) fd.communicate('test\n') #how do i communicate with cat and not xterm sys.exit() #I EXIT HERE #This stuff doesn't run (but works) - sys.exit above for line in fh.readlines(): try: print >>fd.stdout, line.encode('utf-8') blob = TextBlob(line) print >>fd.stdout, blob.detect_language() print >>fd.stdin, blob.translate(to='en') except UnicodeDecodeError, TranslatorError: pass fh.close() From steve at pearwood.info Mon Jul 11 23:38:28 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jul 2016 13:38:28 +1000 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> On Tue, 12 Jul 2016 04:38 am, Ian Kelly wrote: > In what way do the leading zeroes in "00123" add to the precision of > the number? 00123 is the same quantity as 123 and represents no more > precise a measurement. You guys... next you're going to tell me that 1.23 and 1.2300 are the same quantity and represent no more precise a measurement :-) And keep adding zeroes 1.230000000... and claim infinite precision. That's not now "precision" works. Its true that *mathematically* leading zeroes don't change the number, but neither do trailing zeroes. Nevertheless, we *interpret* them as having meaning, as indicators of the precision of measurement in the mathematical sense. In a moment, I'm going to attempt to justify a reasonable meaning for leading zeroes. But that's actually not relevant. printf (and Python's % string operator) interprets the precision field in the mathematical sense for floats, but that's not the only sense possible. The word "precise" has a number of meanings, including: - exactness - accurate - strict conformity to a rule - politeness and nicety - the quality of being reproducible For integers, printf and % interpret the so-called "precision" field of the format string not as a measurement precision (number of decimal places), but as the number of digits to use (which is different from the total field width). For example: py> "%10.8x" % 123 ' 0000007b' How anyone can possibly claim this makes no sense is beyond me! Is the difference between "number of digits" and "number of decimal places" really so hard to grok? I think not. And it's clearly useful: with integers, particular if they represent fixed-size byte quantities, it is very common to use leading zeroes. To a programmer the hex values 7b, 007b and 0000007b have very different meanings: the first is a byte, the second may be a short int, and the third may be a long int. Why shouldn't we use the "precision" field for this? It doesn't mean what scientists mean by precision, but so what? That's not important. Scientists don't usually have to worry about leading zeroes, but programmers do, and its useful to distinguish between the *total* width (padded with spaces) and the *number* width (padded with zeroes). I think that printf and % get this right, and format() gets it wrong. [...] >>> If you truly wanted to format the number with a precision >>> of 5 digits, it would look like this: >>> >>> 0x123.00 >> >> Er, no, because its an integer. > > Which is why if you actually want to do this, you should convert it to > a decimal or a float first (of course, those don't support hexadecimal > output, so if you actually want hexadecimal output *and* digits after > the (hexa)decimal point, then I think you would just have to roll your > own formatting at that point). What? No no no. Didn't you even look at Lawrence's example? He doesn't want to format the number with decimal places at all. Converting an integer to a float just to use the precision field is just wrong. That's like saying that "1234".upper() doesn't make sense because digits don't have uppercase forms, and if you really want to convert "1234" to uppercase you should spell it out in words first: "onetwothreefour".upper() Earlier, I said that I would attempt to give a justification for leading zeroes in terms of measurement too. As I said, this is strictly irrelevant, but I thought it was interesting and so I'm going to share. You can stop reading now if you prefer. If you measure something with a metre ruler marked in centimetres, getting 1.23 metres, that's quite different from measuring it with a ruler marked in tenths of a millimetres and getting 1.2300. That's basic usage for precision in terms of number of decimal places and I'm sure we all agree about that. Now lets go the other way. How to you distinguish between a distance measured using an unmarked metre stick, giving us an answer of 123 metres, versus something measured with a 10km ruler(!) with one metre markings? Obviously with *leading* zeroes rather than trailing zeroes. If I lay out the one metre stick 123 times, then I write the measurement as 123. If I lay out my 10km ruler and note the position, I measure: zero tens of kilometres; zero kilometres; three hundreds-of-metres; two tens-of-metres; three metres; giving 00123 metres of course. Simple! Of course, it's rare that we do that. Why would we bother to distinguish the two situations? And who the hell has a 10km long measuring stick? If I'm a scientist, I'll probably write them both as 123m and not care about the size of the measuring stick, only about the smallest marking on it. At least for measuring straight-line distances, the size of the measuring stick generally doesn't matter. It *does* matter for measuring curves, but paradoxically the bigger the measuring stick (the more leading zeroes) the worse your measurement is likely to be. This is the problem of measuring coastlines and is related to fractal dimension. Suppose I lay my 10km long measuring stick along some piece of coastline, and measure it as 00123 metres. (It's a *thought experiment*, don't hassle me about the unfeasibly large stick. Divide everything by a thousand and call it a 10m stick marked in millimetres if you like.) Chances are that if I used a 1 metre measuring stick, and followed the contour of the coast more closely, I'd get a different number. So the more leading zeroes, the less accurate your measurement is likely to be. But interesting as this is, for most purposes either we're not measuring a curve, or we are but pretend we're not and ignore the fractal dimension. But as I said, none of this is strictly relevant to the question of interpreting the "precision" field of format strings as leading zeroes for integers. That has a common, standard interpretation as "number of digits" (as opposed to "number of decimal places") and is very useful. I maintain that format() has made a mistake by forbidding it. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ben+python at benfinney.id.au Mon Jul 11 23:41:50 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 12 Jul 2016 13:41:50 +1000 Subject: What is precision of a number representation? References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> <57840DFB.4000108@stoneleaf.us> Message-ID: <85y457ttdt.fsf@benfinney.id.au> Ethan Furman writes: > On 07/11/2016 01:56 PM, Ben Finney wrote: > > > Precision is not a property of the number. It is a property of the > > *representation* of that number. > > > > The representation ?1?10?? has a precision of one digit. > > The representation ?100? has a precision of three digits. > > The representation ?00100? has a precision of five digits. > > The representation ?100.00? also has a precision of five digits. > > [?] you haven't explained how 00100 is more precise than 100. I haven't made any claim about ?more precise? in the above. But if you want such claims, here are comparable representations in increasing order of precision: * ?0 ?10?? has one digit of precision. * ?0.0 ?10?? has two digits of precison. * ?0.01 ?10?? has three digits of precision. * ?0.010 ?10?? has four digits of precision. * ?0.0100 ?10?? has five digits of precision. * ?0.01000 ?10?? has six digits of precision. Again, these might all be representations of the same number or of different numbers; the representation claims only to represent a number within a range of tolerance. In decimal notation, some of the above can't be written with the same precision. I could invent a representation ? e.g. show ??? as a place-holder for a digit not within the precision level. In that system, the equivalent representations would be: * ?0????? * ?00???? * ?001??? * ?0010?? * ?00100? * ?00100.0? Each of these claims to represent a quantity beginning at the ten-thousands place, with increasing levels of precision in the claim. So the comparison that invites is to show where the range of tolerance for the representation ends. The fewer digits of precision, the less precise the representation claims to be. -- \ ?I find the whole business of religion profoundly interesting. | `\ But it does mystify me that otherwise intelligent people take | _o__) it seriously.? ?Douglas Adams | Ben Finney From tjreedy at udel.edu Tue Jul 12 00:14:42 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Jul 2016 00:14:42 -0400 Subject: What is precision of a number representation? In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> Message-ID: On 7/11/2016 5:51 PM, Chris Angelico wrote: > This is why it's important to be able to record precisions of > arbitrary numbers. If I then measure the width of this corridor with a > laser, I could get an extremely precise answer - say, 2,147 > millimeters, with a precision of four significant digits, and > excellent accuracy. But if I multiply those numbers together to > establish the floor area of the corridor, the result does NOT have > four significant figures. It would be 64 square meters (not 64.41), > and the accuracy would be pretty low (effectively, the *in*accuracies > of both measurements get combined). But on the other hand, if you want > to know whether your new fridge will fit, you could measure it with > the same laser and come up with a figure of 1,973 mm (four sig fig), > which would mean your clearance is 174mm (four sig fig). Wrong as to the last point. 2147 - 1973 = 174 has only 3 sig. figures. 2147 - 2144 = 3 has 1 significant figure. Subtraction of nearly equal numbers can cancel sig. figures. > How do you > record this? Is it 174.0? 0174? "174 with four significant figures"? None of these. -- Terry Jan Reedy From tjreedy at udel.edu Tue Jul 12 00:17:37 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Jul 2016 00:17:37 -0400 Subject: What is precision of a number representation? In-Reply-To: <57841AE9.3090508@stoneleaf.us> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> <57841AE9.3090508@stoneleaf.us> Message-ID: On 7/11/2016 6:17 PM, Ethan Furman wrote: > On 07/11/2016 02:51 PM, Chris Angelico wrote: >> This is why it's important to be able to record precisions of >> arbitrary numbers. If I then measure the width of this corridor with a >> laser, I could get an extremely precise answer - say, 2,147 >> millimeters, with a precision of four significant digits, and >> excellent accuracy. But if I multiply those numbers together to >> establish the floor area of the corridor, the result does NOT have >> four significant figures. It would be 64 square meters (not 64.41), >> and the accuracy would be pretty low (effectively, the *in*accuracies >> of both measurements get combined). But on the other hand, if you want >> to know whether your new fridge will fit, you could measure it with >> the same laser and come up with a figure of 1,973 mm (four sig fig), >> which would mean your clearance is 174mm (four sig fig). How do you >> record this? Is it 174.0? 0174? "174 with four significant figures"? > > 174.0, A common fallacy. There are only 3 significant figures because one, the first, was cancelled by subtracting close numbers. The same is true of adding numbers of opposite signs. -- Terry Jan Reedy From steve at pearwood.info Tue Jul 12 00:19:37 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jul 2016 14:19:37 +1000 Subject: What is precision of a number representation? (was: Curious Omission In New-Style Formats) References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> Message-ID: <57846fdb$0$1593$c3e8da3$5496439d@news.astraweb.com> On Tue, 12 Jul 2016 07:51 am, Chris Angelico wrote: > say, 2,147 > millimeters, with a precision of four significant digits How do you represent 1 mm to a precision of four significant digits, in such a way that it is distinguished from 1 mm to one significant digit, and 1 mm to a precision of four decimal places? 0001 1 1.0000 -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From no.email at nospam.invalid Tue Jul 12 00:29:10 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 11 Jul 2016 21:29:10 -0700 Subject: Touch screen development in Python References: <5783D5B4.28625.382C3B3B@jana1972.centrum.cz> Message-ID: <87twfveay1.fsf@jester.gateway.pace.com> "Jahn" writes: > Does anyone use Python for developping applications that work with a > touch screen? I've done it on a system where the touch screen events were treated the same way as mouse events. Coding works out about the same way. From rosuav at gmail.com Tue Jul 12 00:36:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jul 2016 14:36:46 +1000 Subject: What is precision of a number representation? (was: Curious Omission In New-Style Formats) In-Reply-To: <57846fdb$0$1593$c3e8da3$5496439d@news.astraweb.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> <57846fdb$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 12, 2016 at 2:19 PM, Steven D'Aprano wrote: > On Tue, 12 Jul 2016 07:51 am, Chris Angelico wrote: > >> say, 2,147 >> millimeters, with a precision of four significant digits > > > How do you represent 1 mm to a precision of four significant digits, in such > a way that it is distinguished from 1 mm to one significant digit, and 1 mm > to a precision of four decimal places? > > 0001 > 1 > 1.0000 Exactly my point. Granted, I mucked up my example (subtraction doesn't maintain sig figs - apologies, my bad), but there are other ways to end up with numbers close to zero with more sig figs than nonzero digits. ChrisA From nad at python.org Tue Jul 12 01:27:47 2016 From: nad at python.org (Ned Deily) Date: Tue, 12 Jul 2016 01:27:47 -0400 Subject: [RELEASE] Python 3.6.0a3 is now available Message-ID: <0E07A2EA-2F6A-4FD8-8C27-C0C2FBA8241B@python.org> On behalf of the Python development community and the Python 3.6 release team, I'm happy to announce the availability of Python 3.6.0a3. 3.6.0a3 is the third of four planned alpha releases of Python 3.6, the next major release of Python. During the alpha phase, Python 3.6 remains under heavy development: additional features will be added and existing features may be modified or deleted. Please keep in mind that this is a preview release and its use is not recommended for production environments. You can find Python 3.6.0a3 here: https://www.python.org/downloads/release/python-360a3/ The next release of Python 3.6 will be 3.6.0a4, currently scheduled for 2016-08-15. --Ned -- Ned Deily nad at python.org -- [] From steve+comp.lang.python at pearwood.info Tue Jul 12 02:21:38 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jul 2016 16:21:38 +1000 Subject: What is precision of a number representation? References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> <57841AE9.3090508@stoneleaf.us> Message-ID: <57848c74$0$11093$c3e8da3@news.astraweb.com> On Tuesday 12 July 2016 08:17, Ethan Furman wrote: > So, so far there is no explanation of why leading zeroes make a number > more precise. Obviously it doesn't, just as trailing zeroes doesn't make a number more precise. Precision in the sense used by scientists is a property of how the measurement was done, not of the number itself. We can arbitrarily add zeroes to the end of 0.5 until the cows come home, and its still just a half, no more, no less. But scientists have a useful convention that you can indicate the measurement precision by showing trailing zeroes: 0.5 is short-hand for 0.5 ? 0.05; 0.50 is short-hand for 0.5 ? 0.005; 0.5000 is short-hand for 0.5 ? 0.00005; etc. That's just a convention, although its a useful one. But its not the only useful convention: 01 is a byte with value 1; 0001 is a double-byte quantity (short int?) with value 1; 00000001 is a 32-bit quantity with value 1; etc. We say that these examples differ in their "number of digits" instead of "number of decimal places", so the difference doesn't quite map to the scientist's meaning of the word "precision". But why should we let that stop us from using the "precision" field of a format string to represent number of digits? If not, then what are the alternatives? Using str.format, how would you get the same output as this? py> "%8.4d" % 25 ' 0025' -- Steve From steve+comp.lang.python at pearwood.info Tue Jul 12 02:27:05 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jul 2016 16:27:05 +1000 Subject: subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window References: Message-ID: <57848dba$0$11093$c3e8da3@news.astraweb.com> On Tuesday 12 July 2016 13:20, Veek. M wrote: > Script grabs some image data and runs imagemagick on it to extract some > chinese. Then tesseract OCR to get the actual unicode. > > I then need to get it translated which also works and then display in > XTerm using cat. Why not just print it? Why do you have to use cat? That sounds like "Useless use of cat" to me: http://porkmail.org/era/unix/award.htmlhttp://porkmail.org/era/unix/award.html -- Steve From steve+comp.lang.python at pearwood.info Tue Jul 12 02:28:53 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jul 2016 16:28:53 +1000 Subject: subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window References: <57848dba$0$11093$c3e8da3@news.astraweb.com> Message-ID: <57848e26$0$11093$c3e8da3@news.astraweb.com> On Tuesday 12 July 2016 16:27, Steven D'Aprano wrote: > On Tuesday 12 July 2016 13:20, Veek. M wrote: > >> Script grabs some image data and runs imagemagick on it to extract some >> chinese. Then tesseract OCR to get the actual unicode. >> >> I then need to get it translated which also works and then display in >> XTerm using cat. > > Why not just print it? Why do you have to use cat? That sounds like "Useless > use of cat" to me: > > http://porkmail.org/era/unix/award.htmlhttp://porkmail.org/era/unix/award.html > Oopsm, accidentally doubled the URL. http://porkmail.org/era/unix/award.html -- Steve From ldompeling at casema.nl Tue Jul 12 04:00:28 2016 From: ldompeling at casema.nl (ldompeling at casema.nl) Date: Tue, 12 Jul 2016 01:00:28 -0700 (PDT) Subject: pocketsphinx no module named pocketsphinx found Message-ID: <6429f3e6-0ae8-4953-b4fb-33c4c45ff790@googlegroups.com> 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. From __peter__ at web.de Tue Jul 12 04:31:54 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Jul 2016 10:31:54 +0200 Subject: pocketsphinx no module named pocketsphinx found References: <6429f3e6-0ae8-4953-b4fb-33c4c45ff790@googlegroups.com> Message-ID: ldompeling at 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 install pocketsphinx successfully? If not, well, it should be obvious that you cannot import a package that is not installed. The pypi page lists the requirements: https://pypi.python.org/pypi/pocketsphinx Make sure that those for your system are fulfilled and then retry the install. If yes, did you create a module called pocketsphinx.py to try out the library? Then rename your own module and remove the corresponding pocketsphinx.pyc. From ldompeling at casema.nl Tue Jul 12 04:47:49 2016 From: ldompeling at casema.nl (ldompeling at casema.nl) Date: Tue, 12 Jul 2016 01:47:49 -0700 (PDT) Subject: pocketsphinx no module named pocketsphinx found In-Reply-To: <6429f3e6-0ae8-4953-b4fb-33c4c45ff790@googlegroups.com> References: <6429f3e6-0ae8-4953-b4fb-33c4c45ff790@googlegroups.com> Message-ID: Op dinsdag 12 juli 2016 10:00:51 UTC+2 schreef ldomp... at casema.nl: > 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. I think that pocketsphinx installed successfully because I install it on my raspberry pi with sudo-apt-get How can I create a module named pocketsphinx.py to try out the library. Thanks From steve+comp.lang.python at pearwood.info Tue Jul 12 05:07:05 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jul 2016 19:07:05 +1000 Subject: pocketsphinx no module named pocketsphinx found References: <6429f3e6-0ae8-4953-b4fb-33c4c45ff790@googlegroups.com> Message-ID: <5784b33a$0$2801$c3e8da3$76491128@news.astraweb.com> On Tuesday 12 July 2016 18:47, ldompeling at casema.nl wrote: > Op dinsdag 12 juli 2016 10:00:51 UTC+2 schreef ldomp... at casema.nl: >> 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. > > I think that pocketsphinx installed successfully because I install it on my > raspberry pi with sudo-apt-get Are you running two different versions of Python? If you are, then perhaps apt- get installed it for the system Python, but you're running a different version. If your Raspberry Pi is running "locate", you can run this: locate site-packages and it will show you all the third-party Python packages installed in the standard location. Can you see pocketsphinx? If not, then it is not installed. Once you are sure it is installed, try running these lines at the Python prompt, one at a time, and tell us exactly what happens: import pocketsphinx If there is no error, what does this give?0 print (pocketsphinx.__file__) (There are TWO underscores at the start and end of "file".) > How can I create a module named > pocketsphinx.py to try out the library. DON'T do that. You **do not** want to create a module called "pocketsphinx.py". If you have, that may be your problem. Call it something else, like "main.py" or "testps.py", or "mypocketsphinx.py". -- Steve From hemla21 at gmail.com Tue Jul 12 05:18:21 2016 From: hemla21 at gmail.com (Heli) Date: Tue, 12 Jul 2016 02:18:21 -0700 (PDT) Subject: Getting number of neighbours for a 3d numpy arrays Message-ID: Hi, 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 following neighbours : n1 with indices [i-1,j,k] if i>0 ; cell with i=0 does not have any n1 neighbour. (left neighbour) n2 with inidices [i+1,j,k] if i0 n4 with inidces [i,j+1,k] if j0 n6 with indices [i,j,k+1] if k0 : n1=myarray[i-1,j,k] if n1== True: n_neigh+=1 if i<248: n2=grains_3d[i+1,j,k] if n2== True: n_neigh_grains+=1 if j>0: n3=myarray[i,j-1,k] if n3== True: n_neigh+=1 if j<1247: n4=myarray[i,j+1,k] if n4== True: n_neigh+=1 if k>0 : n5=myarray[i,j,k-1] if n5== True: n_neigh+=1 if k<169: n6=myarray[i,j,k+1] if n6== True: n_neigh+=1 Is there anyway I can get an array containg all n1 neighbour, a second array containing all n2 neighbours and so on and then add n1 to n6 arrays element-wise to get all neighbours that meet certain conditions for a cell. Thanks in Advance for your help, From antoon.pardon at rece.vub.ac.be Tue Jul 12 05:50:27 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 12 Jul 2016 11:50:27 +0200 Subject: What is precision of a number representation? In-Reply-To: <57846fdb$0$1593$c3e8da3$5496439d@news.astraweb.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> <57846fdb$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5784BD63.20702@rece.vub.ac.be> Op 12-07-16 om 06:19 schreef Steven D'Aprano: > On Tue, 12 Jul 2016 07:51 am, Chris Angelico wrote: > >> say, 2,147 >> millimeters, with a precision of four significant digits > > How do you represent 1 mm to a precision of four significant digits, in such > a way that it is distinguished from 1 mm to one significant digit, and 1 mm > to a precision of four decimal places? > > 0001 > 1 > 1.0000 Your question doesn't has an answer because 1 mm doesn't have a precision of four significant digits. A precision is an indication of a fault tolerance. You don't indicate less fault tolerace by writing it as 0001. Please explain how 0001 represants a difference in precision than just 1. Writing 1.0000 instead of 1 can be understood as the actual number being between 0.99995 and 1.00005 instead of the actual number being between 0.95 and 1.05. Now between which two numbers is 0001 supposed to be? -- Antoon Pardon From marko at pacujo.net Tue Jul 12 06:27:27 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 12 Jul 2016 13:27:27 +0300 Subject: What is precision of a number representation? References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> <57846fdb$0$1593$c3e8da3$5496439d@news.astraweb.com> <5784BD63.20702@rece.vub.ac.be> Message-ID: <87furfducw.fsf@elektro.pacujo.net> Antoon Pardon : > Op 12-07-16 om 06:19 schreef Steven D'Aprano: >> How do you represent 1 mm to a precision of four significant digits, >> in such a way that it is distinguished from 1 mm to one significant >> digit, and 1 mm to a precision of four decimal places? > > Your question doesn't has an answer because 1 mm doesn't have a > precision of four significant digits. Your statement is invalid. You presuppose some notational conventions. 1?mm is simply one millimeter; in and of itself it doesn't in any way convey precision. > A precision is an indication of a fault tolerance. You don't indicate > less fault tolerace by writing it as 0001. I doubt a "fault" is relevant here. In ordinary usage, precision refers to a range of values, which is probably what you are getting at. > Please explain how 0001 represants a difference in precision than just > 1. "Precision" here is not ordinary usage. Historically, it comes from the printf(3) library function: Each conversion specification is introduced by the character %, and ends with a conversion specifier. In between there may be (in this order) zero or more flags, an optional minimum field width, an optional precision and an optional length modifier. [man 3 printf] Thus, "precision" is simply the name of a formatting field, regardless of the semantics of that field. The name was chosen because for floating point numbers, it actually refers to the precision of the numeric representation. However, the field has other uses that have nothing to do with precision: Precision [...] gives the minimum number of digits to appear for d, i, o, u, x, and X conversions, the number of digits to appear after the radix character for a, A, e, E, f, and F conversions, the maximum number of significant digits for g and G conversions, or the maximum number of characters to be printed from a string for s and S conversions. [man 3 printf] > Writing 1.0000 instead of 1 can be understood as the actual number > being between 0.99995 and 1.00005 instead of the actual number being > between 0.95 and 1.05. That certainly is a very common practice. > Now between which two numbers is 0001 supposed to be? What is your problem? What practical trouble is Python's format method giving you? Do you ever "turn on" a light or "roll down" a window by pushing a button? Do you "turn up" the volume by moving a slider? Why, do you ever "write" to a solid state "disk?" Marko From antoon.pardon at rece.vub.ac.be Tue Jul 12 07:02:38 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 12 Jul 2016 13:02:38 +0200 Subject: What is precision of a number representation? In-Reply-To: <87furfducw.fsf@elektro.pacujo.net> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> <57846fdb$0$1593$c3e8da3$5496439d@news.astraweb.com> <5784BD63.20702@rece.vub.ac.be> <87furfducw.fsf@elektro.pacujo.net> Message-ID: <5784CE4E.7040903@rece.vub.ac.be> Op 12-07-16 om 12:27 schreef Marko Rauhamaa: > Antoon Pardon : > >> Op 12-07-16 om 06:19 schreef Steven D'Aprano: >>> How do you represent 1 mm to a precision of four significant digits, >>> in such a way that it is distinguished from 1 mm to one significant >>> digit, and 1 mm to a precision of four decimal places? >> A precision is an indication of a fault tolerance. You don't indicate >> less fault tolerace by writing it as 0001. > >> Please explain how 0001 represants a difference in precision than just >> 1. > "Precision" here is not ordinary usage. Historically, it comes from the > printf(3) library function: Steven was talking about significant digits. So my use of precision was in that context. So I think your printf here is irrelevant. Talking about how your number is printed is different from talking about the significance of the digits. If you for whatever reason want to write 1 as 0001, be my guest. If you state that this somehow expresses a difference in significant digits, I would like someone to explain how. And yes I want that expressed in difference of fault or error tolerance, because that is what IMO significant digits refer to. > >> Now between which two numbers is 0001 supposed to be? > What is your problem? What practical trouble is Python's format method > giving you? This is not about Python's format. This is about someone stating a difference in significant digits. -- Antoon. From ldompeling at casema.nl Tue Jul 12 07:32:56 2016 From: ldompeling at casema.nl (ldompeling at casema.nl) Date: Tue, 12 Jul 2016 04:32:56 -0700 (PDT) Subject: pocketsphinx no module named pocketsphinx found In-Reply-To: <6429f3e6-0ae8-4953-b4fb-33c4c45ff790@googlegroups.com> References: <6429f3e6-0ae8-4953-b4fb-33c4c45ff790@googlegroups.com> Message-ID: Op dinsdag 12 juli 2016 10:00:51 UTC+2 schreef ldomp... at casema.nl: > 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. I had python version 2.6 3.0 3.4 installed and removed. I reinstall pocketsphinx python and now I don't get any errors while import from pocketsphinx. So I tried to run some python examples and now I get this error. I don't have a clue whats coing on. INFO: feat.c(715): Initializing feature stream to type: '1s_c_d_dd', ceplen=13, CMN='live', VARNORM='no', AGC='none' INFO: cmn.c(97): mean[0]= 12.00, mean[1..12]= 0.0 ERROR: "acmod.c", line 83: Folder 'pocketsphinx/model/en-us/en-us' does not contain acoustic model definition 'mdef' Traceback (most recent call last): File "example.py", line 15, in decoder = Decoder(config) File "/usr/local/lib/python2.7/dist-packages/pocketsphinx/pocketsphinx.py", line 271, in __init__ this = _pocketsphinx.new_Decoder(*args) RuntimeError: new_Decoder returned -1 From steve at pearwood.info Tue Jul 12 07:42:08 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 12 Jul 2016 21:42:08 +1000 Subject: pocketsphinx no module named pocketsphinx found References: <6429f3e6-0ae8-4953-b4fb-33c4c45ff790@googlegroups.com> Message-ID: <5784d793$0$1606$c3e8da3$5496439d@news.astraweb.com> On Tue, 12 Jul 2016 09:32 pm, ldompeling at casema.nl wrote: > I reinstall pocketsphinx python and now I don't get any errors while > import from pocketsphinx. So I tried to run some python examples and now I > get this error. I don't have a clue whats coing on. [...] > RuntimeError: new_Decoder returned -1 That's a pocketsphinx error. Try reading the docs, or asking on the pocketsphinx forums. You might be lucky and find somebody here who knows pocketsphinx, but your best chance will come from a specialist pocketsphinx forum. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From __peter__ at web.de Tue Jul 12 08:47:40 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 12 Jul 2016 14:47:40 +0200 Subject: Getting number of neighbours for a 3d numpy arrays References: Message-ID: 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 following neighbours : > > n1 with indices [i-1,j,k] if i>0 ; cell with i=0 does not have any n1 > neighbour. (left neighbour) I'm not a numpy expert, so the following may be less elegant than and not as efficient as possible; it may also be outright wrong ;) With that caveat: $ cat neighbours.py import numpy from collections import deque def print_int(a): print(numpy.array(a, dtype=int)) # generate sample data numpy.random.seed(42) SHAPE = (3, 3, 3) DIMENSIONS = len(SHAPE) # dimensions a = numpy.random.random(SHAPE) < .5 b = numpy.zeros(SHAPE, dtype=int) print("input data:") print_int(a) print("") # actual calculation full = slice(None, None, None) left = slice(None, -1, None) right = slice(1, None, None) ileft = deque([left] + [full] * (DIMENSIONS-1)) iright = deque([right] + [full] * (DIMENSIONS-1)) for i in range(DIMENSIONS): b[ileft] += a[iright] b[iright] += a[ileft] ileft.rotate() iright.rotate() print("number of neighbours:") print(b) $ python neighbours.py input data: [[[1 0 0] [0 1 1] [1 0 0]] [[0 1 0] [0 1 1] [1 1 0]] [[1 1 0] [1 1 1] [1 0 1]]] number of neighbours: [[[0 3 1] [3 2 2] [1 3 1]] [[3 2 2] [3 5 3] [3 2 3]] [[2 3 2] [3 4 3] [2 4 1]]] From nobody at nowhere.invalid Tue Jul 12 08:58:38 2016 From: nobody at nowhere.invalid (Nobody) Date: Tue, 12 Jul 2016 13:58:38 +0100 Subject: Getting number of neighbours for a 3d numpy arrays References: Message-ID: Some common ways to handle the boundary condition: 1. Generate clamped indices, test for validity and substitute invalid entries with an "identity" element. E.g. ijk = np.mgrid[:a,:b,:c] i,j,k = ijk i0,j0,k0 = np.maximum(0,ijk-1) i1,j1,k1 = np.minimum(np.array([[[[a,b,c]]]]).T-1,ijk+1) n1 = (i>0 ) & myarray[i0,j,k] n2 = (i0 ) & myarray[i,j0,k] n4 = (j0 ) & myarray[i,j,k0] n6 = (k0 ) & np.roll(myarray, 1,axis=0) n2 = (i0 ) & np.roll(myarray, 1,axis=1) n4 = (j0 ) & np.roll(myarray, 1,axis=2) n6 = (k <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> <57846fdb$0$1593$c3e8da3$5496439d@news.astraweb.com> <5784BD63.20702@rece.vub.ac.be> Message-ID: <5784edc7$0$1588$c3e8da3$5496439d@news.astraweb.com> On Tue, 12 Jul 2016 07:50 pm, Antoon Pardon wrote: > Op 12-07-16 om 06:19 schreef Steven D'Aprano: >> On Tue, 12 Jul 2016 07:51 am, Chris Angelico wrote: >> >>> say, 2,147 >>> millimeters, with a precision of four significant digits >> >> How do you represent 1 mm to a precision of four significant digits, in >> such a way that it is distinguished from 1 mm to one significant digit, >> and 1 mm to a precision of four decimal places? >> >> 0001 >> 1 >> 1.0000 > > Your question doesn't has an answer because 1 mm doesn't have a precision > of four significant digits. None of this argument has even the slightest relevance to the question of what the so-called "precision" field in a format string means with integer arguments. Regardless of any consensus, or lack thereof, about what a measurement precision of "four significant digits" might mean for a measurement of 1 unit, the meaning and usefulness of the precision field in format strings will remain. How do you get this result with format? py> "%8.4d" % 29 ' 0029' If you don't like my interpretation of leading zeroes, okay, I'm not going to defend it. It's really not that important. Perhaps after thinking about it more I'll also decide that it doesn't really make sense. When it comes to printf and the string % operator with integer types, the so-called "precision" field should not be understood as anything to do with measurement error. > A precision is an indication of a fault tolerance. You don't indicate less > fault tolerace by writing it as 0001. Measurement precision, as indicated by significant digits, doesn't have anything to do with fault tolerance. It tells you the estimated error in the measurement, not how much fault your application can withstand. "Fault tolerance" is a technical term that refers to the ability of a system, machine or device to continue working correctly even when parts of it have broken down. > Please explain how 0001 represants a difference in precision than just 1. The first is a 16-bit word; the second is a 4-bit nybble. Or, if the numbers are in decimal, perhaps the first comes from an old analogue speedometers, where there are four counters. This tells you that the largest possible number that we could count is 9999. The second in that case could come from a single analogue counter, in which case the largest number is 9. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From random832 at fastmail.com Tue Jul 12 09:36:27 2016 From: random832 at fastmail.com (Random832) Date: Tue, 12 Jul 2016 09:36:27 -0400 Subject: What is precision of a number representation? In-Reply-To: <57848c74$0$11093$c3e8da3@news.astraweb.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <5783D63F.5040307@stoneleaf.us> <8560sbvqqd.fsf_-_@benfinney.id.au> <57841AE9.3090508@stoneleaf.us> <57848c74$0$11093$c3e8da3@news.astraweb.com> Message-ID: <1468330587.480682.663966945.2D4D33CE@webmail.messagingengine.com> On Tue, Jul 12, 2016, at 02:21, Steven D'Aprano wrote: > If not, then what are the alternatives? Using str.format, how would > you get the same output as this? > > > py> "%8.4d" % 25 > ' 0025' " %04d" % 25 "%8s" % ("%04d" % 25) The latter (well, generally, "format it how you want and then use %*s to put it in fixed columns") is something that I've actually *done*, because it's easier to reason about. From random832 at fastmail.com Tue Jul 12 09:39:42 2016 From: random832 at fastmail.com (Random832) Date: Tue, 12 Jul 2016 09:39:42 -0400 Subject: subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window In-Reply-To: <57848dba$0$11093$c3e8da3@news.astraweb.com> References: <57848dba$0$11093$c3e8da3@news.astraweb.com> Message-ID: <1468330782.481118.663973601.0478DF11@webmail.messagingengine.com> On Tue, Jul 12, 2016, at 02:27, Steven D'Aprano wrote: > On Tuesday 12 July 2016 13:20, Veek. M wrote: > > I then need to get it translated which also works and then display in > > XTerm using cat. > > Why not just print it? Why do you have to use cat? Well, displaying something in a new xterm (i.e. not one that already exists and is your controlling terminal) without a process to run "in" the terminal is rather esoteric and isn't portable to terminals other than xterm. From vek.m1234 at gmail.com Tue Jul 12 10:13:32 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Tue, 12 Jul 2016 19:43:32 +0530 Subject: subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window References: <57848dba$0$11093$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Tuesday 12 July 2016 13:20, Veek. M wrote: > >> Script grabs some image data and runs imagemagick on it to extract >> some chinese. Then tesseract OCR to get the actual unicode. >> >> I then need to get it translated which also works and then display in >> XTerm using cat. > > Why not just print it? Why do you have to use cat? That sounds like > "Useless use of cat" to me: > > http://porkmail.org/era/unix/award.htmlhttp://porkmail.org/era/unix/award.html > Yeah, i changed that to 'tail -f' - works much better with tempfile. From jonas.thornvall at gmail.com Tue Jul 12 10:24:06 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Tue, 12 Jul 2016 07:24:06 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> Den m?ndag 11 juli 2016 kl. 20:38:51 UTC+2 skrev Steven D'Aprano: > On Tue, 12 Jul 2016 03:52 am, jonas.thornvall at gmail.com wrote: > > > What kind of statistic law or mathematical conjecture or is it even a > > physical law is violated by compression of random binary data? > > The pigeon hole principle. If you have 100 pigeon holes, and 101 pigeons, > then clearly at least one pigeon hole must have two pigeons in it. > > To keep the numbers small and manageable, let's say we are going to compress > one byte at a time. Now a byte has eight bits, so there are exactly 256 > possible bytes: > > 0000 0000 > 0000 0001 > 0000 0010 > ... > 1111 1110 > 1111 1111 > > Now, suppose I claim that I can LOSSLESSLY (that is, reversibly) compress > any random byte to just two bits. The lossless part is important: its not > hard to compress random data by irreversibly throwing some of it away, and > there's no violation there. > > So I claim that you can give me any random byte, I will compress it to just > two bits: > > 00 > 01 > 10 > 11 > > and then be able to decompress it back again to give you the original byte > once more. > > Obviously I'm trying to pull a fast one! There's no way I can do this. I can > squeeze 256 pigeons into just four pigeon holes, but only by doubling them > up. Suppose I compress these three bytes to 00: > > 0000 0000 > 0110 1001 > 1100 0110 > > Now when I go to uncompress 00, what should I return? There is no way for me > to know which of the three was the original value. > > (If I'm cunning, I'll have sneakily stored some data *elsewhere*, say, in > the file name, or in a database, so that you need this extra hidden data to > uncompress the 00 back to a full byte. But then I'm not compressing eight > bits down to two. I'm compressing eight bits down to two bits plus > who-knows-how-many-bits of hidden data.) > > So the pigeon hole principle tells us one of two things: > > (1) If you compress random data, then it must be lossy; I can compress eight > bits to two, but then I can't uncompress it back again, at least not > without throwing away some data. > > (2) Or, if the compression is lossless, then some data must be expanded > rather than compressed. If you pick data at random, some of it will be > expanded. > > Suppose I have a compression algorithm that infallibly and reversibly > compresses as follows: > > 0000 0000 <--> 00 > 0000 0001 <--> 01 > 0000 0010 <--> 10 > 0000 0011 <--> 11 > > That part is fine. But what will my algorithm do with the other 252 bytes? > At *best* it will leave them untouched: > > 0000 0100 <--> 0000 0100 > ... > 1111 1111 <--> 1111 1111 > > which is no compression at all, but at worst it will actually expand them > and make them bigger. (After all, it's likely that my compression format > has at least a bit of overhead.) > > In practice, compression algorithms are designed to look for particular > kinds of order or structure in the data, and compress that. That's fine for > the sorts of non-random data we care about: pictures are rarely pictures of > static, text files are rarely random collections of bits. But if you do > throw a random set of bits at a lossless compression algorithm, it will at > best not compress it at all, and at worst actually make the file bigger. > > > > What is to say that you can not do it if the symbolic representation is > > richer than the symbolic represenatation of the dataset. > > > > Isn't it a fact that the set of squareroots actually depict numbers in a > > shorter way than their actual representation. > > Sure. But you need to know what ?2 means. It *represents* the number > 1.41421356237... but doesn't compress it. There's nothing you can do to the > symbol ?2 that will uncompress back to the infinite series of digits. All > you can do is look it up somewhere to see what the digits are. > > > Now the inpretator or program must know the rules. And i have very good > > rules to make it happen. > > Right. How much information is in the rules? More than you save with > the "compression". Consider: > > 1.41421356237 compressed down to ?2, that's 13 characters down to 2. Great! > But to *uncompress*, you need to store a rule: > > ?2=1.41421356237 > > and that's *sixteen* characters. So your "compression" is: > > original: 13 > compressed to: 2 > plus rule: 16 > > means you have "compressed" 13 characters to 18. > > Now, this is still worth doing if you need to repeat the ?2 many times, so > long as you don't have to repeat the rule. That's useful. But it's not > compression. It's more like keeping an index to a database, or a scrap of > paper with the title of a book written on it: > > "See Lord Of The Rings, by J.R.R. Tolkien" > > That's a lot smaller than the actual book: eight words, instead of who knows > how many tens of thousands. But you can't call it compression: you can't > sit down with the scrap of paper *and nothing else* and uncompress it back > to the entire LOTR trilogy. > > > > > -- > Steven > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. But it seem your reasoning is based upon interpretation of the actual digits, bits and bytes value. There could be different interpretation worlds of course you would have to chose one using digits, An interpretationworld here could be reading out different word lengths of the dataset and maybe a lookup table. But it could also be arithmetic rules that magically recreate a number from a number of folds or difference of folds. From jonas.thornvall at gmail.com Tue Jul 12 10:29:07 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Tue, 12 Jul 2016 07:29:07 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: References: Message-ID: Den tisdag 12 juli 2016 kl. 05:01:20 UTC+2 skrev Lawrence D?Oliveiro: > On Tuesday, July 12, 2016 at 5:52:27 AM UTC+12, jonas.t... at gmail.com wrote: > > > What kind of statistic law or mathematical conjecture or is it even a > > physical law is violated by compression of random binary data? > > Try compressing already-compressed data. > > Does that answer your question? Yes that is my question, and also a claim i can do it. From vek.m1234 at gmail.com Tue Jul 12 10:31:25 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Tue, 12 Jul 2016 20:01:25 +0530 Subject: How do you guys tackle a package with poorish documentation? Message-ID: I've been messing with QQ (a Chinese chat app) and started receiving a lot of shady traffic partly because I was stupid enough to install the insecure QQ=international version. Anyway, so I decided to write something to provide me with a diff for networks. Basically track my current n/w with marginal shady traffic and then try to track what happens when I connect. scapy seems like the internet approved version for python but I installed: pypcap https://github.com/dugsong/pypcap import pcap for ts, pkt in pcap.pcap(): print ts, `pkt` which prints a timestamp and a pkt reference. Works great. Unfortunately I want what's in the packet and took a look at: pydoc pcap class pcap(__builtin__.object) | pcap(name=None, snaplen=65535, promisc=True, timeout_ms=None, immediate=False) -> packet capture object So, what's a 'packet capture object'? It's not in pydoc and I then wasted a lot of time looking for better docs hoping it'll be in a book or in an on-line tutorial, and that's when I encountered scapy. pypcap is and egg with a .so so how do you even do anything with it? My question is: how do you guys deal with a situation like this? Do you look through the source code? Do you switch to scapy? Do you now look for books on scapy - there are quite a few, with chapters covering it. A lot of my time goes to the dogs browsing for stuff so I was wondering if that's the norm? From steve at pearwood.info Tue Jul 12 11:11:39 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2016 01:11:39 +1000 Subject: Compression of random binary data References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> Message-ID: <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Jul 2016 12:24 am, jonas.thornvall at gmail.com wrote: > Den m?ndag 11 juli 2016 kl. 20:38:51 UTC+2 skrev Steven D'Aprano: >> On Tue, 12 Jul 2016 03:52 am, jonas.thornvall at gmail.com wrote: >> >> > What kind of statistic law or mathematical conjecture or is it even a >> > physical law is violated by compression of random binary data? >> >> The pigeon hole principle. If you have 100 pigeon holes, and 101 pigeons, >> then clearly at least one pigeon hole must have two pigeons in it. [...] > But it seem your reasoning is based upon interpretation of the actual > digits, bits and bytes value. Not at all. If you think that, you've misread my example. There's no interpretation of the bytes: they are just 8-bit numbers from 0 to 255. You cannot losslessly compress all 256 of them to just four 2-bit numbers. > There could be different interpretation > worlds of course you would have to chose one using digits, An > interpretationworld here could be reading out different word lengths of > the dataset and maybe a lookup table. Any lookup table you have counts as part of the compressed data. > But it could also be arithmetic rules that magically recreate a number > from a number of folds or difference of folds. Oh, sure, if you believe in magic, anything is possible. Just close your eyes, click your heels together, and wish really, really hard. Suppose I could compress ANY random data, no matter what, down to 10% of the original size. Okay, let's start with a million bits of data. Compress it down to 100,000 bits. But I believe that I can compress *anything*, any random collection of data. Okay, let me compress it again. Now I have 10,000 bits. Compress it again. Now I have 1,000 bits. Compress it again. Now I have 100 bits. Compress it again. Now I have 10 bits. Compress it again. Now I have 1 bit, either a 0 or a 1. Can you not see how absurd this is? I have claimed that I can take *any* random set of data, and by compressing it again and again and again, compress it down to ONE BIT, either a 0 or a 1, WITHOUT LOSS. Somehow I have to take that 0 bit and uncompress it back to the Complete Works Of William Shakespeare, and *also* uncompress it back to the recent Deadpool movie, AND uncompress it back to last year's Ant Man movie, AND uncompress it back to some funny picture of a cat. How can I possibly know which of the billions and billions of different files this 0 bit represents? If you pass me a 0 bit, and say "uncompress this", and I get The Lord Of The Rings novels, and then you pass me another 0 bit, and I uncompress it and get The Hobbit, well, how did I tell the two bits apart? They're both zero. The alternative is to say, it doesn't matter how clever you are, you can't compress *everything*. There are some things that simply won't compress. Eventually you get something no longer compresses. If you could compress EVERYTHING, then you could compress the compressed data, and compress the compressed-compressed data, and so on, until you've got only a single bit. And that is ridiculous. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Tue Jul 12 11:17:39 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2016 01:17:39 +1000 Subject: Compression of random binary data References: Message-ID: <57850a15$0$1584$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Jul 2016 12:29 am, jonas.thornvall at gmail.com wrote: > Den tisdag 12 juli 2016 kl. 05:01:20 UTC+2 skrev Lawrence D?Oliveiro: >> On Tuesday, July 12, 2016 at 5:52:27 AM UTC+12, jonas.t... at gmail.com >> wrote: >> >> > What kind of statistic law or mathematical conjecture or is it even a >> > physical law is violated by compression of random binary data? >> >> Try compressing already-compressed data. >> >> Does that answer your question? > > Yes that is my question, and also a claim i can do it. Can you also make a perpetual motion machine, square the circle, and find an exact rational fraction equal to pi? What gets me is the people who *say* that they can compress already compressed data. We know they can't, because if they could, they could compress it again and again and again and again until there was only a single bit, AND STILL REVERSE IT, using no external storage. Your lookup tables are part of the compressed data. If the "compressed file" plus the lookup table is bigger than the original file, then you haven't really compressed anything. You've just moved some of it from the file into a lookup table. So why do people claim that they can compress already compressed data? Who are they fooling? Themselves? -- Steve From egon.mueller1 at online.de Tue Jul 12 12:27:22 2016 From: egon.mueller1 at online.de (Egon Mueller) Date: Tue, 12 Jul 2016 18:27:22 +0200 Subject: how raspi-idle3 configure? Message-ID: Hello, is there a manual concerning the python3-ide on a raspberry / debian jessie? - The menue bar and the items there would I like to have a little bit greater for better readability. - After running a program is needed long search to return to editing window. - .... Where can read a beginner so simple things about handling the python 3 idle3? I don't think about python programming, only about better handling the ide. Thanks Egon From none at invalid.com Tue Jul 12 12:32:47 2016 From: none at invalid.com (mm0fmf) Date: Tue, 12 Jul 2016 17:32:47 +0100 Subject: Compression of random binary data In-Reply-To: References: Message-ID: On 12/07/2016 15:29, jonas.thornvall at gmail.com wrote: > Den tisdag 12 juli 2016 kl. 05:01:20 UTC+2 skrev Lawrence D?Oliveiro: >> On Tuesday, July 12, 2016 at 5:52:27 AM UTC+12, jonas.t... at gmail.com wrote: >> >>> What kind of statistic law or mathematical conjecture or is it even a >>> physical law is violated by compression of random binary data? >> >> Try compressing already-compressed data. >> >> Does that answer your question? > > Yes that is my question, and also a claim i can do it. > *plonk* From jonas.thornvall at gmail.com Tue Jul 12 13:35:16 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Tue, 12 Jul 2016 10:35:16 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: Den tisdag 12 juli 2016 kl. 17:12:01 UTC+2 skrev Steven D'Aprano: > On Wed, 13 Jul 2016 12:24 am, jonas.thornvall at gmail.com wrote: > > > Den m?ndag 11 juli 2016 kl. 20:38:51 UTC+2 skrev Steven D'Aprano: > >> On Tue, 12 Jul 2016 03:52 am, jonas.thornvall at gmail.com wrote: > >> > >> > What kind of statistic law or mathematical conjecture or is it even a > >> > physical law is violated by compression of random binary data? > >> > >> The pigeon hole principle. If you have 100 pigeon holes, and 101 pigeons, > >> then clearly at least one pigeon hole must have two pigeons in it. > [...] > > But it seem your reasoning is based upon interpretation of the actual > > digits, bits and bytes value. > > Not at all. If you think that, you've misread my example. There's no > interpretation of the bytes: they are just 8-bit numbers from 0 to 255. You > cannot losslessly compress all 256 of them to just four 2-bit numbers. > > > > There could be different interpretation > > worlds of course you would have to chose one using digits, An > > interpretationworld here could be reading out different word lengths of > > the dataset and maybe a lookup table. > > Any lookup table you have counts as part of the compressed data. > > > > But it could also be arithmetic rules that magically recreate a number > > from a number of folds or difference of folds. > > Oh, sure, if you believe in magic, anything is possible. Just close your > eyes, click your heels together, and wish really, really hard. > > Suppose I could compress ANY random data, no matter what, down to 10% of the > original size. Okay, let's start with a million bits of data. Compress it > down to 100,000 bits. > > But I believe that I can compress *anything*, any random collection of data. > Okay, let me compress it again. Now I have 10,000 bits. > > Compress it again. Now I have 1,000 bits. > > Compress it again. Now I have 100 bits. > > Compress it again. Now I have 10 bits. > > Compress it again. Now I have 1 bit, either a 0 or a 1. > > > Can you not see how absurd this is? I have claimed that I can take *any* > random set of data, and by compressing it again and again and again, > compress it down to ONE BIT, either a 0 or a 1, WITHOUT LOSS. Somehow I > have to take that 0 bit and uncompress it back to the Complete Works Of > William Shakespeare, and *also* uncompress it back to the recent Deadpool > movie, AND uncompress it back to last year's Ant Man movie, AND uncompress > it back to some funny picture of a cat. > > How can I possibly know which of the billions and billions of different > files this 0 bit represents? > > If you pass me a 0 bit, and say "uncompress this", and I get The Lord Of The > Rings novels, and then you pass me another 0 bit, and I uncompress it and > get The Hobbit, well, how did I tell the two bits apart? They're both zero. > > > > The alternative is to say, it doesn't matter how clever you are, you can't > compress *everything*. There are some things that simply won't compress. > Eventually you get something no longer compresses. If you could compress > EVERYTHING, then you could compress the compressed data, and compress the > compressed-compressed data, and so on, until you've got only a single bit. > And that is ridiculous. > > > > -- > Steven > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. No it is only compressible down to a limit given by the algorithm. From jonas.thornvall at gmail.com Tue Jul 12 13:46:29 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Tue, 12 Jul 2016 10:46:29 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: <57850a15$0$1584$c3e8da3$5496439d@news.astraweb.com> References: <57850a15$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: <63c6d9ed-8944-4882-83eb-f7f2ce725033@googlegroups.com> Den tisdag 12 juli 2016 kl. 17:19:54 UTC+2 skrev Steven D'Aprano: > On Wed, 13 Jul 2016 12:29 am, jonas.thornvall at gmail.com wrote: > > > Den tisdag 12 juli 2016 kl. 05:01:20 UTC+2 skrev Lawrence D?Oliveiro: > >> On Tuesday, July 12, 2016 at 5:52:27 AM UTC+12, jonas.t... at gmail.com > >> wrote: > >> > >> > What kind of statistic law or mathematical conjecture or is it even a > >> > physical law is violated by compression of random binary data? > >> > >> Try compressing already-compressed data. > >> > >> Does that answer your question? > > > > Yes that is my question, and also a claim i can do it. > > Can you also make a perpetual motion machine, square the circle, and find an > exact rational fraction equal to pi? > > > What gets me is the people who *say* that they can compress already > compressed data. We know they can't, because if they could, they could > compress it again and again and again and again until there was only a > single bit, AND STILL REVERSE IT, using no external storage. Your lookup > tables are part of the compressed data. If the "compressed file" plus the > lookup table is bigger than the original file, then you haven't really > compressed anything. You've just moved some of it from the file into a > lookup table. > > So why do people claim that they can compress already compressed data? Who > are they fooling? Themselves? > > > > -- > Steve Well the algorithm start with looking up a suitable folding structure "close enough to the number", then it works down the folding structure finding the fold where the difference or sum between the folds closest to zero. You do the same prinicple with the remainder until zero is achieved. So our first fold can either be bigger or smaller, and it seek a configuration for the fold that close in max on the actual random number. The second fold could be a fold that depending upon our first fold was bigger or smaller than number either will add or subtract lower layers of the fold. There will come out a difference that need to be folded, the process is repeated until there is nothing to fold. It is basicly a search algorithm looking for suitable folding structures. From torriem at gmail.com Tue Jul 12 14:20:21 2016 From: torriem at gmail.com (Michael Torrie) Date: Tue, 12 Jul 2016 12:20:21 -0600 Subject: Compression of random binary data In-Reply-To: <63c6d9ed-8944-4882-83eb-f7f2ce725033@googlegroups.com> References: <57850a15$0$1584$c3e8da3$5496439d@news.astraweb.com> <63c6d9ed-8944-4882-83eb-f7f2ce725033@googlegroups.com> Message-ID: On 07/12/2016 11:46 AM, jonas.thornvall at gmail.com wrote: > Well the algorithm start with looking up a suitable folding structure > "close enough to the number", then it works down the folding > structure finding the fold where the difference or sum between the > folds closest to zero. > > You do the same prinicple with the remainder until zero is achieved. > > So our first fold can either be bigger or smaller, and it seek a > configuration for the fold that close in max on the actual random > number. The second fold could be a fold that depending upon our first > fold was bigger or smaller than number either will add or subtract > lower layers of the fold. > > There will come out a difference that need to be folded, the process > is repeated until there is nothing to fold. > > It is basicly a search algorithm looking for suitable folding > structures. Better patent it quickly then. And you will win a noble prize for math if you could do what you say you could. From memilanuk at gmail.com Tue Jul 12 14:33:59 2016 From: memilanuk at gmail.com (memilanuk) Date: Tue, 12 Jul 2016 18:33:59 +0000 (UTC) Subject: how raspi-idle3 configure? References: Message-ID: Egon Mueller online.de> writes: > > Where can read a beginner so simple things about handling the python 3 > idle3? I don't think about python programming, only about better > handling the ide. > This link might be of some help... https://hkn.eecs.berkeley.edu/~DYOO/python/idle_intro/index.html HTH, Monte From ldompeling at casema.nl Tue Jul 12 14:35:21 2016 From: ldompeling at casema.nl (ldompeling at casema.nl) Date: Tue, 12 Jul 2016 11:35:21 -0700 (PDT) Subject: pocketsphinx no module named pocketsphinx found In-Reply-To: <6429f3e6-0ae8-4953-b4fb-33c4c45ff790@googlegroups.com> References: <6429f3e6-0ae8-4953-b4fb-33c4c45ff790@googlegroups.com> Message-ID: Op dinsdag 12 juli 2016 10:00:51 UTC+2 schreef ldomp... at casema.nl: > 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. I work it out with importing pocketsphinx and sphinxbase but I have an other error: Traceback (most recent call last): File "", line 1, in ImportError: No module named Decoder Is there a way to download the module Decoder somewhere? From jana1972 at centrum.cz Tue Jul 12 15:10:49 2016 From: jana1972 at centrum.cz (Jahn) Date: Tue, 12 Jul 2016 21:10:49 +0200 Subject: Touch screen development in Python In-Reply-To: <8a12f1bd-f0ee-70bb-01cc-59c6f239afb6@schwertberger.de> References: <5783D5B4.28625.382C3B3B@jana1972.centrum.cz>, <8a12f1bd-f0ee-70bb-01cc-59c6f239afb6@schwertberger.de> Message-ID: <578540B9.9086.3DB648E6@jana1972.centrum.cz> I was thinking about Python touch screen applications for industrial boards( computers). If I have a touch screen with that industrial board, what I must have installed to be able to write touch screen applications in Python? > On 11.07.2016 19:21, Jahn wrote: > > Does anyone use Python for developping applications that work with a touch screen? > > Yes. > > > You should probably specify the platform and the type of applications > that you're interested in. > > Mobiles (Android, iOS, Sailfish OS)? Windows 10 Tablets? Ubuntu Touch? > Embedded systems? > > > Regards, > > Dietmar > > -- > https://mail.python.org/mailman/listinfo/python-list --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From jonas.thornvall at gmail.com Tue Jul 12 15:31:48 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Tue, 12 Jul 2016 12:31:48 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: References: <57850a15$0$1584$c3e8da3$5496439d@news.astraweb.com> <63c6d9ed-8944-4882-83eb-f7f2ce725033@googlegroups.com> Message-ID: <754d562c-ca20-4845-8d2a-ea1c2da6835e@googlegroups.com> Den tisdag 12 juli 2016 kl. 20:20:52 UTC+2 skrev Michael Torrie: > On 07/12/2016 11:46 AM, jonas.thornvall at gmail.com wrote: > > Well the algorithm start with looking up a suitable folding structure > > "close enough to the number", then it works down the folding > > structure finding the fold where the difference or sum between the > > folds closest to zero. > > > > You do the same prinicple with the remainder until zero is achieved. > > > > So our first fold can either be bigger or smaller, and it seek a > > configuration for the fold that close in max on the actual random > > number. The second fold could be a fold that depending upon our first > > fold was bigger or smaller than number either will add or subtract > > lower layers of the fold. > > > > There will come out a difference that need to be folded, the process > > is repeated until there is nothing to fold. > > > > It is basicly a search algorithm looking for suitable folding > > structures. > > Better patent it quickly then. And you will win a noble prize for math > if you could do what you say you could. I doubt it i never got anyone before for my ideas. From jonas.thornvall at gmail.com Tue Jul 12 15:40:11 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Tue, 12 Jul 2016 12:40:11 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: References: <57850a15$0$1584$c3e8da3$5496439d@news.astraweb.com> <63c6d9ed-8944-4882-83eb-f7f2ce725033@googlegroups.com> Message-ID: <3585ccf1-3a02-422f-b37a-e34c2c0635d7@googlegroups.com> Den tisdag 12 juli 2016 kl. 20:20:52 UTC+2 skrev Michael Torrie: > On 07/12/2016 11:46 AM, jonas.thornvall at gmail.com wrote: > > Well the algorithm start with looking up a suitable folding structure > > "close enough to the number", then it works down the folding > > structure finding the fold where the difference or sum between the > > folds closest to zero. > > > > You do the same prinicple with the remainder until zero is achieved. > > > > So our first fold can either be bigger or smaller, and it seek a > > configuration for the fold that close in max on the actual random > > number. The second fold could be a fold that depending upon our first > > fold was bigger or smaller than number either will add or subtract > > lower layers of the fold. > > > > There will come out a difference that need to be folded, the process > > is repeated until there is nothing to fold. > > > > It is basicly a search algorithm looking for suitable folding > > structures. > > Better patent it quickly then. And you will win a noble prize for math > if you could do what you say you could. I must stress when i say number here i really mean +100000 decimal digit. So i basicly search in on big numbers that i compress. So i divide the dataset into suitable sizes for compression. From jonas.thornvall at gmail.com Tue Jul 12 15:42:44 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Tue, 12 Jul 2016 12:42:44 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: <3585ccf1-3a02-422f-b37a-e34c2c0635d7@googlegroups.com> References: <57850a15$0$1584$c3e8da3$5496439d@news.astraweb.com> <63c6d9ed-8944-4882-83eb-f7f2ce725033@googlegroups.com> <3585ccf1-3a02-422f-b37a-e34c2c0635d7@googlegroups.com> Message-ID: <2f61c17e-a3af-413e-a62b-6b7398306701@googlegroups.com> Den tisdag 12 juli 2016 kl. 21:40:36 UTC+2 skrev jonas.t... at gmail.com: > Den tisdag 12 juli 2016 kl. 20:20:52 UTC+2 skrev Michael Torrie: > > On 07/12/2016 11:46 AM, jonas.thornvall at gmail.com wrote: > > > Well the algorithm start with looking up a suitable folding structure > > > "close enough to the number", then it works down the folding > > > structure finding the fold where the difference or sum between the > > > folds closest to zero. > > > > > > You do the same prinicple with the remainder until zero is achieved. > > > > > > So our first fold can either be bigger or smaller, and it seek a > > > configuration for the fold that close in max on the actual random > > > number. The second fold could be a fold that depending upon our first > > > fold was bigger or smaller than number either will add or subtract > > > lower layers of the fold. > > > > > > There will come out a difference that need to be folded, the process > > > is repeated until there is nothing to fold. > > > > > > It is basicly a search algorithm looking for suitable folding > > > structures. > > > > Better patent it quickly then. And you will win a noble prize for math > > if you could do what you say you could. > > I must stress when i say number here i really mean +100000 decimal digit. So i basicly search in on big numbers that i compress. So i divide the dataset into suitable sizes for compression. And the dataset chunks that comes out from the process can also be treated like a new datafile, so the compression is iterative down to a limit. From maillist at schwertberger.de Tue Jul 12 16:22:31 2016 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Tue, 12 Jul 2016 22:22:31 +0200 Subject: Touch screen development in Python In-Reply-To: <578540B9.9086.3DB648E6@jana1972.centrum.cz> References: <5783D5B4.28625.382C3B3B@jana1972.centrum.cz> <8a12f1bd-f0ee-70bb-01cc-59c6f239afb6@schwertberger.de> <578540B9.9086.3DB648E6@jana1972.centrum.cz> Message-ID: On 12.07.2016 21:10, Jahn wrote: > I was thinking about Python touch screen applications for industrial boards( computers). > If I have a touch screen with that industrial board, what I must have installed to be able to > write touch screen applications in Python? This could be any platform: QNX, Android, Windows, Embedded Windows, Windows CE, Windows Mobile, Linux with X, Linux with Wayland, Linux command line and a display connected via SPI or whatever... If you don't write which platform you actually have, you will probably not get answers that will help you. Regards, Dietmar From lawrencedo99 at gmail.com Tue Jul 12 18:13:05 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 12 Jul 2016 15:13:05 -0700 (PDT) Subject: Quick poll: gmean or geometric_mean In-Reply-To: References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9c384acb-d5ce-4ba8-852e-3798aa51ca46@googlegroups.com> On Saturday, July 9, 2016 at 9:05:18 PM UTC+12, Peter Otten wrote: > Life's too short for abbreviations. Why is there no abbreviation for ?abbreviation?? Let me propose ?brev?. Nice and ... um ... abbreviated. From rosuav at gmail.com Tue Jul 12 18:17:49 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2016 08:17:49 +1000 Subject: Quick poll: gmean or geometric_mean In-Reply-To: <9c384acb-d5ce-4ba8-852e-3798aa51ca46@googlegroups.com> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <9c384acb-d5ce-4ba8-852e-3798aa51ca46@googlegroups.com> Message-ID: On Wed, Jul 13, 2016 at 8:13 AM, Lawrence D?Oliveiro wrote: > On Saturday, July 9, 2016 at 9:05:18 PM UTC+12, Peter Otten wrote: > >> Life's too short for abbreviations. > > Why is there no abbreviation for ?abbreviation?? > > Let me propose ?brev?. Nice and ... um ... abbreviated. abbr? ChrisA From lawrencedo99 at gmail.com Tue Jul 12 18:17:58 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 12 Jul 2016 15:17:58 -0700 (PDT) Subject: Quick poll: gmean or geometric_mean In-Reply-To: References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> <87r3b11qnq.fsf@elektro.pacujo.net> Message-ID: <998ee463-331b-4a1a-bc36-aa7e93a63945@googlegroups.com> On Monday, July 11, 2016 at 5:16:53 AM UTC+12, Ian wrote: > For local variables I usually wouldn't bother with the units, but in > general it's a good practice to help avoid crashing your orbiter into > Mars. The Mars Climate Orbiter fiasco wasn?t a problem with using the wrong units (dimensional analysis would have picked that up), but with using wrong unit _systems_. Ironic to see a country that fought a war to liberate itself from an empire, still stay so wedded to ?imperial? units... From lawrencedo99 at gmail.com Tue Jul 12 18:19:45 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 12 Jul 2016 15:19:45 -0700 (PDT) Subject: Quick poll: gmean or geometric_mean In-Reply-To: <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> Message-ID: <4c24cc86-dd87-4a7e-be7d-263ca457ffee@googlegroups.com> On Monday, July 11, 2016 at 2:30:00 AM UTC+12, Rustom Mody wrote: > Force is given by the negative of the universal_gravitational_constant times > the mass_of_first_body times mass_of_second_body divided by the square of > the distance_between_the_bodies > > Cobol anyone? Look at it this way: the ancients (Greeks, Babylonians etc) were doing their maths in the equivalent of Cobol. The reason why mathematicians invented short names for things was because it made the structure easier to see. Being able to easily manipulate that structure is key to solving mathematical problems. From ian.g.kelly at gmail.com Tue Jul 12 18:23:23 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 12 Jul 2016 16:23:23 -0600 Subject: Compression of random binary data In-Reply-To: References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 12, 2016 at 11:35 AM, wrote: > > No it is only compressible down to a limit given by the algorithm. Then your algorithm does not compress random data as you claimed. For some input, determine the limiting output that it ultimately compresses down to. Take that output and feed it through your algorithm as if it were the original input. If the data are to be considered random, then this input is just as probable as the original. What output does the algorithm now create? If it just returns the input unchanged, then how do you discern the original input from this input when decompressing? If it returns a different output of the same size, then repeat the process with the new output. Now there are *two* outputs of that size that can't be repeated. There are only finitely many possible outputs of that size, so eventually you're going to have to get to one that either repeats an output -- in which case your algorithm produces the same output for two different inputs and is therefore incorrect -- or you will get to an input that produces an output *larger* in size than the original. From alister.ware at ntlworld.com Tue Jul 12 18:57:52 2016 From: alister.ware at ntlworld.com (alister) Date: Tue, 12 Jul 2016 22:57:52 GMT Subject: Quick poll: gmean or geometric_mean References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> <87r3b11qnq.fsf@elektro.pacujo.net> <998ee463-331b-4a1a-bc36-aa7e93a63945@googlegroups.com> Message-ID: On Tue, 12 Jul 2016 15:17:58 -0700, Lawrence D?Oliveiro wrote: > On Monday, July 11, 2016 at 5:16:53 AM UTC+12, Ian wrote: > >> For local variables I usually wouldn't bother with the units, but in >> general it's a good practice to help avoid crashing your orbiter into >> Mars. > > The Mars Climate Orbiter fiasco wasn?t a problem with using the wrong > units (dimensional analysis would have picked that up), but with using > wrong unit _systems_. > > Ironic to see a country that fought a war to liberate itself from an > empire, still stay so wedded to ?imperial? units... The are not. a US gallon is smaller than an Imperial Gallon a US Mile is shorter than an Imperial mile and probably most importantly (because it means they keep serving me short measures) a US pint is smaller than an Imperial Pint -- Those who cannot remember the past are condemned to repeat it. -- George Santayana From ben+python at benfinney.id.au Tue Jul 12 19:25:04 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 13 Jul 2016 09:25:04 +1000 Subject: How do you guys tackle a package with poorish documentation? References: Message-ID: <85twfutp67.fsf@benfinney.id.au> "Veek. M" writes: > My question is: how do you guys deal with a situation like this? Do you > look through the source code? Do you switch to scapy? Do you now look > for books on scapy - there are quite a few, with chapters covering it. Once you realise that there is significantly less incentive *for the software maintainer* to spend the effort required in producing and maintaining and distributing high-quality documentation, you necessarily realise that someone must apply such an an incentive ? otherwise the job simply is not done. With that realisation, it becomes immediately clear who has such an incentive: newcomers to the library. Such as you and me. So, when working through an unfamiliar library, make it a habit to record the questions that are not immediately answered. Try to answer them and record those answers in the same place. Once you have enough understanding to know what works and what doesn't, you will inevitably have a set of questions that were raised by trying to learn the library, and were not answered in any obvious place. Take those, file bug reports, make suggested patches to improve the documentation. All this assumes the project is community-maintained. If you come across a library that is not community-maintained, walk away as soon as you realise it; the hope of improvement is much lower. > A lot of my time goes to the dogs browsing for stuff so I was > wondering if that's the norm? Until we make it the norm to *demand* better standards from each other, and provide the example of doing that work with and for each other: yes. -- \ ?A free press is one where it's okay to state the conclusion | `\ you're led to by the evidence.? ?Bill Moyers | _o__) | Ben Finney From jonas.thornvall at gmail.com Tue Jul 12 20:43:22 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Tue, 12 Jul 2016 17:43:22 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: Den onsdag 13 juli 2016 kl. 00:24:23 UTC+2 skrev Ian: > On Tue, Jul 12, 2016 at 11:35 AM, wrote: > > > > No it is only compressible down to a limit given by the algorithm. > > Then your algorithm does not compress random data as you claimed. > > For some input, determine the limiting output that it ultimately > compresses down to. Take that output and feed it through your > algorithm as if it were the original input. If the data are to be > considered random, then this input is just as probable as the > original. What output does the algorithm now create? If it just > returns the input unchanged, then how do you discern the original > input from this input when decompressing? If it returns a different > output of the same size, then repeat the process with the new output. > Now there are *two* outputs of that size that can't be repeated. There > are only finitely many possible outputs of that size, so eventually > you're going to have to get to one that either repeats an output -- in > which case your algorithm produces the same output for two different > inputs and is therefore incorrect -- or you will get to an input that > produces an output *larger* in size than the original. The dataset must have a certain size that is the only requirment, of course you can not compress something into nothing, at least the arithmetic ruleset need to be encoded but what would be the point to just compress something less than a couple of bytes. And of course the number of rounds you applied the algorithm must be stored. But that is no problem for small datasets. From jonas.thornvall at gmail.com Tue Jul 12 20:47:21 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Tue, 12 Jul 2016 17:47:21 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: Den onsdag 13 juli 2016 kl. 00:24:23 UTC+2 skrev Ian: > On Tue, Jul 12, 2016 at 11:35 AM, wrote: > > > > No it is only compressible down to a limit given by the algorithm. > > Then your algorithm does not compress random data as you claimed. > > For some input, determine the limiting output that it ultimately > compresses down to. Take that output and feed it through your > algorithm as if it were the original input. If the data are to be > considered random, then this input is just as probable as the > original. What output does the algorithm now create? If it just > returns the input unchanged, then how do you discern the original > input from this input when decompressing? If it returns a different > output of the same size, then repeat the process with the new output. > Now there are *two* outputs of that size that can't be repeated. There > are only finitely many possible outputs of that size, so eventually > you're going to have to get to one that either repeats an output -- in > which case your algorithm produces the same output for two different > inputs and is therefore incorrect -- or you will get to an input that > produces an output *larger* in size than the original. The later sounds reasonable that is start toggle between states. From lawrencedo99 at gmail.com Tue Jul 12 21:01:54 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 12 Jul 2016 18:01:54 -0700 (PDT) Subject: Announcing PyBidi Message-ID: <534f1409-6464-4def-8f83-158e264c8e93@googlegroups.com> Just thought I?d mention PyBidi , my Python 3 wrapper for all the functionality in FriBidi that I could usefully find, that I threw together over the weekend. I?m impressed that FriBidi doesn?t just do bidirectional logical-to-visual rearrangement, but it will also perform contextual substitutions for Arabic ligatures, which look (to my nonexpert eyes) like they might be good enough for day-to-day written text, without having to resort to HarfBuzz, or Pango, or sophisticated stuff like that. (Feel free to point out I?m wrong; the only language I have any familiarity with that uses, or used to use, Arabic script, is Malay written in the old ?Jawi? script.) From egon.mueller1 at online.de Tue Jul 12 21:15:28 2016 From: egon.mueller1 at online.de (Egon Mueller) Date: Wed, 13 Jul 2016 03:15:28 +0200 Subject: how raspi-idle3 configure? In-Reply-To: References: Message-ID: It is a little bit helpful and very interesting, but answers to my question isn't available. I have to search again. Am 12.07.2016 um 20:33 schrieb memilanuk: > Egon Mueller online.de> writes: >> >> Where can read a beginner so simple things about handling the python 3 >> idle3? I don't think about python programming, only about better >> handling the ide. >> > > This link might be of some help... > > https://hkn.eecs.berkeley.edu/~DYOO/python/idle_intro/index.html > > HTH, > > Monte > > From ben+python at benfinney.id.au Tue Jul 12 21:28:38 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 13 Jul 2016 11:28:38 +1000 Subject: Were is a great place to Share your finished projects? References: <857fd6uogt.fsf@benfinney.id.au> Message-ID: <85lh16tjg9.fsf@benfinney.id.au> Christian Gollwitzer writes: > Am 01.07.16 um 03:38 schrieb Ben Finney: > > If one wants to avoid vendor lock-in, Github is not best: the > > workflow tools (other than Git itself) are completely closed and not > > available for implementation on another vendor's servers. > > Yes, but that is relevant only if the workflow (i.e. pull requests) Pull requests. Code review. Issues. Integration with other services. All the social information around all of those interactions, and more. If *any* of that is valuable, then yes it's important that it not be locked to any one vendor. If *none* of that is valuable, then why prefer GitHub? Clearly people do find those quite valuable, and it is disingenuous to pretend that the code is the only valuable thing in a Github repository. -- \ ?The cost of a thing is the amount of what I call life which is | `\ required to be exchanged for it, immediately or in the long | _o__) run.? ?Henry David Thoreau | Ben Finney From lawrencedo99 at gmail.com Tue Jul 12 21:42:09 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 12 Jul 2016 18:42:09 -0700 (PDT) Subject: subprocess: xterm -c cat, need to send data to cat and have it displayed in the xterm window In-Reply-To: References: Message-ID: On Tuesday, July 12, 2016 at 3:20:35 PM UTC+12, Veek. M wrote: > I then need to get it translated which also works and then display in > XTerm using cat. From lawrencedo99 at gmail.com Tue Jul 12 21:42:44 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 12 Jul 2016 18:42:44 -0700 (PDT) Subject: Quick poll: gmean or geometric_mean In-Reply-To: References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> <87r3b11qnq.fsf@elektro.pacujo.net> <998ee463-331b-4a1a-bc36-aa7e93a63945@googlegroups.com> Message-ID: <766bf2f6-466f-4df9-ae85-ce09e2c8c130@googlegroups.com> On Wednesday, July 13, 2016 at 10:58:14 AM UTC+12, alister wrote: > a US gallon is smaller than an Imperial Gallon > a US Mile is shorter than an Imperial mile > and probably most importantly (because it means they keep serving me > short measures) a US pint is smaller than an Imperial Pint I thought everything was bigger in the USA... From gheskett at shentel.net Tue Jul 12 21:58:18 2016 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 12 Jul 2016 21:58:18 -0400 Subject: Quick poll: gmean or geometric_mean In-Reply-To: <766bf2f6-466f-4df9-ae85-ce09e2c8c130@googlegroups.com> References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <766bf2f6-466f-4df9-ae85-ce09e2c8c130@googlegroups.com> Message-ID: <201607122158.18223.gheskett@shentel.net> On Tuesday 12 July 2016 21:42:44 Lawrence D?Oliveiro wrote: > On Wednesday, July 13, 2016 at 10:58:14 AM UTC+12, alister wrote: > > a US gallon is smaller than an Imperial Gallon > > a US Mile is shorter than an Imperial mile > > and probably most importantly (because it means they keep serving me > > short measures) a US pint is smaller than an Imperial Pint > > I thought everything was bigger in the USA... Only the lies the pols tell us thru the mainsleaze media we loosely call news. And although Texas is indeed pretty good sized, they still use the std definition for a foot, mile or gallon. Been there, checked it out personally. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From steve at pearwood.info Tue Jul 12 22:25:25 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2016 12:25:25 +1000 Subject: Quick poll: gmean or geometric_mean References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> <87r3b11qnq.fsf@elektro.pacujo.net> <998ee463-331b-4a1a-bc36-aa7e93a63945@googlegroups.com> Message-ID: <5785a695$0$1614$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Jul 2016 08:57 am, alister wrote: > a US gallon is smaller than an Imperial Gallon > a US Mile is shorter than an Imperial mile > and probably most importantly (because it means they keep serving me > short measures) a US pint is smaller than an Imperial Pint That's okay, they charge you more to make up for it being smaller. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Tue Jul 12 22:29:35 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2016 12:29:35 +1000 Subject: Compression of random binary data References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5785a790$0$1619$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Jul 2016 03:35 am, jonas.thornvall at gmail.com wrote: > No it is only compressible down to a limit given by the algorithm. Right! Then there is data that you can't compress. Suppose you have some data: data = "ABABABABABAB...ABAB" And you compress it "down to a limit": x = compress(compress(compress(data))) print(x) => prints "@nx7%k!b" Now let's try again with something else: data = "AABBBCCCCDDDDEEEE...ZZZZ" And you compress it "down to a limit": x = compress(compress(compress(compress(data)))) print(x) => prints "wu*$cS#k-pv32zx[&+r" One more time: data = "AABBAABBAABBAABBAABB" x = compress(data) print(x) => prints "g^x3@" We agree on this. Now you say, "Give me some random data, anything at all, and I'll compress it!", and I run a random number generator and out pops: data = "@nx7%k!b" or possibly: data = "wu*$cS#k-pv32zx[&+r" or: data = "g^x3@" and I say "Compress that!" But we've already agreed that this is as compressed as you can possibly make it. You can't compress it any more. So there's *at least some* random data that you can't compress. Surely you have to accept that. You don't get to say "Oh, I don't mean *that* data, I mean only data that I can compress". Random data means its random, you don't get to pick and choose between data you can compress and data that you can't. Now the tricky part is to realise that its not just short sequences of random data that can't be compressed. The same applies for LONG sequences to. If I give you a gigabyte of raw video, you can probably compress that a fair bit. That's what things like x264 encoders do. The x265 encoder is even better. But they're lossy, so you can't reverse them. But if I give you a gigabyte of random data, you'll be lucky to find *any* patterns or redundancies that allow compression. You might be able to shrink the file by a few KB. And if you take that already compressed file, and try to compress it again, well, you've already hit the limit of compression. There no more redundancy left to remove. It doesn't matter how clever you are, or what a "folding structure" is, or how many times you iterate over the data. It's a matter of absolute simplicity: the pigeonhole principle. You can't argue with the numbers. If you start with a 100 digit decimal number, there are 10**100 different pigeons. If you can compress down to a 6 digit decimal number, there are 10**6 pigeon holes. You cannot put 10*100 pigeons into 10**6 pigeon holes without doubling up (which makes your compression lossly). So either some numbers cannot be compressed, or some numbers are compressed to the same result, and you can't tell which was the original. That's your choice: a lossless encoder means some numbers can't be compressed, a lossy encoder means you can't reverse the process exactly. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Tue Jul 12 23:39:24 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2016 13:39:24 +1000 Subject: Were is a great place to Share your finished projects? In-Reply-To: <85lh16tjg9.fsf@benfinney.id.au> References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> Message-ID: On Wed, Jul 13, 2016 at 11:28 AM, Ben Finney wrote: > Pull requests. Code review. Issues. Integration with other services. All > the social information around all of those interactions, and more. > > If *any* of that is valuable, then yes it's important that it not be > locked to any one vendor. Exactly how important? Not so important as to stop slabs of Python from migrating to GitHub, including its pull request system. (Work in progress; currently, PEPs are on GitHub, but the core interpreter hasn't moved yet. See PEP 512.) ChrisA From ben+python at benfinney.id.au Wed Jul 13 00:42:36 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 13 Jul 2016 14:42:36 +1000 Subject: Were is a great place to Share your finished projects? References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> Message-ID: <85h9butagz.fsf@benfinney.id.au> Chris Angelico writes: > On Wed, Jul 13, 2016 at 11:28 AM, Ben Finney wrote: > > Pull requests. Code review. Issues. Integration with other services. > > All the social information around all of those interactions, and > > more. > > > > If *any* of that is valuable, then yes it's important that it not be > > locked to any one vendor. > > Exactly how important? Not so important as to stop slabs of Python > from migrating to GitHub, including its pull request system. I maintain that it is important enough to stop that. The migration happened anyway, because not everyone is convinced of the importance of avoiding vendor lock-in of valuable data, over criteria such as ?this person happens to like Vendor-locked Solution Foo?. There are other projects considering such a migration; I am hopeful they can still be reasoned with. -- \ ?Begin with false premises and you risk reaching false | `\ conclusions. Begin with falsified premises and you forfeit your | _o__) authority.? ?Kathryn Schulz, 2015-10-19 | Ben Finney From rosuav at gmail.com Wed Jul 13 01:11:27 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2016 15:11:27 +1000 Subject: Were is a great place to Share your finished projects? In-Reply-To: <85h9butagz.fsf@benfinney.id.au> References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> Message-ID: On Wed, Jul 13, 2016 at 2:42 PM, Ben Finney wrote: > Chris Angelico writes: > >> On Wed, Jul 13, 2016 at 11:28 AM, Ben Finney wrote: >> > Pull requests. Code review. Issues. Integration with other services. >> > All the social information around all of those interactions, and >> > more. >> > >> > If *any* of that is valuable, then yes it's important that it not be >> > locked to any one vendor. >> >> Exactly how important? Not so important as to stop slabs of Python >> from migrating to GitHub, including its pull request system. > > I maintain that it is important enough to stop that. > > The migration happened anyway, because not everyone is convinced of the > importance of avoiding vendor lock-in of valuable data, over criteria > such as ?this person happens to like Vendor-locked Solution Foo?. > Fine. You're welcome to take a 100% philosophical stance; I applaud you for it. (I understand Richard Stallman is so adamant about not using *any* non-free code - software or firmware - that he restricts himself to a tiny selection of laptops that have free BIOSes.) Personally, I believe practicality beats purity in computing philosophy as well as API design, and I'll happily let GitHub carry my software. What's the worst that can happen? I have to switch to somewhere else, and I lose the issue tracker and pull requests. In the case of CPython, they wouldn't even be lost - they're (to be) backed up. In the meantime, I'm on a well-polished platform with a large number of users. The same cannot be said for *many* other hosts, even if they do use exclusively free software. ChrisA From ian.g.kelly at gmail.com Wed Jul 13 02:21:17 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Jul 2016 00:21:17 -0600 Subject: Curious Omission In New-Style Formats In-Reply-To: <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jul 11, 2016 at 9:38 PM, Steven D'Aprano wrote: > For integers, printf and % interpret the so-called "precision" field of the > format string not as a measurement precision (number of decimal places), > but as the number of digits to use (which is different from the total field > width). For example: > > > py> "%10.8x" % 123 > ' 0000007b' > > How anyone can possibly claim this makes no sense is beyond me! Is the > difference between "number of digits" and "number of decimal places" really > so hard to grok? I think not. I never claimed it's not useful. I don't really have a problem with format supporting it, either. But if it does, then don't call it "precision". That's like writing a function that calculates a mean and calling it "mean", except that if passed a bunch of complex numbers, it just returns the sum instead. I don't know of anybody who would consider that good design, and the "precision" field in printf-style formatting isn't good design either. But it has history behind it, so does that put it in the right? > And it's clearly useful: with integers, particular if they represent > fixed-size byte quantities, it is very common to use leading zeroes. To a > programmer the hex values 7b, 007b and 0000007b have very different > meanings: the first is a byte, the second may be a short int, and the third > may be a long int. And what about 0007b? After all, the very example that started this thread wanted 5 hex digits, not a nice, even power of 2. > Why shouldn't we use the "precision" field for this? For the same reason that we shouldn't use the "mean" function to calculate sums. >>>> If you truly wanted to format the number with a precision >>>> of 5 digits, it would look like this: >>>> >>>> 0x123.00 >>> >>> Er, no, because its an integer. >> >> Which is why if you actually want to do this, you should convert it to >> a decimal or a float first (of course, those don't support hexadecimal >> output, so if you actually want hexadecimal output *and* digits after >> the (hexa)decimal point, then I think you would just have to roll your >> own formatting at that point). > > What? No no no. Didn't you even look at Lawrence's example? He doesn't want > to format the number with decimal places at all. I was referring to the example above. I'm completely aware that it's not the same as what Lawrence wanted. > Converting an integer to a float just to use the precision field is just > wrong. What if I've been doing my math with fixed-point integers (because I don't know about or just don't like decimals), and now I want to format them for output? Is this just wrong? '{:.2f}'.format(int_value / 100) > Now lets go the other way. How to you distinguish between a distance > measured using an unmarked metre stick, giving us an answer of 123 metres, > versus something measured with a 10km ruler(!) with one metre markings? > Obviously with *leading* zeroes rather than trailing zeroes. Fair enough, but I still wouldn't call that "precision". > It *does* matter for measuring curves, but paradoxically the bigger the > measuring stick (the more leading zeroes) the worse your measurement is > likely to be. This is the problem of measuring coastlines and is related to > fractal dimension. Suppose I lay my 10km long measuring stick along some > piece of coastline, and measure it as 00123 metres. (It's a *thought > experiment*, don't hassle me about the unfeasibly large stick. Divide > everything by a thousand and call it a 10m stick marked in millimetres if > you like.) Chances are that if I used a 1 metre measuring stick, and > followed the contour of the coast more closely, I'd get a different number. > So the more leading zeroes, the less accurate your measurement is likely to > be. But interesting as this is, for most purposes either we're not > measuring a curve, or we are but pretend we're not and ignore the fractal > dimension. If you use a 1 meter stick to measure the coastline, you'll go mad as the tide keeps ruining your careful measurements. Best to just use the 10 km stick and get it over with. From steve+comp.lang.python at pearwood.info Wed Jul 13 02:44:00 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2016 16:44 +1000 Subject: Were is a great place to Share your finished projects? References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> Message-ID: <5785e332$0$21718$c3e8da3@news.astraweb.com> On Wednesday 13 July 2016 15:11, Chris Angelico wrote: > You're welcome to take a 100% philosophical stance It's not a philosophical stance to avoid vendor lockin, nor to avoid incipient monopolies, nor to avoid rewarding companies that behave badly. It's not for philosophical reasons that we should avoid tendencies to band- wagon jumping and monopoly building. Its for REAL, PRACTICAL reasons that the short-term gain will invariably be overwhelmed by the long-term loss. You just need to value more than the immediate right here, right now, and not discount future risks excessively. There are people who plan and plant great gardens which they will never see completed, trees taking many decades to reach maturity. And there are those who think that doing the washing on the weekend so they'll have clothes to wear on Tuesday counts as "long term planning". People over-estimate the costs of technical competition and under-estimate the costs of monopolies and the single-network effect. They jump on the bandwagon of "but everyone else is using IBM/Windows/Word/iPhones/Facebook/Github/ whatever" and then wonder why conditions slowly get worse. Its boiling frogs everywhere. Even if Github was 100% open source with no proprietary extensions, and the *technical* cost of leaving was low, the single-network effect would still lock you in, which leaves you (to some degree) at the mercy of Github's management. Don't like the fact that they run their servers on electricity made from burning puppies and the tears of little children? Too bad, what are you going to do, move your project to some backwater VCS where nobody ever goes? You might as well be on AOL for all anyone will ever find your project. It boggles my mind that even devs who are the most socially aware and are all for diversity and codes of conduct and building a better world have such a blind eye when it comes to jumping on bandwagons and blindly following trends. Time-to-read-Connie-Willis'-"Bellwether"-again-ly y'rs, -- Steve From marko at pacujo.net Wed Jul 13 02:57:45 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 13 Jul 2016 09:57:45 +0300 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87h9buyqhi.fsf@elektro.pacujo.net> Ian Kelly : > I don't know of anybody who would consider that good design, and the > "precision" field in printf-style formatting isn't good design either. > But it has history behind it, so does that put it in the right? Apparently, the original intent for the field was for precision only, and the syntax of placing the precision after a dot reinforces the notion. Later, the field found other neat uses and people didn't think of going back and renaming the field in source code and all of the documentation. For Unix hackers, this was a neat trick, a laudable hack. A somewhat similar example is the "execute" permission flag on Unix files. On regular files, it expresses whether the file can be executed. On directory files, it expresses whether it can be "entered". Just as you can enter into philosophical discussions about whether integers or strings can have a precision, you can debate whether a directory can be executed. Marko From rosuav at gmail.com Wed Jul 13 03:00:15 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2016 17:00:15 +1000 Subject: Were is a great place to Share your finished projects? In-Reply-To: <5785e332$0$21718$c3e8da3@news.astraweb.com> References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> Message-ID: On Wed, Jul 13, 2016 at 4:44 PM, Steven D'Aprano wrote: > Even if Github was 100% open source with no proprietary extensions, and the > *technical* cost of leaving was low, the single-network effect would still lock > you in, which leaves you (to some degree) at the mercy of Github's management. > Don't like the fact that they run their servers on electricity made from > burning puppies and the tears of little children? Too bad, what are you going > to do, move your project to some backwater VCS where nobody ever goes? You > might as well be on AOL for all anyone will ever find your project. So what're you going to do? Move *now* to some backwater where nobody ever goes, just in case GitHub ever turns evil? ChrisA From lawrencedo99 at gmail.com Wed Jul 13 03:05:12 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 13 Jul 2016 00:05:12 -0700 (PDT) Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <79cc7bd7-eeda-41c9-ac6d-dd3f4edb319c@googlegroups.com> On Wednesday, July 13, 2016 at 6:22:31 PM UTC+12, Ian wrote: > I never claimed it's not useful. I don't really have a problem with > format supporting it, either. But if it does, then don't call it > "precision". Like it or not, that is the accepted term, as used in the printf(3) man page. Feel free not to use common accepted terms if you don?t want. You can use words to mean whatever you avocado, but don?t expect other people to carrot. From steve+comp.lang.python at pearwood.info Wed Jul 13 04:49:06 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2016 18:49:06 +1000 Subject: Were is a great place to Share your finished projects? References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> Message-ID: <57860084$0$1512$c3e8da3$5496439d@news.astraweb.com> On Wednesday 13 July 2016 17:00, Chris Angelico wrote: > On Wed, Jul 13, 2016 at 4:44 PM, Steven D'Aprano > wrote: >> Even if Github was 100% open source with no proprietary extensions, and the >> *technical* cost of leaving was low, the single-network effect would still >> lock you in, which leaves you (to some degree) at the mercy of Github's >> management. Don't like the fact that they run their servers on electricity >> made from burning puppies and the tears of little children? Too bad, what >> are you going to do, move your project to some backwater VCS where nobody >> ever goes? You might as well be on AOL for all anyone will ever find your >> project. > > So what're you going to do? Move *now* to some backwater where nobody > ever goes, just in case GitHub ever turns evil? Move *now* to a viable alternative, while it's still viable and before it's too late, in order to encourage competition and discourage those idiots who don't know how to use Google and think Github is the entire Internet-for-code. "I couldn't find it on Github, therefore it doesn't exist" is already a real phenomenon. Fortunately, at this point you probably won't want to accept patches from those people. But in five or ten years? I give odds of about 50:50 that even competent coders will have bought into the Github-is-the-universe, just as even people who know better treat Facebook as the entire Internet, and worse. "...some backwater where nobody ever goes..." If you really mean that, then you're saying that Github has already captured such a dominant market share that they are an effective monopoly over all hosted DVCSes, and that programmers no longer have a choice about using them. Its Github, or you're invisible, and leaving is not an option. If you mean that, then be honest: "The horse has already bolted, and vendor lockin is not a concern, its a fact. All I can do is *hope* that Github doesn't turn evil." On the other hand, if you genuinely think that Github *hasn't* captured the market, that migration away from them is still an option, then you've undercut your argument against using competing services. If you genuinely think that migrating away from Github to (let's say) Bitbucket is an option, then your quip about backwaters is invalid. Speaking of F/B, a true story. A friend of mine in the US had this conversation (edited for brevity): "You got married??!? When did you get married?" "Oh, about three months ago." "I'm disappointed that you didn't invite me. I would have loved to have come." "What do you mean? I posted the details on my Wall. Didn't you see it?" -- Steve From steve+comp.lang.python at pearwood.info Wed Jul 13 04:49:50 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2016 18:49:50 +1000 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <79cc7bd7-eeda-41c9-ac6d-dd3f4edb319c@googlegroups.com> Message-ID: <578600af$0$1512$c3e8da3$5496439d@news.astraweb.com> On Wednesday 13 July 2016 17:05, Lawrence D?Oliveiro wrote: > On Wednesday, July 13, 2016 at 6:22:31 PM UTC+12, Ian wrote: > >> I never claimed it's not useful. I don't really have a problem with >> format supporting it, either. But if it does, then don't call it >> "precision". > > Like it or not, that is the accepted term, as used in the printf(3) man page. > > Feel free not to use common accepted terms if you don?t want. You can use > words to mean whatever you avocado, but don?t expect other people to carrot. +1 QOTW -- Steve From rosuav at gmail.com Wed Jul 13 05:20:00 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2016 19:20:00 +1000 Subject: Were is a great place to Share your finished projects? In-Reply-To: <57860084$0$1512$c3e8da3$5496439d@news.astraweb.com> References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <57860084$0$1512$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 13, 2016 at 6:49 PM, Steven D'Aprano wrote: >> what >> are you going to do, move your project to some backwater VCS where nobody >> ever goes? > > "...some backwater where nobody ever goes..." > > If you really mean that, then you're saying that Github has already captured > such a dominant market share that they are an effective monopoly over all > hosted DVCSes, and that programmers no longer have a choice about using them. > Its Github, or you're invisible, and leaving is not an option. Your words, not mine. ChrisA From jonas.thornvall at gmail.com Wed Jul 13 05:46:40 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Wed, 13 Jul 2016 02:46:40 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: <5785a790$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> <5785a790$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <960e3589-00c9-4f71-97b1-2ffed104436f@googlegroups.com> Den onsdag 13 juli 2016 kl. 04:29:48 UTC+2 skrev Steven D'Aprano: > On Wed, 13 Jul 2016 03:35 am, jonas.thornvall at gmail.com wrote: > > > No it is only compressible down to a limit given by the algorithm. > > Right! Then there is data that you can't compress. > > Suppose you have some data: > > data = "ABABABABABAB...ABAB" > > And you compress it "down to a limit": > > x = compress(compress(compress(data))) > print(x) > => prints "@nx7%k!b" > > Now let's try again with something else: > > data = "AABBBCCCCDDDDEEEE...ZZZZ" > > And you compress it "down to a limit": > > x = compress(compress(compress(compress(data)))) > print(x) > => prints "wu*$cS#k-pv32zx[&+r" > > > One more time: > > data = "AABBAABBAABBAABBAABB" > x = compress(data) > print(x) > => prints "g^x3@" > > > We agree on this. Now you say, "Give me some random data, anything at all, > and I'll compress it!", and I run a random number generator and out pops: > > data = "@nx7%k!b" > > or possibly: > > data = "wu*$cS#k-pv32zx[&+r" > > or: > > data = "g^x3@" > > > and I say "Compress that!" > > But we've already agreed that this is as compressed as you can possibly make > it. You can't compress it any more. > > So there's *at least some* random data that you can't compress. Surely you > have to accept that. You don't get to say "Oh, I don't mean *that* data, I > mean only data that I can compress". Random data means its random, you > don't get to pick and choose between data you can compress and data that > you can't. > > Now the tricky part is to realise that its not just short sequences of > random data that can't be compressed. The same applies for LONG sequences > to. If I give you a gigabyte of raw video, you can probably compress that a > fair bit. That's what things like x264 encoders do. The x265 encoder is > even better. But they're lossy, so you can't reverse them. > > But if I give you a gigabyte of random data, you'll be lucky to find *any* > patterns or redundancies that allow compression. You might be able to > shrink the file by a few KB. And if you take that already compressed file, > and try to compress it again, well, you've already hit the limit of > compression. There no more redundancy left to remove. > > It doesn't matter how clever you are, or what a "folding structure" is, or > how many times you iterate over the data. It's a matter of absolute > simplicity: the pigeonhole principle. You can't argue with the numbers. > > If you start with a 100 digit decimal number, there are 10**100 different > pigeons. If you can compress down to a 6 digit decimal number, there are > 10**6 pigeon holes. You cannot put 10*100 pigeons into 10**6 pigeon holes > without doubling up (which makes your compression lossly). > > So either some numbers cannot be compressed, or some numbers are compressed > to the same result, and you can't tell which was the original. That's your > choice: a lossless encoder means some numbers can't be compressed, a lossy > encoder means you can't reverse the process exactly. > > > > > > -- > Steven > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. It is not that the data is not compressible i just need more chunks or random data, it is the footprint of the algorithm that has a certain it is a structure afterall albeit richer in interpretation than the numerical field. You exchange size for computational complexity, but that may be true for any compression algorithm. From jonas.thornvall at gmail.com Wed Jul 13 06:04:43 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Wed, 13 Jul 2016 03:04:43 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: <5785a790$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> <5785a790$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <325b975d-d176-4dc0-8da3-787f60035e65@googlegroups.com> Den onsdag 13 juli 2016 kl. 04:29:48 UTC+2 skrev Steven D'Aprano: > On Wed, 13 Jul 2016 03:35 am, jonas.thornvall at gmail.com wrote: > > > No it is only compressible down to a limit given by the algorithm. > > Right! Then there is data that you can't compress. > > Suppose you have some data: > > data = "ABABABABABAB...ABAB" > > And you compress it "down to a limit": > > x = compress(compress(compress(data))) > print(x) > => prints "@nx7%k!b" > > Now let's try again with something else: > > data = "AABBBCCCCDDDDEEEE...ZZZZ" > > And you compress it "down to a limit": > > x = compress(compress(compress(compress(data)))) > print(x) > => prints "wu*$cS#k-pv32zx[&+r" > > > One more time: > > data = "AABBAABBAABBAABBAABB" > x = compress(data) > print(x) > => prints "g^x3@" > > > We agree on this. Now you say, "Give me some random data, anything at all, > and I'll compress it!", and I run a random number generator and out pops: > > data = "@nx7%k!b" > > or possibly: > > data = "wu*$cS#k-pv32zx[&+r" > > or: > > data = "g^x3@" > > > and I say "Compress that!" > > But we've already agreed that this is as compressed as you can possibly make > it. You can't compress it any more. > > So there's *at least some* random data that you can't compress. Surely you > have to accept that. You don't get to say "Oh, I don't mean *that* data, I > mean only data that I can compress". Random data means its random, you > don't get to pick and choose between data you can compress and data that > you can't. > > Now the tricky part is to realise that its not just short sequences of > random data that can't be compressed. The same applies for LONG sequences > to. If I give you a gigabyte of raw video, you can probably compress that a > fair bit. That's what things like x264 encoders do. The x265 encoder is > even better. But they're lossy, so you can't reverse them. > > But if I give you a gigabyte of random data, you'll be lucky to find *any* > patterns or redundancies that allow compression. You might be able to > shrink the file by a few KB. And if you take that already compressed file, > and try to compress it again, well, you've already hit the limit of > compression. There no more redundancy left to remove. > > It doesn't matter how clever you are, or what a "folding structure" is, or > how many times you iterate over the data. It's a matter of absolute > simplicity: the pigeonhole principle. You can't argue with the numbers. > > If you start with a 100 digit decimal number, there are 10**100 different > pigeons. If you can compress down to a 6 digit decimal number, there are > 10**6 pigeon holes. You cannot put 10*100 pigeons into 10**6 pigeon holes > without doubling up (which makes your compression lossly). > > So either some numbers cannot be compressed, or some numbers are compressed > to the same result, and you can't tell which was the original. That's your > choice: a lossless encoder means some numbers can't be compressed, a lossy > encoder means you can't reverse the process exactly. > > > > > > -- > Steven > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. Ok, try to see it this way ****very big**** numbers can be described as the sum or difference between a sequense of a few polynomials. Unfortunately we lack the computational skill/computing power to find them. That is not the case using foldings/geometric series. From jonas.thornvall at gmail.com Wed Jul 13 06:14:36 2016 From: jonas.thornvall at gmail.com (jonas.thornvall at gmail.com) Date: Wed, 13 Jul 2016 03:14:36 -0700 (PDT) Subject: Compression of random binary data In-Reply-To: <325b975d-d176-4dc0-8da3-787f60035e65@googlegroups.com> References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> <5785a790$0$1619$c3e8da3$5496439d@news.astraweb.com> <325b975d-d176-4dc0-8da3-787f60035e65@googlegroups.com> Message-ID: <33669913-c316-4f2b-88ff-f293251c2283@googlegroups.com> Den onsdag 13 juli 2016 kl. 12:05:03 UTC+2 skrev jonas.t... at gmail.com: > Den onsdag 13 juli 2016 kl. 04:29:48 UTC+2 skrev Steven D'Aprano: > > On Wed, 13 Jul 2016 03:35 am, jonas.thornvall at gmail.com wrote: > > > > > No it is only compressible down to a limit given by the algorithm. > > > > Right! Then there is data that you can't compress. > > > > Suppose you have some data: > > > > data = "ABABABABABAB...ABAB" > > > > And you compress it "down to a limit": > > > > x = compress(compress(compress(data))) > > print(x) > > => prints "@nx7%k!b" > > > > Now let's try again with something else: > > > > data = "AABBBCCCCDDDDEEEE...ZZZZ" > > > > And you compress it "down to a limit": > > > > x = compress(compress(compress(compress(data)))) > > print(x) > > => prints "wu*$cS#k-pv32zx[&+r" > > > > > > One more time: > > > > data = "AABBAABBAABBAABBAABB" > > x = compress(data) > > print(x) > > => prints "g^x3@" > > > > > > We agree on this. Now you say, "Give me some random data, anything at all, > > and I'll compress it!", and I run a random number generator and out pops: > > > > data = "@nx7%k!b" > > > > or possibly: > > > > data = "wu*$cS#k-pv32zx[&+r" > > > > or: > > > > data = "g^x3@" > > > > > > and I say "Compress that!" > > > > But we've already agreed that this is as compressed as you can possibly make > > it. You can't compress it any more. > > > > So there's *at least some* random data that you can't compress. Surely you > > have to accept that. You don't get to say "Oh, I don't mean *that* data, I > > mean only data that I can compress". Random data means its random, you > > don't get to pick and choose between data you can compress and data that > > you can't. > > > > Now the tricky part is to realise that its not just short sequences of > > random data that can't be compressed. The same applies for LONG sequences > > to. If I give you a gigabyte of raw video, you can probably compress that a > > fair bit. That's what things like x264 encoders do. The x265 encoder is > > even better. But they're lossy, so you can't reverse them. > > > > But if I give you a gigabyte of random data, you'll be lucky to find *any* > > patterns or redundancies that allow compression. You might be able to > > shrink the file by a few KB. And if you take that already compressed file, > > and try to compress it again, well, you've already hit the limit of > > compression. There no more redundancy left to remove. > > > > It doesn't matter how clever you are, or what a "folding structure" is, or > > how many times you iterate over the data. It's a matter of absolute > > simplicity: the pigeonhole principle. You can't argue with the numbers. > > > > If you start with a 100 digit decimal number, there are 10**100 different > > pigeons. If you can compress down to a 6 digit decimal number, there are > > 10**6 pigeon holes. You cannot put 10*100 pigeons into 10**6 pigeon holes > > without doubling up (which makes your compression lossly). > > > > So either some numbers cannot be compressed, or some numbers are compressed > > to the same result, and you can't tell which was the original. That's your > > choice: a lossless encoder means some numbers can't be compressed, a lossy > > encoder means you can't reverse the process exactly. > > > > > > > > > > > > -- > > Steven > > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > > enough, things got worse. > > Ok, try to see it this way ****very big**** numbers can be described as the sum or difference between a sequense of a few polynomials. Unfortunately we lack the computational skill/computing power to find them. > > That is not the case using foldings/geometric series. The sum or difference of a few small polynomials would still of course be a polynomial. But as i say it is a case of enrich the interpretation of the symbolic set that you look at you replace digits bits/integers with arithmetic describing them. From mal at europython.eu Wed Jul 13 06:23:49 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 13 Jul 2016 12:23:49 +0200 Subject: EuroPython 2016: Guggenheim and Fine Arts Museum Message-ID: <578616B5.7020708@europython.eu> EuroPython is not the only attraction in Bilbao to attend in July. The city also hosts the famous Guggenheim Museum, featuring modern art in an amazing building designed by Frank O. Gehry. >>> Please see below for a special deal we have for EuroPython attendees *** Guggenheim Museum *** https://ep2016.europython.eu/en/venue/guggenheim-museum/ You can also find the Fine Arts Museum in Bilbao, with exhibitions of Tucker and 50s fashion in France, in addition to other masterpieces. It is very close to the conference venue. *** Fine Arts Museum *** https://ep2016.europython.eu/en/venue/fine-arts-museum/ Special offer for EuroPython attendees: Avoid long queues --------------------------------------------------------- If you want to avoid long queues at the Guggenheim Museum, you can benefit from getting a ticket at the conference desk. We have acquired a block of tickets and will give them away for free, if you donate at least EUR 10 to the EuroPython conference financial aid budget for next year. That?s less than the regular ticket price and you get the additional warm fuzzy feeling of helping others as bonus :-) Donations can be made in cash at the conference desk. With gravitational regards, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/753158920781332481 Thanks. From steve at pearwood.info Wed Jul 13 08:13:37 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2016 22:13:37 +1000 Subject: Compression of random binary data References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> <5785a790$0$1619$c3e8da3$5496439d@news.astraweb.com> <325b975d-d176-4dc0-8da3-787f60035e65@googlegroups.com> Message-ID: <57863073$0$1610$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Jul 2016 08:04 pm, jonas.thornvall at gmail.com wrote: > Ok, try to see it this way ****very big**** numbers can be described as > the sum or difference between a sequense of a few polynomials. *Any* number, big or small, can be given as the sum or difference of a few polynomials: 15 = (25*x**2 - 2*x + 40) - (25*x**2 - 2*x + 25) But... why am I wasting my time with the x**2 and x terms? They must *always* cancel, because I'm trying to simplify to a constant. So I should just write: 15 = 40 - 25 but that's a waste of time to. I should just write: 15 and be done. The same applies for any number, no matter how big. > Unfortunately we lack the computational skill/computing power to find > them. > > That is not the case using foldings/geometric series. You still haven't explained how you are supposed to compress 10**100 possible inputs to just 10**6 outputs without any loss of information. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Wed Jul 13 08:40:03 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 13 Jul 2016 05:40:03 -0700 (PDT) Subject: Program outlining In-Reply-To: References: <09e4f82e-89b2-40b6-9ac1-95513b4719e8@googlegroups.com> Message-ID: <3c14c85e-2a04-4e21-8e9b-a7e48d623dfa@googlegroups.com> On Monday, July 11, 2016 at 6:27:05 PM UTC+5:30, Rustom Mody wrote: > On Monday, July 11, 2016 at 6:26:01 PM UTC+5:30, Rustom Mody wrote: > > Ive been trying to figure out the best outlining that emacs can give for > > programs. > > Oops sorry! Wrong list!! Couple of people wrote me off list asking what I found/know on this. Its collected here ? its really notes for my students so not very well polished :-) http://blog.languager.org/2016/07/emacs-tips.html There?s one section specifically on ?Programming Language Support? And some titbits on specific languages including python From nir36g at gmail.com Wed Jul 13 08:54:39 2016 From: nir36g at gmail.com (Nir Cohen) Date: Wed, 13 Jul 2016 05:54:39 -0700 (PDT) Subject: Packaging multiple wheels in the same package In-Reply-To: References: <0310c596-2f5b-4cca-8059-6e6a81acc35f@googlegroups.com> <577D573B.9040102@stoneleaf.us> Message-ID: <47e86dc2-1196-463f-a3ea-727935879912@googlegroups.com> On Thursday, July 7, 2016 at 7:47:22 AM UTC+3, Nir Cohen wrote: > On Wednesday, July 6, 2016 at 10:09:01 PM UTC+3, Ethan Furman wrote: > > On 07/06/2016 11:43 AM, Nir Cohen wrote: > > > > > We decided that we want to package sets of wheels together created or downloaded > > > by `pip wheel`, add relevant metadata, package them together into a > > single archive > > > (tar.gz or zip) and use the same tool which packs them up to install > > them later on, > > > on the destination hosts. > > > > > > We came up with a tool (http://github.com/cloudify-cosmo/wagon) to do just that > > > and that's what we currently use to create and install our plugins. > > > > Sounds like a great idea! > > > > Once you have your feed-back from here you'll want to take your PEP over > > to the dist-utils sig: > > > > https://mail.python.org/mailman/listinfo/distutils-sig > > > > -- > > ~Ethan~ > > Happy to hear :) > > btw, pull requests are certainly welcome to make whichever changes required to make Wagon PEP-worthy. Sorry to bump this up.. but I'm not sure exactly how I should go about getting as much feedback as possible on this. Any suggestions? From rosuav at gmail.com Wed Jul 13 09:00:15 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2016 23:00:15 +1000 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 13, 2016 at 9:46 PM, Dennis Lee Bieber wrote: > On Wed, 13 Jul 2016 00:21:17 -0600, Ian Kelly > declaimed the following: > >>What if I've been doing my math with fixed-point integers (because I >>don't know about or just don't like decimals), and now I want to >>format them for output? Is this just wrong? >> >> '{:.2f}'.format(int_value / 100) >> > > Ugh... After using integers to keep accuracy in the LSB, you know toss > it out the window by converting to a float which may have an inexact > representation. > > Presuming you kept track of the decimal place during all those integer > operations, format as an integer, then split it at the decimal and insert a > "." at the spot. Or just use divmod: >>> "%d.%02d" % divmod(1<<200, 100) '16069380442589902755419620923411626025222029937827928353013.76' ChrisA From rustompmody at gmail.com Wed Jul 13 09:03:14 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 13 Jul 2016 06:03:14 -0700 (PDT) Subject: Were is a great place to Share your finished projects? In-Reply-To: References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> Message-ID: <4724c168-570d-4938-9f92-b488afffcb4c@googlegroups.com> On Wednesday, July 13, 2016 at 10:42:01 AM UTC+5:30, Chris Angelico wrote: > On Wed, Jul 13, 2016 at 2:42 PM, Ben Finney wrote: > > Chris Angelico writes: > > > >> On Wed, Jul 13, 2016 at 11:28 AM, Ben Finney wrote: > >> > Pull requests. Code review. Issues. Integration with other services. > >> > All the social information around all of those interactions, and > >> > more. > >> > > >> > If *any* of that is valuable, then yes it's important that it not be > >> > locked to any one vendor. > >> > >> Exactly how important? Not so important as to stop slabs of Python > >> from migrating to GitHub, including its pull request system. > > > > I maintain that it is important enough to stop that. > > > > The migration happened anyway, because not everyone is convinced of the > > importance of avoiding vendor lock-in of valuable data, over criteria > > such as ?this person happens to like Vendor-locked Solution Foo?. > > > > Fine. You're welcome to take a 100% philosophical stance; I applaud > you for it. (I understand Richard Stallman is so adamant about not > using *any* non-free code - software or firmware - that he restricts > himself to a tiny selection of laptops that have free BIOSes.) > Personally, I believe practicality beats purity in computing > philosophy as well as API design, and I'll happily let GitHub carry my > software. What's the worst that can happen? I have to switch to > somewhere else, and I lose the issue tracker and pull requests. In the > case of CPython, they wouldn't even be lost - they're (to be) backed > up. In the meantime, I'm on a well-polished platform with a large > number of users. The same cannot be said for *many* other hosts, even > if they do use exclusively free software. > > ChrisA Speaking of notable figure(heads) its good to compare Stallman (rms) and Torvalds. rms started working on the gnu-system before Torvalds He did more work on that He was (and likely is) a more capable programmer Note further that Torvalds was told off by prof. Tanenbaum for his poor quality unimaginative approach to Linux Torvalds still gets the Lion's share of the credit ? how many people say ?GNU-Linux distros? rather than just plain ?Linux?? I?d say this is directly related to his choosing practicality over purity He didn?t change the obsolete (so-called) Unix API He didn?t redesign the OS along the lines fashionable to guys like Tanenbaum He just found himself at the right place at the right time ? holding a protection capable home PC. And beat IBM and Microsoft at producing a kernel for that. No I am not saying that the fears of Ben and Steven are unfounded Just that we may have other battles to fight And other heroes to cheer, eg http://www.trueactivist.com/muslim-man-hugs-isis-suicide-bomber-saves-hundreds-of-lives-in-iraq/ From alister.ware at ntlworld.com Wed Jul 13 09:03:29 2016 From: alister.ware at ntlworld.com (alister) Date: Wed, 13 Jul 2016 13:03:29 GMT Subject: Quick poll: gmean or geometric_mean References: <57808af6$0$1602$c3e8da3$5496439d@news.astraweb.com> <57820c7a$0$1617$c3e8da3$5496439d@news.astraweb.com> <57821eaa$0$1584$c3e8da3$5496439d@news.astraweb.com> <1014e463-20b0-446f-96f6-c142587f4b82@googlegroups.com> <87r3b11qnq.fsf@elektro.pacujo.net> <998ee463-331b-4a1a-bc36-aa7e93a63945@googlegroups.com> <766bf2f6-466f-4df9-ae85-ce09e2c8c130@googlegroups.com> Message-ID: On Tue, 12 Jul 2016 18:42:44 -0700, Lawrence D?Oliveiro wrote: > On Wednesday, July 13, 2016 at 10:58:14 AM UTC+12, alister wrote: > >> a US gallon is smaller than an Imperial Gallon a US Mile is shorter >> than an Imperial mile and probably most importantly (because it means >> they keep serving me short measures) a US pint is smaller than an >> Imperial Pint > > I thought everything was bigger in the USA... well the us fluid ounce is bigger but the US pint is only 16 oz. that is why they keep giving me short measures unless I go to the correct places (The Pub in the Montecarlo Las Vegas offers both sizes :-) ) -- The more you complain, the longer God lets you live. From jussi.piitulainen at helsinki.fi Wed Jul 13 09:04:02 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 13 Jul 2016 16:04:02 +0300 Subject: Curious Omission In New-Style Formats References: <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: Dennis Lee Bieber writes: > On Wed, 13 Jul 2016 00:21:17 -0600, Ian Kelly > declaimed the following: > >> What if I've been doing my math with fixed-point integers (because I >> don't know about or just don't like decimals), and now I want to >> format them for output? Is this just wrong? >> >> '{:.2f}'.format(int_value / 100) >> > > Ugh... After using integers to keep accuracy in the LSB, you > know toss it out the window by converting to a float which may have an > inexact representation. > > Presuming you kept track of the decimal place during all those > integer operations, format as an integer, then split it at the decimal > and insert a "." at the spot. Of course floats fail (for this task) when the number exceeds their integer range, but what would be a number within that range, preferably well within that range, where they also fail? I didn't find any. I tried to find one using the following code. First I found cases where the output was different, but every single time (!) it was a bug in the "safer" routine. Dismiss that as my incompetence, the fact remains that the "dangerous" floating-point variant was never wrong at all while the erroneous outputs from my "safer" formatters were off by an order of magnitude. Floating point errors would be in the digits that matter least. No. The bugs were not in the regex. I was unsure of combining *? with {1,2} that way - it never failed. I wasn't any surer of the non-regex code - it kept failing. import re, random components = re.compile(r'(-?)(\d*?)(\d{1,2})') def safer(x): sign, whole, decimals = components.fullmatch(str(x)).groups() return '{}{:>01}.{:>02}'.format(sign, whole, decimals) def dangerouser(x): return '{:.2f}'.format(x/100) for n in random.sample(range(-9000000000,9000000001), 1000000): x, y = safer(n), dangerouser(n) if x == y: continue print('differ:', n, x, y) From rosuav at gmail.com Wed Jul 13 09:05:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2016 23:05:46 +1000 Subject: Packaging multiple wheels in the same package In-Reply-To: <47e86dc2-1196-463f-a3ea-727935879912@googlegroups.com> References: <0310c596-2f5b-4cca-8059-6e6a81acc35f@googlegroups.com> <577D573B.9040102@stoneleaf.us> <47e86dc2-1196-463f-a3ea-727935879912@googlegroups.com> Message-ID: On Wed, Jul 13, 2016 at 10:54 PM, Nir Cohen wrote: > On Thursday, July 7, 2016 at 7:47:22 AM UTC+3, Nir Cohen wrote: >> On Wednesday, July 6, 2016 at 10:09:01 PM UTC+3, Ethan Furman wrote: >> > Sounds like a great idea! >> > >> > Once you have your feed-back from here you'll want to take your PEP over >> > to the dist-utils sig: >> > >> > https://mail.python.org/mailman/listinfo/distutils-sig >> > >> > -- >> > ~Ethan~ >> >> Happy to hear :) >> >> btw, pull requests are certainly welcome to make whichever changes required to make Wagon PEP-worthy. > > Sorry to bump this up.. but I'm not sure exactly how I should go about getting as much feedback as possible on this. Any suggestions? Well.... a lot of the people here might *use* wheels, but a relatively small proportion *create* them. (I'm not big on creating packages - the only PyPI-published module of mine is a tiny pure-Python one, so it's about as simple as it gets. And it's not even actively maintained any more.) Ethan suggested hopping over to distutils-sig - have you done that? That would be the next step, if you haven't. ChrisA From steve at pearwood.info Wed Jul 13 09:11:16 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 13 Jul 2016 23:11:16 +1000 Subject: Compression of random binary data References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> <5785a790$0$1619$c3e8da3$5496439d@news.astraweb.com> <960e3589-00c9-4f71-97b1-2ffed104436f@googlegroups.com> Message-ID: <57863df5$0$1590$c3e8da3$5496439d@news.astraweb.com> On Wed, 13 Jul 2016 07:46 pm, jonas.thornvall at gmail.com wrote: > It is not that the data is not compressible Yes it is. Until you explain how you can *reversibly* pack 10**100 inputs into 10**6 outputs without loss of information, all your explanations about "folding" and polynomials and structure is just cheap talk. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jussi.piitulainen at helsinki.fi Wed Jul 13 09:16:02 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 13 Jul 2016 16:16:02 +0300 Subject: Curious Omission In New-Style Formats References: <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico writes: > On Wed, Jul 13, 2016 at 9:46 PM, Dennis Lee Bieber > wrote: >> On Wed, 13 Jul 2016 00:21:17 -0600, Ian Kelly >> declaimed the following: >> >>> What if I've been doing my math with fixed-point integers (because I >>> don't know about or just don't like decimals), and now I want to >>> format them for output? Is this just wrong? >>> >>> '{:.2f}'.format(int_value / 100) >>> >> >> Ugh... After using integers to keep accuracy in the LSB, you >> know toss it out the window by converting to a float which may have >> an inexact representation. >> >> Presuming you kept track of the decimal place during all >> those integer operations, format as an integer, then split it at the >> decimal and insert a "." at the spot. > > Or just use divmod: > >>>> "%d.%02d" % divmod(1<<200, 100) > '16069380442589902755419620923411626025222029937827928353013.76' I'm not quite ready to blame floating point for this difference yet: >>> "%d.%02d" % divmod(-1,100) '-1.99' >>> "%.2f" % (-1/100) '-0.01' From rosuav at gmail.com Wed Jul 13 09:49:56 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jul 2016 23:49:56 +1000 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jul 13, 2016 at 11:16 PM, Jussi Piitulainen wrote: >> Or just use divmod: >> >>>>> "%d.%02d" % divmod(1<<200, 100) >> '16069380442589902755419620923411626025222029937827928353013.76' > > I'm not quite ready to blame floating point for this difference yet: > >>>> "%d.%02d" % divmod(-1,100) > '-1.99' >>>> "%.2f" % (-1/100) > '-0.01' Ehhhh, forgot about that :D Negative numbers and modulo *always* trip me up, because different languages have different rules. I inevitably have to go check the docos. ChrisA From antoon.pardon at rece.vub.ac.be Wed Jul 13 10:01:09 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 13 Jul 2016 16:01:09 +0200 Subject: Curious Omission In New-Style Formats In-Reply-To: <578600af$0$1512$c3e8da3$5496439d@news.astraweb.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <79cc7bd7-eeda-41c9-ac6d-dd3f4edb319c@googlegroups.com> <578600af$0$1512$c3e8da3$5496439d@news.astraweb.com> Message-ID: <578649A5.7030307@rece.vub.ac.be> Op 13-07-16 om 10:49 schreef Steven D'Aprano: > On Wednesday 13 July 2016 17:05, Lawrence D?Oliveiro wrote: > >> On Wednesday, July 13, 2016 at 6:22:31 PM UTC+12, Ian wrote: >> >>> I never claimed it's not useful. I don't really have a problem with >>> format supporting it, either. But if it does, then don't call it >>> "precision". >> Like it or not, that is the accepted term, as used in the printf(3) man page. >> >> Feel free not to use common accepted terms if you don?t want. You can use >> words to mean whatever you avocado, but don?t expect other people to carrot. > +1 QOTW But as far as I know, "significant digits" is not the accepted term for the width of the representation when you print a number with added zeroes in front of it. So when we start we a term like "precision" and people jump from that to "significant digits", maybe we should consider how confusing the common accepted term can be. -- Antoon From jussi.piitulainen at helsinki.fi Wed Jul 13 10:23:16 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 13 Jul 2016 17:23:16 +0300 Subject: Curious Omission In New-Style Formats References: <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico writes: > On Wed, Jul 13, 2016 at 11:16 PM, Jussi Piitulainen wrote: >>> Or just use divmod: >>> >>>>>> "%d.%02d" % divmod(1<<200, 100) >>> '16069380442589902755419620923411626025222029937827928353013.76' >> >> I'm not quite ready to blame floating point for this difference yet: >> >>>>> "%d.%02d" % divmod(-1,100) >> '-1.99' >>>>> "%.2f" % (-1/100) >> '-0.01' > > Ehhhh, forgot about that :D Negative numbers and modulo *always* trip > me up, because different languages have different rules. I inevitably > have to go check the docos. Julia's "Euclidean division" (div, rem, divrem) would result in '0.-1' above :) while fld, mod, fldmod (floored or floor or flooring division) would be the same as Python's //, %, divmod. Python 3.4.3 help text for divmod says it returns ((x-x%y)/y, x%y) but that's not quite correct, because type. Probably // is intended. There are easily half a dozen different integer divisions rounding towards or away from zero or up or down or to nearest integer with different ways of breaking ties and matching the sign of dividend or divisor, and a couple of other details, yet I'm not sure if any of them alone would do the job at hand :) Leave it for someone smarter. From rosuav at gmail.com Wed Jul 13 10:28:39 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jul 2016 00:28:39 +1000 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jul 14, 2016 at 12:23 AM, Jussi Piitulainen wrote: > Python 3.4.3 help text for divmod says it returns ((x-x%y)/y, x%y) but > that's not quite correct, because type. Probably // is intended. Starting with 3.5, it says it returns the tuple (x//y, x%y). ChrisA From ethan at stoneleaf.us Wed Jul 13 11:01:06 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 13 Jul 2016 08:01:06 -0700 Subject: Packaging multiple wheels in the same package In-Reply-To: <47e86dc2-1196-463f-a3ea-727935879912@googlegroups.com> References: <0310c596-2f5b-4cca-8059-6e6a81acc35f@googlegroups.com> <577D573B.9040102@stoneleaf.us> <47e86dc2-1196-463f-a3ea-727935879912@googlegroups.com> Message-ID: <578657B2.4020604@stoneleaf.us> On 07/13/2016 05:54 AM, Nir Cohen wrote: > On Thursday, July 7, 2016 at 7:47:22 AM UTC+3, Nir Cohen wrote: >> On Wednesday, July 6, 2016 at 10:09:01 PM UTC+3, Ethan Furman wrote: >>> On 07/06/2016 11:43 AM, Nir Cohen wrote: >>>> We decided that we want to package sets of wheels together created or downloaded >>> > by `pip wheel`, add relevant metadata, package them together into a >>> single archive >>> > (tar.gz or zip) and use the same tool which packs them up to install >>> them later on, >>> > on the destination hosts. >>>> >>>> We came up with a tool (http://github.com/cloudify-cosmo/wagon) to do just that >>> > and that's what we currently use to create and install our plugins. > Sorry to bump this up.. but I'm not sure exactly how I should go about getting as much feedback as possible on this. Any suggestions? You could try Python-Ideas -- plenty of debate happens on that list. ;) -- ~Ethan~ From walters.justin01 at gmail.com Wed Jul 13 12:42:16 2016 From: walters.justin01 at gmail.com (justin walters) Date: Wed, 13 Jul 2016 09:42:16 -0700 Subject: Django Tastypie Vs. Djaogn Rest Framework Message-ID: Hi guys and gals. I've been building a new web application with my business partner. We're using Django and postreSQL. We needed a restful API as we wanted the back end to be completely decoupled from the front end. We ended up going with Tastypie over DRF due to the former being seemingly less complex and easier to get rolling. I've used DRF in the past and found it to have somewhat of a steeper learning curve compared to Tastypie. The way tastypie has you define resources seems a lot more intuitive to me than the way DRF does so. Despite my experience, it seems like DRF is by far the more popular choice for new applications. I was wondering if anyone could offer some insights into why this is the case. Does DRF offer more highly optimized queries? From laurent.pointal at free.fr Wed Jul 13 14:09:00 2016 From: laurent.pointal at free.fr (Laurent Pointal) Date: Wed, 13 Jul 2016 20:09 +0200 Subject: Touch screen development in Python References: <5783D5B4.28625.382C3B3B@jana1972.centrum.cz> <8a12f1bd-f0ee-70bb-01cc-59c6f239afb6@schwertberger.de> <578540B9.9086.3DB648E6@jana1972.centrum.cz> Message-ID: <578683bd$0$3292$426a34cc@news.free.fr> Jahn wrote: > I was thinking about Python touch screen applications for industrial > boards( computers). > If I have a touch screen with that industrial board, what I must have > installed to be able to > write touch screen applications in Python? If you go with Kivy (its built for multitouch graphical interactive applications, can work on Windows, Linux, MacOSX, Android), see the following page for requirements: https://kivy.org/docs/installation/installation.html And learning how to use it (see examples). https://kivy.org/docs/examples/gallery.html Really, give it a try, even on your mouse controlled interface. A+ Laurent. From vijaykumar at bravegnu.org Wed Jul 13 14:48:37 2016 From: vijaykumar at bravegnu.org (Vijay Kumar) Date: Thu, 14 Jul 2016 00:18:37 +0530 Subject: Python Byte Code Hacking Message-ID: <57868D05.2040901@bravegnu.org> Hi Everyone, I wrote an article on Python byte code hacking. The article is available from http://www.bravegnu.org/blog/python-byte-code-hacks.html The article uses an incremental approach for explaining Python's code objects and how to modify them. Unfortunately, I am stuck with Python 2, because Python 2 does not optimize out the divide operation, at compile time, and my example sequence depends on that behavior. I was hoping to do a talk at a regional Python conference along these lines, so thought it might be a good idea to get suggestions and feedback, from the community. Regards, Vijay From torriem at gmail.com Wed Jul 13 15:03:34 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 13 Jul 2016 13:03:34 -0600 Subject: [OT] Compression of random binary data In-Reply-To: <960e3589-00c9-4f71-97b1-2ffed104436f@googlegroups.com> References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> <5785a790$0$1619$c3e8da3$5496439d@news.astraweb.com> <960e3589-00c9-4f71-97b1-2ffed104436f@googlegroups.com> Message-ID: <0502ae4a-e368-4552-4941-81c4584b57dc@gmail.com> On 07/13/2016 03:46 AM, jonas.thornvall at gmail.com wrote: > It is not that the data is not compressible i just need more chunks > or random data, it is the footprint of the algorithm that has a > certain it is a structure afterall albeit richer in interpretation > than the numerical field. Err, no, that does not apply to "random." If the data is truly random then it does not matter whether you have 5 bytes or 5 GB. There is no pattern to discern, and having more chunks of random data won't make it possible to compress. > You exchange size for computational complexity, but that may be true > for any compression algorithm. People are taking issue with your claim that you can compress random data. Clearly you cannot, by your own admission about requiring more chunks of data (see above), and also by the irrefutable logical principles Steven D'Aprano layed out. Probably time to mute this thread. It's not related to Python. From jana1972 at centrum.cz Wed Jul 13 15:33:50 2016 From: jana1972 at centrum.cz (Jahn) Date: Wed, 13 Jul 2016 21:33:50 +0200 Subject: Touch screen development in Python In-Reply-To: <8a12f1bd-f0ee-70bb-01cc-59c6f239afb6@schwertberger.de> References: <5783D5B4.28625.382C3B3B@jana1972.centrum.cz>, <8a12f1bd-f0ee-70bb-01cc-59c6f239afb6@schwertberger.de> Message-ID: <5786979E.23798.52B7F6@jana1972.centrum.cz> I would like to learn more how to write python based touch application for embedded system but I do not know what conditions a touch screen must have so that it will response to touch. Does anyone know? > On 11.07.2016 19:21, Jahn wrote: > > Does anyone use Python for developping applications that work with a touch screen? > > Yes. > > > You should probably specify the platform and the type of applications > that you're interested in. > > Mobiles (Android, iOS, Sailfish OS)? Windows 10 Tablets? Ubuntu Touch? > Embedded systems? > > > Regards, > > Dietmar > > -- > https://mail.python.org/mailman/listinfo/python-list --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus From grant.b.edwards at gmail.com Wed Jul 13 15:34:19 2016 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 13 Jul 2016 19:34:19 +0000 (UTC) Subject: [OT] Compression of random binary data References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> <5785a790$0$1619$c3e8da3$5496439d@news.astraweb.com> <960e3589-00c9-4f71-97b1-2ffed104436f@googlegroups.com> <0502ae4a-e368-4552-4941-81c4584b57dc@gmail.com> Message-ID: On 2016-07-13, Michael Torrie wrote: > On 07/13/2016 03:46 AM, jonas.thornvall at gmail.com wrote: >> It is not that the data is not compressible i just need more chunks >> or random data, it is the footprint of the algorithm that has a >> certain it is a structure afterall albeit richer in interpretation >> than the numerical field. Well, thanks for that. Not only was it authentic frontier gibberish... > Err, no, that does not apply to "random." If the data is truly > random then it does not matter whether you have 5 bytes or 5 GB. > There is no pattern to discern, and having more chunks of random > data won't make it possible to compress. You might as well be arguing with Ludwig Plutonium. -- Grant Edwards grant.b.edwards Yow! I wonder if I should at put myself in ESCROW!! gmail.com From marko at pacujo.net Wed Jul 13 15:35:48 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 13 Jul 2016 22:35:48 +0300 Subject: [OT] Compression of random binary data References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> <5785a790$0$1619$c3e8da3$5496439d@news.astraweb.com> <960e3589-00c9-4f71-97b1-2ffed104436f@googlegroups.com> <0502ae4a-e368-4552-4941-81c4584b57dc@gmail.com> Message-ID: <87a8hlz5yj.fsf@elektro.pacujo.net> Michael Torrie : > If the data is truly random then it does not matter whether you have 5 > bytes or 5 GB. There is no pattern to discern, and having more chunks > of random data won't make it possible to compress. That's true if "truly random" means "evenly distributed". You might have genuine random numbers with some other distribution, for example Gaussian: . Such sequences of random numbers may well be compressible. Marko From vineethmenneni33 at gmail.com Wed Jul 13 17:29:09 2016 From: vineethmenneni33 at gmail.com (vineeth menneni) Date: Wed, 13 Jul 2016 14:29:09 -0700 (PDT) Subject: problem writing excel sheet using python Message-ID: Hi I am finding it difficult to create a excel sheet using openpyxl or xlsxwriter. The problem is that i am loading a table data from MYSQL db which has 600k rows and 15 columns (approximately 100mb data). The error that the terminal shows is that "MemoryError". I just wanted to know if it is possible to create a excel sheet with the above said data in less than one minute using any packages in python. Thanks, Vineeth From rosuav at gmail.com Wed Jul 13 17:41:28 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jul 2016 07:41:28 +1000 Subject: problem writing excel sheet using python In-Reply-To: References: Message-ID: On Thu, Jul 14, 2016 at 7:29 AM, vineeth menneni wrote: > Hi I am finding it difficult to create a excel sheet using openpyxl or xlsxwriter. The problem is that i am loading a table data from MYSQL db which has 600k rows and 15 columns (approximately 100mb data). The error that the terminal shows is that "MemoryError". I just wanted to know if it is possible to create a excel sheet with the above said data in less than one minute using any packages in python. > You can probably build it progressively, row by row. That way, you shouldn't need to keep everything in memory at once. But beyond that, I can't say without seeing your code. ChrisA From torriem at gmail.com Wed Jul 13 17:50:04 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 13 Jul 2016 15:50:04 -0600 Subject: Touch screen development in Python In-Reply-To: <5786979E.23798.52B7F6@jana1972.centrum.cz> References: <5783D5B4.28625.382C3B3B@jana1972.centrum.cz> <8a12f1bd-f0ee-70bb-01cc-59c6f239afb6@schwertberger.de> <5786979E.23798.52B7F6@jana1972.centrum.cz> Message-ID: <5f901f8e-2cbf-ae3c-8e14-acc93a48b58f@gmail.com> On 07/13/2016 01:33 PM, Jahn wrote: > I would like to learn more how to write python based touch application > for embedded system but I do not know what conditions a touch screen must have so that it > will response to touch. > Does anyone know? These days GUI toolkits such as GTK+ or Qt provide convenient methods for interacting with touch displays including touch, dragging, gestures (pinch to zoom), multi-touch, etc. In its simplest form GUIs on touch screens are identical to GUIs with a mouse. Normal button widgets work great with fingers for example. Even slider adjusters work pretty much the same with a finger and with the mouse. More complicated things like pinch to zoom and multi-touch require a bit more help from the toolkit. As Deitmar said, you will have to get a lot more specific in your questions. From lawrencedo99 at gmail.com Wed Jul 13 18:24:11 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 13 Jul 2016 15:24:11 -0700 (PDT) Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> On Wednesday, July 13, 2016 at 6:22:31 PM UTC+12, Ian wrote: > ... don't call it "precision". How about ?mantissa length?, then. That sufficiently neutral for you? From lawrencedo99 at gmail.com Wed Jul 13 18:26:28 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 13 Jul 2016 15:26:28 -0700 (PDT) Subject: Were is a great place to Share your finished projects? In-Reply-To: <4724c168-570d-4938-9f92-b488afffcb4c@googlegroups.com> References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <4724c168-570d-4938-9f92-b488afffcb4c@googlegroups.com> Message-ID: <6ffaa4cc-c564-472f-be9e-539efbc0d97b@googlegroups.com> On Thursday, July 14, 2016 at 1:03:30 AM UTC+12, Rustom Mody wrote: > > Note further that Torvalds was told off by prof. Tanenbaum for his poor > quality unimaginative approach to Linux And today, Prof Tanenbaum is struggling to find a little niche where his Minix product can be of relevance, while the entire computing world is converging around Linux. Who was the ?poor quality unimaginative? one, again? From lawrencedo99 at gmail.com Wed Jul 13 18:29:27 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 13 Jul 2016 15:29:27 -0700 (PDT) Subject: problem writing excel sheet using python In-Reply-To: References: Message-ID: <5720542d-f61a-43e6-8047-52541fe25267@googlegroups.com> On Thursday, July 14, 2016 at 9:29:23 AM UTC+12, vineeth menneni wrote: > > .. I am finding it difficult to create a excel sheet using openpyxl or > xlsxwriter. How about writing ODF using odfpy instead? Microsoft Office is supposed to be ISO-26300-compliant, isn?t it? From timothy.c.delaney at gmail.com Wed Jul 13 18:39:47 2016 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Thu, 14 Jul 2016 08:39:47 +1000 Subject: [OT] Compression of random binary data In-Reply-To: <87a8hlz5yj.fsf@elektro.pacujo.net> References: <5783e7a6$0$1608$c3e8da3$5496439d@news.astraweb.com> <2a412b20-925c-4778-a71d-fad6266feab8@googlegroups.com> <578508ad$0$1614$c3e8da3$5496439d@news.astraweb.com> <5785a790$0$1619$c3e8da3$5496439d@news.astraweb.com> <960e3589-00c9-4f71-97b1-2ffed104436f@googlegroups.com> <0502ae4a-e368-4552-4941-81c4584b57dc@gmail.com> <87a8hlz5yj.fsf@elektro.pacujo.net> Message-ID: On 14 July 2016 at 05:35, Marko Rauhamaa wrote: > Michael Torrie : > > If the data is truly random then it does not matter whether you have 5 > > bytes or 5 GB. There is no pattern to discern, and having more chunks > > of random data won't make it possible to compress. > > That's true if "truly random" means "evenly distributed". You might have > genuine random numbers with some other distribution, for example > Gaussian: . Such > sequences of random numbers may well be compressible. > No one is saying that *all* random data is incompressible - in fact, some random samples are *very* compressible. A single sample of random data might look very much like the text of "A Midsummer Night's Dream" (especially if your method of choosing the random sample was to pick a book off a library shelf). But unless otherwise qualified, a claim of being able to compress random data is taken to mean any and all sets of random data. Anyway, that's going to be my only contribution to this thread. Tim Delaney From lawrencedo99 at gmail.com Wed Jul 13 18:42:18 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 13 Jul 2016 15:42:18 -0700 (PDT) Subject: Clean Singleton Docstrings In-Reply-To: References: Message-ID: 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 module. So all you need is to ensure that your Registry > evaluates to True in a boolean context, e. g. by putting something into it: And there are still those who think that Python?s lax acceptance of non-boolean values as booleans is a good idea... From __peter__ at web.de Wed Jul 13 19:54:18 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Jul 2016 01:54:18 +0200 Subject: Clean Singleton Docstrings References: Message-ID: 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 module. So all you need is to ensure that your Registry >> evaluates to True in a boolean context, e. g. by putting something into >> it: > > And there are still those who think that Python?s lax acceptance of > non-boolean values as booleans is a good idea... I don't think this particular problem serves as an argument for stricter handling of boolean expressions because the fix if object is not None: ... is not completely correct, either: $ cat demo.py no = False yes = True maybe = None $ pydoc3.4 demo.yes | head -n3 Help on bool in demo object: demo.yes = class bool(int) $ pydoc3.4 demo.no | head -n3 no Python documentation found for 'demo.no' $ pydoc3.5 demo.no | head -n3 Help on bool in demo object: demo.no = class bool(int) $ pydoc3.5 demo.maybe | head -n3 No Python documentation found for 'demo.maybe'. Use help() to get the interactive help utility. Use help(str) for help on the str class. Better would be to let the locate() function raise an exception along these lines: for part in parts[n:]: try: object = getattr(object, part) except AttributeError: # return None raise ImportError("Name ... not found in module ...") PS: Do the new hints """ Use help() to get the interactive help utility. Use help(str) for help on the str class. """ make any sense? Not to me, at this time of the day... From ian.g.kelly at gmail.com Wed Jul 13 20:14:51 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Jul 2016 18:14:51 -0600 Subject: Python Byte Code Hacking In-Reply-To: <57868D05.2040901@bravegnu.org> References: <57868D05.2040901@bravegnu.org> Message-ID: On Wed, Jul 13, 2016 at 12:48 PM, Vijay Kumar wrote: > Hi Everyone, > I wrote an article on Python byte code hacking. The article is available > from http://www.bravegnu.org/blog/python-byte-code-hacks.html The article > uses an incremental approach for explaining Python's code objects and how to > modify them. Unfortunately, I am stuck with Python 2, because Python 2 does > not optimize out the divide operation, at compile time, and my example > sequence depends on that behavior. def f(): return g(6, 2) def g(a, b): return a // b Now it can't optimize out the operation. From ian.g.kelly at gmail.com Wed Jul 13 20:25:33 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Jul 2016 18:25:33 -0600 Subject: Clean Singleton Docstrings In-Reply-To: References: Message-ID: On Wed, Jul 13, 2016 at 5:54 PM, Peter Otten <__peter__ at web.de> wrote: > 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 module. So all you need is to ensure that your Registry >>> evaluates to True in a boolean context, e. g. by putting something into >>> it: >> >> And there are still those who think that Python?s lax acceptance of >> non-boolean values as booleans is a good idea... > > I don't think this particular problem serves as an argument for stricter > handling of boolean expressions because the fix > > if object is not None: ... > > is not completely correct, either: A better fix would be to have the locate function raise an exception if the thing is not found instead of returning None. From vineethmenneni33 at gmail.com Wed Jul 13 20:39:48 2016 From: vineethmenneni33 at gmail.com (vineeth menneni) Date: Wed, 13 Jul 2016 17:39:48 -0700 (PDT) Subject: problem writing excel sheet using python In-Reply-To: References: Message-ID: The belwo is the code, I have also tried writing it row by row with xlsxwrites passing argument constant_memory:True. I donot know if my looping code is ineffective. for req_param in request.GET.get("Req-Tables").split(","): sheet_names.append(req_param) title.append(req_param) report_data=db_exec_query( param_table_map[req_param]) sheet_names[key]=wb.active if key!=0: sheet_names[key]=wb.create_sheet(title= (title[key][:15] ) if title[key] > 15 else title[key]) req_param, sys.getsizeof(report_data)) count= 0 for r in report_data: try: sheet_names[key].append(r) except: sheet_names[key].append(str(c).decode('cp1252') for c in r) key=key+1 wb.save(response) On Wednesday, July 13, 2016 at 2:41:43 PM UTC-7, Chris Angelico wrote: > On Thu, Jul 14, 2016 at 7:29 AM, vineeth menneni > wrote: > > Hi I am finding it difficult to create a excel sheet using openpyxl or xlsxwriter. The problem is that i am loading a table data from MYSQL db which has 600k rows and 15 columns (approximately 100mb data). The error that the terminal shows is that "MemoryError". I just wanted to know if it is possible to create a excel sheet with the above said data in less than one minute using any packages in python. > > > > You can probably build it progressively, row by row. That way, you > shouldn't need to keep everything in memory at once. But beyond that, > I can't say without seeing your code. > > ChrisA From ian.g.kelly at gmail.com Wed Jul 13 20:45:30 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Jul 2016 18:45:30 -0600 Subject: Curious Omission In New-Style Formats In-Reply-To: <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> Message-ID: On Wed, Jul 13, 2016 at 4:24 PM, Lawrence D?Oliveiro wrote: > On Wednesday, July 13, 2016 at 6:22:31 PM UTC+12, Ian wrote: > >> ... don't call it "precision". > > How about ?mantissa length?, then. That sufficiently neutral for you? That makes even less sense for integers. From python at mrabarnett.plus.com Wed Jul 13 20:59:16 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 Jul 2016 01:59:16 +0100 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> Message-ID: <9ee2711a-7789-c86e-ed77-fc421752a544@mrabarnett.plus.com> On 2016-07-14 01:45, Ian Kelly wrote: > On Wed, Jul 13, 2016 at 4:24 PM, Lawrence D?Oliveiro > wrote: >> On Wednesday, July 13, 2016 at 6:22:31 PM UTC+12, Ian wrote: >> >>> ... don't call it "precision". >> >> How about ?mantissa length?, then. That sufficiently neutral for you? > > That makes even less sense for integers. > Perhaps "precision or whatever"? :-) From lawrencedo99 at gmail.com Wed Jul 13 23:39:24 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 13 Jul 2016 20:39:24 -0700 (PDT) Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> Message-ID: <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> On Thursday, July 14, 2016 at 12:46:26 PM UTC+12, Ian wrote: > On Wed, Jul 13, 2016 at 4:24 PM, Lawrence D?Oliveiro wrote: >> On Wednesday, July 13, 2016 at 6:22:31 PM UTC+12, Ian wrote: >> >>> ... don't call it "precision". >> >> How about ?mantissa length?, then. That sufficiently neutral for you? > > That makes even less sense for integers. Why? From torriem at gmail.com Thu Jul 14 00:07:08 2016 From: torriem at gmail.com (Michael Torrie) Date: Wed, 13 Jul 2016 22:07:08 -0600 Subject: Were is a great place to Share your finished projects? In-Reply-To: References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> Message-ID: <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> On 07/13/2016 01:00 AM, Chris Angelico wrote: > On Wed, Jul 13, 2016 at 4:44 PM, Steven D'Aprano > wrote: >> Even if Github was 100% open source with no proprietary extensions, and the >> *technical* cost of leaving was low, the single-network effect would still lock >> you in, which leaves you (to some degree) at the mercy of Github's management. >> Don't like the fact that they run their servers on electricity made from >> burning puppies and the tears of little children? Too bad, what are you going >> to do, move your project to some backwater VCS where nobody ever goes? You >> might as well be on AOL for all anyone will ever find your project. > > So what're you going to do? Move *now* to some backwater where nobody > ever goes, just in case GitHub ever turns evil? No, you just run git as it was designed to be used. In a completely decentralized fashion. If Github had honored this aspect of git, there'd be no problem. A repo on GitHub would be just one of many publicly-facing git repos. But by refusing to allow federated pull requests, GitHub has most definitely created lock-in. I understand that in Python's case, pure cost wins out. Python.org could host a GitLab instance, which contains the repo tools plus ticket tracking, etc, and ordinary developers could push their changes to their own public git repos and send in pull requests and it would all work swimmingly. However this comes at considerable cost in terms of maintenance of the server and server software. So I can understand the allure of GitHub. It's shiny and free-ish. From no.email at nospam.invalid Thu Jul 14 00:49:10 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 13 Jul 2016 21:49:10 -0700 Subject: Were is a great place to Share your finished projects? References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> Message-ID: <87poqgese1.fsf@jester.gateway.pace.com> Michael Torrie writes: > So I can understand the allure of GitHub. It's shiny and free-ish. Savannah.nongnu.org is a nice free host for free software projects. I suppose it's less shiny than Github. On the other hand, Github is written in Ruby--what self-respecting Pythonista would stand for that?! ;-) From ian.g.kelly at gmail.com Thu Jul 14 01:18:43 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Jul 2016 23:18:43 -0600 Subject: Curious Omission In New-Style Formats In-Reply-To: <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> Message-ID: On Wed, Jul 13, 2016 at 9:39 PM, Lawrence D?Oliveiro wrote: > On Thursday, July 14, 2016 at 12:46:26 PM UTC+12, Ian wrote: >> On Wed, Jul 13, 2016 at 4:24 PM, Lawrence D?Oliveiro wrote: >>> On Wednesday, July 13, 2016 at 6:22:31 PM UTC+12, Ian wrote: >>> >>>> ... don't call it "precision". >>> >>> How about ?mantissa length?, then. That sufficiently neutral for you? >> >> That makes even less sense for integers. > > Why? Because integers don't have a mantissa. Side note, neither do floating point numbers, really; what is often called the mantissa is more properly known as the significand. But integers don't have that either. Back to naming, I think the best you could do would just be something utterly generic like "formatted size". It doesn't help that in some cases it represents a minimum size and in other cases a maximum, so you can't even characterize it with that. From steve+comp.lang.python at pearwood.info Thu Jul 14 03:43:37 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jul 2016 17:43:37 +1000 Subject: Python Byte Code Hacking References: <57868D05.2040901@bravegnu.org> Message-ID: <578742ab$0$1501$c3e8da3$5496439d@news.astraweb.com> On Thursday 14 July 2016 10:14, Ian Kelly wrote: > On Wed, Jul 13, 2016 at 12:48 PM, Vijay Kumar > wrote: >> Hi Everyone, >> I wrote an article on Python byte code hacking. The article is available >> from http://www.bravegnu.org/blog/python-byte-code-hacks.html The article >> uses an incremental approach for explaining Python's code objects and how to >> modify them. Unfortunately, I am stuck with Python 2, because Python 2 does >> not optimize out the divide operation, at compile time, and my example >> sequence depends on that behavior. > > def f(): > return g(6, 2) > > def g(a, b): > return a // b > > Now it can't optimize out the operation. I haven't had time to read the article yet, but is Vijay talking about Python's peekhole optimizer? It does constant folding, so that arithmetic expressions containing *only* constants will compile to the result: def f(): return 6//2 # compiles to "return 3" The simplest way to defeat that is to use a variable: def f(): x = 6 return x//2 The peephole optimizer is simple-minded enough that it won't pre-compute that. Let's check: py> import dis py> def f(): return 6//2 ... py> dis.dis(f) 1 0 LOAD_CONST 3 (3) 3 RETURN_VALUE py> def f(): ... x = 6 ... return x//2 ... py> dis.dis(f) 2 0 LOAD_CONST 1 (6) 3 STORE_FAST 0 (x) 3 6 LOAD_FAST 0 (x) 9 LOAD_CONST 2 (2) 12 BINARY_FLOOR_DIVIDE 13 RETURN_VALUE -- Steve From steve+comp.lang.python at pearwood.info Thu Jul 14 03:47:17 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jul 2016 17:47:17 +1000 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> Message-ID: <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> On Thursday 14 July 2016 15:18, Ian Kelly wrote: > Side note, neither do floating point numbers, really; what is often > called the mantissa is more properly known as the significand. But > integers don't have that either. Er, then what's a mantissa if it's not what people call a float's mantissa? What makes you say it is "more properly" known as the significand? I'm not necessarily disputing what you say, I'm wondering what is your justification for it. -- Steve From steve+comp.lang.python at pearwood.info Thu Jul 14 04:16:44 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 14 Jul 2016 18:16:44 +1000 Subject: Compression Message-ID: <57874a72$0$2910$c3e8da3$76491128@news.astraweb.com> I thought I'd experiment with some of Python's compression utilities. First I thought I'd try compressing some extremely non-random data: py> import codecs py> data = "something non-random."*1000 py> len(data) 21000 py> len(codecs.encode(data, 'bz2')) 93 py> len(codecs.encode(data, 'zip')) 99 That's really good results. Both the bz2 and Gzip compressors have been able to compress nearly all of the redundancy in the data. What if we shuffle the data so it is more random? py> import random py> data = list(data) py> random.shuffle(data) py> data = ''.join(data) py> len(data); len(codecs.encode(data, 'bz2')) 21000 10494 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 a quarter of the space. What if we try compressing data which has already been compressed? py> cdata = codecs.encode(data, 'bz2') py> len(cdata); len(codecs.encode(cdata, 'bz2')) 15220 15688 There's no shrinkage at all; compression has actually increased the size. What if we use some data which is random, but heavily biased? py> values = string.ascii_letters + ("AAAAAABB")*100 py> data = ''.join(random.choice(values) for i in range(21000)) py> len(data); len(codecs.encode(data, 'bz2')) 21000 5034 So we can see that the bz2 compressor is capable of making use of deviations from uniformity, but the more random the initial data is, the less effective is will be. -- Steve From miragewebstudio12 at gmail.com Thu Jul 14 04:54:02 2016 From: miragewebstudio12 at gmail.com (Mirage Web Studio) Date: Thu, 14 Jul 2016 14:24:02 +0530 Subject: problem writing excel sheet using python In-Reply-To: References: Message-ID: <75E21597-0E60-486A-AC70-09C92ECD97A7@gmail.com> On July 14, 2016 2:59:09 AM GMT+05:30, vineeth menneni wrote: >Hi I am finding it difficult to create a excel sheet using openpyxl or >xlsxwriter. The problem is that i am loading a table data from MYSQL db >which has 600k rows and 15 columns (approximately 100mb data). The >error that the terminal shows is that "MemoryError". I just wanted to >know if it is possible to create a excel sheet with the above said data >in less than one minute using any packages in python. > >Thanks, >Vineeth >-- >https://mail.python.org/mailman/listinfo/python-list Try saving data in csv format an then import it in excel George From __peter__ at web.de Thu Jul 14 04:59:05 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Jul 2016 10:59:05 +0200 Subject: Compression References: <57874a72$0$2910$c3e8da3$76491128@news.astraweb.com> Message-ID: 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 a quarter of the space. It didn't find any redundancy, it found the two unused bits: >>> math.log(len(string.ascii_letters), 2) 5.700439718141093 >>> 21000./8*_ 14963.654260120367 From rosuav at gmail.com Thu Jul 14 07:07:26 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jul 2016 21:07:26 +1000 Subject: Compression In-Reply-To: <57874a72$0$2910$c3e8da3$76491128@news.astraweb.com> References: <57874a72$0$2910$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Jul 14, 2016 at 6:16 PM, 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 a quarter of the space. What it found was an imbalance in the frequencies of byte values - you used 52 values lots of times, and the other 204 never. Huffman coding means those 52 values will get fairly short codes, and if you happened to have just one or two other byte values, they'd be represented by longer codes. It's like the Morse code - by encoding some letters with very short sequences (dot followed by end-of-letter for E, dash followed by end-of-letter for T) and others with much longer sequences (dash-dot-dot-dash-EOL for X), it manages a fairly compact representation of typical English text. The average Morse sequence length for a letter is 3.19, but on real-world data... well, I used the body of your email as sample text (yes, I'm aware it's not all English), and calculated a weighted average of 2.60. (Non-alphabetics are ignored, and the text is case-folded.) Using the entire text of Gilbert & Sullivan's famous operettas, or the text of "The Beauty Stone", or the wikitext source of the Wikipedia article on Morse code, gave similar results (ranging from 2.56 to 2.60); interestingly, a large slab of Lorem Ipsum skewed the numbers slightly lower (2.52), not higher as I was afraid it would, being more 'random'. Further example: os.urandom() returns arbitrary byte values, and (in theory, at least) has equal probability of returning every possible value. Base 64 encoding that data makes three bytes come out as four. Check this out: >>> data = os.urandom(21000) >>> len(base64.b64encode(data)) # just to make sure 28000 >>> len(codecs.encode(data, 'bz2')) 21458 >>> len(codecs.encode(base64.b64encode(data), 'bz2')) 21290 When you remove the redundancy in b64-encoded data, you basically... get back what you started with. (Curiously, several repeated os.urandommings showed consistent results to the above - 214xx for direct 'compression' vs 212xx for b64-then-compress. But in both cases, it's larger than the 21000 bytes of input.) ChrisA From mal at europython.eu Thu Jul 14 07:44:03 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 14 Jul 2016 13:44:03 +0200 Subject: EuroPython 2016: Getting your badge & ticket IDs Message-ID: <57877B03.8080805@europython.eu> For this year, we have reconsidered the way we give out badges to try to reduce the queue lengths and your waiting time. Badges distributed based on ticket ID ------------------------------------- To make finding badges easier, we have printed the ticket ID on each badge and will distribute badges based on ticket ID ranges. Each queue will be for one ticket ID range. Finding your ticket ID ---------------------- We will send all attendees an email with their ticket ID, but you can also look on the website to find your ticket ID. Simply log in and then check the ticket page to find your ticket preview: https://ep2016.europython.eu/p3/tickets/ The ticket ID is listed at the bottom of the ticket preview. If you forget your ticket ID, no worries. We will have a number of volunteers at the registration desk with a mobile app to quickly search the ticket database for your ticket. Simply ask them to help you find the right queue and you?re all set. Should they have trouble finding your ticket in the database, you?ll be asked to visit the registration counter to sort out any issues. Please check your ticket ------------------------ Please note that in order to find your tickets, the person who bought the ticket will have to have assigned the ticket to you, as we?ve outline in a previous blog post: http://blog.europython.eu/post/146895278207/europython-2016-please-configure-your-tickets We already know that there are a number of tickets which have not been assigned to the final attendee, so please double check that you can see your ticket on the ticket page after logging in to the website: https://ep2016.europython.eu/p3/tickets/ If you cannot find your ticket on that page, please ask the person who bought the ticket for you. The process for assigning the ticket is described in our blog post on the topic. If all else fails, simply write to our helpdesk at europython.eu for help. Opening times of the registration desks --------------------------------------- These are the planned opening times of the registration desks where you can pick up your badge (or buy conference tickets or day passes). * Sunday, July 17 In the afternoon at 16:00, we will open the registration desk at the main conference venue, the Euskalduna Conference Center (ECC). It?ll stay open until around 19:00. You will be able to pick up the badges for your already purchased tickets as well as buy new ones at this registration desk. * Monday, July 18 The registration desk at the conference venue, the Euskalduna Conference Center (ECC), will open at 08:00 on Monday. Conference bag distribution --------------------------- We will do the bag stuffing on Sunday, starting at around 16:00 at the ECC. You?re welcome to come and help. The stuffed bags will then be distributed starting on Monday. With gravitational regards, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/753553441239293954 Thanks. From vek.m1234 at gmail.com Thu Jul 14 07:48:26 2016 From: vek.m1234 at gmail.com (Veek. M) Date: Thu, 14 Jul 2016 17:18:26 +0530 Subject: Scapy: sniff(filter='icmp', iface='ppp0', prn=icmp_callback) Message-ID: #!/usr/bin/python import logging logging.getLogger("scapy.runtime").setLevel(logging.ERROR) from scapy.all import TCP, IP, ICMP, sniff def ip_callback(pkt): print '--------------------------- IP--------------------------' pkt.show() print 'IP', pkt.src, pkt.sport, '--->', pkt.dst, pkt.dport def icmp_callback(pkt): print '--------------------------- ICMP --------------------------' print pkt.show() def tcp_callback(pkt): pkt.show() print 'TCP', pkt.src, pkt.sport, '--->', pkt.dst, pkt.dport def udp_callback(pkt): pkt.show() print 'UDP', pkt.src, pkt.sport, '--->', pkt.dst, pkt.dport print 'hello' sniff(filter='icmp', iface='ppp0', prn=icmp_callback) I get: deathstar> python myscapy.py hello and nothing further when ping -c 2 8.8.8.8 runs - why?? Sometimes though it works (once in a blue moon) and i get the show output. From ian.g.kelly at gmail.com Thu Jul 14 10:30:05 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Jul 2016 08:30:05 -0600 Subject: Curious Omission In New-Style Formats In-Reply-To: <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Jul 14, 2016 1:52 AM, "Steven D'Aprano" wrote: > > On Thursday 14 July 2016 15:18, Ian Kelly wrote: > > > Side note, neither do floating point numbers, really; what is often > > called the mantissa is more properly known as the significand. But > > integers don't have that either. > > > Er, then what's a mantissa if it's not what people call a float's mantissa? > > What makes you say it is "more properly" known as the significand? > > I'm not necessarily disputing what you say, I'm wondering what is your > justification for it. http://mathworld.wolfram.com/Significand.html http://mathworld.wolfram.com/Mantissa.html The significand of -3.14159 is the sequence of digits 314159. The mantissa of -3.14159 is the number 0.85841. I don't have a copy of the IEEE-754 standard, but I believe that it also uses the term "significand" and specifically avoids the term "mantissa". From robert.kern at gmail.com Thu Jul 14 11:17:35 2016 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 14 Jul 2016 16:17:35 +0100 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2016-07-14 15:30, Ian Kelly wrote: > On Jul 14, 2016 1:52 AM, "Steven D'Aprano" > wrote: >> >> On Thursday 14 July 2016 15:18, Ian Kelly wrote: >> >>> Side note, neither do floating point numbers, really; what is often >>> called the mantissa is more properly known as the significand. But >>> integers don't have that either. >> >> Er, then what's a mantissa if it's not what people call a float's mantissa? >> >> What makes you say it is "more properly" known as the significand? >> >> I'm not necessarily disputing what you say, I'm wondering what is your >> justification for it. > > http://mathworld.wolfram.com/Significand.html > http://mathworld.wolfram.com/Mantissa.html > > The significand of -3.14159 is the sequence of digits 314159. The > mantissa of -3.14159 is the number 0.85841. > > I don't have a copy of the IEEE-754 standard, but I believe that it > also uses the term "significand" and specifically avoids the term > "mantissa". Confirmed. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From marko at pacujo.net Thu Jul 14 12:02:27 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 14 Jul 2016 19:02:27 +0300 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87shvccing.fsf@elektro.pacujo.net> Ian Kelly : > The significand of -3.14159 is the sequence of digits 314159. The > mantissa of -3.14159 is the number 0.85841. Fight it all you want. However: In American English, the original word for [significand] seems to have been mantissa (Burks[1] et al.), and this usage remains common in computing and among computer scientists. This digit string is referred to as the significand, mantissa, or coefficient. and, FWIW: Liukulukuun kuuluu nelj? osaa: etumerkki (s), mantissa (m), kantaluku (k) ja eksponentti (c). [...] x = (?1)^s mk^c. Marko From ian.g.kelly at gmail.com Thu Jul 14 13:10:44 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Jul 2016 11:10:44 -0600 Subject: Curious Omission In New-Style Formats In-Reply-To: <87shvccing.fsf@elektro.pacujo.net> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> Message-ID: On Thu, Jul 14, 2016 at 10:02 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> The significand of -3.14159 is the sequence of digits 314159. The >> mantissa of -3.14159 is the number 0.85841. > > Fight it all you want. However: > > In American English, the original word for [significand] seems to > have been mantissa (Burks[1] et al.), and this usage remains common > in computing and among computer scientists. > https://en.wikipedia.org/wiki/Significand#Use_of_.22mantissa.22> Just because it's already common to use the wrong term doesn't mean the usage should be promulgated further. From marko at pacujo.net Thu Jul 14 13:30:27 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 14 Jul 2016 20:30:27 +0300 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> Message-ID: <87vb08xh3g.fsf@elektro.pacujo.net> Ian Kelly : > On Thu, Jul 14, 2016 at 10:02 AM, Marko Rauhamaa wrote: >> In American English, the original word for [significand] seems to >> have been mantissa (Burks[1] et al.), and this usage remains >> common in computing and among computer scientists. > https://en.wikipedia.org/wiki/Significand#Use_of_.22mantissa.22> > > Just because it's already common to use the wrong term doesn't mean > the usage should be promulgated further. Where do you get the idea that the common usage is "wrong?" What do you use as a standard? Marko From crtbraille at gmail.com Thu Jul 14 13:35:23 2016 From: crtbraille at gmail.com (Carter Temm) Date: Thu, 14 Jul 2016 12:35:23 -0500 Subject: Don't understand why I'm getting this error Message-ID: 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 change TIME = argv to TIME = 2 It does exactly what I intended, no issues. What's wrong? Thanks for any help. Also, The error I get when trying to run is: Traceback (most recent call last): File "sound_recorder.py", line 21, in for i in range(0, int(RATE / CHUNK * TIME)): OverflowError: range() result has too many items? From sohcahtoa82 at gmail.com Thu Jul 14 13:51:57 2016 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Thu, 14 Jul 2016 10:51:57 -0700 (PDT) Subject: Don't understand why I'm getting this error In-Reply-To: References: Message-ID: <97e65526-f468-4dc9-8b39-b064cb30ccef@googlegroups.com> On Thursday, July 14, 2016 at 10:39:35 AM UTC-7, 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 change > > TIME = argv > > to > > TIME = 2 > > It does exactly what I intended, no issues. What's wrong? Thanks for any help. > > > > Also, The error I get when trying to run is: Traceback (most recent call last): File "sound_recorder.py", line 21, in for i in range(0, int(RATE / CHUNK * TIME)): OverflowError: range() result has too many items? argv is a list containing the name (or path depending on OS) of the script and all the command line parameters passed to it. I suspect that the problem is that the contents of argv will be strings, but you need TIME to be an integer. Even if you use "python myScript.py 5", argv[1] will be a string because Python doesn't know if "5" is actually supposed to be an integer, or if your script might be expecting a file name, and you have a file named "5". An OverflowError when using range(..) usually means your range is too big. I'm assuming you're using Python 2.x. Try printing int(RATE / CHUNK * TIME) to see if the value is what you're expecting. Also consider using xrange(..). It doesn't require the entire list to be stored in memory. From rgaddi at highlandtechnology.invalid Thu Jul 14 14:06:17 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Thu, 14 Jul 2016 18:06:17 -0000 (UTC) Subject: Don't understand why I'm getting this error References: Message-ID: 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 change > > TIME = argv > > to > > TIME = 2 > > It does exactly what I intended, no issues. What's wrong? Thanks for any help. > > Also, The error I get when trying to run is: Traceback (most recent call last): File "sound_recorder.py", line 21, in for i in range(0, int(RATE / CHUNK * TIME)): OverflowError: range() result has too many items? > Offhand, I'll bet that you're getting TIME="2" instead of TIME=2. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From __peter__ at web.de Thu Jul 14 14:17:16 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 Jul 2016 20:17:16 +0200 Subject: Don't understand why I'm getting this error References: Message-ID: 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 change > > TIME = argv > > to > > TIME = 2 > > It does exactly what I intended, no issues. What's wrong? Thanks for any > help. > > > > Also, The error I get when trying to run is: Traceback (most recent call > last): File "sound_recorder.py", line 21, in for i in range(0, > int(RATE / CHUNK * TIME)): OverflowError: range() result has too many > items? RATE/CHUNK is an integer, but TIME when extracted from sys.argv is a str. The * operator tells python to repeat the string RATE/CHUNK times: >>> RATE = 44100 >>> CHUNK = 1024 >>> TIME = "2" >>> RATE/CHUNK * TIME '2222222222222222222222222222222222222222222' You need to convert TIME to an int before evaluating the expression to get the expected result: >>> RATE/CHUNK * int(TIME) 86 From hasan.diwan at gmail.com Thu Jul 14 15:04:00 2016 From: hasan.diwan at gmail.com (hasan.diwan at gmail.com) Date: Thu, 14 Jul 2016 12:04:00 -0700 (PDT) Subject: Were is a great place to Share your finished projects? In-Reply-To: References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> Message-ID: Michael Torrie writes: >I understand that in Python's case, pure cost wins out. Python.org >could host a GitLab instance, which contains the repo tools plus ticket >tracking, etc, and ordinary developers could push their changes to their >own public git repos and send in pull requests and it would all work >swimmingly. However this comes at considerable cost in terms of >maintenance of the server and server software. So I can understand the >allure of GitHub. It's shiny and free-ish. Python's primary repository is Mercurial (hg.python.org), not Git. Were python to switch, it wouldn't be too much work to just deploy gitlab (or whatever) instead of mercurial. However, I see nothing git offers over mercurial. -- H From tjreedy at udel.edu Thu Jul 14 15:34:42 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Jul 2016 15:34:42 -0400 Subject: Were is a great place to Share your finished projects? In-Reply-To: References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> Message-ID: On 7/14/2016 3:04 PM, hasan.diwan at gmail.com wrote: > Python's primary repository is Mercurial (hg.python.org), not Git. CPython's current repository .... Ditto for the PSF Python docs. > Were python to switch, Like it or not, CPython and the Docs are moving to git and github. PEPs and the devguide have already been moved. -- Terry Jan Reedy From nir36g at gmail.com Thu Jul 14 15:40:57 2016 From: nir36g at gmail.com (Nir Cohen) Date: Thu, 14 Jul 2016 12:40:57 -0700 (PDT) Subject: Packaging multiple wheels in the same package In-Reply-To: References: <0310c596-2f5b-4cca-8059-6e6a81acc35f@googlegroups.com> <577D573B.9040102@stoneleaf.us> <47e86dc2-1196-463f-a3ea-727935879912@googlegroups.com> <578657B2.4020604@stoneleaf.us> Message-ID: Appreciate it! Will do! From lawrencedo99 at gmail.com Thu Jul 14 19:04:32 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 14 Jul 2016 16:04:32 -0700 (PDT) Subject: Were is a great place to Share your finished projects? In-Reply-To: References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> Message-ID: On Friday, July 15, 2016 at 7:04:14 AM UTC+12, hasan... at gmail.com wrote: > ... I see nothing git offers over mercurial. Except greater productivity. From 007brendan at gmail.com Thu Jul 14 19:13:21 2016 From: 007brendan at gmail.com (Brendan Abel) Date: Thu, 14 Jul 2016 16:13:21 -0700 Subject: Were is a great place to Share your finished projects? In-Reply-To: References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> Message-ID: A lot of these arguments and points have already been made and hashed out on the python-dev list. There's a very good article that one of the python core developers wrote about the decision to move to github http://www.snarky.ca/the-history-behind-the-decision-to-move-python-to-github Basically, maintaining an open source git server, bug tracker, etc. would have cost time and money, and historically very few people were willing to contribute those, especially the people who were the most opinionated on the desire to remain "pure to open source". Github gives all these things away for free. And pretty much every python developer has already used github for other projects. In the article he makes a good point that if you're that worried about always using open-source, then you shouldn't be using gmail, or twitter, or even automobiles, since they all use software that is closed-source. At some point, paying for software just makes sense. On Thu, Jul 14, 2016 at 12:34 PM, Terry Reedy wrote: > On 7/14/2016 3:04 PM, hasan.diwan at gmail.com wrote: > > Python's primary repository is Mercurial (hg.python.org), not Git. >> > > CPython's current repository .... > Ditto for the PSF Python docs. > > Were python to switch, >> > > Like it or not, CPython and the Docs are moving to git and github. > PEPs and the devguide have already been moved. > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list > From lawrencedo99 at gmail.com Thu Jul 14 19:26:26 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 14 Jul 2016 16:26:26 -0700 (PDT) Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> Message-ID: On Friday, July 15, 2016 at 5:11:46 AM UTC+12, Ian wrote: > Just because it's already common to use the wrong term doesn't mean > the usage should be promulgated further. Yes of course. The only logically-acceptable meaning of ?mantissa? is ?female mantis?, and any other usage is to be the immediate target of derisive laughter and scorn. From ian.g.kelly at gmail.com Thu Jul 14 20:17:09 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 14 Jul 2016 18:17:09 -0600 Subject: Curious Omission In New-Style Formats In-Reply-To: <87vb08xh3g.fsf@elektro.pacujo.net> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> Message-ID: On Jul 14, 2016 11:37 AM, "Marko Rauhamaa" wrote: > > Ian Kelly : > > On Thu, Jul 14, 2016 at 10:02 AM, Marko Rauhamaa wrote: > >> In American English, the original word for [significand] seems to > >> have been mantissa (Burks[1] et al.), and this usage remains > >> common in computing and among computer scientists. >> https://en.wikipedia.org/wiki/Significand#Use_of_.22mantissa.22> > > > > Just because it's already common to use the wrong term doesn't mean > > the usage should be promulgated further. > > Where do you get the idea that the common usage is "wrong?" What do you > use as a standard? Is it "wrong" to consider some usages "wrong"? By what standard? I'm not interested in arguing over philosophy, so I won't. From steve at pearwood.info Thu Jul 14 20:39:05 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 15 Jul 2016 10:39:05 +1000 Subject: Were is a great place to Share your finished projects? References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> Message-ID: <578830ac$0$1621$c3e8da3$5496439d@news.astraweb.com> On Fri, 15 Jul 2016 09:04 am, Lawrence D?Oliveiro wrote: > On Friday, July 15, 2016 at 7:04:14 AM UTC+12, hasan... at gmail.com wrote: > >> ... I see nothing git offers over mercurial. > > Except greater productivity. That has not been even close to my experience. And I don't mean my *personal* experience. About seven years ago, the senior technical manager at my work chose hg over git. When he left to go to greener pastures, the dev team took about 30 seconds to to reverse his decision and migrate to git, after which the level of VCS-related screw-ups and queries went through the roof. To give you an idea of how screwed up things are, even though I'm not one of the developer team, and have never pushed a thing into the code repositories (I have pushed into documentation repos), somehow according to "git blame" I'm responsible for a bunch of code. (If I'd been paid for this code I didn't write, I wouldn't mind so much...) -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Thu Jul 14 20:45:46 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 15 Jul 2016 10:45:46 +1000 Subject: Were is a great place to Share your finished projects? References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> Message-ID: <5788323c$0$1620$c3e8da3$5496439d@news.astraweb.com> On Fri, 15 Jul 2016 09:13 am, Brendan Abel wrote: > In the article he makes a good point that if > you're that worried about always using open-source, then you shouldn't be > using gmail, or twitter, or even automobiles, It's not a good point. I don't use gmail, or twitter, and if I could find a car that didn't rely on closed-source code, I would use it. Just because choice is limited and its hard or impossible to get open-source engines doesn't mean that closed-source engines are a good idea. > since they all use software > that is closed-source. ?At some point, paying for software just makes > sense. No, that doesn't follow. The opposite of "open source" is not "paying for software". You can pay somebody to maintain your open source repo just as easily as you can pay somebody else to maintain their own closed source repo. I watched the discussion on Python-Dev that decided to move to github, and there were completely viable open source hg alternatives. Although nobody was quite crass enough to come right out and say it, the alternatives were all dismissed because they weren't Github, because "everyone uses github". -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From lawrencedo99 at gmail.com Thu Jul 14 21:08:57 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Thu, 14 Jul 2016 18:08:57 -0700 (PDT) Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> Message-ID: On Friday, July 15, 2016 at 12:17:27 PM UTC+12, Ian wrote: > Is it "wrong" to consider some usages "wrong"? By what standard? Do you say ?head over heels? or ?heels over head?? ?Burgle? or ?burglari{s,z}e?? From ben+python at benfinney.id.au Thu Jul 14 21:11:20 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 15 Jul 2016 11:11:20 +1000 Subject: Were is a great place to Share your finished projects? References: <857fd6uogt.fsf@benfinney.id.au> <85lh16tjg9.fsf@benfinney.id.au> <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> <5788323c$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: <854m7ru2mf.fsf@benfinney.id.au> Steven D'Aprano writes: > On Fri, 15 Jul 2016 09:13 am, Brendan Abel wrote: > > since they all use software that is closed-source. ?At some point, > > paying for software just makes sense. Is it 1998 again already? Or am I expecting too much that people involved in software in the 21st century should not fall for the canard of ?why don't you want to pay for software?, because it is *completely irrelevant* to the issue of software freedom. So please, stop repeating that canard. Of course paying for software makes sense. That in no way entails vendor lock-in of valuable community data, and we should not be paying for that. > No, that doesn't follow. The opposite of "open source" is not "paying > for software". You can pay somebody to maintain your open source repo > just as easily as you can pay somebody else to maintain their own > closed source repo. Yes. Likewise, just because you don't hand any money to someone doesn't mean you are free from vendor lock-in and proprietary protocols. One day perhaps we won't need to repeat that for it to be understood. > I watched the discussion on Python-Dev that decided to move to github, > and there were completely viable open source hg alternatives. Although > nobody was quite crass enough to come right out and say it, the > alternatives were all dismissed because they weren't Github, because > "everyone uses github". Fortunately there are a zillion software projects who can still choose a hosting provider that won't lock them in, and good free-software hosting alternatives like Pagure are beginning to appear. Not all is lost. -- \ ?The Initial Mystery that attends any journey is: how did the | `\ traveller reach his starting point in the first place?? ?Louise | _o__) Bogan, _Journey Around My Room_ | Ben Finney From marko at pacujo.net Fri Jul 15 02:06:32 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 15 Jul 2016 09:06:32 +0300 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> Message-ID: <87lh13xwnr.fsf@elektro.pacujo.net> Ian Kelly : > On Jul 14, 2016 11:37 AM, "Marko Rauhamaa" wrote: >> Where do you get the idea that the common usage is "wrong?" What do >> you use as a standard? > > Is it "wrong" to consider some usages "wrong"? By what standard? > > I'm not interested in arguing over philosophy, so I won't. Common usage among educated speakers ordinarily is the yardstick for language questions. However, I'm cool with "cuz I say so." Marko From antoon.pardon at rece.vub.ac.be Fri Jul 15 03:54:25 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 15 Jul 2016 09:54:25 +0200 Subject: Curious Omission In New-Style Formats In-Reply-To: <87lh13xwnr.fsf@elektro.pacujo.net> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> Message-ID: <578896B1.1030104@rece.vub.ac.be> Op 15-07-16 om 08:06 schreef Marko Rauhamaa: > Ian Kelly : > >> On Jul 14, 2016 11:37 AM, "Marko Rauhamaa" wrote: >>> Where do you get the idea that the common usage is "wrong?" What do >>> you use as a standard? >> Is it "wrong" to consider some usages "wrong"? By what standard? >> >> I'm not interested in arguing over philosophy, so I won't. > Common usage among educated speakers ordinarily is the yardstick for > language questions. But educated about what exactly? Each time someone talks about "a steep learning curve" in order to indicate something is difficult to master, he is using it wrong, because actual steep learning curves indicate something can be mastered quickly. Now I suspect most people who talk about steep learning curves are educated, they just aren't educated about learning curves and so I think common usage among educated speakers is inadequate as a yard stick. -- Antoon Pardon From jussi.piitulainen at helsinki.fi Fri Jul 15 04:40:11 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 15 Jul 2016 11:40:11 +0300 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> Message-ID: Antoon Pardon writes: > Op 15-07-16 om 08:06 schreef Marko Rauhamaa: >> >> Common usage among educated speakers ordinarily is the yardstick for >> language questions. > > But educated about what exactly? > > Each time someone talks about "a steep learning curve" in order to > indicate something is difficult to master, he is using it wrong, > because actual steep learning curves indicate something can be > mastered quickly. > > Now I suspect most people who talk about steep learning curves are > educated, they just aren't educated about learning curves and so I > think common usage among educated speakers is inadequate as a yard > stick. I think I see your point, but I think it's also easy to think the axes of the metaphor so that it makes sense: c , o , s , t . . l e a r n i n g First two steps l-e plain sailing. Next two steps a-r steep climb. Cost is the effort that makes the learner experience the learning as steep. (Spending more *time* without ever paying much attention may not be the best of ideas - it may be the worst of ideas - if the goal is to learn but it still fits the graph: cost goes up for little or no gain.) Perhaps more proper to call that a cost-to-learn curve or something? But when it becomes unwieldy, it gets shortened to something shorter, and here the more informative component has won. Maybe. From marko at pacujo.net Fri Jul 15 05:20:10 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 15 Jul 2016 12:20:10 +0300 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> Message-ID: <87lh13cl6d.fsf@elektro.pacujo.net> Antoon Pardon : > Op 15-07-16 om 08:06 schreef Marko Rauhamaa: >> Common usage among educated speakers ordinarily is the yardstick for >> language questions. > > But educated about what exactly? In this case we are talking about those people who actively talk about significand/mantissa. By and large, they call the thing mantissa. I'm not at all irritated or confused by that (even if my opinion mattered). I *am* irritated by Americans using "Km" for kilometer and "msec" for millisecond (even though my opinion doesn't matter). Marko From antoon.pardon at rece.vub.ac.be Fri Jul 15 06:44:51 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 15 Jul 2016 12:44:51 +0200 Subject: Curious Omission In New-Style Formats In-Reply-To: <87lh13cl6d.fsf@elektro.pacujo.net> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> <87lh13cl6d.fsf@elektro.pacujo.net> Message-ID: <5788BEA3.7050700@rece.vub.ac.be> Op 15-07-16 om 11:20 schreef Marko Rauhamaa: > Antoon Pardon : > >> Op 15-07-16 om 08:06 schreef Marko Rauhamaa: >>> Common usage among educated speakers ordinarily is the yardstick for >>> language questions. >> But educated about what exactly? > In this case we are talking about those people who actively talk about > significand/mantissa. By and large, they call the thing mantissa. I think there is an important difference between actively talking about something and being educated (about it). I have known people who actively talked about negative feedback while what they actually meant was a vicious circle that technically was possitive feedback but with results they wanted to avoid. -- Antoon Pardon. From steve at pearwood.info Fri Jul 15 06:56:15 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 15 Jul 2016 20:56:15 +1000 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> Message-ID: <5788c151$0$1619$c3e8da3$5496439d@news.astraweb.com> On Fri, 15 Jul 2016 06:40 pm, Jussi Piitulainen wrote: > Antoon Pardon writes: > >> Op 15-07-16 om 08:06 schreef Marko Rauhamaa: >>> >>> Common usage among educated speakers ordinarily is the yardstick for >>> language questions. >> >> But educated about what exactly? >> >> Each time someone talks about "a steep learning curve" in order to >> indicate something is difficult to master, he is using it wrong, >> because actual steep learning curves indicate something can be >> mastered quickly. That's not necessarily the case. See below. >> Now I suspect most people who talk about steep learning curves are >> educated, they just aren't educated about learning curves and so I >> think common usage among educated speakers is inadequate as a yard >> stick. > > I think I see your point, but I think it's also easy to think the axes > of the metaphor so that it makes sense: > > c , > o , > s , > t . . > l e a r n i n g > > First two steps l-e plain sailing. Next two steps a-r steep climb. Cost > is the effort that makes the learner experience the learning as steep. > (Spending more *time* without ever paying much attention may not be the > best of ideas - it may be the worst of ideas - if the goal is to learn > but it still fits the graph: cost goes up for little or no gain.) > > Perhaps more proper to call that a cost-to-learn curve or something? > But when it becomes unwieldy, it gets shortened to something shorter, > and here the more informative component has won. Maybe. "Learning curve" or "experience curve" is not just an metaphor, it is an actual technical term. See the Wikipedia article: https://en.wikipedia.org/wiki/Learning_curve Now, there are a couple of ways that we can interpret the idiom of "steep learning curve". One is the way Wikipedia interprets it: as a mistake. According to this conventional explanation, people have *wrongly* imagined a curve like this: (for best results, view using a fixed width font like Courier) K x n x o x w l x e d g x e + Effort or cost or time needed to gain that knowledge or skill as being "hard to learn" at the beginning, when in fact it shows the opposite: with just a little bit of effort, you can learn a lot. But (so goes the conventional explanation) people think of steep in the sense of climbing a steep mountain, and think that it shows that the learning process is really hard at the start. I believe Wikipedia is wrong. I think that there is a natural interpretation of "steep learning curve" which matches *both* the idiomatic and technical meanings, with the same graph. Remember that the English idiom of a steep learning curve is not just hard to learn. It means that something takes a lot of effort to gain mastery over, after which things become easier. Learning Ancient Etruscan is hard for beginners and experts alike, because there is so little information available about Ancient Etruscan that even the experts can hardly be said to have mastered the language. That would not often be described as a steep learning curve, as it lacks the sense of getting easier with time. Learning Etruscan might have a curve like this: K n x o x w x l x e x d x g x e + Effort or cost or time It's hard at the beginning, because you don't know the language; then it gets a bit easier, for a while, then it gets difficult again because you run out of information about the language. Here is a curve that matches the common idiom. It is (1) steep, (2) requires a lot of effort for very little progress at the beginning, and (3) becomes easier with time: K x n x o x w x l x e x d x g x e + Effort or cost or time Mastery makes the going easy, but it takes a long time to see any real progress. You can interpret the "steepness" in two ways: it's steep (easy) for experts, and if you turn your head to the side, it's steep (hard, like climbing a steep mountain) at the beginning). Another way to interpret it is to ask, what's the *cost* (in time, or effort) to gain a certain amount of knowledge? That's equivalent to swapping the X and Y axes: C x o x s x t ? x o r ? t x i m e + Knowledge gained That's not the conventional layout of the axis, but it does make sense, and it's more likely that people have this reversed layout in mind when thinking about "steepness of learning" than it is that they were thinking about the original curve and misinterpreting the meaning of the gradient. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From antoon.pardon at rece.vub.ac.be Fri Jul 15 07:05:01 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 15 Jul 2016 13:05:01 +0200 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> Message-ID: <5788C35D.2070800@rece.vub.ac.be> Op 15-07-16 om 10:40 schreef Jussi Piitulainen: > Antoon Pardon writes: > >> Op 15-07-16 om 08:06 schreef Marko Rauhamaa: >>> Common usage among educated speakers ordinarily is the yardstick for >>> language questions. >> But educated about what exactly? >> >> Each time someone talks about "a steep learning curve" in order to >> indicate something is difficult to master, he is using it wrong, >> because actual steep learning curves indicate something can be >> mastered quickly. >> >> Now I suspect most people who talk about steep learning curves are >> educated, they just aren't educated about learning curves and so I >> think common usage among educated speakers is inadequate as a yard >> stick. > I think I see your point, but I think it's also easy to think the axes > of the metaphor so that it makes sense: > > c , > o , > s , > t . . > l e a r n i n g Only for someone who is not very familiar with how we graphically represent results. The cost/effort is always put on the X-ax because that is what we directly control and also because that is what always increases. You can't unspent time in trying to master something. We make this choice because we want a mathematical function. What if you have a set back? How do you show that on your graph? Ask people if they prefer a steep or shallow pay check curve. Most seem very quick in choosing for the steep curve. -- Antoon From steve at pearwood.info Fri Jul 15 07:39:31 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 15 Jul 2016 21:39:31 +1000 Subject: math.frexp Message-ID: <5788cb76$0$1599$c3e8da3$5496439d@news.astraweb.com> I'm experimenting with various implementations of product(values). Here's a naive version that easily suffers from overflow: from functools import reduce from operator import mul def product_naive(values): return reduce(mul, values) py> product_naive([2, 4, 5]) 40 py> product_naive([1e200, 1e200, 1e200]) inf So I started experimenting with math.frexp, but I'm having trouble understanding what I'm doing wrong here. Help on built-in function frexp in module math: frexp(...) frexp(x) Return the mantissa and exponent of x, as pair (m, e). m is a float and e is an int, such that x = m * 2.**e. If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0. If x and y are both floats, then given: m1, e1 = math.frexp(x) m2, e2 = math.frexp(y) Then x*y = m1*m2 * 2.0**(e1 + e2). We can test that: py> from math import frexp py> x = 2.5 py> y = 3.5 py> x*y 8.75 py> m1, e1 = math.frexp(x) py> m2, e2 = math.frexp(y) py> m1*m2 * 2.0**(e1 + e2) 8.75 Looks good to me. So let's try a less naive version of product(): def product_scaled(values): scale = 0 prod = 1.0 for a in values: m1, e1 = math.frexp(a) m2, e2 = math.frexp(prod) scale += (e1 + e2) prod *= (m1*m2) return (prod * 2.0**scale) py> product_scaled([2.5, 3.5]) # expected 8.75 2.734375 What am I doing wrong? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From antoon.pardon at rece.vub.ac.be Fri Jul 15 07:44:38 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 15 Jul 2016 13:44:38 +0200 Subject: Curious Omission In New-Style Formats In-Reply-To: <5788c151$0$1619$c3e8da3$5496439d@news.astraweb.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> <5788c151$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5788CCA6.90405@rece.vub.ac.be> Op 15-07-16 om 12:56 schreef Steven D'Aprano: > On Fri, 15 Jul 2016 06:40 pm, Jussi Piitulainen wrote: > >> Antoon Pardon writes: >> >>> Op 15-07-16 om 08:06 schreef Marko Rauhamaa: >>>> Common usage among educated speakers ordinarily is the yardstick for >>>> language questions. >>> But educated about what exactly? >>> >>> Each time someone talks about "a steep learning curve" in order to >>> indicate something is difficult to master, he is using it wrong, >>> because actual steep learning curves indicate something can be >>> mastered quickly. > That's not necessarily the case. See below. I think it does. > > "Learning curve" or "experience curve" is not just an metaphor, it is an > actual technical term. See the Wikipedia article: > > https://en.wikipedia.org/wiki/Learning_curve I know and the technical term precedes the metaphor. > Remember that the English idiom of a steep learning curve is not just hard > to learn. It means that something takes a lot of effort to gain mastery > over, after which things become easier. Yes things/practicing become easier, mastering even further does not. > Here is a curve that matches the common idiom. It is (1) steep, (2) requires > a lot of effort for very little progress at the beginning, and (3) becomes > easier with time: > > > K x > n x > o x > w x > l x > e x > d x > g x > e > + Effort or cost or time I think you are making things up now. I have never seen an actual learning curve with that shape. All learning curves I have seen show the law of diminishing (marginal) returns. > Another way to interpret it is to ask, what's the *cost* (in time, or > effort) to gain a certain amount of knowledge? That's equivalent to > swapping the X and Y axes: Which you don't expect because if swapping axes was common, most people would understand that talking about steep or shallow curves would be meaningless since you wouldn't know whether is was steep with standaard ax positions or steep with swapped ax posititions. > > C x > o x > s x > t > ? x > o > r > ? > t x > i > m > e > + Knowledge gained > > > > That's not the conventional layout of the axis, but it does make sense, and > it's more likely that people have this reversed layout in mind when > thinking about "steepness of learning" than it is that they were thinking > about the original curve and misinterpreting the meaning of the gradient. No, that is what people come up with afterwards. If you just start a conversation about how people learn and how long it would take to get some mastery and how we could present progress in a graph, virtually everyone uses the conventional axes layout. This talk about swapped axes only come from people who used the steep learning curve metaphor, when you then try to show them what an actual steep learning curve implies. From rosuav at gmail.com Fri Jul 15 07:48:10 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Jul 2016 21:48:10 +1000 Subject: math.frexp In-Reply-To: <5788cb76$0$1599$c3e8da3$5496439d@news.astraweb.com> References: <5788cb76$0$1599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jul 15, 2016 at 9:39 PM, Steven D'Aprano wrote: > py> from math import frexp > py> x = 2.5 > py> y = 3.5 > py> x*y > 8.75 > py> m1, e1 = math.frexp(x) > py> m2, e2 = math.frexp(y) > py> m1*m2 * 2.0**(e1 + e2) > 8.75 > > > Looks good to me. So let's try a less naive version of product(): > > > def product_scaled(values): > scale = 0 > prod = 1.0 > for a in values: > m1, e1 = math.frexp(a) > m2, e2 = math.frexp(prod) > scale += (e1 + e2) > prod *= (m1*m2) > return (prod * 2.0**scale) > > > py> product_scaled([2.5, 3.5]) # expected 8.75 > 2.734375 > You're chaining your product twice. (Also your scale, although that appears to be correct.) Changing it to "prod = m1 * m2" gives 8.75. But what do you gain by this? You're still stuffing the result back into a float at the end, so all you do is change from getting float("inf") to getting OverflowError. How can you make it not overflow? ChrisA From jussi.piitulainen at helsinki.fi Fri Jul 15 09:13:25 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 15 Jul 2016 16:13:25 +0300 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> <5788c151$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: [in response to my attempt to understand "steep learning curve"] > "Learning curve" or "experience curve" is not just an metaphor, it is > an actual technical term. See the Wikipedia article: > > https://en.wikipedia.org/wiki/Learning_curve > > > Now, there are a couple of ways that we can interpret the idiom of > "steep learning curve". One is the way Wikipedia interprets it: as a > mistake. [- -] Ouch. Next time I hear anyone use the phrase, if I need to know whether they mean "easy to learn" or "hard to learn" or something else, I think I'll ask them... Thanks. From jussi.piitulainen at helsinki.fi Fri Jul 15 09:28:00 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 15 Jul 2016 16:28:00 +0300 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> <5788C35D.2070800@rece.vub.ac.be> Message-ID: Antoon Pardon writes: > Op 15-07-16 om 10:40 schreef Jussi Piitulainen: >> Antoon Pardon writes: >> >>> Op 15-07-16 om 08:06 schreef Marko Rauhamaa: >>>> Common usage among educated speakers ordinarily is the yardstick for >>>> language questions. >>> But educated about what exactly? >>> >>> Each time someone talks about "a steep learning curve" in order to >>> indicate something is difficult to master, he is using it wrong, >>> because actual steep learning curves indicate something can be >>> mastered quickly. >>> >>> Now I suspect most people who talk about steep learning curves are >>> educated, they just aren't educated about learning curves and so I >>> think common usage among educated speakers is inadequate as a yard >>> stick. >> I think I see your point, but I think it's also easy to think the axes >> of the metaphor so that it makes sense: >> >> c , >> o , >> s , >> t . . >> l e a r n i n g > > Only for someone who is not very familiar with how we graphically > represent results. The cost/effort is always put on the X-ax because > that is what we directly control and also because that is what always > increases. You can't unspent time in trying to master something. We > make this choice because we want a mathematical function. > > What if you have a set back? How do you show that on your graph? Nice points, thank you. You may be simply right on this, and I may have learnt something. > Ask people if they prefer a steep or shallow pay check curve. Most > seem very quick in choosing for the steep curve. I'm not at all sure how I would answer. By asking what is meant? Because to me it sounds like a trick question to begin with. There's an old story they tell in my family about a child who begs for bread from a house. The lady of the house asks if they want a one-hand slice (yhe k?e leip?) or a two-hand slice (kahe k?e leip?), and when the poor hungry child asks for the two-hand slice, they get a slice so thin that it needs to be held with both hands. That's mean. From jussi.piitulainen at helsinki.fi Fri Jul 15 09:38:35 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 15 Jul 2016 16:38:35 +0300 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> <5788c151$0$1619$c3e8da3$5496439d@news.astraweb.com> <5788CCA6.90405@rece.vub.ac.be> Message-ID: Antoon Pardon writes: > No, that is what people come up with afterwards. If you just start a > conversation about how people learn and how long it would take to get > some mastery and how we could present progress in a graph, virtually > everyone uses the conventional axes layout. This talk about swapped > axes only come from people who used the steep learning curve metaphor, > when you then try to show them what an actual steep learning curve > implies. Or from people who try to be charitable when other people use it. At least I like to think that that's what I did. (I'm not at all inclined to do that about certain other terms, but those discussions are also not inclined to go anywhere.) From random832 at fastmail.com Fri Jul 15 09:39:15 2016 From: random832 at fastmail.com (Random832) Date: Fri, 15 Jul 2016 09:39:15 -0400 Subject: Curious Omission In New-Style Formats In-Reply-To: <5788CCA6.90405@rece.vub.ac.be> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> <5788c151$0$1619$c3e8da3$5496439d@news.astraweb.com> <5788CCA6.90405@rece.vub.ac.be> Message-ID: <1468589955.2680993.667243833.4A729BDD@webmail.messagingengine.com> On Fri, Jul 15, 2016, at 07:44, Antoon Pardon wrote: > No, that is what people come up with afterwards. If you just start a > conversation about how people learn and how long it would take to get > some mastery and how we could present progress in a graph, virtually > everyone uses the conventional axes layout. _Why_ do you think this? The natural way to graph progress vs effort is to have progress on the horizontal access and effort on the vertical axis, because that's what you get when you're climbing a literal hill, the only context in the universe where "vertical" and "horizontal" aren't arbitrarily assigned but are real spatial dimensions. The only reason to do it the other way is an association with time and the convention of using time for the horizontal axis. > This talk about swapped axes only come from people who used the steep > learning curve metaphor, when you then try to show them what an actual > steep learning curve implies. From antoon.pardon at rece.vub.ac.be Fri Jul 15 10:32:55 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 15 Jul 2016 16:32:55 +0200 Subject: Curious Omission In New-Style Formats In-Reply-To: <1468589955.2680993.667243833.4A729BDD@webmail.messagingengine.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> <5788c151$0$1619$c3e8da3$5496439d@news.astraweb.com> <5788CCA6.90405@rece.vub.ac.be> <1468589955.2680993.667243833.4A729BDD@webmail.messagingengine.com> Message-ID: <5788F417.6030809@rece.vub.ac.be> Op 15-07-16 om 15:39 schreef Random832: > > On Fri, Jul 15, 2016, at 07:44, Antoon Pardon wrote: > >> No, that is what people come up with afterwards. If you just start a >> conversation about how people learn and how long it would take to get >> some mastery and how we could present progress in a graph, virtually >> everyone uses the conventional axes layout. > _Why_ do you think this? The natural way to graph progress vs effort is > to have progress on the horizontal access and effort on the vertical > axis, because that's what you get when you're climbing a literal hill, > the only context in the universe where "vertical" and "horizontal" > aren't arbitrarily assigned but are real spatial dimensions. No that is not the natural way. That is the way you pick afterwards if you want your graph to resemble the metaphor. But it is not the way people "naturally" graph these numbers, if the metafor was not put into their head in first place. Certainly not people who actually study these kind of things. > The only reason to do it the other way is an association with time and > the convention of using time for the horizontal axis. No the reason is, we prefer the graph to be a function. That is for every x at most one y. Using the axes the other way around would mean that set backs would result in multiple y values for the same x. -- Antoon Pardon. From antoon.pardon at rece.vub.ac.be Fri Jul 15 10:47:21 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 15 Jul 2016 16:47:21 +0200 Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> <5788c151$0$1619$c3e8da3$5496439d@news.astraweb.com> <5788CCA6.90405@rece.vub.ac.be> Message-ID: <5788F779.3010608@rece.vub.ac.be> Op 15-07-16 om 15:38 schreef Jussi Piitulainen: > Antoon Pardon writes: > >> No, that is what people come up with afterwards. If you just start a >> conversation about how people learn and how long it would take to get >> some mastery and how we could present progress in a graph, virtually >> everyone uses the conventional axes layout. This talk about swapped >> axes only come from people who used the steep learning curve metaphor, >> when you then try to show them what an actual steep learning curve >> implies. > Or from people who try to be charitable when other people use it. At > least I like to think that that's what I did. Sure, you can be charitable when other people use it. IME that doesn't contradict that when you somehow find yourself in need of actually graphing these kind of numbers you are likely to follow the conventional layout. -- Antoon Pardon. From steve at pearwood.info Fri Jul 15 11:12:27 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 16 Jul 2016 01:12:27 +1000 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <76762c79-a85d-48f1-8132-5decd10ce4f1@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> <5788c151$0$1619$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5788fd5c$0$1590$c3e8da3$5496439d@news.astraweb.com> On Fri, 15 Jul 2016 11:13 pm, Jussi Piitulainen wrote: > Steven D'Aprano writes: > > [in response to my attempt to understand "steep learning curve"] > >> "Learning curve" or "experience curve" is not just an metaphor, it is >> an actual technical term. See the Wikipedia article: >> >> https://en.wikipedia.org/wiki/Learning_curve >> >> >> Now, there are a couple of ways that we can interpret the idiom of >> "steep learning curve". One is the way Wikipedia interprets it: as a >> mistake. > > [- -] > > Ouch. Next time I hear anyone use the phrase, if I need to know whether > they mean "easy to learn" or "hard to learn" or something else, I think > I'll ask them... You really don't need to. "Steep learning curve" in ordinary English ALWAYS means that it is hard to make progress and then gets easier once you have mastered it. Its a common idiom. If you're talking to an actual expert in the field about an actual graph, then it might be worth asking them what they mean. And the chances are they will mean exactly the same thing as ordinary people, and they'll just say "turn your head to the side, see how steep the graph is at the start". That's my prediction. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Fri Jul 15 11:13:35 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 16 Jul 2016 01:13:35 +1000 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> <5788C35D.2070800@rece.vub.ac.be> Message-ID: <5788fd9f$0$1590$c3e8da3$5496439d@news.astraweb.com> On Fri, 15 Jul 2016 11:28 pm, Jussi Piitulainen wrote: > There's an old story they tell in my family about a child who begs for > bread from a house. The lady of the house asks if they want a one-hand > slice (yhe k?e leip?) or a two-hand slice (kahe k?e leip?), and when the > poor hungry child asks for the two-hand slice, they get a slice so thin > that it needs to be held with both hands. That's mean. Ha, that's exactly the same story my grandmother (who was Estonian-Russian) used to tell me. If you don't mind me asking, what nationality are you? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jussi.piitulainen at helsinki.fi Fri Jul 15 11:27:57 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Fri, 15 Jul 2016 18:27:57 +0300 Subject: Curious Omission In New-Style Formats References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <57874385$0$1501$c3e8da3$5496439d@news.astraweb.com> <87shvccing.fsf@elektro.pacujo.net> <87vb08xh3g.fsf@elektro.pacujo.net> <87lh13xwnr.fsf@elektro.pacujo.net> <578896B1.1030104@rece.vub.ac.be> <5788C35D.2070800@rece.vub.ac.be> <5788fd9f$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Fri, 15 Jul 2016 11:28 pm, Jussi Piitulainen wrote: > >> There's an old story they tell in my family about a child who begs for >> bread from a house. The lady of the house asks if they want a one-hand >> slice (yhe k?e leip?) or a two-hand slice (kahe k?e leip?), and when the >> poor hungry child asks for the two-hand slice, they get a slice so thin >> that it needs to be held with both hands. That's mean. > > > Ha, that's exactly the same story my grandmother (who was > Estonian-Russian) used to tell me. If you don't mind me asking, what > nationality are you? Finnish. Karelian enough that it probably is the exact same story. From bamccaig at gmail.com Fri Jul 15 11:39:02 2016 From: bamccaig at gmail.com (Brandon McCaig) Date: Fri, 15 Jul 2016 11:39:02 -0400 Subject: Were is a great place to Share your finished projects? In-Reply-To: <578830ac$0$1621$c3e8da3$5496439d@news.astraweb.com> References: <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> <578830ac$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20160715153902.GA3587@test-chamber-1.castopulence.org> On Fri, Jul 15, 2016 at 10:39:05AM +1000, Steven D'Aprano wrote: > About seven years ago, the senior technical manager at my work chose hg over > git. When he left to go to greener pastures, the dev team took about 30 > seconds to to reverse his decision and migrate to git, after which the > level of VCS-related screw-ups and queries went through the roof. Git used to have much sharper edges than Mercurial, but that is pretty much a thing of the past. With Git you pretty much can't permanently lose history unless you try really, really hard. It'll always be there in the reflog for a period of several days minimum (I think 2 weeks by default?) and if you're worried about it you can configure it to put that off for months or years... On the other hand, I have had Mercurial bugs repeatedly lose work of mine. The kind of bugs that aren't easy to reproduce so nearly impossible to report and nearly impossible to fix. The ecosystem of "extensions" makes this problem inevitable. You depend on extensions, typically third-party extensions for the first few years of their life, for all of the power-user stuff, and the extensions have as much power to corrupt or lose history as the main library does. And of course, they have the potential to alter the behavior of the core library making reporting bugs that much more difficult ("ok, but which extensions, official or unofficial, do you have installed?"). Now instead of one team writing bugs you have N teams writing them in isolation. Combined with their failure to accomodate the distributed development model properly you now have a bunch of incompatible ideas for managing branches and history editing and they still haven't gotten it all right yet (but they're getting closer the more and more they model the design after Git). > To give you an idea of how screwed up things are, even though I'm not one of > the developer team, and have never pushed a thing into the code > repositories (I have pushed into documentation repos), somehow according > to "git blame" I'm responsible for a bunch of code. The user name and email fields are not controlled in either Git or Mercurial so anybody can commit code under your name without you being involved. That would be pretty unprofessional though... I can't imagine Git magically pulling your name out of nowhere when it looks up the author of commits that are responsible for lines of code... Maybe you should report that to the mailing list and get to the bottom of it... I suspect that the explanation has nothing to do with any bugs in Git. Regards, -- Brandon McCaig Castopulence Software Blog perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }. q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.}; tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say' -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: From rosuav at gmail.com Fri Jul 15 12:12:16 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jul 2016 02:12:16 +1000 Subject: Were is a great place to Share your finished projects? In-Reply-To: <20160715153902.GA3587@test-chamber-1.castopulence.org> References: <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> <578830ac$0$1621$c3e8da3$5496439d@news.astraweb.com> <20160715153902.GA3587@test-chamber-1.castopulence.org> Message-ID: On Sat, Jul 16, 2016 at 1:39 AM, Brandon McCaig wrote: > [regarding Mercurial] > Combined with their failure to accomodate the distributed > development model properly you now have a bunch of incompatible > ideas for managing branches and history editing and they still > haven't gotten it all right yet (but they're getting closer the > more and more they model the design after Git). I've never managed to get Mercurial's branching system into my head (and then you have the people saying "don't use hg branches at all, just use named tags" or somesuch), but the git branching system is extremely simple. In fact, all of git is very simple. To anyone who is having trouble with comprehending git, I strongly recommend this video. It assumes you have a basic understanding of git commands (or can pause the video and look up a git-hg Rosetta Stone), but you don't need expert-level knowledge. In fact, it's aimed at people ages 4 and up... https://www.youtube.com/watch?v=1ffBJ4sVUb4 >> To give you an idea of how screwed up things are, even though I'm not one of >> the developer team, and have never pushed a thing into the code >> repositories (I have pushed into documentation repos), somehow according >> to "git blame" I'm responsible for a bunch of code. > > The user name and email fields are not controlled in either Git > or Mercurial so anybody can commit code under your name without > you being involved. That would be pretty unprofessional though... If you're paranoid, you can have git sign your commits, in which case anyone could commit code under your name, but not using your private key. You can then tell people to be suspicious of any commits they can't cryptographically verify. > I can't imagine Git magically pulling your name out of nowhere > when it looks up the author of commits that are responsible for > lines of code... Maybe you should report that to the mailing list > and get to the bottom of it... I suspect that the explanation has > nothing to do with any bugs in Git. There are a few possibilities. If someone copied a slab of code from the documentation repo straight into the code repo (maybe you provided examples or something), git might detect that and recognize the copying. In that case, you'd be (correctly) responsible for that code, and the author would be a two-part "originally authored" pointing to your docs commit and "moved or copied here by" pointing to the commit that actually incorporated it. But if the repositories are completely separate, this is unlikely. More likely, someone might be able to cherry-pick the commit itself, if there is a corresponding file in code; again, this would have a two-part authorship marker "author" and "committer", because every git commit has this. (This is something Mercurial lacks. Every commit is blamed to the person with the commit-bit who pushed it, rather than the person who actually wrote the code. Obviously the committer is important, but so is the author.) If you want to get to the bottom of it, I would advise exploring the commits that are tagged with your name. Do they look like changes you made? Did you provide a patch file that someone else committed? And, who committed the changes - can you email that person to ask for clarification? The beauty of git is that all the information is right there, if you just look at it - 'git show 142857' will answer most of the above questions, and add "--format=full" or "--format=fuller" [1] to get the committer's info. Dig around... have fun! [1] I mean, not "fuller", just... more formatful. Wait, what? ChrisA From steve at pearwood.info Fri Jul 15 12:32:26 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 16 Jul 2016 02:32:26 +1000 Subject: math.frexp References: <5788cb76$0$1599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5789101c$0$1615$c3e8da3$5496439d@news.astraweb.com> On Fri, 15 Jul 2016 09:48 pm, Chris Angelico wrote: >> py> product_scaled([2.5, 3.5]) # expected 8.75 >> 2.734375 >> > > You're chaining your product twice. (Also your scale, although that > appears to be correct.) Changing it to "prod = m1 * m2" gives 8.75. D'oh! Thanks! I needed some fresh eyes on that, because I have been staring at it for two days. > But what do you gain by this? You're still stuffing the result back > into a float at the end, so all you do is change from getting > float("inf") to getting OverflowError. How can you make it not > overflow? If the result is too big to be represented as a float at the end of the product, then of course it will overflow. But this can give some protection against overflow of intermediate values. Consider multiplying: 2.0, 1e200, 1e200, 1e-200, 1e-200, 3.0 Mathematically, the answer should be 6. In principle, by rescaling when needed to prevent overflow (or underflow), product() should be able to get something very close to 6, if not exactly 6. But I'm not actually writing a general product() function. I'm doing this for geometric mean, so I return the scaling exponent and the mantissa[1] separately, and then take the nth-root of them individually, before combining them into the final result. Here's an example from my test suite. I can take the geometric mean of: [2.0**900, 2.0**920, 2.0**960, 2.0**980, 2.0**990] and get to within a relative error of 1e-14 of the correct answer, 2**950: py> geometric_mean([2.0**900, 2.0**920, 2.0**960, 2.0**980, 2.0**990]) 9.516908214257811e+285 py> 2.0**950 9.516908214257812e+285 Here's one that's exact: py> geometric_mean([2e300, 4e300, 8e300, 16e300, 32e300]) 8e+300 [1] I don't care what it's actually called :-) -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From nobody at nowhere.invalid Fri Jul 15 12:39:00 2016 From: nobody at nowhere.invalid (Nobody) Date: Fri, 15 Jul 2016 17:39:00 +0100 Subject: math.frexp References: <5788cb76$0$1599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 15 Jul 2016 21:39:31 +1000, Steven D'Aprano wrote: > prod *= (m1*m2) Should be: prod = m1*m2 or: prod *= m1 (in the latter case, there's no point in decomposing prod). Of course, if the result overflows, it's going to overflow whether you use the naive approach or frexp(); in the latter case, it's the 2.0**scale which will overflow. One advantage of processing the scale separately is that you can use e.g. return ((int(prod * 2**53) * (2**(scale-53))) if scale >= 53 else prod * 2**scale) which will return a (long) integer if the exponent is such that the fractional bits are lost. From rosuav at gmail.com Fri Jul 15 12:44:45 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jul 2016 02:44:45 +1000 Subject: math.frexp In-Reply-To: <5789101c$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <5788cb76$0$1599$c3e8da3$5496439d@news.astraweb.com> <5789101c$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jul 16, 2016 at 2:32 AM, Steven D'Aprano wrote: > If the result is too big to be represented as a float at the end of the > product, then of course it will overflow. But this can give some protection > against overflow of intermediate values. Consider multiplying: > > 2.0, 1e200, 1e200, 1e-200, 1e-200, 3.0 > > > Mathematically, the answer should be 6. In principle, by rescaling when > needed to prevent overflow (or underflow), product() should be able to get > something very close to 6, if not exactly 6. I was under the impression that appropriate reordering of the elements could prevent over/underflow and maximize accuracy, but that may be a mistaken memory. However... > But I'm not actually writing a general product() function. I'm doing this > for geometric mean, so I return the scaling exponent and the mantissa[1] > separately, and then take the nth-root of them individually, before > combining them into the final result. ... this makes a lot of sense. In effect, I *think*, you're basically doing the multiplication on something rather larger than a 64-bit IEEE float, then taking the nth-root, and then combine them and convert back to float. Is this about right? ChrisA From random832 at fastmail.com Fri Jul 15 14:28:05 2016 From: random832 at fastmail.com (Random832) Date: Fri, 15 Jul 2016 14:28:05 -0400 Subject: math.frexp In-Reply-To: <5789101c$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <5788cb76$0$1599$c3e8da3$5496439d@news.astraweb.com> <5789101c$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1468607285.2744204.667500217.193B8D54@webmail.messagingengine.com> On Fri, Jul 15, 2016, at 12:32, Steven D'Aprano wrote: > I can take the geometric mean of: > > [2.0**900, 2.0**920, 2.0**960, 2.0**980, 2.0**990] > > and get to within a relative error of 1e-14 of the correct answer, > 2**950: > > py> geometric_mean([2.0**900, 2.0**920, 2.0**960, 2.0**980, 2.0**990]) > 9.516908214257811e+285 > py> 2.0**950 > 9.516908214257812e+285 > > Here's one that's exact: > > py> geometric_mean([2e300, 4e300, 8e300, 16e300, 32e300]) > 8e+300 My own attempt gave an exact result for both test cases. from math import frexp as _frexp, ldexp def frexp(x): if type(x) is tuple: m, e1 = x m, e2 = _frexp(m) return m, e1 + e2 else: return _frexp(x) def _mul(a, b): ma, ea = frexp(a) mb, eb = frexp(b) return frexp((ma * mb, ea + eb)) def _product(values): return reduce(_mul, values) def geometric_mean(values): n = len(values) pm, pe = _product(values) me, re = divmod(pe, n) pm = ldexp(pm, re) return ldexp(pm**(1./n), me) From marko at pacujo.net Fri Jul 15 14:28:20 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 15 Jul 2016 21:28:20 +0300 Subject: Were is a great place to Share your finished projects? References: <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> <578830ac$0$1621$c3e8da3$5496439d@news.astraweb.com> <20160715153902.GA3587@test-chamber-1.castopulence.org> Message-ID: <877fcmycvv.fsf@elektro.pacujo.net> Chris Angelico : > I've never managed to get Mercurial's branching system into my head > (and then you have the people saying "don't use hg branches at all, > just use named tags" or somesuch), but the git branching system is > extremely simple. In fact, all of git is very simple. To anyone who is > having trouble with comprehending git, I strongly recommend this > video. It assumes you have a basic understanding of git commands (or > can pause the video and look up a git-hg Rosetta Stone), but you don't > need expert-level knowledge. In fact, it's aimed at people ages 4 and > up... I use git daily but don't really use branches, and need to ask a coworker about the branching commands. Also, reverting changes in git keeps baffling me (I need to check the source code of emacs' vc-mode to figure out how it's done). Anyway, all of this has reminded me that bitkeeper is now free. I've never tried it so let's see if it is everything Sun's Teamware was. Marko From marko at pacujo.net Fri Jul 15 14:57:09 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 15 Jul 2016 21:57:09 +0300 Subject: Were is a great place to Share your finished projects? References: <85h9butagz.fsf@benfinney.id.au> <5785e332$0$21718$c3e8da3@news.astraweb.com> <1bf3954e-f46d-384f-92e2-4a67970cb66c@gmail.com> <578830ac$0$1621$c3e8da3$5496439d@news.astraweb.com> <20160715153902.GA3587@test-chamber-1.castopulence.org> <877fcmycvv.fsf@elektro.pacujo.net> Message-ID: <8737naybju.fsf@elektro.pacujo.net> Marko Rauhamaa : > Anyway, all of this has reminded me that bitkeeper is now free. I've > never tried it so let's see if it is everything Sun's Teamware was. Hm, ran into compilation trouble. Maybe I should wait till bk is available for Fedora. Marko From no.email at nospam.invalid Fri Jul 15 16:24:34 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 15 Jul 2016 13:24:34 -0700 Subject: math.frexp References: <5788cb76$0$1599$c3e8da3$5496439d@news.astraweb.com> <5789101c$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87eg6uejjx.fsf@jester.gateway.pace.com> Steven D'Aprano writes: > But this can give some protection against overflow of intermediate > values. Might be simplest to just add the logarithms. Look up Kahan summation for how to do that while minimizing loss of precision. From lawrencedo99 at gmail.com Fri Jul 15 19:35:58 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 15 Jul 2016 16:35:58 -0700 (PDT) Subject: Curious Omission In New-Style Formats In-Reply-To: References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> Message-ID: <4cffe61d-5188-464e-986a-5a60403b9f26@googlegroups.com> On Thursday, July 14, 2016 at 12:46:26 PM UTC+12, Ian wrote: > > On Wed, Jul 13, 2016 at 4:24 PM, Lawrence D?Oliveiro wrote: >> >> How about ?mantissa length?, then. That sufficiently neutral for you? > > That makes even less sense for integers. Perhaps you would prefer the more gender-neutral term ?persontissa? ... From rosuav at gmail.com Fri Jul 15 20:57:40 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jul 2016 10:57:40 +1000 Subject: Curious Omission In New-Style Formats In-Reply-To: <4cffe61d-5188-464e-986a-5a60403b9f26@googlegroups.com> References: <834b1cce-38dd-474c-8915-4ff1cd6b27ec@googlegroups.com> <7fcc8c21-106f-41d4-a5ba-409f3b54a56d@googlegroups.com> <5783c91e$0$1622$c3e8da3$5496439d@news.astraweb.com> <57846636$0$1621$c3e8da3$5496439d@news.astraweb.com> <06f2dedb-ce7a-4ca8-9fe8-8dba36f3d3ba@googlegroups.com> <4cffe61d-5188-464e-986a-5a60403b9f26@googlegroups.com> Message-ID: On Sat, Jul 16, 2016 at 9:35 AM, Lawrence D?Oliveiro wrote: > On Thursday, July 14, 2016 at 12:46:26 PM UTC+12, Ian wrote: >> >> On Wed, Jul 13, 2016 at 4:24 PM, Lawrence D?Oliveiro wrote: >>> >>> How about ?mantissa length?, then. That sufficiently neutral for you? >> >> That makes even less sense for integers. > > Perhaps you would prefer the more gender-neutral term ?persontissa? ... I would laugh, but gender issues are extremely significand to a lot of people... ChrisA From rustompmody at gmail.com Sat Jul 16 00:04:31 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 15 Jul 2016 21:04:31 -0700 (PDT) Subject: Clean Singleton Docstrings In-Reply-To: References: Message-ID: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> On Thursday, July 14, 2016 at 5:24:50 AM UTC+5:30, Peter Otten wrote: > Lawrence D?Oliveiro wrote: > > And there are still those who think that Python?s lax acceptance of > > non-boolean values as booleans is a good idea... > > I don't think this particular problem serves as an argument for stricter > handling of boolean expressions because the fix
I was going to apologise for the snark Then I see thats not my words; I said something along similar lines Doesn't mean python needs to change Just that suggesting that python's bool notion is straightforward is an unnecessary lie ? especially to newbies. From ethan at stoneleaf.us Sat Jul 16 00:20:17 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 15 Jul 2016 21:20:17 -0700 Subject: Clean Singleton Docstrings In-Reply-To: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> Message-ID: <5789B601.9000604@stoneleaf.us> On 07/15/2016 09:04 PM, Rustom Mody wrote: > Just that suggesting that python's bool notion is straightforward is an > unnecessary lie ? especially to newbies. Python's boolean concept is as simple as it gets -- what is not straightforward about it? -- ~Ethan~ From rustompmody at gmail.com Sat Jul 16 01:48:35 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 15 Jul 2016 22:48:35 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> On Thursday, June 30, 2016 at 10:52:50 PM UTC+5:30, Steven D'Aprano wrote: > Okay, if you think that automata cannot be empty, I'll accept that. In that > case, then I'll change my answer and say that __bool__ for automata should > simply return True. All automata should be truthy. > I am not sure with what tone of voice you are saying that If ... ?return True? is about as good -- ie useful -- as (say) def __bool__(self): from random import random return int(2*random()) then I think we agree But then there is a well-established behavior pattern in python captured by the contexts that raise AttributeError/NameError/TypeError etc viz For things that are undefined we are told politely they are undefined IOW Why say something is useless and define it rather than just leave undefined something that is ill-defined. If on the other hand you are giving that ?return True?as a serious useful definition? If both you and Chris tripped up on a right definition of an ?empty? automaton and regex respectively, I believe it demonstrates that getting boolishness for an arbitrary type right is at least non-trivial. [FWIW My belief: In general its nonsensical] From rustompmody at gmail.com Sat Jul 16 01:51:56 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 15 Jul 2016 22:51:56 -0700 (PDT) Subject: Clean Singleton Docstrings In-Reply-To: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> Message-ID: <45ffd6af-128b-429e-82fe-2e0c3d39ba9d@googlegroups.com> On Saturday, July 16, 2016 at 9:50:13 AM UTC+5:30, Ethan Furman wrote: > On 07/15/2016 09:04 PM, Rustom Mody wrote: > > > Just that suggesting that python's bool notion is straightforward is an > > unnecessary lie ? especially to newbies. > > Python's boolean concept is as simple as it gets -- what is not straightforward about it? I thought the other thread "Operator precedence/boolean logic" demonstrated that. Ive added a further continuation there ? where this topic is more relevant From rustompmody at gmail.com Sat Jul 16 01:58:50 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 15 Jul 2016 22:58:50 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> Message-ID: >From other thread: On Saturday, July 16, 2016 at 9:50:13 AM UTC+5:30, Ethan Furman wrote: > On 07/15/2016 09:04 PM, Rustom Mody wrote: > > > Just that suggesting that python's bool notion is straightforward is an > > unnecessary lie ? especially to newbies. > > Python's boolean concept is as simple as it gets -- what is not straightforward about it? And to expand on my On Saturday, July 16, 2016 at 11:18:48 AM UTC+5:30, Rustom Mody wrote: > FWIW My belief: In general its nonsensical C's 0 is false; rest-of-universe is true is a mess Python increases the mess by making the false-y candidates also non-singleton This seems to work for container-like objects like lists,strings,sets, etc with None and 0 being somewhat elliptical analogues But when we allow __bool__ to be available for any and every thing and give it some implicit random definition, this is just plain nonsense. [What is the bool-nature -- aka Buddha-nature -- of graphs question remains yet answered] From lawrencedo99 at gmail.com Sat Jul 16 02:19:43 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Fri, 15 Jul 2016 23:19:43 -0700 (PDT) Subject: Clean Singleton Docstrings In-Reply-To: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> Message-ID: <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> On Saturday, July 16, 2016 at 4:20:13 PM UTC+12, Ethan Furman wrote: > > On 07/15/2016 09:04 PM, Rustom Mody wrote: > >> Just that suggesting that python's bool notion is straightforward is an >> unnecessary lie ? especially to newbies. > > Python's boolean concept is as simple as it gets -- what is not > straightforward about it? The fact that it led to the aforementioned bug. From rosuav at gmail.com Sat Jul 16 02:29:18 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jul 2016 16:29:18 +1000 Subject: Clean Singleton Docstrings In-Reply-To: <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> Message-ID: On Sat, Jul 16, 2016 at 4:19 PM, Lawrence D?Oliveiro wrote: > On Saturday, July 16, 2016 at 4:20:13 PM UTC+12, Ethan Furman wrote: >> >> On 07/15/2016 09:04 PM, Rustom Mody wrote: >> >>> Just that suggesting that python's bool notion is straightforward is an >>> unnecessary lie ? especially to newbies. >> >> Python's boolean concept is as simple as it gets -- what is not >> straightforward about it? > > The fact that it led to the aforementioned bug. The difference between ints and floats can lead to bugs, too. Which one should we eliminate? Tuple augmented assignment can lead to extremely confusing bugs. Let's abolish augmented assignment. Or tuples? Operator precedence leads to bugs when people don't respect it. Eliminate it; all operators function at the same precedence, with middle-to-outside associativity (as popularized by the "if/else" ternary operator). There. Now we have a bug-free language. Tongue removed from cheek... The Python policy is a *lot* easier to work with than REXX's policy is. In REXX, if you put a value in an IF statement that isn't its canonical True or False (in its case, "1" and "0"), you get a run-time error. Python lets you use None, False, 0, etc, as falsey, and if you really want a comparison, you put it in there. How is this a problem? As demonstrated elsewhere, the problem isn't the boolification. The problem is that an 'if' was used where exception handling would have been far better. ChrisA From random832 at fastmail.com Sat Jul 16 02:53:58 2016 From: random832 at fastmail.com (Random832) Date: Sat, 16 Jul 2016 02:53:58 -0400 Subject: Clean Singleton Docstrings In-Reply-To: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> Message-ID: <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> On Sat, Jul 16, 2016, at 02:29, Chris Angelico wrote: > The difference between ints and floats can lead to bugs, too. Which > one should we eliminate? Eliminate both of them. Move to a single abstract numeric type* a la Scheme, with an "inexact" attribute (inexact numbers may or may not be represented by a float, or by the same bigint/decimal/rational types as exact ones with a flag set to mark them as inexact.) *which may have multiple concrete representations, just as our single abstract unicode string type has different concrete representations for ASCII, Latin-1, UCS-2, and UCS-4. From rosuav at gmail.com Sat Jul 16 03:27:43 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jul 2016 17:27:43 +1000 Subject: Clean Singleton Docstrings In-Reply-To: <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> Message-ID: On Sat, Jul 16, 2016 at 4:53 PM, Random832 wrote: > On Sat, Jul 16, 2016, at 02:29, Chris Angelico wrote: >> The difference between ints and floats can lead to bugs, too. Which >> one should we eliminate? > > Eliminate both of them. Move to a single abstract numeric type* a la > Scheme, with an "inexact" attribute (inexact numbers may or may not be > represented by a float, or by the same bigint/decimal/rational types as > exact ones with a flag set to mark them as inexact.) > > *which may have multiple concrete representations, just as our single > abstract unicode string type has different concrete representations for > ASCII, Latin-1, UCS-2, and UCS-4. Thing is, a Unicode string could be represented in exactly one way (UCS-4), with identical semantics. Look at Py2's "wide build" (eg most Linux builds). The rest is just optimization. With a single abstract numeric type, what exactly does "inexact" mean, where does it come from, and how does that affect the expected behaviour and performance of numbers? Will an "Exact" non-integer be stored as Decimal or Fraction? How do you know? They have vastly different semantics, and you should be able to choose. ChrisA From marko at pacujo.net Sat Jul 16 03:58:53 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 16 Jul 2016 10:58:53 +0300 Subject: Clean Singleton Docstrings References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> Message-ID: <87eg6uvwsi.fsf@elektro.pacujo.net> Chris Angelico : > With a single abstract numeric type, what exactly does "inexact" mean, > where does it come from, and how does that affect the expected > behaviour and performance of numbers? Not much is said in the standard: Thus inexactness is a contagious property of a number. If two implementations produce exact results for a computation that did not involve inexact intermediate results, the two ultimate results will be mathematically equivalent. This is generally not true of computations involving inexact numbers since approximate methods such as floating point arithmetic may be used, but it is the duty of each implementation to make the result as close as practical to the mathematically ideal result. Exactness should be considered a flag that expresses whether the result is an approximation. > Will an "Exact" non-integer be stored as Decimal or Fraction? How do > you know? They have vastly different semantics, and you should be able > to choose. The manual of the Scheme implementation would likely explain the particular properties of its number system implementation. At its simplest, you could have an implementation that only supports, say, signed 16-bit exact integers. All other numbers would be inexact floats. Implementations are encouraged, but not required, to support exact integers and exact rationals of practically unlimited size and precision, and to implement the above procedures and the / procedure in such a way that they always return exact results when given exact arguments. If one of these procedures is unable to deliver an exact result when given exact arguments, then it may either report a violation of an implementation restriction or it may silently coerce its result to an inexact number. Such a coercion may cause an error later. An implementation may use floating point and other approximate representation strategies for inexact numbers. This report recommends, but does not require, that the IEEE 32-bit and 64-bit floating point standards be followed by implementations that use flonum representations, and that implementations using other representations should match or exceed the precision achievable using these floating point standards [12]. In particular, implementations that use flonum representations must follow these rules: A flonum result must be represented with at least as much precision as is used to express any of the inexact arguments to that operation. It is desirable (but not required) for potentially inexact operations such as sqrt, when applied to exact arguments, to produce exact answers whenever possible (for example the square root of an exact 4 ought to be an exact 2). Marko From steve at pearwood.info Sat Jul 16 04:54:31 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 16 Jul 2016 18:54:31 +1000 Subject: Clean Singleton Docstrings References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> Message-ID: <5789f649$0$1622$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Jul 2016 04:53 pm, Random832 wrote: > On Sat, Jul 16, 2016, at 02:29, Chris Angelico wrote: >> The difference between ints and floats can lead to bugs, too. Which >> one should we eliminate? > > Eliminate both of them. Move to a single abstract numeric type* a la > Scheme, with an "inexact" attribute (inexact numbers may or may not be > represented by a float, or by the same bigint/decimal/rational types as > exact ones with a flag set to mark them as inexact.) > > *which may have multiple concrete representations, just as our single > abstract unicode string type has different concrete representations for > ASCII, Latin-1, UCS-2, and UCS-4. No, that's not going to work. It works for Unicode because the implementation *really is just a detail*. Whether 'A' is represented as a seven-bit ASCII code, 8-bit Latin-1 code, 16-bit UCS-2 code or 32-bit UCS-4 code makes no difference to the behaviour of the string. (There may or may not be performance differences, but that's a separate issue.) But that doesn't hold for numbers. For a combination of accidental, intentional and historical reasons, we need to support multiple numeric types with different behaviour sometimes even different APIs. For example, different int types behave differently on overflow; floats have signed zeroes and infinities but fractions don't, etc. But most importantly, one needs to be able to distinguish between (say) real numbers and complex numbers, where sqrt(x) and sqrt(x+0j) do not necessarily return the same value. Or you want to implement (say) "integers modulo 12" such that 11+1 gives 0. You can't do that if you are limited to a single abstract Number type. Still, there's probably a lot we could do to improve the ability to duck-type numbers in Python. For instance, it is a nuisance that we write: math.isfinite(x) for floats, but x.is_finite() for Decimals. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Sat Jul 16 05:14:45 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 16 Jul 2016 19:14:45 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> Message-ID: <5789fb06$0$1605$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Jul 2016 03:58 pm, Rustom Mody wrote: > > From other thread: > > On Saturday, July 16, 2016 at 9:50:13 AM UTC+5:30, Ethan Furman wrote: >> On 07/15/2016 09:04 PM, Rustom Mody wrote: >> >> > Just that suggesting that python's bool notion is straightforward is an >> > unnecessary lie ? especially to newbies. >> >> Python's boolean concept is as simple as it gets -- what is not >> straightforward about it? > > And to expand on my > > On Saturday, July 16, 2016 at 11:18:48 AM UTC+5:30, Rustom Mody wrote: >> FWIW My belief: In general its nonsensical > > C's 0 is false; rest-of-universe is true is a mess Really? In what way? As far as I know, C requires bools to be ints, not arbitrary values, and the compiler will enforce that. What mess do you get from C allowing 2 as well as 1 to be treated as true? > Python increases the mess by making the false-y candidates also > non-singleton So you say, but you haven't demonstrated this. > This seems to work for container-like objects like lists,strings,sets, etc > with None and 0 being somewhat elliptical analogues Right. This is a good, concrete, practical example that duck-typed truthy and falsey values DOES work: it works for numbers, it works for strings, it works for containers. > But when we allow __bool__ to be available for any and every thing and > give it some implicit random definition, this is just plain nonsense. > > [What is the bool-nature -- aka Buddha-nature -- of graphs question > [remains yet answered] No, I already answered that in the earlier thread. Graphs are collections or sequences of nodes. An empty graph (one with zero nodes) should be falsey; all other graphs (one or more nodes) should be truthy. I say "should", not "must". Practicality beats purity: if your application has a specific need for (let's say) a graph with exactly two cycles to be considered falsey, and all others to be truthy, then you are free to define your graph type that way. As an internal application-only class, that's probably okay, but as a generic graph type in a library, it's probably a bad idea. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From mal at europython.eu Sat Jul 16 05:33:42 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Sat, 16 Jul 2016 11:33:42 +0200 Subject: EuroPython 2016: Recruiting Offers Message-ID: <5789FF76.1030304@europython.eu> Many of our sponsors are looking for new employees, so EuroPython 2016 is not only an exciting conference, but may very well also be your chance to find the perfect job you?ve always been looking for. Sponsor job board ----------------- We will post sponsor recruiting offers on the job board of our website: *** EuroPython 2016 Job Board *** https://ep2015.europython.eu/en/sponsor/job-board/ Sponsor recruiting messages --------------------------- If you want to receive the sponsor messages directly to your inbox, please log in to the website and enable the recruiting message option in your privacy settings. With gravitational regards, -- EuroPython 2016 Team http://ep2016.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/754246761380798464 Thanks. From steve at pearwood.info Sat Jul 16 05:46:34 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 16 Jul 2016 19:46:34 +1000 Subject: Clean Singleton Docstrings References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> Message-ID: <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> Oh, and a further thought... On Sat, 16 Jul 2016 04:53 pm, Random832 wrote: > Eliminate both of them. Move to a single abstract numeric type* a la > Scheme, with an "inexact" attribute (inexact numbers may or may not be > represented by a float, or by the same bigint/decimal/rational types as > exact ones with a flag set to mark them as inexact.) But that's *wrong*. Numbers are never inexact. (You can have interval arithmetic using "fuzzy numbers", but they're ALWAYS inexact.) It is calculations which are exact or inexact, not numbers. There's no a priori reason to expect that 0.499999 is "inexact" while 0.5 is "exact", you need to know the calculation that generated it: py> from decimal import * py> getcontext().prec = 6 py> Decimal("9.000002")/6 # inexact Decimal('1.50000') py> Decimal(1)/2 - Decimal('1e-6') # exact Decimal('0.499999') It seems to me that unless you're prepared to actually do some sort of error tracking, just having an "inexact/exact" flag is pretty useless. If I perform a series of calculations, and get 1.0 as the result, and the inexact flag is set, that doesn't mean that 1.0 is the wrong answer -- it may be that the errors have cancelled and 1.0 is the exact answer. Or it may be that the error bound is 1.0 ? 10000, and the calculation has diverged so far from the correct result that it is useless. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From mal at europython.eu Sat Jul 16 06:12:38 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Sat, 16 Jul 2016 12:12:38 +0200 Subject: EPS Board Candidates for 2016/2017 Message-ID: <578A0896.1030804@europython.eu> At this year?s General Assembly we will vote in a new board of the EuroPython Society: http://www.europython-society.org/post/146998034935/invitation-to-the-europython-society-general This posting is also available as blog post: http://www.europython-society.org/post/147488545100/eps-board-candidates-for-20162017 List of Board Candidates ======================== The EPS bylaws require one chair and 2 - 6 board members. The following candidates have stated their willingness to work on the EPS board. We are presenting them here (in alphabetical order). Borja Ayerdi ------------ PhD Student / Co-Founder and CEO of Neurita / Treasurer Borja is a PhD student in the University of the Basque Country. He has a degree in Information Engineering of the same university. His PhD thesis is focused in several areas of machine learning applications to image processing, including aortic and brain imaging as well as hyperspectral satellite imaging. He uses Python for his research projects. He is a co-founder and the treasurer of the non-profit Python San Sebastian society (ACPySS). With the local community he is co-organizer of Python San Sebastian Conference Series. He is member of the EuroPython 2015 and 2016 core organization team. He loves the social interaction and the community. Christian Calogero Barra ------------------------ Curious / Traveler / Pythonista / Student of Statistics @UNIPD >From 2015 he is a member of the EuroPython Organisers, chair of the Web workgroup and a member of the Program and Support workgroup. He is a Free Software enthusiasm and he would like to teach Python to european kids. Until 2014 he had a company in the renewable energy sector, company founded in 2009. He is also a member of PyCon Italia Organisers and Python Italia Association and plans to join other Python Communities in Europe. Currently is studying Statistics at the University of Padua, with a focus on big data and technology applications. When he is not having fun with his computer he likes to enjoy Travels, the Nature, sports and books. Oier Echaniz Beneitez --------------------- PhD Student / Consultant / Chair of ACPySS Oier currently is a PhD Student in the University of the Basque Country. He has a degree in Information Engineering from the same university. His PhD is focused in medical imaging, cancer diagnosis and machine learning. He uses Python in his daily programming projects. He is also co-founder and chair of the Python San Sebastian society (ACPySS), a non-profit organization involved in the use of Python, Free Software and Technology in business and education. With the local community he co-organized a Software Carpentry and is co-organizer in the Python San Sebastian conference series. He is member of the EuroPython 2015 and 2016 core organization team. In his leisure time he helps as an IT expert in a non-profit organization called ASPANOGI. This organization takes care of children with cancer, teaching them computer science and providing them tools and machines where they can play during hospitalization. Joaquin Berenguer ----------------- PhD / Consultant / Software Engineering Manager Joaquin is Director at Berentec, a Professional Services Company. He has a MS in Telecommunication at University of Madrid, and MS in Robotics at University of Alicante, Services Manager at Sybase during 19 years. Python is my favorite Language, and EPS gives the opportunity to be engaged in the future of this Language. Dr. Darya Chyzhyk ----------------- PhD / Python programming enthusiastic for research and science Currently, Darya is a Post-Doc at the University of Florida, USA. She has a degree in applied mathematics and defended her thesis in computer science. Last 7 years Darya has been working on computer aided diagnostic computer systems for brain diseases at the University of the Basque Country, Spain and she is a member of of the Computational Intelligence Group since 2009. Her aim is to develop computational methods for brain MRI processing and analysis, including open sours tools, that help to the medical people in their specific pathologies research studies. She has experience in International Conference organization and take part in the events for the teenagers and kids such as Week of science. Participant in more than 10 international science conference, trainings and summer courses. Board member of Python San Sebastian Society (ACPySS) and on-site team of EuroPython 2015 and 2016. Alexander Hendorf ----------------- Pythonista / CTO / Speaker / Data-Nerd As Chief Information Officer of German management consultancy K?nigsweg, Alexander is guiding enterprises and institutions through change processes of digitalization and automation. Alexander always loved data almost as much as music and so no wonder he?s organizer of local meet ups and one of the 25 mongoDB Community Masters. He loves to share this expertise and engages in the global community as program chair of the EuroPython conference, speaker and trainer at multiple international conferences. Since 2015 he is member of the EuroPython core organization team. Marc-Andr? Lemburg ------------------ Pythonista / CEO / Coach / Consultant Marc-Andre is the CEO and founder of eGenix.com, a Python-focused project and consulting company based in Germany. He has a degree in mathematics from the University of D?sseldorf. His work with and for Python started in 1994. He became Python Core Developer in 1997, designed and implemented the Unicode support in Python and continued to maintain the Python Unicode implementation for more than a decade. Marc-Andre is a founding member of the Python Software Foundation (PSF) and has served on the PSF Board several times. In 2002, Marc-Andre was on the executive committee to run the first EuroPython conference in Charleroi, Belgium. He also co-organized the second EuroPython 2003 conference. Since then, he has attended every single EuroPython conference and continued being involved in the workings of the conference organization. In 2012, he was elected as board member of the EuroPython Society (EPS). He enjoyed the last few years working with the EPS board members on steering the EuroPython conference to the new successful EuroPython Workgroup structures to sustain the continued growth, while maintaining the EuroPython spirit and fun aspect of the conference. For the EuroPython 2016 edition, Marc-Andre chaired the EuroPython Admin WG and Communications WG and contributed to several other WGs. He worked on the EuroPython website, signed up new sponsors, setup the conference app, wrote tools for the registration desk, the schedule and the speaker lists. He also setup the pre-launch website back in Nov 2015, helped running the budget and kept an eye on the EPS operations. Going forward, he would like to broaden the scope of the EPS, aiding Python adoption in Europe, enable it to provide full financial backing of the conference and prepare it for a bright future. Anthon van der Neut ------------------- Consultant / Software Engineering Manager He has been working with Python on a professional basis since 1998, after having been introduced to the language a few years earlier while working in Amsterdam. Since 2007 he maintains the C implementation of OrderedDict he developed, used by those pythonistas for whom a Pure Python implementation is not fast enough. He has spoken at and visited PyCon and visited several EuroPythons after moving back to Europe. He has managed software development in companies across 3 continents, primarily oriented at 3D resp. 2D computer graphics and media management software. This included managing the Commotion development team, then used at ILM for rotoscoping Star Wars episodes I-III. He was quaestor on the board of the student society Augustinus while studying Mathematics, Japanese and Linguistics in Leiden. He was founding chairman of the Dutch 68000 user group (back in 1984 when that processor was state-of-the-art) and published about his work on how to hook up a floating point coprocessor in his Atari ST, as well as on how to adapt the libraries of Modula-2 to use it. More recently he has managed the website and member administration of his local karate-club. When not working on Python, but still at the computer, he can be found answering questions on the Unix & Linux resp. Ebooks StackExchange sites, or refreshing his math skills at Khan Academy where he is one of the few to hold the coveted Tesla badge. When detached from his keyboard, he can be found cooking for his teenage daughter or practising karate. He joined the EPS as he likes to work with like minded people in a multicultural environment promoting his favourite programming language. Dr. Alexandre Manhaes Savio --------------------------- Pythonista / PhD / Co-Founder and CTO / Trainer / Spokesperson Alex has a PhD on machine learning applied to different modalities of brain MRI for the detection of neurodegeneration and psychiatric disorders. After that he tried to start a company, but instead co-founded a local Python society called ACPySS. He was one of the core organizers of EP2015 and now EP2016. He currently works as a researcher in the Nuclear Medicine Department of the university clinic of the Technical University of Munich in Germany. There he contributes to and create neuroimaging modules with Python as well as code to improve the efficiency of the EuroPython organization tasks. He doesn?t know very well what to do with his life so he is trying to enjoy it for now. What does the EPS Board do ? ---------------------------- The EPS board runs the day-to-day business of the EuroPython Society. It is allowed to enter contracts for the society and handle any issues that have not been otherwise regulated in the bylaws or by the General Assembly. Most business is handled by email on the board mailing list, board meetings are usually run as conference calls. Board members are generally expected to take on leadership roles within the EuroPython Workgroups. Enjoy, -- EuroPython Society http://www.europython-society.org/ From steve at pearwood.info Sat Jul 16 06:16:49 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 16 Jul 2016 20:16:49 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> Message-ID: <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Jul 2016 03:48 pm, Rustom Mody wrote: > On Thursday, June 30, 2016 at 10:52:50 PM UTC+5:30, Steven D'Aprano wrote: >> Okay, if you think that automata cannot be empty, I'll accept that. In >> that case, then I'll change my answer and say that __bool__ for automata >> should simply return True. All automata should be truthy. >> > > I am not sure with what tone of voice you are saying that A standard, non-sarcastic tone of voice. > If ... ?return True? is about as good -- ie useful -- as (say) > > def __bool__(self): > from random import random > return int(2*random()) > > then I think we agree No, I don't agree with that. "Emptiness" or "zeroness" or "falsity" doesn't necessarily make sense for every single kind of object. If we were modelling (say) Employees, then I would probably model all Employees as truthy. That's easy to do: all objects are truthy by default, so I don't have to do a thing. If there is some concept of an "empty/null/do-nothing" automata, then I would consider making such null automata falsey. But I'm no sure I would care enough to bother. For example, functions are all truthy, even do-nothing functions. > But then there is a well-established behavior pattern in python > captured by the contexts that raise AttributeError/NameError/TypeError etc > viz For things that are undefined we are told politely they are undefined > > IOW Why say something is useless and define it rather than just leave > undefined something that is ill-defined. You are forgetting that you're not necessarily encountering automata in a context where you are expecting an automata and nothing else: x = Turing_Machine(foo) if x: x.run() else: x.blibbet() You may encounter one in code that is expecting arbitrary objects, without caring whether they are floats or HTTPServers or re.MatchObjects or automata or Employees or something else: for obj in bunch_of_objects: if obj: turn_left() else: turn_right() There's an argument in favour of Pascal-style "true booleans" that require you to use True and False *only* in boolean contexts; and there's an argument in favour of Python's truthiness where any object can duck-type in a bool context; but what doesn't make sense is to have *some* objects be usable as true/false, forcing you to write code like this everywhere you have to deal with arbitrary truthy objects: for obj in bunch_of_objects: try: # Okay for collections, sequences, ints, floats, None, # FooManagers, HttpServers, Dogs, Horses, Pizzashops, etc. flag = bool(obj) except TypeError: # But not okay for Automata, Employees, Cats, PrintFormatters, etc. flag = True # default to true, say if flag: turn_left() else: turn_right() That's just awful language design. You should have either two booleans only, or all objects should be booleans. > If on the other hand you are giving that ?return True?as a serious useful > definition? Sure. An automata is an object, and by default, all objects are "something" and hence truthy. That's the "no-brainer" answer, it requires no justification at all. If you think the answer should be something else, *that* is what needs justification. Why shouldn't it be truthy? > If both you and Chris tripped up on a right definition of an ?empty? > automaton and regex respectively, I believe it demonstrates that getting > boolishness for an arbitrary type right is at least non-trivial. [FWIW My > belief: In general its nonsensical] Firstly, I disagree that I tripped up on anything. You haven't given any reason to think that Automata objects shouldn't be truthy, and even if you do, isn't that just a matter of opinion? But in general, deciding on whether an arbitrary object should be truthy or falsey is not hard, and most of the time you don't have to do a thing to get the right behaviour. - Does the object represent a collection or sequence? If so, then the right behaviour is to delegate to `len(obj) != 0`. - Does the object represent a number? If so, then the right behaviour is to delegate to `obj != 0`. - Does the object represent (in some sense) nothing rather than something? That is, is it a reification of "there's nothing here"? E.g. something like None in Python, null/nil pointers, Void, or Undefined. Then it should be falsey. - Otherwise, it represents something rather than nothing, and unless you have pressing reason to do otherwise, it should be truthy. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Sat Jul 16 06:21:13 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 16 Jul 2016 20:21:13 +1000 Subject: math.frexp References: <5788cb76$0$1599$c3e8da3$5496439d@news.astraweb.com> <5789101c$0$1615$c3e8da3$5496439d@news.astraweb.com> <87eg6uejjx.fsf@jester.gateway.pace.com> Message-ID: <578a0a9a$0$1610$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Jul 2016 06:24 am, Paul Rubin wrote: > Steven D'Aprano writes: >> But this can give some protection against overflow of intermediate >> values. > > Might be simplest to just add the logarithms. Look up Kahan summation > for how to do that while minimizing loss of precision. Simplest, but least accurate, even with Kahan summation or equivalent. Even a naive implementation of product does better: py> from operator import mul py> reduce(mul, [1.0, 2.0, 3.0, 4.0, 5.0]) 120.0 py> math.exp(math.fsum(math.log(x) for x in [1.0, 2.0, 3.0, 4.0, 5.0])) 119.99999999999997 That second answer might be good enough for getting an astronaut to the Moon, but it's not good enough to get them back again *wink* -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From mal at europython.eu Sat Jul 16 06:40:41 2016 From: mal at europython.eu (M.-A. Lemburg) Date: Sat, 16 Jul 2016 12:40:41 +0200 Subject: EuroPython 2017 On-site Teams: Call for Interest (CFI) Message-ID: <578A0F29.2050004@europython.eu> The EuroPython Society (EPS) is happy to announce the Call for Interest (CFI) for EuroPython 2017: http://www.europython-society.org/post/147488978255/europython-2017-on-site-teams-call-for-interest The purpose of this call is to get to know teams willing to help organize the EuroPython conference on site at a suitable location and determine the Call for Participation (CFP) candidates in the second phase of the selection process. If your team is interested in submitting a CFP in phase two of the process, please send in a CFI proposal. Some important dates: * 2016-07-22 CFIs received until this day will be announced in the conference closing session * 2016-07-29 Deadline for CFI submissions Enjoy, -- EuroPython Society http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europythons/status/754261202260361217 Thanks. From rosuav at gmail.com Sat Jul 16 06:46:14 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jul 2016 20:46:14 +1000 Subject: Operator Precedence/Boolean Logic In-Reply-To: <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jul 16, 2016 at 8:16 PM, Steven D'Aprano wrote: >> If both you and Chris tripped up on a right definition of an ?empty? >> automaton and regex respectively, I believe it demonstrates that getting >> boolishness for an arbitrary type right is at least non-trivial. [FWIW My >> belief: In general its nonsensical] > > Firstly, I disagree that I tripped up on anything. You haven't given any > reason to think that Automata objects shouldn't be truthy, and even if you > do, isn't that just a matter of opinion? I also disagree that I "tripped up", but there is room for differing decisions in API design, and this is one of them. I can't say perfectly, from my armchair (which I'm not in anyway - way too cumbersome for a desktop computer), which objects are capable of being "empty" and which are not. The implementer of the automaton class or the regex class has to decide what counts as "empty". As Steven says, the default is that they're all truthy, and onus is on the implementer to demonstrate that this object is functionally equivalent to 0 or an empty collection. (And it's possible for ANYONE to get that wrong - cf timedelta.) ChrisA From steve at pearwood.info Sat Jul 16 07:02:13 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 16 Jul 2016 21:02:13 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: <578a1436$0$1601$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Jul 2016 08:46 pm, Chris Angelico wrote: > As Steven says, > the default is that they're all truthy, and onus is on the implementer > to demonstrate that this object is functionally equivalent to 0 or an > empty collection. (And it's possible for ANYONE to get that wrong - cf > timedelta.) I think you're thinking of time values, not timedelta values. Until recently, midnight was considered falsey just because it happened to be implemented as 0 seconds: [steve at ando ~]$ python3.3 -c "import datetime;print(bool(datetime.time(0)))" False [steve at ando ~]$ python3.6 -c "import datetime;print(bool(datetime.time(0)))" True That was a real bug, letting the concrete implementation show through into the abstract API by accident, but it's corrected now. timedelta values, being a difference between two times, have a qualitative difference between delta = 0 and every other value. A difference of zero is no difference at all, and it makes sense to make that falsey. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Sat Jul 16 08:15:56 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 16 Jul 2016 05:15:56 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: <829546d9-6575-4aaa-8c8e-483676af6594@googlegroups.com> Earlier you said: > > 1. Graphs -- the kind mathematicians define with "Let G =(V,E) be a > > graph..." > > I would make the empty graph (zero nodes) falsey, and non-empty graphs (one > or more nodes) truthy. > > > > 2. Automata which in a way are special kinds of graphs > > As above. Now you say: > > If on the other hand you are giving that ?return True?as a serious useful > > definition? > > Sure. An automata is an object, and by default, all objects are "something" > and hence truthy. That's the "no-brainer" answer, it requires no > justification at all. If you think the answer should be something else, > *that* is what needs justification. Why shouldn't it be truthy? How do we put these two together? Maybe thusly? https://en.wikibooks.org/wiki/Sufism/Nasrudin#Of_any_two_options_choose_the_third From rustompmody at gmail.com Sat Jul 16 08:33:13 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 16 Jul 2016 05:33:13 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <3a840cef-24d2-4abb-8e5b-dc80bf48944d@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, July 16, 2016 at 4:16:34 PM UTC+5:30, Chris Angelico wrote: > On Sat, Jul 16, 2016 at 8:16 PM, Steven D'Aprano wrote: > >> If both you and Chris tripped up on a right definition of an ?empty? > >> automaton and regex respectively, I believe it demonstrates that getting > >> boolishness for an arbitrary type right is at least non-trivial. [FWIW My > >> belief: In general its nonsensical] > > > > Firstly, I disagree that I tripped up on anything. You haven't given any > > reason to think that Automata objects shouldn't be truthy, and even if you > > do, isn't that just a matter of opinion? > > I also disagree that I "tripped up", but there is room for differing > decisions in API design, and this is one of them. I can't say > perfectly, from my armchair (which I'm not in anyway - way too > cumbersome for a desktop computer), which objects are capable of being > "empty" and which are not. The implementer of the automaton class or > the regex class has to decide what counts as "empty". As Steven says, > the default is that they're all truthy, and onus is on the implementer > to demonstrate that this object is functionally equivalent to 0 or an > empty collection. (And it's possible for ANYONE to get that wrong - cf > timedelta.) Just to re-iterate what we are talking about (and before you continue to score self-goals): You folks ? Chris and Steven ? likely know a lot more python than I do ? no one questioning that. You also have a bizarre notion that python's property: ?Everything has auto-bool-nature? IS STRAIGHTFORWARD. My point of those examples is to show that with such an outlook you will invariably trip up. Python in fact has a well established rheostat for this: Simple ? Complex ? Complicated If we agree to this bool business being complicated then we are being honest If we agree to it being complex ? well euphemisms are necessary in civilized society I guess If however you insist its simple, you will trip up. And the fact that that may be nothing to do with trick questions posed by me is seen in the other thread where Peter saw a subtle distinction in boolishness that we all missed. So yes ?Anyone can get that wrong? is a self-goal You are making my point and then saying you disagree. With what/whom? Yourself?? From gerald.britton at gmail.com Sat Jul 16 09:58:31 2016 From: gerald.britton at gmail.com (Gerald Britton) Date: Sat, 16 Jul 2016 09:58:31 -0400 Subject: Operator Precedence/Boolean Logic Message-ID: >Earlier you said: >* > 1. Graphs -- the kind mathematicians define with "Let G =(V,E) be a *>* > graph..." *> >* I would make the empty graph (zero nodes) falsey, and non-empty graphs (one *>* or more nodes) truthy. *> > >* > 2. Automata which in a way are special kinds of graphs *> >* As above. * >Now you say: >* > If on the other hand you are giving that ?return True?as a serious useful *>* > definition? *> >* Sure. An automata is an object, and by default, all objects are "something" *>* and hence truthy. That's the "no-brainer" answer, it requires no *>* justification at all. If you think the answer should be something else, *>* *that* is what needs justification. Why shouldn't it be truthy? * >How do we put these two together> easy peasy: lists, tuples, dicts etc are also objects. They define their truthiness by the presence of members. An empty list has a boolean value of false. for a custom object, you can accept the default boolean value of true or override __bool__ so that it returns what you want. So for a graph G, I'd say if |V| = |E| = 0, G has a boolean value of false. Maybe thusly?https://en.wikibooks.org/wiki/Sufism/Nasrudin#Of_any_two_options_choose_the_third ------------------------------ - Previous message (by thread): Operator Precedence/Boolean Logic - Next message (by thread): EuroPython 2016: Recruiting Offers - *Messages sorted by:* [ date ] [ thread ] [ subject ] [ author ] ------------------------------ More information about the Python-list mailing list -- Gerald Britton, MCSE-DP, MVP LinkedIn Profile: http://ca.linkedin.com/in/geraldbritton From rosuav at gmail.com Sat Jul 16 10:26:19 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 00:26:19 +1000 Subject: Operator Precedence/Boolean Logic In-Reply-To: <578a1436$0$1601$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a1436$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jul 16, 2016 at 9:02 PM, Steven D'Aprano wrote: > On Sat, 16 Jul 2016 08:46 pm, Chris Angelico wrote: > >> As Steven says, >> the default is that they're all truthy, and onus is on the implementer >> to demonstrate that this object is functionally equivalent to 0 or an >> empty collection. (And it's possible for ANYONE to get that wrong - cf >> timedelta.) > > I think you're thinking of time values, not timedelta values. Until > recently, midnight was considered falsey just because it happened to be > implemented as 0 seconds: > > [steve at ando ~]$ python3.3 -c "import datetime;print(bool(datetime.time(0)))" > False > [steve at ando ~]$ python3.6 -c "import datetime;print(bool(datetime.time(0)))" > True > > That was a real bug, letting the concrete implementation show through into > the abstract API by accident, but it's corrected now. > > timedelta values, being a difference between two times, have a qualitative > difference between delta = 0 and every other value. A difference of zero is > no difference at all, and it makes sense to make that falsey. Umm, yes. That's the one. Time, not timedelta. My bad. Point still stands, though - the concept of "midnight" does not truly equate to "empty" or "zero", and that bug stood for a long time. ChrisA From steve at pearwood.info Sat Jul 16 12:27:09 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jul 2016 02:27:09 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Jul 2016 10:33 pm, Rustom Mody wrote: > You also have a bizarre notion that python's property: ?Everything has > auto-bool-nature? IS STRAIGHTFORWARD. That's a very strong claim. You're not just pointing out that there may be a few old corner cases here and there where Python's treatment of bools fails to be straightforward, or is a little harder than it appears at first glance. You're making the claim that it is BIZARRE (grossly unconventional or unusual, beyond belief, foolish, laughable, ludicrous, nonsensical, outrageous, ridiculous, crazy) to think that it might be straightfoward. In other words, that it is obviously, clearly not-straightforward. If you really mean your words, and don't wish to step back and make a less extreme claim, then you ought to be easily able to show that Python's use of bools hardly ever works. It's clearly a terrible idea, almost every use of it is a failure, even Blind Freddy can see that it is hard to use and not straightforward. The truthiness API is straightforward. Any value or object is usable in a boolean context, and there is a well-defined protocol for deciding whether arbitrary objects are considered true or false: * If the class defined a __nonzero__ (or __bool__ in Python 3) method, then the truthiness of the object is given by the result of calling that method. * If there is no __nonzero__ (or __bool__) method, but the class defines __len__, which returns zero, then the object is deemed falsey, otherwise it is deemed to be truthy. * If the class lacks both dunder methods, then the object is deemed truthy. This should not be hard to understand. So what part of this system is not straightfoward? (1) Is it that programming the required dunder methods is not necessarily trivial for every imaginable object? Nobody said that had to be. (2) Is it that it may be tricky for the designer of the class to map the class values/objects into the true/false dichotomy? Python gives a simple and, yes, straightforward metaphor to use: if an object represents nothing (an empty container, null, void) then it should be falsey, otherwise it should be truthy. But that doesn't mean that every imaginable class trivially maps into that dichotomy. Suppose we create a tri-state logic class, with three states Yes, No and Maybe. Obviously Yes should map to True, and No to False. What should Maybe map to? We may spend many sleepless hours weighing up the pros and cons of mapping Maybe to True versus Maybe to False. Or we might flip a coin. And yes, Rustom, I'm very familiar with the philosophical objections to the something/nothing distinction. "Is zero truly nothing, or is it some thing distinct from the absence of any number?" I'm not interested in that argument. Let the philosophers count angels, but as far as Python code goes, I'm an intuitionist: if I have zero sheep, that's the same as not having any sheep, or having no sheep. I'm more sympathetic to the view that an empty list is different from absence of a list, therefore it's something, not nothing. Fine, if that's the way you want to reason, go right ahead and do so when you write your own language. But in Python, practicality wins, and empty sequences and collections are treated as "nothing". (It's a metaphor, not a deep philosophical axiom.) (3) Is it that sometimes people write code involving boolean contexts that may not be trivially understood and obviously bug free? Sure they do. So what? Do you expect perfection of code for every feature? (4) Or something else? If so, what is your basis for claiming that this is not straightforward? What part, or parts, is not straightforward? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Sat Jul 16 12:36:09 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jul 2016 02:36:09 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <63fe7ea9-a14f-94a2-cdd5-27aa902fbf6b@online.de> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <829546d9-6575-4aaa-8c8e-483676af6594@googlegroups.com> Message-ID: <578a627b$0$1603$c3e8da3$5496439d@news.astraweb.com> On Sat, 16 Jul 2016 10:15 pm, Rustom Mody wrote: > Earlier you said: > >> > 1. Graphs -- the kind mathematicians define with "Let G =(V,E) be a >> > graph..." >> >> I would make the empty graph (zero nodes) falsey, and non-empty graphs >> (one or more nodes) truthy. >> >> >> > 2. Automata which in a way are special kinds of graphs >> >> As above. If automata are graphs, and there is a zero-node graph that represents an automation, then it should be falsey. If there is no such "empty automation", then there shouldn't be. Was that unclear? If I failed to make that obvious enough for you to understand, then I apologise. It may be that you feel that there's no such thing as an empty automation. Okay, that seems reasonable to me too. One can map functions to flow-charts, which are a special kind of graph too. But a flow chart with no elements is no flow chart at all: even the identity function, or the do-nothing procedure, will be represented by a flow chart with at least one node. So there are no falsey functions. Maybe there are no falsey automata either. > Now you say: > >> > If on the other hand you are giving that ?return True?as a serious >> > useful definition? >> >> Sure. An automata is an object, and by default, all objects are >> "something" and hence truthy. That's the "no-brainer" answer, it requires >> no justification at all. If you think the answer should be something >> else, *that* is what needs justification. Why shouldn't it be truthy? > > > How do we put these two together? Um, in the obvious, straightforward way? What part of my statements is giving you trouble? Should I use smaller words? Bigger words? Draw a picture? Automata were *your* idea. I have no concept of what *your* idea of automata are, except that *you* claim that they are a kind of graph. If you want to specify the semantics of automata that you consider important in detail, then perhaps we can decide which ones should be falsey (if any). Otherwise I'm reduce to talking in generalities, as the question is under-specified. If there are automata equivalent to the empty graph (graph with no nodes), then they should be falsey. All others (those equivalent to graphs with one or more nodes) should be truthy. If you disagree, well, Rustom, it's YOUR class, you tell me under what conditions you think an automation object should be considered truthy or falsey. Mu is not an option. You have to pick one or the other. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python at mrabarnett.plus.com Sat Jul 16 12:58:41 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 16 Jul 2016 17:58:41 +0100 Subject: Operator Precedence/Boolean Logic In-Reply-To: <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0d294d49-2cf0-84be-ebcd-af1d0ffc7222@mrabarnett.plus.com> On 2016-07-16 17:27, Steven D'Aprano wrote: > On Sat, 16 Jul 2016 10:33 pm, Rustom Mody wrote: [snip] > And yes, Rustom, I'm very familiar with the philosophical objections to the > something/nothing distinction. "Is zero truly nothing, or is it some thing > distinct from the absence of any number?" I'm not interested in that > argument. Let the philosophers count angels, but as far as Python code > goes, I'm an intuitionist: if I have zero sheep, that's the same as not > having any sheep, or having no sheep. > [snip] And if you're going to argue that zero is something, then you could also argue that false is something... From rosuav at gmail.com Sat Jul 16 13:06:42 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 03:06:42 +1000 Subject: Operator Precedence/Boolean Logic In-Reply-To: <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <576b8a41$0$2792$c3e8da3$76491128@news.astraweb.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 17, 2016 at 2:27 AM, Steven D'Aprano wrote: > If you really mean your words, and don't wish to step back and make a less > extreme claim, then you ought to be easily able to show that Python's use > of bools hardly ever works. It's clearly a terrible idea, almost every use > of it is a failure, even Blind Freddy can see that it is hard to use and > not straightforward. Anecdotal, yet important, factoid: When I teach Python to people who've come from other languages, I explain it as: "In Python, anything that represents emptiness is false. Everything else is true.". So far, not a single student has failed to understand this, and quite a few have thanked me for the simplicity (as if it's credited to me, rather than just being a reflection of Python's reality). > The truthiness API is straightforward. Any value or object is usable in a > boolean context, and there is a well-defined protocol for deciding whether > arbitrary objects are considered true or false: > > * If the class defined a __nonzero__ (or __bool__ in Python 3) method, then > the truthiness of the object is given by the result of calling that method. > > * If there is no __nonzero__ (or __bool__) method, but the class defines > __len__, which returns zero, then the object is deemed falsey, otherwise it > is deemed to be truthy. > > * If the class lacks both dunder methods, then the object is deemed truthy. This isn't how truthiness is generally understood, though. Do you explain to someone that (1).__bool__() returns True, or do you simply say that 1, being a non-zero number, is true? > But that doesn't mean that every imaginable class trivially maps into that > dichotomy. Suppose we create a tri-state logic class, with three states > Yes, No and Maybe. Obviously Yes should map to True, and No to False. What > should Maybe map to? We may spend many sleepless hours weighing up the pros > and cons of mapping Maybe to True versus Maybe to False. Or we might flip a > coin. Maybe can also raise an exception in __bool__ if it likes. Or, to emphasize the tri-state nature of your logic class, *all* your instances could raise, with a message saying that "if x:" should be "if x >= tri.Maybe:" or "if x is tried.and.True" depending on how you want to handle Maybe. Ultimately, though, computers don't work with Maybes. They work with concrete yes/no answers: should I run this code or not? (In assembly/machine language, probably "should I take this jump or not" covers it all.) Somewhere along the way, you have to turn that Maybe in to either True or False, and that should be *before* you're asking the question "if x:". Perhaps "Maybe" really means "Inherit" (as in the DeScribe style sheet system; you have a tree of styles, and a style could say "Bold: True" or "Bold: False", but if it doesn't, it's shown as "Bold: Maybe" but really means "Bold: Same as parent"), in which case you resolve it with "while x == tri.Maybe: x = self.parent.x" before doing the lookups. Or perhaps Maybe means "the user didn't enter a value", in which case you go with some global default. Or perhaps it means "the data is too borderline to call this one", in which case you flip a coin. Actual physical coin, mind, no simulations here! > And yes, Rustom, I'm very familiar with the philosophical objections to the > something/nothing distinction. "Is zero truly nothing, or is it some thing > distinct from the absence of any number?" I'm not interested in that > argument. Let the philosophers count angels, but as far as Python code > goes, I'm an intuitionist: if I have zero sheep, that's the same as not > having any sheep, or having no sheep. > > I'm more sympathetic to the view that an empty list is different from > absence of a list, therefore it's something, not nothing. Fine, if that's > the way you want to reason, go right ahead and do so when you write your > own language. But in Python, practicality wins, and empty sequences and > collections are treated as "nothing". (It's a metaphor, not a deep > philosophical axiom.) Pike took the opposite view - an empty array is still true. Did you put up a new shopping list? Yes, there's a list there, even though it's currently empty. Both make sense, and both languages have very simple definitions of "this is true, that is false". (And both permit user-defined types to choose whether they're truthy or falsey, so of course someone somewhere has made a pathological case, guaranteed.) Python says that having zero sheep is the same as not having any sheep; Pike says that a box of doughnuts is still a box even when you've eaten all the doughnuts. Most importantly, neither of them is "bizarre". (In most practical usage, it actually works out pretty much the same way.) Rustom, I await evidence from you that (a) new Python programmers are massively confused because of the boolification rules, or (b) transitioning programmers (new to Python but with experience in some other language) are confused, or (c) that this is more of a bug magnet than comparable features, while providing less useful functionality. Go! Prove to us. ChrisA From random832 at fastmail.com Sat Jul 16 14:04:32 2016 From: random832 at fastmail.com (Random832) Date: Sat, 16 Jul 2016 14:04:32 -0400 Subject: Clean Singleton Docstrings In-Reply-To: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> Message-ID: <1468692272.2410242.668163177.52CA7567@webmail.messagingengine.com> On Sat, Jul 16, 2016, at 03:27, Chris Angelico wrote: > Will an "Exact" non-integer be stored as Decimal or > Fraction? How do you know? They have vastly different semantics, and > you should be able to choose. Er, the point is for them to _not_ have different semantics. A decimal storage format would simply be an optimization for a fraction whose denominator is a power of 10 (or of 2 and 5) The semantics of the current Decimal class are those of an inexact number. From marko at pacujo.net Sat Jul 16 14:43:27 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 16 Jul 2016 21:43:27 +0300 Subject: Clean Singleton Docstrings References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <1468692272.2410242.668163177.52CA7567@webmail.messagingengine.com> Message-ID: <8760s5whio.fsf@elektro.pacujo.net> Random832 : > On Sat, Jul 16, 2016, at 03:27, Chris Angelico wrote: >> Will an "Exact" non-integer be stored as Decimal or >> Fraction? How do you know? They have vastly different semantics, and >> you should be able to choose. > > Er, the point is for them to _not_ have different semantics. A decimal > storage format would simply be an optimization for a fraction whose > denominator is a power of 10 (or of 2 and 5) > > The semantics of the current Decimal class are those of an inexact > number. The most common use for Python's Decimal class is *exact* amounts of currency. The exactness of a number in Scheme is just a flag. You can force exactness of a number literal with the #e or #i prefix: (exact? #e1.2e-7) ==> #t # 1.2e-7 exactly (exact? #i7) ==> #f # approximately 7 Marko From no.email at nospam.invalid Sat Jul 16 15:49:21 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 16 Jul 2016 12:49:21 -0700 Subject: math.frexp References: <5788cb76$0$1599$c3e8da3$5496439d@news.astraweb.com> <5789101c$0$1615$c3e8da3$5496439d@news.astraweb.com> <87eg6uejjx.fsf@jester.gateway.pace.com> <578a0a9a$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87a8hhe532.fsf@jester.gateway.pace.com> Steven D'Aprano writes: >>> protection against overflow of intermediate values. >> Might be simplest to just add the logarithms. > Simplest, but least accurate, even with Kahan summation or equivalent. Well the idea was to avoid overflow first, then hold on to whatever precision you have after that. Is there a way to use extended (e.g. 80-bit) floats in numpy/scipy/etc.? From rosuav at gmail.com Sat Jul 16 17:02:14 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 07:02:14 +1000 Subject: Clean Singleton Docstrings In-Reply-To: <1468692272.2410242.668163177.52CA7567@webmail.messagingengine.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <1468692272.2410242.668163177.52CA7567@webmail.messagingengine.com> Message-ID: On Sun, Jul 17, 2016 at 4:04 AM, Random832 wrote: > On Sat, Jul 16, 2016, at 03:27, Chris Angelico wrote: >> Will an "Exact" non-integer be stored as Decimal or >> Fraction? How do you know? They have vastly different semantics, and >> you should be able to choose. > > Er, the point is for them to _not_ have different semantics. A decimal > storage format would simply be an optimization for a fraction whose > denominator is a power of 10 (or of 2 and 5) > > The semantics of the current Decimal class are those of an inexact > number. In that case, an 'Exact' non-integer will have appalling performance - fractions.Fraction doesn't really work all that nicely when the numbers start getting huge. ChrisA From marko at pacujo.net Sat Jul 16 17:27:34 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 17 Jul 2016 00:27:34 +0300 Subject: Clean Singleton Docstrings References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <1468692272.2410242.668163177.52CA7567@webmail.messagingengine.com> Message-ID: <87wpkluvcp.fsf@elektro.pacujo.net> Chris Angelico : > In that case, an 'Exact' non-integer will have appalling performance - > fractions.Fraction doesn't really work all that nicely when the > numbers start getting huge. In Scheme, any math operation is allowed to drop exactness: If one of these procedures is unable to deliver an exact result when given exact arguments, then it may either report a violation of an implementation restriction or it may silently coerce its result to an inexact number. Now, that's neither the recommendation nor the reality; exactness is preserved at the expense of efficiency. However, that's unlikely to be an issue in the normal use of Python's Decimal. Marko From shrey.desai at gmail.com Sat Jul 16 18:14:52 2016 From: shrey.desai at gmail.com (shrey.desai at gmail.com) Date: Sat, 16 Jul 2016 15:14:52 -0700 (PDT) Subject: PEP Request: Advanced Data Structures Message-ID: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> I have found it slightly frustrating that Python does not have built-in support for advanced data structures (Linked Lists, Stacks/Queues, BST) in its distribution. Many computer science students, developers, and software engineers rely on these data structures; having the data structures be a part of the distribution and be maintained by the Python community would be immensely useful. Currently, we are required to write our own modules that represent these data structures and rigorously test/refactor them before we can actually use them. This gets annoying because instead of spending time USING the "correct" version of the data structure, we have to spend time creating them in the first place. Programming languages like Java have support for Linked Lists, for example, which makes it easy to just use it instead of trying to create it over again. As a computer science undergraduate student, I don't want to spend time writing the module but instead I want to work with it, play around with it, and do problems with it. I know Python currently has a Queue module, but this can definitely be expanded. There are other more advanced data structures out there, like AVL trees, splay trees, and tries, but I think that would be overkilll. Having these data structures above would be immensely useful. I'm looking to create a PEP for this issue and some people that would be willing to 1) vouch for this idea and 2) co-author the draft. Eventually, we would be co-developers for the project as well. Who's in? From rosuav at gmail.com Sat Jul 16 18:18:01 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 08:18:01 +1000 Subject: Clean Singleton Docstrings In-Reply-To: <87wpkluvcp.fsf@elektro.pacujo.net> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <1468692272.2410242.668163177.52CA7567@webmail.messagingengine.com> <87wpkluvcp.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 17, 2016 at 7:27 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> In that case, an 'Exact' non-integer will have appalling performance - >> fractions.Fraction doesn't really work all that nicely when the >> numbers start getting huge. > > In Scheme, any math operation is allowed to drop exactness: > > If one of these procedures is unable to deliver an exact result when > given exact arguments, then it may either report a violation of an > implementation restriction or it may silently coerce its result to an > inexact number. The trouble is, repeated addition of fractions is *able* to deliver an exact result. It just might result in an incredibly slow program. And then if you mix types, does it aim for the greatest possible 'accuracy', even if that's not quite accurate? (For instance, if you add 0.2 to 5/8, does it convert to float or to fraction?) ChrisA From rosuav at gmail.com Sat Jul 16 18:19:42 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 08:19:42 +1000 Subject: PEP Request: Advanced Data Structures In-Reply-To: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> Message-ID: On Sun, Jul 17, 2016 at 8:14 AM, wrote: > I have found it slightly frustrating that Python does not have built-in support for advanced data structures (Linked Lists, Stacks/Queues, BST) in its distribution. Many computer science students, developers, and software engineers rely on these data structures; having the data structures be a part of the distribution and be maintained by the Python community would be immensely useful. > Why do you need a linked list? That's an implementation detail; why not simply use a regular list? Not trolling, genuinely asking. Is there something that you specifically need those exact structures for? Also: You may find what you want on PyPI. There's no need for them to be in the core language if they can be published as third-party modules. ChrisA From shrey.desai at gmail.com Sat Jul 16 18:33:12 2016 From: shrey.desai at gmail.com (Shrey Desai) Date: Sat, 16 Jul 2016 15:33:12 -0700 (PDT) Subject: PEP Request: Advanced Data Structures In-Reply-To: References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> Message-ID: <7af57bf9-72d7-4d0f-8db4-3ea02d701a5f@googlegroups.com> On Saturday, July 16, 2016 at 3:19:56 PM UTC-7, Chris Angelico wrote: > On Sun, Jul 17, 2016 at 8:14 AM, wrote: > > I have found it slightly frustrating that Python does not have built-in support for advanced data structures (Linked Lists, Stacks/Queues, BST) in its distribution. Many computer science students, developers, and software engineers rely on these data structures; having the data structures be a part of the distribution and be maintained by the Python community would be immensely useful. > > > > Why do you need a linked list? That's an implementation detail; why > not simply use a regular list? > > Not trolling, genuinely asking. Is there something that you > specifically need those exact structures for? > > Also: You may find what you want on PyPI. There's no need for them to > be in the core language if they can be published as third-party > modules. > > ChrisA Hi Chris, thanks for the reply. There's a couple of reasons why I would need a Linked List (and other data structures): - Education: the Linked List is a core data structure that CS undergraduates (among others) use and study, so it is vital that they have hands on access to them. A list is basically a dynamic array; the only property it shares with a Linked List is that it's dynamic. - Development: the use of correct data structures is important when developing applications, especially for issues like scaling and efficiency. For instance, when working with polynomials, Linked Lists provide a great interface to access and edit them. Also, I have a couple of issues with them being published as third-party modules: 1. These data structures have to be rock solid. They should be clearly defined, rigorously tested, and they should simply work. Python would put more emphasis on its development rather than some external developer that might quit half way. 2. Some external packages might contain better data structures than others. For instance, there might be some "DataStructures" package that contains everything, but maybe some developer published a "LinkedList" package that has the best Linked List implementation and some other developer published a "BST" package that has the best BST implementation. Why mix and match when everything can be in one place? 3. Python, fundamentally, is an easy to use language and it should stay that way. Beginners shouldn't have to worry about installing external modules when the data structures package is in the distribution and all they need to do to use it is import it. From rosuav at gmail.com Sat Jul 16 18:45:12 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 08:45:12 +1000 Subject: PEP Request: Advanced Data Structures In-Reply-To: <7af57bf9-72d7-4d0f-8db4-3ea02d701a5f@googlegroups.com> References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> <7af57bf9-72d7-4d0f-8db4-3ea02d701a5f@googlegroups.com> Message-ID: On Sun, Jul 17, 2016 at 8:33 AM, Shrey Desai wrote: > Hi Chris, thanks for the reply. There's a couple of reasons why I would need a Linked List (and other data structures): > - Education: the Linked List is a core data structure that CS undergraduates (among others) use and study, so it is vital that they have hands on access to them. A list is basically a dynamic array; the only property it shares with a Linked List is that it's dynamic. > - Development: the use of correct data structures is important when developing applications, especially for issues like scaling and efficiency. For instance, when working with polynomials, Linked Lists provide a great interface to access and edit them. > For education, I wouldn't worry too much about performance or edge cases, and just use something really simple: class LinkedList: def __init__(self): self.head = self.tail = None def append(self, item): if self.tail: self.tail = self.tail.append(item) self.head = self.tail = _listitem(item) class _listitem: def __init__(self, item): self.item = item self.next = None def append(self, item): self.next = type(self)(item) return self.next Then add other methods as you teach them (iteration, item removal, etc). Performance is probably terrible, but who cares? You won't notice it in sample code. For development, I'm pretty sure the native CPython list type is going to out-perform anything you could implement as a linked list. Even more so if you're using PyPy, where it knows how to optimize the list (but won't necessarily be able to optimize your type). Instead of messing around with data types, just implement your code using the most simple and obvious style, and worry about performance/scaling/efficiency only if and when you find out that that's a bottleneck. I very much doubt that it will be. ChrisA From vlastimil.brom at gmail.com Sat Jul 16 19:18:30 2016 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 17 Jul 2016 01:18:30 +0200 Subject: math.frexp In-Reply-To: <5788cb76$0$1599$c3e8da3$5496439d@news.astraweb.com> References: <5788cb76$0$1599$c3e8da3$5496439d@news.astraweb.com> Message-ID: 2016-07-15 13:39 GMT+02:00 Steven D'Aprano : > I'm experimenting with various implementations of product(values). Here's a > naive version that easily suffers from overflow: > > from functools import reduce > from operator import mul > > def product_naive(values): > return reduce(mul, values) >... > -- > Steven > -- > https://mail.python.org/mailman/listinfo/python-list Hi, just to add another approach to already proposed ones, I thought about using fractions for computations instead of floats where possible. The accuracy shoud be better, - it works fine for my tests with multiplying however, the downside is - for computing fractional power the fractions fall back to float, as irrational numbers are expected in the output, hence the float overflow is also possible (unless an individual implementation of the root computation would be used in gmean...). The hackish code in adapt_float_exp enhances the accuracy compared to directly building Fractions from large floats in exponential notation. (I can realise, that this approach might be insufficient for the scale you intend to support, due to the mentioned fallback to floats.) Regards, vbr ======================== #! Python # -*- coding: utf-8 -*- from fractions import Fraction def adapt_float_exp(flt): """Return Fraction extracted from float literal in exponential notation.""" if "e" not in str(flt).lower(): return Fraction(flt) else: mant_str, exp_str = str(flt).lower().split("e") return Fraction(mant_str) * 10 ** Fraction(exp_str) def prod_fract(*args): prod = 1 for arg in args: if isinstance(arg, float): arg = adapt_float_exp(arg) prod *= arg return prod def gmean(*args): prod = prod_fract(*args) root = Fraction(prod) ** Fraction(1, len(args)) # fractional power ** - irrational - implemented via floats !! - overflow ... return root print(repr(prod_fract(2.0, 1e200, 1e200, 1e-200, 1e-200, 3.0))) print(repr(gmean(2.0, 1e200, 1e200, 1e-200, 1e-200, 3.0))) From breamoreboy at gmail.com Sat Jul 16 19:21:45 2016 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sat, 16 Jul 2016 16:21:45 -0700 (PDT) Subject: PEP Request: Advanced Data Structures In-Reply-To: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> Message-ID: <9fd86f22-5b57-488e-9bc5-93423a370077@googlegroups.com> On Saturday, July 16, 2016 at 11:15:04 PM UTC+1, Shrey Desai wrote: > I have found it slightly frustrating that Python does not have built-in support for advanced data structures (Linked Lists, Stacks/Queues, BST) in its distribution. Many computer science students, developers, and software engineers rely on these data structures; having the data structures be a part of the distribution and be maintained by the Python community would be immensely useful. > > Currently, we are required to write our own modules that represent these data structures and rigorously test/refactor them before we can actually use them. This gets annoying because instead of spending time USING the "correct" version of the data structure, we have to spend time creating them in the first place. > > Programming languages like Java have support for Linked Lists, for example, which makes it easy to just use it instead of trying to create it over again. As a computer science undergraduate student, I don't want to spend time writing the module but instead I want to work with it, play around with it, and do problems with it. > > I know Python currently has a Queue module, but this can definitely be expanded. There are other more advanced data structures out there, like AVL trees, splay trees, and tries, but I think that would be overkilll. Having these data structures above would be immensely useful. > > I'm looking to create a PEP for this issue and some people that would be willing to 1) vouch for this idea and 2) co-author the draft. Eventually, we would be co-developers for the project as well. > > Who's in? Thanks but no thanks :) I find the structures listed here http://kmike.ru/python-data-structures and here https://pypi.python.org/pypi/sortedcontainers more than adequate for my needs. Cheers. Mark Lawrence. From no.email at nospam.invalid Sat Jul 16 19:36:43 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 16 Jul 2016 16:36:43 -0700 Subject: PEP Request: Advanced Data Structures References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> Message-ID: <8760s5duk4.fsf@jester.gateway.pace.com> shrey.desai at gmail.com writes: > As a computer science undergraduate student, I don't want to spend > time writing the module but instead I want to work with it, play > around with it, and do problems with it. For educational purposes, I think writing the module yourself is part of the idea. Also, Python isn't really the right language for that. Most things in Python are done with Python lists (elastic vectors), deques/queues, or dictionaries. That's almost always sufficient in practice. I've occasionally wanted an AVL tree for shared dictionaries but that's about it. The C++ standard template library (STL) and Boost have most of what you want, at a lower level than Python. Or if you really want to be hardcore, implement everything yourself in assembler. From tjreedy at udel.edu Sat Jul 16 20:10:47 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 16 Jul 2016 20:10:47 -0400 Subject: PEP Request: Advanced Data Structures In-Reply-To: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> Message-ID: On 7/16/2016 6:14 PM, shrey.desai at gmail.com wrote: > I have found it slightly frustrating that Python does not have > built-in support for advanced data structures (Linked Lists, You and I have different ideas of 'advanced data structures' ;-). To me, linked list are limited structures used in functional programming to make mutable structure from immutable-except-on-creation cells. In any case, one can easily use tuples to create branching structures. Tuples and lists containing tuples and lists are routine in python programming. Wrapping such usage in a LinkedList class is optional -- and unusual. > Stacks/Queues, Nearly two decades ago, I promoted the addition of the list.pop method as the inverse of list.append, in order to make lists easily usable as stacks. This is routine in python code today. collections.deque instances are advanced data structures that can be used as stacks, queues, or both, at either end. The class has tests that I presume are rigorous. > BST) British Summer Time? (Suggestion from Google) > Currently, we are required to write our own modules that represent > these data structures and rigorously test/refactor them before we can > actually use them. If an instructor makes you wrap the structures that Python provides before you can use then, that is between you and the instructor, and not our doing. The instructor could let you use Python as it is or hand you the wrapping he likes. -- Terry Jan Reedy From python at mrabarnett.plus.com Sat Jul 16 20:38:39 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 17 Jul 2016 01:38:39 +0100 Subject: PEP Request: Advanced Data Structures In-Reply-To: References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> Message-ID: <6b459de7-87cc-ddb5-093b-b0194977a892@mrabarnett.plus.com> On 2016-07-17 01:10, Terry Reedy wrote: > On 7/16/2016 6:14 PM, shrey.desai at gmail.com wrote: >> I have found it slightly frustrating that Python does not have >> built-in support for advanced data structures (Linked Lists, > > You and I have different ideas of 'advanced data structures' ;-). To > me, linked list are limited structures used in functional programming to > make mutable structure from immutable-except-on-creation cells. In any > case, one can easily use tuples to create branching structures. Tuples > and lists containing tuples and lists are routine in python programming. > Wrapping such usage in a LinkedList class is optional -- and unusual. > They're the kind of things I'd write when using C, but, then, C is missing a lot of stuff! :-) >> Stacks/Queues, > > Nearly two decades ago, I promoted the addition of the list.pop method > as the inverse of list.append, in order to make lists easily usable as > stacks. This is routine in python code today. > > collections.deque instances are advanced data structures that can be > used as stacks, queues, or both, at either end. The class has tests > that I presume are rigorous. > >> BST) > > British Summer Time? (Suggestion from Google) > Binary search tree. Given that Python has dict, there's not much need for a binary search tree. [snip] From python.list at tim.thechases.com Sat Jul 16 20:45:10 2016 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 16 Jul 2016 19:45:10 -0500 Subject: PEP Request: Advanced Data Structures In-Reply-To: References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> Message-ID: <20160716194510.6283c8f4@bigbox.christie.dr> On 2016-07-17 08:19, Chris Angelico wrote: > Why do you need a linked list? That's an implementation detail; why > not simply use a regular list? > > Not trolling, genuinely asking. Is there something that you > specifically need those exact structures for? I know there have been times I want known performance characteristics. My main reason for wanting linked lists is usually for stacks/queues with O(1) push/pop, and I understand that a deque handles most of that fairly efficiently ("approximately the same O(1) performance in either direction"). The bisect and heapq modules also help with some of my usual use-cases for BSTs (presuming "BST" unpacks as "binary search tree"), while nested arrays/dicts usually serve for most of the rest of my other tree/trie needs. So usually I'm less concerned with the actual algorithm name than I am with the "I want to {push,pop,search,insert,delete} in O(f) time" where O(f) is usually either O(1) or O(N log N), instead of the alternatives which might use O(N), O(N**k), or worse, O(k**N). For anything beyond those basic CS data-structures, there's usually something conveniently in PyPI. -tkc From cs at zip.com.au Sat Jul 16 20:54:26 2016 From: cs at zip.com.au (cs at zip.com.au) Date: Sun, 17 Jul 2016 10:54:26 +1000 Subject: PEP Request: Advanced Data Structures In-Reply-To: References: Message-ID: <20160717005426.GA50011@cskk.homeip.net> On 16Jul2016 19:49, Dennis Lee Bieber wrote: >On Sat, 16 Jul 2016 15:33:12 -0700 (PDT), Shrey Desai > declaimed the following: >>- Education: the Linked List is a core data structure that CS undergraduates >>(among others) use and study, so it is vital that they have hands on access >>to them. A list is basically a dynamic array; the only property it shares >>with a Linked List is that it's dynamic. > > My CS courses required us to implement our own linked lists (in FORTRAN >IV yet). Providing a built-in linked list just negates the educational >aspect. I was thinking this exact same thing. >>- Development: the use of correct data structures is important when >>developing applications, especially for issues like scaling and efficiency. >>For instance, when working with polynomials, Linked Lists provide a great >>interface to access and edit them. > > What does having links gain you that you don't get from a regular list >with slicing? Well, in a larger context you can keep a reference to an element deep in the list, and insert a new element in O(1) time at that point. The usualy argument against providing linked lists and other basic graph related functions in the stdlib is that there are in practice many many decisions one can make about exactly what kind of implementation specifics one might like in such a thing, and what methods to present for use with the thing. On the flip side, implementing a simple linked list in a specific context is pretty trivial as Chris has demonstrated. I do take the point that a preexisting (and hopefully debugged) class would obviate a testing burden for users. Provided the class provided enough. If it didn't the end user is back to replacing or extending it, and having to test anyway. To the OP: have you looked in PyPI and found no graph classes? Cheers, Cameron Simpson From rosuav at gmail.com Sat Jul 16 21:30:25 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 11:30:25 +1000 Subject: PEP Request: Advanced Data Structures In-Reply-To: <20160717005426.GA50011@cskk.homeip.net> References: <20160717005426.GA50011@cskk.homeip.net> Message-ID: On Sun, Jul 17, 2016 at 10:54 AM, wrote: > Well, in a larger context you can keep a reference to an element deep in the > list, and insert a new element in O(1) time at that point. > I'd like to know how many elements your list needs before that actually becomes faster than CPython's heavily-optimized C-implemented list structure. And if someone's proposing a new core data type, I very much doubt that'll fly - and at the C level, wouldn't tracing the links cost massively more than the occasional insertion too? I'm not sure O(1) is of value at any size, if the costs of all your other operations go up. ChrisA From lawrencedo99 at gmail.com Sat Jul 16 21:59:30 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sat, 16 Jul 2016 18:59:30 -0700 (PDT) Subject: Passing File Descriptors To Subprocesses Message-ID: A few years ago I wrote a tool to do comparisons between different versions of the Android API. Then one day, after a Python update (from the dates, it had to have been some version of 3.2), it stopped working. It took quite a while--over a year--until I figured out what was happening, and I could move my code from Python 2 back to Python 3 again. The various subprocess functions have arguments called ?close_fds? and ?pass_fds?, which specify which file descriptors are to be left open in the child process. Yet no matter what I set these to, it seemed I could not pass my pipes to a subprocess. What the docs *don?t* tell you is that these arguments do not control what happens after the exec. The file descriptors that are kept open are only those which do not have the FD_CLOEXEC flags set in their fcntl settings. Remember how the subprocess functions work: * first, a fork(2) call is executed, then * the child process does execve(2) (or some convenience variant of this) to actually execute the command or program that you specified. The ?close_fds? and ?pass_fds? args only matter in the first step. You need to specify these, *and* have the right CLOEXEC settings on those file descriptors for the second step. Leave out either one, and your child process does not get the file descriptors. Python 3.4 has added special calls to manage this CLOEXEC setting. My code uses fcntl . The docs for the subprocess module need to make this requirement clear. From no.email at nospam.invalid Sat Jul 16 22:33:08 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 16 Jul 2016 19:33:08 -0700 Subject: PEP Request: Advanced Data Structures References: <20160717005426.GA50011@cskk.homeip.net> Message-ID: <871t2tdme3.fsf@jester.gateway.pace.com> Chris Angelico writes: >> keep a reference to an element deep in the list, and insert a new >> element in O(1) time at that point. > at the C level, wouldn't tracing the links cost massively more than > the occasional insertion too? I'm not sure O(1) is of value at any > size, if the costs of all your other operations go up. I think the idea is that you're already deep in the list when you decide to insert an element or do other surgery on the list. An example might be a lookup table with linear search, where you want to bring the LRU item to the front of the list after finding it. Really though, that's an ugly thing to be doing in any language, and it definitely isn't something that comes up much in Python. From rosuav at gmail.com Sat Jul 16 22:43:01 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 12:43:01 +1000 Subject: PEP Request: Advanced Data Structures In-Reply-To: <871t2tdme3.fsf@jester.gateway.pace.com> References: <20160717005426.GA50011@cskk.homeip.net> <871t2tdme3.fsf@jester.gateway.pace.com> Message-ID: On Sun, Jul 17, 2016 at 12:33 PM, Paul Rubin wrote: > Chris Angelico writes: >>> keep a reference to an element deep in the list, and insert a new >>> element in O(1) time at that point. >> at the C level, wouldn't tracing the links cost massively more than >> the occasional insertion too? I'm not sure O(1) is of value at any >> size, if the costs of all your other operations go up. > > I think the idea is that you're already deep in the list when you decide > to insert an element or do other surgery on the list. An example might > be a lookup table with linear search, where you want to bring the LRU > item to the front of the list after finding it. Really though, that's > an ugly thing to be doing in any language, and it definitely isn't > something that comes up much in Python. Right, but how did you *get* that deep into the list? By following a chain of pointers. That's a relatively costly operation, so the benefit of not having to move all the following elements is damaged some by the cost of chasing pointers to get there in the first place. So overall, performance would be better with the high-performance list, even if it does mean moving a bunch of elements (when you delete some). Since it's a difference in asymptotic cost, there would theoretically be some number of elements after which it would be cheaper to use the linked list... but maybe the cost of chasing pointers goes up even more, to make that never happen. ChrisA From python at mrabarnett.plus.com Sat Jul 16 22:49:06 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 17 Jul 2016 03:49:06 +0100 Subject: PEP Request: Advanced Data Structures In-Reply-To: <871t2tdme3.fsf@jester.gateway.pace.com> References: <20160717005426.GA50011@cskk.homeip.net> <871t2tdme3.fsf@jester.gateway.pace.com> Message-ID: On 2016-07-17 03:33, Paul Rubin wrote: > Chris Angelico writes: >>> keep a reference to an element deep in the list, and insert a new >>> element in O(1) time at that point. >> at the C level, wouldn't tracing the links cost massively more than >> the occasional insertion too? I'm not sure O(1) is of value at any >> size, if the costs of all your other operations go up. > > I think the idea is that you're already deep in the list when you decide > to insert an element or do other surgery on the list. An example might > be a lookup table with linear search, where you want to bring the LRU > item to the front of the list after finding it. Really though, that's > an ugly thing to be doing in any language, and it definitely isn't > something that comes up much in Python. > I once sped up lookups on a doubly-linked list by adding a dict that would take me straight to the appropriate node. This was in C, though. From eryksun at gmail.com Sat Jul 16 23:00:35 2016 From: eryksun at gmail.com (eryk sun) Date: Sun, 17 Jul 2016 03:00:35 +0000 Subject: Passing File Descriptors To Subprocesses In-Reply-To: References: Message-ID: On Sun, Jul 17, 2016 at 1:59 AM, Lawrence D?Oliveiro wrote: > The various subprocess functions have > arguments called ?close_fds? and ?pass_fds?, which specify which file descriptors are to be > left open in the child process. Yet no matter what I set these to, it seemed I could not pass > my pipes to a subprocess. > > What the docs *don?t* tell you is that these arguments do not control what happens after the > exec. The file descriptors that are kept open are only those which do not have the > FD_CLOEXEC flags set in their fcntl settings. It works correctly in 3.4+, which makes the pass_fds file descriptors inheritable in the child, after fork. See issue 18571 and PEP 446, section "Other Changes": http://bugs.python.org/issue18571 https://www.python.org/dev/peps/pep-0446/#other-changes For example: Python 3.5.1+ (default, Mar 30 2016, 22:46:26) [GCC 5.3.1 20160330] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import os, subprocess >>> fdr, fdw = os.pipe() >>> fdw 4 >>> os.get_inheritable(fdw) False >>> subprocess.call(['python3'], pass_fds=[fdw]) child: Python 3.5.1+ (default, Mar 30 2016, 22:46:26) [GCC 5.3.1 20160330] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.write(4, b'spam') 4 >>> exit() parent: 0 >>> os.read(fdr, 4) b'spam' From cs at zip.com.au Sat Jul 16 23:27:09 2016 From: cs at zip.com.au (cs at zip.com.au) Date: Sun, 17 Jul 2016 13:27:09 +1000 Subject: PEP Request: Advanced Data Structures In-Reply-To: References: Message-ID: <20160717032709.GA61131@cskk.homeip.net> On 17Jul2016 12:43, Chris Angelico wrote: >On Sun, Jul 17, 2016 at 12:33 PM, Paul Rubin wrote: >> Chris Angelico writes: >>>> keep a reference to an element deep in the list, and insert a new >>>> element in O(1) time at that point. >>> at the C level, wouldn't tracing the links cost massively more than >>> the occasional insertion too? I'm not sure O(1) is of value at any >>> size, if the costs of all your other operations go up. >> >> I think the idea is that you're already deep in the list when you decide >> to insert an element or do other surgery on the list. An example might >> be a lookup table with linear search, where you want to bring the LRU >> item to the front of the list after finding it. Really though, that's >> an ugly thing to be doing in any language, and it definitely isn't >> something that comes up much in Python. > >Right, but how did you *get* that deep into the list? By following a >chain of pointers. That's a relatively costly operation, so the >benefit of not having to move all the following elements is damaged >some by the cost of chasing pointers to get there in the first place. No, you're assuming too much here. Consider: LL = LinkedList() item = LL.insert( (some, tuple, value) ) ... do lots of stuff with the list ... ... now item refers to something that might be anywhere ... item.add_after( (context, for, a, new, item, in , the, list) ) ... and any number of other scenarios of similar nature: note a node in the list and get to done things at or near that node at an arbirary other time. This applies to _any_ graph like data structure where nodes would have to be found by traversal. Anyway, I'm not arguing that Pythons basic list type doesn't address a great many needs. I'm arguing that no one size fits all. The core strength of a linked list is O(1) insertion at any point, provided you have a reference to that point. Whether that is enough benefit depends on the use case. Cheers, Cameron Simpson From rustompmody at gmail.com Sat Jul 16 23:43:16 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 16 Jul 2016 20:43:16 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> <0d294d49-2cf0-84be-ebcd-af1d0ffc7222@mrabarnett.plus.com> Message-ID: <9eda5007-a48f-4bac-8d09-c8af9e6b9987@googlegroups.com> Heh! A flurry of opinions! No time right now? other than to say thank you (MRAB) for this little gem: On Saturday, July 16, 2016 at 10:29:02 PM UTC+5:30, MRAB wrote: > On 2016-07-16 17:27, Steven D'Aprano wrote: > > On Sat, 16 Jul 2016 10:33 pm, Rustom Mody wrote: > [snip] > > > And yes, Rustom, I'm very familiar with the philosophical objections to the > > something/nothing distinction. "Is zero truly nothing, or is it some thing > > distinct from the absence of any number?" I'm not interested in that > > argument. Let the philosophers count angels, but as far as Python code > > goes, I'm an intuitionist: if I have zero sheep, that's the same as not > > having any sheep, or having no sheep. > > > [snip] > > And if you're going to argue that zero is something, then you could also > argue that false is something... Likewise Chris? example of the comparison of Pike and Python alternative semantics From rosuav at gmail.com Sun Jul 17 00:03:02 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 14:03:02 +1000 Subject: PEP Request: Advanced Data Structures In-Reply-To: <20160717032709.GA61131@cskk.homeip.net> References: <20160717032709.GA61131@cskk.homeip.net> Message-ID: On Sun, Jul 17, 2016 at 1:27 PM, wrote: >> Right, but how did you *get* that deep into the list? By following a >> chain of pointers. That's a relatively costly operation, so the >> benefit of not having to move all the following elements is damaged >> some by the cost of chasing pointers to get there in the first place. > > > No, you're assuming too much here. Consider: > > LL = LinkedList() > item = LL.insert( (some, tuple, value) ) > ... do lots of stuff with the list ... > ... now item refers to something that might be anywhere ... > item.add_after( (context, for, a, new, item, in , the, list) ) > ... > > and any number of other scenarios of similar nature: note a node in the list > and get to done things at or near that node at an arbirary other time. > Sure, that makes sense. The ability to hang onto a "list position" is a useful one, I don't deny that. (Indices work if all you ever do is append, but your add_after will invalidate any indices after that.) I just very much doubt that the linked list will afford any overall performance improvement over the standard CPython built-in list object - and if it does, you're definitely in the realm of special-purpose code for a specific situation. And there's nothing wrong with that. Having not myself had a good early grounding in data structure design, I think it's something worth teaching. And Python's fine at doing that - the concepts of a linked list translate nicely into Python objects and attributes - even though it'll never actually be something Python needs. Once you've learned what the different fundamental structures are, you'll have a better understanding of what's going on (for instance, knowing the advantages and critical disadvantages of hashtables like CPython's dict), and possibly know when to roll your own instead of using someone else's (knowing that "lst.insert(0, lst.pop(idx))" is slow, you might instead "lst.append(lst.pop(idx))" and have your list in reverse order - a good start, but maybe you'd decide to go linked-list anyway). But for most jobs, just think in terms of abstract data structures, and trust the language to do the details. ChrisA From rosuav at gmail.com Sun Jul 17 00:05:41 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 14:05:41 +1000 Subject: Operator Precedence/Boolean Logic In-Reply-To: <9eda5007-a48f-4bac-8d09-c8af9e6b9987@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> <0d294d49-2cf0-84be-ebcd-af1d0ffc7222@mrabarnett.plus.com> <9eda5007-a48f-4bac-8d09-c8af9e6b9987@googlegroups.com> Message-ID: On Sun, Jul 17, 2016 at 1:43 PM, Rustom Mody wrote: > Heh! A flurry of opinions! > No time right now? other than to say thank you (MRAB) for this little gem: > > On Saturday, July 16, 2016 at 10:29:02 PM UTC+5:30, MRAB wrote: >> On 2016-07-16 17:27, Steven D'Aprano wrote: >> > On Sat, 16 Jul 2016 10:33 pm, Rustom Mody wrote: >> [snip] >> >> > And yes, Rustom, I'm very familiar with the philosophical objections to the >> > something/nothing distinction. "Is zero truly nothing, or is it some thing >> > distinct from the absence of any number?" I'm not interested in that >> > argument. Let the philosophers count angels, but as far as Python code >> > goes, I'm an intuitionist: if I have zero sheep, that's the same as not >> > having any sheep, or having no sheep. >> > >> [snip] >> >> And if you're going to argue that zero is something, then you could also >> argue that false is something... > > Likewise Chris? example of the comparison of Pike and Python alternative > semantics So if you accept that there are different semantics that all have validity, can you also accept that Python's model is not "bizarre"? ChrisA From steve at pearwood.info Sun Jul 17 00:21:47 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jul 2016 14:21:47 +1000 Subject: PEP Request: Advanced Data Structures References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> Message-ID: <578b07dc$0$1616$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Jul 2016 08:14 am, shrey.desai at gmail.com wrote: > I have found it slightly frustrating that Python does not have built-in > support for advanced data structures (Linked Lists, Stacks/Queues, BST) in > its distribution. They are hardly "advanced" data structures. They are trivial data structures. When I did an undergraduate course in computer science, we were expected to write them ourselves, from scratch. Linked lists are primitive data structures used by languages that don't have Python's advanced list data structure. For nearly everything that you think you want a linked list, you will be better off to use a built-in list. For stacks and queues, use collections.deque. For binary search trees, you will mostly use a dict. If there are exceptions, they are unusual. > Many computer science students, developers, and software > engineers rely on these data structures; having the data structures be a > part of the distribution and be maintained by the Python community would > be immensely useful. They really wouldn't be. I cannot imagine when anyone would want to use a linked list when lists are available. That would be a very big step backwards in both performance and power: harder to use, and slower. [...] > I'm looking to create a PEP for this issue and some people that would be > willing to 1) vouch for this idea and 2) co-author the draft. Eventually, > we would be co-developers for the project as well. Perhaps I'm wrong, but it sounds to me that you should spend more time learning Python and less time trying to mechanically translate C algorithms into Python code. Python doesn't have a linked list class because it is unnecessary. Python doesn't need a dedicated stack or single-threaded queue class, because it has deque. (As a comp sci undergrad, you have probably heard of double-ended queues.) Python already has a thread-safe queue. *Maybe* there's a use-case for a self-balancing tree structure in Python, but which one? How often do you need to use keys that can't be hashed? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Sun Jul 17 02:44:42 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 16 Jul 2016 23:44:42 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> <0d294d49-2cf0-84be-ebcd-af1d0ffc7222@mrabarnett.plus.com> <9eda5007-a48f-4bac-8d09-c8af9e6b9987@googlegroups.com> Message-ID: <4854a8df-0d64-4abe-8289-ddad178d315f@googlegroups.com> On Sunday, July 17, 2016 at 9:35:57 AM UTC+5:30, Chris Angelico wrote: > On Sun, Jul 17, 2016 at 1:43 PM, Rustom Mody wrote: > > Heh! A flurry of opinions! > > No time right now? other than to say thank you (MRAB) for this little gem: > > > > On Saturday, July 16, 2016 at 10:29:02 PM UTC+5:30, MRAB wrote: > >> On 2016-07-16 17:27, Steven D'Aprano wrote: > >> > On Sat, 16 Jul 2016 10:33 pm, Rustom Mody wrote: > >> [snip] > >> > >> > And yes, Rustom, I'm very familiar with the philosophical objections to the > >> > something/nothing distinction. "Is zero truly nothing, or is it some thing > >> > distinct from the absence of any number?" I'm not interested in that > >> > argument. Let the philosophers count angels, but as far as Python code > >> > goes, I'm an intuitionist: if I have zero sheep, that's the same as not > >> > having any sheep, or having no sheep. > >> > > >> [snip] > >> > >> And if you're going to argue that zero is something, then you could also > >> argue that false is something... > > > > Likewise Chris? example of the comparison of Pike and Python alternative > > semantics > > So if you accept that there are different semantics that all have > validity, can you also accept that Python's model is not "bizarre"? > > ChrisA I am sure Chris you can distinguish between: - Python?s (bool) model is bizarre - The model ?Everything has auto-bool-nature? is bizarre - The notion ? ?Everything has auto-bool-nature? is straightforward ? is bizarre My earlier statement (with emphasis in original): > You also have a bizarre notion that python's property: ?Everything has > auto-bool-nature? IS STRAIGHTFORWARD. If you like you can take me to task for not being sufficiently punctilious about quote-marks as I am now. [And remember your objections to my (mis)use of unicode ] From rustompmody at gmail.com Sun Jul 17 02:59:58 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 16 Jul 2016 23:59:58 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <4854a8df-0d64-4abe-8289-ddad178d315f@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> <0d294d49-2cf0-84be-ebcd-af1d0ffc7222@mrabarnett.plus.com> <9eda5007-a48f-4bac-8d09-c8af9e6b9987@googlegroups.com> <4854a8df-0d64-4abe-8289-ddad178d315f@googlegroups.com> Message-ID: <52c68e6b-ecc0-4b0e-8296-9181fa10ce95@googlegroups.com> On Sunday, July 17, 2016 at 12:15:40 PM UTC+5:30, Rustom Mody wrote: > On Sunday, July 17, 2016 at 9:35:57 AM UTC+5:30, Chris Angelico wrote: > > On Sun, Jul 17, 2016 at 1:43 PM, Rustom Mody wrote: > > > Heh! A flurry of opinions! > > > No time right now? other than to say thank you (MRAB) for this little gem: > > > > > > On Saturday, July 16, 2016 at 10:29:02 PM UTC+5:30, MRAB wrote: > > >> On 2016-07-16 17:27, Steven D'Aprano wrote: > > >> > On Sat, 16 Jul 2016 10:33 pm, Rustom Mody wrote: > > >> [snip] > > >> > > >> > And yes, Rustom, I'm very familiar with the philosophical objections to the > > >> > something/nothing distinction. "Is zero truly nothing, or is it some thing > > >> > distinct from the absence of any number?" I'm not interested in that > > >> > argument. Let the philosophers count angels, but as far as Python code > > >> > goes, I'm an intuitionist: if I have zero sheep, that's the same as not > > >> > having any sheep, or having no sheep. > > >> > > > >> [snip] > > >> > > >> And if you're going to argue that zero is something, then you could also > > >> argue that false is something... > > > > > > Likewise Chris? example of the comparison of Pike and Python alternative > > > semantics > > > > So if you accept that there are different semantics that all have > > validity, can you also accept that Python's model is not "bizarre"? > > > > ChrisA > > I am sure Chris you can distinguish between: > > - Python?s (bool) model is bizarre > - The model ?Everything has auto-bool-nature? is bizarre > - The notion ? ?Everything has auto-bool-nature? is straightforward ? is bizarre > > > My earlier statement (with emphasis in original): > > You also have a bizarre notion that python's property: ?Everything has > > auto-bool-nature? IS STRAIGHTFORWARD. > > If you like you can take me to task for not being sufficiently punctilious > about quote-marks as I am now. > [And remember your objections to my (mis)use of unicode ] To add to that: This is my first post in this thread: https://mail.python.org/pipermail/python-list/2016-June/710678.html I dont think I need to change much what is there other than to say this: A snarky tone is unconducive to a serious discussion. So I could restate that without the snark? something which I believe I?ve already done in recent posts From lawrencedo99 at gmail.com Sun Jul 17 03:06:09 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 17 Jul 2016 00:06:09 -0700 (PDT) Subject: Passing File Descriptors To Subprocesses In-Reply-To: References: Message-ID: <55a943e2-c798-459c-bffe-aca4f6734284@googlegroups.com> On Sunday, July 17, 2016 at 3:01:36 PM UTC+12, eryk sun wrote: > It works correctly in 3.4+ ... Yup, confirmed it happens only in 3.3. From marko at pacujo.net Sun Jul 17 03:26:56 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 17 Jul 2016 10:26:56 +0300 Subject: PEP Request: Advanced Data Structures References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> <6b459de7-87cc-ddb5-093b-b0194977a892@mrabarnett.plus.com> Message-ID: <87mvlgvi67.fsf@elektro.pacujo.net> MRAB : > Given that Python has dict, there's not much need for a binary search tree. Dicts don't have the concept of key order. I use my own AVL tree to implement timers. A balanced tree data structure is the only major data structure I've missed in Python. It is there in Java and C++, for example. The Linux kernel makes use of it as well. Marko From rosuav at gmail.com Sun Jul 17 03:33:02 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 17:33:02 +1000 Subject: Operator Precedence/Boolean Logic In-Reply-To: <4854a8df-0d64-4abe-8289-ddad178d315f@googlegroups.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> <0d294d49-2cf0-84be-ebcd-af1d0ffc7222@mrabarnett.plus.com> <9eda5007-a48f-4bac-8d09-c8af9e6b9987@googlegroups.com> <4854a8df-0d64-4abe-8289-ddad178d315f@googlegroups.com> Message-ID: On Sun, Jul 17, 2016 at 4:44 PM, Rustom Mody wrote: > I am sure Chris you can distinguish between: > > - Python?s (bool) model is bizarre > - The model ?Everything has auto-bool-nature? is bizarre > - The notion ? ?Everything has auto-bool-nature? is straightforward ? is bizarre > > > My earlier statement (with emphasis in original): >> You also have a bizarre notion that python's property: ?Everything has >> auto-bool-nature? IS STRAIGHTFORWARD. I can distinguish them, yes. But Python's boolification model is fundamentally the same as the model "Everything has auto-bool-nature". So those two aren't really all that different, save that one of them is language-agnostic. I understand your third statement, but I posit that these last points have proven it false. There are clearly a number of viable semantic systems: 1) REXX and, I think, Pascal: there are two specific values that may be used in conditionals, and anything else is an error 2) Everything is legal in a conditional, and has a truth value 2a) Pike: 0 is false, every other object is true, unless it defines a magic method 2b) Python: Empty values and collections are false, everything else is true, unless it defines a magic method 2c) JavaScript: 0, null, undefined, nan, "", false are false, everything else is true, including all objects (no magic method option) 3) Machine code: There are no conditionals - just CPU flags that you can jump or not jump on. All of them work. So you could *disagree* with the statement that Python's model is straight-forward, but you cannot say that this statement is *bizarre*. ChrisA From rustompmody at gmail.com Sun Jul 17 03:33:55 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 17 Jul 2016 00:33:55 -0700 (PDT) Subject: PEP Request: Advanced Data Structures In-Reply-To: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> References: <21fcec53-cf5b-4529-9790-63a1c46f534b@googlegroups.com> Message-ID: On Sunday, July 17, 2016 at 3:45:04 AM UTC+5:30, Shrey Desai wrote: > I have found it slightly frustrating that Python does not have built-in support for advanced data structures (Linked Lists, Stacks/Queues, BST) in its distribution. Many computer science students, developers, and software engineers rely on these data structures; having the data structures be a part of the distribution and be maintained by the Python community would be immensely useful. > > Currently, we are required to write our own modules that represent these data structures and rigorously test/refactor them before we can actually use them. This gets annoying because instead of spending time USING the "correct" version of the data structure, we have to spend time creating them in the first place. > > Programming languages like Java have support for Linked Lists, for example, which makes it easy to just use it instead of trying to create it over again. As a computer science undergraduate student, I don't want to spend time writing the module but instead I want to work with it, play around with it, and do problems with it. > > I know Python currently has a Queue module, but this can definitely be expanded. There are other more advanced data structures out there, like AVL trees, splay trees, and tries, but I think that would be overkilll. Having these data structures above would be immensely useful. > > I'm looking to create a PEP for this issue and some people that would be willing to 1) vouch for this idea and 2) co-author the draft. Eventually, we would be co-developers for the project as well. > > Who's in? Hi Shrey Your wish and direction is commendable And looks at an important question Do consider however that the boot may well be on the other foot: viz. So ?Python does not have advanced data structures? fir students/edu-purposes? may suggest that python should change Or that education should! Some examples of the nature the the fast-shifting ground under our feet: It was important for programmers to know and use registers/instruction-formats etc very effectively at one time. At some time it stopped being relevant. Or card-punches, Or large central ACs, Or tape drives, Or interrupts. Some of these have just died; some remain in specialized places; some are ubiquitous but with enough strong abstractions that vanilla programmers dont ever think of these nowadays The same holds for broad areas Cryptography is where CS started in WWII; vanished thereafter; reappeared in specialized quarters of late Numerical computing was the hi-cathedral for the next few decades By the time I was a student in the 80s it was there but somehow felt old and past-tense. I expect recently instituted courses dont have it; or have it specialized. These shifts are elaborated somewhat more https://mail.python.org/pipermail/python-list/2016-June/710678.html and sequel Coming to data structures (and algorithms) yes it (they) are important courses? and widely misunderstood Here is Bob Harper *quoting a developer* everyone knows that algorithms as we learned them at school are irrelevant to practice." https://www.cs.cmu.edu/~rwh/papers/secp/secp.pdf (pg 2) [Harper is a senior respected faculty at Carnegie Mellon] I think the same applies to data structures with redoubled force: Most of what is called data structures ? linked lists etc ? should really be called *storage structures* ie How to survive and do useful work when your system/software is highly crippling. Greenspun's 10th law: Any sufficiently complicated C program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Lisp. If you understand that python is in a sense closer to Lisp than to C, maybe you see that there are broadly two choices - Traditional CS-edu view... C, C++, Java, OO-gook, data-structures, algorithms etc where the basic philosophy is Crippling is a way of life; Be Brave! And hobble more vigorously!? - The alternative CS view as understood by Harper, MIT and other progressive places embracing the ?functional? style (stupid word if you ask me) The idea being to throw out 70-80 % of traditional CS from the curriculum and get students doing good stuff much faster by putting them on a *different* learning curve. That this stuff is a bit bleeding edge can be seen in the fact that ACM curriculum has started embracing ?functional? only in 2013 ? ie 50 years after Lisp: http://blog.languager.org/2015/06/functional-programming-moving-target.html Sorry for a ramble. Summary: Yes the languages we use to teach need to be rethought So does our teaching ;-) From marko at pacujo.net Sun Jul 17 03:41:48 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 17 Jul 2016 10:41:48 +0300 Subject: Clean Singleton Docstrings References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <1468692272.2410242.668163177.52CA7567@webmail.messagingengine.com> <87wpkluvcp.fsf@elektro.pacujo.net> Message-ID: <87inw4vhhf.fsf@elektro.pacujo.net> Chris Angelico : > The trouble is, repeated addition of fractions is *able* to deliver an > exact result. It just might result in an incredibly slow program. True, although the programmer has control over the feature. If you *want* the luxury of exact fractions, you pay the price. If you don't, you make the numbers inexact. A somewhat analogous situation is there in Python's integers, which have an unlimited range. The feature is extremely useful in cryptography, for example (DSA verification is a couple of lines of Python). > And then if you mix types, does it aim for the greatest possible > 'accuracy', even if that's not quite accurate? (For instance, if you > add 0.2 to 5/8, does it convert to float or to fraction?) Thus inexactness is a contagious property of a number. Guile: (+ 0.2 5/8) ==> 0.825 (exact? (+ 0.2 5/8)) ==> #f Python, for comparison: >>> 0.2 + fractions.Fraction(5, 8) 0.825 >>> decimal.Decimal("0.1") + 0.1 Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'decimal.Decimal' and 'float' >>> fractions.Fraction(5, 8) + decimal.Decimal("0.1") Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'Fraction' and 'decim al.Decimal' Marko From lawrencedo99 at gmail.com Sun Jul 17 03:44:40 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 17 Jul 2016 00:44:40 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <576B9B33.2030903@rece.vub.ac.be> <07e13a5d-38bf-7bfa-f45f-a24dea8e3004@online.de> <576ba927$0$1504$c3e8da3$5496439d@news.astraweb.com> <87wplgfdb5.fsf@elektro.pacujo.net> <4c257ef7-519f-4121-b63b-fb38566072d0@googlegroups.com> <5773c832$0$1598$c3e8da3$5496439d@news.astraweb.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> <0d294d49-2cf0-84be-ebcd-af1d0ffc7222@mrabarnett.plus.com> <9eda5007-a48f-4bac-8d09-c8af9e6b9987@googlegroups.com> <4854a8df-0d64-4abe-8289-ddad178d315f@googlegroups.com> Message-ID: On Sunday, July 17, 2016 at 7:33:19 PM UTC+12, Chris Angelico wrote: > 1) REXX and, I think, Pascal: there are two specific values that may > be used in conditionals, and anything else is an error Worth comparing how two different languages deal with strict enforcement of booleans: * Modula-2 does it right: BOOL is a separate type which is required for conditionals, but + the ORD and VAL functions offer typesafe conversions to and from integers, and + BOOL can be used as an array index type, just like any other enumerated type. * Java does it wrong: not only does it not provide easy conversions, but it doesn?t allow enumerations to be used as array index types. Python would do well to learn from the Modula-2 style. From rosuav at gmail.com Sun Jul 17 03:51:47 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 17:51:47 +1000 Subject: Clean Singleton Docstrings In-Reply-To: <87inw4vhhf.fsf@elektro.pacujo.net> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <1468692272.2410242.668163177.52CA7567@webmail.messagingengine.com> <87wpkluvcp.fsf@elektro.pacujo.net> <87inw4vhhf.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 17, 2016 at 5:41 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> The trouble is, repeated addition of fractions is *able* to deliver an >> exact result. It just might result in an incredibly slow program. > > True, although the programmer has control over the feature. If you > *want* the luxury of exact fractions, you pay the price. If you don't, > you make the numbers inexact. Not if you have a single "Number" type: On Sat, Jul 16, 2016 at 4:53 PM, Random832 wrote: > Eliminate both of them. Move to a single abstract numeric type* a la > Scheme, with an "inexact" attribute (inexact numbers may or may not be > represented by a float, or by the same bigint/decimal/rational types as > exact ones with a flag set to mark them as inexact.) Currently yes, you can choose to use fractions.Fraction and pay the price. How, if you have a single type with different representations, can you make that choice? ChrisA From random832 at fastmail.com Sun Jul 17 04:03:39 2016 From: random832 at fastmail.com (Random832) Date: Sun, 17 Jul 2016 04:03:39 -0400 Subject: Clean Singleton Docstrings In-Reply-To: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <1468692272.2410242.668163177.52CA7567@webmail.messagingengine.com> <87wpkluvcp.fsf@elektro.pacujo.net> <87inw4vhhf.fsf@elektro.pacujo.net> Message-ID: <1468742619.2555411.668475737.072BADA7@webmail.messagingengine.com> On Sun, Jul 17, 2016, at 03:51, Chris Angelico wrote: > > True, although the programmer has control over the feature. If you > > *want* the luxury of exact fractions, you pay the price. If you don't, > > you make the numbers inexact. > > Not if you have a single "Number" type: Saying that exact and inexact numbers can't be a single type is like saying positive and negative numbers can't be the same type. Saying that fractions and floats can't be a single type is like saying ASCII strings and UCS-4 strings can't be the same type within the FSR. "Single abstract Number type" doesn't preclude a "FNR" where some Number objects are represented as floats and others are not. From random832 at fastmail.com Sun Jul 17 04:08:21 2016 From: random832 at fastmail.com (Random832) Date: Sun, 17 Jul 2016 04:08:21 -0400 Subject: Clean Singleton Docstrings In-Reply-To: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <1468692272.2410242.668163177.52CA7567@webmail.messagingengine.com> <87wpkluvcp.fsf@elektro.pacujo.net> <87inw4vhhf.fsf@elektro.pacujo.net> Message-ID: <1468742901.2556137.668478097.6FBDE3C3@webmail.messagingengine.com> On Sun, Jul 17, 2016, at 03:51, Chris Angelico wrote: > Currently yes, you can choose to use fractions.Fraction and pay the > price. How, if you have a single type with different representations, > can you make that choice? Sorry, I forgot to answer your question. Though, your implicit claim that it's impossible to make choices if your choices aren't represented by different types is absurd. For example, you could have a function that returns an inexact number with the (approximately) same value as the given number. From rosuav at gmail.com Sun Jul 17 04:44:35 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 18:44:35 +1000 Subject: Clean Singleton Docstrings In-Reply-To: <1468742901.2556137.668478097.6FBDE3C3@webmail.messagingengine.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <1468692272.2410242.668163177.52CA7567@webmail.messagingengine.com> <87wpkluvcp.fsf@elektro.pacujo.net> <87inw4vhhf.fsf@elektro.pacujo.net> <1468742901.2556137.668478097.6FBDE3C3@webmail.messagingengine.com> Message-ID: On Sun, Jul 17, 2016 at 6:08 PM, Random832 wrote: > On Sun, Jul 17, 2016, at 03:51, Chris Angelico wrote: >> Currently yes, you can choose to use fractions.Fraction and pay the >> price. How, if you have a single type with different representations, >> can you make that choice? > > Sorry, I forgot to answer your question. Though, your implicit claim > that it's impossible to make choices if your choices aren't represented > by different types is absurd. > > For example, you could have a function that returns an inexact number > with the (approximately) same value as the given number. Which inexact type, though? Do you get decimal.Decimal, float, or something else? How do you make that choice? And it's a critical choice to make. They're not just "inexact numbers". You can have an exact float (eg 7/2) or an inexact one, and same with Decimal. ChrisA From bbking4611 at laposte.net Sun Jul 17 05:09:45 2016 From: bbking4611 at laposte.net (bbking4611 at laposte.net) Date: Sun, 17 Jul 2016 02:09:45 -0700 (PDT) Subject: python IDLE display with a 13.3-inch screen Message-ID: Hello, I just load the latest version of Python 3.5 on my new computer Asus 13.3-inch full HD display and the police is blurred in IDLE. I like to use IDLE with my students but I am unable to solve the problem. If someone can do an update for its screens. Thank you. Cordially. From ldompeling at casema.nl Sun Jul 17 05:19:19 2016 From: ldompeling at casema.nl (ldompeling at casema.nl) Date: Sun, 17 Jul 2016 02:19:19 -0700 (PDT) Subject: SyntaxError: Non-ASCII character Message-ID: I copy this script from the magpi but when I run this script I get this error: SyntaxError: Non-ASCII character '\xe2' in file sound.py on line 32, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details Below is the eamplescript. What is wrong with this script. # You need to import the pyaudio module import pyaudio # First, we will listen # We need to set some parameters # Buffer chunk size in bytes CHUNK = 1024 # The audio format FORMAT = pyaudio.paInt16 # The number of channels to record on CHANNELS = 2 # The sample rate, 44.1KHz RATE = 44100 # The number of seconds to record for RECORD_SECS = 5 # Next, we create a PyAudio object p = pyaudio.PyAudio() # We need a stream to record from stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=TRUE, frames_per_buffer=CHUNK) # We can now record into a temporary buffer frames = [] for i in range(0, int(RATE / CHUNK * RECORD_SECS)): data = stream.read(CHUNK) frames.append(data) # We can now shut everything down stream.stop_stream() stream.close() p.terminate() # If we want to play a wave file, we will need the wave module import wave # We can open it, give a filename wf = wave.open(?test.wav?, ?rb?) # We need a new PyAudio object p = pyaudio.PyAudio() # We will open a stream, using the settings from the wave file stream = p.open(format=p.get_format_from_width(wf.getsampwidth()), channels=wf.getnchannels(), rate=wf.getframerate(), output=True) # We can now read from the file and play it out data = wf.readframes(CHUNK) while data != ??: stream.write(data) data = wf.readframes(CHUNK) # Don?t forget to shut everything down again stream.stop_stream() stream.close() p.terminate() From rosuav at gmail.com Sun Jul 17 05:26:38 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 19:26:38 +1000 Subject: SyntaxError: Non-ASCII character In-Reply-To: References: Message-ID: On Sun, Jul 17, 2016 at 7:19 PM, wrote: > wf = wave.open(?test.wav?, ?rb?) Watch your quotes. They want to be flat quotes, U+0022 "this sort", not any sort of typographical quote. Recommendation: Use a programmer's editor, not a word processor, for working with code. As well as not mangling it, it'll often show you problems before they happen. Also, recommendation: Use Python 3, not Python 2. Your code looks like it's intended for Py3, but your error says that you ran it under Py2. The solution may be as simple as running "python3 script.py" rather than "python script.py". ChrisA From rustompmody at gmail.com Sun Jul 17 05:57:31 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 17 Jul 2016 02:57:31 -0700 (PDT) Subject: SyntaxError: Non-ASCII character In-Reply-To: References: Message-ID: <5165e8ec-2be6-49ba-8654-2ca39d643d3f@googlegroups.com> On Sunday, July 17, 2016 at 2:56:53 PM UTC+5:30, Chris Angelico wrote: > On Sun, Jul 17, 2016 at 7:19 PM, wrote: > > wf = wave.open(?test.wav?, ?rb?) > > Watch your quotes. They want to be flat quotes, U+0022 "this sort", > not any sort of typographical quote. > > Recommendation: Use a programmer's editor, not a word processor, for > working with code. As well as not mangling it, it'll often show you > problems before they happen. > > Also, recommendation: Use Python 3, not Python 2. Your code looks like > it's intended for Py3, but your error says that you ran it under Py2. > The solution may be as simple as running "python3 script.py" rather > than "python script.py". Happens when you cut paste? from web but especially from pdfs I dare say that Python3?s : Traceback (most recent call last): File "", line 1, in File "/home/ariston/foo.py", line 31 wf = wave.open(?test.wav?, ?rb?) ^ SyntaxError: invalid character in identifier is probably worse than Python2?s Traceback (most recent call last): File "", line 1, in File "foo.py", line 31 SyntaxError: Non-ASCII character '\xe2' in file foo.py on line 31, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details From steve at pearwood.info Sun Jul 17 06:04:53 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jul 2016 20:04:53 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> <0d294d49-2cf0-84be-ebcd-af1d0ffc7222@mrabarnett.plus.com> <9eda5007-a48f-4bac-8d09-c8af9e6b9987@googlegroups.com> <4854a8df-0d64-4abe-8289-ddad178d315f@googlegroups.com> Message-ID: <578b5847$0$1603$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Jul 2016 05:44 pm, Lawrence D?Oliveiro wrote: > On Sunday, July 17, 2016 at 7:33:19 PM UTC+12, Chris Angelico wrote: >> 1) REXX and, I think, Pascal: there are two specific values that may >> be used in conditionals, and anything else is an error > > Worth comparing how two different languages deal with strict enforcement > of booleans: > * Modula-2 does it right: BOOL is a separate type which is > required for conditionals, but > + the ORD and VAL functions offer typesafe conversions to and from > integers, and > + BOOL can be used as an array index type, just like any > other enumerated type. That's also the Pascal model, which is no surprise, since Modula-2 and Pascal are both invented by the same person, Nicholas(?) Wirth. I'll certainly agree that the Pascal/Modula-2 model for bools is a good model. On balance, I think that I'd argue: - in statically typed languages, I'd look for the Pascal model; - in dynamically typed languages, I'd look for something that matches Python's truthiness rules; - or at least some other consistent, useful and simple metaphor for truthiness; - a mere collection of objects which happen to be arbitrarily treated as truthy or falsey (like Ruby and Javascript?), lacking any consistent metaphor, is in some ways the worst of both worlds. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Sun Jul 17 06:35:20 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jul 2016 20:35:20 +1000 Subject: Clean Singleton Docstrings References: <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <1468692272.2410242.668163177.52CA7567@webmail.messagingengine.com> <87wpkluvcp.fsf@elektro.pacujo.net> <87inw4vhhf.fsf@elektro.pacujo.net> <1468742619.2555411.668475737.072BADA7@webmail.messagingengine.com> Message-ID: <578b5f6a$0$22142$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Jul 2016 06:03 pm, Random832 wrote: > On Sun, Jul 17, 2016, at 03:51, Chris Angelico wrote: >> > True, although the programmer has control over the feature. If you >> > *want* the luxury of exact fractions, you pay the price. If you don't, >> > you make the numbers inexact. >> >> Not if you have a single "Number" type: > > Saying that exact and inexact numbers can't be a single type is like > saying positive and negative numbers can't be the same type. Unless you're talking about about interval arithmetic, "inexact number" is an oxymoron. Numbers are not inexact or exact, only calculations are. 0.09090909090909091 is just as exact as Fraction(1, 11), they just happen to be different numbers. The first is exactly: Fraction(3275345183542179, 36028797018963968) which is a perfectly good and exact number, precisely equal to: Fraction(3275345183542178, 36028797018963968) + Fraction(1, 36028797018963968) among many other exact calculations. So I would like to know how you justify claiming that one number is exact and the other is not? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Sun Jul 17 06:37:54 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jul 2016 20:37:54 +1000 Subject: python IDLE display with a 13.3-inch screen References: Message-ID: <578b6003$0$22142$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Jul 2016 07:09 pm, bbking4611 at laposte.net wrote: > Hello, I just load the latest version of Python 3.5 on my new computer > Asus 13.3-inch full HD display and the police is blurred in IDLE. Police? police n 1: the force of policemen and officers; "the law came looking for him" [syn: police, police force, constabulary, law] I think you mean a different word, but I have no idea what. > I like > to use IDLE with my students but I am unable to solve the problem. If > someone can do an update for its screens. Thank you. Cordially. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From kent.tong.mo at gmail.com Sun Jul 17 06:57:01 2016 From: kent.tong.mo at gmail.com (Kent Tong) Date: Sun, 17 Jul 2016 03:57:01 -0700 (PDT) Subject: can't add variables to instances of built-in classes Message-ID: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> 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 call last): File "", line 1, in AttributeError: 'str' object has no attribute 'x' What makes this difference? Thanks in advance! From steve at pearwood.info Sun Jul 17 07:01:17 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jul 2016 21:01:17 +1000 Subject: SyntaxError: Non-ASCII character References: <5165e8ec-2be6-49ba-8654-2ca39d643d3f@googlegroups.com> Message-ID: <578b657f$0$1590$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Jul 2016 07:57 pm, Rustom Mody wrote: > I dare say that Python3?s : > Traceback (most recent call last): > File "", line 1, in > File "/home/ariston/foo.py", line 31 > wf = wave.open(?test.wav?, ?rb?) > ^ > SyntaxError: invalid character in identifier If the caret ^ would line up with the invalid character, that would give a hint to the reader which character was invalid. Or perhaps showing, or naming, the invalid character in the error message: SyntaxError: invalid character '?' in identifier > is probably worse than Python2?s > > Traceback (most recent call last): > File "", line 1, in > File "foo.py", line 31 > SyntaxError: Non-ASCII character '\xe2' in file foo.py on line 31, but no > encoding declared; see http://python.org/dev/peps/pep-0263/ for details I'm not sure. I think the Python 2 version is less useful: it doesn't show you the line, you have to go look for it yourself. Then you have to work out what character is \xe2, which is generally not easy because your editor is unlikely to show the escape code but rather some apparently normal looking character. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Sun Jul 17 07:02:24 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 17 Jul 2016 21:02:24 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> <0d294d49-2cf0-84be-ebcd-af1d0ffc7222@mrabarnett.plus.com> <9eda5007-a48f-4bac-8d09-c8af9e6b9987@googlegroups.com> <4854a8df-0d64-4abe-8289-ddad178d315f@googlegroups.com> Message-ID: <578b65c2$0$1590$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Jul 2016 04:44 pm, Rustom Mody wrote: > My earlier statement (with emphasis in original): >> You also have a bizarre notion that python's property: ?Everything has >> auto-bool-nature? IS STRAIGHTFORWARD. I'm still waiting to hear in what way it is not straightforward. You keep insisting that it isn't, but haven't told us in what way it is not. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From __peter__ at web.de Sun Jul 17 07:40:31 2016 From: __peter__ at web.de (Peter Otten) Date: Sun, 17 Jul 2016 13:40:31 +0200 Subject: can't add variables to instances of built-in classes References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> Message-ID: 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 call last): > File "", line 1, in > AttributeError: 'str' object has no attribute 'x' > > What makes this difference? By default custom classes have a dictionary (called __dict__) to hold these attributes. If for every string or integer there were such a dict that would waste a lot of memory. You can subclass if you need it: >>> class Str(str): pass ... >>> s = Str("hello") >>> s.x = 42 >>> s 'hello' >>> s.x 42 You can also avoid the dict in your own classes by specifiying slots for allowed attributes: >>> class Test: ... __slots__ = ("foo", "bar") ... >>> t = Test() >>> t.foo = 42 >>> t.baz = "whatever" Traceback (most recent call last): File "", line 1, in AttributeError: 'Test' object has no attribute 'baz' Use this feature sparingly, only when you know that there are going to be many (millions rather than thousands) of Test instances. From wilsonokw at gmail.com Sun Jul 17 07:50:38 2016 From: wilsonokw at gmail.com (Wilson Ong) Date: Sun, 17 Jul 2016 04:50:38 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> Message-ID: > Use this feature sparingly, only when you know that there are going to be > many (millions rather than thousands) of Test instances. Why use it sparingly? Is it for extensibility? What if I'm pretty sure that my class is going to have exactly these attributes only? From kent.tong.mo at gmail.com Sun Jul 17 07:53:27 2016 From: kent.tong.mo at gmail.com (Kent Tong) Date: Sun, 17 Jul 2016 04:53:27 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> Message-ID: Hi Peter, Thanks a lot for your excellent explanation! From ldompeling at casema.nl Sun Jul 17 08:01:21 2016 From: ldompeling at casema.nl (ldompeling at casema.nl) Date: Sun, 17 Jul 2016 05:01:21 -0700 (PDT) Subject: SyntaxError: Non-ASCII character In-Reply-To: References: Message-ID: Op zondag 17 juli 2016 11:19:32 UTC+2 schreef ldomp... at casema.nl: > I copy this script from the magpi but when I run this script I get this error: > SyntaxError: Non-ASCII character '\xe2' in file sound.py on line 32, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details > > Below is the eamplescript. What is wrong with this script. > > > # You need to import the pyaudio module > import pyaudio > # First, we will listen > # We need to set some parameters > # Buffer chunk size in bytes > CHUNK = 1024 > # The audio format > FORMAT = pyaudio.paInt16 > # The number of channels to record on > CHANNELS = 2 > # The sample rate, 44.1KHz > RATE = 44100 > # The number of seconds to record for > RECORD_SECS = 5 > # Next, we create a PyAudio object > p = pyaudio.PyAudio() > # We need a stream to record from > stream = p.open(format=FORMAT, channels=CHANNELS, > rate=RATE, input=TRUE, frames_per_buffer=CHUNK) > # We can now record into a temporary buffer > frames = [] > for i in range(0, int(RATE / CHUNK * RECORD_SECS)): > data = stream.read(CHUNK) > frames.append(data) > # We can now shut everything down > stream.stop_stream() > stream.close() > p.terminate() > # If we want to play a wave file, we will need the wave module > import wave > # We can open it, give a filename > wf = wave.open(?test.wav?, ?rb?) > # We need a new PyAudio object > p = pyaudio.PyAudio() > # We will open a stream, using the settings from the wave file > stream = p.open(format=p.get_format_from_width(wf.getsampwidth()), > channels=wf.getnchannels(), rate=wf.getframerate(), > output=True) > # We can now read from the file and play it out > data = wf.readframes(CHUNK) > while data != ??: > stream.write(data) > data = wf.readframes(CHUNK) > # Don?t forget to shut everything down again > stream.stop_stream() > stream.close() > p.terminate() I installed python 3.4 and set my python path to PYTONPATH:/usr/bin/python3.4 When I try to import pyaudio then I get this error: Python 3.4.2 (default, Oct 19 2014, 13:31:11) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pyaudio Traceback (most recent call last): File "", line 1, in ImportError: No module named 'pyaudio' Do I have to set a path also for to find the modules From rosuav at gmail.com Sun Jul 17 08:02:31 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 22:02:31 +1000 Subject: can't add variables to instances of built-in classes In-Reply-To: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> Message-ID: On Sun, Jul 17, 2016 at 9:50 PM, Wilson Ong wrote: >> Use this feature sparingly, only when you know that there are going to be >> many (millions rather than thousands) of Test instances. > > Why use it sparingly? Is it for extensibility? What if I'm pretty sure that my class is going to have exactly these attributes only? "Pretty sure" isn't enough justification for a relatively meagre saving of memory. Much easier to leave it flexible. It's only once the memory saving stops being "relatively meagre" (for instance, with the built-in 'str' type - there are a LOT of strings in a Python program, since your variable names are stored as strings) that it's worth doing that. ChrisA From rosuav at gmail.com Sun Jul 17 08:11:06 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jul 2016 22:11:06 +1000 Subject: SyntaxError: Non-ASCII character In-Reply-To: References: Message-ID: On Sun, Jul 17, 2016 at 10:01 PM, wrote: > I installed python 3.4 and set my python path to PYTONPATH:/usr/bin/python3.4 > > When I try to import pyaudio then I get this error: > Python 3.4.2 (default, Oct 19 2014, 13:31:11) > [GCC 4.9.1] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import pyaudio > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named 'pyaudio' > > Do I have to set a path also for to find the modules You shouldn't need to set your python path. But, what you may need to do is install pyaudio under Python 3. Whatever you did for Py2, do again for Py3 - for instance: $ sudo python3 -m pip install pyaudio ChrisA From ldompeling at casema.nl Sun Jul 17 09:35:27 2016 From: ldompeling at casema.nl (ldompeling at casema.nl) Date: Sun, 17 Jul 2016 06:35:27 -0700 (PDT) Subject: SyntaxError: Non-ASCII character In-Reply-To: References: Message-ID: <05605cfc-bc97-4dfe-bd6d-6a494079a684@googlegroups.com> Op zondag 17 juli 2016 11:19:32 UTC+2 schreef ldomp... at casema.nl: > I copy this script from the magpi but when I run this script I get this error: > SyntaxError: Non-ASCII character '\xe2' in file sound.py on line 32, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details > > Below is the eamplescript. What is wrong with this script. > > > # You need to import the pyaudio module > import pyaudio > # First, we will listen > # We need to set some parameters > # Buffer chunk size in bytes > CHUNK = 1024 > # The audio format > FORMAT = pyaudio.paInt16 > # The number of channels to record on > CHANNELS = 2 > # The sample rate, 44.1KHz > RATE = 44100 > # The number of seconds to record for > RECORD_SECS = 5 > # Next, we create a PyAudio object > p = pyaudio.PyAudio() > # We need a stream to record from > stream = p.open(format=FORMAT, channels=CHANNELS, > rate=RATE, input=TRUE, frames_per_buffer=CHUNK) > # We can now record into a temporary buffer > frames = [] > for i in range(0, int(RATE / CHUNK * RECORD_SECS)): > data = stream.read(CHUNK) > frames.append(data) > # We can now shut everything down > stream.stop_stream() > stream.close() > p.terminate() > # If we want to play a wave file, we will need the wave module > import wave > # We can open it, give a filename > wf = wave.open(?test.wav?, ?rb?) > # We need a new PyAudio object > p = pyaudio.PyAudio() > # We will open a stream, using the settings from the wave file > stream = p.open(format=p.get_format_from_width(wf.getsampwidth()), > channels=wf.getnchannels(), rate=wf.getframerate(), > output=True) > # We can now read from the file and play it out > data = wf.readframes(CHUNK) > while data != ??: > stream.write(data) > data = wf.readframes(CHUNK) > # Don?t forget to shut everything down again > stream.stop_stream() > stream.close() > p.terminate() I hate it to ask you again but I really want that this script going to work. And I use the raspberry pi for it. I also get a lot off alsa errors on my screen so I don't no if that result in this error: Traceback (most recent call last): File "sound.py", line 19, in rate=RATE, input=TRUE, frames_per_buffer=CHUNK) NameError: name 'TRUE' is not defined From steve at pearwood.info Sun Jul 17 10:49:36 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jul 2016 00:49:36 +1000 Subject: SyntaxError: Non-ASCII character References: Message-ID: <578b9b01$0$1585$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Jul 2016 10:01 pm, ldompeling at casema.nl wrote: > I installed python 3.4 and set my python path to > PYTONPATH:/usr/bin/python3.4 > > When I try to import pyaudio then I get this error: > Python 3.4.2 (default, Oct 19 2014, 13:31:11) > [GCC 4.9.1] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import pyaudio > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named 'pyaudio' > > Do I have to set a path also for to find the modules No, but you do have to install pyaudio separately for each version of Python you have. So if you have installed Python 2.7 and 3.4, and Python 2.7 has pyaudio installed, Python 3.4 cannot use the same one. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Sun Jul 17 10:50:19 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jul 2016 00:50:19 +1000 Subject: SyntaxError: Non-ASCII character References: <05605cfc-bc97-4dfe-bd6d-6a494079a684@googlegroups.com> Message-ID: <578b9b2c$0$1591$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Jul 2016 11:35 pm, ldompeling at casema.nl wrote: > I also get a lot off alsa errors on my screen so I don't no if that result > in this error: > > Traceback (most recent call last): > File "sound.py", line 19, in > rate=RATE, input=TRUE, frames_per_buffer=CHUNK) > NameError: name 'TRUE' is not defined Try using input=True instead. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Sun Jul 17 11:00:00 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 17 Jul 2016 08:00:00 -0700 (PDT) Subject: Operator Precedence/Boolean Logic In-Reply-To: <578b65c2$0$1590$c3e8da3$5496439d@news.astraweb.com> References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <57745c6d$0$1583$c3e8da3$5496439d@news.astraweb.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> <0d294d49-2cf0-84be-ebcd-af1d0ffc7222@mrabarnett.plus.com> <9eda5007-a48f-4bac-8d09-c8af9e6b9987@googlegroups.com> <4854a8df-0d64-4abe-8289-ddad178d315f@googlegroups.com> <578b65c2$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, July 17, 2016 at 4:32:36 PM UTC+5:30, Steven D'Aprano wrote: > On Sun, 17 Jul 2016 04:44 pm, Rustom Mody wrote: > > > My earlier statement (with emphasis in original): > >> You also have a bizarre notion that python's property: ?Everything has > >> auto-bool-nature? IS STRAIGHTFORWARD. > > I'm still waiting to hear in what way it is not straightforward. You keep > insisting that it isn't, but haven't told us in what way it is not. The re/automaton/graph examples were towards this only and I think we are running in circles on this. [Note the persons involved and even the specific types involved are in a sense not relevant] There is however one point that I briefly alluded that can be expanded on, viz. Python?s bool behavior is inconsistent with rest of python?s standard behavior. >>> class C: ... pass ... >>> c=C() >>> c+c Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'instance' and 'instance' >>> c.a Traceback (most recent call last): File "", line 1, in AttributeError: C instance has no attribute 'a' >>> a Traceback (most recent call last): File "", line 1, in NameError: name 'a' is not defined IOW the details ? AttributeError/NameError/TypeError ? may differ but in general python has a well-established (and IMHO kind) behavior, if programmer fails to define something python helpfully says that and makes no random guesses. The extremal behavior at the other end of the spectum is probably html: Whatever html you throw at whatever browser it will be rendered in some way or other. [Some people like this ? standards are for wimps] For bools python is closer to html than to its normal peremptory default: >>> if c: ... print "Yes" ... else: ... print "No" ... Yes From steve at pearwood.info Sun Jul 17 11:04:01 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jul 2016 01:04:01 +1000 Subject: can't add variables to instances of built-in classes References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> Message-ID: <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> On Sun, 17 Jul 2016 09:50 pm, Wilson Ong wrote: > >> Use this feature sparingly, only when you know that there are going to be >> many (millions rather than thousands) of Test instances. > > Why use it sparingly? Is it for extensibility? What if I'm pretty sure > that my class is going to have exactly these attributes only? It's your own code, you can do anything you like, its not like the Python Police will come and arrest you. But *best practice* is for instances to have a __dict__, which allows them to have instance attributes. Python code expects to be able to inspect, and write to, the instance __dict__, and if you don't have one, you may break code that doesn't expect it. But it is not a hard rule, just a strong recommendation. There are exceptions. Most built-ins don't have __dict__, partly as an optimization, and partly to allow sharing of builtins across sub-interpreters; __slots__ was specifically invented so that classes created in Python could avoid creating a per-instance __dict__, for cases where you expect to have vast numbers of instances with only a fixed number of attributes. In this case, having an unused __dict__ can be wasteful. But note that in recent versions of Python, there is less need to use __slots__, and a much smaller benefit. The reason is that the instance dicts can now share storage for their keys. https://www.python.org/dev/peps/pep-0412/ __slots__ is not obsolete, but 99% of the time you shouldn't bother with it. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Sun Jul 17 11:58:38 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jul 2016 01:58:38 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> <0d294d49-2cf0-84be-ebcd-af1d0ffc7222@mrabarnett.plus.com> <9eda5007-a48f-4bac-8d09-c8af9e6b9987@googlegroups.com> <4854a8df-0d64-4abe-8289-ddad178d315f@googlegroups.com> <578b65c2$0$1590$c3e8da3$5496439d@news.astraweb.com> Message-ID: <578bab30$0$1614$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Jul 2016 01:00 am, Rustom Mody wrote: >> I'm still waiting to hear in what way it is not straightforward. You keep >> insisting that it isn't, but haven't told us in what way it is not. > > The re/automaton/graph examples were towards this only and I think we are > running in circles on this. [Note the persons involved and even the > specific types involved are in a sense not relevant] Ah, so its a secret, is it? ;-) > There is however one point that I briefly alluded that can be expanded on, > viz. Python?s bool behavior is inconsistent with rest of python?s standard > behavior. "Inconsistent" is too strong. Treatment of bools is certainly different from (say) arithmetic. Python doesn't assume that every object can duck-type as a number -- there's no standard protocol for coercing HTTPServer objects into floats, for example. But bools are not the only "universal" type. Strings are too. All objects can be coerced to strings, using either str() or repr(). If you define only one of __str__ or __repr__, Python will use the other. If you define neither, you will inherit from object. If you are using a classic class in Python 2, you will inherit the built-in conversion. Likewise equality: == is expected to work with *every* class, without exception, so if you fail to define an __eq__ method, Python will use its own default behaviour (which is to compare object identity). There are a small, but very important, set of functions which are expected to work on all objects, and coercion to bool is one of them. > IOW the details ? AttributeError/NameError/TypeError ? may differ but in > general python has a well-established (and IMHO kind) behavior, if > programmer fails to define something python helpfully says that and makes > no random guesses. There is *no random guessing* involved. I've already gone through the steps of the bool protocol two, three, maybe four times. Why do you misrepresent this as "random guesses"? There's no element of chance, the protocol is completely deterministic and documented. There's a preferred API, __nonzero__ in Python 2 and __bool__ in Python 3, if that isn't defined there's a fallback using __len__, if that's not defined then the usual rules of inheritance apply and you inherit from your superclasses. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Sun Jul 17 12:01:30 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jul 2016 02:01:30 +1000 Subject: Operator Precedence/Boolean Logic References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <5775555f$0$22140$c3e8da3$5496439d@news.astraweb.com> <7ecde6d0-d3db-4a7a-8de6-65b398fedafe@googlegroups.com> <578a0992$0$1610$c3e8da3$5496439d@news.astraweb.com> <578a605f$0$1611$c3e8da3$5496439d@news.astraweb.com> <0d294d49-2cf0-84be-ebcd-af1d0ffc7222@mrabarnett.plus.com> <9eda5007-a48f-4bac-8d09-c8af9e6b9987@googlegroups.com> <4854a8df-0d64-4abe-8289-ddad178d315f@googlegroups.com> <578b65c2$0$1590$c3e8da3$5496439d@news.astraweb.com> <578bab30$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <578babdb$0$1614$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Jul 2016 01:58 am, Steven D'Aprano wrote: > All objects > can be coerced to strings, using either str() or repr(). If you define > only one of __str__ or __repr__, Python will use the other. Er, sorry, that was incoherent. I hit Send too quick, without editing. What I meant to say was, if you *fail* to define both __str__ and __repr__, Python will use whichever you define in place of the missing one. And of course, if you define neither, then you will inherit from object. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From best_lay at yahoo.com Sun Jul 17 12:07:44 2016 From: best_lay at yahoo.com (Wildman) Date: Sun, 17 Jul 2016 11:07:44 -0500 Subject: SyntaxError: Non-ASCII character References: Message-ID: On Sun, 17 Jul 2016 05:01:21 -0700, ldompeling wrote: > I installed python 3.4 and set my python path to PYTONPATH:/usr/bin/python3.4 > > When I try to import pyaudio then I get this error: > Python 3.4.2 (default, Oct 19 2014, 13:31:11) > [GCC 4.9.1] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import pyaudio > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named 'pyaudio' You need to install the Pytyon3 version of pyaudio... sudo apt-get install python3-pyaudio > Do I have to set a path also for to find the modules No. -- GNU/Linux user #557453 The cow died so I don't need your bull! From ldompeling at casema.nl Sun Jul 17 12:27:21 2016 From: ldompeling at casema.nl (ldompeling at casema.nl) Date: Sun, 17 Jul 2016 09:27:21 -0700 (PDT) Subject: SyntaxError: Non-ASCII character In-Reply-To: References: Message-ID: <5d689fa9-323e-4da2-8e00-48e2f8a5c88b@googlegroups.com> Op zondag 17 juli 2016 11:19:32 UTC+2 schreef ldomp... at casema.nl: > I copy this script from the magpi but when I run this script I get this error: > SyntaxError: Non-ASCII character '\xe2' in file sound.py on line 32, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details > > Below is the eamplescript. What is wrong with this script. > > > # You need to import the pyaudio module > import pyaudio > # First, we will listen > # We need to set some parameters > # Buffer chunk size in bytes > CHUNK = 1024 > # The audio format > FORMAT = pyaudio.paInt16 > # The number of channels to record on > CHANNELS = 2 > # The sample rate, 44.1KHz > RATE = 44100 > # The number of seconds to record for > RECORD_SECS = 5 > # Next, we create a PyAudio object > p = pyaudio.PyAudio() > # We need a stream to record from > stream = p.open(format=FORMAT, channels=CHANNELS, > rate=RATE, input=TRUE, frames_per_buffer=CHUNK) > # We can now record into a temporary buffer > frames = [] > for i in range(0, int(RATE / CHUNK * RECORD_SECS)): > data = stream.read(CHUNK) > frames.append(data) > # We can now shut everything down > stream.stop_stream() > stream.close() > p.terminate() > # If we want to play a wave file, we will need the wave module > import wave > # We can open it, give a filename > wf = wave.open(?test.wav?, ?rb?) > # We need a new PyAudio object > p = pyaudio.PyAudio() > # We will open a stream, using the settings from the wave file > stream = p.open(format=p.get_format_from_width(wf.getsampwidth()), > channels=wf.getnchannels(), rate=wf.getframerate(), > output=True) > # We can now read from the file and play it out > data = wf.readframes(CHUNK) > while data != ??: > stream.write(data) > data = wf.readframes(CHUNK) > # Don?t forget to shut everything down again > stream.stop_stream() > stream.close() > p.terminate() When I change input=True instead than I get a lot of errors: Traceback (most recent call last): File "sound.py", line 19, in rate=RATE, input=True, frames_per_buffer=CHUNK) File "/usr/lib/python3/dist-packages/pyaudio.py", line 747, in open stream = Stream(self, *args, **kwargs) File "/usr/lib/python3/dist-packages/pyaudio.py", line 442, in __init__ self._stream = pa.open(**arguments) OSError: [Errno Invalid number of channels] -9998 I don't think we can solve those errors Anyway thanks for helping me out so far. From tsanchez117.ts at gmail.com Sun Jul 17 15:00:58 2016 From: tsanchez117.ts at gmail.com (tsanchez117.ts at gmail.com) Date: Sun, 17 Jul 2016 12:00:58 -0700 (PDT) Subject: Python code change Message-ID: <22010181-adea-4934-aa6b-fcbec9fef91f@googlegroups.com> Im trying to run a Python application but im stuck on a problem. The application requires a log in and password to run the application. The only problem that I'm having is that the code was written to connect to a data base and from there it sees the username and password that is linked to the data base. The file application was in .pyc, I already uncompyled to py. I was wondering if there is any way that I can change the code to where the log in and username are in the code and not in the database with the same outcome of course. I can send you the code if that'll be helpful? Thank you. From steve at pearwood.info Sun Jul 17 15:37:04 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jul 2016 05:37:04 +1000 Subject: Python code change References: <22010181-adea-4934-aa6b-fcbec9fef91f@googlegroups.com> Message-ID: <578bde61$0$1591$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Jul 2016 05:00 am, tsanchez117.ts at gmail.com wrote: > Im trying to run a Python application but im stuck on a problem. The > application requires a log in and password to run the application. The > only problem that I'm having is that the code was written to connect to a > data base and from there it sees the username and password that is linked > to the data base. The file application was in .pyc, I already uncompyled > to py. I was wondering if there is any way that I can change the code to > where the log in and username are in the code and not in the database with > the same outcome of course. I can send you the code if that'll be helpful? > Thank you. No. If the database requires a username and password, it requires a username and password. You can't get around that by editing the Python file. If you can gain access to the database, you might be able to remove the password from it so that there is no need for authentication, but first you have to get access to the database. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From lawrencedo99 at gmail.com Sun Jul 17 23:00:55 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Sun, 17 Jul 2016 20:00:55 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> 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 , for example. From rustompmody at gmail.com Mon Jul 18 00:16:18 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 17 Jul 2016 21:16:18 -0700 (PDT) Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> On Saturday, July 16, 2016 at 3:16:48 PM UTC+5:30, Steven D'Aprano wrote: > On Sat, 16 Jul 2016 04:53 pm, Random832 wrote: > > > Eliminate both of them. Move to a single abstract numeric type* a la > > Scheme, with an "inexact" attribute (inexact numbers may or may not be > > represented by a float, or by the same bigint/decimal/rational types as > > exact ones with a flag set to mark them as inexact.) > > But that's *wrong*. Numbers are never inexact. (You can have interval > arithmetic using "fuzzy numbers", but they're ALWAYS inexact.) It is > calculations which are exact or inexact, not numbers. There's no a priori > reason to expect that 0.499999 is "inexact" while 0.5 is "exact", you need > to know the calculation that generated it: Heh! Did you check what scheme has to say about this before holding forth? I suggest a tool called google. It can make one seem profound Here are the first couple of hits it gives (me) for ?scheme exact number? | Scheme integers can be exact and inexact. For example, a number | written as 3.0 with an explicit decimal-point is inexact, but it | is also an integer. The functions integer? and scm_is_integer | report true for such a number, but the functions exact-integer?? | only allow exact integers and thus report | false. Likewise, the conversion functions like | scm_to_signed_integer only accept exact integers. | | The motivation for this behavior is that the inexactness of a number | should not be lost silently. If you want to allow inexact integers, | you can explicitly insert a call to inexact->exact or to its C | equivalent scm_inexact_to_exact. (Only inexact integers will be | converted by this call into exact integers; inexact non-integers | will become exact fractions.) https://www.gnu.org/software/guile/manual/html_node/Integers.html | All numbers are complex numbers. Some of them are real numbers, and | all of the real numbers that can be represented are also rational | numbers, except for +inf.0 (positive infinity), +inf.f | (single-precision variant), -inf.0 (negative infinity), -inf.f | (single-precision variant), +nan.0 (not-a-number), and +nan.f | (single-precision variant). Among the rational numbers, some are | integers, because round applied to the number produces the same | number. | | Orthogonal to those categories, each number is also either an exact | number or an inexact number. Unless otherwise specified, computations | that involve an inexact number produce inexact results. Certain | operations on inexact numbers, however, produce an exact number, such | as multiplying an inexact number with an exact 0. Operations that | mathematically produce irrational numbers for some rational arguments | (e.g., sqrt) may produce inexact results even for exact arguments. https://docs.racket-lang.org/reference/numbers.html AIUI? There are two almost completely unrelated notions of exact 1. ? in decimal cannot be exactly represented though 0.3 0.33 etc are approximations. We could call these inexact forms of ? 2. Measurement and observation produces numbers. These are inexact inherently. Scheme's notion of exact is towards capturing the second notion. According to which ?There were 20,000 people in the stadium? would be an inexact integer [Yeah note Inexact INTEGER] whereas ?2, e, ? are all exact. Just that they dont have finite decimal/continued fraction and of course float representations. In short one could think of inexact and exact ? in scheme's intended semantics ? as better called scientific (or science-ic) and mathematic numbers. Or if you prefer more philosophic jargon: analytic numbers and synthetic numbers: The fact that analytic/mathematic and synthetic/science-ic domains at all correspond is at the least surprising. Famous article calling it ?unreasonable? starts with this: | THERE IS A story about two friends, who were classmates in high | school, talking about their jobs. One of them became a statistician | and was working on population trends. He showed a reprint to his | former classmate. The reprint started, as usual, with the Gaussian | distribution and the statistician explained to his former classmate | the meaning of the symbols for the actual population, for the average | population, and so on. His classmate was a bit incredulous and was not | quite sure whether the statistician was pulling his leg. "How can you | know that?" was his query. "And what is this symbol here?" "Oh," said | the statistician, "this is pi." "What is that?" "The ratio of the | circumference of the circle to its diameter." "Well, now you are | pushing your joke too far," said the classmate, "surely the population | has nothing to do with the circumference of the circle." | https://www.dartmouth.eduh/~matc/MathDrama/reading/Wigner.html But the match while strong is not quite perfect: Physical length (unlike math numbers) may have a ?least count? https://en.wikipedia.org/wiki/Planck_length Likewise time https://en.wikipedia.org/wiki/Planck_time And of course all this is highly speculative; ie it may be https://en.wikipedia.org/wiki/Chronon At the more mundane level when I read off 2 volts on a voltmeter - May be reading wrong by seeing from a wrong angle - Meter may be miscalibrated - Or broken - Or the range setting was not 0-10 as I imagined but 0-500 - And so on IOW numbers picked off from the real world are just naturally wrong And that's nothing to do with math operations like floating point introducing errors From rosuav at gmail.com Mon Jul 18 00:35:48 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jul 2016 14:35:48 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> Message-ID: On Mon, Jul 18, 2016 at 2:16 PM, Rustom Mody wrote: > On Saturday, July 16, 2016 at 3:16:48 PM UTC+5:30, Steven D'Aprano wrote: > Here are the first couple of hits it gives (me) for ?scheme exact number? > > | Scheme integers can be exact and inexact. For example, a number > | written as 3.0 with an explicit decimal-point is inexact, but it > | is also an integer. > > AIUI? > There are two almost completely unrelated notions of exact > > 1. ? in decimal cannot be exactly represented though 0.3 0.33 etc are approximations. > We could call these inexact forms of ? > > 2. Measurement and observation produces numbers. These are inexact inherently. > > Scheme's notion of exact is towards capturing the second notion. Why does that mean that 3.0 is inexact? In what way is 3.0 "inexact"? It's an exact value representing the integer three. ChrisA From ben+python at benfinney.id.au Mon Jul 18 00:46:35 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 18 Jul 2016 14:46:35 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> Message-ID: <85r3arsgd0.fsf@benfinney.id.au> Rustom Mody writes: > AIUI? > There are two almost completely unrelated notions of exact > > 1. ? in decimal cannot be exactly represented though 0.3 0.33 etc are > approximations. We could call these inexact forms of ? Better would be to use the term already used: 0.3333 is an inexact *representation* of ?. > 2. Measurement and observation produces numbers. These are inexact > inherently. What is ?those?? The measurement is imprecise, the observations are inexact. It makes no sense to say that a number is inexact. Exactness is not a property of a number. It has one value, which is its identity; it is a singleton. > Scheme's notion of exact is towards capturing the second notion. > According to which > ?There were 20,000 people in the stadium? would be an inexact integer > [Yeah note Inexact INTEGER] The number 20?000 is an integer. It has exactly that value. The number of people may differ (say, 19?997 people), and ?20?000 people? is then an inexact representation of the number of people. > whereas ?2, e, ? are all exact. Exactly what? A number either is ?, or it is not. The number ? is not exact or inexact; it simply has one value. > IOW numbers picked off from the real world are just naturally wrong The measurement can be wrong. We know that the chances are very high that the measurement will be imprecise. How can the *number* be wrong? You will be able to express yourself much more clearly on this topic when you cease conflating a number with measurements of that number, or conflating a number with representations of that number. -- \ ?I know you believe you understood what you think I said, but I | `\ am not sure you realize that what you heard is not what I | _o__) meant.? ?Robert J. McCloskey | Ben Finney From rustompmody at gmail.com Mon Jul 18 01:22:34 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 17 Jul 2016 22:22:34 -0700 (PDT) Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <85r3arsgd0.fsf@benfinney.id.au> Message-ID: <72c698ab-c5f8-4fb6-a274-3b92daf729d0@googlegroups.com> On Monday, July 18, 2016 at 10:16:58 AM UTC+5:30, Ben Finney wrote: > You will be able to express yourself much more clearly on this topic > when you cease conflating a number with measurements of that number, or > conflating a number with representations of that number. > That more or less sums up (my understanding of) scheme's intent of having the exact/inexact classification: An inexact number is a measured/observed number with that data intentionally preserved. An exact number is just a mathematic number ie a plain ol' number >From the scheme docs I earlier quoted: | [Motivation for (in)exact...] the inexactness of a number (is a property | that) should not be lost silently. As Chris question/example illustrates this may be sufficiently messed up by floats that the distinction may not be worth making. Dunno... Ive no definite opinion/data on that. To put it simply float is such a grotesquely unmathematical type that it is unlikely to cooperate with clean orthogonal distinctions such as - Exact/inexact types are orthogonal to the rest of the number hierarchy - Modelling converts a ?real-world? measurement/observation into a mathematical entity - etc From rustompmody at gmail.com Mon Jul 18 01:37:50 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 17 Jul 2016 22:37:50 -0700 (PDT) Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> Message-ID: <4a5bcb6a-6fc9-4c60-a24c-0c2dc3ffcb19@googlegroups.com> On Monday, July 18, 2016 at 10:06:11 AM UTC+5:30, Chris Angelico wrote: > On Mon, Jul 18, 2016 at 2:16 PM, Rustom Mody wrote: > > On Saturday, July 16, 2016 at 3:16:48 PM UTC+5:30, Steven D'Aprano wrote: > > Here are the first couple of hits it gives (me) for ?scheme exact number? > > > > | Scheme integers can be exact and inexact. For example, a number > > | written as 3.0 with an explicit decimal-point is inexact, but it > > | is also an integer. > > > > AIUI? > > There are two almost completely unrelated notions of exact > > > > 1. ? in decimal cannot be exactly represented though 0.3 0.33 etc are approximations. > > We could call these inexact forms of ? > > > > 2. Measurement and observation produces numbers. These are inexact inherently. > > > > Scheme's notion of exact is towards capturing the second notion. > > Why does that mean that 3.0 is inexact? In what way is 3.0 "inexact"? > It's an exact value representing the integer three. [Assuming you are asking in good faith and in the same vein I am answering without claiming to know all this with much certainty] I believe we need to distinguish between the intention and its realization within the syntactic (in this case lexical) structures of the language. The INTENTION is that in addition to capturing the usual number tower ? ? ? ? ? (or parts therefore) scheme also captures ORTHOGONALLY (word in the docs) the (in)exactness attribute In the realization, the designers need to (over)load these different attributes onto numeric constants. So the ruse chosen is that fraction-constants by default are exact Decimal constants are inexact And one can override any of these by suitable a function [At least that's my understanding] From rosuav at gmail.com Mon Jul 18 01:48:50 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jul 2016 15:48:50 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <4a5bcb6a-6fc9-4c60-a24c-0c2dc3ffcb19@googlegroups.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <4a5bcb6a-6fc9-4c60-a24c-0c2dc3ffcb19@googlegroups.com> Message-ID: On Mon, Jul 18, 2016 at 3:37 PM, Rustom Mody wrote: > On Monday, July 18, 2016 at 10:06:11 AM UTC+5:30, Chris Angelico wrote: >> Why does that mean that 3.0 is inexact? In what way is 3.0 "inexact"? >> It's an exact value representing the integer three. > > [Assuming you are asking in good faith and in the same vein I am answering > without claiming to know all this with much certainty] [Yes, I was] > I believe we need to distinguish between the intention and its realization > within the syntactic (in this case lexical) structures of the language. > > The INTENTION is that in addition to capturing the usual number tower > ? ? ? ? ? (or parts therefore) > scheme also captures ORTHOGONALLY (word in the docs) the (in)exactness attribute > > In the realization, the designers need to (over)load these different attributes > onto numeric constants. > So the ruse chosen is that fraction-constants by default are exact > Decimal constants are inexact > And one can override any of these by suitable a function > [At least that's my understanding] Ah. Okay. So in theory, you could have exact float literals and inexact integer literals, if you tag them in some way: 300 ; Exactly 300 300! ; Inexact - roughly 300 3.0 ; Exactly three 3.0! ; Roughly three and zero tenths This then eliminates the problem of representing exact non-integers (for instance, IEEE floating point has no problem representing exactly 3.125, but if all floats are automatically "inexact", you lose that facility), but it then pushes the question of "what does inexact really MEAN" up to the programmer, at which point it really ends up in the domain of error values rather than a simple flag "inexact". In Python, this sort of thing would be perfect as a PyPI package - "numbers with error values" - which could then define all arithmetic operations and how they combine error values (with an implicit upcast from any numeric type to "number with error value of +/- 0"). It wouldn't need to be part of the core language. ChrisA From marko at pacujo.net Mon Jul 18 02:21:30 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Jul 2016 09:21:30 +0300 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <4a5bcb6a-6fc9-4c60-a24c-0c2dc3ffcb19@googlegroups.com> Message-ID: <87y44zsbyt.fsf@elektro.pacujo.net> Chris Angelico : > Ah. Okay. So in theory, you could have exact float literals and > inexact integer literals, if you tag them in some way: > > 300 ; Exactly 300 > 300! ; Inexact - roughly 300 > 3.0 ; Exactly three > 3.0! ; Roughly three and zero tenths In Scheme: #e300 #i300 #e3.0 #i3.0 In principle, a Scheme implementation could have exact algebraic numbers spiked with exact constants like e and ?. In practice, exact numbers are integers and rationals, while inexact numbers are floats and complex numbers. It is a matter of opinion whether the conceptual abstraction is worth the confusion. Marko From __peter__ at web.de Mon Jul 18 03:38:33 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Jul 2016 09:38:33 +0200 Subject: can't add variables to instances of built-in classes References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> Message-ID: 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 > , for example. When you remove them, does your library stop working? Is there a significant increase of memory consumption? Or is there something I didn't think of that makes them useful for you? From alister.ware at ntlworld.com Mon Jul 18 04:37:03 2016 From: alister.ware at ntlworld.com (alister) Date: Mon, 18 Jul 2016 08:37:03 GMT Subject: Python code change References: <22010181-adea-4934-aa6b-fcbec9fef91f@googlegroups.com> Message-ID: On Sun, 17 Jul 2016 12:00:58 -0700, tsanchez117.ts wrote: > Im trying to run a Python application but im stuck on a problem. The > application requires a log in and password to run the application. The > only problem that I'm having is that the code was written to connect to > a data base and from there it sees the username and password that is > linked to the data base. The file application was in .pyc, I already > uncompyled to py. I was wondering if there is any way that I can change > the code to where the log in and username are in the code and not in the > database with the same outcome of course. I can send you the code if > that'll be helpful? Thank you. talk to the system administrator if you are authorised to have this information they will be able to provide it -- "The combination of a number of things to make existence worthwhile." "Yes, the philosophy of 'none,' meaning 'all.'" -- Spock and Lincoln, "The Savage Curtain", stardate 5906.4 From steve+comp.lang.python at pearwood.info Mon Jul 18 05:29:42 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 18 Jul 2016 19:29:42 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> Message-ID: <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> On Monday 18 July 2016 14:16, Rustom Mody wrote: > On Saturday, July 16, 2016 at 3:16:48 PM UTC+5:30, Steven D'Aprano wrote: >> But that's *wrong*. Numbers are never inexact. (You can have interval >> arithmetic using "fuzzy numbers", but they're ALWAYS inexact.) It is >> calculations which are exact or inexact, not numbers. There's no a priori >> reason to expect that 0.499999 is "inexact" while 0.5 is "exact", you need >> to know the calculation that generated it: > > Heh! Did you check what scheme has to say about this before holding forth? > I suggest a tool called google. It can make one seem profound Emphasis on the "seem" rather than "actually be" *wink* > Here are the first couple of hits it gives (me) for ?scheme exact number? [...] > | The motivation for this behavior is that the inexactness of a number > | should not be lost silently. I appreciate the motivation, but I don't think the Scheme, er, scheme is well- thought out or meaningful. "Exact" or "inexact" is too blunt an instrument to be of much use. If you do a bunch of calculations, and get a result of 1.0, all that tells you is that the "true" (i.e. infinitely precise) value is something possibly centered at 1 with an unknown, not necessarily small, error. So now you know that *at least one* calculation was inexact, but not which ones, or the magnitude of the errors introduced. The Scheme system is effectively the same as a really poor interval arithmetic system, where numbers can be recorded in two forms: x ? 0 # exact x ? ? # inexact and nothing in between. > AIUI? > There are two almost completely unrelated notions of exact > > 1. ? in decimal cannot be exactly represented though 0.3 0.33 etc are > approximations. > We could call these inexact forms of ? But 0.3 is an exact representation of 3/10, 0.1 + 0.2, 0.6/2, etc. > 2. Measurement and observation produces numbers. These are inexact > inherently. > > Scheme's notion of exact is towards capturing the second notion. I don't see anything in the Guile documentation you linked to which supports that interpretation. > According to which > ?There were 20,000 people in the stadium? would be an inexact integer > [Yeah note Inexact INTEGER] Without a bound on the error ("between 0 and 7 billion people, but probably 20,000") that's of very little use. > whereas > ?2, e, ? are all exact. Just that they dont have finite decimal/continued > fraction and of course float representations. There are computer algebra systems capable of treating irrationals like ?2, e and ? as exact numbers, but I'm pretty sure Guile is not one of them. > In short one could think of inexact and exact ? in scheme's intended > semantics ? as better called scientific (or science-ic) and mathematic > numbers. I don't think so. "Science" uses both experimentally-derived numbers (e.g. G, c, the mass of the electron) and numbers known exactly (?2, e, ?). I think one could better think of Scheme's semantics as a poorly-thought out hybrid between traditional numerics and a vague approximation to interval arithmetic. -- Steve From erikkago at gmail.com Mon Jul 18 05:50:04 2016 From: erikkago at gmail.com (Eric kago) Date: Mon, 18 Jul 2016 12:50:04 +0300 Subject: Request for help Message-ID: Hi Pythoners I need help in understanding hoe to put up the code to the following command - Create a constructor that takes in an integer and assigns this to a `balance` property Regards, Eric Kago +254(0)714249373 Nairobi Kenya From marko at pacujo.net Mon Jul 18 06:00:12 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Jul 2016 13:00:12 +0300 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> Message-ID: <877fcjcllf.fsf@elektro.pacujo.net> Steven D'Aprano : > I think one could better think of Scheme's semantics as a > poorly-thought out hybrid between traditional numerics and a vague > approximation to interval arithmetic. Python programmers (among others) frequently run into issues with surprising results in floating-point arithmetics. For better or worse, Scheme has tried to abstract the concept. You don't need to explain the ideas of IEEE 64-bit floating-point numbers or tie the hands of the implementation. Instead, what you have is "reliable" arithmetics and "best-effort" arithmetics, a bit like TCP is "reliable" and UDP is "best-effort". "Inexact" means there's a possibility of rounding errors. "Exact" means no rounding errors were introduced by the limitations of the hardware or the algorithms. How inexact the inexact results is a complicated topic for numeric programming. Marko From rustompmody at gmail.com Mon Jul 18 06:14:56 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 18 Jul 2016 03:14:56 -0700 (PDT) Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> Message-ID: <817ffebd-ee2b-4950-9687-19b5c44d1281@googlegroups.com> On Monday, July 18, 2016 at 2:59:56 PM UTC+5:30, Steven D'Aprano wrote: > On Monday 18 July 2016 14:16, Rustom Mody wrote: > > AIUI? > > There are two almost completely unrelated notions of exact > > > > 1. ? in decimal cannot be exactly represented though 0.3 0.33 etc are > > approximations. > > We could call these inexact forms of ? > > But 0.3 is an exact representation of 3/10, 0.1 + 0.2, 0.6/2, etc. > > > > 2. Measurement and observation produces numbers. These are inexact > > inherently. > > > > Scheme's notion of exact is towards capturing the second notion. > > I don't see anything in the Guile documentation you linked to which supports > that interpretation. Exact example :: index operations into data structures may need to know the index exactly, as may some operations on polynomial coefficients in a symbolic algebra system. Inexact example :: the results of measurements are inherently inexact, and irrational numbers may be approximated by rational and therefore inexact approximations. [from the Scheme standard http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-6.html ] I believe the two clauses: - measurements inherently inexact - rational approximations to irrationals The first represents the basic intention The second represents the fact that pragmatically we are stuck with things like floating point as the same chapter indicates at start: || This chapter describes Scheme's model for numbers. It is important to || distinguish between the mathematical numbers, the Scheme objects that || attempt to model them, the machine representations used to implement || the numbers, and notations used to write numbers. In this report, the || term number refers to a mathematical number, and the term number || object refers to a Scheme object representing a number. This report || uses the types complex, real, rational, and integer to refer to both || mathematical numbers and number objects. The fixnum and flonum types || refer to special subsets of the number objects, as determined by || common machine representations, as explained below. || || Numbers may be arranged into a tower of subsets in which each level is a subset of the level above it: || || number || complex || real || rational || integer || || For example, 5 is an integer. Therefore 5 is also a rational, a real, || and a complex. The same is true of the number objects that model 5. || || There is no simple relationship between the subset that contains a || number and its representation inside a computer. For example, the || integer 5 may have several represen || operations treat number objects as abstract data, as independent of || their representation as possible. Although an implementation of Scheme || may use many different representations for numbers, this should not be || apparent to a casual programmer writing simple programs. Whether scheme achieves all these laudable and lofty goals of representation independence, genuine mathematical subsetting (unlike the usual programming story where float and int are disjoint) etc, I will along with Marko say: ?Cant say if it has turned out practicable? Practicability has of course many variables floating point h/w induces floating point languages perpetuates the h/w perpetuates the languages? etc Are viable alternatives possible?? Dunno? From rosuav at gmail.com Mon Jul 18 06:15:10 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jul 2016 20:15:10 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <877fcjcllf.fsf@elektro.pacujo.net> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> Message-ID: On Mon, Jul 18, 2016 at 8:00 PM, Marko Rauhamaa wrote: > Python programmers (among others) frequently run into issues with > surprising results in floating-point arithmetics. For better or worse, > Scheme has tried to abstract the concept. You don't need to explain the > ideas of IEEE 64-bit floating-point numbers or tie the hands of the > implementation. Instead, what you have is "reliable" arithmetics and > "best-effort" arithmetics, a bit like TCP is "reliable" and UDP is > "best-effort". The problem with that is that failing to explain IEEE floating point and just calling it "inexact" scares people off unnecessarily. I've seen a lot of very intelligent people who think that you should never compare floats with the == operator, because floats randomly introduce "inaccuracy". And then you get these sorts of functions: EPSILON = 0.000001 # Adjust to control numeric accuracy def is_equal(f1, f2, epsilon=EPSILON): if abs(f1) > abs(f2): f1, f2 = f2, f1 return abs(f2-f1) < f1*epsilon and interminable debates about how to pick an epsilon, whether it should be relative to the smaller value (as here) or the larger (use f2 instead), or maybe should be an absolute value, or maybe it should be relative to the largest/smallest value that was ever involved in the calculation, or........ Floating point numbers are a representation of real numbers that involves a certain amount of precision. They're ultimately no different from grade-school arithmetic where you round stuff off so 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. Explain what they REALLY do and how they work, and you'll find they're not so scary. ChrisA From rustompmody at gmail.com Mon Jul 18 06:24:31 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 18 Jul 2016 03:24:31 -0700 (PDT) Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> Message-ID: <402d8e8a-6acf-44e8-99e2-fa09da10d7bc@googlegroups.com> On Monday, July 18, 2016 at 3:45:26 PM UTC+5:30, Chris Angelico wrote: > On Mon, Jul 18, 2016 at 8:00 PM, Marko Rauhamaa wrote: > > Python programmers (among others) frequently run into issues with > > surprising results in floating-point arithmetics. For better or worse, > > Scheme has tried to abstract the concept. You don't need to explain the > > ideas of IEEE 64-bit floating-point numbers or tie the hands of the > > implementation. Instead, what you have is "reliable" arithmetics and > > "best-effort" arithmetics, a bit like TCP is "reliable" and UDP is > > "best-effort". > > The problem with that is that failing to explain IEEE floating point > and just calling it "inexact" scares people off unnecessarily. I've > seen a lot of very intelligent people who think that you should never > compare floats with the == operator, because floats randomly introduce > "inaccuracy". And then you get these sorts of functions: > > EPSILON = 0.000001 # Adjust to control numeric accuracy > def is_equal(f1, f2, epsilon=EPSILON): > if abs(f1) > abs(f2): > f1, f2 = f2, f1 > return abs(f2-f1) < f1*epsilon > > and interminable debates about how to pick an epsilon, whether it > should be relative to the smaller value (as here) or the larger (use > f2 instead), or maybe should be an absolute value, or maybe it should > be relative to the largest/smallest value that was ever involved in > the calculation, or........ > I dont know what point you are trying to make Here is behavior. Should one use == ?? Python 2.7.11+ (default, Apr 17 2016, 14:00:29) [GCC 5.3.1 20160413] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> .1+.1+.1 == .3 False EPSILON = 0.000001 # Adjust to control numeric accuracy def is_equal(f1, f2, epsilon=EPSILON): if abs(f1) > abs(f2): f1, f2 = f2, f1 return abs(f2-f1) < f1*epsilon >>> ... ... ... ... >>> is_equal(.1+.1+.1, .3) True >>> From rosuav at gmail.com Mon Jul 18 06:37:23 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Jul 2016 20:37:23 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <402d8e8a-6acf-44e8-99e2-fa09da10d7bc@googlegroups.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <402d8e8a-6acf-44e8-99e2-fa09da10d7bc@googlegroups.com> Message-ID: On Mon, Jul 18, 2016 at 8:24 PM, Rustom Mody wrote: > I dont know what point you are trying to make > Here is behavior. Should one use == ?? > > Python 2.7.11+ (default, Apr 17 2016, 14:00:29) > [GCC 5.3.1 20160413] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> .1+.1+.1 == .3 > False > > EPSILON = 0.000001 # Adjust to control numeric accuracy > def is_equal(f1, f2, epsilon=EPSILON): > if abs(f1) > abs(f2): > f1, f2 = f2, f1 > return abs(f2-f1) < f1*epsilon >>>> ... ... ... ... > >>>> is_equal(.1+.1+.1, .3) > True >>>> Sure, simple equality hasn't given you an "intuitive" result - but that's because your source code is in decimal. So you need to properly understand it. If you work with something that can be represented precisely in binary, you have no problems with equality: >>> 7/4 + 9/4 + 11/4 + 13/4 == 10 True It's only the repeating values that have that problem. And if you disassemble your example, it's obvious why you get False: >>> dis.dis(lambda: .1+.1+.1 == .3) 1 0 LOAD_CONST 4 (0.30000000000000004) 2 LOAD_CONST 2 (0.3) 4 COMPARE_OP 2 (==) 6 RETURN_VALUE Of course those two values aren't the same. And it'd be just as obvious if you looked at them in binary. It'd look like this in decimal: 0.6667 + 0.6667 + 0.6667 == 2.0 Well, duh, all those intermediate values are rounded up, so you're getting the sum of the rounding, and of course it's not equal. That's why you need to get some comprehension of floating-point and how it *really* functions. ChrisA From marko at pacujo.net Mon Jul 18 07:38:59 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Jul 2016 14:38:59 +0300 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> Message-ID: <8737n7ch0s.fsf@elektro.pacujo.net> 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... Scheme, though doesn't force the implementation to use binary. It could use trinary or sexagesimal for all Scheme cares. The application shouldn't care, either. Marko From __peter__ at web.de Mon Jul 18 08:58:17 2016 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 Jul 2016 14:58:17 +0200 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <8737n7ch0s.fsf@elektro.pacujo.net> Message-ID: 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 already have one nibble and a carry bit, and it didn't help... > > Scheme, though doesn't force the implementation to use binary. It could > use trinary or sexagesimal for all Scheme cares. The application > shouldn't care, either. > > > Marko From ethan at stoneleaf.us Mon Jul 18 09:10:08 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 18 Jul 2016 06:10:08 -0700 Subject: can't add variables to instances of built-in classes In-Reply-To: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> Message-ID: <578CD530.5090702@stoneleaf.us> On 07/17/2016 04:50 AM, Wilson Ong wrote: >> Use this feature sparingly, only when you know that there are going to be >> many (millions rather than thousands) of Test instances. > > Why use it sparingly? Is it for extensibility? What if I'm pretty sure that > my class is going to have exactly these attributes only? One of the very nice things about Python is being able to fiddle with objects, both for debugging and for extending. One of the ways that's accomplished is by adding attributes to instances, but when __slots__ is defined that ability is lost, which can make using/debugging those types of objects harder. __slots__ is a memory optimization, and like most optimazations you shouldn't use it until you know you need it. -- ~Ethan~ From random832 at fastmail.com Mon Jul 18 09:25:02 2016 From: random832 at fastmail.com (Random832) Date: Mon, 18 Jul 2016 09:25:02 -0400 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <85r3arsgd0.fsf@benfinney.id.au> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <85r3arsgd0.fsf@benfinney.id.au> Message-ID: <1468848302.3478533.669441217.49D14390@webmail.messagingengine.com> On Mon, Jul 18, 2016, at 00:46, Ben Finney wrote: > What is ?those?? The measurement is imprecise, the observations are > inexact. > > It makes no sense to say that a number is inexact. Exactness is not a > property of a number. There's no reason it shouldn't be a property of an object of a numeric type available in a programming environment though. From random832 at fastmail.com Mon Jul 18 09:32:19 2016 From: random832 at fastmail.com (Random832) Date: Mon, 18 Jul 2016 09:32:19 -0400 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <4a5bcb6a-6fc9-4c60-a24c-0c2dc3ffcb19@googlegroups.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <4a5bcb6a-6fc9-4c60-a24c-0c2dc3ffcb19@googlegroups.com> Message-ID: <1468848739.3480190.669444305.44E020B8@webmail.messagingengine.com> On Mon, Jul 18, 2016, at 01:37, Rustom Mody wrote: > The INTENTION is that in addition to capturing the usual number tower > ? ? ? ? ? (or parts therefore) Well, ?. You hardly ever see representations of numbers that are in ?-?. > scheme also captures ORTHOGONALLY (word in the docs) the (in)exactness > attribute > > In the realization, the designers need to (over)load these different > attributes onto numeric constants. So the ruse chosen is that fraction- > constants by default are exact Decimal constants are inexact And one > can override any of these by suitable a function [At least that's my > understanding] The other thing you're missing is that implementations are free to choose any representation they want (such as an IEEE binary float, or a rational of bounded denominator) for inexact numbers, no matter how they were written, because they're not required to preserve the exact value. The fact that an implementation *could* also use an IEEE binary float to represent an exact rational number whose denominator happens to be power of two is immaterial to this discussion. It's not required to actually be "orthogonal" in the sense that you're imagining - i.e. being able to have inexact numbers whose machine representations are big integers, big rationals, etc. An implementation could choose to represent *all* inexact numbers as floats. From rapzak at gmail.com Mon Jul 18 11:05:25 2016 From: rapzak at gmail.com (Kasper Jepsen) Date: Mon, 18 Jul 2016 08:05:25 -0700 (PDT) Subject: COM Server - COMTYPES / PYTHONCOM Message-ID: Hello all, I have some major problems with something i am not good at :( I have come to a situation where i have to add a COM server in my python code the get access to it from Labview Teststand. Firs i have tried with pythoncom/wincom and got it almost working, it registered and i could look it up in the windows COM data list. But this combination do not register coclasses: Coclasses are not registered (that is, RegisterTypeLib does not write any values to the CLSID key of the coclass). http://docs.activestate.com/activepython/2.6/pywin32/pythoncom__RegisterTypeLib_meth.html IDL File: http://pastebin.com/WGCMmzHv And here the code: http://pastebin.com/44t45tPj my reference: https://chromium.googlesource.com/chromium/deps/python_26/+/cd4a3da8f0f0806bec98a40d80484f2362908250/Lib/site-packages/win32com/test/pippo_server.py --------------------------------------------------------------------- Then i started by using COMTYPES, but this do not at all register into the COM catalog on windows - both solutions i can connect to from another python. here is my code - IDL is the same. http://pastebin.com/ke5V5ZbY How do i continue so i can use this server from Teststand or any other windows program?? I really hope some can give me an example or help me in what is wrong - i think it is quite close... Thank you From ian.g.kelly at gmail.com Mon Jul 18 11:25:25 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 18 Jul 2016 09:25:25 -0600 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jul 18, 2016 at 3:29 AM, Steven D'Aprano wrote: > On Monday 18 July 2016 14:16, Rustom Mody wrote: >> In short one could think of inexact and exact ? in scheme's intended >> semantics ? as better called scientific (or science-ic) and mathematic >> numbers. > > I don't think so. "Science" uses both experimentally-derived numbers (e.g. G, > c, the mass of the electron) and numbers known exactly (?2, e, ?). Off-topic, c being a fundamental constant is actually in the latter category. Its *exact* value is 299792458 m/s. The length of the meter, on the other hand, is defined as the distance traveled by light in a vacuum in 1/299792458 seconds and is subject to the precision of measurements. From marko at pacujo.net Mon Jul 18 11:40:10 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Jul 2016 18:40:10 +0300 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87d1mbrm3p.fsf@elektro.pacujo.net> Ian Kelly : > Off-topic, c being a fundamental constant is actually in the latter > category. Its *exact* value is 299792458 m/s. > > The length of the meter, on the other hand, is defined as the distance > traveled by light in a vacuum in 1/299792458 seconds and is subject to > the precision of measurements. Since both c and the second are exact magnitudes, so is the meter. The second [...] is quantitatively defined in terms of exactly 9,192,631,770 periods of a certain frequency of radiation from the caesium atom: a so-called atomic clock. Marko From marko at pacujo.net Mon Jul 18 11:55:59 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Jul 2016 18:55:59 +0300 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <87d1mbrm3p.fsf@elektro.pacujo.net> Message-ID: <877fcjrldc.fsf@elektro.pacujo.net> Marko Rauhamaa : > Ian Kelly : >> Off-topic, c being a fundamental constant is actually in the latter >> category. Its *exact* value is 299792458 m/s. >> >> The length of the meter, on the other hand, is defined as the distance >> traveled by light in a vacuum in 1/299792458 seconds and is subject to >> the precision of measurements. > > Since both c and the second are exact magnitudes, so is the meter. > > The second [...] is quantitatively defined in terms of exactly > 9,192,631,770 periods of a certain frequency of radiation from the > caesium atom: a so-called atomic clock. > Which would became immediately apparent if you programmed in Scheme. One meter is equal to the wavelength of said magnitude times: 9192631770/299792458 ==> 656616555/21413747 (exact? 9192631770/299792458) ==> #t Marko From ian.g.kelly at gmail.com Mon Jul 18 13:13:08 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 18 Jul 2016 11:13:08 -0600 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <877fcjrldc.fsf@elektro.pacujo.net> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <87d1mbrm3p.fsf@elektro.pacujo.net> <877fcjrldc.fsf@elektro.pacujo.net> Message-ID: On Mon, Jul 18, 2016 at 9:55 AM, Marko Rauhamaa wrote: > Marko Rauhamaa : > >> Ian Kelly : >>> Off-topic, c being a fundamental constant is actually in the latter >>> category. Its *exact* value is 299792458 m/s. >>> >>> The length of the meter, on the other hand, is defined as the distance >>> traveled by light in a vacuum in 1/299792458 seconds and is subject to >>> the precision of measurements. >> >> Since both c and the second are exact magnitudes, so is the meter. >> >> The second [...] is quantitatively defined in terms of exactly >> 9,192,631,770 periods of a certain frequency of radiation from the >> caesium atom: a so-called atomic clock. >> > > Which would became immediately apparent if you programmed in Scheme. One > meter is equal to the wavelength of said magnitude times: Okay, so how is that wavelength defined? If you needed to mark a meter stick, and all you had was the definition of c and the second, how would you do it without measuring anything? From marko at pacujo.net Mon Jul 18 14:58:23 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 18 Jul 2016 21:58:23 +0300 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <87d1mbrm3p.fsf@elektro.pacujo.net> <877fcjrldc.fsf@elektro.pacujo.net> Message-ID: <87wpkircxc.fsf@elektro.pacujo.net> Ian Kelly : > Okay, so how is that wavelength defined? > > If you needed to mark a meter stick, and all you had was the > definition of c and the second, how would you do it without measuring > anything? I wouldn't be measuring a meter stick. To measure, say, the height of a desk, I would bring in some caesium and shine its radiation from the desk level down to the floor. By counting the ebbs and flows of the radiation as it leaves the nozzle and strikes the wooden floor I make the approximage height measurement. However, I know *exactly* how long a meter is without making a measurement. Marko From alister.ware at ntlworld.com Mon Jul 18 16:20:49 2016 From: alister.ware at ntlworld.com (alister) Date: Mon, 18 Jul 2016 20:20:49 GMT Subject: Request for help Message-ID: On Mon, 18 Jul 2016 12:50:04 +0300, Eric kago wrote: > Hi Pythoners > > I need help in understanding hoe to put up the code to the following > command > > > - Create a constructor that takes in an integer and assigns this to a > `balance` property > > > > > Regards, > > Eric Kago +254(0)714249373 Nairobi Kenya I suggest next time you stay awake during lessons. -- I treasure this strange combination found in very few persons: a fierce desire for life as well as a lucid perception of the ultimate futility of the quest. -- Madeleine Gobeil From lawrencedo99 at gmail.com Mon Jul 18 17:48:01 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 18 Jul 2016 14:48:01 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> Message-ID: <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> On Monday, July 18, 2016 at 7:39:09 PM UTC+12, Peter Otten wrote: > Lawrence D?Oliveiro wrote: > >> I find __slots__ very useful. I have them right through my Qahirah classes >> , for example. > > Or is there something I didn't think of that makes them useful for you? When you have lots of read/write properties, I find __slots__ to be a good idea. From ben+python at benfinney.id.au Mon Jul 18 20:21:01 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 19 Jul 2016 10:21:01 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <85r3arsgd0.fsf@benfinney.id.au> <1468848302.3478533.669441217.49D14390@webmail.messagingengine.com> Message-ID: <85mvlesck2.fsf@benfinney.id.au> Random832 writes: > On Mon, Jul 18, 2016, at 00:46, Ben Finney wrote: > > What is ?those?? The measurement is imprecise, the observations are > > inexact. > > > > It makes no sense to say that a number is inexact. Exactness is not > > a property of a number. > > There's no reason it shouldn't be a property of an object of a numeric > type available in a programming environment though. Yes. Because the object is not a number, it is a representation of a number :-) -- \ ?Truth is stranger than fiction, but it is because fiction is | `\ obliged to stick to possibilities, truth isn't.? ?Mark Twain, | _o__) _Following the Equator_ | Ben Finney From rustompmody at gmail.com Mon Jul 18 20:36:39 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 18 Jul 2016 17:36:39 -0700 (PDT) Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <87wpkircxc.fsf@elektro.pacujo.net> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <87d1mbrm3p.fsf@elektro.pacujo.net> <877fcjrldc.fsf@elektro.pacujo.net> <87wpkircxc.fsf@elektro.pacujo.net> Message-ID: On Tuesday, July 19, 2016 at 12:28:36 AM UTC+5:30, Marko Rauhamaa wrote: > Ian Kelly : > > > Okay, so how is that wavelength defined? > > > > If you needed to mark a meter stick, and all you had was the > > definition of c and the second, how would you do it without measuring > > anything? > > I wouldn't be measuring a meter stick. To measure, say, the height of a > desk, I would bring in some caesium and shine its radiation from the > desk level down to the floor. By counting the ebbs and flows of the > radiation as it leaves the nozzle and strikes the wooden floor I make > the approximage height measurement. > > However, I know *exactly* how long a meter is without making a > measurement. I recollect ? school physics textbook so sorry no link ? that in the Newton gravitation law f = -GMm/r? there was a discussion about the exponent of r ie 2 And that to some 6 decimal places it had been verified that it was actually 2.000002 I dont remember all the details Just that something so obviously to a layman mathematic/analytic as 2 for a physicist may be something calling for experimental verification ie synthetic/scienceic: http://plato.stanford.edu/entries/analytic-synthetic/ From lawrencedo99 at gmail.com Mon Jul 18 22:53:59 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Mon, 18 Jul 2016 19:53:59 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> Message-ID: <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> On Tuesday, July 19, 2016 at 11:12:52 AM UTC+12, bream... at gmail.com wrote: > > On Monday, July 18, 2016 at 10:48:15 PM UTC+1, Lawrence D?Oliveiro wrote: >> >> >> When you have lots of read/write properties, I find __slots__ to be a good >> idea. > > Please explain why, thank you. I was trying something like ctx.dashes = ((0.1, 0.03, 0.03, 0.03), 0) and wondering why it wasn?t working... From steve at pearwood.info Mon Jul 18 23:03:52 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jul 2016 13:03:52 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> Message-ID: <578d989a$0$1621$c3e8da3$5496439d@news.astraweb.com> On Tue, 19 Jul 2016 01:25 am, Ian Kelly wrote: > On Mon, Jul 18, 2016 at 3:29 AM, Steven D'Aprano > wrote: >> On Monday 18 July 2016 14:16, Rustom Mody wrote: >>> In short one could think of inexact and exact ? in scheme's intended >>> semantics ? as better called scientific (or science-ic) and mathematic >>> numbers. >> >> I don't think so. "Science" uses both experimentally-derived numbers >> (e.g. G, c, the mass of the electron) and numbers known exactly (?2, e, >> ?). > > Off-topic, c being a fundamental constant is actually in the latter > category. Its *exact* value is 299792458 m/s. > > The length of the meter, on the other hand, is defined as the distance > traveled by light in a vacuum in 1/299792458 seconds and is subject to > the precision of measurements. You're right, of course, but that's a post-facto redefinition of both c and the metre. Historically, the metre was defined first, then people spent a lot of time measuring the speed of light (I believe it was Galileo who made the first known attempt). Eventually, physicists decided that it was easier to declare by fiat that c = 299792458 m/s EXACTLY, and use that definition to imply a standard metre, rather than keep a standard metre and use that to measure c. That makes it a matter of convenience and practicality rather than purity. It also reflects the current theoretical paradigm that sees c as a constant and both distance and time subject to distortion. Had special and general relativity been disproven, or never invented, it's unlikely that we would have declared c to be more fundamental than distance. (We haven't declared that G is exactly such-and-such a value, and used that to define the kilogram.) -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Mon Jul 18 23:06:39 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jul 2016 13:06:39 +1000 Subject: Request for help References: Message-ID: <578d9940$0$1621$c3e8da3$5496439d@news.astraweb.com> On Tue, 19 Jul 2016 06:20 am, alister wrote: > I suggest next time you stay awake during lessons. That's an uncalled for nasty comment. You don't know the O.P's issues or why he is having difficulty. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Mon Jul 18 23:16:32 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jul 2016 13:16:32 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <87d1mbrm3p.fsf@elektro.pacujo.net> <877fcjrldc.fsf@elektro.pacujo.net> <87wpkircxc.fsf@elektro.pacujo.net> Message-ID: <578d9b91$0$22140$c3e8da3$5496439d@news.astraweb.com> On Tue, 19 Jul 2016 10:36 am, Rustom Mody wrote: > I recollect ? school physics textbook so sorry no link ? > that in the Newton gravitation law > f = -GMm/r? > > there was a discussion about the exponent of r ie 2 > And that to some 6 decimal places it had been verified that it was > actually 2.000002 Because gravitational forces are so weak, it is very difficult to experimentally distinguish (say) an exponent of 1.999999 from 2.000002 from 2 exactly. Most physicists would say that an experimental result of 2.000002 is pretty good confirmation that the theoretical power of 2 is correct. Only a very few would think that the experiment was evidence that both Newtonian and Einsteinian gravitational theory is incorrect. (Newton, for obvious reasons; but also general relativity, since Newton's law can be derived from the "low mass/large distance" case of general relativity.) But it's an interesting hypothetical: what if the power wasn't 2 exactly? -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Mon Jul 18 23:21:32 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jul 2016 13:21:32 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <85r3arsgd0.fsf@benfinney.id.au> <1468848302.3478533.669441217.49D14390@webmail.messagingengine.com> Message-ID: <578d9cbd$0$22140$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Jul 2016 11:25 pm, Random832 wrote: > On Mon, Jul 18, 2016, at 00:46, Ben Finney wrote: >> What is ?those?? The measurement is imprecise, the observations are >> inexact. >> >> It makes no sense to say that a number is inexact. Exactness is not a >> property of a number. > > There's no reason it shouldn't be a property of an object of a numeric > type available in a programming environment though. Yes, there is a reason. Objects of numeric types in programming environments are intended to model numbers. Since numbers are not "exact" or "inexact" (but only calculations), then adding an "exact" attribute to the number makes as much sense as adding attributes "colour", "weight", or "flavour". -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Mon Jul 18 23:26:13 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 18 Jul 2016 20:26:13 -0700 (PDT) Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <578d9b91$0$22140$c3e8da3$5496439d@news.astraweb.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <87d1mbrm3p.fsf@elektro.pacujo.net> <877fcjrldc.fsf@elektro.pacujo.net> <87wpkircxc.fsf@elektro.pacujo.net> <578d9b91$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <05d3a70a-865f-416a-9915-447c475ee67c@googlegroups.com> On Tuesday, July 19, 2016 at 8:46:44 AM UTC+5:30, Steven D'Aprano wrote: > On Tue, 19 Jul 2016 10:36 am, Rustom Mody wrote: > > > I recollect ? school physics textbook so sorry no link ? > > that in the Newton gravitation law > > f = -GMm/r? > > > > there was a discussion about the exponent of r ie 2 > > And that to some 6 decimal places it had been verified that it was > > actually 2.000002 > > Because gravitational forces are so weak, it is very difficult to > experimentally distinguish (say) an exponent of 1.999999 from 2.000002 from > 2 exactly. > > Most physicists would say that an experimental result of 2.000002 is pretty > good confirmation that the theoretical power of 2 is correct. Only a very > few would think that the experiment was evidence that both Newtonian and > Einsteinian gravitational theory is incorrect. Yes this was ? if memory is right ? the conclusion, viz.: Experimentally it looks like 2.000002 (or whatever) This is as good as we can measure So concluding its 2 seems to be reasonable with that 0.000002 relegated to experimental error Nevertheless my main point was that such a math (aka analytic to a layman) looking entity like 2, may for a physicist be a quantity for synthetic verification > > (Newton, for obvious reasons; but also general relativity, since Newton's > law can be derived from the "low mass/large distance" case of general > relativity.) > > But it's an interesting hypothetical: what if the power wasn't 2 exactly? May be related to the margin of error for G being quite high From steve at pearwood.info Mon Jul 18 23:42:43 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 19 Jul 2016 13:42:43 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> Message-ID: <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Jul 2016 08:15 pm, Chris Angelico wrote: > On Mon, Jul 18, 2016 at 8:00 PM, Marko Rauhamaa wrote: >> Python programmers (among others) frequently run into issues with >> surprising results in floating-point arithmetics. For better or worse, >> Scheme has tried to abstract the concept. You don't need to explain the >> ideas of IEEE 64-bit floating-point numbers or tie the hands of the >> implementation. Instead, what you have is "reliable" arithmetics and >> "best-effort" arithmetics, a bit like TCP is "reliable" and UDP is >> "best-effort". > > The problem with that is that failing to explain IEEE floating point > and just calling it "inexact" scares people off unnecessarily. I've > seen a lot of very intelligent people who think that you should never > compare floats with the == operator, because floats randomly introduce > "inaccuracy". Yes, this. "Never compare floats for equality" is a pernicious myth that won't die. > And then you get these sorts of functions: > > EPSILON = 0.000001 # Adjust to control numeric accuracy > def is_equal(f1, f2, epsilon=EPSILON): > if abs(f1) > abs(f2): > f1, f2 = f2, f1 > return abs(f2-f1) < f1*epsilon > > and interminable debates about how to pick an epsilon, whether it > should be relative to the smaller value (as here) or the larger (use > f2 instead), or maybe should be an absolute value, or maybe it should > be relative to the largest/smallest value that was ever involved in > the calculation, or........ Your code is buggy. Consider: py> is_equal(-1.0, -1.0) False > Floating point numbers are a representation of real numbers that > involves a certain amount of precision. They're ultimately no > different from grade-school arithmetic where you round stuff off so > 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. Well, kinda... yes, ultimately deep down you're right. There's nothing mysterious about floats. The lack of fundamental properties associativity: (a+b)+c = a+(b+c) and distributivity: a?(b+c) = a?b + a?c are due to numbers being recorded in finite precision, which means that some calculations are inexact. But the *consequences* of that simple fact are quite profound, and difficult. Earlier you mentioned "interminable debates about how to pick an epsilon", but the reason for that is that it is really, really hard to pick an epsilon in any systematic, objective way. In the statistics module, I have run into this problem. Where possible, and surprisingly often, I can test for exact equality. For example, here are a couple of tests for geometric mean: def test_multiply_data_points(self): # Test multiplying every data point by a constant. c = 111 data = [3.4, 4.5, 4.9, 6.7, 6.8, 7.2, 8.0, 8.1, 9.4] expected = self.func(data)*c result = self.func([x*c for x in data]) self.assertEqual(result, expected) def test_doubled_data(self): # Test doubling data from [a,b...z] to [a,a,b,b...z,z]. data = [random.uniform(1, 500) for _ in range(1000)] expected = self.func(data) actual = self.func(data*2) self.assertApproxEqual(actual, expected, rel=1e-13) I didn't hand-tune the constants in test_multiply_data_points, but nor can I guarantee that if you replace them with other constants of similar magnitude the assertEqual test will still be appropriate. In the test_doubled_data case, rounding errors accumulate faster, and cancel less often, so I use an inexact comparison. Why do I check for a relative error of 1e-13, rather than 1e-12 or 2.5e-14? *shrug* I can't give an objective reason for it. It just seems right to me: if the relative error was much bigger, I'd say that the geometric mean function was too inaccurate. If it were much smaller, it's too hard for me to have the tests pass. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Tue Jul 19 00:58:15 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 18 Jul 2016 21:58:15 -0700 (PDT) Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, July 19, 2016 at 9:12:57 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 18 Jul 2016 08:15 pm, Chris Angelico wrote: > > > On Mon, Jul 18, 2016 at 8:00 PM, Marko Rauhamaa wrote: > >> Python programmers (among others) frequently run into issues with > >> surprising results in floating-point arithmetics. For better or worse, > >> Scheme has tried to abstract the concept. You don't need to explain the > >> ideas of IEEE 64-bit floating-point numbers or tie the hands of the > >> implementation. Instead, what you have is "reliable" arithmetics and > >> "best-effort" arithmetics, a bit like TCP is "reliable" and UDP is > >> "best-effort". > > > > The problem with that is that failing to explain IEEE floating point > > and just calling it "inexact" scares people off unnecessarily. I've > > seen a lot of very intelligent people who think that you should never > > compare floats with the == operator, because floats randomly introduce > > "inaccuracy". > > Yes, this. "Never compare floats for equality" is a pernicious myth that > won't die. In this context, I asked Chris: > I dont know what point you are trying to make > Here is behavior. Should one use == ?? As often happens between me and Chris I ask a ?why? (in this case ?what?) question. And he gives a ?how? answer So I again ask: You say ?"Never compare floats for equality" is a pernicious myth? Given that for Chris? is_equal we get is_equal(.1+.1+.1, .3) is True whereas for python builtin == its False What (non)myth do you suggest for replacement? [Note I am not arguing for the goodness of his is_equal] Analogy: Mutable default parameters are a source of problem and confusion. No A says. One can use them to simulate statics No B says No problem as long as you make sure there is no mutation to the mutable, either inside or outside the function. Sure thats all true. However "Module-globals? is a simpler answer than A And ?DON?T? is simpler than B So awaiting your preferred myth-ology? From gheskett at shentel.net Tue Jul 19 01:22:55 2016 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 19 Jul 2016 01:22:55 -0400 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <578d9b91$0$22140$c3e8da3$5496439d@news.astraweb.com> References: <578d9b91$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201607190122.55105.gheskett@shentel.net> On Monday 18 July 2016 23:16:32 Steven D'Aprano wrote: > On Tue, 19 Jul 2016 10:36 am, Rustom Mody wrote: > > I recollect ? school physics textbook so sorry no link ? > > that in the Newton gravitation law > > f = -GMm/r? > > > > there was a discussion about the exponent of r ie 2 > > And that to some 6 decimal places it had been verified that it was > > actually 2.000002 > > Because gravitational forces are so weak, it is very difficult to > experimentally distinguish (say) an exponent of 1.999999 from 2.000002 > from 2 exactly. > > Most physicists would say that an experimental result of 2.000002 is > pretty good confirmation that the theoretical power of 2 is correct. > Only a very few would think that the experiment was evidence that both > Newtonian and Einsteinian gravitational theory is incorrect. > > (Newton, for obvious reasons; but also general relativity, since > Newton's law can be derived from the "low mass/large distance" case of > general relativity.) > > But it's an interesting hypothetical: what if the power wasn't 2 > exactly? > I do not believe it is. The theory of relativity says that the faster you are going, the more massive you become. Ergo the rate of the acceleration will decrease as the mass builds up. But the speeds most of us deal with are so close to at rest that we do not realize in the everyday world around us, that this does apply at the speeds you throw that ball while juggling 3 of them. The effect is quite minimal at our everyday speeds, but there is not a set point where it kicks in, its always there. Its just that the difference at everyday speeds, is likely a few hundred digits to the right of the decimal point. Now, trade those 1 lb balls in on a few quintillion electrons, enough to account for 5.3 amps of current thru a klystron amplifier tube, and the acceleration voltage speeding the electrons along is 20,000 volts. That beam of electrons is trucking right along at a measurable fraction of c speed. Its also dumping something more than 100KW into the cooling water flowing thru the bottom of the tube where the beam lands and is absorbed. This amplifier does not operate by varying the current like a normal vacuum tube, it constant current. It is a capacitatively driven tube, and the power comes back out by being capacitatively coupled from the electron beam. How many of you can remember the audio buzz in the UHF channels tv sound 20 years ago? So I am going to tell you how that buzz became part of the UHF landscape for so many years, so bear with me as I have a story to tell. This klystron amplifier, a new one of which was north of $125,000 in the 1970's when I learned about them, is a long tube, around 5 feet long with alternating sections of copper tubeing and ceramic insulators separating the copper sections. Typically 4 ceramic sections, each of which was sealed to a section of copper equiped with contact rings on each end of the copper sections. A tunable box cavity connected the copper sections together, bridging the ceramic spacer, so that when the tube was "dressed" with these cavity's, and lowered into its focusing magnet, (2200 lbs) you could feed about 1 watt of signal into the top cavity, which either retarded the velocity of the beam slightly, or accellerated it a bit. The beam then passed out of that cavity and on into the next one, tuned a couple megahertz lower, then passed thru the third cavity normally tuned about 4.2 megahertz higher. Each cavity it passed thru reinforced this small velocity change until one could visualize the electrons traveling in little balls by the time it enters the last cavity, and this cavity has a coupling loop to extract the amplified signal, 30 kilowatts of it, all because that last cavity is ringing like a bell because of the capacitative coupling between these bunched up electrons and the cavity. The buzz that was so annoying is directly related to the relativistic effects being modified by the video signal. The electrons gain more mass as they speed up, so the speed up does not match the slowdown because they lose mass thereby slowing more, so the net effect is that the tube gets longer at the high power levels of the synch signal, inventing an FM signal that is not there in the drive. Then, since most tv transmitters before digital were actually two transmitters, one for the video, and one for the audio, and the audio ran at a constant power level since it was an FM signal, so the aural was not similarly effected. The old tv's also used the difference frequency, here in the US of 4.5 megahertz as their aural detection system. So this FM component to the visual became mixed with the unaffected audio, injecting this darned buzz into the audio IN your tv. And relativity, in the form of e=mv2 was the culprit. Not even the FCC had that figured out. I had that pointed out to me by a blown water pump breaker, and the lack of cooling water blew the bottom out of the collector bucket on the visual tube. About 50 milliseconds after the pump went locked rotor from the phase failure. After replacing the breaker, I wheeled the aural tube out of its cubicle and put it into the visual transmitter and tuned it up for picture service, old tube, got about 80% power out of it. Then I rigged a cable of aural drive over to the visual and fed about 100 milliwatts of aural drive just to get back on the air while Varian was building me a new klystron which takes several weeks. At home that night, checking to see if the viewers might notice, the pix looked ok but something told me to crank up the sound. Zero buzz, because both signals were being amplified in the same tube, and subjected to identical amounts of this distortion, there was no difference to be detected in the tv itself. The distortion was absolutely in lock step and totally inaudible to the tv's. With both tubes running normally, that buzz was only down about 53db at best. So relativity applies, even to the baseball being thrown by a little leager. We just do not have the precision to measure it when the effect is hundreds of digits to the right of the decimal point. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From rosuav at gmail.com Tue Jul 19 01:27:24 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jul 2016 15:27:24 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 19, 2016 at 1:42 PM, Steven D'Aprano wrote: >> And then you get these sorts of functions: >> >> EPSILON = 0.000001 # Adjust to control numeric accuracy >> def is_equal(f1, f2, epsilon=EPSILON): >> if abs(f1) > abs(f2): >> f1, f2 = f2, f1 >> return abs(f2-f1) < f1*epsilon >> >> and interminable debates about how to pick an epsilon, whether it >> should be relative to the smaller value (as here) or the larger (use >> f2 instead), or maybe should be an absolute value, or maybe it should >> be relative to the largest/smallest value that was ever involved in >> the calculation, or........ > > Your code is buggy. Consider: > > py> is_equal(-1.0, -1.0) > False Duh, I got the < and <= bug! Shows how easy it is to get this kind of function wrong. (Even more so, it shows how easy it is to get code wrong when you type straight into an email and never test it.) > Earlier you mentioned "interminable debates > about how to pick an epsilon", but the reason for that is that it is > really, really hard to pick an epsilon in any systematic, objective way. Yeah, and that's the problem. If you're working with some concept of measurement error, what you actually mean is that every number in your calculation is actually a range centered on that number; which means that "equality" really means "overlapping ranges". Epsilon-based equality is just that, only with a global epsilon instead of one that actually cares about the real error value. How can that NOT be doomed to failure? ChrisA From rosuav at gmail.com Tue Jul 19 01:30:24 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jul 2016 15:30:24 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jul 19, 2016 at 2:58 PM, Rustom Mody wrote: > Analogy: > Mutable default parameters are a source of problem and confusion. > > No A says. One can use them to simulate statics > > No B says No problem as long as you make sure there is no mutation to the mutable, either inside or outside the function. > > Sure thats all true. However > "Module-globals? is a simpler answer than A > And ?DON?T? is simpler than B > > So awaiting your preferred myth-ology? Preferred: Understand what's going on. Unless you're talking to a novice/student programmer (in which case "Oh, don't do that - ask me about it later when we're not busy fixing this problem" is a valid response), it's best that people understand what they're working with. ChrisA From crazyguyplaying13 at gmail.com Tue Jul 19 02:07:04 2016 From: crazyguyplaying13 at gmail.com (WePlayGames WeEnjoyIt) Date: Mon, 18 Jul 2016 23:07:04 -0700 (PDT) Subject: an error Message-ID: <175aeac6-b975-425b-b2b1-580a64ce0854@googlegroups.com> while True: for event in pygame.event.get(): if event.type==pygame.QUIT: pygame.quit() sys.exit() pygame1.blit(image1,(0,0)) print ("choose from 0-8") p1=int(input()) while p1>8 or p1<0 or list_b[p1]=="X" or list_b[p1]=="O": print ("wtf bro") p1=int(input()) list_b[p1]="X" if p1==0: pygame1.blit(image2,(31,36)) elif p1==1: pygame1.blit(image2,(90,36)) elif p1==2: pygame1.blit(image2,(143,36)) elif p1==3: pygame1.blit(image2,(31,90)) elif p1==4: pygame.blit(image2,(90,90)) elif p1==5: pygame1.blit(image2,(143,90)) elif p1==6: pygame1.blit(image2,(31,146)) elif p1==7: pygame1.blit(image2,(90,146)) elif p1==8: pygame1.blit(image2,(143,146)) total+=1 print ("choose from 0-8") p2=int(input()) while p2>8 or p2<0 or list_b[p2]=="X" or list_b[p2]=="O": print ("wtf bro") p2=int(input()) list_b[p2]=="O" if p2==0: pygame1.blit(image3,(31,36)) elif p2==1: pygame1.blit(image3,(90,36)) elif p2==2: pygame1.blit(image3,(143,36)) elif p2==3: pygame1.blit(image3,(31,90)) elif p2==4: pygame1.blit(image3,(90,90)) elif p2==5: pygame1.blit(image3,(143,90)) elif p2==6: pygame1.blit(image3,(31,146)) elif p2==7: pygam1e.blit(image3,(90,146)) elif p2==8: pygame1.blit(image3,(143,146) total+=1 fps=40 clockfps.tick(fps) pygame.display.update() the problem with this is that i get an syntax error at the very end at the TOTAL+=1 when i delete this it tells me that there is an error at the clockfps.tick(fps) thing what the heck is going on :p From rosuav at gmail.com Tue Jul 19 02:20:04 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jul 2016 16:20:04 +1000 Subject: an error In-Reply-To: <175aeac6-b975-425b-b2b1-580a64ce0854@googlegroups.com> References: <175aeac6-b975-425b-b2b1-580a64ce0854@googlegroups.com> Message-ID: On Tue, Jul 19, 2016 at 4:07 PM, WePlayGames WeEnjoyIt wrote: > the problem with this is that i get an syntax error at the very end at the TOTAL+=1 when i delete this it tells me that there is an error at the clockfps.tick(fps) thing what the heck is going on :p > When you get an error, Python gives you a very useful error message (and traceback, although that doesn't apply to syntax errors like this). Copy and paste that here. There are many possible syntax errors, and Python will tell you which one. ChrisA From ian.g.kelly at gmail.com Tue Jul 19 02:20:57 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 19 Jul 2016 00:20:57 -0600 Subject: an error In-Reply-To: <175aeac6-b975-425b-b2b1-580a64ce0854@googlegroups.com> References: <175aeac6-b975-425b-b2b1-580a64ce0854@googlegroups.com> Message-ID: On Tue, Jul 19, 2016 at 12:07 AM, WePlayGames WeEnjoyIt wrote: > pygame1.blit(image3,(143,146) This line is missing a closing parenthesis. From crazyguyplaying13 at gmail.com Tue Jul 19 02:26:57 2016 From: crazyguyplaying13 at gmail.com (WePlayGames WeEnjoyIt) Date: Mon, 18 Jul 2016 23:26:57 -0700 (PDT) Subject: an error In-Reply-To: References: <175aeac6-b975-425b-b2b1-580a64ce0854@googlegroups.com> Message-ID: <6c990c11-c4b5-4ee8-8ee9-488bfe56784d@googlegroups.com> ?? ?????, 19 ??????? 2016 - 9:20:20 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Tue, Jul 19, 2016 at 4:07 PM, WePlayGames WeEnjoyIt > wrote: > > the problem with this is that i get an syntax error at the very end at the TOTAL+=1 when i delete this it tells me that there is an error at the clockfps.tick(fps) thing what the heck is going on :p > > > > When you get an error, Python gives you a very useful error message > (and traceback, although that doesn't apply to syntax errors like > this). Copy and paste that here. There are many possible syntax > errors, and Python will tell you which one. > > ChrisA thanks chris for responding, it doesnt say anything else just syntax error it have seen this error again when im using the for loop and it seems like when i delete everything after total+=1 i get a different error called UNEXPECTED EOF WHILE PARSING From rosuav at gmail.com Tue Jul 19 02:32:19 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jul 2016 16:32:19 +1000 Subject: an error In-Reply-To: <6c990c11-c4b5-4ee8-8ee9-488bfe56784d@googlegroups.com> References: <175aeac6-b975-425b-b2b1-580a64ce0854@googlegroups.com> <6c990c11-c4b5-4ee8-8ee9-488bfe56784d@googlegroups.com> Message-ID: On Tue, Jul 19, 2016 at 4:26 PM, WePlayGames WeEnjoyIt wrote: > thanks chris for responding, it doesnt say anything else just syntax error > it have seen this error again when im using the for loop and it seems like when i delete everything after total+=1 i get a different error called UNEXPECTED EOF WHILE PARSING Are you sure it says nothing else? Copy and paste exactly what happens when you type "python3 yourgamename.py". Exactly what happens. ChrisA From crazyguyplaying13 at gmail.com Tue Jul 19 02:37:12 2016 From: crazyguyplaying13 at gmail.com (WePlayGames WeEnjoyIt) Date: Mon, 18 Jul 2016 23:37:12 -0700 (PDT) Subject: an error In-Reply-To: References: <175aeac6-b975-425b-b2b1-580a64ce0854@googlegroups.com> <6c990c11-c4b5-4ee8-8ee9-488bfe56784d@googlegroups.com> Message-ID: ?? ?????, 19 ??????? 2016 - 9:32:34 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Tue, Jul 19, 2016 at 4:26 PM, WePlayGames WeEnjoyIt > wrote: > > thanks chris for responding, it doesnt say anything else just syntax error > > it have seen this error again when im using the for loop and it seems like when i delete everything after total+=1 i get a different error called UNEXPECTED EOF WHILE PARSING > > Are you sure it says nothing else? Copy and paste exactly what happens > when you type "python3 yourgamename.py". > > Exactly what happens. > > ChrisA ITS OK the problem was solved i forgot to close the thingy like ian said but now i got more problems ( not errors however). like i know how to load and blit a picture in my pygame window but i dont know why it wont work in this code, like nothing is actually appearing in my screen. long story short what i want to happend is image1 to appear in but it doesnt From rosuav at gmail.com Tue Jul 19 02:45:01 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Jul 2016 16:45:01 +1000 Subject: an error In-Reply-To: References: <175aeac6-b975-425b-b2b1-580a64ce0854@googlegroups.com> <6c990c11-c4b5-4ee8-8ee9-488bfe56784d@googlegroups.com> Message-ID: On Tue, Jul 19, 2016 at 4:37 PM, WePlayGames WeEnjoyIt wrote: > ?? ?????, 19 ??????? 2016 - 9:32:34 ?.?. UTC+3, ? ??????? Chris Angelico ??????: >> On Tue, Jul 19, 2016 at 4:26 PM, WePlayGames WeEnjoyIt >> wrote: >> > thanks chris for responding, it doesnt say anything else just syntax error >> > it have seen this error again when im using the for loop and it seems like when i delete everything after total+=1 i get a different error called UNEXPECTED EOF WHILE PARSING >> >> Are you sure it says nothing else? Copy and paste exactly what happens >> when you type "python3 yourgamename.py". >> >> Exactly what happens. >> >> ChrisA > > ITS OK the problem was solved i forgot to close the thingy like ian said but now i got more problems ( not errors however). like i know how to load and blit a picture in my pygame window but i dont know why it wont work in this code, like nothing is actually appearing in my screen. long story short what i want to happend is image1 to appear in but it doesnt > It's important not just to solve your problem, but to learn *how* to solve problems. Learning to read tracebacks is essential to being a Python programmer. ChrisA From tjreedy at udel.edu Tue Jul 19 05:12:03 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 19 Jul 2016 05:12:03 -0400 Subject: an error In-Reply-To: <175aeac6-b975-425b-b2b1-580a64ce0854@googlegroups.com> References: <175aeac6-b975-425b-b2b1-580a64ce0854@googlegroups.com> Message-ID: On 7/19/2016 2:07 AM, WePlayGames WeEnjoyIt wrote: > pygame1.blit(image3,(143,146) If you type this line (including \n) into IDLE's Python-aware editor, it will notice that there is an open parenthesis for a function call and indent the next line to the space under the 'i' of image. This is because you either A) did not make a mistake and intend to type more before the closing parenthesis, and according to PEP 8, lined up with 'i' is the place to start, or B) you did make a mistake and should notice the indent as a signal. -- Terry Jan Reedy From steve at pearwood.info Tue Jul 19 12:31:52 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 20 Jul 2016 02:31:52 +1000 Subject: Request for help References: Message-ID: <578e55f9$0$1583$c3e8da3$5496439d@news.astraweb.com> On Mon, 18 Jul 2016 07:50 pm, Eric kago wrote: > Hi Pythoners > > I need help in understanding hoe to put up the code to the following > command Hi Eric, You might find that the "Tutor" mailing list is better for simple questions like this: https://mail.python.org/mailman/listinfo/tutor Remember, for help with home work, show the code you already have. > - Create a constructor that takes in an integer and assigns this to a > `balance` property Talking about a "constructor" means that you need to have a class. We define a class with the "class" keyword: class Myclass: pass To give it a constructor method, you need to use the __init__ method, or sometimes __new__. In this case, I think __init__ is what you want. Do you know how to define methods inside a class? Remember that __init__ is spelled with TWO underscores at the start and end. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From laurent.pointal at free.fr Tue Jul 19 13:24:49 2016 From: laurent.pointal at free.fr (Laurent Pointal) Date: Tue, 19 Jul 2016 19:24:49 +0200 Subject: an error References: <175aeac6-b975-425b-b2b1-580a64ce0854@googlegroups.com> Message-ID: <578e6261$0$23756$426a74cc@news.free.fr> WePlayGames WeEnjoyIt wrote: > elif p2==8: > pygame1.blit(image3,(143,146) <============= missing ) > total+=1 > fps=40 > clockfps.tick(fps) > pygame.display.update() > > the problem with this is that i get an syntax error at the very end at the > TOTAL+=1 when i delete this it tells me that there is an error at the > clockfps.tick(fps) thing what the heck is going on :p Someone else shows you the error. When you have a syntax error in a specific line (see printed traceback), it is common to have to look at previous lines to identify some open parenthesis, brackets, square brackets with missing close one. A+ Laurent. From lawrencedo99 at gmail.com Tue Jul 19 13:46:37 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 19 Jul 2016 10:46:37 -0700 (PDT) Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: References: <578d9b91$0$22140$c3e8da3$5496439d@news.astraweb.com> <201607190122.55105.gheskett@shentel.net> Message-ID: On Wednesday, July 20, 2016 at 12:07:25 AM UTC+12, Gene Heskett wrote: > This klystron amplifier, a new one of which was north of $125,000 in the > 1970's when I learned about them, is a long tube, around 5 feet long > with alternating sections of copper tubeing and ceramic insulators > separating the copper sections. Typically 4 ceramic sections, each of > which was sealed to a section of copper equiped with contact rings on > each end of the copper sections. A tunable box cavity connected the > copper sections together, bridging the ceramic spacer, so that when the > tube was "dressed" with these cavity's, and lowered into its focusing > magnet, (2200 lbs) you could feed about 1 watt of signal into the top > cavity... What is this ?watt? of which you speak? How much is that in foot-poundals per second? From edgargdcv at gmail.com Tue Jul 19 14:59:06 2016 From: edgargdcv at gmail.com (edgargdcv at gmail.com) Date: Tue, 19 Jul 2016 11:59:06 -0700 (PDT) Subject: python - handling HTTP requests asynchronously In-Reply-To: <59a499d5-13e1-4092-895f-34aca0827525@googlegroups.com> References: <59a499d5-13e1-4092-895f-34aca0827525@googlegroups.com> Message-ID: <7f6dcd1f-aeb6-4565-aa7e-b54d2b6fb274@googlegroups.com> Could you please help me showing me your code ? I'm in a situation similar greetings . From gheskett at shentel.net Tue Jul 19 16:35:45 2016 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 19 Jul 2016 16:35:45 -0400 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: References: Message-ID: <201607191635.45810.gheskett@shentel.net> On Tuesday 19 July 2016 13:46:37 Lawrence D?Oliveiro wrote: > On Wednesday, July 20, 2016 at 12:07:25 AM UTC+12, Gene Heskett wrote: > > This klystron amplifier, a new one of which was north of $125,000 in > > the 1970's when I learned about them, is a long tube, around 5 feet > > long with alternating sections of copper tubeing and ceramic > > insulators separating the copper sections. Typically 4 ceramic > > sections, each of which was sealed to a section of copper equiped > > with contact rings on each end of the copper sections. A tunable box > > cavity connected the copper sections together, bridging the ceramic > > spacer, so that when the tube was "dressed" with these cavity's, and > > lowered into its focusing magnet, (2200 lbs) you could feed about 1 > > watt of signal into the top cavity... > > What is this ?watt? of which you speak? How much is that in > foot-poundals per second? A unit of electrical power, simplified to 1 volt at 1 amp = 1 watt when that currant is passed thru a 1 ohm resistor. But since the majority of radio frequency stuff is designed for a characteristic impedance of 50 ohms, then the currant is 20 milliamps while the voltage rises to 50 volts. And I am not familiar with this foot-poundals per second that you question about, but just from the wording I'd say it is a fifty dollar way to say horsepower. Which is defined in the area of exerting a force to a 440 pound weight, sufficient to lift that weight one foot in one second. Thats for an average horse. I was once in the seat of a stuck in the mud clear above the drawbar of a 1930's Case LA farm tractor. About 8500 lbs. Daddy whistled up King & Colonial, a pair of perches that between them weighted a hundred or so above the 4000 pound mark on the dial at the elevator. :) He also dug out a brace & bit to make a new double-tree out of a 7 foot length of well seasoned Iowa oak cut full native size of 2" thick by 12" wide. And despite the rationing in effect at the end of WW-II when this took place, found a lb of sugar cubes for his overall pocket. Harnessing up the perches, he hooked the traces to this new double-tree, and cleviced a 75 foot length of 1/2" chain to it. He brought them down to where the tractor could be reached from fairly dry ground, drug that chain down and hooked it to the back frame of the 4 bottom 16" plow I was pulling at the time, pulled the hitch pin after digging down to it, waded back the the perches and took a place where he could grab the bridals and made tsk tsk noises. Pulling the plow was done so it would not be in the way. Lead them back and brought the chain back & hooked it to the drawbar. Walking back to the horses he had a small handfull of sugar cubes in each hand and gave it to them. Then grasping the bridals again, a push forward with the tsk tsk. Then a whoa. They had found they were stuck and would need to put some real pull on that chain the next time, which they did, digging a trench under their bellies for about 10 feet when daddy said whoa again. The tractor had moved. So he gave me instructions to put it in reverse and to be ready to slam the clutch lever home the next time it moved. After a breather, wash, rinse and repeat and the tractor was back on dry ground. At peak pull, that 75 feet of 1/2" log chain was up in the air about 6" in the middle. Now if any of you know how to convert that mid-sag amount, the pull on the chain can be deduced, its called the intercept point method. My guess is that that 4100 lbs of horseflesh were peaking at 10,000 lbs on the far end of that chain. They of course can't do it for very long, 10 seconds perhaps, but by then I was loose and all they were dragging was the chain. The horses got the rest of that pound of sugar cubes. Those were the two most gentle giants I have ever lived around. WW-II ended just a couple months later with V-J day. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From alister.ware at ntlworld.com Tue Jul 19 17:21:46 2016 From: alister.ware at ntlworld.com (alister) Date: Tue, 19 Jul 2016 21:21:46 GMT Subject: Request for help References: <578d9940$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 19 Jul 2016 13:06:39 +1000, Steven D'Aprano wrote: > On Tue, 19 Jul 2016 06:20 am, alister wrote: > >> I suggest next time you stay awake during lessons. > > That's an uncalled for nasty comment. You don't know the O.P's issues or > why he is having difficulty. because he has failed to provide any context. the question as phrased looks exactly like a homework question a tutor would set after a lesson introducing classes -- If you keep anything long enough, you can throw it away. From breamoreboy at gmail.com Tue Jul 19 17:24:44 2016 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Tue, 19 Jul 2016 14:24:44 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> Message-ID: <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> On Tuesday, July 19, 2016 at 3:54:12 AM UTC+1, Lawrence D?Oliveiro wrote: > On Tuesday, July 19, 2016 at 11:12:52 AM UTC+12, bream... at gmail.com wrote: > > > > On Monday, July 18, 2016 at 10:48:15 PM UTC+1, Lawrence D?Oliveiro wrote: > >> > >> > >> When you have lots of read/write properties, I find __slots__ to be a good > >> idea. > > > > Please explain why, thank you. > > I was trying something like > > ctx.dashes = ((0.1, 0.03, 0.03, 0.03), 0) > > and wondering why it wasn?t working... This makes no sense to me at all. You appear to be trying to create a tuple, which contains a tuple and an integer. You then say it doesn't work, but imply that using __slots__ fixes the problem. So please explain exactly what you were trying to achieve, the exact error you got, with the complete traceback, and how using __slots__ fixed the problem. Cheers. Mark Lawrence. From python at mrabarnett.plus.com Tue Jul 19 17:59:44 2016 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 19 Jul 2016 22:59:44 +0100 Subject: Request for help In-Reply-To: References: <578d9940$0$1621$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3a7ac547-476b-d7d2-3ee0-c88c7196600d@mrabarnett.plus.com> On 2016-07-19 22:21, alister wrote: > On Tue, 19 Jul 2016 13:06:39 +1000, Steven D'Aprano wrote: > >> On Tue, 19 Jul 2016 06:20 am, alister wrote: >> >>> I suggest next time you stay awake during lessons. >> >> That's an uncalled for nasty comment. You don't know the O.P's issues or >> why he is having difficulty. > > because he has failed to provide any context. > the question as phrased looks exactly like a homework question a tutor > would set after a lesson introducing classes > > It looked a lot like some posts from earlier this year. From marko at pacujo.net Tue Jul 19 18:17:09 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 20 Jul 2016 01:17:09 +0300 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <201607191635.45810.gheskett@shentel.net> Message-ID: <87lh0xqnmi.fsf@elektro.pacujo.net> Gene Heskett : > On Tuesday 19 July 2016 13:46:37 Lawrence D?Oliveiro wrote: >> What is this ?watt? of which you speak? > > A unit of electrical power, simplified to 1 volt at 1 amp = 1 watt > when that currant is passed thru a 1 ohm resistor. But since the > majority of radio frequency stuff is designed for a characteristic > impedance of 50 ohms, then the currant is 20 milliamps while the > voltage rises to 50 volts. Where I live, it is mandatory for stores to display not only prices but also prices per unit. Unfortunately, the "unit" for batteries is a piece. Thus, it is not possible to make price comparisons between different battery brands. I'd love it if batteries were priced per joule, or even per kilowatt-hour. According to , an alkaline AA battery holds 0.00260 kWh. Amazon is selling the Duracell brand at USD 18.38/34-pack, or at about USD 200/kWh. Marko From ian.g.kelly at gmail.com Tue Jul 19 18:27:10 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 19 Jul 2016 16:27:10 -0600 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <201607191635.45810.gheskett@shentel.net> References: <201607191635.45810.gheskett@shentel.net> Message-ID: On Tue, Jul 19, 2016 at 2:35 PM, Gene Heskett wrote: > And I am not familiar with this foot-poundals per second that you > question about, but just from the wording I'd say it is a fifty dollar > way to say horsepower. https://en.wikipedia.org/wiki/Foot-poundal > Which is defined in the area of exerting a force > to a 440 pound weight, sufficient to lift that weight one foot in one > second. 1 (imperial) horsepower is 550 (not 440) foot-pounds per second. A foot-pound is the energy transferred by exerting a 1-pound force through a displacement of 1 foot. A pound is the force needed to accelerate 1 pound-mass at 32.174 ft/s**2 (the acceleration of gravity). A poundal in contrast is the force needed to accelerate 1 pound-mass at 1 ft/s**2. A foot-poundal therefore is the energy transferred by exerting a 1-poundal force through a displacement of 1 foot. A foot-poundal is thus (approximately) 1/32.174 of a foot-pound. Multiplying it out, 1 horsepower is approximately 17695.7 foot-poundals per second. Ah, the machinations that users of imperial units have to endure. From greg.ewing at canterbury.ac.nz Tue Jul 19 19:07:46 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 20 Jul 2016 11:07:46 +1200 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: References: <578d9b91$0$22140$c3e8da3$5496439d@news.astraweb.com> <201607190122.55105.gheskett@shentel.net> Message-ID: Gene Heskett wrote: > The theory of relativity says that the faster you > are going, the more massive you become. It doesn't, really. The equations only seem to say that if you insist on keeping the Newtonian definitions of momentum and kinetic energy in the context of relativity, which is a silly thing to do when you think about it. Physicists realised that nearly a century ago, and no longer use the idea of a velocity-dependent mass. -- Greg From marko at pacujo.net Tue Jul 19 19:09:58 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 20 Jul 2016 02:09:58 +0300 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <201607191635.45810.gheskett@shentel.net> Message-ID: <87bn1tql6h.fsf@elektro.pacujo.net> Ian Kelly : > Ah, the machinations that users of imperial units have to endure. Europeans often mistakenly believe that Americans haven't yet adopted the SI units. They have: - the length of a ski is measured in centimeters - the width of film and the diameter of a gun barrel are measured in millimeters - the wavelength of visible light is measured in nanometers - the volume of a soda bottle is measured in liters - a quantity of confiscated narcotics is measured in kilograms - daily allowance of a vitamin is measured in milligrams - the pitch of a note is measured in hertz - a short timespan is measured in seconds So the problem Europeans have with the situation is *not* the lack of adoption of new units. Rather, it is the refusal of giving up the traditional units. The Anglo-American culture is notorious for its eagerness to absorb foreign influences. What it abhors is reductionism. There is always room for more words, ideas, mores, inventions, but nothing is ever deprecated with a simple edict. Marko From marko at pacujo.net Tue Jul 19 19:20:32 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 20 Jul 2016 02:20:32 +0300 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <578d9b91$0$22140$c3e8da3$5496439d@news.astraweb.com> <201607190122.55105.gheskett@shentel.net> Message-ID: <877fchqkov.fsf@elektro.pacujo.net> Gregory Ewing : > Physicists realised that nearly a century ago, and no > longer use the idea of a velocity-dependent mass. Roche states that about 60% of modern authors just use rest mass and avoid relativistic mass. Marko From lawrencedo99 at gmail.com Tue Jul 19 19:58:52 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 19 Jul 2016 16:58:52 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> Message-ID: On Wednesday, July 20, 2016 at 9:24:57 AM UTC+12, bream... at gmail.com wrote: > > On Tuesday, July 19, 2016 at 3:54:12 AM UTC+1, Lawrence D?Oliveiro wrote: >> >> On Tuesday, July 19, 2016 at 11:12:52 AM UTC+12, bream... at gmail.com wrote: >>> >>> On Monday, July 18, 2016 at 10:48:15 PM UTC+1, Lawrence D?Oliveiro wrote: >>>> >>>> >>>> When you have lots of read/write properties, I find __slots__ to be a >>>> good idea. >>> >>> Please explain why, thank you. >> >> I was trying something like >> >> ctx.dashes = ((0.1, 0.03, 0.03, 0.03), 0) >> >> and wondering why it wasn?t working... > > This makes no sense to me at all. You appear to be trying to create a > tuple, which contains a tuple and an integer. You then say it doesn't > work, but imply that using __slots__ fixes the problem. So please explain > exactly what you were trying to achieve, the exact error you got, with the > complete traceback, and how using __slots__ fixed the problem. No traceback. The lines were simply coming out solid, instead of dashed. From lawrencedo99 at gmail.com Tue Jul 19 20:01:24 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 19 Jul 2016 17:01:24 -0700 (PDT) Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: References: <201607191635.45810.gheskett@shentel.net> Message-ID: <5d5b4214-71c7-4096-a297-a9f9f0247646@googlegroups.com> On Wednesday, July 20, 2016 at 10:28:04 AM UTC+12, Ian wrote: > Ah, the machinations that users of imperial units have to endure. Deep in some people?s hearts, the Mars Climate Orbiter still sails... From random832 at fastmail.com Tue Jul 19 23:15:29 2016 From: random832 at fastmail.com (Random832) Date: Tue, 19 Jul 2016 23:15:29 -0400 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <87lh0xqnmi.fsf@elektro.pacujo.net> References: <201607191635.45810.gheskett@shentel.net> <87lh0xqnmi.fsf@elektro.pacujo.net> Message-ID: <1468984529.3605005.671271489.50995BFE@webmail.messagingengine.com> On Tue, Jul 19, 2016, at 18:17, Marko Rauhamaa wrote: > I'd love it if batteries were priced per joule, or even per > kilowatt-hour. Typically their capacity is labeled in amp-hours. You have to know your devices to know if the voltage difference between different battery types (Which ranges from 1.2 to 1.7 for nominal-1.5 AAA/AA/C/D cells, and may be lower under load) is significant or not, and in what direction. A lower-voltage battery in an incandescent flashlight will last longer but not be as bright. No idea how it shakes out for LEDs, motors, or complex electronics. Some devices may not be operable at all below a certain voltage, and of course the voltage reduces over time as the battery is drained. There are just too many variables, and even the nominal amp-hour rating assumes a certain discharge rate. And of course, for rechargeable batteries there are even more variables; but there what you're buying isn't power. From gheskett at shentel.net Tue Jul 19 23:16:05 2016 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 19 Jul 2016 23:16:05 -0400 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: References: <201607191635.45810.gheskett@shentel.net> Message-ID: <201607192316.05845.gheskett@shentel.net> On Tuesday 19 July 2016 18:27:10 Ian Kelly wrote: > On Tue, Jul 19, 2016 at 2:35 PM, Gene Heskett wrote: > > And I am not familiar with this foot-poundals per second that you > > question about, but just from the wording I'd say it is a fifty > > dollar way to say horsepower. > > https://en.wikipedia.org/wiki/Foot-poundal > > > Which is defined in the area of exerting a force > > to a 440 pound weight, sufficient to lift that weight one foot in > > one second. > > 1 (imperial) horsepower is 550 (not 440) foot-pounds per second. A > foot-pound is the energy transferred by exerting a 1-pound force > through a displacement of 1 foot. A pound is the force needed to > accelerate 1 pound-mass at 32.174 ft/s**2 (the acceleration of > gravity). A poundal in contrast is the force needed to accelerate 1 > pound-mass at 1 ft/s**2. A foot-poundal therefore is the energy > transferred by exerting a 1-poundal force through a displacement of 1 > foot. A foot-poundal is thus (approximately) 1/32.174 of a foot-pound. > > Multiplying it out, 1 horsepower is approximately 17695.7 > foot-poundals per second. > > Ah, the machinations that users of imperial units have to endure. Thanks for the correction, and the explanation. I should have checked at wikipedia myself. I don't know where I got the 440 from unless its yards from the tree to the trap when drag racing. I did a bit of that 60 years back, discovered it was an expen$ive hobby. Bring lots and lots of money if you want to play with the big dogs. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From steve+comp.lang.python at pearwood.info Wed Jul 20 01:42:50 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 20 Jul 2016 15:42:50 +1000 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> Message-ID: <578f0f5c$0$11115$c3e8da3@news.astraweb.com> On Tuesday 19 July 2016 14:58, Rustom Mody wrote: > So I again ask: You say ?"Never compare floats for equality" is a pernicious > myth? It is the word *never* which makes it superstition. If people said "Take care with using == for floats, its often not what you want" I would have no argument with the statement. I'd even (reluctantly) accept "usually not what you want". But "never" is out- and-out cargo-cult programming. > Given that for Chris? is_equal we get > is_equal(.1+.1+.1, .3) is True > whereas for python builtin == its False > > What (non)myth do you suggest for replacement? Floating point maths is hard, thinking carefully about what you are doing and whether it is appropriate to use == or a fuzzy almost-equal comparison, or if equality is the right way at all. "But thinking is hard, can't you just tell me the answer?" No. But I can give some guidelines: Floating point arithmetic is deterministic, it doesn't just randomly mix in error out of spite or malice. So in principle, you can always estimate the rounding error from any calculation -- and sometimes there is none. Arithmetic on integer-values (e.g. 1.0) is always exact, up to a limit of either 2**53 or approximately 1e53, I forget which. (That's why most Javascript programmers fail to notice that they don't have an integer type.) So long as you're using operations that only produce integer values from integer arguments (such as + - * // but not / ) then all calculations are exact. It is a waste of time to do: x = 2.0 y = x*1002.0 is_equal(y, 2004.0, 1e-16) when you can just do y == 2004.0. If you do decide to use an absolute error, e.g.: abs(x - y) < tolerance keep in mind that your tolerance needs to be chosen relative to the x and y. For large values of x and y, the smallest possible difference may be very large: py> x = 1e80 py> delta = 2**-1000 py> assert delta py> while x + delta == x: ... delta *= 2 ... else: ... print(delta) ... 6.58201822928e+63 So if you're comparing two numbers around 1e80 or so, doing a "fuzzy comparison" using an absolute tolerance of less than 6.5e63 or so is just a slow and complicated way of performing an exact comparison using the == operator. Absolute tolerance is faster and easier to understand, and works when the numbers are on opposite sides of zero, or if one (or both) is zero. But generally speaking, relative tolerance of one form or another: abs(x - y) <= abs(x)*relative_tolerance abs(x - y) <= abs(y)*relative_tolerance abs(x - y) <= min(abs(x), abs(y))*relative_tolerance abs(x - y) <= max(abs(x), abs(y))*relative_tolerance is probably better, but they are slower. A nice, simple technique is just to round: if round(x, 6) == round(y, 6): but that's not quite the same as abs(x-y) < 1e-6. For library code that cares greatly about precision, using "Unit Last Place" (ULP) calculations are probably best. But that's a whole different story. -- Steve From rosuav at gmail.com Wed Jul 20 02:11:23 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Jul 2016 16:11:23 +1000 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] In-Reply-To: <578f0f5c$0$11115$c3e8da3@news.astraweb.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> Message-ID: On Wed, Jul 20, 2016 at 3:42 PM, Steven D'Aprano wrote: > Arithmetic on integer-values (e.g. 1.0) is always exact, up to a limit of > either 2**53 or approximately 1e53, I forget which. (That's why most Javascript > programmers fail to notice that they don't have an integer type.) It's 2**53, because 64-bit floats use a 53-bit mantissa (52-bits stored and an implicit 1 at the beginning, although I can never remember how denormals are represented). Works out to a bit under 1e16. AIUI asm.js offers a 32-bit integer type, which in fall-back mode is represented with the native "Number" type; for values that could be stored in a 32-bit integer, a 64-bit float is perfectly accurate (just stupidly inefficient compared to a real integer type). ChrisA From rosuav at gmail.com Wed Jul 20 02:19:28 2016 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Jul 2016 16:19:28 +1000 Subject: can't add variables to instances of built-in classes In-Reply-To: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> Message-ID: 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... at gmail.com wrote: >> >> On Tuesday, July 19, 2016 at 3:54:12 AM UTC+1, Lawrence D?Oliveiro wrote: >>> >>> On Tuesday, July 19, 2016 at 11:12:52 AM UTC+12, bream... at gmail.com wrote: >>>> >>>> On Monday, July 18, 2016 at 10:48:15 PM UTC+1, Lawrence D?Oliveiro wrote: >>>>> >>>>> >>>>> When you have lots of read/write properties, I find __slots__ to be a >>>>> good idea. >>>> >>>> Please explain why, thank you. >>> >>> I was trying something like >>> >>> ctx.dashes = ((0.1, 0.03, 0.03, 0.03), 0) >>> >>> and wondering why it wasn?t working... >> >> This makes no sense to me at all. You appear to be trying to create a >> tuple, which contains a tuple and an integer. You then say it doesn't >> work, but imply that using __slots__ fixes the problem. So please explain >> exactly what you were trying to achieve, the exact error you got, with the >> complete traceback, and how using __slots__ fixed the problem. > > No traceback. The lines were simply coming out solid, instead of dashed. And __slots__ fixed the problem how, exactly? This sounds like the sort of cargo cult debugging that I'd expect of PHP programmers ("I put addslashes around everything and now it works, so in future I'll use addslashes everywhere"), but around here, we're better than that. ChrisA From lawrencedo99 at gmail.com Wed Jul 20 02:45:38 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Tue, 19 Jul 2016 23:45:38 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> Message-ID: 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... at gmail.com wrote: >>> >>> On Tuesday, July 19, 2016 at 3:54:12 AM UTC+1, Lawrence D?Oliveiro wrote: >>>> >>>> On Tuesday, July 19, 2016 at 11:12:52 AM UTC+12, bream... at gmail.com >>>> wrote: >>>>> >>>>> On Monday, July 18, 2016 at 10:48:15 PM UTC+1, Lawrence D?Oliveiro >>>>> wrote: >>>>>> >>>>>> >>>>>> When you have lots of read/write properties, I find __slots__ to be a >>>>>> good idea. >>>>> >>>>> Please explain why, thank you. >>>> >>>> I was trying something like >>>> >>>> ctx.dashes = ((0.1, 0.03, 0.03, 0.03), 0) >>>> >>>> and wondering why it wasn?t working... >>> >>> This makes no sense to me at all. You appear to be trying to create a >>> tuple, which contains a tuple and an integer. You then say it doesn't >>> work, but imply that using __slots__ fixes the problem. So please explain >>> exactly what you were trying to achieve, the exact error you got, with the >>> complete traceback, and how using __slots__ fixed the problem. >> >> No traceback. The lines were simply coming out solid, instead of dashed. > > And __slots__ fixed the problem how, exactly? The Context attribute that controls the dash settings is called ?dash?, not ?dashes?. > This sounds like the sort of cargo cult debugging that I'd expect of PHP > programmers ("I put addslashes around everything and now it works, so in > future I'll use addslashes everywhere"), but around here, we're better than > that. OK, boss. From antoon.pardon at rece.vub.ac.be Wed Jul 20 03:09:29 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 20 Jul 2016 09:09:29 +0200 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] In-Reply-To: <578f0f5c$0$11115$c3e8da3@news.astraweb.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> Message-ID: <578F23A9.7070105@rece.vub.ac.be> Op 20-07-16 om 07:42 schreef Steven D'Aprano: > Floating point maths is hard, thinking carefully about what you are doing and > whether it is appropriate to use == or a fuzzy almost-equal comparison, or if > equality is the right way at all. > > "But thinking is hard, can't you just tell me the answer?" > > No. But I can give some guidelines: > > Floating point arithmetic is deterministic, it doesn't just randomly mix in > error out of spite or malice. So in principle, you can always estimate the > rounding error from any calculation -- and sometimes there is none. I would like to see a practical example of such an outcome. > Arithmetic on integer-values (e.g. 1.0) is always exact, up to a limit of > either 2**53 or approximately 1e53, I forget which. (That's why most Javascript > programmers fail to notice that they don't have an integer type.) So long as > you're using operations that only produce integer values from integer arguments > (such as + - * // but not / ) then all calculations are exact. It is a waste of > time to do: > > x = 2.0 > y = x*1002.0 > is_equal(y, 2004.0, 1e-16) > > when you can just do y == 2004.0. But why perforem integer arithmetics in floats, isn't that a waste of time too? I really see no reason to use floats if you know all your results will be integers. -- Antoon. From marko at pacujo.net Wed Jul 20 03:16:53 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 20 Jul 2016 10:16:53 +0300 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <201607191635.45810.gheskett@shentel.net> <87lh0xqnmi.fsf@elektro.pacujo.net> <1468984529.3605005.671271489.50995BFE@webmail.messagingengine.com> Message-ID: <87zipcpymy.fsf@elektro.pacujo.net> Random832 : > On Tue, Jul 19, 2016, at 18:17, Marko Rauhamaa wrote: >> I'd love it if batteries were priced per joule, or even per >> kilowatt-hour. > > Typically their capacity is labeled in amp-hours. Did you really see that labeled on the (nonrechargeable AA) battery? > You have to know your devices to know if the voltage difference > between different battery types (Which ranges from 1.2 to 1.7 for > nominal-1.5 AAA/AA/C/D cells, and may be lower under load) is > significant or not, and in what direction. Well, your amp hours will be shittier with a lower voltage. That's why reporting joules would be more honest. Marko From steve+comp.lang.python at pearwood.info Wed Jul 20 03:22:15 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 20 Jul 2016 17:22:15 +1000 Subject: can't add variables to instances of built-in classes References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> Message-ID: <578f26a9$0$1612$c3e8da3$5496439d@news.astraweb.com> On Wednesday 20 July 2016 16:45, Lawrence D?Oliveiro wrote: >>>>> I was trying something like >>>>> >>>>> ctx.dashes = ((0.1, 0.03, 0.03, 0.03), 0) >>>>> >>>>> and wondering why it wasn?t working... And so are we. Since you've already solved the problem, maybe you could enlighten us? >>>> This makes no sense to me at all. You appear to be trying to create a >>>> tuple, which contains a tuple and an integer. You then say it doesn't >>>> work, but imply that using __slots__ fixes the problem. So please explain >>>> exactly what you were trying to achieve, the exact error you got, with the >>>> complete traceback, and how using __slots__ fixed the problem. >>> >>> No traceback. The lines were simply coming out solid, instead of dashed. >> >> And __slots__ fixed the problem how, exactly? > > The Context attribute that controls the dash settings is called ?dash?, not > ?dashes?. Ah, finally, an actually *useful* reply. Honestly Lawrence, couldn't you have just said this right at the start, instead of having us drag the answer out of you over multiple email exchanges? If you had said right at the beginning "I have a habit of mistyping attribute names, and using __slots__ ensures I get an immediate error" then we would have understood you. Instead, you waste our time, *and yours*, leading us up the garden path by implying that you fixed a display bug by changing something like: class Context(object): def __init__(self): self.dashes = something to: class Context(object): __slots__ = ("dashes",) def __init__(self): self.dashes = something Perhaps now you understand why you gave us the impression of cargo-cult debugging. -- Steve From marko at pacujo.net Wed Jul 20 03:25:01 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 20 Jul 2016 10:25:01 +0300 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> Message-ID: <87vb00py9e.fsf@elektro.pacujo.net> Antoon Pardon : > But why perforem integer arithmetics in floats, Conceptual and practical simplificity. > isn't that a waste of time too? Probably not, especially compared with the overhead of boxing. Marko From __peter__ at web.de Wed Jul 20 03:26:08 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 20 Jul 2016 09:26:08 +0200 Subject: can't add variables to instances of built-in classes References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> Message-ID: 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... at gmail.com >>> wrote: >>>> >>>> On Tuesday, July 19, 2016 at 3:54:12 AM UTC+1, Lawrence D?Oliveiro >>>> wrote: >>>>> >>>>> On Tuesday, July 19, 2016 at 11:12:52 AM UTC+12, bream... at gmail.com >>>>> wrote: >>>>>> >>>>>> On Monday, July 18, 2016 at 10:48:15 PM UTC+1, Lawrence D?Oliveiro >>>>>> wrote: >>>>>>> >>>>>>> >>>>>>> When you have lots of read/write properties, I find __slots__ to be >>>>>>> a good idea. >>>>>> >>>>>> Please explain why, thank you. >>>>> >>>>> I was trying something like >>>>> >>>>> ctx.dashes = ((0.1, 0.03, 0.03, 0.03), 0) >>>>> >>>>> and wondering why it wasn?t working... >>>> >>>> This makes no sense to me at all. You appear to be trying to create a >>>> tuple, which contains a tuple and an integer. You then say it doesn't >>>> work, but imply that using __slots__ fixes the problem. So please >>>> explain exactly what you were trying to achieve, the exact error you >>>> got, with the complete traceback, and how using __slots__ fixed the >>>> problem. >>> >>> No traceback. The lines were simply coming out solid, instead of dashed. >> >> And __slots__ fixed the problem how, exactly? > > The Context attribute that controls the dash settings is called ?dash?, > not ?dashes?. > >> This sounds like the sort of cargo cult debugging that I'd expect of PHP >> programmers ("I put addslashes around everything and now it works, so in >> future I'll use addslashes everywhere"), but around here, we're better >> than that. > > OK, boss. pylint can detect candidates for accidental attribute creation: $ cat attrib.py class Context: def __init__(self): self.dashes = None ctx = Context() ctx.dasehs = ("foo", "bar") $ pylint attrib | grep dasehs W: 6, 4: Attribute 'dasehs' defined outside __init__ (attribute-defined- outside-init) From lawrencedo99 at gmail.com Wed Jul 20 04:50:43 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 20 Jul 2016 01:50:43 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> Message-ID: <18acf908-b761-4a60-8d7c-5e4576b03320@googlegroups.com> 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. From lawrencedo99 at gmail.com Wed Jul 20 05:10:13 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 20 Jul 2016 02:10:13 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> Message-ID: <32fea203-d689-448b-91ac-0229c7a20b10@googlegroups.com> On Tuesday, July 19, 2016 at 9:48:15 AM UTC+12, I wrote: > When you have lots of read/write properties, I find __slots__ to be a good > idea. Let me amend that. When you have *any* read/write properties, I find __slots__ to be a good idea. From __peter__ at web.de Wed Jul 20 05:15:58 2016 From: __peter__ at web.de (Peter Otten) Date: Wed, 20 Jul 2016 11:15:58 +0200 Subject: can't add variables to instances of built-in classes References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> <18acf908-b761-4a60-8d7c-5e4576b03320@googlegroups.com> Message-ID: 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. From steve at pearwood.info Wed Jul 20 08:10:52 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 20 Jul 2016 22:10:52 +1000 Subject: can't add variables to instances of built-in classes References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> <18acf908-b761-4a60-8d7c-5e4576b03320@googlegroups.com> Message-ID: <578f6a4f$0$22142$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Jul 2016 06:50 pm, 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. As well as those added intentionally. Sometimes I wonder what it is that you see in Python and why you use it. You're frequently complaining about features of the language. You go out of your way to write in the style of Java/C/whatever in Python, which means you get all the disadvantages of writing verbose and inflexible static Java/C/whatever PLUS the inefficiency of dynamic Python, so the worst of both worlds. I genuinely don't see what you get out of using Python. Would you care to explain? There must be something you like about it, even if it isn't the ability to add attributes to (nearly) arbitrary objects without declaring them, or the duck-typing of booleans. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Wed Jul 20 08:47:14 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 20 Jul 2016 22:47:14 +1000 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> Message-ID: <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Jul 2016 05:09 pm, Antoon Pardon wrote: > Op 20-07-16 om 07:42 schreef Steven D'Aprano: >> Floating point maths is hard, thinking carefully about what you are doing >> and whether it is appropriate to use == or a fuzzy almost-equal >> comparison, or if equality is the right way at all. >> >> "But thinking is hard, can't you just tell me the answer?" >> >> No. But I can give some guidelines: >> >> Floating point arithmetic is deterministic, it doesn't just randomly mix >> in error out of spite or malice. So in principle, you can always estimate >> the rounding error from any calculation -- and sometimes there is none. > > I would like to see a practical example of such an outcome. [steve at ando ~]$ cd /home/steve/python/python-dev/3.4/Lib/test/ [steve at ando test]$ grep self.assertEqual test_statistics.py | wc -l 95 Not all of the 95 examples of using assertEqual apply to float values, but a good proportion of them do. And if I were a better computer scientist, there would probably be a lot more assertEquals in my code. A lot of the time that I do a fuzzy comparison its because I'm too lazy or not good enough to get a better result. I am not a good computer scientist. But Bruce Dawson *is* a good computer scientist: https://randomascii.wordpress.com/2014/01/27/theres-only-four-billion-floatsso-test-them-all/ Quote: Conventional wisdom says that you should never compare two floats for equality ? you should always use an epsilon. Conventional wisdom is wrong. I?ve written in great detail about how to compare floating-point values using an epsilon, but there are times when it is just not appropriate. Sometimes there really is an answer that is correct, and in those cases anything less than perfection is just sloppy. So yes, I?m proudly comparing floats to see if they are equal. >> Arithmetic on integer-values (e.g. 1.0) is always exact, up to a limit of >> either 2**53 or approximately 1e53, I forget which. (That's why most >> Javascript programmers fail to notice that they don't have an integer >> type.) So long as you're using operations that only produce integer >> values from integer arguments (such as + - * // but not / ) then all >> calculations are exact. It is a waste of time to do: >> >> x = 2.0 >> y = x*1002.0 >> is_equal(y, 2004.0, 1e-16) >> >> when you can just do y == 2004.0. > > But why perforem integer arithmetics in floats, isn't that a waste of time > too? I really see no reason to use floats if you know all your results > will be integers. In Python, it's probably neither harmful nor useful. The cost of dealing with boxed values (objects rather than low-level machine values) will probably outweigh any performance gain one way or the other. But in lower-level languages, you might find that floating point arithmetic is faster than integer arithmetic, if you can pass the work on to a FPU instead of a (slow?) CPU. Or not. It depends on the machine. Or you might be using a language like Javascript, which intentionally has only floats for numbers. That's okay, you can still perform exact integer arithmetic, so long as you stay within the bounds of ?2**16. Not even in Javascript do you need to write something like this: x = 0.0 for i in range(20): x += 1.0 assert abs(x - 20.0) <= 1e-16 -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From alister.ware at ntlworld.com Wed Jul 20 09:24:47 2016 From: alister.ware at ntlworld.com (alister) Date: Wed, 20 Jul 2016 13:24:47 GMT Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <201607191635.45810.gheskett@shentel.net> <87bn1tql6h.fsf@elektro.pacujo.net> Message-ID: On Wed, 20 Jul 2016 02:09:58 +0300, Marko Rauhamaa wrote: > Ian Kelly : > >> Ah, the machinations that users of imperial units have to endure. > > Europeans often mistakenly believe that Americans haven't yet adopted > the SI units. They have: > > - the length of a ski is measured in centimeters > > - the width of film and the diameter of a gun barrel are measured in > millimeters > > - the wavelength of visible light is measured in nanometers > > - the volume of a soda bottle is measured in liters > > - a quantity of confiscated narcotics is measured in kilograms > > - daily allowance of a vitamin is measured in milligrams > > - the pitch of a note is measured in hertz > > - a short timespan is measured in seconds > > > So the problem Europeans have with the situation is *not* the lack of > adoption of new units. Rather, it is the refusal of giving up the > traditional units. > > The Anglo-American culture is notorious for its eagerness to absorb > foreign influences. What it abhors is reductionism. There is always room > for more words, ideas, mores, inventions, but nothing is ever deprecated > with a simple edict. > > > Marko One of my biggest questions since the Brexit vote is can we g back to using imperial weights & measures (please). -- Egotist: A person of low taste, more interested in himself than in me. -- Ambrose Bierce From marko at pacujo.net Wed Jul 20 09:54:55 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 20 Jul 2016 16:54:55 +0300 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] References: <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87r3aopg7k.fsf@elektro.pacujo.net> Steven D'Aprano : > I am not a good computer scientist. But Bruce Dawson *is* a good > computer scientist: > > https://randomascii.wordpress.com/2014/01/27/theres-only-four-billion-f > loatsso-test-them-all/ > > Quote: > > Conventional wisdom says that you should never compare two floats > for equality ? you should always use an epsilon. Conventional > wisdom is wrong. > > I?ve written in great detail about how to compare floating-point > values using an epsilon, but there are times when it is just not > appropriate. Sometimes there really is an answer that is correct, > and in those cases anything less than perfection is just sloppy. > > So yes, I?m proudly comparing floats to see if they are equal. The point of view in the linked article is very different from that of most application programming that makes use of floating-point numbers. Yes, if what you are testing or developing is a numeric or mathematical package, you should test its numeric/mathematical soundness to the bit. However, in virtually any other context, you have barely any use for a floating-point equality comparison because: 1. Floating-point numbers are an approximation of *real numbers*. Two independently measured real numbers are never equal because under any continuous probability distribution, the probability of any given real number is zero. Only continuous ranges can have nonzero probabilities. 2. Floating-point numbers are *imperfect approximations* of real numbers. Even when real numbers are derived exactly, floating-point operations may introduce "lossy compression artifacts" that have to be compensated for in application programs. What you have to do exactly to compensate for these challenges depends on the application, and is very easy to get wrong. However, if an application programmer is using == to compare two floating-point data values, it is almost certainly a mistake. > Or you might be using a language like Javascript, which intentionally > has only floats for numbers. That's okay, you can still perform exact > integer arithmetic, so long as you stay within the bounds of ?2**16. > > Not even in Javascript do you need to write something like this: > > x = 0.0 > for i in range(20): > x += 1.0 > > assert abs(x - 20.0) <= 1e-16 Correct because Javascript makes an exactness guarantee of its integers (I imagine). In Python, I think it would usually be bad style to rely even on: 1.0 + 1.0 == 2.0 It is very difficult to find a justification for that assumption in Python's specifications. What we have: Floating-point numbers are represented in computer hardware as base 2 (binary) fractions. almost all platforms map Python floats to IEEE-754 ?double precision? numbers.Real (float) These represent machine-level double precision floating point numbers. You are at the mercy of the underlying machine architecture (and C or Java implementation) for the accepted range and handling of overflow. I believe a Python implementation that would have: 1.0 + 1.0 != 2.0 would not be in violation of Python's data model. In fact, even: 1.0 != 1.0 might be totally conformant. For example, we could have a new underlying real-number technology that stored the value in an *analogous* format (say, an ultra-precise voltage level) and performed the calculations using some fast, analogous circuitry. Marko From random832 at fastmail.com Wed Jul 20 10:00:36 2016 From: random832 at fastmail.com (Random832) Date: Wed, 20 Jul 2016 10:00:36 -0400 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: <87zipcpymy.fsf@elektro.pacujo.net> References: <201607191635.45810.gheskett@shentel.net> <87lh0xqnmi.fsf@elektro.pacujo.net> <1468984529.3605005.671271489.50995BFE@webmail.messagingengine.com> <87zipcpymy.fsf@elektro.pacujo.net> Message-ID: <1469023236.4087317.671694609.2B24E2C5@webmail.messagingengine.com> On Wed, Jul 20, 2016, at 03:16, Marko Rauhamaa wrote: > Random832 : > > Typically their capacity is labeled in amp-hours. > > Did you really see that labeled on the (nonrechargeable AA) battery? Sorry, I must have imagined that. Anyway, my point was that the reality is too complicated to easily assign a number to - that they don't even try supports that. Duracell's datasheets don't even have a single number, just a bunch of line graphs. > > You have to know your devices to know if the voltage difference > > between different battery types (Which ranges from 1.2 to 1.7 for > > nominal-1.5 AAA/AA/C/D cells, and may be lower under load) is > > significant or not, and in what direction. > > Well, your amp hours will be shittier with a lower voltage. Define "shittier". An incandescent flashlight (which consumes less power at lower voltage) will last longer, but won't be as bright. If it's still acceptably bright, that's not worse. > That's why > reporting joules would be more honest. And *my* point is that the number of joules depends on how the battery is used. And different types of batteries are optimized for different applications. From rosuav at gmail.com Wed Jul 20 10:26:12 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Jul 2016 00:26:12 +1000 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] In-Reply-To: <87r3aopg7k.fsf@elektro.pacujo.net> References: <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> <87r3aopg7k.fsf@elektro.pacujo.net> Message-ID: On Wed, Jul 20, 2016 at 11:54 PM, Marko Rauhamaa wrote: > 2. Floating-point numbers are *imperfect approximations* of real > numbers. Even when real numbers are derived exactly, floating-point > operations may introduce "lossy compression artifacts" that have to > be compensated for in application programs. This is the kind of black FUD that has to be fought off. What "compression artifacts" are introduced? The *only* lossiness in IEEE binary floating-point arithmetic is rounding. (This is the bit where someone like Steven is going to point out that there's something else as well.) Unless you are working with numbers that require more precision than you have available, the result should be perfectly accurate. And there are other systems far less 'simple'. Can you imagine this second assertion failing? assert x <= y # if not, swap the values assert x <= (x+y)/2 <= y Because it can with decimal.Decimal, due to the way rounding happens in decimal. ChrisA From marko at pacujo.net Wed Jul 20 10:59:11 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 20 Jul 2016 17:59:11 +0300 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] References: <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> <87r3aopg7k.fsf@elektro.pacujo.net> Message-ID: <87mvlcpd8g.fsf@elektro.pacujo.net> Chris Angelico : > On Wed, Jul 20, 2016 at 11:54 PM, Marko Rauhamaa wrote: >> 2. Floating-point numbers are *imperfect approximations* of real >> numbers. Even when real numbers are derived exactly, >> floating-point operations may introduce "lossy compression >> artifacts" that have to be compensated for in application >> programs. > > This is the kind of black FUD that has to be fought off. What > "compression artifacts" are introduced? The *only* lossiness in IEEE > binary floating-point arithmetic is rounding. You are joining me in spreading the FUD. Yes, the immediate lossiness is rounding, but the effects of that rounding can result in atrocious accumulative errors in numeric calculations. > Unless you are working with numbers that require more precision than > you have available, the result should be perfectly accurate. Whoa, hold it there! Catastrophic cancellation () is not a myth: >>> 0.2 / (0.2 - 0.1) 2.0 >>> 0.2 / ((2e15 + 0.2) - (2e15 + 0.1)) 0.8 You can fall victim to the phenomenon when you collect statistics over a long time. The cumulative sum of a measurement can grow very large, which causes the na?ve per-second rate calculation to become increasingly bogus. Marko From ian.g.kelly at gmail.com Wed Jul 20 13:42:02 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 20 Jul 2016 11:42:02 -0600 Subject: reversed(enumerate(x)) Message-ID: I had occasion to write something like this: for i, n in reversed(enumerate(x)): pass Of course this fails with "TypeError: argument to reversed() must be a sequence". I ended up using this instead: for i, n in zip(reversed(range(len(x))), reversed(x)): pass This works but is extraordinarily ugly and not terribly clear. I think it's less confusing however than: for i, n in zip(range(len(x)-1, -1, -1), reversed(n)): pass How would you write this? From rosuav at gmail.com Wed Jul 20 13:46:56 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Jul 2016 03:46:56 +1000 Subject: reversed(enumerate(x)) In-Reply-To: References: Message-ID: On Thu, Jul 21, 2016 at 3:42 AM, Ian Kelly wrote: > I had occasion to write something like this: > > for i, n in reversed(enumerate(x)): pass > > Of course this fails with "TypeError: argument to reversed() must be a > sequence". I ended up using this instead: > > for i, n in zip(reversed(range(len(x))), reversed(x)): pass At the cost of coalescing the enumeration, you could: for i, n in reversed(list(enumerate(x))): pass It's reasonably clean but less efficient. ChrisA From 007brendan at gmail.com Wed Jul 20 13:54:19 2016 From: 007brendan at gmail.com (Brendan Abel) Date: Wed, 20 Jul 2016 10:54:19 -0700 Subject: reversed(enumerate(x)) In-Reply-To: References: Message-ID: You could create your own generator that wraps enumerate def reverse_enumerate(iterable): for i, val in enumerate(reversed(iterable)): yield len(iterable) - 1 - i, val for i, val in reverse_enumerate(x): ... On Wed, Jul 20, 2016 at 10:42 AM, Ian Kelly wrote: > I had occasion to write something like this: > > for i, n in reversed(enumerate(x)): pass > > Of course this fails with "TypeError: argument to reversed() must be a > sequence". I ended up using this instead: > > for i, n in zip(reversed(range(len(x))), reversed(x)): pass > > This works but is extraordinarily ugly and not terribly clear. I think > it's less confusing however than: > > for i, n in zip(range(len(x)-1, -1, -1), reversed(n)): pass > > How would you write this? > -- > https://mail.python.org/mailman/listinfo/python-list > From steve at pearwood.info Wed Jul 20 15:13:18 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 21 Jul 2016 05:13:18 +1000 Subject: reversed(enumerate(x)) References: Message-ID: <578fcd4f$0$1595$c3e8da3$5496439d@news.astraweb.com> On Thu, 21 Jul 2016 03:46 am, Chris Angelico wrote: > On Thu, Jul 21, 2016 at 3:42 AM, Ian Kelly wrote: >> I had occasion to write something like this: >> >> for i, n in reversed(enumerate(x)): pass >> >> Of course this fails with "TypeError: argument to reversed() must be a >> sequence". I ended up using this instead: >> >> for i, n in zip(reversed(range(len(x))), reversed(x)): pass > > At the cost of coalescing the enumeration, you could: > > for i, n in reversed(list(enumerate(x))): pass > > It's reasonably clean but less efficient. Less efficient than what? reversed() only operates on sequences, so it can't operate on arbitrary iterators of unknown length? Possibly of indefinite length? def iter(): while random.random() > 0.01: yield random.random() So in the most general case, you have to form a list before you can reverse it. Personally, I think your version is the most straightforward and obvious solution that works on anything. (Well, perhaps not on infinite iterators.) Yes, you have to convert x into a list, but that's in general the only way to use reversed() anyway. If your needs are not too great, or simplicity of code is more important than The "best" solution might be some more work: you might convert x into a list only if it's an iterator, then iterate over it in reverse: def sequencefy(x): if x is iter(x): return list(x) return x def enumerate_down(it): seq = sequencefy(it) n = len(seq) - 1 for item in reversed(seq): yield (n, item) n -= 1 for i, item = enumerate_down(x): ... An advantage of this is that it works well with lazy sequences like (x)range. There's no need to build up a huge list of (index, item) pairs before reversing it. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From random832 at fastmail.com Wed Jul 20 15:16:11 2016 From: random832 at fastmail.com (Random832) Date: Wed, 20 Jul 2016 15:16:11 -0400 Subject: reversed(enumerate(x)) In-Reply-To: References: Message-ID: <1469042171.969423.672037929.5B2B15E7@webmail.messagingengine.com> On Wed, Jul 20, 2016, at 13:42, Ian Kelly wrote: > I had occasion to write something like this: > > for i, n in reversed(enumerate(x)): pass > > How would you write this? I'd write my own version of enumerate with a step argument, and call enumerate(reversed(x), start=len(x), step=-1) From rosuav at gmail.com Wed Jul 20 15:47:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Jul 2016 05:47:46 +1000 Subject: reversed(enumerate(x)) In-Reply-To: <578fcd4f$0$1595$c3e8da3$5496439d@news.astraweb.com> References: <578fcd4f$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jul 21, 2016 at 5:13 AM, Steven D'Aprano wrote: > On Thu, 21 Jul 2016 03:46 am, Chris Angelico wrote: > >> On Thu, Jul 21, 2016 at 3:42 AM, Ian Kelly wrote: >>> I had occasion to write something like this: >>> >>> for i, n in reversed(enumerate(x)): pass >>> >>> Of course this fails with "TypeError: argument to reversed() must be a >>> sequence". I ended up using this instead: >>> >>> for i, n in zip(reversed(range(len(x))), reversed(x)): pass >> >> At the cost of coalescing the enumeration, you could: >> >> for i, n in reversed(list(enumerate(x))): pass >> >> It's reasonably clean but less efficient. > > > Less efficient than what? Than something that let you "enumerate the reverse" of something. Consider: # Here's what we want to happen. x = ["foo", "bar", "spam"] for i, n in reversed(enumerate(x)): # ENABLE MINDREADING MAGIC print(i, n) 2 spam 1 bar 0 foo So we could do this by first reversing the sequence, and then *enumerating down*. But enumerate() doesn't allow that - it has a 'start' parameter, but no 'step'. Let's pretend it did. for i, n in enumerate(reversed(x), len(x)-1, -1): # same result The very cleanest, IMO, would be something like this: def enumerate_reversed(seq): n = len(seq) for obj in reversed(seq): n -= 1 yield n, obj > reversed() only operates on sequences, so it can't operate on arbitrary > iterators of unknown length? Possibly of indefinite length? Of course not; but it doesn't necessarily require that the sequence exist as a list, much less as two. My simple and naive example will take any sequence, pair values with their indices, coalesce the result as a list, and then iterate backward through that list. Imagine if the sequence in question were range(1<<256), for instance. You can't list(enumerate(x)) that, but you can certainly reversed() it and get its length... well, okay, apparently len(range(1<<256)) is illegal in CPython, but len(range(1<<63-1)) is fine. You shouldn't need to list() that. So yes, my naive version is less memory efficient for large lists. > Personally, I think your version is the most straightforward and obvious > solution that works on anything. (Well, perhaps not on infinite iterators.) > Yes, you have to convert x into a list, but that's in general the only way > to use reversed() anyway. If your needs are not too great, or simplicity of > code is more important than I agree, which is why I suggested it. > The "best" solution might be some more work: you might convert x into a list > only if it's an iterator, then iterate over it in reverse: > > > def sequencefy(x): > if x is iter(x): > return list(x) > return x > > def enumerate_down(it): > seq = sequencefy(it) > n = len(seq) - 1 > for item in reversed(seq): > yield (n, item) > n -= 1 > > for i, item = enumerate_down(x): > ... > > > > An advantage of this is that it works well with lazy sequences like > (x)range. There's no need to build up a huge list of (index, item) pairs > before reversing it. Yeah, or the simpler version that I used. All depends how much complexity you really need. ChrisA From vineethmenneni33 at gmail.com Wed Jul 20 17:39:28 2016 From: vineethmenneni33 at gmail.com (vineeth menneni) Date: Wed, 20 Jul 2016 14:39:28 -0700 (PDT) Subject: apache not ale to execute a vbscript with python Message-ID: Hi, I am trying to call a external vbscript through subprocess.call() it works fine with my local, but when i try to test apache says that no such file or directory. The problem here is that the vbscript should generate a .xlsx file and it is not being created. So apache gives a warning no such file or directory. Can you suggest any solutions. Thanks From lawrencedo99 at gmail.com Wed Jul 20 17:48:03 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 20 Jul 2016 14:48:03 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: <578f6a4f$0$22142$c3e8da3$5496439d@news.astraweb.com> References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> <18acf908-b761-4a60-8d7c-5e4576b03320@googlegroups.com> <578f6a4f$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, July 21, 2016 at 12:11:09 AM UTC+12, Steven D'Aprano wrote: > [long irrelevant rant deleted] Just because I pointed out what a load of nonsense you were spouting about __slots__, by giving a counterexample of their usefulness? Man, your pride must be hurt... From lawrencedo99 at gmail.com Wed Jul 20 18:11:26 2016 From: lawrencedo99 at gmail.com (=?UTF-8?Q?Lawrence_D=E2=80=99Oliveiro?=) Date: Wed, 20 Jul 2016 15:11:26 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> <18acf908-b761-4a60-8d7c-5e4576b03320@googlegroups.com> Message-ID: On Wednesday, July 20, 2016 at 9:16:30 PM UTC+12, Peter Otten wrote: > > 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. You mean, being able to dynamically add new attributes to an object? Probably not a good idea to mix that with read/write properties... From greg.ewing at canterbury.ac.nz Wed Jul 20 18:46:58 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 21 Jul 2016 10:46:58 +1200 Subject: What exactly is "exact" (was Clean Singleton Docstrings) In-Reply-To: References: <201607191635.45810.gheskett@shentel.net> <87lh0xqnmi.fsf@elektro.pacujo.net> <1468984529.3605005.671271489.50995BFE@webmail.messagingengine.com> <87zipcpymy.fsf@elektro.pacujo.net> <1469023236.4087317.671694609.2B24E2C5@webmail.messagingengine.com> Message-ID: Random832 wrote: >>Well, your amp hours will be shittier with a lower voltage. > > Define "shittier". An incandescent flashlight (which consumes less power > at lower voltage) will last longer, but won't be as bright. If it's > still acceptably bright, that's not worse. I think the point is that the cell will deliver (at most) the same number of amp-hours at high load as low load, but if the voltage is lower, those amp-hours will represent less energy delivered to the load. An amp-hour that doesn't give you as much energy as you were expecting could be described as "shitty". :-) On top of that, the cell might deliver less amp-hours at high load, for bonus shittiness. -- Greg From breamoreboy at gmail.com Wed Jul 20 21:04:38 2016 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Wed, 20 Jul 2016 18:04:38 -0700 (PDT) Subject: can't add variables to instances of built-in classes In-Reply-To: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> <18acf908-b761-4a60-8d7c-5e4576b03320@googlegroups.com> <578f6a4f$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: <03ce3d45-aadb-46df-8d64-4e33ffd44825@googlegroups.com> On Wednesday, July 20, 2016 at 10:48:23 PM UTC+1, Lawrence D?Oliveiro wrote: > On Thursday, July 21, 2016 at 12:11:09 AM UTC+12, Steven D'Aprano wrote: > > > [long irrelevant rant deleted] > > Just because I pointed out what a load of nonsense you were spouting about __slots__, by giving a counterexample of their usefulness? Man, your pride must be hurt... I hereby request that the moderators take this idiot offline as he's managed to insult two highly respected members of this community in no time at all, those of course being Steven D'Aprano and Peter Otten. Kindest regards. Mark Lawrence. From michael.selik at gmail.com Wed Jul 20 21:54:46 2016 From: michael.selik at gmail.com (Michael Selik) Date: Wed, 20 Jul 2016 20:54:46 -0500 Subject: reversed(enumerate(x)) In-Reply-To: References: Message-ID: > On Jul 20, 2016, at 12:42 PM, Ian Kelly wrote: > > for i, n in reversed(enumerate(x)): pass > > fails with "TypeError: argument to reversed() must be a sequence". So make it a sequence: for i, n in reversed(list(enumerate(x))): pass If ``x`` is very large, you can use your zip/range technique to save memory. From rosuav at gmail.com Wed Jul 20 22:29:38 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Jul 2016 12:29:38 +1000 Subject: can't add variables to instances of built-in classes In-Reply-To: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> <18acf908-b761-4a60-8d7c-5e4576b03320@googlegroups.com> Message-ID: On Thu, Jul 21, 2016 at 8:11 AM, Lawrence D?Oliveiro wrote: > On Wednesday, July 20, 2016 at 9:16:30 PM UTC+12, Peter Otten wrote: >> >> 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. > > You mean, being able to dynamically add new attributes to an object? > > Probably not a good idea to mix that with read/write properties... This is exactly what Steven was talking about. If you can't handle dynamic read-write attributes (whether they're properties or simple attributes is orthogonal to this), why even use Python? You can get a linter to tell you about misspelled attribute names, which has a huge advantage over __slots__ in that it can give you the information prior to actually hitting that line of code (prior to even running the program - and some editors have integrated linters, so you don't even need to consciously run the linter, you just see the results as you type). That gives you virtually the same benefit as C/Java style of coding, where you're forced to declare all your members in the class; but as an added bonus, you can *dynamically add attributes*! Don't think that's useful? Well, the other day I wanted to add a wrapper around the constructor for someone else's object to stash a bit of extra information into it (to track down a resource leak - turned out there was an ever-growing collection of objects, because they weren't being removed from that object), and if I'd been using Java, the response would have been "no way does that even make sense". Thanks to dynamic code, I could do what I needed to and track down the leak. If the author of that object had used __slots__, though, I'd have been utterly stuck. Using __slots__ basically takes your object down to the level of a Java one. That's generally fine for something immutable (you really don't need to be adding attributes to the integer 42), but even with immutables, I've sometimes wanted to add hidden attributes; with mutable objects, it's common enough that you want to leave the option open unless you have good reason not to. And "my editor sucks" is not a good reason; nor is "my debugging skills suck". ChrisA From steve at pearwood.info Wed Jul 20 22:48:54 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 21 Jul 2016 12:48:54 +1000 Subject: can't add variables to instances of built-in classes References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> <18acf908-b761-4a60-8d7c-5e4576b03320@googlegroups.com> Message-ID: <57903817$0$1602$c3e8da3$5496439d@news.astraweb.com> On Thu, 21 Jul 2016 08:11 am, Lawrence D?Oliveiro wrote: > On Wednesday, July 20, 2016 at 9:16:30 PM UTC+12, Peter Otten wrote: >> >> 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. > > You mean, being able to dynamically add new attributes to an object? > > Probably not a good idea to mix that with read/write properties... Why not? If you're going to make a comment, would you please include some actual significant information in your post? Dropping obtuse hints and incomplete answers are not useful, and they give the strong impression that you are only replying in order to gain a smug sense of superiority rather than to disseminate knowledge and understanding. Remember that other people cannot know the thought in your mind, they can only judge by the actual words you have written, and if those words standing alone do not explain your thinking, then people will: (1) fail to understand the information you are trying to pass on; (2) imagine that you are intentionally trying to be difficult; and (3) characterise you as an insufferable, pretentious wanker who thinks that giving mysterious, unintelligible responses makes him out to be ever-so smarter than everyone else. Poor quality answer: "Probably not a good idea to mix that with read/write properties..." Better: "Probably not a good idea to mix that with read/write properties, for the following reasons: [succinct explanation of the reasons why one should avoid mixing ordinary attributes and properties]. Here's a longer discussion [link to URL]." -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Thu Jul 21 00:04:12 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 21 Jul 2016 14:04:12 +1000 Subject: What exactly is "exact" (was Clean Singleton Docstrings) References: <201607191635.45810.gheskett@shentel.net> <87bn1tql6h.fsf@elektro.pacujo.net> Message-ID: <579049be$0$1591$c3e8da3$5496439d@news.astraweb.com> On Wed, 20 Jul 2016 11:24 pm, alister wrote: > One of my biggest questions since the Brexit vote is can we g back to > using imperial weights & measures (please). I suppose you might as well -- there's no more empire, no more jobs or houses, and once the financial traders leave London there'll be no more money. When Scotland and Northern Ireland leaves there'll be no more United Kingdom either, and then you and the Welsh can sit around all day trying to remember how many cubic chains in a hogshead and the number of pints to a firkin, and blaming the perfidious French and cabbage-eating Huns for kicking you out of the EU against your will. England Prevails! -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Thu Jul 21 01:28:17 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 20 Jul 2016 22:28:17 -0700 (PDT) Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] In-Reply-To: <578f0f5c$0$11115$c3e8da3@news.astraweb.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> Message-ID: On Wednesday, July 20, 2016 at 11:13:05 AM UTC+5:30, Steven D'Aprano wrote: > On Tuesday 19 July 2016 14:58, Rustom Mody wrote: > > > So I again ask: You say ?"Never compare floats for equality" is a pernicious > > myth? > > It is the word *never* which makes it superstition. If people said "Take care > with using == for floats, its often not what you want" I would have no argument > with the statement. > > I'd even (reluctantly) accept "usually not what you want". But "never" is out- > and-out cargo-cult programming. You seem to not understand the realities of teaching. You (teacher in general) cannot say a saga; only epigrams You cannot transmit wisdom (even if you own some) just a bit of savviness/cleverness. So let me ask the question again differently: How many errors happen by people not using ?-neighborhood checks instead of == checks How many errors happen by the opposite (mis)use? IOW ?myth?... ok ?pernicious myth? Not BTW APL whose main domain of application is scientific chooses to enshrine this ?equality is ?-neighborhood checking not exact equality checking ? into its builtin ?==? And http://www.dyalog.com/uploads/documents/Papers/tolerant_comparison/tolerant_comparison.htm ? is spelt ?ct (Comparison Tolerance) And of course == is spelt = From rosuav at gmail.com Thu Jul 21 01:35:07 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Jul 2016 15:35:07 +1000 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] In-Reply-To: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> Message-ID: On Thu, Jul 21, 2016 at 3:28 PM, Rustom Mody wrote: > ? is spelt ?ct (Comparison Tolerance) > And of course == is spelt = spelt is spelled spelled. Unless, of course, you mean the wheat variety. ChrisA From rustompmody at gmail.com Thu Jul 21 01:38:10 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 20 Jul 2016 22:38:10 -0700 (PDT) Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] In-Reply-To: <87mvlcpd8g.fsf@elektro.pacujo.net> References: <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> <87r3aopg7k.fsf@elektro.pacujo.net> <87mvlcpd8g.fsf@elektro.pacujo.net> Message-ID: <6a6a2749-c2e1-42ca-923d-766b69fc35ad@googlegroups.com> On Wednesday, July 20, 2016 at 8:29:25 PM UTC+5:30, Marko Rauhamaa wrote: > Chris Angelico : > > > On Wed, Jul 20, 2016 at 11:54 PM, Marko Rauhamaa wrote: > >> 2. Floating-point numbers are *imperfect approximations* of real > >> numbers. Even when real numbers are derived exactly, > >> floating-point operations may introduce "lossy compression > >> artifacts" that have to be compensated for in application > >> programs. > > > > This is the kind of black FUD that has to be fought off. What > > "compression artifacts" are introduced? The *only* lossiness in IEEE > > binary floating-point arithmetic is rounding. > > You are joining me in spreading the FUD. Yes, the immediate lossiness is > rounding, but the effects of that rounding can result in atrocious > accumulative errors in numeric calculations. > > > Unless you are working with numbers that require more precision than > > you have available, the result should be perfectly accurate. > > Whoa, hold it there! Catastrophic cancellation ( https://en.wikipedia.org/wiki/Loss_of_significance>) is not a myth: Whose lead para starts: | Catastrophic cancellation? The effect is that the number of accurate | (significant) digits in the result is reduced unacceptably. Ways to avoid this | effect are studied in numerical analysis. I would go a step further: The field of numerical analysis came into existence only because this fact multiplied by the fact that computers do their (inaccurate ? inexact) computations billions of times faster than we do makes significance a very significant problem! From hjazz6 at ymail.com Thu Jul 21 01:44:41 2016 From: hjazz6 at ymail.com (Rayne) Date: Thu, 21 Jul 2016 05:44:41 +0000 (UTC) Subject: Python packages listed in PyPI References: <2005046224.2877266.1469079881286.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <2005046224.2877266.1469079881286.JavaMail.yahoo@mail.yahoo.com> Hi, May I know if the Python packages listed on the PyPI page (https://pypi.python.org/pypi) are OS-independent? That is, do I download and install the same package on both Windows and Linux systems? Thank you. Regards,Rayne From rustompmody at gmail.com Thu Jul 21 01:52:02 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 20 Jul 2016 22:52:02 -0700 (PDT) Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] In-Reply-To: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> Message-ID: <47de7a37-1cef-4698-890c-fca5e5449145@googlegroups.com> On Thursday, July 21, 2016 at 11:05:28 AM UTC+5:30, Chris Angelico wrote: > On Thu, Jul 21, 2016 at 3:28 PM, Rustom Mody wrote: > > ? is spelt ?ct (Comparison Tolerance) > > And of course == is spelt = > > spelt is spelled spelled. Unless, of course, you mean the wheat variety. Love it! Though not everyone agrees (including Australians!) http://english.stackexchange.com/questions/5712/spelt-vs-spelled Anyway... Ive been collecting quines/self-referential statements for classes on Theory of computation. Like these from Douglas Hofstadter. To which I?ll add yours You cant have ?your cake? and spell it ?too? You cant have your use and mention it too If this sentence were in Chinese it would say something else .siht ekil ti gnidaer eb d'uoy ,werbeH ni erew ecnetnes siht fI From petef4+usenet at gmail.com Thu Jul 21 02:19:32 2016 From: petef4+usenet at gmail.com (Pete Forman) Date: Thu, 21 Jul 2016 07:19:32 +0100 Subject: Python packages listed in PyPI References: <2005046224.2877266.1469079881286.JavaMail.yahoo.ref@mail.yahoo.com> <2005046224.2877266.1469079881286.JavaMail.yahoo@mail.yahoo.com> Message-ID: Rayne writes: > May I know if the Python packages listed on the PyPI page > (https://pypi.python.org/pypi) are OS-independent? That is, do I > download and install the same package on both Windows and Linux The simple answer is yes. pip install will find the appropriate implementation for your OS and version of Python. If the package is pure Python then it will be the same across OS. If there is some binary content then PyPI will deliver the correct wheel (precompiled) or C/C++ source. The latter generally builds OOTB on Linux but needs extra work on Windows as that does not bundle a compiler. -- Pete Forman From hjazz6 at ymail.com Thu Jul 21 02:28:37 2016 From: hjazz6 at ymail.com (Rayne) Date: Thu, 21 Jul 2016 06:28:37 +0000 (UTC) Subject: Python packages listed in PyPI In-Reply-To: References: <2005046224.2877266.1469079881286.JavaMail.yahoo.ref@mail.yahoo.com> <2005046224.2877266.1469079881286.JavaMail.yahoo@mail.yahoo.com> Message-ID: <1027565569.3146921.1469082517173.JavaMail.yahoo@mail.yahoo.com> Thanks! One more question: Does "pip install" require Internet to work? Or are all implementations already contained in the packages and so do not require additional downloads? From: Pete Forman To: python-list at python.org Sent: Thursday, July 21, 2016 2:19 PM Subject: Re: Python packages listed in PyPI Rayne writes: > May I know if the Python packages listed on the PyPI page > (https://pypi.python.org/pypi) are OS-independent? That is, do I > download and install the same package on both Windows and Linux The simple answer is yes. pip install will find the appropriate implementation for your OS and version of Python. If the package is pure Python then it will be the same across OS. If there is some binary content then PyPI will deliver the correct wheel (precompiled) or C/C++ source. The latter generally builds OOTB on Linux but needs extra work on Windows as that does not bundle a compiler. -- Pete Forman -- https://mail.python.org/mailman/listinfo/python-list From steve+comp.lang.python at pearwood.info Thu Jul 21 02:34:23 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 21 Jul 2016 16:34:23 +1000 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> Message-ID: <57906cf3$0$1501$c3e8da3$5496439d@news.astraweb.com> On Thursday 21 July 2016 15:28, Rustom Mody wrote: > On Wednesday, July 20, 2016 at 11:13:05 AM UTC+5:30, Steven D'Aprano wrote: >> On Tuesday 19 July 2016 14:58, Rustom Mody wrote: >> >> > So I again ask: You say ?"Never compare floats for equality" is a >> > pernicious myth? >> >> It is the word *never* which makes it superstition. If people said "Take >> care with using == for floats, its often not what you want" I would have no >> argument with the statement. >> >> I'd even (reluctantly) accept "usually not what you want". But "never" is >> out- and-out cargo-cult programming. > > You seem to not understand the realities of teaching. > You (teacher in general) cannot say a saga; only epigrams Is "Don't use exact equality unless you know what you're doing" enough of an epigram for you? > You cannot transmit wisdom (even if you own some) just a bit of > savviness/cleverness. Maybe so, but that's no excuse for transmitting outright misinformation and superstition. In physics, dealing with motion in the presence of energy losses is hard, and beginning and intermediate levels of physics will generally explicitly or implicitly ignore friction and air resistance. But physics teachers do not teach that "air resistance doesn't exist; you mustn't try to take friction into account". They teach that it is a simplification. > So let me ask the question again differently: > How many errors happen by people not using ?-neighborhood checks instead of > == checks How many errors happen by the opposite (mis)use? Precisely 35, and 17812, respectively. > IOW ?myth?... ok ?pernicious myth? Not > > BTW APL whose main domain of application is scientific chooses to enshrine > this ?equality is ?-neighborhood checking not exact equality checking ? into > its builtin ?==? I have a lot of respect for Ken Iverson, and a lot of admiration for language designers willing to experiment with alternate paradigms. But keeping in mind that in APL, if you set ?ct to 0 you get an exact comparison, can you find any quotes from Iverson saying that you should *never* perform exact equality comparisons? > And > http://www.dyalog.com/uploads/documents/Papers/tolerant_comparison/tolerant_comparison.htm Nice resource, thank you. > ? is spelt ?ct (Comparison Tolerance) > And of course == is spelt = -- Steve From ben+python at benfinney.id.au Thu Jul 21 02:35:51 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 21 Jul 2016 16:35:51 +1000 Subject: Python packages listed in PyPI References: <2005046224.2877266.1469079881286.JavaMail.yahoo.ref@mail.yahoo.com> <2005046224.2877266.1469079881286.JavaMail.yahoo@mail.yahoo.com> Message-ID: <85shv3qz08.fsf@benfinney.id.au> Rayne via Python-list writes: > May I know if the Python packages listed on the PyPI page > (https://pypi.python.org/pypi) are OS-independent? There is a Trove classifier, ?Operating System?, which allows the package maintainer to declare one or more specific operating systems. For example, a package might have the trove classifiers ?Operating System :: MacOS :: MacOS X? and ?Operating System :: POSIX?. That is a positive assertion from the package maintainer that those operating systems are supported. > That is, do I download and install the same package on both Windows > and Linux systems? You should use ?pip? to decide which specific file to download for your platform. -- \ ?How wonderful that we have met with a paradox. Now we have | `\ some hope of making progress.? ?Niels Bohr | _o__) | Ben Finney From steve+comp.lang.python at pearwood.info Thu Jul 21 02:36:27 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 21 Jul 2016 16:36:27 +1000 Subject: Python packages listed in PyPI References: <2005046224.2877266.1469079881286.JavaMail.yahoo.ref@mail.yahoo.com> <2005046224.2877266.1469079881286.JavaMail.yahoo@mail.yahoo.com> <1027565569.3146921.1469082517173.JavaMail.yahoo@mail.yahoo.com> Message-ID: <57906d6d$0$1501$c3e8da3$5496439d@news.astraweb.com> On Thursday 21 July 2016 16:28, Rayne wrote: > Thanks! One more question: Does "pip install" require Internet to work? Yes, you must have internet access. -- Steve From ben+python at benfinney.id.au Thu Jul 21 02:38:18 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 21 Jul 2016 16:38:18 +1000 Subject: Python packages listed in PyPI References: <2005046224.2877266.1469079881286.JavaMail.yahoo.ref@mail.yahoo.com> <2005046224.2877266.1469079881286.JavaMail.yahoo@mail.yahoo.com> <1027565569.3146921.1469082517173.JavaMail.yahoo@mail.yahoo.com> Message-ID: <85oa5rqyw5.fsf@benfinney.id.au> (Please don't top-post; instead, interleave your responses and trim material you're not responding to.) Rayne via Python-list writes: > Thanks! One more question: Does "pip install" require Internet to > work? Yes, ?pip? resolves the dependencies, download the files, and installs them. > Or are all implementations already contained in the packages and so do > not require additional downloads? I don't understand what difference you intend between ?implementations? and ?packages?. -- \ ?Pinky, are you pondering what I'm pondering?? ?Wuh, I think | `\ so, Brain, but burlap chafes me so.? ?_Pinky and The Brain_ | _o__) | Ben Finney From __peter__ at web.de Thu Jul 21 02:59:01 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 21 Jul 2016 08:59:01 +0200 Subject: can't add variables to instances of built-in classes References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> <18acf908-b761-4a60-8d7c-5e4576b03320@googlegroups.com> <578f6a4f$0$22142$c3e8da3$5496439d@news.astraweb.com> <03ce3d45-aadb-46df-8d64-4e33ffd44825@googlegroups.com> Message-ID: breamoreboy at gmail.com wrote: > I hereby request that the moderators take this idiot offline as he's Mark, please behave yourself. From hjazz6 at ymail.com Thu Jul 21 02:59:02 2016 From: hjazz6 at ymail.com (Rayne) Date: Thu, 21 Jul 2016 06:59:02 +0000 (UTC) Subject: Python packages listed in PyPI In-Reply-To: <85oa5rqyw5.fsf@benfinney.id.au> References: <2005046224.2877266.1469079881286.JavaMail.yahoo.ref@mail.yahoo.com> <2005046224.2877266.1469079881286.JavaMail.yahoo@mail.yahoo.com> <1027565569.3146921.1469082517173.JavaMail.yahoo@mail.yahoo.com> <85oa5rqyw5.fsf@benfinney.id.au> Message-ID: <1045501676.2853648.1469084342401.JavaMail.yahoo@mail.yahoo.com> "I don't understand what difference you intend between ?implementations? and ?packages?." I meant whether the package is self-contained, that is, all the different implementations for different OS and versions of Python are already contained in the package itself. But you've already answered my question that additional downloads of the correct version for specific OS and Python version is required. From marko at pacujo.net Thu Jul 21 03:52:31 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 21 Jul 2016 10:52:31 +0300 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] References: <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> <87r3aopg7k.fsf@elektro.pacujo.net> <87mvlcpd8g.fsf@elektro.pacujo.net> <6a6a2749-c2e1-42ca-923d-766b69fc35ad@googlegroups.com> Message-ID: <87h9bjpgw0.fsf@elektro.pacujo.net> Rustom Mody : > The field of numerical analysis came into existence only because this > fact multiplied by the fact that computers do their (inaccurate ? > inexact) computations billions of times faster than we do makes > significance a very significant problem! A couple of related anecdotes involving integer errors. 1. I worked on a (video) product that had to execute a piece of code every 7 ?s or so. A key requirement was that the beat must not drift far apart from the ideal over time. At first I thought the traditional nanosecond resolution would be sufficient for the purpose but then made a calculation: maximum rounding error = 0.5 ns/7 ?s = 70 ?s/s = 6 s/day That's why I decided to calculate the interval down to a femtosecond, whose error was well within our tolerance. 2. After running the LXDE GUI on my 32-bit Linux environment for some time, the CPU utilization monitor showed the CPU was mysteriously doing work 100% of the time. The only way out was to reboot the machine. After a few months and a few reboots, I investigated the situation more carefully. It turned out LXDE's CPU meter was reading jiffy counts from a textual /proc file with scanf("%ld"). Jiffies start from 0 at the time of the boot and increment every millisecond. Thus, the maximum signed 32-bit integer is reached in less than 25 days. When scanf("%ld") overflows, it sets the value to MAX_LONG. That effectively meant time stopped going forward and all rate calculations would shoot through the roof. This problem would not have occurred if the C standard consistently specified modulo arithmetics for integer operations. The solution was to use scanf("%lld") instead. Marko From rosuav at gmail.com Thu Jul 21 04:46:44 2016 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Jul 2016 18:46:44 +1000 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] In-Reply-To: <87h9bjpgw0.fsf@elektro.pacujo.net> References: <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> <87r3aopg7k.fsf@elektro.pacujo.net> <87mvlcpd8g.fsf@elektro.pacujo.net> <6a6a2749-c2e1-42ca-923d-766b69fc35ad@googlegroups.com> <87h9bjpgw0.fsf@elektro.pacujo.net> Message-ID: On Thu, Jul 21, 2016 at 5:52 PM, Marko Rauhamaa wrote: > A couple of related anecdotes involving integer errors. > > 1. I worked on a (video) product that had to execute a piece of code > every 7 ?s or so. A key requirement was that the beat must not drift > far apart from the ideal over time. At first I thought the > traditional nanosecond resolution would be sufficient for the purpose > but then made a calculation: > > maximum rounding error = 0.5 ns/7 ?s > = 70 ?s/s > = 6 s/day > > That's why I decided to calculate the interval down to a femtosecond, > whose error was well within our tolerance. I'd be curious to know whether, had you used nanosecond resolution, you ever would have seen anything like that +/- 6s/day error. One convenient attribute of the real world [1] is that, unless there's a good reason for it to do otherwise [2], random error will tend to cancel out rather than accumulate. With error of +/- 0.5 ns, assume (for the sake of argument) that the actual error at each measurement is random.choice((-0.4, -0.3, -0.2, -0.1, 0.1, 0.2, 0.3, 0.4)) ns, with zero and the extremes omitted to make the calculations simpler. In roughly twelve billion randomizations (86400 seconds divided by 7?s), the chances of having more than one billion more positive than negative are... uhh.... actually, I don't know how to calculate probabilities off numbers that big, but pretty tiny. So you're going to have at least 5.5 billion negatives to offset your positives (or positives to offset your negatives, same diff); more likely they'll be even closer. So if you have (say) 5.5 to 6.5 ratio of signs, what you're actually working with is half a second per day of accumulated error - and I think you'd have a pretty tiny probability of even *that* extreme a result. If it's more like 5.9 to 6.1, you'd have 0.1 seconds per day of error, at most. Plus, the same probabilistic calculation can be done for days across a month, so even though the theory would let you drift by three minutes a month, the chances of shifting by even an entire second over that time are fairly slim. This is something where I'd be more worried about systematic bias in the code than anything from measurement or rounding error. (I don't believe I've ever actually used a computer that's capable of nanosecond-accurate time calculations. Generally they return time in nanoseconds for consistency, but they won't return successive integer values. You must have been on some seriously high-end hardware - although that doesn't surprise me much, given that you were working on a video product.) ChrisA [1] Believe you me, it has no shortage of INconvenient attributes, so it's nice to have one swing the balance back a bit! [2] If there's systematic error - if your 7 ?s is actually averaging 7.25 ?s - you need to deal with that separately. From petef4+usenet at gmail.com Thu Jul 21 05:04:15 2016 From: petef4+usenet at gmail.com (Pete Forman) Date: Thu, 21 Jul 2016 10:04:15 +0100 Subject: Python packages listed in PyPI In-Reply-To: <1027565569.3146921.1469082517173.JavaMail.yahoo@mail.yahoo.com> References: <2005046224.2877266.1469079881286.JavaMail.yahoo.ref@mail.yahoo.com> <2005046224.2877266.1469079881286.JavaMail.yahoo@mail.yahoo.com> <1027565569.3146921.1469082517173.JavaMail.yahoo@mail.yahoo.com> Message-ID: On 21 July 2016 at 07:28, Rayne wrote: > Thanks! One more question: Does "pip install" require Internet to work? Or > are all implementations already contained in the packages and so do not > require additional downloads? > pip install is downloading from https://pypi.python.org so yes you do need internet access. Having said that there are a couple of ways to feed pip. You can run a local pypi server to host previously downloaded packages or tell pip to install from a file. "pip help install" Automatic handling of additional downloads is automatic in pip. If the package you are installing requires some other packages then it will install those too. -- Pete Forman From marko at pacujo.net Thu Jul 21 05:09:13 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 21 Jul 2016 12:09:13 +0300 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] References: <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> <87r3aopg7k.fsf@elektro.pacujo.net> <87mvlcpd8g.fsf@elektro.pacujo.net> <6a6a2749-c2e1-42ca-923d-766b69fc35ad@googlegroups.com> <87h9bjpgw0.fsf@elektro.pacujo.net> Message-ID: <8760rzpdc6.fsf@elektro.pacujo.net> Chris Angelico : > On Thu, Jul 21, 2016 at 5:52 PM, Marko Rauhamaa wrote: >> A couple of related anecdotes involving integer errors. >> >> 1. I worked on a (video) product that had to execute a piece of code >> every 7 ?s or so. A key requirement was that the beat must not drift >> far apart from the ideal over time. At first I thought the >> traditional nanosecond resolution would be sufficient for the purpose >> but then made a calculation: >> >> maximum rounding error = 0.5 ns/7 ?s >> = 70 ?s/s >> = 6 s/day >> >> That's why I decided to calculate the interval down to a femtosecond, >> whose error was well within our tolerance. > > I'd be curious to know whether, had you used nanosecond resolution, > you ever would have seen anything like that +/- 6s/day error. One > convenient attribute of the real world [1] is that, unless there's a > good reason for it to do otherwise [2], random error will tend to > cancel out rather than accumulate. With error of +/- 0.5 ns, assume > (for the sake of argument) that the actual error at each measurement > is random.choice((-0.4, -0.3, -0.2, -0.1, 0.1, 0.2, 0.3, 0.4)) ns, No, this is a systematic error due to the rounding of a rational number to the nearest nanosecond interval. Systematic errors of this kind are a real thing and not even all that uncommon. > (I don't believe I've ever actually used a computer that's capable of > nanosecond-accurate time calculations. Generally they return time in > nanoseconds for consistency, but they won't return successive integer > values. You must have been on some seriously high-end hardware - > although that doesn't surprise me much, given that you were working on > a video product.) Nanosecond, even femtosecond, calculations are trivially simple integer arithmetics that can be performed with pencil and paper. The hardware was nothing fancy, and the timing error due to various hardware, software and network realities was in the order of ?100 ?s. That was tolerable and could be handled through buffering. However, a cumulative error of 6 seconds per day was *not* tolerable. The calculations needed to be extremely simple because the interrupt routine had to execute every 7 microseconds. You had to let the hardware RTC do most of the work and do just a couple of integer operations in the interrupt routine. In particular, you didn't have time to recalculate and reprogram the RTC at every interrupt. Marko From rustompmody at gmail.com Thu Jul 21 09:14:15 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 21 Jul 2016 06:14:15 -0700 (PDT) Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] In-Reply-To: <57906cf3$0$1501$c3e8da3$5496439d@news.astraweb.com> References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <57906cf3$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, July 21, 2016 at 12:04:35 PM UTC+5:30, Steven D'Aprano wrote: > On Thursday 21 July 2016 15:28, Rustom Mody wrote: > > BTW APL whose main domain of application is scientific chooses to enshrine > > this ?equality is ?-neighborhood checking not exact equality checking ? into > > its builtin ?==? > > I have a lot of respect for Ken Iverson, and a lot of admiration for language > designers willing to experiment with alternate paradigms. This choice has significant(!!) costs: Fuzzy equality is not transitive: One can get a = b ? b = c ? a ? c > > But keeping in mind that in APL, if you set ?ct to 0 you get an exact > comparison, can you find any quotes from Iverson saying that you should *never* > perform exact equality comparisons? There you go with your strawmen! Remember it was you (and Chris) who expressed extreme positions: ?Pernicious myth? ?FUD? etc From puravnshah at gmail.com Thu Jul 21 09:39:54 2016 From: puravnshah at gmail.com (puravnshah at gmail.com) Date: Thu, 21 Jul 2016 06:39:54 -0700 (PDT) Subject: How to do Integration testing of a C code/firmware in python Message-ID: I am doing an Internship at a company. I have a multi threaded code/firmware in c. I have done its unit testing with cantata in c++ and now want to do Integration testing in python with the device connected to my PC. From where do I start. How and what to write. The code has various functions with sensor, adc,dac, etc If any more info let me know I am a newbie with no experience so let me know if any mistake From sigmaphine1914 at gmail.com Thu Jul 21 09:56:25 2016 From: sigmaphine1914 at gmail.com (sigmaphine1914 at gmail.com) Date: Thu, 21 Jul 2016 06:56:25 -0700 (PDT) Subject: Ide or code editor confusion Message-ID: <2184a0ad-9d51-42db-ae11-5d0ab4512582@googlegroups.com> I'm learning Python and something is really unclear on the chapter im on. So Python has its own IDE to write code but now it's talking about "code editors" My confusion is so I need a code editor like Sublime text? Is that what Python IDE is for? From rosuav at gmail.com Thu Jul 21 10:07:17 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jul 2016 00:07:17 +1000 Subject: Ide or code editor confusion In-Reply-To: <2184a0ad-9d51-42db-ae11-5d0ab4512582@googlegroups.com> References: <2184a0ad-9d51-42db-ae11-5d0ab4512582@googlegroups.com> Message-ID: On Thu, Jul 21, 2016 at 11:56 PM, wrote: > I'm learning Python and something is really unclear on the chapter im on. > > So Python has its own IDE to write code but now it's talking about "code editors" > > My confusion is so I need a code editor like Sublime text? Is that what Python IDE is for? You can use any text editor to write your Python code. If you're using nothing except Python, IDLE is excellent, but if you work with several different languages, you may prefer Sublime, or Atom, or SciTE, or GNU Nano, or something else. You can pick up pretty much any text editor (not a word processor, and not Windows Notepad, but virtually anything else will do) and use that to work on your code. Without knowing what chapter of what book you're reading, I can't advise any further. ChrisA From sigmaphine1914 at gmail.com Thu Jul 21 10:22:45 2016 From: sigmaphine1914 at gmail.com (sigmaphine1914 at gmail.com) Date: Thu, 21 Jul 2016 07:22:45 -0700 (PDT) Subject: Ide or code editor confusion In-Reply-To: References: <2184a0ad-9d51-42db-ae11-5d0ab4512582@googlegroups.com> Message-ID: <7f142caf-5e3c-4fcf-818a-017b593fd0f7@googlegroups.com> Beginning Python: using Python 2.6 and Python 3.1. By James Payne Part II. But I think that answered my question. Great because au was worried From python at mrabarnett.plus.com Thu Jul 21 10:27:15 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 21 Jul 2016 15:27:15 +0100 Subject: Ide or code editor confusion In-Reply-To: References: <2184a0ad-9d51-42db-ae11-5d0ab4512582@googlegroups.com> Message-ID: On 2016-07-21 15:07, Chris Angelico wrote: > On Thu, Jul 21, 2016 at 11:56 PM, wrote: >> I'm learning Python and something is really unclear on the chapter im on. >> >> So Python has its own IDE to write code but now it's talking about "code editors" >> >> My confusion is so I need a code editor like Sublime text? Is that what Python IDE is for? > > You can use any text editor to write your Python code. If you're using > nothing except Python, IDLE is excellent, but if you work with several > different languages, you may prefer Sublime, or Atom, or SciTE, or GNU > Nano, or something else. You can pick up pretty much any text editor > (not a word processor, and not Windows Notepad, but virtually anything > else will do) and use that to work on your code. > > Without knowing what chapter of what book you're reading, I can't > advise any further. > The key is that the editor should work with "plain text". A "code editor" is one that works with plain text, but has been designed with programming in mind. It will have useful features such as syntax colouring (different colours for reserved words, strings, ...), case conversion, easy indentation of multiple lines, and so on. From jussi.piitulainen at helsinki.fi Thu Jul 21 10:31:49 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 21 Jul 2016 17:31:49 +0300 Subject: Ide or code editor confusion References: <2184a0ad-9d51-42db-ae11-5d0ab4512582@googlegroups.com> Message-ID: sigmaphine1914 at gmail.com writes: > I'm learning Python and something is really unclear on the chapter im > on. > > So Python has its own IDE to write code but now it's talking about > "code editors" > > My confusion is so I need a code editor like Sublime text? Is that > what Python IDE is for? You need a code editor that you are comfortable with. If you are already comfortable with this IDE thing that you talk about, you can use it as your code editor. You can also use some other editor. If you like. If you are curious. Even one that doesn't know about Python (but those who claim to edit code by moving magnets over the hard disk are only joking. That's not done). From rosuav at gmail.com Thu Jul 21 10:37:56 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jul 2016 00:37:56 +1000 Subject: Ide or code editor confusion In-Reply-To: <7f142caf-5e3c-4fcf-818a-017b593fd0f7@googlegroups.com> References: <2184a0ad-9d51-42db-ae11-5d0ab4512582@googlegroups.com> <7f142caf-5e3c-4fcf-818a-017b593fd0f7@googlegroups.com> Message-ID: On Fri, Jul 22, 2016 at 12:22 AM, wrote: > Beginning Python: using Python 2.6 and Python 3.1. By James Payne > > Part II. > > But I think that answered my question. Great because au was worried Ugh, that's extremely old now. The current versions of Python are 2.7 (first released in 2010, and getting periodic bugfix releases) and 3.5 (released 2015, and also getting bugfix releases). I strongly recommend you use a newer version - either 3.4 or 3.5, one of which will be available in most Linux repositories. You can always grab the latest from python.org. If you can't find a book that makes use of 3.4+, ask around; there are quite a few books which have been updated to that. The feature difference between 3.1 and 3.5 is huge. ChrisA From python at bdurham.com Thu Jul 21 10:42:21 2016 From: python at bdurham.com (Malcolm Greene) Date: Thu, 21 Jul 2016 10:42:21 -0400 Subject: Technique for safely reloading dynamically generated module Message-ID: <1469112141.379402.672830825.05659985@webmail.messagingengine.com> 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 regeneration. Is this process is simple as the following pseudo code or are there other issues we need to be aware of? Are there better techniques for this workflow (eval, compile, etc)? We're working in Python 3.5.1. import importlib # custom_code is the module our code will generate - a version of this # file will always be present # if custom_code.py is missing, a blank version of this file is created # before this step import custom_code while True: # (re)generates custom_code.py visible in sys.path generate_custom_code( source_file ) # reload the module whose source we just generated importlib.reload( custom_code ) # run the main code in generated module custom_code.go() Thank you, Malcolm ? From rosuav at gmail.com Thu Jul 21 10:55:08 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jul 2016 00:55:08 +1000 Subject: Technique for safely reloading dynamically generated module In-Reply-To: <1469112141.379402.672830825.05659985@webmail.messagingengine.com> References: <1469112141.379402.672830825.05659985@webmail.messagingengine.com> Message-ID: On Fri, Jul 22, 2016 at 12:42 AM, 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 regeneration. Is > this process is simple as the following pseudo code or are there other > issues we need to be aware of? Are there better techniques for this > workflow (eval, compile, etc)? > > We're working in Python 3.5.1. > > import importlib > > # custom_code is the module our code will generate - a version of this > # file will always be present > # if custom_code.py is missing, a blank version of this file is created > # before this step > import custom_code > > while True: > # (re)generates custom_code.py visible in sys.path > generate_custom_code( source_file ) > > # reload the module whose source we just generated > importlib.reload( custom_code ) > > # run the main code in generated module > custom_code.go() > I would avoid importlib.reload() if I can. Using compile/eval is probably more effective; you might need to change how the module gets organized, but if you already require a go() function, that's probably enough. Something like this: while True: python_code = generate_custom_code(source_file) ns = {} exec(python_code, ns) ns["go"]() (Presumably your go() function doesn't return until you want to regenerate the code?) Personally, what I'd do is have an initializer function, and have that register the module in whatever way is appropriate (eg some sort of "handle_request" function). Then the main program runs an event loop, everything's handled asynchronously, and you can have either a file system trigger "this file has changed, go and regenerate it" or an explicit action by the admin to regenerate. But definitely I'd craft the source code as a string, not writing anything to disk, and exec it directly; the import machinery is unnecessary here. ChrisA From __peter__ at web.de Thu Jul 21 11:40:16 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 21 Jul 2016 17:40:16 +0200 Subject: Technique for safely reloading dynamically generated module References: <1469112141.379402.672830825.05659985@webmail.messagingengine.com> Message-ID: 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 regeneration. Is > this process is simple as the following pseudo code or are there other > issues we need to be aware of? Are there better techniques for this > workflow (eval, compile, etc)? > > We're working in Python 3.5.1. > > import importlib > > # custom_code is the module our code will generate - a version of this > # file will always be present > # if custom_code.py is missing, a blank version of this file is created > # before this step > import custom_code > > while True: > # (re)generates custom_code.py visible in sys.path > generate_custom_code( source_file ) > > # reload the module whose source we just generated > importlib.reload( custom_code ) > > # run the main code in generated module > custom_code.go() If the go() function in that loop is the only place where the generated module is used you can avoid writing code to the file system altogether. Here's a really simple alternative suggestion based on exec(): SOURCEFILE = "whatever.dsl" def make_func(sourcefile): ns = {} exec(generated_code(sourcefile), ns) return ns["go"] def generated_code(sourcefile): # placeholder for your actual source generation return """ def go(): print("Generated from", {!r}) """.format(sourcefile) while True: # XXX should we wait for updates of sourcefile here? go = make_func(SOURCEFILE) go() From python at bdurham.com Thu Jul 21 12:07:45 2016 From: python at bdurham.com (Malcolm Greene) Date: Thu, 21 Jul 2016 12:07:45 -0400 Subject: Technique for safely reloading dynamically generated module In-Reply-To: References: <1469112141.379402.672830825.05659985@webmail.messagingengine.com> Message-ID: <1469117265.403838.672932729.2B34F311@webmail.messagingengine.com> Thank you Chris and Peter. The source file we're generating has one main function (go) with some supporting functions and classes as well. Will there be any problems referencing additional functions or classes defined in the source that gets passed to exec ... as long as references to those functions and classes happen within the generated module? I assume that one downside to the exec() approach is that there is no persistent namespace for this code's functions and classes, eg. after the exec() completes, its namespace disappears and is not available to code that follows? The Python documentation also warns: "Be aware that the return and yield statements may not be used outside of function definitions even within the context of code passed to the exec() function. The return value is None." Malcolm From steve at pearwood.info Thu Jul 21 12:10:18 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 22 Jul 2016 02:10:18 +1000 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] References: <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <57906cf3$0$1501$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5790f3eb$0$1618$c3e8da3$5496439d@news.astraweb.com> On Thu, 21 Jul 2016 11:14 pm, Rustom Mody wrote: > On Thursday, July 21, 2016 at 12:04:35 PM UTC+5:30, Steven D'Aprano wrote: >> On Thursday 21 July 2016 15:28, Rustom Mody wrote: >> > BTW APL whose main domain of application is scientific chooses to >> > enshrine this ?equality is ?-neighborhood checking not exact equality >> > checking ? into its builtin ?==? >> >> I have a lot of respect for Ken Iverson, and a lot of admiration for >> language designers willing to experiment with alternate paradigms. > > This choice has significant(!!) costs: Fuzzy equality is not transitive: > One can get > a = b ? b = c ? a ? c >> >> But keeping in mind that in APL, if you set ?ct to 0 you get an exact >> comparison, can you find any quotes from Iverson saying that you should >> *never* perform exact equality comparisons? > > There you go with your strawmen! > Remember it was you (and Chris) who expressed extreme positions: > ?Pernicious myth? ?FUD? etc And YOU'RE the one who is raising APL as an argument *against* my characterisation. Do you think that Iverson would agree with the conventional wisdom that we should NEVER test floats for exact equality? Do you know of ANY expert in numeric computation who will agree with the conventional wisdom? If so, who? I'll admit that I've stolen my description of this rule as "superstition" from perhaps the world's foremost authority on numeric computation, Professor William Kahan. (See the forward to "Apple Numerics Manual, Second Edition, 1988.) You don't like my use of the term "pernicious"? In my opinion, any conventional wisdom which keeps people *more* rather than *less* ignorant is pernicious. Anything which discourages them from testing their numeric functions to the full precision possible is pernicious. Anything which encourages the idea that numeric computation using floats is non-deterministic is pernicious. But if you don't agree, feel free to dismiss the word as mere hyperbola and MOVE ON. You don't have to nit pick about every word I use. The bottom line is, while it is often true that using exact equality is going to surprise people, the conventional wisdom to NEVER do so is both (1) factually wrong, there are plenty of examples where one can and should use exact equality, and (2) rather useless, as the conventional wisdom gives no clue as to the practicalities of what to replace it with. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ian.g.kelly at gmail.com Thu Jul 21 12:13:51 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 21 Jul 2016 10:13:51 -0600 Subject: reversed(enumerate(x)) In-Reply-To: <1469042171.969423.672037929.5B2B15E7@webmail.messagingengine.com> References: <1469042171.969423.672037929.5B2B15E7@webmail.messagingengine.com> Message-ID: On Wed, Jul 20, 2016 at 1:16 PM, Random832 wrote: > On Wed, Jul 20, 2016, at 13:42, Ian Kelly wrote: >> I had occasion to write something like this: >> >> for i, n in reversed(enumerate(x)): pass >> >> How would you write this? > > I'd write my own version of enumerate with a step argument, and call > enumerate(reversed(x), start=len(x), step=-1) Makes it a little too easy to commit an off-by-one error, I think. As you did here. From rosuav at gmail.com Thu Jul 21 12:16:39 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jul 2016 02:16:39 +1000 Subject: Technique for safely reloading dynamically generated module In-Reply-To: <1469117265.403838.672932729.2B34F311@webmail.messagingengine.com> References: <1469112141.379402.672830825.05659985@webmail.messagingengine.com> <1469117265.403838.672932729.2B34F311@webmail.messagingengine.com> Message-ID: On Fri, Jul 22, 2016 at 2:07 AM, Malcolm Greene wrote: > The source file we're generating has one main function (go) with some > supporting functions and classes as well. Will there be any problems > referencing additional functions or classes defined in the source that > gets passed to exec ... as long as references to those functions and > classes happen within the generated module? > > I assume that one downside to the exec() approach is that there is no > persistent namespace for this code's functions and classes, eg. after > the exec() completes, its namespace disappears and is not available to > code that follows? Functions keep references to their globals, so you should be safe. > The Python documentation also warns: "Be aware that the return and yield > statements may not be used outside of function definitions even within > the context of code passed to the exec() function. The return value is > None." Yeah, that's just emphasizing that exec() is looking for module-level code. Just as you can't put a flush-left "return" statement into a .py file, you can't use one in exec(). As long as your code builder is returning a string equivalent to what you'd find in an actual Python module (that is, exactly what it's already doing, given that you currently attempt to import it), you'll be fine. ChrisA From ian.g.kelly at gmail.com Thu Jul 21 12:25:48 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 21 Jul 2016 10:25:48 -0600 Subject: reversed(enumerate(x)) In-Reply-To: References: Message-ID: On Wed, Jul 20, 2016 at 11:54 AM, Brendan Abel <007brendan at gmail.com> wrote: > You could create your own generator that wraps enumerate > > def reverse_enumerate(iterable): > for i, val in enumerate(reversed(iterable)): > yield len(iterable) - 1 - i, val > > for i, val in reverse_enumerate(x): > ... Thanks, I like this. But I think I'll define it as: def reverse_enumerate(sequence): return zip(reversed(range(len(sequence))), reversed(sequence)) To avoid performing the loop in Python. From python at bdurham.com Thu Jul 21 12:51:04 2016 From: python at bdurham.com (Malcolm Greene) Date: Thu, 21 Jul 2016 12:51:04 -0400 Subject: Max size of Python source code and compiled equivalent Message-ID: <1469119864.416096.672987297.69184C7E@webmail.messagingengine.com> 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 documentation that covers max Python source (*.py) and compiled file (*.pyc) sizes without success. Any tips on where to look for this information? Background: Python 3.5.1 on Linux. Thank you, Malcolm From rosuav at gmail.com Thu Jul 21 13:08:22 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jul 2016 03:08:22 +1000 Subject: Max size of Python source code and compiled equivalent In-Reply-To: <1469119864.416096.672987297.69184C7E@webmail.messagingengine.com> References: <1469119864.416096.672987297.69184C7E@webmail.messagingengine.com> Message-ID: On Fri, Jul 22, 2016 at 2:51 AM, 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 documentation that > covers max Python source (*.py) and compiled file (*.pyc) sizes without > success. Any tips on where to look for this information? Heh, great question, and I'm curious too! But one place to get a bit more info is the standard library. rosuav at sikorsky:~/cpython/Lib$ find -name \*.py|xargs ls -lS|head -rw-r--r-- 1 rosuav rosuav 624122 Jul 17 17:38 ./pydoc_data/topics.py -rw-r--r-- 1 rosuav rosuav 229348 Jun 15 23:20 ./_pydecimal.py -rw-r--r-- 1 rosuav rosuav 210900 Jul 21 22:41 ./test/test_decimal.py -rw-r--r-- 1 rosuav rosuav 205399 Jun 15 23:20 ./test/test_email/test_email.py -rw-r--r-- 1 rosuav rosuav 203297 Jun 23 13:22 ./test/test_socket.py -rw-r--r-- 1 rosuav rosuav 183195 Jul 17 17:38 ./test/test_descr.py -rw-r--r-- 1 rosuav rosuav 166684 Jun 29 16:26 ./tkinter/__init__.py -rw-r--r-- 1 rosuav rosuav 164583 Jun 15 23:20 ./test/test_argparse.py -rw-r--r-- 1 rosuav rosuav 162603 Jun 15 23:20 ./test/test_buffer.py -rw-r--r-- 1 rosuav rosuav 159528 Jun 15 23:20 ./test/datetimetester.py rosuav at sikorsky:~/cpython/Lib$ find -name \*.pyc|xargs ls -lS|head -rw-r--r-- 1 rosuav rosuav 387893 Jul 22 00:03 ./pydoc_data/__pycache__/topics.cpython-36.pyc -rw-r--r-- 1 rosuav rosuav 231742 Jul 18 12:45 ./test/__pycache__/test_descr.cpython-36.pyc -rw-r--r-- 1 rosuav rosuav 202168 Jul 11 12:40 ./test/test_email/__pycache__/test_email.cpython-36.pyc -rw-r--r-- 1 rosuav rosuav 179521 Jul 11 12:40 ./tkinter/__pycache__/__init__.cpython-36.pyc -rw-r--r-- 1 rosuav rosuav 178331 Jul 11 12:40 ./test/__pycache__/test_socket.cpython-36.pyc -rw-r--r-- 1 rosuav rosuav 166424 Jul 11 12:40 ./test/__pycache__/test_argparse.cpython-36.pyc -rw-r--r-- 1 rosuav rosuav 162697 Jul 11 12:40 ./__pycache__/_pydecimal.cpython-36.pyc -rw-r--r-- 1 rosuav rosuav 160564 Jul 22 00:04 ./test/__pycache__/test_decimal.cpython-36.pyc -rw-r--r-- 1 rosuav rosuav 157038 Jul 11 12:40 ./test/__pycache__/test_inspect.cpython-36.pyc -rw-r--r-- 1 rosuav rosuav 149682 Jul 11 12:41 ./lib2to3/tests/__pycache__/test_fixers.cpython-36.pyc So you can have 600KB of source code or 350KB of pyc without any trouble whatsoever. (You won't actually be using .pyc files if you use exec as recommended in the other thread, but it's still a reasonable way of estimating compiled size.) If there are limits, they're certainly no lower than this. ChrisA From python at bdurham.com Thu Jul 21 13:27:59 2016 From: python at bdurham.com (Malcolm Greene) Date: Thu, 21 Jul 2016 13:27:59 -0400 Subject: Max size of Python source code and compiled equivalent In-Reply-To: References: <1469119864.416096.672987297.69184C7E@webmail.messagingengine.com> Message-ID: <1469122079.424705.673026689.0541FBF5@webmail.messagingengine.com> > Heh, great question, and I'm curious too! But one place to get a bit more info is the standard library. > > rosuav at sikorsky:~/cpython/Lib$ find -name \*.py|xargs ls -lS|head > -rw-r--r-- 1 rosuav rosuav 624122 Jul 17 17:38 ./pydoc_data/topics.py Brilliant! :) Thanks Chris! Malcolm From tjreedy at udel.edu Thu Jul 21 13:32:36 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 21 Jul 2016 13:32:36 -0400 Subject: Technique for safely reloading dynamically generated module In-Reply-To: <1469117265.403838.672932729.2B34F311@webmail.messagingengine.com> References: <1469112141.379402.672830825.05659985@webmail.messagingengine.com> <1469117265.403838.672932729.2B34F311@webmail.messagingengine.com> Message-ID: On 7/21/2016 12:07 PM, Malcolm Greene wrote: > I assume that one downside to the exec() approach is that there is no > persistent namespace for this code's functions and classes, eg. after > the exec() completes, its namespace disappears and is not available to > code that follows? Objects only disappear when no references are left. So it is up to you whether you drop the namespace and use a new one for the next exec call or whether you use the same namespace over and over. IDLE's run module does the latter. Simplified, IDLE's Shell simulates the interactive interpreter by sending user input to this code in the run module. main = fake_main() # with __name__ = '__main__', __builtins__ = ... while True: try: code = user_input() exec(code, main) except BaseException as e: handle_exception(e) -- Terry Jan Reedy From __peter__ at web.de Thu Jul 21 14:17:49 2016 From: __peter__ at web.de (Peter Otten) Date: Thu, 21 Jul 2016 20:17:49 +0200 Subject: Max size of Python source code and compiled equivalent References: <1469119864.416096.672987297.69184C7E@webmail.messagingengine.com> Message-ID: 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 documentation that > covers max Python source (*.py) and compiled file (*.pyc) sizes without > success. Any tips on where to look for this information? > > Background: Python 3.5.1 on Linux. I don't know if/where this is documented, but there are structural limits: >>> def nested(N): ... return "".join(" " * i + "if 1:\n" for i in range(N)) + " " * N + "print('hi')" ... >>> print(nested(3)) if 1: if 1: if 1: print('hi') >>> exec(nested(99)) hi >>> exec(nested(100)) Traceback (most recent call last): File "", line 1, in File "", line 101 print('hi') ^ IndentationError: too many levels of indentation From ben.usenet at bsb.me.uk Thu Jul 21 19:54:35 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Fri, 22 Jul 2016 00:54:35 +0100 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] References: <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8760rybl8k.fsf@bsb.me.uk> Steven D'Aprano writes: > Or you might be using a language like Javascript, which intentionally has > only floats for numbers. That's okay, you can still perform exact integer > arithmetic, so long as you stay within the bounds of ?2**16. Small point: it's 2**52. -- Ben. From ckaynor at zindagigames.com Thu Jul 21 20:43:15 2016 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Thu, 21 Jul 2016 17:43:15 -0700 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] In-Reply-To: <8760rybl8k.fsf@bsb.me.uk> References: <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> <8760rybl8k.fsf@bsb.me.uk> Message-ID: On Thu, Jul 21, 2016 at 4:54 PM, Ben Bacarisse wrote: > Steven D'Aprano writes: > > > Or you might be using a language like Javascript, which intentionally has > > only floats for numbers. That's okay, you can still perform exact integer > > arithmetic, so long as you stay within the bounds of ?2**16. > > Small point: it's 2**52. > If you really want to be picky, it is 2**53, inclusive: >>> 2**53-2.0 9007199254740990.0 >>> 2**53-1.0 9007199254740991.0 >>> 2**53+0.0 # Can no longer store odd numbers, but 2**53 is even so it can still be stored. 9007199254740992.0 >>> 2**53+1.0 9007199254740992.0 >>> 2**53+2.0 9007199254740994.0 This works as there is an implied one bit in the field for floats, giving 53 bits of storage despite only having 52 bits of storage. As the sign is stored in a separate bit, the same limit applies to both positive and negative numbers. From sigmaphine1914 at gmail.com Thu Jul 21 22:27:38 2016 From: sigmaphine1914 at gmail.com (sigmaphine1914 at gmail.com) Date: Thu, 21 Jul 2016 19:27:38 -0700 (PDT) Subject: learning python. learning defining functions . need help Message-ID: <432aeb03-ea14-4ece-8e5b-a7521cf12b84@googlegroups.com> having a little trouble with defining functions. i have a doc called ch5.py and when i was trying the following i had issues " Try It Out: Defining a Function Try saving the following in your file for Chapter 5, ch5.py.def in_fridge(): try: count = fridge[wanted_food] except KeyError: count = 0 return count How It Works When you invoke ch5.py (press F5 while in Code Editor) with just the in_fridge function defined, you won't see any output. However, the function will be defined, and it can be invoked from the interactive Python session that you've created. To take advantage of the in_fridge function, though, you have to ensure that there is a dictionary called fridge with food names in it. In addition, you have to have a string in the name wanted_food. This string is how you can ask, using in_fridge, whether that food is available. Therefore, from the interactive session, you can do this to use the function: >>> fridge = {'apples':10, 'oranges':3, 'milk':2} >>> wanted_food = 'apples' >>> in_fridge() 10 >>> wanted_food = 'oranges' >>> in_fridge() 3 >>> wanted_food = 'milk' >>> in_fridge() 2" ---this is what I have and tried to run-- def in_fridge(): fridge = {'apples':10, 'oranges':3, 'milk':2} wanted_food = 'apples' in_fridge() where am i going wrong From jmbayless at gmail.com Fri Jul 22 00:19:39 2016 From: jmbayless at gmail.com (Jordan Bayless) Date: Thu, 21 Jul 2016 21:19:39 -0700 (PDT) Subject: Stupid question, just need a quick and dirty fix Message-ID: I'm trying to modify some code to suit my purposes and I'm just trying to filter results as necessary. Basically, the code is returning one of a number from a subset of 150 numbers. I want to only do anything with it if the number is a 'good' one. I'm by no means a Python programmer (C# for me by trade) and I'm not looking for anything that will be distributed..I just want something that works. Basically, here's what I'm trying to insert: global blnDesiredInd blnDesiredInd == False if IDNum < 10: blnDesiredInd = True if IDNum == 12: blnDesiredInd = True if IDNum == 15: blnDesiredInd = True if IDNum == 24: blnDesiredInd = True if IDNum == 25: blnDesiredInd = True if IDNum == 26: blnDesiredInd = True if IDNum == 27: blnDesiredInd = True if IDNum == 28: blnDesiredInd = True if IDNum == 31: blnDesiredInd = True if IDNum == 34: blnDesiredInd = True if IDNum == 35: blnDesiredInd = True if IDNum == 36: blnDesiredInd = True if IDNum == 37: blnDesiredInd = True if IDNum == 38: blnDesiredInd = True if IDNum == 39: blnDesiredInd = True if IDNum == 40: blnDesiredInd = True if IDNum == 45: blnDesiredInd = True if IDNum == 50: blnDesiredInd = True if IDNum == 51: blnDesiredInd = True if IDNum == 53: blnDesiredInd = True if IDNum == 55: blnDesiredInd = True if IDNum == 56: blnDesiredInd = True if IDNum == 57: blnDesiredInd = True if IDNum == 59: blnDesiredInd = True if IDNum == 62: blnDesiredInd = True if IDNum == 65: blnDesiredInd = True if IDNum == 68: blnDesiredInd = True if IDNum == 71: blnDesiredInd = True if IDNum == 76: blnDesiredInd = True if IDNum == 78: blnDesiredInd = True if IDNum == 80: blnDesiredInd = True if IDNum == 82: blnDesiredInd = True if IDNum == 83: blnDesiredInd = True if IDNum == 87: blnDesiredInd = True if IDNum == 88: blnDesiredInd = True if IDNum == 89: blnDesiredInd = True if IDNum == 91: blnDesiredInd = True if IDNum == 93: blnDesiredInd = True if IDNum == 94: blnDesiredInd = True if IDNum == 96: blnDesiredInd = True if IDNum == 97: blnDesiredInd = True if IDNum == 101: blnDesiredInd = True if IDNum == 103: blnDesiredInd = True if IDNum == 105: blnDesiredInd = True if IDNum == 106: blnDesiredInd = True if IDNum == 107: blnDesiredInd = True if IDNum == 109: blnDesiredInd = True if IDNum == 110: blnDesiredInd = True if IDNum == 112: blnDesiredInd = True if IDNum == 113: blnDesiredInd = True if IDNum == 115: blnDesiredInd = True if IDNum == 122: blnDesiredInd = True if IDNum == 124: blnDesiredInd = True if IDNum == 125: blnDesiredInd = True if IDNum == 126: blnDesiredInd = True if IDNum == 130: blnDesiredInd = True if IDNum == 131: blnDesiredInd = True if IDNum == 132: blnDesiredInd = True if IDNum > 133: blnDesiredInd = True if blnDesiredInd == True: I get various errors no matter what I do to this to try and make it work. Variable not defined. Referenced before assignment. etc etc. I'm lost. How do I make it work? From rosuav at gmail.com Fri Jul 22 00:28:37 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jul 2016 14:28:37 +1000 Subject: Stupid question, just need a quick and dirty fix In-Reply-To: References: Message-ID: On Fri, Jul 22, 2016 at 2:19 PM, Jordan Bayless wrote: > I get various errors no matter what I do to this to try and make it work. Variable not defined. Referenced before assignment. etc etc. I'm lost. How do I make it work? It might be easier if you post all your code. To be honest, what I'd be looking at is something like this: good_ids = { 12, 15, 24, ... # fill in all of these } desired = id < 10 or id > 133 or id in good_ids But it's possible your problem has nothing to do with your massive 'if' tree and everything to do with indentation or other problems we can't see. ChrisA From jmbayless at gmail.com Fri Jul 22 00:39:22 2016 From: jmbayless at gmail.com (Jordan Bayless) Date: Thu, 21 Jul 2016 21:39:22 -0700 (PDT) Subject: Stupid question, just need a quick and dirty fix In-Reply-To: References: Message-ID: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> On Thursday, July 21, 2016 at 11:28:55 PM UTC-5, Chris Angelico wrote: > On Fri, Jul 22, 2016 at 2:19 PM, Jordan Bayless wrote: > > I get various errors no matter what I do to this to try and make it work. Variable not defined. Referenced before assignment. etc etc. I'm lost. How do I make it work? > > It might be easier if you post all your code. To be honest, what I'd > be looking at is something like this: > > good_ids = { > 12, 15, 24, > ... # fill in all of these > } > desired = id < 10 or id > 133 or id in good_ids > > But it's possible your problem has nothing to do with your massive > 'if' tree and everything to do with indentation or other problems we > can't see. > > ChrisA Posting the entire code snippet is tough because it's thousands of lines of code. Basically, I'm inside of a For loop already. The code worked when I got it, but I'm trying to tap into it and extend it outward to notify me via email in certain circumstances. I got it to send the email, but it seems there's a) no case statement (WTF?) and b) I'm limited to how many elif statements I can use. Again, I don't particularly care how elegant this is because it's ultimately getting disposed of sooner rather than later..I just want it to work. Let me review my code and see if I can pare it down to the essentials so I can give a better idea of what I'm doing. From rosuav at gmail.com Fri Jul 22 00:45:58 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jul 2016 14:45:58 +1000 Subject: Stupid question, just need a quick and dirty fix In-Reply-To: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> References: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> Message-ID: On Fri, Jul 22, 2016 at 2:39 PM, Jordan Bayless wrote: > it seems there's a) no case statement (WTF?) and b) I'm limited to how many elif statements I can use. The latter isn't true; and you're not using elif anyway. With no case statement, you get pushed to other, better ways of doing things, like the much simpler way I showed in my previous email - it uses set membership rather than a series of individual equality checks. Faster, cleaner, much easier to work with. ChrisA From michael.selik at gmail.com Fri Jul 22 01:18:23 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 22 Jul 2016 01:18:23 -0400 Subject: Stupid question, just need a quick and dirty fix In-Reply-To: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> References: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> Message-ID: <29AAD1BA-6068-45D9-99AD-5EF9825D445D@gmail.com> > On Jul 22, 2016, at 12:39 AM, Jordan Bayless wrote: > > Posting the entire code snippet is tough because it's thousands of lines of code. You could paste into a GitHub gist (https://gist.github.com/) and share the link. From jmbayless at gmail.com Fri Jul 22 01:26:25 2016 From: jmbayless at gmail.com (Jordan Bayless) Date: Thu, 21 Jul 2016 22:26:25 -0700 (PDT) Subject: Stupid question, just need a quick and dirty fix In-Reply-To: References: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> Message-ID: <2795f3e5-e660-40c6-8a43-97a9613d7577@googlegroups.com> No, I tried using a bunch of elif statements earlier and when I added more than around 3 of them it threw errors. I just assumed that was some kind of limit. We both agree that's piss-poor, lazy coding. I'm just trying to find something that works though. To this point, everything I try fails. I added your code and now it's telling me my variable isn't defined. good_ids = { 2, 3, 4, 5, 6, 7, 8, 9, 12, 15, 24, 25, 26, 27, 28, 31, 34, 35, 36, 37, 38, 39, 40, 45, 50, 51, 53, 55, 56, 57, 59, 62, 65, 68, 71, 76, 78, 80, 82, 83, 87, 88, 89, 91, 93, 94, 96, 97, 101, 103, 105, 106, 107, 109, 110, 112, 113, 115, 122, 124, 125, 126, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151 } desired = Id < 10 or Id > 133 or Id in good_ids When I try to validate whether I passed that check, I'm told there's a Name error and it's not defined (using the last line of the snippet above). Also, I guess I'm at a loss for what I'm supposed to do with "desired" to check it prior to running my email code. if desired == True: doesn't work I'm headed to bed. Too tired to focus on making this work and I apparently really don't 'get' what I'm doing. Maybe I'll be better off with fresh eyes on it tomorrow. From himurakenshin54 at gmail.com Fri Jul 22 02:01:26 2016 From: himurakenshin54 at gmail.com (Tian JiaLin) Date: Thu, 21 Jul 2016 23:01:26 -0700 (PDT) Subject: Convert from unsigned long long to PyLong Message-ID: <45db6d56-90a3-4e4f-958a-65ecb5da5ac6@googlegroups.com> HI There, I'm using MySQLdb as the MySQL client. Recently I got a weird problem of this library. After looking into it, I suspect the problem may related to the conversion from unsigned long to PyLongObject. Here is the detail, If you are familiar with MySQLdb, the following snippet is a way to query the data from MySQL: connection = MySQLdb.connect(...) connection.autocommit(True) try: cursor = connection.cursor() if not cursor.execute(sql, values) > 0: return None row = cursor.fetchone() finally: connection.close() return row[0] Sometimes the return value of execute method would be 18446744073709552000 even there is no matched data available. I checked the source code of the library, the underlying implementation is https://github.com/farcepest/MySQLdb1/blob/master/_mysql.c#L835, static PyObject * _mysql_ConnectionObject_affected_rows( _mysql_ConnectionObject *self, PyObject *args) { if (!PyArg_ParseTuple(args, "")) return NULL; check_connection(self); return PyLong_FromUnsignedLongLong(mysql_affected_rows(&(self->connection))); } And here is the official doc for mysql_affected_rows http://dev.mysql.com/doc/refman/5.7/en/mysql-affected-rows.html. Let me give a superficial understanding, please correct me if I were wrong. In a 64-bit system, the mysql_affected_rows is supposed to return a number of unsigned long, which means the range should be 0 ~ 2^64 (18446744073709551616), How could it be possible the function PyLong_FromUnsignedLongLong return a converted value larger than 2^64, that's what I don't understand. Does anyone have some ideas of it? The versions of the components I used: Python: 2.7.6 MySQL 5.7.11 MySQLdb 1.2.5 Thanks From no.email at nospam.invalid Fri Jul 22 02:03:04 2016 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 21 Jul 2016 23:03:04 -0700 Subject: Stupid question, just need a quick and dirty fix References: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> <2795f3e5-e660-40c6-8a43-97a9613d7577@googlegroups.com> Message-ID: <87y44ub46f.fsf@jester.gateway.pace.com> Jordan Bayless writes: > desired = Id < 10 or Id > 133 or Id in good_ids > When I try to validate whether I passed that check, I'm told there's a > Name error and it's not defined (using the last line of the snippet > above). Id was called IDNum in your earlier pst > Also, I guess I'm at a loss for what I'm supposed to do with "desired" > to check it prior to running my email code. > > if desired == True: doesn't work That should work, but it's more concise and idiomatic to say "if desired: ..." > I'm headed to bed. Too tired to focus on making this work and I > apparently really don't 'get' what I'm doing. Maybe I'll be better off > with fresh eyes on it tomorrow. You're probably better off reading a basic Python tutorial than trying to mess with a working piece of code by trial and error without knowing the language. https://docs.python.org/2/tutorial/index.html is a good place to get started. From steve at pearwood.info Fri Jul 22 02:08:48 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 22 Jul 2016 16:08:48 +1000 Subject: Stupid question, just need a quick and dirty fix References: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> <29AAD1BA-6068-45D9-99AD-5EF9825D445D@gmail.com> Message-ID: <5791b872$0$1604$c3e8da3$5496439d@news.astraweb.com> On Fri, 22 Jul 2016 03:18 pm, Michael Selik wrote: > >> On Jul 22, 2016, at 12:39 AM, Jordan Bayless wrote: >> >> Posting the entire code snippet is tough because it's thousands of lines >> of code. > > You could paste into a GitHub gist (https://gist.github.com/) and share > the link. Are you going to read "thousands of lines" of unfamiliar code trying to work out what changes need to be made to fix an underspecified problem? Yeah, sure you are. Have fun. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Fri Jul 22 02:34:30 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jul 2016 16:34:30 +1000 Subject: Stupid question, just need a quick and dirty fix In-Reply-To: <2795f3e5-e660-40c6-8a43-97a9613d7577@googlegroups.com> References: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> <2795f3e5-e660-40c6-8a43-97a9613d7577@googlegroups.com> Message-ID: On Fri, Jul 22, 2016 at 3:26 PM, Jordan Bayless wrote: > When I try to validate whether I passed that check, I'm told there's a Name error and it's not defined (using the last line of the snippet above). You're still not posting (a) your code, or (b) the full traceback, so it's not easy for us to help you. ChrisA From steve at pearwood.info Fri Jul 22 02:37:19 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 22 Jul 2016 16:37:19 +1000 Subject: Stupid question, just need a quick and dirty fix References: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> <2795f3e5-e660-40c6-8a43-97a9613d7577@googlegroups.com> Message-ID: <5791bf21$0$1599$c3e8da3$5496439d@news.astraweb.com> On Fri, 22 Jul 2016 03:26 pm, Jordan Bayless wrote: > No, I tried using a bunch of elif statements earlier and when I added more > than around 3 of them it threw errors. I just assumed that was some kind > of limit. Right, because a 20+ years old programming language used by millions of professionals all around the world *obviously* must have a limit of three elif statements in a clause. What else could it be? *wink* If only Python would print an exception and an error message so that we could diagnose the error. Oh wait, it does. Instead of just complaining about the limitations of a language you clearly know nothing about, why don't you copy and paste the exceptions so that we can see them? There's no sin in knowing nothing about a language. We all started off ignorant. But jumping to conclusions, particularly the conclusion "well it must be the language's fault", that's just pretty poor. I know you're frustrated. You need to relax, and approach this systematically, and not just blindly make changes without understanding them. More below. > We both agree that's piss-poor, lazy coding. I'm just trying to > find something that works though. To this point, everything I try fails. > > I added your code and now it's telling me my variable isn't defined. Have you tried defining it? Which variable? If you read the error message, it will tell you which variable is not defined. Then you read the code to see where you are trying to access the variable before defining it. This won't work: print(x) x = 1 but this will: x = 1 print(x) Can you see why? You need to have given the variable a value *before* using it. > good_ids = { > 2, 3, 4, 5, 6, 7, 8, 9, 12, 15, 24, 25, 26, 27, 28, 31, 34, 35, 36, > 37, 38, 39, 40, 45, 50, 51, 53, 55, 56, 57, 59, 62, 65, 68, 71, 76, > 78, 80, 82, 83, 87, 88, 89, 91, 93, 94, 96, 97, 101, 103, 105, 106, > 107, 109, 110, 112, 113, 115, 122, 124, 125, 126, 130, 131, 132, 134, > 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, > 149, 150, 151 > } > > desired = Id < 10 or Id > 133 or Id in good_ids > > When I try to validate whether I passed that check, I'm told there's a > Name error and it's not defined (using the last line of the snippet > above). Right. And what name does it say is not defined? Is is "Id"? Ask yourself: is Id defined anywhere? The answer will be No. Where does the name come from? You blindly copied it from Chris Angelico's code. He said: desired = Id < 10 or Id > 133 or Id in good_ids (actually he used lowercase "id" rather than "Id"). But go back to your original request, where you wrote: Basically, here's what I'm trying to insert: global blnDesiredInd blnDesiredInd == False if IDNum < 10: blnDesiredInd = True if IDNum == 12: blnDesiredInd = True [...] Maybe if you replace the names Chris used with the names your program already uses? good_ids = { blah blah blah } blnDesiredInd = IDNum < 10 or IDNum > 133 or IDNum in good_ids > Also, I guess I'm at a loss for what I'm supposed to do with "desired" to > check it prior to running my email code. > > if desired == True: doesn't work What were you planning on doing with blnDesiredInd? if blnDesiredInd: # no need to say "== True" # do the thing you want to do when blnDesiredInd is true ... else: # do the thing you want to do when blnDesiredInd is not true ... You have to replace the dots ... with actual code, of course, but we can't help you with that. It's *your* project, not ours, we have no idea what you want to happen. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ablacktshirt at gmail.com Fri Jul 22 04:52:18 2016 From: ablacktshirt at gmail.com (Yubin Ruan) Date: Fri, 22 Jul 2016 01:52:18 -0700 (PDT) Subject: python3: why writing to socket require bytes type while writing to a file require str ? Message-ID: <47f3acf9-8da2-4aad-a6f0-7a9efbdfe4c3@googlegroups.com> Hi, I'm migrating my code to python3 now and find it hard to deal with python's 'str' and 'bytes' type. It's kind of painful. One thing I find really confusing is that, writing to a socket requires argument to be of type 'bytes'(otherwise python throw 'str does not support buffer interface...' exception), while writing to a file requires argument to be of type 'str'. Why is that? In standard UNIX interface, everything is file, which mean that writing to a socket is the same as writing to a normal file. This is true is python2. But thing doesn't seem to work in python 3. Does anyone have idea why is this in python3 ? In my understanding, writing to a file would requires that everything be written byte by byte. So writing objects of type 'bytes' to socket makes sense. But, how could python write to file using unicode(type 'str')? Does python encode 'str'(Unicode) automatically before writing things to file? If it's true, then why can't it do that automatic encoding when I trying to write a 'str' to socket ? Regards, Ruan From rosuav at gmail.com Fri Jul 22 05:09:33 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jul 2016 19:09:33 +1000 Subject: python3: why writing to socket require bytes type while writing to a file require str ? In-Reply-To: <47f3acf9-8da2-4aad-a6f0-7a9efbdfe4c3@googlegroups.com> References: <47f3acf9-8da2-4aad-a6f0-7a9efbdfe4c3@googlegroups.com> Message-ID: On Fri, Jul 22, 2016 at 6:52 PM, Yubin Ruan wrote: > In my understanding, writing to a file would requires that everything be written byte by byte. So writing objects of type 'bytes' to socket makes sense. But, how could python write to file using unicode(type 'str')? Does python encode 'str'(Unicode) automatically before writing things to file? If it's true, then why can't it do that automatic encoding when I trying to write a 'str' to socket ? > Did you specify an encoding when you opened the file? Did you specify an encoding when you opened the socket? ChrisA From frank at chagford.com Fri Jul 22 05:21:47 2016 From: frank at chagford.com (Frank Millman) Date: Fri, 22 Jul 2016 11:21:47 +0200 Subject: python3: why writing to socket require bytes type while writing to a file require str ? In-Reply-To: <47f3acf9-8da2-4aad-a6f0-7a9efbdfe4c3@googlegroups.com> References: <47f3acf9-8da2-4aad-a6f0-7a9efbdfe4c3@googlegroups.com> Message-ID: "Yubin Ruan" wrote in message news:47f3acf9-8da2-4aad-a6f0-7a9efbdfe4c3 at googlegroups.com... > In my understanding, writing to a file would requires that everything be > written byte by byte. So writing objects of type 'bytes' to socket makes > sense. But, how could python write to file using unicode(type 'str')? Does > python encode 'str'(Unicode) automatically before writing things to file? > If it's true, then why can't it do that automatic encoding when I trying > to write a 'str' to socket ? > If you open a file for writing in text mode, using 'w', it expects a string. If you open it in binary mode, using 'wb', it expects bytes. HTH Frank Millman From steve at pearwood.info Fri Jul 22 06:41:57 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 22 Jul 2016 20:41:57 +1000 Subject: python3: why writing to socket require bytes type while writing to a file require str ? References: <47f3acf9-8da2-4aad-a6f0-7a9efbdfe4c3@googlegroups.com> Message-ID: <5791f877$0$1591$c3e8da3$5496439d@news.astraweb.com> On Fri, 22 Jul 2016 06:52 pm, Yubin Ruan wrote: > Hi, > I'm migrating my code to python3 now and find it hard to deal with > python's 'str' and 'bytes' type. It's kind of painful. One thing I > find really confusing is that, writing to a socket requires argument > to be of type 'bytes' Correct. Sockets are low-level endpoint for transmitting bytes between processes. > (otherwise python throw 'str does not support > buffer interface...' exception), while writing to a file requires > argument to be of type 'str'. Why is that? Only files opened in text mode expect str (text strings). Files opened in binary mode expect bytes. This is for convenience: Python is a high-level programming language, and so for the majority of Python programmers, writing to text files should accept *text*, not bytes. Python allows you to specify the encoding that the file will use (defaulting to UTF-8), and will automatically encode and decode when writing and reading from the file. > In standard UNIX interface, > everything is file, which mean that writing to a socket is the same as > writing to a normal file. Python is not Unix-only and doesn't exclusively follow the Unix philosophy. For example, None is not a file, nor are floats, or lists. A Python text file is an object which provides an interface for writing Unicode text strings to low-level byte-oriented files using some encoding. Python binary files are similar objects, except they skip the encoding part and so require bytes. Files opened in text mode will also automatically convert line-endings to the correct ending used by your operating system. > This is true is python2. But thing doesn't > seem to work in python 3. Does anyone have idea why is this in python3 > ? In my understanding, writing to a file would requires that > everything be written byte by byte. So writing objects of type 'bytes' > to socket makes sense. But, how could python write to file using > unicode(type 'str')? Does python encode 'str'(Unicode) automatically > before writing things to file? Yes. But remember, only if the file is opened in text mode. To open the file in binary mode, add "b" to the mode: open("foo", "rb") open("foo", "wb") > If it's true, then why can't it do that > automatic encoding when I trying to write a 'str' to socket ? Probably because nobody has requested that functionality before. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From thilfigr16 at gmail.com Fri Jul 22 09:00:39 2016 From: thilfigr16 at gmail.com (thilfigr16 at gmail.com) Date: Fri, 22 Jul 2016 06:00:39 -0700 (PDT) Subject: Stupid question, just need a quick and dirty fix In-Reply-To: <5791bf21$0$1599$c3e8da3$5496439d@news.astraweb.com> References: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> <2795f3e5-e660-40c6-8a43-97a9613d7577@googlegroups.com> <5791bf21$0$1599$c3e8da3$5496439d@news.astraweb.com> Message-ID: I'm certainly not going to sugar-coat it and act like I know anything about this language, or wax about how I think it's "inferior" for any reason (because doing so would be pretty foolish). I just figured I'd be able to muddle through and find *something* that would easily filter out results I didn't want. I assumed getting it to port through gmail to notify me would be the hard part and that was actually quite easy. I'm by no means looking to go out and put "Python programmer" on my resume after finishing this task, I was just hoping to dial in the code a bit better for my needs. My var names changed on this thread because I was just using them here as references. I'll figure out how to just post the whole PY file when I'm home tonight and I'll point out the lines where I'm having issues. I do appreciate the information and I still need to go up and read (comprehend) everything posted to see if I can take it from there. Thanks! From rosuav at gmail.com Fri Jul 22 09:24:27 2016 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Jul 2016 23:24:27 +1000 Subject: learning python. learning defining functions . need help In-Reply-To: References: <432aeb03-ea14-4ece-8e5b-a7521cf12b84@googlegroups.com> Message-ID: On Fri, Jul 22, 2016 at 11:13 PM, Dennis Lee Bieber wrote: > Now... Going much beyond the assignment (if you were having trouble > with the assignment, this will seem like magic) [Python 2.7]: I'm not sure, but I think your code would become Py3 compatible if you just change your prints. Which I'd recommend - it's not difficult to just always print a single string, and most example code is ASCII-only and has no difficulty with the bytes/unicode distinction. But, point of curiosity... > class Refrigerator(object): > def __init__(self, stock=None): > if stock is None or type(stock) != type(dict()): > self._stock = dict() > else: > self._stock = stock ... why do you call up "type(dict())"? Why not either just "dict" or "type({})"? ChrisA From zagyen at gmail.com Fri Jul 22 09:59:55 2016 From: zagyen at gmail.com (Zagyen Leo) Date: Fri, 22 Jul 2016 06:59:55 -0700 (PDT) Subject: Just starting to learn Python, and encounter a problem Message-ID: yeah, it may be quite simple to you experts, but hard to me. In one of exercises from the Tutorial it said: "Write a program that asks the user their name, if they enter your name say "That is a nice name", if they enter "John Cleese" or "Michael Palin", tell them how you feel about them ;), otherwise tell them "You have a nice name." And i write so: name = input("Enter your name here: ") if name == "John Cleese" or "Michael Palin": print("Sounds like a gentleman.") else: print("You have a nice name.") But strangely whatever I type in (e.g. Santa Claus), it always say "Sounds like a gentleman.", not the result I want. From random832 at fastmail.com Fri Jul 22 10:30:05 2016 From: random832 at fastmail.com (Random832) Date: Fri, 22 Jul 2016 10:30:05 -0400 Subject: Just starting to learn Python, and encounter a problem In-Reply-To: References: Message-ID: <1469197805.1500560.673872225.0F14EA3D@webmail.messagingengine.com> On Fri, Jul 22, 2016, at 09:59, Zagyen Leo wrote: > yeah, it may be quite simple to you experts, but hard to me. > > In one of exercises from the Tutorial it said: "Write a program that asks > the user their name, if they enter your name say "That is a nice name", > if they enter "John Cleese" or "Michael Palin", tell them how you feel > about them ;), otherwise tell them "You have a nice name." > > And i write so: > > name = input("Enter your name here: ") > if name == "John Cleese" or "Michael Palin": > print("Sounds like a gentleman.") > else: > print("You have a nice name.") > > But strangely whatever I type in (e.g. Santa Claus), it always say > "Sounds like a gentleman.", not the result I want. "or" is a lower precedence than "==". > if name == "John Cleese" or "Michael Palin" becomes if (name == "John Cleese") or "Michael Palin"; becomes if False or "Michael Palin"; becomes if "Michael Palin"; and non-empty strings are considered true. You want if Name == "John Cleese" or Name == "Michael Palin"; or if Name in ("John Cleese", "Michael Palin") From bgailer at gmail.com Fri Jul 22 10:36:25 2016 From: bgailer at gmail.com (Bob Gailer) Date: Fri, 22 Jul 2016 10:36:25 -0400 Subject: Just starting to learn Python, and encounter a problem In-Reply-To: References: Message-ID: On Jul 22, 2016 10:00 AM, "Zagyen Leo" wrote: > > yeah, it may be quite simple to you experts, but hard to me. > > In one of exercises from the Tutorial it said: "Write a program that asks the user their name, if they enter your name say "That is a nice name", if they enter "John Cleese" or "Michael Palin", tell them how you feel about them ;), otherwise tell them "You have a nice name." > > And i write so: > > name = input("Enter your name here: ") > if name == "John Cleese" or "Michael Palin": > print("Sounds like a gentleman.") > else: > print("You have a nice name.") > > But strangely whatever I type in (e.g. Santa Claus), it always say "Sounds like a gentleman.", not the result I want. Even without knowing the operator precedence, this will be evaluated either as: (name == "John Cleese") or "Michael Palin") or: name == ("John Cleese" or "Michael Palin"). Case 1: (name == "John Cleese") evaluates to either True or False. False or "Michael Palin" evaluates to ( believe it or not) " Michael Palin"! Which, as far as if is concerned, is True. True or "Michael Palin" evaluates to True. Case 2: "John Cleese" or "Michael Palin" evaluates to False; name== False evaluates to False. One way to get the results you want: if name in ("John Cleese" or "Michael Palin"): From gordon at address.invalid Fri Jul 22 10:37:33 2016 From: gordon at address.invalid (Gordon Levi) Date: Sat, 23 Jul 2016 00:37:33 +1000 Subject: Just starting to learn Python, and encounter a problem References: Message-ID: Zagyen Leo wrote: >yeah, it may be quite simple to you experts, but hard to me. > >In one of exercises from the Tutorial it said: "Write a program that asks the user their name, if they enter your name say "That is a nice name", if they enter "John Cleese" or "Michael Palin", tell them how you feel about them ;), otherwise tell them "You have a nice name." > >And i write so: > >name = input("Enter your name here: ") >if name == "John Cleese" or "Michael Palin": > print("Sounds like a gentleman.") >else: > print("You have a nice name.") > >But strangely whatever I type in (e.g. Santa Claus), it always say "Sounds like a gentleman.", not the result I want. The second line should be if name == "John Cleese" or name == "Michael Palin": As discussed in recent lengthy thread in this group the following line, and hence your statement, is always true - If "Michael Palin": From python at mrabarnett.plus.com Fri Jul 22 10:46:20 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 22 Jul 2016 15:46:20 +0100 Subject: Convert from unsigned long long to PyLong In-Reply-To: <45db6d56-90a3-4e4f-958a-65ecb5da5ac6@googlegroups.com> References: <45db6d56-90a3-4e4f-958a-65ecb5da5ac6@googlegroups.com> Message-ID: <5737fedc-cd76-3223-16ce-9541a6c51a5f@mrabarnett.plus.com> On 2016-07-22 07:01, Tian JiaLin wrote: > HI There, > > I'm using MySQLdb as the MySQL client. Recently I got a weird problem of this library. After looking into it, I suspect the problem may related to the conversion from unsigned long to PyLongObject. > > Here is the detail, If you are familiar with MySQLdb, the following snippet is a way to query the data from MySQL: > > > connection = MySQLdb.connect(...) > > connection.autocommit(True) > try: > cursor = connection.cursor() > if not cursor.execute(sql, values) > 0: > return None > row = cursor.fetchone() > finally: > connection.close() > return row[0] > > > Sometimes the return value of execute method would be 18446744073709552000 even there is no matched data available. I checked the source code of the library, the underlying implementation is https://github.com/farcepest/MySQLdb1/blob/master/_mysql.c#L835, > > static PyObject * > _mysql_ConnectionObject_affected_rows( > _mysql_ConnectionObject *self, > PyObject *args) > { > if (!PyArg_ParseTuple(args, "")) return NULL; > check_connection(self); > return PyLong_FromUnsignedLongLong(mysql_affected_rows(&(self->connection))); > } > > And here is the official doc for mysql_affected_rows http://dev.mysql.com/doc/refman/5.7/en/mysql-affected-rows.html. > > Let me give a superficial understanding, please correct me if I were wrong. > > In a 64-bit system, the mysql_affected_rows is supposed to return a number of unsigned long, which means the range should be 0 ~ 2^64 (18446744073709551616), How could it be possible the function PyLong_FromUnsignedLongLong return a converted value larger than 2^64, that's what I don't understand. > > Does anyone have some ideas of it? > > > The versions of the components I used: > > Python: 2.7.6 > MySQL 5.7.11 > MySQLdb 1.2.5 > > The function returns an unsigned value, but it will return -1 (i.e. ~0) if there's an error, so check for an error with ~result == 0. From python at mrabarnett.plus.com Fri Jul 22 10:58:28 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 22 Jul 2016 15:58:28 +0100 Subject: Stupid question, just need a quick and dirty fix In-Reply-To: References: Message-ID: <927ed464-34fd-8f73-26d0-84b58cc9c4b2@mrabarnett.plus.com> On 2016-07-22 05:19, Jordan Bayless wrote: > I'm trying to modify some code to suit my purposes and I'm just trying to filter results as necessary. Basically, the code is returning one of a number from a subset of 150 numbers. I want to only do anything with it if the number is a 'good' one. I'm by no means a Python programmer (C# for me by trade) and I'm not looking for anything that will be distributed..I just want something that works. > > Basically, here's what I'm trying to insert: > > global blnDesiredInd > > blnDesiredInd == False > [snip] The line: blnDesiredInd == False looks wrong. It should probably be: blnDesiredInd = False From walters.justin01 at gmail.com Fri Jul 22 11:04:38 2016 From: walters.justin01 at gmail.com (justin walters) Date: Fri, 22 Jul 2016 08:04:38 -0700 Subject: Just starting to learn Python, and encounter a problem In-Reply-To: References: Message-ID: : On Jul 22, 2016 7:46 AM, "Gordon Levi" wrote: > > Zagyen Leo wrote: > > >yeah, it may be quite simple to you experts, but hard to me. > > > >In one of exercises from the Tutorial it said: "Write a program that asks the user their name, if they enter your name say "That is a nice name", if they enter "John Cleese" or "Michael Palin", tell them how you feel about them ;), otherwise tell them "You have a nice name." > > > >And i write so: > > > >name = input("Enter your name here: ") > >if name == "John Cleese" or "Michael Palin": > > print("Sounds like a gentleman.") > >else: > > print("You have a nice name.") > > > >But strangely whatever I type in (e.g. Santa Claus), it always say "Sounds like a gentleman.", not the result I want. > > The second line should be > if name == "John Cleese" or name == "Michael Palin": > > As discussed in recent lengthy thread in this group the following > line, and hence your statement, is always true - > > If "Michael Palin": > -- > https://mail.python.org/mailman/listinfo/python-list The easiest way to right this would be to use a tuple like so: if name in ('John Cleese', 'Michael Palin'): print ('They sound like a gentleman') From python at mrabarnett.plus.com Fri Jul 22 11:08:17 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 22 Jul 2016 16:08:17 +0100 Subject: Just starting to learn Python, and encounter a problem In-Reply-To: References: Message-ID: <685410d4-3db5-68ed-50c3-3a0d2646fbce@mrabarnett.plus.com> On 2016-07-22 14:59, Zagyen Leo wrote: > yeah, it may be quite simple to you experts, but hard to me. > > In one of exercises from the Tutorial it said: "Write a program that asks the user their name, if they enter your name say "That is a nice name", if they enter "John Cleese" or "Michael Palin", tell them how you feel about them ;), otherwise tell them "You have a nice name." > > And i write so: > > name = input("Enter your name here: ") > if name == "John Cleese" or "Michael Palin": > print("Sounds like a gentleman.") > else: > print("You have a nice name.") > > But strangely whatever I type in (e.g. Santa Claus), it always say "Sounds like a gentleman.", not the result I want. > This bit: name == "John Cleese" or "Michael Palin" means the same as: (name == "John Cleese") or "Michael Palin" If name is "Santa Claus", that's: "Santa Claus" == "John Cleese" or "Michael Palin" which is: False or "Michael Palin" which is: "Michael Palin" and any string except "" is treated as True. The condition should be: name == "John Cleese" or name == "Michael Palin" (Shorter alternatives are available; you'll learn about them later!) From walters.justin01 at gmail.com Fri Jul 22 11:21:17 2016 From: walters.justin01 at gmail.com (justin walters) Date: Fri, 22 Jul 2016 08:21:17 -0700 Subject: learning python. learning defining functions . need help In-Reply-To: References: <432aeb03-ea14-4ece-8e5b-a7521cf12b84@googlegroups.com> Message-ID: On Fri, Jul 22, 2016 at 6:24 AM, Chris Angelico wrote: > On Fri, Jul 22, 2016 at 11:13 PM, Dennis Lee Bieber > wrote: > > Now... Going much beyond the assignment (if you were having > trouble > > with the assignment, this will seem like magic) [Python 2.7]: > > I'm not sure, but I think your code would become Py3 compatible if you > just change your prints. Which I'd recommend - it's not difficult to > just always print a single string, and most example code is ASCII-only > and has no difficulty with the bytes/unicode distinction. But, point > of curiosity... > > > class Refrigerator(object): > > def __init__(self, stock=None): > > if stock is None or type(stock) != type(dict()): > > self._stock = dict() > > else: > > self._stock = stock > > ... why do you call up "type(dict())"? Why not either just "dict" or > "type({})"? > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > Hi Chris, Try opening the interactive terminal on your command line and type the following: type({}) == dict() That should illustrate why. This is because simply typing '{}' could be interpreted as either a dict or a set. My interpreter defaults 'type({})' to 'dict', but it's best to not take the risk. You could also replace that line with: if stock is None or type(stock) != dict: From kent.tong.mo at gmail.com Fri Jul 22 11:33:15 2016 From: kent.tong.mo at gmail.com (Kent Tong) Date: Fri, 22 Jul 2016 08:33:15 -0700 (PDT) Subject: Why not allow empty code blocks? Message-ID: Hi I'm aware that we can use 'pass' as an empty code block. But why doesn't python allow a code block to be empty and thus eliminate the need for this null statement? thanks in advance From random832 at fastmail.com Fri Jul 22 11:35:02 2016 From: random832 at fastmail.com (Random832) Date: Fri, 22 Jul 2016 11:35:02 -0400 Subject: learning python. learning defining functions . need help In-Reply-To: References: <432aeb03-ea14-4ece-8e5b-a7521cf12b84@googlegroups.com> Message-ID: <1469201702.1515177.673935617.42048544@webmail.messagingengine.com> On Fri, Jul 22, 2016, at 11:21, justin walters wrote: > Try opening the interactive terminal on your command line and type the > following: > > type({}) == dict() > > That should illustrate why. That doesn't illustrate anything relevant at all. The reason this is false is because dict() is a dict instance, not the dict type. type({}) == dict == type(dict()) will always* be true. >This is because simply typing '{}' could be interpreted as either a >dict or a set. My interpreter defaults 'type({})' to 'dict', but it's >best to not take the risk. This is part of the language spec, it is not something that can be chosen by each interpreter. *well, assuming that "type" and "dict" have not been reassigned from their built-in definitions. From rosuav at gmail.com Fri Jul 22 11:35:56 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Jul 2016 01:35:56 +1000 Subject: learning python. learning defining functions . need help In-Reply-To: References: <432aeb03-ea14-4ece-8e5b-a7521cf12b84@googlegroups.com> Message-ID: On Sat, Jul 23, 2016 at 1:21 AM, justin walters wrote: > Hi Chris, > > Try opening the interactive terminal on your command line and type the > following: > > type({}) == dict() > > That should illustrate why. This is because simply typing '{}' could be > interpreted as > either a dict or a set. My interpreter defaults 'type({})' to 'dict', but > it's best to not > take the risk. Of course the type of {} is not equal to an empty dict, but it *will* be equal to dict itself: >>> type({}) == dict True And it's not ambiguous; it's always going to mean a dictionary. There's no empty set syntax in Python (well, not as of 3.6, anyway). > You could also replace that line with: > > if stock is None or type(stock) != dict: That's exactly what I was saying. Barring shenanigans (like shadowing 'dict' with a function or something), type(dict()) will always be dict. ChrisA From darcy at Vex.Net Fri Jul 22 11:41:18 2016 From: darcy at Vex.Net (D'Arcy J.M. Cain) Date: Fri, 22 Jul 2016 11:41:18 -0400 Subject: learning python. learning defining functions . need help In-Reply-To: References: <432aeb03-ea14-4ece-8e5b-a7521cf12b84@googlegroups.com> Message-ID: <20160722114118.6a809d29@imp> On Fri, 22 Jul 2016 08:21:17 -0700 justin walters wrote: > You could also replace that line with: > > if stock is None or type(stock) != dict: Use isinstance(). That handles classes that subclass dict as well. -- D'Arcy J.M. Cain System Administrator, Vex.Net http://www.Vex.Net/ IM:darcy at Vex.Net VoIP: sip:darcy at Vex.Net From cousinstanley at gmail.com Fri Jul 22 11:45:08 2016 From: cousinstanley at gmail.com (Cousin Stanley) Date: Fri, 22 Jul 2016 08:45:08 -0700 Subject: Stupid question, just need a quick and dirty fix References: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> <2795f3e5-e660-40c6-8a43-97a9613d7577@googlegroups.com> Message-ID: Jordan Bayless wrote: > .... > desired = Id < 10 or Id > 133 or Id in good_ids > > When I try to validate whether I passed that check, > I'm told there's a Name error and it's not defined > .... On the outside chance that failing to define Id produces the Name error, I defined Id in a for loop as a test for your copy/pasted code .... $ cat id_test.py #!/usr/bin/env python3 good_ids = { 2, 3, 4, 5, 6, 7, 8, 9, 12, 15, 24, 25, 26, 27, 28, 31, 34, 35, 36, 37, 38, 39, 40, 45, 50, 51, 53, 55, 56, 57, 59, 62, 65, 68, 71, 76, 78, 80, 82, 83, 87, 88, 89, 91, 93, 94, 96, 97, 101, 103, 105, 106, 107, 109, 110, 112, 113, 115, 122, 124, 125, 126, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151 } test_ids = [ 1 , 10 , 128 , 42 , 137 , 444 ] print( ) for Id in test_ids : desired = Id < 10 or Id > 133 or Id in good_ids print( ' Id : %4d .... desired : %s ' % ( Id , desired ) ) $ ./id_test.py Id : 1 .... desired : True Id : 10 .... desired : False Id : 128 .... desired : False Id : 42 .... desired : False Id : 137 .... desired : True Id : 444 .... desired : True -- Stanley C. Kitching Human Being Phoenix, Arizona From python at bdurham.com Fri Jul 22 12:01:13 2016 From: python at bdurham.com (Malcolm Greene) Date: Fri, 22 Jul 2016 12:01:13 -0400 Subject: Algorithm for sequencing a collection of dependent equations Message-ID: <1469203273.1522601.673919081.7AC3AFEA@webmail.messagingengine.com> We're working on a DSL (domain specific language) that we translate into a list of tokenized expressions. My challenge is to figure out how to sequence evaluation of these expressions so that we evaluate these expressions in the proper order given that expressions have dependencies on other expressions. We've done the work to determine the full list of tokens associated with each expression (after referencing other expressions) and we've detected expressions that result in loops. Here's an example of expressions and their full list of dependencies: a = b + b + b + c + c > b, c, d, e, s, t, x b = c + d + e > c, d, e, s, t, x c = s + 3 > s, x d = t + 1 > t e = t + 2 > t s = x + 100 > x t = 10 > None x = 1 > None y = 2 > None I'm looking for an algorithm/data structure that will me to start with the least dependent expression (t, x, y) and move through the list of expressions in dependency order ending with the expression with the most dependencies. I imagine that spreadsheets have to perform a similar type of analysis to figure out how to recalculate their cells. Suggestions on algorithms and/or data structures (some form of graph?) to support the above goals? Thank you, Malcolm From ben.usenet at bsb.me.uk Fri Jul 22 12:14:22 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Fri, 22 Jul 2016 17:14:22 +0100 Subject: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)] References: <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> <578f0f5c$0$11115$c3e8da3@news.astraweb.com> <578F23A9.7070105@rece.vub.ac.be> <578f72d4$0$1610$c3e8da3$5496439d@news.astraweb.com> <8760rybl8k.fsf@bsb.me.uk> Message-ID: <87oa5pabvl.fsf@bsb.me.uk> Chris Kaynor writes: > On Thu, Jul 21, 2016 at 4:54 PM, Ben Bacarisse wrote: > >> Steven D'Aprano writes: >> >> > Or you might be using a language like Javascript, which intentionally has >> > only floats for numbers. That's okay, you can still perform exact integer >> > arithmetic, so long as you stay within the bounds of ?2**16. >> >> Small point: it's 2**52. >> > > If you really want to be picky, it is 2**53, inclusive: Yes, I mis-typed. Typical, I suppose, for a correction! To add something useful, there are properties Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER which are 2**53 - 1 and -2**53 + 1. These are the largest (and smallest) integers such that i and i+1 (or i and i-1) are exactly representable. -- Ben. From mail at timgolden.me.uk Fri Jul 22 12:35:34 2016 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 22 Jul 2016 17:35:34 +0100 Subject: Algorithm for sequencing a collection of dependent equations In-Reply-To: <1469203273.1522601.673919081.7AC3AFEA@webmail.messagingengine.com> References: <1469203273.1522601.673919081.7AC3AFEA@webmail.messagingengine.com> Message-ID: <38f58976-713b-a59f-a030-ddf3d21a8439@timgolden.me.uk> On 22/07/2016 17:01, Malcolm Greene wrote: > We're working on a DSL (domain specific language) that we translate into > a list of tokenized expressions. My challenge is to figure out how to > sequence evaluation of these expressions so that we evaluate these > expressions in the proper order given that expressions have dependencies > on other expressions. > > We've done the work to determine the full list of tokens associated with > each expression (after referencing other expressions) and we've detected > expressions that result in loops. [... snip ...] > I'm looking for an algorithm/data structure that will me to start with > the least dependent expression (t, x, y) and move through the list of > expressions in dependency order ending with the expression with the most > dependencies. > > I imagine that spreadsheets have to perform a similar type of analysis > to figure out how to recalculate their cells. > > Suggestions on algorithms and/or data structures (some form of graph?) > to support the above goals? I think that what you're looking for is a topological sort TJG From rgaddi at highlandtechnology.invalid Fri Jul 22 12:44:45 2016 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 22 Jul 2016 16:44:45 -0000 (UTC) Subject: Why not allow empty code blocks? References: Message-ID: Kent Tong wrote: > Hi > > I'm aware that we can use 'pass' as an empty code block. But why doesn't python allow a code block to be empty and thus eliminate the need for this null statement? > > thanks in advance Because it's more likely that you have an indentation error than an intentional need for an empty code block, and Python's trying to prevent you shooting yourself in the foot. If you actually needed an empty code block, the langugage provides a way of marking that emptyness as intentional. That way is the pass statement. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From python at bdurham.com Fri Jul 22 12:45:37 2016 From: python at bdurham.com (Malcolm Greene) Date: Fri, 22 Jul 2016 12:45:37 -0400 Subject: Algorithm for sequencing a collection of dependent equations In-Reply-To: <38f58976-713b-a59f-a030-ddf3d21a8439@timgolden.me.uk> References: <1469203273.1522601.673919081.7AC3AFEA@webmail.messagingengine.com> <38f58976-713b-a59f-a030-ddf3d21a8439@timgolden.me.uk> Message-ID: <1469205937.1530704.674003649.2BF5DA05@webmail.messagingengine.com> Hi Tim, > I think that what you're looking for is a topological sort BINGO! That's *exactly* what I was searching for. Thank you very much, Malcolm From python at mrabarnett.plus.com Fri Jul 22 14:36:56 2016 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 22 Jul 2016 19:36:56 +0100 Subject: learning python. learning defining functions . need help In-Reply-To: <20160722114118.6a809d29@imp> References: <432aeb03-ea14-4ece-8e5b-a7521cf12b84@googlegroups.com> <20160722114118.6a809d29@imp> Message-ID: <3379130e-1205-9f02-61c6-e30aee47435f@mrabarnett.plus.com> On 2016-07-22 16:41, D'Arcy J.M. Cain wrote: > On Fri, 22 Jul 2016 08:21:17 -0700 > justin walters wrote: >> You could also replace that line with: >> >> if stock is None or type(stock) != dict: > > Use isinstance(). That handles classes that subclass dict as well. > If you're checking that it's a dict, there's no need to check whether it's None, because None isn't a dict either! From michael.selik at gmail.com Fri Jul 22 14:53:58 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 22 Jul 2016 18:53:58 +0000 Subject: Stupid question, just need a quick and dirty fix In-Reply-To: <5791b872$0$1604$c3e8da3$5496439d@news.astraweb.com> References: <881b184c-11e4-41e7-a01e-6a21d454ce68@googlegroups.com> <29AAD1BA-6068-45D9-99AD-5EF9825D445D@gmail.com> <5791b872$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jul 22, 2016 at 2:11 AM Steven D'Aprano wrote: > On Fri, 22 Jul 2016 03:18 pm, Michael Selik wrote: > >> On Jul 22, 2016, at 12:39 AM, Jordan Bayless > wrote: > >> > >> Posting the entire code snippet is tough because it's thousands of lines > >> of code. > > > > You could paste into a GitHub gist (https://gist.github.com/) and share > > the link. > > Are you going to read "thousands of lines" of unfamiliar code trying to > work > out what changes need to be made to fix an underspecified problem? > > Yeah, sure you are. Have fun. > I suppose not :-) But then I could follow up with a request for the traceback. From python at bdurham.com Fri Jul 22 16:04:28 2016 From: python at bdurham.com (Malcolm Greene) Date: Fri, 22 Jul 2016 16:04:28 -0400 Subject: Dynamically call methods where method is known by address vs name Message-ID: <1469217868.1572637.674159593.622C5164@webmail.messagingengine.com> I know I can do the following: >>> s = 'lower' >>> getattr(s, 'upper')() 'LOWER' But how could I do the same if I had the method 'address' (better name???) vs. method name? >>> upper_method = s.upper How do I combine this upper_method with string s to execute the method and return 'LOWER'? Thank you, Malcolm ? From michael.selik at gmail.com Fri Jul 22 16:32:37 2016 From: michael.selik at gmail.com (Michael Selik) Date: Fri, 22 Jul 2016 20:32:37 +0000 Subject: Dynamically call methods where method is known by address vs name In-Reply-To: <1469217868.1572637.674159593.622C5164@webmail.messagingengine.com> References: <1469217868.1572637.674159593.622C5164@webmail.messagingengine.com> Message-ID: On Fri, Jul 22, 2016 at 4:05 PM Malcolm Greene wrote: > I know I can do the following: > > >>> s = 'lower' > >>> getattr(s, 'upper')() > 'LOWER' > > But how could I do the same if I had the method 'address' (better > name???) vs. method name? > > >>> upper_method = s.upper > > How do I combine this upper_method with string s to execute the method > and return 'LOWER'? > In [1]: s = 'hello' In [2]: f = s.upper In [3]: f() Out[3]: 'HELLO' In [4]: g = str.upper In [5]: g(s) Out[5]: 'HELLO' Is that what you're looking for? From python at bdurham.com Fri Jul 22 17:04:59 2016 From: python at bdurham.com (Malcolm Greene) Date: Fri, 22 Jul 2016 17:04:59 -0400 Subject: Dynamically call methods where method is known by address vs name In-Reply-To: References: <1469217868.1572637.674159593.622C5164@webmail.messagingengine.com> Message-ID: <1469221499.1585449.674210929.09FA7A4D@webmail.messagingengine.com> Hi Michael, > Out[3]: 'HELLO' > In [4]: g = str.upper > In [5]: g(s) > Out[5]: 'HELLO' That's perfect! My mistake was trying to use the method returned by ''.upper vs. str.upper. Thank you, Malcolm ? From mail.python.org at marco.sulla.e4ward.com Fri Jul 22 20:27:44 2016 From: mail.python.org at marco.sulla.e4ward.com (Marco S.) Date: Sat, 23 Jul 2016 02:27:44 +0200 Subject: How asyncio works? and event loop vs exceptions Message-ID: I'm developing a web app based on aiohttp, and I find the event loop concept very interesting. I never programmed with it before, but I know that node.js and GUIs are based on it. What I can't understand is how asyncio make it possible to run multiple tasks concurrently, since it's single threaded (if you don't use loop.run_in_executor()). I just tried to imagine that it should act as a cpu scheduler. Is this true? If so, how and when asyncio decide to switch to another task? Furthermore I have a question about exceptions in asyncio. If I understand well how it works, tasks exceptions can be caught only if you wait for task completion, with yield from, await or loop.run_until_complete(future). But in this case the coroutine blocks the execution of the program until it returns. On the contrary you can execute the coroutine inside an asyncio task and it will be non-blocking, but in this case exceptions can't be caught in a try statement. Is this correct? If so, asyncio programming style can't be a little divergent from what was the philosophy of Python until now? From steve at pearwood.info Fri Jul 22 21:44:56 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 23 Jul 2016 11:44:56 +1000 Subject: learning python. learning defining functions . need help References: <432aeb03-ea14-4ece-8e5b-a7521cf12b84@googlegroups.com> Message-ID: <5792cc18$0$1597$c3e8da3$5496439d@news.astraweb.com> On Sat, 23 Jul 2016 01:21 am, justin walters wrote: > That should illustrate why. This is because simply typing '{}' could be > interpreted as > either a dict or a set. No. {} is always an empty dict. That is a language guarantee. Any programming language where {} is not an empty disk is not valid Python. > My interpreter defaults 'type({})' to 'dict', but it's best to not > take the risk. Are you concerned that type([]) might not be list? Or type("") might not be str? Or that type(0) might not be int? > You could also replace that line with: > > if stock is None or type(stock) != dict: Generally speaking, the right way to test whether something is an instance of a type is to use the isinstance() function: if stock is None or not isinstance(stock, dict): ... That will work correctly even if stock belongs to a subclass of dict. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Fri Jul 22 21:49:36 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 23 Jul 2016 11:49:36 +1000 Subject: Why not allow empty code blocks? References: Message-ID: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> On Sat, 23 Jul 2016 01:33 am, Kent Tong wrote: > Hi > > I'm aware that we can use 'pass' as an empty code block. But why doesn't > python allow a code block to be empty and thus eliminate the need for this > null statement? Because it cannot tell the difference between an empty code block and failing to indent the code block: for x in sequence: print('loop') Is that meant to print 'loop' each time around the loop, or just once, at the end of the loop? There are cases where the interpreter could tell: if flag: else: block Obviously the "if" block is empty. But for consistency, and simplicity, the interpreter requires a pass there too. One less thing to be programmed, one less thing for the user to remember. Just require pass any time you have an empty block, rather than try to remember where it is required and were it is optional. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From kent.tong.mo at gmail.com Fri Jul 22 22:06:41 2016 From: kent.tong.mo at gmail.com (Kent Tong) Date: Fri, 22 Jul 2016 19:06:41 -0700 (PDT) Subject: Why not allow empty code blocks? In-Reply-To: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, July 23, 2016 at 9:49:51 AM UTC+8, Steven D'Aprano wrote: > Because it cannot tell the difference between an empty code block and > failing to indent the code block: > > for x in sequence: > print('loop') Thanks for the excellent answer! From zagyen at gmail.com Sat Jul 23 02:13:37 2016 From: zagyen at gmail.com (Zagyen Leo) Date: Fri, 22 Jul 2016 23:13:37 -0700 (PDT) Subject: Just starting to learn Python, and encounter a problem In-Reply-To: References: <1469197805.1500560.673872225.0F14EA3D@webmail.messagingengine.com> Message-ID: I got it! Thank you. Hope in one day I could help other newbies as you do. From tjreedy at udel.edu Sat Jul 23 05:56:25 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 23 Jul 2016 05:56:25 -0400 Subject: How asyncio works? and event loop vs exceptions In-Reply-To: References: Message-ID: On 7/22/2016 8:27 PM, Marco S. via Python-list wrote: > I'm developing a web app based on aiohttp, and I find the event loop > concept very interesting. I never programmed with it before, but I > know that node.js and GUIs are based on it. > > What I can't understand is how asyncio make it possible to run > multiple tasks concurrently, since it's single threaded (if you don't > use loop.run_in_executor()). I just tried to imagine that it should > act as a cpu scheduler. Is this true? The code for BaseEventLoop is in asyncio.base_events.py. In particular, see def run_forever. Very simplified, def run_forever(): while True: handle_ready_io_events() call_ready_scheduled_functions() > If so, how and when asyncio decide to switch to another task? It does not decide. Asyncio does *cooperative* multi-tasking. This depends on handlers running for a short time and quitting, even if there is more work to do. The OS does *pre-emptive* multi-tasking; it switches processes that are still running. It is possible to add other events into the mix. Adding these lines def tk_update(): root.update() loop.call_later(.01, tk_update) tk_update() to an asyncio program before loop.run_forever and the loop will drive a tkinter gui. A day ago, I experimentally patched IDLE to run off of an asyncio loop instead of the tk loop. Everything I tried worked. See https://bugs.python.org/issue27546. > Furthermore I have a question about exceptions in asyncio. I am too ignorant about this to even ask. -- Terry Jan Reedy From marko at pacujo.net Sat Jul 23 07:13:46 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 23 Jul 2016 14:13:46 +0300 Subject: Why not allow empty code blocks? References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87vazwppxx.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sat, 23 Jul 2016 01:33 am, Kent Tong wrote: >> I'm aware that we can use 'pass' as an empty code block. But why >> doesn't python allow a code block to be empty and thus eliminate the >> need for this null statement? > > Because it cannot tell the difference between an empty code block and > failing to indent the code block: > > for x in sequence: > print('loop') > > Is that meant to print 'loop' each time around the loop, or just once, at > the end of the loop? I don't see an ambiguity: obviously the print call takes place after finishing the loop. > There are cases where the interpreter could tell: > > if flag: > else: > block > > Obviously the "if" block is empty. But for consistency, and > simplicity, the interpreter requires a pass there too. I wonder if there is any true case of ambiguity. I guess this is all about an enforced aesthetic principle: GvR doesn't like the looks of an empty block. > One less thing to be programmed, one less thing for the user to > remember. Just require pass any time you have an empty block, rather > than try to remember where it is required and were it is optional. Actually, the requirement of a dummy statement is a slight annoyance for the programmer. After deleting a statement, you must see if you have to put in a pass statement. And after adding a statement, you may feel the urge to remove the redundant pass statement. Marko From rosuav at gmail.com Sat Jul 23 07:34:49 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Jul 2016 21:34:49 +1000 Subject: Why not allow empty code blocks? In-Reply-To: <87vazwppxx.fsf@elektro.pacujo.net> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> Message-ID: On Sat, Jul 23, 2016 at 9:13 PM, Marko Rauhamaa wrote: >> One less thing to be programmed, one less thing for the user to >> remember. Just require pass any time you have an empty block, rather >> than try to remember where it is required and were it is optional. > > Actually, the requirement of a dummy statement is a slight annoyance for > the programmer. After deleting a statement, you must see if you have to > put in a pass statement. And after adding a statement, you may feel the > urge to remove the redundant pass statement. How often do you actually need empty statements, adding stuff, removing stuff, like that? Possibly there's a code smell here. ChrisA From marko at pacujo.net Sat Jul 23 07:49:05 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 23 Jul 2016 14:49:05 +0300 Subject: Why not allow empty code blocks? References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> Message-ID: <87r3akpob2.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, Jul 23, 2016 at 9:13 PM, Marko Rauhamaa wrote: >>> One less thing to be programmed, one less thing for the user to >>> remember. Just require pass any time you have an empty block, rather >>> than try to remember where it is required and were it is optional. >> >> Actually, the requirement of a dummy statement is a slight annoyance >> for the programmer. After deleting a statement, you must see if you >> have to put in a pass statement. And after adding a statement, you >> may feel the urge to remove the redundant pass statement. > > How often do you actually need empty statements, adding stuff, > removing stuff, like that? Possibly there's a code smell here. Quite often. For example: class ItHitFan(Exception): pass ==> class ItHitFan(Exception): def __init__(self, huh): super().__init__() self.huh = huh Marko From rustompmody at gmail.com Sat Jul 23 08:28:16 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 23 Jul 2016 05:28:16 -0700 (PDT) Subject: Detecting the trivial can be non-trivial (was Why not allow empty code blocks?) In-Reply-To: <87vazwppxx.fsf@elektro.pacujo.net> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> Message-ID: <116a5c2b-01cc-4ed3-a82c-1ee0a94200dc@googlegroups.com> On Saturday, July 23, 2016 at 4:44:00 PM UTC+5:30, Marko Rauhamaa wrote: > Steven D'Aprano : > > > On Sat, 23 Jul 2016 01:33 am, Kent Tong wrote: > >> I'm aware that we can use 'pass' as an empty code block. But why > >> doesn't python allow a code block to be empty and thus eliminate the > >> need for this null statement? > > > > Because it cannot tell the difference between an empty code block and > > failing to indent the code block: > > > > for x in sequence: > > print('loop') > > > > Is that meant to print 'loop' each time around the loop, or just once, at > > the end of the loop? > > I don't see an ambiguity: obviously the print call takes place after > finishing the loop. > > > There are cases where the interpreter could tell: > > > > if flag: > > else: > > block > > > > Obviously the "if" block is empty. But for consistency, and > > simplicity, the interpreter requires a pass there too. > > I wonder if there is any true case of ambiguity. I guess this is all > about an enforced aesthetic principle: GvR doesn't like the looks of an > empty block. > > > One less thing to be programmed, one less thing for the user to > > remember. Just require pass any time you have an empty block, rather > > than try to remember where it is required and were it is optional. > > Actually, the requirement of a dummy statement is a slight annoyance for > the programmer. After deleting a statement, you must see if you have to > put in a pass statement. And after adding a statement, you may feel the > urge to remove the redundant pass statement. Tsk Tsk? The Europeans took 500 years to appreciate that zero is a necessity https://en.wikipedia.org/wiki/Arabic_numerals#Adoption_in_Europe Do you seriously suppose that they did not have the asymptotic/limiting case of: There are 3 apples in the basket There are 2 apples in the basket There are 1 apples in the basket Now you can (and they probably did) replace the ?1? by ?no? But that?s not a number You can have nothing there: There are apples in the basket Is it visible? Problem is more evident if we use a ?base-1? system There are XXX apples in the basket There are XX apples in the basket There are X apples in the basket There are apples in the basket IOW the notion of zero is trivial enough (in hindsight) First-classing it as a notation is not at all trivial This question is analogous ? maybe almost identical ? to the question of the most trivial automata/regex etc. For a long time the re ? dfa transformation went and was taught the laborious route: re ? nfa-with-?-transitions ? nfa-without-?-transitions ? dfa https://en.wikipedia.org/wiki/Thompson's_construction https://en.wikipedia.org/wiki/Powerset_construction Now there is a direct, straightforward method which only becomes available (thinkable) when we have a null regular expression: https://drona.csa.iisc.ernet.in/~deepakd/fmcs-06/seminars/presentation.pdf Coming back to zero: While it is true that European civilization knew of and ignored the zero for 500 years and science-advances happened only after adopting zero, and today we take it for granted. Still it remains true that zero is a bit anomalous. Some evidences of this: Lets say that a numeral is in normal form if it has no leading zeros. So 0025 normalizes to 25. Is 0 a normal form? Likewise: Early versions of Fortran had loops that could not execute zero times: http://www-pnp.physics.ox.ac.uk/~gronbech/intfor/node18.html In the same vein ?pass? (Dijkstra called it ?skip?) and ?abort? (roughly ?raise Exception? in python-speak) correspond to 1 and 0 in numbers And IMHO anyone who rejects the search/formalization for the trivial case as a useless activity is effectively pushing us back to the dark ages. And if one finds it hard to believe that humans can be incredibly resistant to learning from mistakes, here's a list of long-lasting errors like rejecting zero: http://blog.languager.org/2016/01/how-long.html From darcy at Vex.Net Sat Jul 23 08:29:47 2016 From: darcy at Vex.Net (D'Arcy J.M. Cain) Date: Sat, 23 Jul 2016 08:29:47 -0400 Subject: Why not allow empty code blocks? In-Reply-To: <87vazwppxx.fsf@elektro.pacujo.net> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> Message-ID: <20160723082947.7cae8bd1@imp> On Sat, 23 Jul 2016 14:13:46 +0300 Marko Rauhamaa wrote: > > for x in sequence: > > print('loop') > > > > Is that meant to print 'loop' each time around the loop, or just > > once, at the end of the loop? > > I don't see an ambiguity: obviously the print call takes place after > finishing the loop. It's ambiguous to the reader what was actually meant. Forcing a "pass" there shows the reader that the empty block was not a mistake. Explicit is better than implicit. > I wonder if there is any true case of ambiguity. I guess this is all > about an enforced aesthetic principle: GvR doesn't like the looks of > an empty block. I don't think that he would be alone. > Actually, the requirement of a dummy statement is a slight annoyance > for the programmer. After deleting a statement, you must see if you > have to put in a pass statement. And after adding a statement, you > may feel the urge to remove the redundant pass statement. If you allow empty blocks and you use it I hope that you would add a comment so that the reader knows that you meant it. for x in sequence: # this is an empty block Is that better than "pass"? -- D'Arcy J.M. Cain System Administrator, Vex.Net http://www.Vex.Net/ IM:darcy at Vex.Net VoIP: sip:darcy at Vex.Net From marko at pacujo.net Sat Jul 23 09:13:58 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 23 Jul 2016 16:13:58 +0300 Subject: Why not allow empty code blocks? References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> Message-ID: <87fur0a44p.fsf@elektro.pacujo.net> "D'Arcy J.M. Cain" : > On Sat, 23 Jul 2016 14:13:46 +0300 > Marko Rauhamaa wrote: >> I don't see an ambiguity: obviously the print call takes place after >> finishing the loop. > > It's ambiguous to the reader what was actually meant. Forcing a "pass" > there shows the reader that the empty block was not a mistake. Just let the syntax speak for itself. The code means what the language definition says it means. >> I wonder if there is any true case of ambiguity. I guess this is all >> about an enforced aesthetic principle: GvR doesn't like the looks of >> an empty block. > > I don't think that he would be alone. Then just appeal to that subjective preference instead of some objective necessity. BTW, the standard shell requires a dummy statement in a block even though the block boundaries are clearly marked: while not quit; do done is a syntax error. This works: while not quit; do : done > If you allow empty blocks and you use it I hope that you would add a > comment so that the reader knows that you meant it. Once you learn the idioms of a language, you don't need to comment the obvious. > for x in sequence: # this is an empty block > > Is that better than "pass"? Er, in that hypothetical world, the right answer would be simply: for x in sequence: Note that I'm not arguing for the removal of "pass." I'm just saying it isn't strictly necessary. Marko From darcy at Vex.Net Sat Jul 23 09:54:41 2016 From: darcy at Vex.Net (D'Arcy J.M. Cain) Date: Sat, 23 Jul 2016 09:54:41 -0400 Subject: Why not allow empty code blocks? In-Reply-To: <87fur0a44p.fsf@elektro.pacujo.net> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> Message-ID: <20160723095441.29562c54@imp> On Sat, 23 Jul 2016 16:13:58 +0300 Marko Rauhamaa wrote: > "D'Arcy J.M. Cain" : > > It's ambiguous to the reader what was actually meant. Forcing a > > "pass" there shows the reader that the empty block was not a > > mistake. > > Just let the syntax speak for itself. The code means what the language > definition says it means. Exactly so given this... for x in sequence: print("Something") If the language allowed that then we know exactly what the programmer said. What we don't know is what the programmer meant. The above is a simple and obvious statement but real code is more complicated. Add a few comments and a little nesting and what used to be obvious isn't. The interpreter would still know what the programmer said but without the pass requirement it is easier for it to be not what he meant. Python has some nice features like this one that protect the programmer and allow much faster development because there is a safety net. If you like knives without handles you know where to find Perl. Gotta go. The metaphor police are at the door. -- D'Arcy J.M. Cain System Administrator, Vex.Net http://www.Vex.Net/ IM:darcy at Vex.Net VoIP: sip:darcy at Vex.Net From bc at freeuk.com Sat Jul 23 10:00:03 2016 From: bc at freeuk.com (BartC) Date: Sat, 23 Jul 2016 15:00:03 +0100 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> Message-ID: On 23/07/2016 12:34, Chris Angelico wrote: > On Sat, Jul 23, 2016 at 9:13 PM, Marko Rauhamaa wrote: >>> One less thing to be programmed, one less thing for the user to >>> remember. Just require pass any time you have an empty block, rather >>> than try to remember where it is required and were it is optional. >> >> Actually, the requirement of a dummy statement is a slight annoyance for >> the programmer. After deleting a statement, you must see if you have to >> put in a pass statement. And after adding a statement, you may feel the >> urge to remove the redundant pass statement. > > How often do you actually need empty statements, adding stuff, > removing stuff, like that? Possibly there's a code smell here. All the time? For example when creating a set of empty functions to be populated later, or empty branches of if and so on to be filled in as so you go. Or, for debugging or other reasons, when you need to comment out the contents of a block. Then pass needs to be added. However in the absence of a strong end-of-block indicator and having to infer the end of the block from what may or may not follow, then pass is useful when the block is empty. But I don't think it needed to be mandatory. -- Bartc From ian.g.kelly at gmail.com Sat Jul 23 10:06:31 2016 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 23 Jul 2016 08:06:31 -0600 Subject: How asyncio works? and event loop vs exceptions In-Reply-To: References: Message-ID: On Fri, Jul 22, 2016 at 6:27 PM, Marco S. via Python-list wrote: > Furthermore I have a question about exceptions in asyncio. If I > understand well how it works, tasks exceptions can be caught only if > you wait for task completion, with yield from, await or > loop.run_until_complete(future). But in this case the coroutine blocks > the execution of the program until it returns. On the contrary you can > execute the coroutine inside an asyncio task and it will be > non-blocking, but in this case exceptions can't be caught in a try > statement. If you don't want to block the current function on the task, then spin off another task to do the error handling. Instead of this: async def do_something(): try: await do_something_else() except DidNothingError as e: handle_error(e) ... Consider this: async def do_something(): get_event_loop().create_task(await_and_handle(do_something_else())) ... async def await_and_handle(awaitable): try: await awaitable except DidNothingError as e: handle_error(e) If you want, you could generalize that further by passing in the exception class and error handler as well: async def do_something(): get_event_loop().create_task(await_and_handle( do_something_else(), DidNothingError, handle_error)) ... async def await_and_handle(awaitable, error_class, handler): try: await awaitable except error_class as e: handler(e) From bc at freeuk.com Sat Jul 23 10:06:41 2016 From: bc at freeuk.com (BartC) Date: Sat, 23 Jul 2016 15:06:41 +0100 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> Message-ID: On 23/07/2016 14:54, D'Arcy J.M. Cain wrote: > On Sat, 23 Jul 2016 16:13:58 +0300 > Marko Rauhamaa wrote: >> "D'Arcy J.M. Cain" : >>> It's ambiguous to the reader what was actually meant. Forcing a >>> "pass" there shows the reader that the empty block was not a >>> mistake. >> >> Just let the syntax speak for itself. The code means what the language >> definition says it means. > > Exactly so given this... > > for x in sequence: > print("Something") > > If the language allowed that then we know exactly what the programmer > said. What we don't know is what the programmer meant. The above is a > simple and obvious statement but real code is more complicated. Add a > few comments and a little nesting and what used to be obvious isn't. > The interpreter would still know what the programmer said but without > the pass requirement it is easier for it to be not what he meant. > > Python has some nice features like this one that protect the programmer > and allow much faster development because there is a safety net. If > you like knives without handles you know where to find Perl. pass can only do so much. If doesn't help here: for x in sequence: print("Something") print("Something else") Was the second print meant to be indented as well or not? Perhaps rather than 'pass', the language ought to have provided an optional 'end' keyword to mark the end of a block. Then there would be less speculation about what was meant: for x in sequence: print("Something") end print("Something else") (And no speculation at all if 'end' was mandatory. Python already provides 'else' (and 'except'?) which can do a similar job in some circumstances.) -- Bartc From rosuav at gmail.com Sat Jul 23 10:19:22 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jul 2016 00:19:22 +1000 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 24, 2016 at 12:00 AM, BartC wrote: > On 23/07/2016 12:34, Chris Angelico wrote: >> >> On Sat, Jul 23, 2016 at 9:13 PM, Marko Rauhamaa wrote: >>>> >>>> One less thing to be programmed, one less thing for the user to >>>> remember. Just require pass any time you have an empty block, rather >>>> than try to remember where it is required and were it is optional. >>> >>> >>> Actually, the requirement of a dummy statement is a slight annoyance for >>> the programmer. After deleting a statement, you must see if you have to >>> put in a pass statement. And after adding a statement, you may feel the >>> urge to remove the redundant pass statement. >> >> >> How often do you actually need empty statements, adding stuff, >> removing stuff, like that? Possibly there's a code smell here. > > > All the time? No, or I wouldn't have qualified it with the very weak "possibly". > For example when creating a set of empty functions to be populated later, or > empty branches of if and so on to be filled in as so you go. Forget 'pass' - just give each function a docstring. That syntactically defines the block, and it's useful. > Or, for debugging or other reasons, when you need to comment out the > contents of a block. Then pass needs to be added. How often do you comment out an entire block and not its header? I don't remember the last time I did that. It's certainly not so common that adding 'pass' takes up a significant part of a debugging session. ChrisA From steve at pearwood.info Sat Jul 23 11:55:29 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jul 2016 01:55:29 +1000 Subject: Why not allow empty code blocks? References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> Message-ID: <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> On Sun, 24 Jul 2016 12:06 am, BartC wrote: > pass can only do so much. If doesn't help here: > > for x in sequence: > print("Something") > print("Something else") > > Was the second print meant to be indented as well or not? True. But once you start wondering about code the programmer *hasn't* written, you could drive yourself crazy: ...but what if the second print is supposed to follow an "if" clause, which has been left out...? *Most* for-loops have non-empty blocks. Only a tiny minority have empty blocks for any appreciable period of time. (This is not 1970, and we don't write timing loops like "for x in range(1000): pass".) *Most* code is correctly indented. So the interpreter should assume that indentation *is correct*, unless there is a reason to doubt that. What sort of reasons could there be? - if the indentation increases when it shouldn't: print("Hello") print("World!") # unexpected indent - if it dedents to a value that doesn't align with a previous block: for x in sequence: print(x) print("dedented") # half-way between current and previous block - if it doesn't indent when you expect it to: for x in sequence: print(x) Yes, that last one *could* be an empty block. But empty blocks are rare. Its more likely to be an error. If it's not an error, than the programmer can just insert a "pass" statement to satisfy the interpreter. > Perhaps rather than 'pass', the language ought to have provided an > optional 'end' keyword to mark the end of a block. Then there would be > less speculation about what was meant: It can't be optional. If it were optional, we'd be no better off: for x in sequence: print(x) The "end" is missing, but is it missing from the end of the empty block, or the end of the non-empty block? for x in sequence: end print(x) for x in sequence: print(x) end In any case, using "end" instead of "pass" is a poor tradeoff. Instead of needing to use "pass" (say) one time in a thousand when it is needed, you would need to use "end" 999 times in a thousand when it *isn't* needed. > for x in sequence: > print("Something") > end > print("Something else") > > (And no speculation at all if 'end' was mandatory. Python already > provides 'else' (and 'except'?) which can do a similar job in some > circumstances.) -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From cloverobert at gmail.com Sat Jul 23 13:59:33 2016 From: cloverobert at gmail.com (Robert Clove) Date: Sat, 23 Jul 2016 23:29:33 +0530 Subject: Is there a way to invoke remote power shell as Admin. Message-ID: Hi, I am basically trying to solve the following problem http://stackoverflow.com/questions/38540424/open-power-shell-as-admin-on-remote-vm Regards Clove From g.starck at gmail.com Sat Jul 23 14:18:50 2016 From: g.starck at gmail.com (gst) Date: Sat, 23 Jul 2016 11:18:50 -0700 (PDT) Subject: Just starting to learn Python, and encounter a problem In-Reply-To: References: Message-ID: Heuh case 2 : "String1" or "String2" Evaluates to "String1" ? From python at mrabarnett.plus.com Sat Jul 23 15:06:31 2016 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 23 Jul 2016 20:06:31 +0100 Subject: Just starting to learn Python, and encounter a problem In-Reply-To: References: Message-ID: <9d0a21d9-dddd-c473-f468-9473612591ca@mrabarnett.plus.com> On 2016-07-23 19:18, gst wrote: > Heuh case 2 : > > "String1" or "String2" > > Evaluates to "String1" ? > Suppose you have: x or y If bool(x) returns True, then the result will be x, else the result will be y. Example 1: bool("String1") returns True, therefore the result of: "String1" or "String2" is "String1". Example 2: bool("") returns False, so the result of: "" or "String2" is "String2". (The empty string "" is considered 'false-y'; all other strings (i.e. all non-empty strings) are considered 'true-y'.) From steve at pearwood.info Sat Jul 23 21:58:52 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jul 2016 11:58:52 +1000 Subject: Just starting to learn Python, and encounter a problem References: Message-ID: <579420dc$0$22141$c3e8da3$5496439d@news.astraweb.com> On Sun, 24 Jul 2016 04:18 am, gst wrote: > Heuh case 2 : > > "String1" or "String2" > > Evaluates to "String1" ? Correct. What did you expect? Have you read the Fine Manual? https://docs.python.org/3/reference/expressions.html#boolean-operations -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ben.usenet at bsb.me.uk Sun Jul 24 06:15:24 2016 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Sun, 24 Jul 2016 11:15:24 +0100 Subject: Detecting the trivial can be non-trivial (was Why not allow empty code blocks?) References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <116a5c2b-01cc-4ed3-a82c-1ee0a94200dc@googlegroups.com> Message-ID: <878twrs5oj.fsf@bsb.me.uk> Rustom Mody writes: > For a long time the re ? dfa transformation went and was taught the laborious > route: > re ? nfa-with-?-transitions ? nfa-without-?-transitions ? dfa > > https://en.wikipedia.org/wiki/Thompson's_construction > https://en.wikipedia.org/wiki/Powerset_construction > > Now there is a direct, straightforward method which only becomes available > (thinkable) when we have a null regular expression: > https://drona.csa.iisc.ernet.in/~deepakd/fmcs-06/seminars/presentation.pdf "Now" seems an odd thing to say since the technique is quite old. It would be better to say that it has been re-discovered. But thanks for the link -- I was unaware of the idea. Unfortunately the material is not well presented there (lower-case phi for the empty set?) but in trying to understand what it was saying I found: https://www.cl.cam.ac.uk/~so294/documents/jfp09.pdf which, in my opinion, does it very much better. -- Ben. From bc at freeuk.com Sun Jul 24 06:35:48 2016 From: bc at freeuk.com (BartC) Date: Sun, 24 Jul 2016 11:35:48 +0100 Subject: Why not allow empty code blocks? In-Reply-To: <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 23/07/2016 16:55, Steven D'Aprano wrote: > On Sun, 24 Jul 2016 12:06 am, BartC wrote: > >> pass can only do so much. If doesn't help here: >> >> for x in sequence: >> print("Something") >> print("Something else") >> >> Was the second print meant to be indented as well or not? > > True. But once you start wondering about code the programmer *hasn't* > written, you could drive yourself crazy: > > ...but what if the second print is supposed to follow > an "if" clause, which has been left out...? I didn't want to get into this subject again, but Python's indentation scheme is fragile. Given an otherwise correctly typed program that compiles with no errors, then it is very easy (if Backspace or Delete is inadvertently pressed for example), for an indent to disappear without your noticing, but a program still compiles. And still runs without execution errors. But might now be subtly wrong. Deleting any other character than a leading space or tab I think is more likely to result in an error that would be noticed, generate a compile error, or execute error ('variable not initialised'), or that goes wrong more obviously. >> Perhaps rather than 'pass', the language ought to have provided an >> optional 'end' keyword to mark the end of a block. Then there would be >> less speculation about what was meant: > > It can't be optional. If it were optional, we'd be no better off: > > for x in sequence: > print(x) But that's a choice. Being optional, it means someone /can/ make use of it... > The "end" is missing, but is it missing from the end of the empty block, or > the end of the non-empty block? > > for x in sequence: > end > print(x) > > for x in sequence: > print(x) > end ...then it might look like the first example above. The second would be an error. > > In any case, using "end" instead of "pass" is a poor tradeoff. Instead of > needing to use "pass" (say) one time in a thousand when it is needed, you > would need to use "end" 999 times in a thousand when it *isn't* needed. Yes, well, some of us wouldn't mind! But my suggestion is simply that you can write: for x in sequence: end instead of: for x in sequence: pass The first now allows statements to be added or removed from the body of the loop without needing to change the 'end'; it wouldn't look out of place as a trailing 'pass' would. But thinking about it some more, it wouldn't work. All the blocks that don't now use 'end' would look odd. I think it would either have to be all or nothing. I guess nothing. -- Bartc From bc at freeuk.com Sun Jul 24 06:45:22 2016 From: bc at freeuk.com (BartC) Date: Sun, 24 Jul 2016 11:45:22 +0100 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/07/2016 11:35, BartC wrote: > On 23/07/2016 16:55, Steven D'Aprano wrote: >> In any case, using "end" instead of "pass" is a poor tradeoff. Instead of >> needing to use "pass" (say) one time in a thousand when it is needed, you >> would need to use "end" 999 times in a thousand when it *isn't* needed. > > Yes, well, some of us wouldn't mind! 'end' to terminate a block can be emulated of course: end=0 def fn(a): if a<=1: return 1 else: return fn(a-1) end end And in this example it wouldn't impact on performance as it is not evaluated. But although it can make source code look more conventional, it would not be supported by the language (repeated, out of place or missing 'end' lines are not an error). And an empty block will still need pass. -- bartc From rosuav at gmail.com Sun Jul 24 07:27:13 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jul 2016 21:27:13 +1000 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 24, 2016 at 8:45 PM, BartC wrote: > 'end' to terminate a block can be emulated of course: > > end=0 > > def fn(a): > if a<=1: > return 1 > else: > return fn(a-1) > end > end > > And in this example it wouldn't impact on performance as it is not > evaluated. Actually, they would be (you'll have a LOAD_GLOBAL followed by POP_TOP). Much better to use Python's inbuilt hash-braces support, available via a hash-future directive. #from __future__ import braces def fn(a): #{ if a <= 1: #{ return 1 #} else: #{ return fn(a-1) #} #} ChrisA From steve at pearwood.info Sun Jul 24 08:17:23 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 24 Jul 2016 22:17:23 +1000 Subject: Why not allow empty code blocks? References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> On Sun, 24 Jul 2016 08:35 pm, BartC wrote: > I didn't want to get into this subject again, but Python's indentation > scheme is fragile. *shrug* Okay, it's fragile. In 20 (give or take a couple) years of programming in Python, do you know how many times this fragility has been an *actual* problem? Why don't you take a guess? > Given an otherwise correctly typed program that compiles with no errors, > then it is very easy (if Backspace or Delete is inadvertently pressed > for example), for an indent to disappear without your noticing, Not really. It depends on the editor, but typically you need to have your text insertion point somewhere in the indent. And when you do accidentally press Delete, what happens? The high-level structure of the code changes. Typically things will no longer align: def f(): for x in seq: do_this() do_that() do_more() which is a SyntaxError. It requires quite the coincidence before you can accidentally delete an indent and have the code still run. Far more likely is that accidentally pressing delete will break the code in a way that can't be detected until runtime: def f(): for x in seq: do_this() d_that() do_more() Conclusion: if you're the sort of person who habitually presses the Delete or Backspace key without paying attention, you're going to have a bad time. (Do other professions make arguments like this? Do carpenters, say, argue against nail guns because "well if you accidentally hold a loaded nail gun to your head, then press the trigger, bad things will happen"? Or is it just programmers who make a common practice of arguing that the programming language should protect the user from sheer carelessness?) > but a > program still compiles. And still runs without execution errors. But > might now be subtly wrong. That's certainly *theoretically* possible, but its really not likely. The only way it could happen is: - you have a block with at least two lines; - your insertion point is in the indent of the last line of the block; - but not the actual text part; - your editor is configured to dedent on Delete/Backspace, not just delete a single space; or you're using tabs to indent; - and the block isn't followed by another block (e.g. if...else...) > Deleting any other character than a leading space or tab I think is more > likely to result in an error that would be noticed, generate a compile > error, or execute error ('variable not initialised'), or that goes wrong > more obviously. pi = 314159 # oops accidentally hit delete [...] > But my suggestion is simply that you can write: > > for x in sequence: > end > > instead of: > > for x in sequence: > pass > > The first now allows statements to be added or removed from the body of > the loop without needing to change the 'end'; it wouldn't look out of > place as a trailing 'pass' would. You know, I suspect that you've probably spent more time talking about the effort required to delete and insert "pass" than the *actual* effort spent by a hundred programmers deleting and inserting "pass" in their code. > But thinking about it some more, it wouldn't work. All the blocks that > don't now use 'end' would look odd. I think it would either have to be > all or nothing. I guess nothing. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From joel.goldstick at gmail.com Sun Jul 24 08:28:40 2016 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 24 Jul 2016 08:28:40 -0400 Subject: Why not allow empty code blocks? In-Reply-To: <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 24, 2016 at 8:17 AM, Steven D'Aprano wrote: > On Sun, 24 Jul 2016 08:35 pm, BartC wrote: > >> I didn't want to get into this subject again, but Python's indentation >> scheme is fragile. > > *shrug* > > Okay, it's fragile. In 20 (give or take a couple) years of programming in > Python, do you know how many times this fragility has been an *actual* > problem? Why don't you take a guess? > > >> Given an otherwise correctly typed program that compiles with no errors, >> then it is very easy (if Backspace or Delete is inadvertently pressed >> for example), for an indent to disappear without your noticing, > > Not really. It depends on the editor, but typically you need to have your > text insertion point somewhere in the indent. > > And when you do accidentally press Delete, what happens? The high-level > structure of the code changes. Typically things will no longer align: > > def f(): > for x in seq: > do_this() > do_that() > do_more() > > which is a SyntaxError. It requires quite the coincidence before you can > accidentally delete an indent and have the code still run. Far more likely > is that accidentally pressing delete will break the code in a way that > can't be detected until runtime: > > def f(): > for x in seq: > do_this() > d_that() > do_more() > > Conclusion: if you're the sort of person who habitually presses the Delete > or Backspace key without paying attention, you're going to have a bad time. > > (Do other professions make arguments like this? Do carpenters, say, argue > against nail guns because "well if you accidentally hold a loaded nail gun > to your head, then press the trigger, bad things will happen"? Or is it > just programmers who make a common practice of arguing that the programming > language should protect the user from sheer carelessness?) > > >> but a >> program still compiles. And still runs without execution errors. But >> might now be subtly wrong. > > That's certainly *theoretically* possible, but its really not likely. The > only way it could happen is: > > - you have a block with at least two lines; > - your insertion point is in the indent of the last line of the block; > - but not the actual text part; > - your editor is configured to dedent on Delete/Backspace, not just > delete a single space; or you're using tabs to indent; > - and the block isn't followed by another block (e.g. if...else...) > > > >> Deleting any other character than a leading space or tab I think is more >> likely to result in an error that would be noticed, generate a compile >> error, or execute error ('variable not initialised'), or that goes wrong >> more obviously. > > pi = 314159 # oops accidentally hit delete > > > [...] >> But my suggestion is simply that you can write: >> >> for x in sequence: >> end >> >> instead of: >> >> for x in sequence: >> pass >> >> The first now allows statements to be added or removed from the body of >> the loop without needing to change the 'end'; it wouldn't look out of >> place as a trailing 'pass' would. > > You know, I suspect that you've probably spent more time talking about the > effort required to delete and insert "pass" than the *actual* effort spent > by a hundred programmers deleting and inserting "pass" in their code. > > >> But thinking about it some more, it wouldn't work. All the blocks that >> don't now use 'end' would look odd. I think it would either have to be >> all or nothing. I guess nothing. > > > > > -- > Steven > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > This thread is beginning to feel like a dog whistle for people who like braces. I've been python coding since 2009 I think, and I think I have used pass less than a handful of times. ... and except for sets and dicts, I can't remember using a { -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From rosuav at gmail.com Sun Jul 24 08:48:20 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jul 2016 22:48:20 +1000 Subject: Why not allow empty code blocks? In-Reply-To: <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 24, 2016 at 10:17 PM, Steven D'Aprano wrote: > (Do other professions make arguments like this? Do carpenters, say, argue > against nail guns because "well if you accidentally hold a loaded nail gun > to your head, then press the trigger, bad things will happen"? Or is it > just programmers who make a common practice of arguing that the programming > language should protect the user from sheer carelessness?) What about "if you accidentally drop a loaded nailgun, it will fire sharp bits of metal at high velocity in all directions"? I'd say the only difference is that carpentry has been around longer, so they had all these arguments a long time ago and settled on safe ways of doing things. Why has (most of) the programming world advanced from naive text editors to programming editors with syntax highlighting, linters, and other features? Because we are more efficient when our tools protect us from mistakes. Did people argue a few decades ago about the value of syntax highlighting? Personally, I took a long while to get from "well, it'd be nice, but I won't go to any serious effort for it" to "it's my normal way of coding, and anything that DOESN'T have it is for quick tweaks only". Also, why does CPython keep an eye on things like Coverity? If the core devs are competent, they should be able to write code that never dereferences null pointers, mismatch INCREF/DECREF, or any of those other errors - right? But life's better with protection. It's a trade-off. How much effort do you want to go to? Duplicate work in daily operation is a high price to pay, which is why Python doesn't demand "indentation AND 'end' keywords", but protection does have value. Maybe the people who are most worried about this can enact a simple rule: no dedent without a blank line? That can easily be verified by a script, and it'd protect against most of the given examples. It's not too much effort (after any reasonable-sized block you'll probably have a blank anyway, so it's only the tiniest of loops that would be affected). And no language changes are needed :) ChrisA From bc at freeuk.com Sun Jul 24 09:09:29 2016 From: bc at freeuk.com (BartC) Date: Sun, 24 Jul 2016 14:09:29 +0100 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/07/2016 11:45, BartC wrote: > On 24/07/2016 11:35, BartC wrote: > 'end' to terminate a block can be emulated of course: > > end=0 > > def fn(a): > if a<=1: > return 1 > else: > return fn(a-1) > end > end Actually this is a good example of how tabs can go wrong (and how the tab system /is/ fragile - sorry but it is). I almost certainly wrote the above using 4 and 8 spaces for the tabs, except for the 'return 1' where I must have used an actual tab by mistake. (And I tested it now by doing just that, and posting in alt.test.) So the original /looked/ correct in my Thunderbird newsreader before I posted. But after I posted, that tab somehow got changed to 4 spaces, as it now looks wrong. In this instance, the result won't compile. But it's not hard to imagine a much larger program where that change would go unnoticed, and the result is still valid code**. Then anyone copying and pasting the posted code, would have a program with a bug in it. Mysteriously however, Chris Angelico's reply which quoted my post, showed a properly tabbed version! (Unless he fixed it manually.) (** Where working code has been posted, then Python will have picked up inconsistencies where tabs and spaces are mixed. However take this code: def fn(): if a: <8 spaces>pass This looks fine in my editor when is expanded to 4 spaces: def fn(): if a: pass Python however doesn't like it (Python 2 doesn't anyway), because it somehow assumes tabs expand to 8 spaces, so that the two indents look like this to it: def fn(): if a: pass So I can see a lot of problems whenever tabs are expanded differently: a=1 b=0 if a: if b: print ("One") <8 spaces>print ("Two") In my editor with 4-space tabs, it looks like the code will print nothing as the two print lines are aligned within the 'if b:' block. But in Python 2, it will print "Two". Python 3 more wisely reports the inconsistency.) -- Bartc From mail.python.org at marco.sulla.e4ward.com Sun Jul 24 09:11:21 2016 From: mail.python.org at marco.sulla.e4ward.com (Marco Sulla) Date: Sun, 24 Jul 2016 15:11:21 +0200 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24 July 2016 at 14:48, Chris Angelico wrote: > Maybe the people who are most worried about this can enact a > simple rule: no dedent without a blank line? That can easily be > verified by a script, and it'd protect against most of the given > examples. It's not too much effort (after any reasonable-sized block > you'll probably have a blank anyway, so it's only the tiniest of loops > that would be affected). And no language changes are needed :) I'm incredibly in favor of such a modification, but maybe this is work for a linter. Honestly, I find the "pass" statement very clear and simple. There's more misleading problems in Python syntax, like this: someFunction( "param1" "param2" # comma missed, there will be only one parameter "param1param2" ) and this one too: class Parent(Base): __tablename__ = 'parent' id = Column(Integer, primary_key=True) children = relationship("Child"), # comma inserted by error. children will be a tuple and SQLAlchemy will fail with misleading errors From rosuav at gmail.com Sun Jul 24 09:24:57 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jul 2016 23:24:57 +1000 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 24, 2016 at 11:09 PM, BartC wrote: > Actually this is a good example of how tabs can go wrong (and how the tab > system /is/ fragile - sorry but it is). > > I almost certainly wrote the above using 4 and 8 spaces for the tabs, except > for the 'return 1' where I must have used an actual tab by mistake. (And I > tested it now by doing just that, and posting in alt.test.) > No, it's an example of how *mixing tabs and spaces* can go wrong. And in fact will always go wrong unless you legislate the width of a tab. (Recommendation: A tab is equal to 3.14159 spaces. Now you can't get confused. Use 6.283 spaces if that's too narrow for you.) So don't mix tabs and spaces. Ever. ChrisA From rosuav at gmail.com Sun Jul 24 09:38:36 2016 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jul 2016 23:38:36 +1000 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jul 24, 2016 at 11:11 PM, Marco Sulla wrote: > On 24 July 2016 at 14:48, Chris Angelico wrote: >> Maybe the people who are most worried about this can enact a >> simple rule: no dedent without a blank line? That can easily be >> verified by a script, and it'd protect against most of the given >> examples. It's not too much effort (after any reasonable-sized block >> you'll probably have a blank anyway, so it's only the tiniest of loops >> that would be affected). And no language changes are needed :) > > I'm incredibly in favor of such a modification, but maybe this is work > for a linter. Sorry if I wasn't clear, but I definitely did mean for this to be the work of a linter ("verified by a script", and "no language changes are needed"). > Honestly, I find the "pass" statement very clear and simple. There's > more misleading problems in Python syntax, like this: > > someFunction( > "param1" > "param2" # comma missed, there will be only one parameter "param1param2" > ) That can also be caught by a linter; it can also be caught by a standard habit of ALWAYS putting trailing commas on anything that gets wrapped. It's not so common with function calls, but the equivalent situation with list display is: colors = [ "red", "green" "blue", "yellow", "cyan", "magenta" ] Same problem with the missed comma, but it's also common enough to put one after "magenta" too, and it's a great protection. Again, you could have your linter demand this, if you wanted to (and put the linter into your pre-commit hook or equivalent), or you could just eyeball it ("nothing at the end of the line? really?"). > and this one too: > > class Parent(Base): > __tablename__ = 'parent' > id = Column(Integer, primary_key=True) > children = relationship("Child"), # comma inserted by error. > children will be a tuple and SQLAlchemy will fail with misleading > errors Hmm, that's a bit harder to pin down, but since *none* of the members will have commas here, I'd be surprised to spot one there. Though part of the problem here is that SQLAlchemy is such a gigantic package that its error messages tend to be a bit confusing. But that said, here's what happened when I tried it: rosuav at sikorsky:~$ python3 Python 3.6.0a3+ (default:bff31254a0f0, Jul 17 2016, 17:39:49) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from sqlalchemy.ext.declarative import declarative_base >>> from sqlalchemy import Column, Integer >>> from sqlalchemy.orm import relationship >>> Base = declarative_base() >>> class Parent(Base): ... __tablename__ = 'parent' ... id = Column(Integer, primary_key=True) ... children = relationship("Child"), ... /usr/local/lib/python3.6/site-packages/sqlalchemy/ext/declarative/base.py:297: SAWarning: Ignoring declarative-like tuple value of attribute children: possibly a copy-and-paste error with a comma left at the end of the line? "left at the end of the line?" % k) >>> Parent >>> rosuav at sikorsky:~$ python3 -m pip freeze|grep -i alchemy SQLAlchemy==1.0.11 Maybe enabling warnings is all you need, or maybe it depends on the version of SQLAlchemy. In any case, nice spot, declarative-base! ChrisA From bc at freeuk.com Sun Jul 24 10:05:32 2016 From: bc at freeuk.com (BartC) Date: Sun, 24 Jul 2016 15:05:32 +0100 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/07/2016 14:24, Chris Angelico wrote: > On Sun, Jul 24, 2016 at 11:09 PM, BartC wrote: >> Actually this is a good example of how tabs can go wrong (and how the tab >> system /is/ fragile - sorry but it is). >> >> I almost certainly wrote the above using 4 and 8 spaces for the tabs, except >> for the 'return 1' where I must have used an actual tab by mistake. (And I >> tested it now by doing just that, and posting in alt.test.) >> > > No, it's an example of how *mixing tabs and spaces* can go wrong. And > in fact will always go wrong unless you legislate the width of a tab. That's easy to say. How do you actually ensure that they aren't mixed? The software may not highlight the difference. I use 100% tabs in my editor. While in Thunderbird, I have to use 100% spaces otherwise it will screw up. But what stops me pressing tab out of habit? The code looks right, I post it, and if it then goes wrong, I might not notice. Nor would anyone else. Also, sometimes you want to paste code into Thunderbird that contains tabs; that can be erratic too. And very often I want to post other people's code that is full of spaces (notably from Thunderbird), into mine that is full of tabs. (I have the same problem with other languages, but there it's largely cosmetic.) So I still think it's fragile, meaning you have to take a lot of extra care. -- Bartc From steve at pearwood.info Sun Jul 24 10:32:38 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 25 Jul 2016 00:32:38 +1000 Subject: Why not allow empty code blocks? References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5794d188$0$1618$c3e8da3$5496439d@news.astraweb.com> On Mon, 25 Jul 2016 12:05 am, BartC wrote: >> No, it's an example of how *mixing tabs and spaces* can go wrong. And >> in fact will always go wrong unless you legislate the width of a tab. > > That's easy to say. How do you actually ensure that they aren't mixed? > The software may not highlight the difference. (1) Use a better editor. (2) Use a linter that checks for dodgy indentation. (3) Run the "tabnanny" module on your script: python -m tabnanny myscripy.py (4) Run Python 2.7 with the -t option to warn about inconsistent tab usage, or -tt to raise errors. (5) Or for that matter any version of Python going all the way back to Python 1.5, if not older. There has been no excuse for getting bitten by mixed tabs/spaces since at least 1998. (6) Or upgrade to Python 3, which will automatically enforce the rule about not mixing tabs and spaces. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From bc at freeuk.com Sun Jul 24 10:44:37 2016 From: bc at freeuk.com (BartC) Date: Sun, 24 Jul 2016 15:44:37 +0100 Subject: Why not allow empty code blocks? In-Reply-To: <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/07/2016 13:17, Steven D'Aprano wrote: > On Sun, 24 Jul 2016 08:35 pm, BartC wrote: >> Given an otherwise correctly typed program that compiles with no errors, >> then it is very easy (if Backspace or Delete is inadvertently pressed >> for example), for an indent to disappear without your noticing, > > Not really. It depends on the editor, but typically you need to have your > text insertion point somewhere in the indent. > > And when you do accidentally press Delete, what happens? The high-level > structure of the code changes. Typically things will no longer align: > > def f(): > for x in seq: > do_this() > do_that() > do_more() > > which is a SyntaxError. Unless it happened on the do_more() line. > It requires quite the coincidence before you can > accidentally delete an indent and have the code still run. On my editor, if I press the cursor up and down keys, the current column moves to the left if I pass a blank line and stays there. In Python code, then the cursor will often end up at the start of an indent. Far more likely > is that accidentally pressing delete will break the code in a way that > can't be detected until runtime: > > def f(): > for x in seq: > do_this() > d_that() > do_more() Yes, I mentioned that; it will cause some exception. But moving do_more() out of the loop above might not do so. > > Conclusion: if you're the sort of person who habitually presses the Delete > or Backspace key without paying attention, you're going to have a bad time. It happens in all sorts of ways. Your attention is diverted, you're doing something on your desk, but you hit one of the keys by mistake. You might have pressed Delete or you might not. You look at the screen which has a 5000-line program open, and you see this (borrowing your example and with the cursor at "_"): def f(): for x in seq: do_this() do_that() _ do_more() Did you just unindent do_more(), or is that where it's meant to be? Undo may or may not help (or it may undo something is needed). If you see this however: def f(): for x in seq: do_this() _o_that() do_more() You can see that o_that() doesn't look like its neighbours, and you can verify there's no o_that() in scope. -- Bartc From rustompmody at gmail.com Sun Jul 24 10:49:47 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 24 Jul 2016 07:49:47 -0700 (PDT) Subject: Detecting the trivial can be non-trivial (was Why not allow empty code blocks?) In-Reply-To: <878twrs5oj.fsf@bsb.me.uk> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <116a5c2b-01cc-4ed3-a82c-1ee0a94200dc@googlegroups.com> <878twrs5oj.fsf@bsb.me.uk> Message-ID: On Sunday, July 24, 2016 at 3:45:40 PM UTC+5:30, Ben Bacarisse wrote: > Rustom Mody writes: > > > For a long time the re ? dfa transformation went and was taught the laborious > > route: > > re ? nfa-with-?-transitions ? nfa-without-?-transitions ? dfa > > > > https://en.wikipedia.org/wiki/Thompson's_construction > > https://en.wikipedia.org/wiki/Powerset_construction > > > > Now there is a direct, straightforward method which only becomes available > > (thinkable) when we have a null regular expression: > > https://drona.csa.iisc.ernet.in/~deepakd/fmcs-06/seminars/presentation.pdf > > "Now" seems an odd thing to say since the technique is quite old. It > would be better to say that it has been re-discovered. The ?Now? was not meant time-ly! > > But thanks for the link -- I was unaware of the idea. Unfortunately the > material is not well presented there (lower-case phi for the empty set?) > but in trying to understand what it was saying I found: > > https://www.cl.cam.ac.uk/~so294/documents/jfp09.pdf > > which, in my opinion, does it very much better. Yeah I think the one used when I was studying was this one http://www2.in.tum.de/hp/file?fid=571 Anyway my main point was that getting trivial cases right is damn hard And eliding the trivial case from a notation ? because its too trivial to be useful is damn stupid From rosuav at gmail.com Sun Jul 24 10:51:02 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jul 2016 00:51:02 +1000 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jul 25, 2016 at 12:44 AM, BartC wrote: > Your attention is diverted, you're doing something on your desk, but you hit > one of the keys by mistake. You might have pressed Delete or you might not. > You look at the screen which has a 5000-line program open, and you see this > (borrowing your example and with the cursor at "_"): > > def f(): > for x in seq: > do_this() > do_that() > _ do_more() > > Did you just unindent do_more(), or is that where it's meant to be? Undo may > or may not help (or it may undo something is needed). Undo, redo. See what happened. Easy. Also, if you're regularly committing to source control, you can always check the diff. Before you 'git commit', check what 'gitk' shows, or before 'hg commit', have a glance at 'hg diff'. Make sure what you're seeing is what you intend to change. Remember, code doesn't just accidentally change; everything should have purpose, including (especially) any indent/unindent. Source control protects you from everything other than multiple changes since the last commit. So commit often. It'll save you a lot of time - if not coding time, then debating-on-python-list time. :) ChrisA From totopopo6 at gmx.com Sun Jul 24 13:37:44 2016 From: totopopo6 at gmx.com (GIACOMO ZUCCO BITCOIN TECHNOLOGY CONSULTANT) Date: Sun, 24 Jul 2016 10:37:44 -0700 (PDT) Subject: Redacted Message-ID: Redacted From bc at freeuk.com Sun Jul 24 14:14:10 2016 From: bc at freeuk.com (BartC) Date: Sun, 24 Jul 2016 19:14:10 +0100 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/07/2016 15:51, Chris Angelico wrote: > On Mon, Jul 25, 2016 at 12:44 AM, BartC wrote: >> Your attention is diverted, you're doing something on your desk, but you hit >> one of the keys by mistake. You might have pressed Delete or you might not. >> You look at the screen which has a 5000-line program open, and you see this >> (borrowing your example and with the cursor at "_"): >> >> def f(): >> for x in seq: >> do_this() >> do_that() >> _ do_more() >> >> Did you just unindent do_more(), or is that where it's meant to be? Undo may >> or may not help (or it may undo something is needed). > > Undo, redo. See what happened. Easy. > > Also, if you're regularly committing to source control, you can always > check the diff. Before you 'git commit', check what 'gitk' shows, or > before 'hg commit', have a glance at 'hg diff'. Make sure what you're > seeing is what you intend to change. Remember, code doesn't just > accidentally change; everything should have purpose, including > (especially) any indent/unindent. > > Source control protects you from everything other than multiple > changes since the last commit. So commit often. It'll save you a lot > of time - if not coding time, then debating-on-python-list time. :) OK. I understand that it is not possible to point out any kind of weakness of a language (any language not just Python!) because the counter-argument is always going to be about: Use syntax highlighting, use a smart editor, use a version control system, use a linter, use 'tabnanny', use tool X, Y or Z to get around the problems, use obscure language options.. The thing is, if everyone does depend more on such tools, then it really doesn't matter exactly what the language does - the tools will take care of such details. So the language could delimit blocks using any scheme it likes, including use 'end', 'else' and so on. It only becomes important to people like me who use plain editors. -- Bartc -- Bartc From neceros at gmail.com Sun Jul 24 14:27:22 2016 From: neceros at gmail.com (neceros at gmail.com) Date: Sun, 24 Jul 2016 11:27:22 -0700 (PDT) Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <153dbc0e-2b2a-46f6-b05c-5ee98d31ba02@googlegroups.com> On Sunday, July 24, 2016 at 6:09:40 AM UTC-7, BartC wrote: > On 24/07/2016 11:45, BartC wrote: > > On 24/07/2016 11:35, BartC wrote: > > > 'end' to terminate a block can be emulated of course: > > > > end=0 > > > > def fn(a): > > if a<=1: > > return 1 > > else: > > return fn(a-1) > > end > > end > > Actually this is a good example of how tabs can go wrong (and how the > tab system /is/ fragile - sorry but it is). > > I almost certainly wrote the above using 4 and 8 spaces for the tabs, > except for the 'return 1' where I must have used an actual tab by > mistake. (And I tested it now by doing just that, and posting in alt.test.) > > So the original /looked/ correct in my Thunderbird newsreader before I > posted. But after I posted, that tab somehow got changed to 4 spaces, as > it now looks wrong. > > In this instance, the result won't compile. But it's not hard to imagine > a much larger program where that change would go unnoticed, and the > result is still valid code**. > > Then anyone copying and pasting the posted code, would have a program > with a bug in it. > > Mysteriously however, Chris Angelico's reply which quoted my post, > showed a properly tabbed version! (Unless he fixed it manually.) > > (** Where working code has been posted, then Python will have picked up > inconsistencies where tabs and spaces are mixed. However take this code: > > def fn(): > if a: > <8 spaces>pass > > This looks fine in my editor when is expanded to 4 spaces: > > def fn(): > if a: > pass > > Python however doesn't like it (Python 2 doesn't anyway), because it > somehow assumes tabs expand to 8 spaces, so that the two indents look > like this to it: > > def fn(): > if a: > pass > > So I can see a lot of problems whenever tabs are expanded differently: > > a=1 > b=0 > > if a: > if b: > print ("One") > <8 spaces>print ("Two") > > In my editor with 4-space tabs, it looks like the code will print > nothing as the two print lines are aligned within the 'if b:' block. But > in Python 2, it will print "Two". Python 3 more wisely reports the > inconsistency.) > > -- > Bartc Don't use tabs. Ever. It's simple. From jonathan.hayward at pobox.com Sun Jul 24 14:34:27 2016 From: jonathan.hayward at pobox.com (Jonathan Hayward) Date: Sun, 24 Jul 2016 13:34:27 -0500 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: I might point out something that captures something about pass: it is made to do extra duty in web2py, which is meant to shield students from some of the more preventable complexities of a LUM CLI, and you don't easily indent code the way that Vim and Emacs, let alone a full IDE besides the IDE nature of web2py, forces people to deal with. People getting up to speed with Vim or Emacs, for anything that is usually indented, find and/or seek out how to maintain indentation without hitting the space bar 4/8/12/... times at the beginning of the next line. And it works. It was probably not intended or even anticipated in the design of Python, but my understanding is that the adapted usage works well. And if I may put on asbestos longjohns, there is no reason I am aware of why syntactic sugar, in the style of Python-influenced Coffeescript, could not be modified to make "from __future__ import braces" represent a live and active feature. The net effect of significant whitespace in Python is that it provides one model to "say what you mean and mean what you say", and everybody who understands the language recognizes the beginning and end of a block, the end of a statement, a noop, etc. And this is pretty much the job description of C-family language syntax etc. Now there are advantages, namely no braces and no brace holy wars either, fewer Perlish sigils as even a statement is usually ended by line break, and so on. But Python-style and C-style syntax alike provide an unambiguous tool to specify what you want, and an unambiguous means of interpreting what was actually said. The non-C-style syntax was the biggest "steaming pile of dinosaur dung" hurdle before ESR appreciated the language, but Python syntax and C-style syntax are both adequate. They may or may not be equal, but every instance of code which unambiguous Pythonic syntax is underscored is an effect that should usually be equally easy to implement with C-style syntax. On Sun, Jul 24, 2016 at 1:14 PM, BartC wrote: > On 24/07/2016 15:51, Chris Angelico wrote: > >> On Mon, Jul 25, 2016 at 12:44 AM, BartC wrote: >> >>> Your attention is diverted, you're doing something on your desk, but you >>> hit >>> one of the keys by mistake. You might have pressed Delete or you might >>> not. >>> You look at the screen which has a 5000-line program open, and you see >>> this >>> (borrowing your example and with the cursor at "_"): >>> >>> def f(): >>> for x in seq: >>> do_this() >>> do_that() >>> _ do_more() >>> >>> Did you just unindent do_more(), or is that where it's meant to be? Undo >>> may >>> or may not help (or it may undo something is needed). >>> >> >> Undo, redo. See what happened. Easy. >> >> Also, if you're regularly committing to source control, you can always >> check the diff. Before you 'git commit', check what 'gitk' shows, or >> before 'hg commit', have a glance at 'hg diff'. Make sure what you're >> seeing is what you intend to change. Remember, code doesn't just >> accidentally change; everything should have purpose, including >> (especially) any indent/unindent. >> >> Source control protects you from everything other than multiple >> changes since the last commit. So commit often. It'll save you a lot >> of time - if not coding time, then debating-on-python-list time. :) >> > > OK. I understand that it is not possible to point out any kind of weakness > of a language (any language not just Python!) because the counter-argument > is always going to be about: > > Use syntax highlighting, use a smart editor, use a version control system, > use a linter, use 'tabnanny', use tool X, Y or Z to get around the > problems, use obscure language options.. > > The thing is, if everyone does depend more on such tools, then it really > doesn't matter exactly what the language does - the tools will take care of > such details. So the language could delimit blocks using any scheme it > likes, including use 'end', 'else' and so on. > > It only becomes important to people like me who use plain editors. > > -- > Bartc > > > -- > Bartc > -- > https://mail.python.org/mailman/listinfo/python-list > -- [image: Christos Jonathan Seth Hayward] *Jonathan Hayward*, a User Experience professional. Email ? Flagship Website ? Github ? *LinkedIn * ? Portfolio + More ? *Recent Title * ? Skills Loads of talent and a thorough grounding in all major academic disciplines supporting User Experience. From alister.ware at ntlworld.com Sun Jul 24 14:52:05 2016 From: alister.ware at ntlworld.com (alister) Date: Sun, 24 Jul 2016 18:52:05 GMT Subject: Why not allow empty code blocks? References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, 24 Jul 2016 19:14:10 +0100, BartC wrote: > On 24/07/2016 15:51, Chris Angelico wrote: >> On Mon, Jul 25, 2016 at 12:44 AM, BartC wrote: >>> Your attention is diverted, you're doing something on your desk, but >>> you hit one of the keys by mistake. You might have pressed Delete or >>> you might not. You look at the screen which has a 5000-line program >>> open, and you see this (borrowing your example and with the cursor at >>> "_"): >>> >>> def f(): >>> for x in seq: >>> do_this() >>> do_that() >>> _ do_more() >>> >>> Did you just unindent do_more(), or is that where it's meant to be? >>> Undo may or may not help (or it may undo something is needed). >> >> Undo, redo. See what happened. Easy. >> >> Also, if you're regularly committing to source control, you can always >> check the diff. Before you 'git commit', check what 'gitk' shows, or >> before 'hg commit', have a glance at 'hg diff'. Make sure what you're >> seeing is what you intend to change. Remember, code doesn't just >> accidentally change; everything should have purpose, including >> (especially) any indent/unindent. >> >> Source control protects you from everything other than multiple changes >> since the last commit. So commit often. It'll save you a lot of time - >> if not coding time, then debating-on-python-list time. :) > > OK. I understand that it is not possible to point out any kind of > weakness of a language (any language not just Python!) because the > counter-argument is always going to be about: > > Use syntax highlighting, use a smart editor, use a version control > system, use a linter, use 'tabnanny', use tool X, Y or Z to get around > the problems, use obscure language options.. > > The thing is, if everyone does depend more on such tools, then it really > doesn't matter exactly what the language does - the tools will take care > of such details. So the language could delimit blocks using any scheme > it likes, including use 'end', 'else' and so on. > > It only becomes important to people like me who use plain editors. > > -- > Bartc whichever language you use regardless of editor, there will have been design decisions made that could (by your logic) be considered flaws because an error made is not picked up by the compiler. apple were recently bitten by "Goto Fail" an error that could not have happened in the same way with pythons indentation rules. correct the design of your compiler for one type of error & you will find that you are now open to another. IMHO typing pass to signify a deliberately empty block is a minor nuisance (at worst) making it optional is more likely to lead to bugs either way my opinion is nut important because the decision has already been made. -- I sat laughing snidely into my notebook until they showed me a PC running Linux... And oh! It was as though the heavens opened and God handed down a client-side OS so beautiful, so graceful, and so elegant that a million Microsoft developers couldn't have invented it even if they had a hundred years and a thousand crates of Jolt cola. -- Polly Sprenger, LAN Times From songofacandy at gmail.com Sun Jul 24 14:59:13 2016 From: songofacandy at gmail.com (INADA Naoki) Date: Mon, 25 Jul 2016 03:59:13 +0900 Subject: Convert from unsigned long long to PyLong In-Reply-To: <45db6d56-90a3-4e4f-958a-65ecb5da5ac6@googlegroups.com> References: <45db6d56-90a3-4e4f-958a-65ecb5da5ac6@googlegroups.com> Message-ID: Thank you for reporting this issue. I'll fix it in next release of mysqlclient (MySQL-python has not been maintained for these years. Please use mysqlclient. It supports Python 3.) On Fri, Jul 22, 2016 at 3:01 PM, Tian JiaLin wrote: > HI There, > > I'm using MySQLdb as the MySQL client. Recently I got a weird problem of this library. After looking into it, I suspect the problem may related to the conversion from unsigned long to PyLongObject. > > Here is the detail, If you are familiar with MySQLdb, the following snippet is a way to query the data from MySQL: > > > connection = MySQLdb.connect(...) > > connection.autocommit(True) > try: > cursor = connection.cursor() > if not cursor.execute(sql, values) > 0: > return None > row = cursor.fetchone() > finally: > connection.close() > return row[0] > > > Sometimes the return value of execute method would be 18446744073709552000 even there is no matched data available. I checked the source code of the library, the underlying implementation is https://github.com/farcepest/MySQLdb1/blob/master/_mysql.c#L835, > > static PyObject * > _mysql_ConnectionObject_affected_rows( > _mysql_ConnectionObject *self, > PyObject *args) > { > if (!PyArg_ParseTuple(args, "")) return NULL; > check_connection(self); > return PyLong_FromUnsignedLongLong(mysql_affected_rows(&(self->connection))); > } > > And here is the official doc for mysql_affected_rows http://dev.mysql.com/doc/refman/5.7/en/mysql-affected-rows.html. > > Let me give a superficial understanding, please correct me if I were wrong. > > In a 64-bit system, the mysql_affected_rows is supposed to return a number of unsigned long, which means the range should be 0 ~ 2^64 (18446744073709551616), How could it be possible the function PyLong_FromUnsignedLongLong return a converted value larger than 2^64, that's what I don't understand. > > Does anyone have some ideas of it? > > > The versions of the components I used: > > Python: 2.7.6 > MySQL 5.7.11 > MySQLdb 1.2.5 > > > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list -- INADA Naoki From rosuav at gmail.com Sun Jul 24 15:00:28 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jul 2016 05:00:28 +1000 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jul 25, 2016 at 4:14 AM, BartC wrote: > OK. I understand that it is not possible to point out any kind of weakness > of a language (any language not just Python!) because the counter-argument > is always going to be about: > > Use syntax highlighting, use a smart editor, use a version control system, > use a linter, use 'tabnanny', use tool X, Y or Z to get around the problems, > use obscure language options.. Obscure? I guess - it's not like it's listed in the --help screen. Oh wait. And of course, all you need to do is upgrade to Python 3 and it becomes the default. Wait, you lump "use a VCS" into the category of "stuff people tell you that you're not really willing to do"? Are you saying you don't use git, Mercurial, etc, etc, to track your projects? Then start using one. Now. "Now-now", as Princess Anna says in the Italian dub. > The thing is, if everyone does depend more on such tools, then it really > doesn't matter exactly what the language does - the tools will take care of > such details. So the language could delimit blocks using any scheme it > likes, including use 'end', 'else' and so on. > > It only becomes important to people like me who use plain editors. Yes, that's exactly right. Tell me, is this part of a linter or a language compiler/interpreter? rosuav at sikorsky:~$ cat 1.c #include int main() { int months[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; printf("The array is at %p.\n", months); printf("There are %d days in December.\n", months[12]); printf("And this is what 28 looks like: %s\n", months[1]); } rosuav at sikorsky:~$ gcc -Wall -O2 1.c 1.c: In function ?main?: 1.c:7:9: warning: format ?%s? expects argument of type ?char *?, but argument 2 has type ?int? [-Wformat=] printf("And this is what 28 looks like: %s\n", months[1]); ^ 1.c:6:2: warning: array subscript is above array bounds [-Warray-bounds] printf("There are %d days in December.\n", months[12]); ^ rosuav at sikorsky:~$ Today's C compilers emit warnings for things that yesterday's third-party linters did. Is there virtue in running gcc with all warnings disabled? Equally, is there a valid reason for choosing to use a "plain editor" when you could use one that helps you? A skilled craftsman in any field will choose to use quality tools. They save time, and time is money. Are there any carpenters who restrict themselves to hand tools? (Stylistic choice aside. KirkwoodWorking has "hand tools Sunday" where he avoids all power tools, and it's taking him months and months to finish one cabinet. But the rest of the week, power tools win.) Would you, if given the choice, use an ancient 80386 running MS-DOS in 4MB of RAM, or a modern system running a modern OS in 16GB? Would you type your code on a tablet computer or something with a real keyboard? So why do you use "dumb editor" as a line of argument, rather than getting a smarter editor? I don't have a lot of sympathy for people who use suboptimal tools and expect everything to work for them. Sure, sometimes you're forced to use something less than ideal (maybe you're stuck on someone else's Windows box and good tools simply aren't there, and you can't go installing a ton of stuff just to get started), but then you KNOW you're working in bad conditions. You don't make that your normal life. ChrisA From ascianpipadan at yahoo.com Sun Jul 24 15:15:47 2016 From: ascianpipadan at yahoo.com (GIOVANNI ZIBORDI COBRAF MODENA) Date: Sun, 24 Jul 2016 12:15:47 -0700 (PDT) Subject: Redacted Message-ID: Redacted From ascianpipadan at yahoo.com Sun Jul 24 15:16:26 2016 From: ascianpipadan at yahoo.com (GIOVANNI ZIBORDI COBRAF MODENA) Date: Sun, 24 Jul 2016 12:16:26 -0700 (PDT) Subject: Redacted Message-ID: <5f57274a-e3f0-41f3-b9d0-81e6698d2577@googlegroups.com> Redacted From ascianpipadan at yahoo.com Sun Jul 24 15:16:59 2016 From: ascianpipadan at yahoo.com (GIOVANNI ZIBORDI COBRAF MODENA) Date: Sun, 24 Jul 2016 12:16:59 -0700 (PDT) Subject: Redacted Message-ID: <6f300fb5-db28-4a25-9ddc-c4f01e505ac7@googlegroups.com> Redacted From ascianpipadan at yahoo.com Sun Jul 24 15:17:31 2016 From: ascianpipadan at yahoo.com (GIOVANNI ZIBORDI COBRAF MODENA) Date: Sun, 24 Jul 2016 12:17:31 -0700 (PDT) Subject: Redacted Message-ID: <16fa6202-6a5c-4adc-b279-53e7d331d6d8@googlegroups.com> Redacted From ascianpipadan at yahoo.com Sun Jul 24 15:18:12 2016 From: ascianpipadan at yahoo.com (GIOVANNI ZIBORDI COBRAF MODENA) Date: Sun, 24 Jul 2016 12:18:12 -0700 (PDT) Subject: Redacted Message-ID: Redacted From ascianpipadan at yahoo.com Sun Jul 24 15:18:58 2016 From: ascianpipadan at yahoo.com (GIOVANNI ZIBORDI COBRAF MODENA) Date: Sun, 24 Jul 2016 12:18:58 -0700 (PDT) Subject: Redacted Message-ID: <664567a7-ebd9-4843-8aa1-df9f0ce127be@googlegroups.com> Redacted From ascianpipadan at yahoo.com Sun Jul 24 15:19:32 2016 From: ascianpipadan at yahoo.com (GIOVANNI ZIBORDI COBRAF MODENA) Date: Sun, 24 Jul 2016 12:19:32 -0700 (PDT) Subject: Redacted Message-ID: <548200b0-05b6-453a-84fa-9d39c7e56289@googlegroups.com> Redacted From ascianpipadan at yahoo.com Sun Jul 24 15:20:19 2016 From: ascianpipadan at yahoo.com (GIOVANNI ZIBORDI COBRAF MODENA) Date: Sun, 24 Jul 2016 12:20:19 -0700 (PDT) Subject: Redacted Message-ID: Redacted From ascianpipadan at yahoo.com Sun Jul 24 15:21:05 2016 From: ascianpipadan at yahoo.com (GIOVANNI ZIBORDI COBRAF MODENA) Date: Sun, 24 Jul 2016 12:21:05 -0700 (PDT) Subject: Redacted Message-ID: Redacted From ascianpipadan at yahoo.com Sun Jul 24 15:21:47 2016 From: ascianpipadan at yahoo.com (GIOVANNI ZIBORDI COBRAF MODENA) Date: Sun, 24 Jul 2016 12:21:47 -0700 (PDT) Subject: Redacted Message-ID: <9ab8fb70-9d12-4a40-bf3d-b63db5716d78@googlegroups.com> Redacted From ascianpipadan at yahoo.com Sun Jul 24 15:22:17 2016 From: ascianpipadan at yahoo.com (GIOVANNI ZIBORDI COBRAF MODENA) Date: Sun, 24 Jul 2016 12:22:17 -0700 (PDT) Subject: Redacted Message-ID: <6bdceeb7-4775-421b-b066-72fe950adefa@googlegroups.com> Redacted From ascianpipadan at yahoo.com Sun Jul 24 15:22:49 2016 From: ascianpipadan at yahoo.com (GIOVANNI ZIBORDI COBRAF MODENA) Date: Sun, 24 Jul 2016 12:22:49 -0700 (PDT) Subject: Redacted Message-ID: Redacted From bc at freeuk.com Sun Jul 24 16:03:34 2016 From: bc at freeuk.com (BartC) Date: Sun, 24 Jul 2016 21:03:34 +0100 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/07/2016 20:00, Chris Angelico wrote: > On Mon, Jul 25, 2016 at 4:14 AM, BartC wrote: > A skilled craftsman in any field will choose to use quality tools. Materials (ie. languages) are important too. > So why do you use > "dumb editor" as a line of argument, rather than getting a smarter > editor? Perhaps because I prefer to use my own languages and I don't have anyone writing the specialist tools for me that would be necessary. > I don't have a lot of sympathy for people who use suboptimal tools and > expect everything to work for them. Sure, sometimes you're forced to > use something less than ideal (maybe you're stuck on someone else's > Windows box and good tools simply aren't there, and you can't go > installing a ton of stuff just to get started), but then you KNOW > you're working in bad conditions. You don't make that your normal > life. Some of us are used to working with minimalist tools and can be extremely productive with them. But since you used some C, let me give an example of poor design from that language (there are plenty; I've written up quite a big collection of them). You might know that type declarations in C, as soon as you go beyond the basics, become completely impossible and convoluted. I've never managed to get my head around them. There are utilities such as 'Cdecl' that are used to convert a C declaration to English, and vice versa. That's how good a feature they are! So what would have been a better solution here: to have fixed the language, or to have grafted on a simpler type declaration scheme that could co-exist with the old one; or to have ignored the problem and depended on using external tools? Or just insisted that everyone learns that arcane aspect of C, despite it being unreadable and error-prone. (My own solution is that I use a home-made language in place of C, which has fixed most such problems. So my main 'tool' is a custom-made language. And for block delimiting, it uses neither tabbed indents or braces!) -- Bartc From josphine_libraries at hotmail.com Sun Jul 24 16:04:18 2016 From: josphine_libraries at hotmail.com (josphine said) Date: Sun, 24 Jul 2016 20:04:18 +0000 Subject: New to programming and asking about accessibility with jaws screen reader. Message-ID: Hello, I have downloaded python3.6 and found it is not accessible with jaws 17. So, is there any skripts for jaws for that? Or any suggestions? Every guidance will highly appreciated. Thanks. From vfaronov at gmail.com Sun Jul 24 16:10:15 2016 From: vfaronov at gmail.com (Vasiliy Faronov) Date: Sun, 24 Jul 2016 23:10:15 +0300 Subject: Depending on enum34 from a library Message-ID: Hi all, I'm building a Python library where I want to use Python 3.4-style enums. Because I need to support Python 2.7, I'm considering using enum34 [1]. But I'm not sure how to do this: If I simply depend on enum34, it will install a module named `enum` even in Python 3.4+ environments, and that could shadow the stdlib module. Personally I would be very surprised if installing a library caused an unrelated stdlib module to be replaced with a third-party one, even if it's "just" a backport. However, in my environments, `sys.path` is such that stdlib comes before site-packages -- perhaps this is normal enough that I can rely on it? Or I could change my setup.py to include enum34 in `install_requires` only if running on Python 2.7. But that will make my distribution's metadata dynamic, which doesn't sound like a good idea [2]. At the very least, I think it will prevent me from building a universal wheel. So, what's the best current practice here? [1] https://pypi.python.org/pypi/enum34 [2] https://mail.python.org/pipermail/distutils-sig/2009-July/012826.html -- Vasiliy From joseph.lee22590 at gmail.com Sun Jul 24 16:22:37 2016 From: joseph.lee22590 at gmail.com (Joseph Lee) Date: Sun, 24 Jul 2016 13:22:37 -0700 Subject: New to programming and asking about accessibility with jaws screen reader. In-Reply-To: References: Message-ID: <004601d1e5e9$1f223050$5d6690f0$@gmail.com> Hi, How are you running Python - via Command Prompt, perhaps? It might be better to ask a list like program-l (a dedicated programming list for blind devs). Cheers, Joseph -----Original Message----- From: Python-list [mailto:python-list-bounces+joseph.lee22590=gmail.com at python.org] On Behalf Of josphine said Sent: Sunday, July 24, 2016 1:04 PM To: python-list at python.org Subject: New to programming and asking about accessibility with jaws screen reader. Hello, I have downloaded python3.6 and found it is not accessible with jaws 17. So, is there any skripts for jaws for that? Or any suggestions? Every guidance will highly appreciated. Thanks. -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sun Jul 24 17:08:46 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jul 2016 07:08:46 +1000 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jul 25, 2016 at 6:03 AM, BartC wrote: > On 24/07/2016 20:00, Chris Angelico wrote: >> >> On Mon, Jul 25, 2016 at 4:14 AM, BartC wrote: > > >> A skilled craftsman in any field will choose to use quality tools. > > Materials (ie. languages) are important too. Materials, tools, same difference. (Not sure I could even draw the line in software, and ultimately, my line of argument applies equally to both.) >> So why do you use >> "dumb editor" as a line of argument, rather than getting a smarter >> editor? > > > Perhaps because I prefer to use my own languages and I don't have anyone > writing the specialist tools for me that would be necessary. So because you've chosen to use your own languages, you are frustrated at Python because you're not using a decent editor? Get yourself something nice and configurable, so that when you open a Python file it gives you the features you need. I use SciTE, and it quite happily is currently working with text, Pike, Pike Module, reStructuredText, HTML, SRT, and Python files, and that's counting only the ones that I have loaded in it right at this instant. Had some C files up recently (both .c and .h - was editing CPython), and various other things. SciTE doesn't recognize .srt files, so it treats them as plain text - as in, like a dumb editor would. Even if your own language can't be parsed using any existing parser (adding language support usually isn't that hard, if the same parser can be reused), you can still make use of smart editor features for all other languages you work with. Why is this such a problem? Why is it so hard? >> I don't have a lot of sympathy for people who use suboptimal tools and >> expect everything to work for them. Sure, sometimes you're forced to >> use something less than ideal (maybe you're stuck on someone else's >> Windows box and good tools simply aren't there, and you can't go >> installing a ton of stuff just to get started), but then you KNOW >> you're working in bad conditions. You don't make that your normal >> life. > > Some of us are used to working with minimalist tools and can be extremely > productive with them. And then you complain that the language is "fragile" or in some way frustrating to you. Because you've restricted yourself to minimalist tools. Go ahead! Be productive. I'm sure there are people out there saying "I'm used to working with C and can be extremely productive with it". Let 'em. Me, I'll use high level languages and be even more productive. Thanks. > But since you used some C, let me give an example of poor design from that > language (there are plenty; I've written up quite a big collection of them). > > You might know that type declarations in C, as soon as you go beyond the > basics, become completely impossible and convoluted. I've never managed to > get my head around them. > > There are utilities such as 'Cdecl' that are used to convert a C declaration > to English, and vice versa. That's how good a feature they are! > > So what would have been a better solution here: to have fixed the language, > or to have grafted on a simpler type declaration scheme that could co-exist > with the old one; or to have ignored the problem and depended on using > external tools? > > Or just insisted that everyone learns that arcane aspect of C, despite it > being unreadable and error-prone. When do you get those uber-convoluted declarations in C? Sure, they come up in C++ (which is why the language grew some features to manage that complexity), but outside of demonstration code, when do you get actual declarations of massively-nested constructs? I've literally *never* seen them - not rarely, NEVER - in production code. > (My own solution is that I use a home-made language in place of C, which has > fixed most such problems. So my main 'tool' is a custom-made language. > > And for block delimiting, it uses neither tabbed indents or braces!) Sure. You're most welcome to use that. But it doesn't mean that Python is unusable. Plus, I'd much rather trust Python in production than something custom-made, even by me. The performance, reliability, and security of a well-respected language far outstrip anything I could build. ChrisA From rosuav at gmail.com Sun Jul 24 17:10:31 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jul 2016 07:10:31 +1000 Subject: New to programming and asking about accessibility with jaws screen reader. In-Reply-To: References: Message-ID: On Mon, Jul 25, 2016 at 6:04 AM, josphine said wrote: > I have downloaded python3.6 and found it is not accessible with jaws 17. > So, is there any skripts for jaws for that? Exactly what did you download, and where from? ChrisA From mail.python.org at marco.sulla.e4ward.com Sun Jul 24 17:48:09 2016 From: mail.python.org at marco.sulla.e4ward.com (Marco Sulla) Date: Sun, 24 Jul 2016 23:48:09 +0200 Subject: How asyncio works? and event loop vs exceptions In-Reply-To: References: Message-ID: On 23 July 2016 at 16:06, Ian Kelly wrote: > On Fri, Jul 22, 2016 at 6:27 PM, Marco S. via Python-list > wrote: >> Furthermore I have a question about exceptions in asyncio. If I >> understand well how it works, tasks exceptions can be caught only if >> you wait for task completion, with yield from, await or >> loop.run_until_complete(future). But in this case the coroutine blocks >> the execution of the program until it returns. On the contrary you can >> execute the coroutine inside an asyncio task and it will be >> non-blocking, but in this case exceptions can't be caught in a try >> statement. > > If you don't want to block the current function on the task, then spin > off another task to do the error handling. Instead of this: > > async def do_something(): > try: > await do_something_else() > except DidNothingError as e: > handle_error(e) > ... > > Consider this: > > async def do_something(): > get_event_loop().create_task(await_and_handle(do_something_else())) > ... > > async def await_and_handle(awaitable): > try: > await awaitable > except DidNothingError as e: > handle_error(e) Really good suggestion, thank you. From jacob at blindza.co.za Sun Jul 24 17:54:04 2016 From: jacob at blindza.co.za (Jacob Kruger) Date: Sun, 24 Jul 2016 23:54:04 +0200 Subject: New to programming and asking about accessibility with jaws screen reader. In-Reply-To: References: Message-ID: <68eef7b3-2a42-b296-e877-8d6dd39213a2@blindza.co.za> What part is not accessible? Ask since while haven't really gone past 3.4 and 3.5.1, at times, I generally work with specific text/code editors, and the command line window, and this works fine for me with both NVDA, and jaws 17 at times. Stay well Jacob Kruger Blind Biker Skype: BlindZA "Resistance is futile, but, acceptance is versatile..." On 2016-07-24 10:04 PM, josphine said wrote: > Hello, > I have downloaded python3.6 and found it is not accessible with jaws 17. > So, is there any skripts for jaws for that? > Or any suggestions? > Every guidance will highly appreciated. > Thanks. From bc at freeuk.com Sun Jul 24 18:13:30 2016 From: bc at freeuk.com (BartC) Date: Sun, 24 Jul 2016 23:13:30 +0100 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 24/07/2016 22:08, Chris Angelico wrote: > On Mon, Jul 25, 2016 at 6:03 AM, BartC wrote: >> Perhaps because I prefer to use my own languages and I don't have anyone >> writing the specialist tools for me that would be necessary. > > So because you've chosen to use your own languages, you are frustrated > at Python because you're not using a decent editor? My point is that with a bit more thought into the design of a language, clever tools would be less important. A language should stand by itself and not lean on specialist tools to be make it more usable. A solid end-of-block symbol (as you get with 'else' and 'except' because then you KNOW that's the end of that block) would have been welcome with the Python indent scheme. > Get yourself > something nice and configurable, so that when you open a Python file > it gives you the features you need. I use SciTE, I have one big problem with most editors (including SciTE): they are not properly line-oriented. If you hold down Backspace in the middle of a line, it won't just delete until it hits the beginning of the line; it keeps going! I can't live with that: editing would be like walking on eggshells. I need hard line stops. (I can't touch type; I need to look at the keyboard a lot.) (And SciTE won't support a custom language for highlighting and stuff. Maybe it's configurable, but there seems to be a lexer module that needs to be provided. Suddenly it seems a lot of work to do.) > Why is this such a problem? Why is it so hard? Who says it's a problem? I'm quite happy with the screen editors I use that are little changed since the early 80s (and before that I used line editors; now those /were/ horrible). >> You might know that type declarations in C, as soon as you go beyond the >> basics, become completely impossible and convoluted. > When do you get those uber-convoluted declarations in C? (They don't need to be elaborate to start being confusing. Take 'int *a[]' and 'int (*a)[]'; one of these is an array of pointers, the other a pointer to an array. Quite different! But which is which? And when you start dealing with pointers to functions, now you're talking! And yes C++ takes this to a whole new dimension. What a language...) >> And for block delimiting, it uses neither tabbed indents or braces!) > > Sure. You're most welcome to use that. But it doesn't mean that Python > is unusable. It's not unusable. Just a minor nuisance (working with Python using my editor). And troublesome pasting Python code from elsewhere which is always full of spaces rather than tabs. (Sometimes uneven mixes of spaces too.) The Python indent thing isn't a big deal. But having 'end' after each (final) block would have made life just a bit simpler. The whole topic is a trivial point of syntax. (My only issue with 'pass' is that, for some inexplicable reason, my fingers always type it is '#pass'.) > Plus, I'd much rather trust Python in production than something > custom-made, even by me. The performance, reliability, and security of > a well-respected language far outstrip anything I could build. Well, performance is where I usually have an edge at the minute (with my own interpreted language). But if I had to recommend a language, it would have to be Python (I can't be dealing with users and support and all that...) -- Bartc From ben+python at benfinney.id.au Sun Jul 24 18:18:30 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 25 Jul 2016 08:18:30 +1000 Subject: Depending on enum34 from a library References: Message-ID: <85eg6ir87d.fsf@benfinney.id.au> Vasiliy Faronov writes: > If I simply depend on enum34, it will install a module named `enum` > even in Python 3.4+ environments, and that could shadow the stdlib > module. As far as I know, ?enum34? is intended to provide all the same features as the latest Python 3 standard library's ?enum? library. > Personally I would be very surprised if installing a library > caused an unrelated stdlib module to be replaced with a third-party > one, even if it's "just" a backport. However, in my environments, > `sys.path` is such that stdlib comes before site-packages -- perhaps > this is normal enough that I can rely on it? I think that this is similar to using the ?unit2? library, which is intended to be used in projects to allow Python 2 and Python 3 to run the same code to import ?unittest? and get the features of the latest Python 3 ?unittest?. That is, the existence of ?enum34? is intended to allow you to just depend on that library, import ?enum?, and your code will work correctly in Python 2 and Python 3 unchanged. You are then using a Python 3 feature, just ported to an external library. The advantage is that when eventually you stop supporting Python 2, you can drop the external library, and your code keeps on importing ?enum? and works. Now, you may not trust that will work as seamlessly as described! That's reasonable, and it is your choice whether the risk is worth it. Consider the maintainer of the library, consider what they say about how the library is expected to be used now and in the future, and choose which risk to take. -- \ ?If one tells the truth, one is sure, sooner or later, to be | `\ found out.? ?Oscar Wilde, _Phrases and Philosophies for the Use | _o__) of the Young_, 1894 | Ben Finney From jacob at blindza.co.za Sun Jul 24 18:31:07 2016 From: jacob at blindza.co.za (Jacob Kruger) Date: Mon, 25 Jul 2016 00:31:07 +0200 Subject: New to programming and asking about accessibility with jaws screen reader. In-Reply-To: References: <38dba969-22fd-e468-2736-7da72f6fe336@blindza.co.za> Message-ID: <3f25ecfd-2659-1e36-419a-4281a9a4e975@blindza.co.za> Presume you're talking about python idle IDE? Forget it, and, like said, I use edSharp programmers text editor, and work from command line/console when want to test/run my code. Stay well Jacob Kruger Blind Biker Skype: BlindZA "Resistance is futile, but, acceptance is versatile..." On 2016-07-25 12:14 AM, josphine said wrote: > Thanks for your care, > Downloaded it from the python download page, (86-64 bit). > It reads only the menus, when i try to write anything , readable only with the curser,,. > > Maybe i don't know exactly how to use it, > So if possible that anyone walk with me step by step?? > Sorry for that. > Thanks, god bless you all. > > Sent from my iPhone > >> On Jul 24, 2016, at 11:52 PM, Jacob Kruger wrote: >> >> What part is not accessible? >> >> >> Ask since while haven't really gone past 3.4 and 3.5.1, at times, I generally work with specific text/code editors, and the command line window, and this works fine for me with both NVDA, and jaws 17 at times. >> >> >> Stay well >> >> >> Jacob Kruger >> Blind Biker >> Skype: BlindZA >> "Resistance is futile, but, acceptance is versatile..." >> >>> On 2016-07-24 10:04 PM, josphine said wrote: >>> Hello, >>> I have downloaded python3.6 and found it is not accessible with jaws 17. >>> So, is there any skripts for jaws for that? >>> Or any suggestions? >>> Every guidance will highly appreciated. >>> Thanks. > From greg.ewing at canterbury.ac.nz Sun Jul 24 20:40:05 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 25 Jul 2016 12:40:05 +1200 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: BartC wrote: > On 24/07/2016 14:24, Chris Angelico wrote: > >> No, it's an example of how *mixing tabs and spaces* can go wrong. And >> in fact will always go wrong unless you legislate the width of a tab. > > That's easy to say. How do you actually ensure that they aren't mixed? > The software may not highlight the difference. Python 3 will tell you immediately, since it forbids mixing tabs and spaces. >>> def f(): ... a ... b File "", line 3 b ^ TabError: inconsistent use of tabs and spaces in indentation > So I still think it's fragile, meaning you have to take a lot of extra > care. The practical experience of a very large number of Python programmers suggests that it requires very little additional care over and above that normally required for programming. What's your experience? How often has this caused you trouble, and what proportion is it of all the Python programming you've done? -- Greg From rustompmody at gmail.com Sun Jul 24 20:56:58 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 24 Jul 2016 17:56:58 -0700 (PDT) Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, July 25, 2016 at 1:33:48 AM UTC+5:30, BartC wrote: > On 24/07/2016 20:00, Chris Angelico wrote: > > On Mon, Jul 25, 2016 at 4:14 AM, BartC wrote: > > > A skilled craftsman in any field will choose to use quality tools. > > Materials (ie. languages) are important too. > > > So why do you use > > "dumb editor" as a line of argument, rather than getting a smarter > > editor? > > Perhaps because I prefer to use my own languages and I don't have anyone > writing the specialist tools for me that would be necessary. This language-vs-IDE divide has been recogized: http://blog.osteele.com/posts/2004/11/ides/ From greg.ewing at canterbury.ac.nz Sun Jul 24 21:04:43 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 25 Jul 2016 13:04:43 +1200 Subject: Why not allow empty code blocks? In-Reply-To: References: <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: BartC wrote: > (They don't need to be elaborate to start being confusing. Take 'int > *a[]' and 'int (*a)[]'; one of these is an array of pointers, the other > a pointer to an array. Quite different! But which is which? Where have you seen 'int (*a)[]' used? I don't think I've ever seen any real-life C code that used a pointer to an array, as opposed to a pointer to the first element of the array. Usually it would just be declared either 'int a[]' or 'int *a'. -- Greg From bc at freeuk.com Sun Jul 24 21:14:46 2016 From: bc at freeuk.com (BartC) Date: Mon, 25 Jul 2016 02:14:46 +0100 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/07/2016 01:40, Gregory Ewing wrote: > BartC wrote: >> So I still think it's fragile, meaning you have to take a lot of extra >> care. > > The practical experience of a very large number of Python > programmers suggests that it requires very little additional > care over and above that normally required for programming. > > What's your experience? How often has this caused you trouble, > and what proportion is it of all the Python programming you've > done? > I've done little Python coding but still, having to use kid gloves for indents does figure quite a bit in that. I can give some more examples but I'll probably be told that I'm using the wrong tools! Which suggest there is a problem, but the effort has gone into working around them using external tools. (But understandable if the language design was fixed 25 years ago.) For example: if cond: a b I want to comment out the if statement temporarily, but I also have to fix the indents: #if cond: a b (Or add the comment and insert a dummy 'if 1:'.) Or I want to add a temporary condition around: a b which again requires me to indent those statements (and unindent them again later). Or I want to permanently have a commented out #if guard around some code: #if cond: a b to be uncommented from time to time (to do with debugging). But it's not as simple as just uncommenting that one line. Or I want to have a temporary print statement within a block, but it needs to be at the right indentation. Not a great imposition, but it's now less visible as a temporary addition. Or I need to move or copy code from one location to another, but the indentation levels are different. This would need fixing in other languages too, but if this is part of a temporary try out which will change again a few minutes later, I can dispense with the correct indentation in another language, until the code is more permanent. In short, because correct indentation is required at all times, it's less flexible when you want to do a lot of messing around. Now, if I was going to do a LOT of Python coding, then I would solve most of those problems (by having my own tool to superimpose a more amenable syntax on the language). For casual work though I have to go along with the indent scheme. (And there are usually other issues with Python that are more troublesome than getting the layout right.) I'll leave you with a code fragment that might be pasted from elsewhere (it's not meant to mean anything): if cond: a b c The question is: is this the whole block? We don't know, as we can't see what came next. But if now I add the next line, and it was this (anything actually with one less indent): if cond2: then yes it was the whole block, IF we assume an indent didn't get clobbered in the process! But if the line happened to be: else: now we know for sure. -- Bartc From ben+python at benfinney.id.au Sun Jul 24 21:45:12 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 25 Jul 2016 11:45:12 +1000 Subject: Why not allow empty code blocks? References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85a8h6qymv.fsf@benfinney.id.au> BartC writes: > On 25/07/2016 01:40, Gregory Ewing wrote: > > What's your experience? How often has this caused you trouble, and > > what proportion is it of all the Python programming you've done? > > I've done little Python coding Then you are not in a position to make the prnouncements about Python's effect on coding efficiency that you are pronouncing, in this and other threads. > I can give some more examples but I'll probably be told that I'm using > the wrong tools! You should gain a lot more experience using Python for productive work, before declaring any effects on productive work inherent to the language design. > Which suggest there is a problem Or that the programming tools of 25 years ago compare poorly to today's tools. Even tools that have existed for 25 years have benefited from the intervening time. No-one uses Emacs *as it was 25 years ago* and expects to be as proficient as someone using Emacs as it is today. -- \ ?Beware of bugs in the above code; I have only proved it | `\ correct, not tried it.? ?Donald Knuth, 1977-03-29 | _o__) | Ben Finney From steve at pearwood.info Sun Jul 24 22:37:24 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 25 Jul 2016 12:37:24 +1000 Subject: Why not allow empty code blocks? References: <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57957b65$0$1584$c3e8da3$5496439d@news.astraweb.com> On Mon, 25 Jul 2016 08:13 am, BartC wrote: > A solid end-of-block symbol (as you get with 'else' and 'except' because > then you KNOW that's the end of that block) would have been welcome with > the Python indent scheme. A solid end-of-block symbol would have been entire redundant and unnecessary. You know when the block ends: it ends when one of two things happen: - you dedent out a level; - you reach the end of file; whichever happens next. Requiring an otherwise pointless end of block delimiter to protect against your cat walking over your keyboard, or clumsy programmers who accidentally hit keys and don't notice, is not a virtue. It doesn't make the language better. It just increases friction when writing code. There are approximately a million billion trillion zillion things that can go wrong if you randomly hit keys without paying attention to what you are doing, and regardless of whether you have a static or dynamic language, only a tiny fraction of them can be detected ahead of time. When you're typing plain English paragraphs like this, why don't you end each sentence with "END", just in case you accidentally delete the punctuation mark and don't notice? END That way, you have less fragile text. END The reader can easily tell when you have the end of a sentence, even if you accidentally delete the full stop, because of the special end marker. END And two end markers could represent the end of a paragraph, just in case you accidentally delete the break between paragraphs? END END Actually, COMMA now that I think about it, COMMA I'm starting to come around to your way of thinking. END We can tag other punctuation marks too, COMMA like commas, COMMA to ensure that our language is less fragile. END No more will you have to fear the ambiguity of accidentally dropping a comma: COLON END END "We invited the strippers, JFK, and Stalin." "We invited the strippers, JFK and Stalin." http://i.imgur.com/fycHx.jpg Instead, COMNA the error becomes obvious: COLON EMD END " QUOTE We invited the strippers, COMMA JFK COMMA and Stalin. END " QUOTE END END -- DASH DASH SPACE END END Steven END END ? QUOTE Cheer up, COMMA ? END they said, COMMA ? QUOTE things could be worse. END ? QUOTE So I cheered up, COMMA and sure enough, COMMA things got worse. END END From torriem at gmail.com Sun Jul 24 22:48:45 2016 From: torriem at gmail.com (Michael Torrie) Date: Sun, 24 Jul 2016 20:48:45 -0600 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4f14af95-de52-df47-9beb-b473bde0ec06@gmail.com> On 07/24/2016 07:14 PM, BartC wrote: > I've done little Python coding but still, having to use kid gloves for > indents does figure quite a bit in that. > > I can give some more examples but I'll probably be told that I'm using > the wrong tools! Which suggest there is a problem, but the effort has > gone into working around them using external tools. (But understandable > if the language design was fixed 25 years ago.) I only code in Python these days and I simply do not find the indenting syntax to be a problem. Far more often I'm bitten by the dynamic nature of Python (would happen in any dynamic language). I'll be using a particular member attribute which I accidentally misspell somewhere and sometimes that results in silent failure. Something doesn't work, but no exception is thrown. Unit tests, and perhaps lint, are required to catch these errors. That is one thing about a dynamic language: comprehensive testing is required as you go along. > > For example: > > if cond: > a > b > > I want to comment out the if statement temporarily, but I also have to > fix the indents: > > #if cond: > a > b Good example, and I've encountered this one, but honestly fixing the indent is best programming practice anyway. If I want to preserve context, copying the entire block and then commenting it out to preserve it is what I prefer. Anyway, I'd want to fix indenting even if I was using braces. Just to make the code readable and maintainable over time as more often than not temporary becomes permanent. If it's truly a temporary removal, your "if 1:" idiom seems most correct to me, with the original condition commented out. Also there are times when I simply don't worry about commenting things out. I just delete them and fix the indenting and move on with life. I can always revert my changes if I end up barking up the wrong tree. > > (Or add the comment and insert a dummy 'if 1:'.) This is a good idea for temporarily taking out the condition. Sounds like good practice to me. > > Or I want to add a temporary condition around: > > a > b > > which again requires me to indent those statements (and unindent them > again later). Or I want to permanently have a commented out #if guard > around some code: > > #if cond: > a > b > > to be uncommented from time to time (to do with debugging). But it's not > as simple as just uncommenting that one line. With a end statement you'd of course have to comment out both the if and the end lines. Just to nitpick. > > Or I want to have a temporary print statement within a block, but it > needs to be at the right indentation. Not a great imposition, but it's > now less visible as a temporary addition. Pretty much all print statements in my code are visible as a temporary addition. There is really little other reason to use it. So every so often I'll search for all my print statements and comment them out or delete them once the code is operational. But even then, using a logging function is probably even better solution. > Or I need to move or copy code from one location to another, but the > indentation levels are different. This would need fixing in other > languages too, but if this is part of a temporary try out which will > change again a few minutes later, I can dispense with the correct > indentation in another language, until the code is more permanent. In venerable old ViM I just highlight the block and move it in or out. Not having editor support would make this very painful. But you'd be wanting to adjust the indenting anyway, in any language. So while it would cause an error in Python, in any other language you'd want to do this anyway, just to make the code readable. > In short, because correct indentation is required at all times, it's > less flexible when you want to do a lot of messing around. I guess I just don't find this to be particularly problematic. And Python is great for doing a lot of messing around in for me. > Now, if I was going to do a LOT of Python coding, then I would solve > most of those problems (by having my own tool to superimpose a more > amenable syntax on the language). For casual work though I have to go > along with the indent scheme. (And there are usually other issues with > Python that are more troublesome than getting the layout right.) I tend to not have a lot of strong opinions about languages I have little experience in. What is it about your experience that leads to such strong opinions about a language you do very little in? I dislike what I see of Ruby but I have no opinions strong enough to voice on the Ruby lists (or even read them). Just curious. > I'll leave you with a code fragment that might be pasted from elsewhere > (it's not meant to mean anything): > > if cond: > a > b > c > > The question is: is this the whole block? We don't know, as we can't see > what came next. But if now I add the next line, and it was this > (anything actually with one less indent): > > if cond2: > > then yes it was the whole block, IF we assume an indent didn't get > clobbered in the process! But if the line happened to be: > > else: > > now we know for sure. I've never had this problem in Python. I have the source file in front of me. I can scroll down until the block ends. And if the programmer keeps his functions short, it's as readable or more readable than in any other language. I submit you'd have the same readability problem with a very long and deeply blocked C function without the help of something like brace matching in your editor. It's true I can reformat the file to clean up the indenting in a C program, but the author should have done that to begin with. Just because a C function compiles doesn't mean it's correct, and if the indenting is all over the place you can't easily follow the logic and judge its correctness anyway. From rustompmody at gmail.com Sun Jul 24 22:48:48 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 24 Jul 2016 19:48:48 -0700 (PDT) Subject: Can math.atan2 return INF? In-Reply-To: <5774d75d$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <57697e61$0$1590$c3e8da3$5496439d@news.astraweb.com> <1mp7m3g.picev12e77h4N%pdorange@pas-de-pub-merci.mac.com> <5769ec12$0$1610$c3e8da3$5496439d@news.astraweb.com> <87d1n9kzk9.fsf@bsb.me.uk> <1mp9e9m.s25gk61k28dhhN%pdorange@pas-de-pub-merci.mac.com> <87inx1janx.fsf@bsb.me.uk> <576b5eb4$0$1595$c3e8da3$5496439d@news.astraweb.com> <576b8576$0$1510$c3e8da3$5496439d@news.astraweb.com> <877fdgj7f4.fsf@bsb.me.uk> <576c1207$0$1597$c3e8da3$5496439d@news.astraweb.com> <1mpb97o.f86qm9eqx9uyN%pdorange@pas-de-pub-merci.mac.com> <87shw3es70.fsf@elektro.pacujo.net> <57739650$0$1601$c3e8da3$5496439d@news.astraweb.com> <87mvm4uux1.fsf@elektro.pacujo.net> <5774d75d$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9902c200-52d0-4e70-baa0-f721a4ed2ee5@googlegroups.com> On Thursday, June 30, 2016 at 1:55:18 PM UTC+5:30, Steven D'Aprano wrote: > On Thursday 30 June 2016 12:13, Rustom Mody wrote: > > > In particular the question: "Are real numbers really real?" is where it > > starts off... http://blog.languager.org/2015/03/cs-history-0.html > > The pre-history of what later became computer science is very interesting, but > I fear that you are too focused on questions of "mysticism" and not enough on > what those people actually did and said. I?ve been preparing material for some classes on Theory of Computation (ToC) Starting from the premise that in a way G?del is more primary to ToC than Turing [And also been fan of G?del-Escher-Bach from my college days] And came across this proof (by G?del!) that God exists : https://en.wikipedia.org/wiki/G%C3%B6del%27s_ontological_proof From rosuav at gmail.com Sun Jul 24 23:12:02 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jul 2016 13:12:02 +1000 Subject: Why not allow empty code blocks? In-Reply-To: <4f14af95-de52-df47-9beb-b473bde0ec06@gmail.com> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <4f14af95-de52-df47-9beb-b473bde0ec06@gmail.com> Message-ID: On Mon, Jul 25, 2016 at 12:48 PM, Michael Torrie wrote: > Far more often I'm bitten by the dynamic nature of Python (would happen > in any dynamic language). I'll be using a particular member attribute > which I accidentally misspell somewhere and sometimes that results in > silent failure. Something doesn't work, but no exception is thrown. > Unit tests, and perhaps lint, are required to catch these errors. That > is one thing about a dynamic language: comprehensive testing is required > as you go along. > To be quite honest, comprehensive testing is needed in more static languages too. There are certain categories of error which can be detected by a compiler/linter, and certain which cannot; a language that forces you to declare variables will catch variable name misspellings, but only if they don't land you on an existing variable, and still won't catch the dynamic places like dict keys (imagine getting a block of JSON from somewhere, converting it into a dictionary, and looking up stuff in it - the compiler can't know whether your incoming data is correct and your code wrong, or the other way around). A language with less dynamism might be able to catch more, but still not everything, so ultimately, it all comes down to testing anyway. ChrisA From rustompmody at gmail.com Sun Jul 24 23:20:16 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 24 Jul 2016 20:20:16 -0700 (PDT) Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <4f14af95-de52-df47-9beb-b473bde0ec06@gmail.com> Message-ID: On Monday, July 25, 2016 at 8:42:21 AM UTC+5:30, Chris Angelico wrote: > On Mon, Jul 25, 2016 at 12:48 PM, Michael Torrie wrote: > > Far more often I'm bitten by the dynamic nature of Python (would happen > > in any dynamic language). I'll be using a particular member attribute > > which I accidentally misspell somewhere and sometimes that results in > > silent failure. Something doesn't work, but no exception is thrown. > > Unit tests, and perhaps lint, are required to catch these errors. That > > is one thing about a dynamic language: comprehensive testing is required > > as you go along. > > > > To be quite honest, comprehensive testing is needed in more static > languages too. There are certain categories of error which can be > detected by a compiler/linter, and certain which cannot; a language > that forces you to declare variables will catch variable name > misspellings, but only if they don't land you on an existing variable, > and still won't catch the dynamic places like dict keys (imagine > getting a block of JSON from somewhere, converting it into a > dictionary, and looking up stuff in it - the compiler can't know > whether your incoming data is correct and your code wrong, or the > other way around). A language with less dynamism might be able to > catch more, but still not everything, So far ? Fine! > so ultimately, it all comes down to testing anyway. All?? There is a famous quote by Dijkstra: ?Testing shows the presence, not the absence of bugs? Or if you prefer things of a more ?practical? (so-called_ nature: http://www.testingexcellence.com/reasons-automated-tests-fail-to-find-regression-bugs/ From rosuav at gmail.com Sun Jul 24 23:28:53 2016 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Jul 2016 13:28:53 +1000 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <4f14af95-de52-df47-9beb-b473bde0ec06@gmail.com> Message-ID: On Mon, Jul 25, 2016 at 1:20 PM, Rustom Mody wrote: >> so ultimately, it all comes down to testing anyway. > > All?? > > There is a famous quote by Dijkstra: > ?Testing shows the presence, not the absence of bugs? > > Or if you prefer things of a more ?practical? (so-called_ nature: > http://www.testingexcellence.com/reasons-automated-tests-fail-to-find-regression-bugs/ If testing won't find the bugs, what will? By "testing", I don't just mean automated tests, although of course that's one of the most efficient ways. Dogfooding is an important part of testing too. ChrisA From rustompmody at gmail.com Sun Jul 24 23:46:46 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 24 Jul 2016 20:46:46 -0700 (PDT) Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <4f14af95-de52-df47-9beb-b473bde0ec06@gmail.com> Message-ID: <2ce4424a-89d3-4d56-9cd7-7b3a79076150@googlegroups.com> On Monday, July 25, 2016 at 8:59:10 AM UTC+5:30, Chris Angelico wrote: > On Mon, Jul 25, 2016 at 1:20 PM, Rustom Mody wrote: > >> so ultimately, it all comes down to testing anyway. > > > > All?? > > > > There is a famous quote by Dijkstra: > > ?Testing shows the presence, not the absence of bugs? > > > > Or if you prefer things of a more ?practical? (so-called_ nature: > > http://www.testingexcellence.com/reasons-automated-tests-fail-to-find-regression-bugs/ > > If testing won't find the bugs, what will? By "testing", I don't just > mean automated tests, although of course that's one of the most > efficient ways. Dogfooding is an important part of testing too. Dijkstra made that (and such) statements towards advocating formal program proving. Whether we agree/disagree with that line is one thing. The bald fact that tests are finite and the actual search space for cases for anything remotely non-trivial is infinite is undeniable. From steve at pearwood.info Mon Jul 25 00:27:13 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 25 Jul 2016 14:27:13 +1000 Subject: Why not allow empty code blocks? References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <4f14af95-de52-df47-9beb-b473bde0ec06@gmail.com> Message-ID: <57959523$0$1586$c3e8da3$5496439d@news.astraweb.com> On Mon, 25 Jul 2016 01:20 pm, Rustom Mody wrote: >> so ultimately, it all comes down to testing anyway. > > All?? Ultimately, yes. It all comes down to testing. How else do you know that your program to flernge the widget *actually* flernges the widget or not? > There is a famous quote by Dijkstra: > ?Testing shows the presence, not the absence of bugs? Correct. And as Knuth said: "Beware of bugs in the above code; I have only proved it correct, not tried it." You cannot *prove* the absence of bugs in a large, complex program, because how do you know your proof is correct? Your automatic prover is a program, which will contain bugs. If you don't use an automatic prover, then how do you know you didn't make a mistake in your manual proof? Ultimately, any program beyond a certain level of complexity can only be *suspected* to be correct. > Or if you prefer things of a more ?practical? (so-called_ nature: > http://www.testingexcellence.com/reasons-automated-tests-fail-to-find-regression-bugs/ -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve at pearwood.info Mon Jul 25 00:28:35 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 25 Jul 2016 14:28:35 +1000 Subject: Pythons for .Net Message-ID: <57959574$0$1586$c3e8da3$5496439d@news.astraweb.com> Yes, I said Pythons plural :-) For those wanting to use Python on .Net or Mono, there is some good news. Firstly, the venerable old "Python for .Net" project is still alive, and now supports up to Python 3.5 on .Net or Mono. PythonNet, as this is known, integrates the regular CPython interpreter with .Net or Mono. Secondly, we can also expect that IronPython will have a new lease of life. Continuing on the work of their predecessor, Jeff Hardy, the IronPython project now has two tech leads who will carry it forward: Alex Earl and Benedikt Eggers. https://thelasttechie.com/2016/07/24/its-back-python-for-net/ IronPython is a reimplementation of Python, written in C# as managed code for .Net. It doesn't use a GIL, and is sometimes considered a little faster than CPython, so this is good news for the Python ecosystem. IronPython: http://ironpython.net/ Python for .Net: https://github.com/pythonnet/pythonnet http://pythonnet.github.io/ https://pypi.python.org/pypi/pythonnet -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+comp.lang.python at pearwood.info Mon Jul 25 03:20:21 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 25 Jul 2016 17:20:21 +1000 Subject: Why not allow empty code blocks? References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <4f14af95-de52-df47-9beb-b473bde0ec06@gmail.com> <2ce4424a-89d3-4d56-9cd7-7b3a79076150@googlegroups.com> Message-ID: <5795bdb6$0$1526$c3e8da3$5496439d@news.astraweb.com> On Monday 25 July 2016 13:46, Rustom Mody wrote: > The bald fact that tests are finite and the actual search space for cases for > anything remotely non-trivial is infinite is undeniable. I deny it :-P "Infinity" is pretty big. It's *really* big. It's bigger than most people think. You might think your credit card bill last month was big, but infinity is much bigger. Mathematicians deal with numbers which are so unfathomably huge that we can't even talk about them using the ordinary notation we use for ordinary numbers. Take something as unbelievably big as Graham's Number, so big they had to invent specialised notation just to discuss it: http://mathworld.wolfram.com/GrahamsNumber.html http://www.youtube.com/watch?v=XTeJ64KD5cg Let's make it bigger! Square it. No, cube it! Take the factorial! Cube it again! Raise that number to the power of itself! Add one! Compared to infinity, this new number is infinitesimally tiny. Compared to infinity, this new number is barely even there. Compared to infinity, that new number might as well be zero. Given that any actual program has to *exist* in order to be tested, it must be finite in size. Since the observable universe contains "merely" something of the order of 10**89 or so elementary particles (electrons, protons, etc) even with the combinatory explosion of possibilities, the upper bound on the number of test cases will be something like (10**89)**(10**89), which is minuscule compared to Graham's Number, let alone our even Vaster number. Which is so far short of infinity that in one sense we can say that it has barely even taken a single step in the direction of infinity. (Of course I realise you were using "infinite" just as hyperbole. I just couldn't resist bringing Graham's Number into the discussion.) -- Steve From bc at freeuk.com Mon Jul 25 05:44:53 2016 From: bc at freeuk.com (BartC) Date: Mon, 25 Jul 2016 10:44:53 +0100 Subject: Why not allow empty code blocks? In-Reply-To: References: <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/07/2016 02:04, Gregory Ewing wrote: > BartC wrote: >> (They don't need to be elaborate to start being confusing. Take 'int >> *a[]' and 'int (*a)[]'; one of these is an array of pointers, the >> other a pointer to an array. Quite different! But which is which? > > Where have you seen 'int (*a)[]' used? I don't think I've > ever seen any real-life C code that used a pointer to an > array, as opposed to a pointer to the first element of the > array. (Yes everyone uses T*a (pointer to T) instead of T(*a)[] (pointer to array of T), because, thanks to how C mixes up deferencing and indexing, the former can be accessed as a[i] instead of (*a)[i]. But it's wrong, and leads to errors that the language can't detect. Such as when a points to a single element not a block: define ANY combination such as 'pointer to pointer to array'; you need to access an element using (deref, deref, index), but C also allows (index, deref, deref) or (deref, index, deref), or (index, index, index). Provided the right number of deref/index ops are provided, C can't tell the difference because derefs and index ops are interchangeable! But only one combination is correct. I came across T(*a)[] when translating from a language that handles this properly, into C. In fact I use the translator to convert type-specs from straightforward format into C. Another tool to get around a flaw.) -- Bartc From bc at freeuk.com Mon Jul 25 06:39:21 2016 From: bc at freeuk.com (BartC) Date: Mon, 25 Jul 2016 11:39:21 +0100 Subject: Why not allow empty code blocks? In-Reply-To: <57957b65$0$1584$c3e8da3$5496439d@news.astraweb.com> References: <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> <57957b65$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25/07/2016 03:37, Steven D'Aprano wrote: > On Mon, 25 Jul 2016 08:13 am, BartC wrote: > >> A solid end-of-block symbol (as you get with 'else' and 'except' because >> then you KNOW that's the end of that block) would have been welcome with >> the Python indent scheme. > > A solid end-of-block symbol would have been entire redundant and > unnecessary. You know when the block ends: it ends when one of two things > happen: > > - you dedent out a level; > - you reach the end of file; > whichever happens next. Requiring an otherwise pointless end of block > delimiter to protect against your cat walking over your keyboard, or clumsy > programmers who accidentally hit keys and don't notice, is not a virtue. It > doesn't make the language better. It just increases friction when writing > code. Remember when movies used to finish with "The End"? I wonder what that was all about? After all you can tell when it's finished when you see the opening titles of the next movie! Or when the lights come back up in the cinema ('theater'). If you've ever watched Monty Python (on topic!) and the Holy Grail at the cinema, you will have appreciated it even more. You just get a black screen and nothing more happens. People were waiting for several minutes, eventually starting to get up and leave. END may seem redundant, but it's just very handy. You know FOR SURE you are at a particular point, instead of having to infer it from what may or may not come next, which might not be visible off the bottom of the screen. > When you're typing plain English paragraphs like this, why don't you end > each sentence with "END" The period is more the equivalent of C's semicolon. That nearly always coincides with end-or-line so also lends itself to be inferred, as horizontally source code tends to be a limited width. But otherwise free-flowing English text is not a good comparison with a programming language syntax. -- Bartc From robin at reportlab.com Mon Jul 25 07:02:49 2016 From: robin at reportlab.com (Robin Becker) Date: Mon, 25 Jul 2016 12:02:49 +0100 Subject: Algorithm for sequencing a collection of dependent equations In-Reply-To: <1469203273.1522601.673919081.7AC3AFEA@webmail.messagingengine.com> References: <1469203273.1522601.673919081.7AC3AFEA@webmail.messagingengine.com> Message-ID: On 22/07/2016 17:01, Malcolm Greene wrote: .......... > Here's an example of expressions and their full list of dependencies: > > a = b + b + b + c + c > b, c, d, e, s, t, x > b = c + d + e > c, d, e, s, t, x > c = s + 3 > s, x > d = t + 1 > t > e = t + 2 > t > s = x + 100 > x > t = 10 > None > x = 1 > None > y = 2 > None > > I'm looking for an algorithm/data structure that will me to start with > the least dependent expression (t, x, y) and move through the list of > expressions in dependency order ending with the expression with the most > dependencies. > > I imagine that spreadsheets have to perform a similar type of analysis > to figure out how to recalculate their cells. > > Suggestions on algorithms and/or data structures (some form of graph?) > to support the above goals? > > Thank you, > Malcolm > assuming you have no loops then the topological sort is what you need. If you have mutual dependencies then you need to find a set of variables that cuts all the loops and solve for those simultaneously. Unfortunately for a directed graph structure I think the minimal cutset problem is NP complete so good luck with that. -- Robin Becker From random832 at fastmail.com Mon Jul 25 10:36:56 2016 From: random832 at fastmail.com (Random832) Date: Mon, 25 Jul 2016 10:36:56 -0400 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1469457416.2293088.676076929.367DBBE3@webmail.messagingengine.com> On Sun, Jul 24, 2016, at 18:13, BartC wrote: > (They don't need to be elaborate to start being confusing. Take 'int > *a[]' and 'int (*a)[]'; one of these is an array of pointers, the other > a pointer to an array. Quite different! But which is which? int (*a)[]; === int x[]; where x is (*a). To work out the other one you need to know operator precedence, but you need to know operator precedence to understand a _lot_ of things. C type _casts_ are slightly harder, since you have to work out where the identifier belongs in a token sequence that has had it removed. But it's usually not hard [look for the sequence "*)", which is otherwise illegal and appears in most complicated type casts]. From Joaquin.Alzola at lebara.com Mon Jul 25 12:45:23 2016 From: Joaquin.Alzola at lebara.com (Joaquin Alzola) Date: Mon, 25 Jul 2016 16:45:23 +0000 Subject: Unittest Message-ID: Hi Guys I have a question related to unittest. I suppose a SW that is going to live will not have any trace of unittest module along their code. So is it the way to do it to put all unittest in a preproduction environment and then remove all lines relate to unittest once the SW is release into production? What is the best way of working with unittest? BR Joaquin This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. From rustompmody at gmail.com Mon Jul 25 12:54:59 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 25 Jul 2016 09:54:59 -0700 (PDT) Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <85a8h6qymv.fsf@benfinney.id.au> Message-ID: <436abc76-29e8-4964-859d-b1223a1c7528@googlegroups.com> On Monday, July 25, 2016 at 7:15:36 AM UTC+5:30, Ben Finney wrote: > Even tools that have existed for 25 years have benefited from the > intervening time. No-one uses Emacs *as it was 25 years ago* and expects > to be as proficient as someone using Emacs as it is today. As a general comment ? fine Your exemplar however is ironic What everyone calls window it calls frame; what everyone calls pane it calls window because its legacy from pre-gui days What everyone calls Alt it calls Meta and shortens it to ?M-? because the Sun workstations that have been dead 20 years had a Meta-key And the most annoying bugbear: The whole world uses cua keys: https://en.wikipedia.org/wiki/IBM_Common_User_Access it proudly sticks to what it was doing pre-cua I could go on? From rosuav at gmail.com Mon Jul 25 13:02:29 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Jul 2016 03:02:29 +1000 Subject: Why not allow empty code blocks? In-Reply-To: <436abc76-29e8-4964-859d-b1223a1c7528@googlegroups.com> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <85a8h6qymv.fsf@benfinney.id.au> <436abc76-29e8-4964-859d-b1223a1c7528@googlegroups.com> Message-ID: On Tue, Jul 26, 2016 at 2:54 AM, Rustom Mody wrote: > The whole world uses cua keys: > https://en.wikipedia.org/wiki/IBM_Common_User_Access > [emacs] proudly sticks to what it was doing pre-cua Sadly, the "whole world" doesn't. Windows itself lacks quite a few of the CUA keys (ask a Windows user how to move a window with the keyboard, and s/he won't say "Alt-F7"), and some Windows applications make this even worse (Adobe Reader egregiously so - you can't even use Ctrl-Ins to copy to the clipboard, despite all the rest of Windows supporting it). But hey. MOST of the world uses the CUA keys. And yes, Emacs doesn't. For better or for worse, you have to learn Emacs as its own thing. ChrisA From rustompmody at gmail.com Mon Jul 25 13:11:49 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 25 Jul 2016 10:11:49 -0700 (PDT) Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <85a8h6qymv.fsf@benfinney.id.au> <436abc76-29e8-4964-859d-b1223a1c7528@googlegroups.com> Message-ID: <654dbafd-6ac8-4f96-b7c5-03200454aeca@googlegroups.com> On Monday, July 25, 2016 at 10:32:45 PM UTC+5:30, Chris Angelico wrote: > On Tue, Jul 26, 2016 at 2:54 AM, Rustom Mody wrote: > > The whole world uses cua keys: > > https://en.wikipedia.org/wiki/IBM_Common_User_Access > > [emacs] proudly sticks to what it was doing pre-cua > > Sadly, the "whole world" doesn't. Windows itself lacks quite a few of > the CUA keys (ask a Windows user how to move a window with the > keyboard, and s/he won't say "Alt-F7"), and some Windows applications > make this even worse (Adobe Reader egregiously so - you can't even use > Ctrl-Ins to copy to the clipboard, despite all the rest of Windows > supporting it). Ok I was speaking in-a-manner-of-speaking -- in two ways All means most Cua means the most common cua-keys ? C-x C-c C-v of which the first two specially are so deeply embedded into emacs as prefixes for 100s of other functions that its hard to change without significant upheaval > > But hey. MOST of the world uses the CUA keys. And yes, Emacs doesn't. > For better or for worse, you have to learn Emacs as its own thing. Yeah? Just playing around with magit It the tool of choice in emacs world as a git client And in all probability the best git client around So yes emacs is unbeatable and emacs is obsolete And that?s what makes it so annoying ? impossible to find a replacement From rosuav at gmail.com Mon Jul 25 13:26:22 2016 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Jul 2016 03:26:22 +1000 Subject: Why not allow empty code blocks? In-Reply-To: <654dbafd-6ac8-4f96-b7c5-03200454aeca@googlegroups.com> References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <85a8h6qymv.fsf@benfinney.id.au> <436abc76-29e8-4964-859d-b1223a1c7528@googlegroups.com> <654dbafd-6ac8-4f96-b7c5-03200454aeca@googlegroups.com> Message-ID: On Tue, Jul 26, 2016 at 3:11 AM, Rustom Mody wrote: > On Monday, July 25, 2016 at 10:32:45 PM UTC+5:30, Chris Angelico wrote: >> On Tue, Jul 26, 2016 at 2:54 AM, Rustom Mody wrote: >> > The whole world uses cua keys: >> > https://en.wikipedia.org/wiki/IBM_Common_User_Access >> > [emacs] proudly sticks to what it was doing pre-cua >> >> Sadly, the "whole world" doesn't. Windows itself lacks quite a few of >> the CUA keys (ask a Windows user how to move a window with the >> keyboard, and s/he won't say "Alt-F7"), and some Windows applications >> make this even worse (Adobe Reader egregiously so - you can't even use >> Ctrl-Ins to copy to the clipboard, despite all the rest of Windows >> supporting it). > > Ok I was speaking in-a-manner-of-speaking -- in two ways > All means most > Cua means the most common cua-keys ? C-x C-c C-v > of which the first two specially are so deeply embedded into emacs as prefixes > for 100s of other functions that its hard to change without significant upheaval Wrong - CUA's standard keys are Shift-Del, Ctrl-Ins, Shift-Ins for the same operations. The alphabetics are not part of the CUA standard. That said, though, most applications support both - primarily because most GUI widgets are built to support both, and applications are taught to respond to signals like 'paste'. This is one of those cases where building your own is both way more work AND way less useful to people; the same thing often happens when a program decides to be "cute" with its UI and get rid of the title bar and regular frame, painting its own window borders and stuff. It's a lot of work to make that look decent, and then you end up with something that doesn't play nicely with the rest of the system. You'd better have a really good justification for that - and no, "it looks pretty" is NOT that justification. ChrisA From bc at freeuk.com Mon Jul 25 13:33:59 2016 From: bc at freeuk.com (BartC) Date: Mon, 25 Jul 2016 18:33:59 +0100 Subject: Why not allow empty code blocks? In-Reply-To: References: <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> <1469457416.2293088.676076929.367DBBE3@webmail.messagingengine.com> Message-ID: On 25/07/2016 15:36, Random832 wrote: > On Sun, Jul 24, 2016, at 18:13, BartC wrote: [About C type specs] I've replied briefly here as this is off-topic now: http://pastebin.com/ZfcHqpXK -- Bartc From python at bdurham.com Mon Jul 25 15:16:21 2016 From: python at bdurham.com (Malcolm Greene) Date: Mon, 25 Jul 2016 15:16:21 -0400 Subject: Caller's module name, function/method name and line number for output to logging Message-ID: <1469474181.734306.676367265.29267D36@webmail.messagingengine.com> Is there a technique for accessing a function's *CALLER* module name, function/method name and line number so that this information can be passed to a logging library's logger? I have a routine that detects an error condition, but I want to report the error's context relative to the caller, not the current function. TD;LR: I want to peek 1 level up the call stack for this information. A bonus would be a way to have my logger use info vs the current %(module)s, %(funcName)s, and %(lineno)d values. Thank you, Malcolm From tjreedy at udel.edu Mon Jul 25 17:07:19 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 25 Jul 2016 17:07:19 -0400 Subject: Caller's module name, function/method name and line number for output to logging In-Reply-To: <1469474181.734306.676367265.29267D36@webmail.messagingengine.com> References: <1469474181.734306.676367265.29267D36@webmail.messagingengine.com> Message-ID: On 7/25/2016 3:16 PM, Malcolm Greene wrote: > 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 needs to look 2 levels up. > passed to a logging library's logger? I have a routine that detects an > error condition, but I want to report the error's context relative to > the caller, not the current function. TD;LR: I want to peek 1 level up > the call stack for this information. A bonus would be a way to have my > logger use info vs the current %(module)s, %(funcName)s, and > %(lineno)d values. -- Terry Jan Reedy From python at bdurham.com Mon Jul 25 18:40:29 2016 From: python at bdurham.com (Malcolm Greene) Date: Mon, 25 Jul 2016 18:40:29 -0400 Subject: Caller's module name, function/method name and line number for output to logging In-Reply-To: References: <1469474181.734306.676367265.29267D36@webmail.messagingengine.com> Message-ID: <1469486429.2217869.676546129.5F3AEEE4@webmail.messagingengine.com> 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 needs to look 2 levels up. Perfect! That's exactly what I was looking for. Thank you, Malcolm From steve at pearwood.info Mon Jul 25 21:12:11 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 26 Jul 2016 11:12:11 +1000 Subject: Spot the bug: getoptquestion.py References: <577a4766$0$5839$e4fe514c@news.xs4all.nl> <577e3d66$0$5816$e4fe514c@news.xs4all.nl> Message-ID: <5796b8ec$0$1603$c3e8da3$5496439d@news.astraweb.com> On Thu, 7 Jul 2016 09:30 pm, Oscar wrote: > Thanks all for the input. I think it all boils down to: "If you don't > want a space in your long_option, don't put a space in there". No, I don't think so. I think we can do better than that: http://bugs.python.org/issue27619 What decided it for me was that the shell getopt on my system ignores leading and trailing spaces. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From 007brendan at gmail.com Mon Jul 25 21:15:37 2016 From: 007brendan at gmail.com (Brendan Abel) Date: Mon, 25 Jul 2016 18:15:37 -0700 Subject: Unittest In-Reply-To: References: Message-ID: Generally, all your unittests will be inside a "tests" directory that lives outside your package directory. That directory will be excluded when you build or install your project using your setup.py script. Take a look at some popular 3rd party python packages to see how they structure their projects and setup their setup.py. On Mon, Jul 25, 2016 at 9:45 AM, Joaquin Alzola wrote: > Hi Guys > > I have a question related to unittest. > > I suppose a SW that is going to live will not have any trace of unittest > module along their code. > > So is it the way to do it to put all unittest in a preproduction > environment and then remove all lines relate to unittest once the SW is > release into production? > > What is the best way of working with unittest? > > BR > > Joaquin > > This email is confidential and may be subject to privilege. If you are not > the intended recipient, please do not copy or disclose its content but > contact the sender immediately upon receipt. > -- > https://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Mon Jul 25 22:30:03 2016 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 26 Jul 2016 12:30:03 +1000 Subject: Unittest References: Message-ID: <851t2hqggk.fsf@benfinney.id.au> Joaquin Alzola writes: > I suppose a SW that is going to live will not have any trace of > unittest module along their code. Many packages are deployed with their unit test suite. The files don't occupy much space, don't interfere with the running of the program, and can be helpful to run the tests in the deployed environment. > So is it the way to do it to put all unittest in a preproduction > environment and then remove all lines relate to unittest once the SW > is release into production? I would advise not to bother. Prepare the release of the entire source needed to build the distribution, and don't worry about somehow excluding the test suite. > This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. Please do not use an email system which appends these obnoxious messages in a public forum. Either convince the people who impose that false disclaimer onto your message to stop doing that; or, stop using that system for writing to a public forum. -- \ ?Are you pondering what I'm pondering?? ?Umm, I think so, Don | `\ Cerebro, but, umm, why would Sophia Loren do a musical?? | _o__) ?_Pinky and The Brain_ | Ben Finney From rustompmody at gmail.com Mon Jul 25 22:43:57 2016 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 25 Jul 2016 19:43:57 -0700 (PDT) Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <85a8h6qymv.fsf@benfinney.id.au> <436abc76-29e8-4964-859d-b1223a1c7528@googlegroups.com> <654dbafd-6ac8-4f96-b7c5-03200454aeca@googlegroups.com> Message-ID: <226c0275-fbbf-4cc4-8499-49965ae46f38@googlegroups.com> On Monday, July 25, 2016 at 10:56:41 PM UTC+5:30, Chris Angelico wrote: > On Tue, Jul 26, 2016 at 3:11 AM, Rustom Mody wrote: > > On Monday, July 25, 2016 at 10:32:45 PM UTC+5:30, Chris Angelico wrote: > >> On Tue, Jul 26, 2016 at 2:54 AM, Rustom Mody wrote: > >> > The whole world uses cua keys: > >> > https://en.wikipedia.org/wiki/IBM_Common_User_Access > >> > [emacs] proudly sticks to what it was doing pre-cua > >> > >> Sadly, the "whole world" doesn't. Windows itself lacks quite a few of > >> the CUA keys (ask a Windows user how to move a window with the > >> keyboard, and s/he won't say "Alt-F7"), and some Windows applications > >> make this even worse (Adobe Reader egregiously so - you can't even use > >> Ctrl-Ins to copy to the clipboard, despite all the rest of Windows > >> supporting it). > > > > Ok I was speaking in-a-manner-of-speaking -- in two ways > > All means most > > Cua means the most common cua-keys ? C-x C-c C-v > > of which the first two specially are so deeply embedded into emacs as prefixes > > for 100s of other functions that its hard to change without significant upheaval > > Wrong - CUA's standard keys are Shift-Del, Ctrl-Ins, Shift-Ins for the > same operations. The alphabetics are not part of the CUA standard. > That said, though, most applications support both - primarily because > most GUI widgets are built to support both, and applications are > taught to respond to signals like 'paste'. You must be right Ironically I learnt the word cua from emacs? cua-mode which basically make C-c C-x C-v (dont know which others) behave like the rest of the world expects. Trouble is the first two are so deeply enmeshed into emacs that it does a bad job of it. And conventional wisdom in emacs land is to avoid it and get used to the (30+ year old!) emacs standard From tjreedy at udel.edu Tue Jul 26 01:57:41 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 26 Jul 2016 01:57:41 -0400 Subject: Unittest In-Reply-To: References: Message-ID: On 7/25/2016 12:45 PM, Joaquin Alzola wrote: > Hi Guys > > I have a question related to unittest. > > I suppose a SW that is going to live will not have any trace of > unittest module along their code. In order to test idlelib, I had to a _utest=False (unittest = False) parameter to some functions. They are there when you run IDLE. I like to put if __name__ == '__main__': at the bottom of non-script files. Some people don't like this, but it makes running the tests trivial while editing a file -- whether to make a test pass or to avoid regressions when making 'neutral' changes. > So is it the way to do it to put all unittest in a preproduction > environment and then remove all lines relate to unittest once the SW > is release into production? How would you know that you do not introduce bugs when you change code after testing? When you install Python on Windows, installing the test/ directory is a user option. -- Terry Jan Reedy From __peter__ at web.de Tue Jul 26 02:47:44 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Jul 2016 08:47:44 +0200 Subject: Caller's module name, function/method name and line number for output to logging References: <1469474181.734306.676367265.29267D36@webmail.messagingengine.com> <1469486429.2217869.676546129.5F3AEEE4@webmail.messagingengine.com> Message-ID: 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 needs to look 2 levels up. > > Perfect! That's exactly what I was looking for. Fine! Then you can avoid the evil hack I came up with many moons ago: https://mail.python.org/pipermail/python-list/2010-March/570941.html ;) From greg.ewing at canterbury.ac.nz Tue Jul 26 03:21:14 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 26 Jul 2016 19:21:14 +1200 Subject: Why not allow empty code blocks? In-Reply-To: References: <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: BartC wrote: > (Yes everyone uses T*a (pointer to T) instead of T(*a)[] (pointer to > array of T), because, thanks to how C mixes up deferencing and indexing, > the former can be accessed as a[i] instead of (*a)[i]. > > But it's wrong, and leads to errors that the language can't detect. Such > as when a points to a single element not a block: This is an implementation issue, not a language issue. A sufficiently pedantic implementation could and would detect this kind of error at run time. Most implementations of C are not that pedantic, but you can't blame the language for that. -- Greg From greg.ewing at canterbury.ac.nz Tue Jul 26 03:23:54 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 26 Jul 2016 19:23:54 +1200 Subject: Why not allow empty code blocks? In-Reply-To: References: <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> <57957b65$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: BartC wrote: > But otherwise free-flowing English text is not a good comparison with a > programming language syntax. I think Python is more like poetry. -- roses are red violets are blue is this the end of the poem no-one can tell because there is no end marker thus spake the bdfl From marko at pacujo.net Tue Jul 26 03:56:14 2016 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 26 Jul 2016 10:56:14 +0300 Subject: Why not allow empty code blocks? References: <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87h9bcltnl.fsf@elektro.pacujo.net> Gregory Ewing : > BartC wrote: >> (Yes everyone uses T*a (pointer to T) instead of T(*a)[] (pointer to >> array of T), because, thanks to how C mixes up deferencing and >> indexing, the former can be accessed as a[i] instead of (*a)[i]. >> >> But it's wrong, and leads to errors that the language can't detect. >> Such as when a points to a single element not a block: > > This is an implementation issue, not a language issue. A sufficiently > pedantic implementation could and would detect this kind of error at > run time. Most implementations of C are not that pedantic, but you > can't blame the language for that. Well, one of the novelties in C was the intentional blurring of the lines between arrays and sequences of elements in memory. The notation: int a[3]; declares a as an array. However, the expression: a does not produce an array; instead, it produces a pointer to the first element of the array. Even: *&a produces a pointer to the array's first element. Marko From greg.ewing at canterbury.ac.nz Tue Jul 26 04:35:49 2016 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 26 Jul 2016 20:35:49 +1200 Subject: Why not allow empty code blocks? In-Reply-To: <87h9bcltnl.fsf@elektro.pacujo.net> References: <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> <87h9bcltnl.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > int a[3]; > > a > > produces a pointer to the array's first element. Yes, and that makes using true pointer-to-array types in C really awkward. You're fighting against the way the language was designed to be used. If you use a language in an un-idiomatic way, you can't really complain when you have difficulties as a result. -- Greg From python at bdurham.com Tue Jul 26 05:54:48 2016 From: python at bdurham.com (Malcolm Greene) Date: Tue, 26 Jul 2016 05:54:48 -0400 Subject: Caller's module name, function/method name and line number for output to logging In-Reply-To: References: <1469474181.734306.676367265.29267D36@webmail.messagingengine.com> <1469486429.2217869.676546129.5F3AEEE4@webmail.messagingengine.com> Message-ID: <1469526888.2916983.676979097.6F25A876@webmail.messagingengine.com> Hi Peter, > Fine! Then you can avoid the evil hack I came up with many moons ago: > https://mail.python.org/pipermail/python-list/2010-March/570941.html Evil? Damn evil! Love it! Thank you, Malcolm From python at bdurham.com Tue Jul 26 06:11:04 2016 From: python at bdurham.com (Malcolm Greene) Date: Tue, 26 Jul 2016 06:11:04 -0400 Subject: Possible to capture cgitb style output in a try/except section? Message-ID: <1469527864.2996118.676987281.0EE8893F@webmail.messagingengine.com> 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 believe that the only way I can get cgitb output is to let an exception propagate to the point of terminating my script ... at which point cgitb grabs the exception and does its magic. Thank you, Malcolm From bc at freeuk.com Tue Jul 26 06:11:20 2016 From: bc at freeuk.com (BartC) Date: Tue, 26 Jul 2016 11:11:20 +0100 Subject: Why not allow empty code blocks? In-Reply-To: References: <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 26/07/2016 08:21, Gregory Ewing wrote: > BartC wrote: >> (Yes everyone uses T*a (pointer to T) instead of T(*a)[] (pointer to >> array of T), because, thanks to how C mixes up deferencing and >> indexing, the former can be accessed as a[i] instead of (*a)[i]. >> >> But it's wrong, and leads to errors that the language can't detect. >> Such as when a points to a single element not a block: > > This is an implementation issue, not a language issue. > A sufficiently pedantic implementation could and would > detect this kind of error at run time. Most implementations > of C are not that pedantic, but you can't blame the > language for that. (No, it's a language issue. Yes you might be able to have a sufficiently complex (and slow) implementation that at best could detect errors at runtime, but that's not much help. It boils down to this: if you have a pointer type T*, does it point to a standalone T object, or to an array or block of T objects? The language allows a pointer P of type T* pointing to a single T object to be accessed as P[i]. Apparently this is not seen as a problem... (More observations about C here: https://github.com/bartg/langs/blob/master/C%20Problems.md)) -- Bartc From urschrei at gmail.com Tue Jul 26 08:06:19 2016 From: urschrei at gmail.com (urschrei at gmail.com) Date: Tue, 26 Jul 2016 05:06:19 -0700 (PDT) Subject: NumPy frombuffer giving nonsense values when reading C float array on Windows Message-ID: <4481593b-69fe-4314-aca8-50b783847212@googlegroups.com> 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-element array shape = (10, 2) array_size = np.prod(shape) mem_size = 8 * array_size array_str = ctypes.string_at(ptr, mem_size) # convert to NumPy array,and copy to a list ls = np.frombuffer(array_str, dtype="float64", count=array_size).reshape(shape).tolist() # return pointer so it can be freed drop_array(ptr) return ls This works correctly and consistently on Linux and OSX using NumPy 1.11.0, but fails on Windows 32 bit and 64-bit about 50% of the time, returning nonsense values. Am I doing something wrong? Is there a better way to do this? -- s From steve at pearwood.info Tue Jul 26 09:40:27 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 26 Jul 2016 23:40:27 +1000 Subject: Possible to capture cgitb style output in a try/except section? References: <1469527864.2996118.676987281.0EE8893F@webmail.messagingengine.com> Message-ID: <5797684c$0$1591$c3e8da3$5496439d@news.astraweb.com> On Tue, 26 Jul 2016 08:11 pm, 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? Anything that cgitb captures in a traceback can be captured at any time and processed anyway you like. There's no real magic happening in cgitb, you can read the source and program your own traceback handler that records any details you like. Or you can use the cgitb module as-is, and capture the output: py> from StringIO import StringIO py> s = StringIO() py> import cgitb py> handler = cgitb.Hook(file=s, format="text").handle py> try: ... x = 1/0 ... except Exception as e: ... handler() ... py> text = s.getvalue() py> print text Python 2.7.2: /usr/local/bin/python2.7 Tue Jul 26 23:37:06 2016 A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. [...] The above is a description of an error in a Python program. Here is the original traceback: Traceback (most recent call last): File "", line 2, in ZeroDivisionError: division by zero -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From vostrushka at gmail.com Tue Jul 26 09:52:01 2016 From: vostrushka at gmail.com (Crane Ugly) Date: Tue, 26 Jul 2016 06:52:01 -0700 (PDT) Subject: Python environment on mac Message-ID: <950a22b5-6b34-4f99-8312-94972cb372da@googlegroups.com> Mac OS X comes with its own version of python and structure to support it. So far it was good enough for me. Then I started to use modules that distributed through MacPorts and this is where I get lost. I do not quite understand how Python environment is set. Or how to set it in a way of using, say MacPorts distribution alone. For example: standard location for pip utility is /usr/local/bin/pip. MacPorts structure has it too but as a link lrwxr-xr-x 1 root admin 67 May 23 22:32 /opt/local/bin/pip-2.7 -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip Which means that the standard utility will be used. The things is that depending on a way I run pip I get different results: $ pip list|grep pep8 pep8 (1.7.0) $ sudo pip list|grep pep8 $ pep8 was installed through macports. In second case pip is using stripped environment and pointing to standard Mac OS Python repository. But in a way to install anything with pip I have to use sudo. In my profile I have variable PYTHONPATH: PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages It is pointing to macports structure. But when I use sudo (in case of using pip) it get stripped. How to setup and maintain python environment in a trustful way? So it is clear where all installed modules are? Leonid From __peter__ at web.de Tue Jul 26 10:04:56 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Jul 2016 16:04:56 +0200 Subject: Possible to capture cgitb style output in a try/except section? References: <1469527864.2996118.676987281.0EE8893F@webmail.messagingengine.com> Message-ID: 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 believe that the only way > I can get cgitb output is to let an exception propagate to the point of > terminating my script ... at which point cgitb grabs the exception and > does its magic. I see Steven has already answered while I was composing an example script. Rather than throwing it away I'll give it below: #!/usr/bin/env python3 import cgitb cgitb.enable() print("Content-type: text/html\r\n\r\n") print("") print("hello world
") for expr in [ "1 + 1", "1 / 0", # handled in the except clause "2 * 2", "1 x 2", # handled by sys.excepthook set via cgitb.enable() "3 * 3" # not reached ]: try: print(expr, "=", eval(expr)) except ZeroDivisionError: cgitb.Hook().handle() print("
") print("") From hemla21 at gmail.com Tue Jul 26 10:10:18 2016 From: hemla21 at gmail.com (Heli) Date: Tue, 26 Jul 2016 07:10:18 -0700 (PDT) Subject: reshape with xyz ordering Message-ID: Hi, 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 maintaining the xyz ordering of the data? my val looks like the following: x,y,z, val 0,0,0,val1 0,0,1,val2 0,0,2,val3 ... Thanks a lot for your help, From __peter__ at web.de Tue Jul 26 10:20:44 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Jul 2016 16:20:44 +0200 Subject: NumPy frombuffer giving nonsense values when reading C float array on Windows References: <4481593b-69fe-4314-aca8-50b783847212@googlegroups.com> Message-ID: urschrei at 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-element array > shape = (10, 2) > array_size = np.prod(shape) > mem_size = 8 * array_size > array_str = ctypes.string_at(ptr, mem_size) > # convert to NumPy array,and copy to a list > ls = np.frombuffer(array_str, dtype="float64", > count=array_size).reshape(shape).tolist() > # return pointer so it can be freed > drop_array(ptr) > return ls > > This works correctly and consistently on Linux and OSX using NumPy 1.11.0, > but fails on Windows 32 bit and 64-bit about 50% of the time, returning > nonsense values. Am I doing something wrong? Is there a better way to do > this? I'd verify that the underlying memory has not been freed by the "binary" when you are doing the ctypes/numpy processing. You might get the correct values only when you are "lucky" and the memory has not yet been reused for something else, and you are "lucky" on Linux/OSX more often than on Windows... From antoon.pardon at rece.vub.ac.be Tue Jul 26 10:31:34 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 26 Jul 2016 16:31:34 +0200 Subject: Why not allow empty code blocks? In-Reply-To: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: <57977446.4000801@rece.vub.ac.be> Op 24-07-16 om 21:00 schreef Chris Angelico: > A skilled craftsman in any field will choose to use quality tools. > They save time, and time is money.[/quote] Sure, but sometimes there is a flaw somewhere. A flaw whose consequences can be reduced by using an extra tool. If that is the case the real solution seems to get rid of the flaw and not to use the tool. So if someone argues there is a flaw somewhere, pointing to tools doesn't contradict that. -- Antoon. From __peter__ at web.de Tue Jul 26 10:59:03 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Jul 2016 16:59:03 +0200 Subject: reshape with xyz ordering References: Message-ID: 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 > maintaining the xyz ordering of the data? > > > my val looks like the following: > > x,y,z, val > 0,0,0,val1 > 0,0,1,val2 > 0,0,2,val3 > ... > > Thanks a lot for your help, I'm not sure I understand the question. Does shape = [max(t) + 1 for t in [x, y, z]] cube = myval.reshape(shape) give what you want? From urschrei at gmail.com Tue Jul 26 11:09:49 2016 From: urschrei at gmail.com (sth) Date: Tue, 26 Jul 2016 08:09:49 -0700 (PDT) Subject: NumPy frombuffer giving nonsense values when reading C float array on Windows In-Reply-To: References: <4481593b-69fe-4314-aca8-50b783847212@googlegroups.com> Message-ID: On Tuesday, 26 July 2016 15:21:14 UTC+1, Peter Otten 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-element array > > shape = (10, 2) > > array_size = np.prod(shape) > > mem_size = 8 * array_size > > array_str = ctypes.string_at(ptr, mem_size) > > # convert to NumPy array,and copy to a list > > ls = np.frombuffer(array_str, dtype="float64", > > count=array_size).reshape(shape).tolist() > > # return pointer so it can be freed > > drop_array(ptr) > > return ls > > > > This works correctly and consistently on Linux and OSX using NumPy 1.11.0, > > but fails on Windows 32 bit and 64-bit about 50% of the time, returning > > nonsense values. Am I doing something wrong? Is there a better way to do > > this? > > I'd verify that the underlying memory has not been freed by the "binary" > when you are doing the ctypes/numpy processing. You might get the correct > values only when you are "lucky" and the memory has not yet been reused for > something else, and you are "lucky" on Linux/OSX more often than on > Windows... I'm pretty sure the binary isn't freeing the memory prematurely; I wrote it and I'm testing it, and the Python tests run 10^6 loops of: array retrieval -> numpy array allocation + copying to list -> passing original array back to be freed. I'm not completely ruling it out (it's difficult to test a .dylib / .so using valgrind), but getting the ctypes / numpy side right would at least allow me to eliminate one potential source of problems. From auriocus at gmx.de Tue Jul 26 11:36:20 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 26 Jul 2016 17:36:20 +0200 Subject: NumPy frombuffer giving nonsense values when reading C float array on Windows In-Reply-To: References: <4481593b-69fe-4314-aca8-50b783847212@googlegroups.com> Message-ID: Am 26.07.16 um 17:09 schrieb sth: > it's difficult to test a .dylib / .so using valgrind Why is it difficult? If you have a python script such that python mytests.py loads the .so and runs the tests, then valgrind --tool=memcheck python mytests.py should work. This should immediately spit out an error in case that numpy accesses deleted memory. Of course debug information should be enabled when compiling the .so for more useful output, and it could be helpful to have it for numpy/python, too, but that's not a requirement. Christian From cfkaran2 at gmail.com Tue Jul 26 11:38:00 2016 From: cfkaran2 at gmail.com (CFK) Date: Tue, 26 Jul 2016 11:38:00 -0400 Subject: Python environment on mac In-Reply-To: <950a22b5-6b34-4f99-8312-94972cb372da@googlegroups.com> References: <950a22b5-6b34-4f99-8312-94972cb372da@googlegroups.com> Message-ID: There are two variables you will need to set; PATH and PYTHONPATH. You set your PYTHONPATH correctly, but for executables like pip, you need to set the PATH as well. You MUST do that for each account! The reason it didn't work as root is because once you su to root, it replaces your PYTHONPATH and PATH (and all other environment variables) with root's. sudo shouldn't have that problem. BE VERY CAREFUL CHANGING THESE VARIABLES FOR ROOT! I managed to wedge a system until I reverted my environment. Thanks, Cem Karan On Jul 26, 2016 9:58 AM, "Crane Ugly" wrote: > Mac OS X comes with its own version of python and structure to support it. > So far it was good enough for me. Then I started to use modules that > distributed through MacPorts and this is where I get lost. > I do not quite understand how Python environment is set. Or how to set it > in a way of using, say MacPorts distribution alone. > For example: standard location for pip utility is /usr/local/bin/pip. > MacPorts structure has it too but as a link > lrwxr-xr-x 1 root admin 67 May 23 22:32 /opt/local/bin/pip-2.7 -> > /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip > Which means that the standard utility will be used. > The things is that depending on a way I run pip I get different results: > $ pip list|grep pep8 > pep8 (1.7.0) > $ sudo pip list|grep pep8 > $ > pep8 was installed through macports. > In second case pip is using stripped environment and pointing to standard > Mac OS Python repository. > But in a way to install anything with pip I have to use sudo. > In my profile I have variable PYTHONPATH: > > PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages > It is pointing to macports structure. But when I use sudo (in case of > using pip) it get stripped. > How to setup and maintain python environment in a trustful way? So it is > clear where all installed modules are? > > Leonid > -- > https://mail.python.org/mailman/listinfo/python-list > From python at bdurham.com Tue Jul 26 11:52:47 2016 From: python at bdurham.com (Malcolm Greene) Date: Tue, 26 Jul 2016 11:52:47 -0400 Subject: Possible to capture cgitb style output in a try/except section? In-Reply-To: References: <1469527864.2996118.676987281.0EE8893F@webmail.messagingengine.com> Message-ID: <1469548367.1451657.677295577.18F0D7FD@webmail.messagingengine.com> Hi Steven and Peter, Steven: Interestingly (oddly???) enough, the output captured by hooking the cgitb handler on my system appears to be shorter than the default cgitb output. You can see this yourself via this tiny script: import cgitb cgitb.enable(format='text') x = 1/0 The solution I came up with (Python 3.5.1) was to use your StringIO technique with the Hook's 'file=' parameter. import io cgitb_buffer = io.StringIO() cgitb.Hook(file=cgitb_buffer, format='text) return cgitb_buffer.getvalue() Peter: Your output was helpful in seeing the difference I mentioned above. Thank you both for your help! Malcolm From python at bdurham.com Tue Jul 26 12:11:43 2016 From: python at bdurham.com (Malcolm Greene) Date: Tue, 26 Jul 2016 12:11:43 -0400 Subject: Python 3.5 glob.glob() 2nd param (*) and how to detect files/folders beginning with "."? Message-ID: <1469549503.1455120.677317601.2592D9D2@webmail.messagingengine.com> In reading Python 3.5.1's glob.glob documentation[1] I'm puzzled by the following: 1. The signature for glob.glob() is "glob.glob(pathname, *, recursive=False)". What is the meaning of the 2nd parameter listed with an asterisk? 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 non-default approach is to match these type of files? Thank you, Malcolm [1] https://docs.python.org/3/library/glob.html ? From jussi.piitulainen at helsinki.fi Tue Jul 26 12:26:55 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 26 Jul 2016 19:26:55 +0300 Subject: Python 3.5 glob.glob() 2nd param (*) and how to detect files/folders beginning with "."? References: <1469549503.1455120.677317601.2592D9D2@webmail.messagingengine.com> Message-ID: Malcolm Greene writes: > In reading Python 3.5.1's glob.glob documentation[1] I'm puzzled by the > following: > > 1. The signature for glob.glob() is "glob.glob(pathname, *, > recursive=False)". What is the meaning of the 2nd parameter listed > with an asterisk? It's not a parameter. It's special syntax to indicate that the remaining parameters are keyword-only. > 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 non-default > approach is to match these type of files? Glob with a pattern that starts with a dot. Glob twice if you want both kinds. Or look into that fnmatch that is referenced from glob documentation and said not to consider leading dots special. > [1] https://docs.python.org/3/library/glob.html . From urschrei at gmail.com Tue Jul 26 12:47:58 2016 From: urschrei at gmail.com (sth) Date: Tue, 26 Jul 2016 09:47:58 -0700 (PDT) Subject: NumPy frombuffer giving nonsense values when reading C float array on Windows In-Reply-To: References: <4481593b-69fe-4314-aca8-50b783847212@googlegroups.com> Message-ID: On Tuesday, 26 July 2016 16:36:33 UTC+1, Christian Gollwitzer wrote: > Am 26.07.16 um 17:09 schrieb sth: > > it's difficult to test a .dylib / .so using valgrind > > Why is it difficult? If you have a python script such that > > python mytests.py > > loads the .so and runs the tests, then > > valgrind --tool=memcheck python mytests.py > > should work. This should immediately spit out an error in case that > numpy accesses deleted memory. > > Of course debug information should be enabled when compiling the .so for > more useful output, and it could be helpful to have it for numpy/python, > too, but that's not a requirement. > > Christian Valgrind isn't giving me any errors; it's reporting possibly-lost memory, but this is constant -- if I call the foreign functions once or 10^6 times, the number of bytes it reports possibly lost (and the number of bytes it reports still reachable) remain the same. From __peter__ at web.de Tue Jul 26 12:48:52 2016 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Jul 2016 18:48:52 +0200 Subject: Python 3.5 glob.glob() 2nd param (*) and how to detect files/folders beginning with "."? References: <1469549503.1455120.677317601.2592D9D2@webmail.messagingengine.com> Message-ID: 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 non-default > approach is to match these type of files? I don't think there is a clean way. You can monkey-patch if you don't need the default behaviour elsewhere in your application: $ touch foo .bar baz $ python3 Python 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import glob >>> glob.glob("*") ['foo', 'baz'] >>> glob._ishidden = lambda path: False >>> glob.glob("*") ['.bar', 'foo', 'baz'] From python at bdurham.com Tue Jul 26 12:52:30 2016 From: python at bdurham.com (Malcolm Greene) Date: Tue, 26 Jul 2016 12:52:30 -0400 Subject: Python 3.5 glob.glob() 2nd param (*) and how to detect files/folders beginning with "."? In-Reply-To: References: <1469549503.1455120.677317601.2592D9D2@webmail.messagingengine.com> Message-ID: <1469551950.1463886.677372913.554C7F17@webmail.messagingengine.com> Hi Jussi, You answered my questions - thank you! Malcolm > 1. The signature for glob.glob() is "glob.glob(pathname, *, > recursive=False)". What is the meaning of the 2nd parameter listed > with an asterisk? It's not a parameter. It's special syntax to indicate that the remaining parameters are keyword-only. > 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 non-default > approach is to match these type of files? Glob with a pattern that starts with a dot. Glob twice if you want both kinds. Or look into that fnmatch that is referenced from glob documentation and said not to consider leading dots special. From crtbraille at gmail.com Tue Jul 26 13:22:16 2016 From: crtbraille at gmail.com (Carter Temm) Date: Tue, 26 Jul 2016 12:22:16 -0500 Subject: making executables smaller Message-ID: Hi, I?m writing a couple different projects at the moment, and when I compile it into a single executable using pyinstaller, it becomes extremely large. I?m guessing this is because of the modules used. Because I?m not that skilled at python, I put stuff like for example, import sys. I imagine the final project could be made smaller by specifying from something import something_else. but the thing is, I don?t know what smaller I could import with these set of modules. Is there a program that could tell me this. Sorry if this question is really basic, but it?d be helpful. From nakirekantijahnavi at gmail.com Tue Jul 26 13:51:26 2016 From: nakirekantijahnavi at gmail.com (Nakirekanti Jahnavi) Date: Tue, 26 Jul 2016 23:21:26 +0530 Subject: FW: error in python IDLE In-Reply-To: <57961e75.4508620a.6e4b5.0e91@mx.google.com> References: <57961e75.4508620a.6e4b5.0e91@mx.google.com> Message-ID: <5797a331.4500420a.e898f.59ee@mx.google.com> Sent from Mail for Windows 10 From: Nakirekanti Jahnavi From eryksun at gmail.com Tue Jul 26 14:09:47 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 26 Jul 2016 18:09:47 +0000 Subject: NumPy frombuffer giving nonsense values when reading C float array on Windows In-Reply-To: <4481593b-69fe-4314-aca8-50b783847212@googlegroups.com> References: <4481593b-69fe-4314-aca8-50b783847212@googlegroups.com> Message-ID: On Tue, Jul 26, 2016 at 12:06 PM, 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: If this comes from a function result, are you certain that its restype is ctypes.c_void_p? I commonly see typos here such as setting "restypes" instead of "restype". > [[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-element array > shape = (10, 2) > array_size = np.prod(shape) > mem_size = 8 * array_size > array_str = ctypes.string_at(ptr, mem_size) > # convert to NumPy array,and copy to a list > ls = np.frombuffer(array_str, dtype="float64", count=array_size).reshape(shape).tolist() > # return pointer so it can be freed > drop_array(ptr) > return ls > > This works correctly and consistently on Linux and OSX using NumPy 1.11.0, but fails on > Windows 32 bit and 64-bit about 50% of the time, returning nonsense values. Am I doing > something wrong? Is there a better way to do this? numpy.ctypeslib facilitates working with ctypes functions, pointers and arrays via the factory functions as_array, as_ctypes, and ndpointer. ndpointer creates a c_void_p subclass that overrides the default from_param method to allow passing arrays as arguments to ctypes functions and also implements the _check_retval_ hook to automatically convert a pointer result to a numpy array. The from_param method validates an array argument to ensure it has the proper data type, shape, and memory layout. For example: g = ctypes.CDLL(None) # Unix only Base = np.ctypeslib.ndpointer(dtype='B', shape=(4,)) # strchr example g.strchr.argtypes = (Base, ctypes.c_char) g.strchr.restype = ctypes.c_char_p d = np.array(list(b'012\0'), dtype='B') e = np.array(list(b'0123\0'), dtype='B') # wrong shape >>> g.strchr(d, b'0'[0]) b'012' >>> g.strchr(e, b'0'[0]) Traceback (most recent call last): File "", line 1, in ctypes.ArgumentError: argument 1: : array must have shape (4,) The _check_retval_ hook of an ndpointer calls numpy.array on the result of a function. Its __array_interface__ property is used to create a copy with the defined data type and shape. For example: g.strchr.restype = Base >>> d.ctypes._as_parameter_ # source address c_void_p(24657952) >>> a = g.strchr(d, b'0'[0]) >>> a array([48, 49, 50, 0], dtype=uint8) >>> a.ctypes._as_parameter_ # it's a copy c_void_p(19303504) As a copy, the array owns its data: >>> a.flags C_CONTIGUOUS : True F_CONTIGUOUS : True OWNDATA : True WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False You can subclass the ndpointer type to have _check_retval_ instead return a view of the result (i.e. copy=False), which may be desirable for a large result array but probably isn't worth it for small arrays. For example: class Result(Base): @classmethod def _check_retval_(cls, result): return np.array(result, copy=False) g.strchr.restype = Result >>> a = g.strchr(d, b'0'[0]) >>> a.ctypes._as_parameter_ # it's NOT a copy c_void_p(24657952) Because it's not a copy, the array view doesn't own the data, but note that it's not a read-only view: >>> a.flags C_CONTIGUOUS : True F_CONTIGUOUS : True OWNDATA : False WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False From urschrei at gmail.com Tue Jul 26 14:31:23 2016 From: urschrei at gmail.com (sth) Date: Tue, 26 Jul 2016 11:31:23 -0700 (PDT) Subject: NumPy frombuffer giving nonsense values when reading C float array on Windows In-Reply-To: References: <4481593b-69fe-4314-aca8-50b783847212@googlegroups.com> Message-ID: On Tuesday, 26 July 2016 19:10:46 UTC+1, eryk sun wrote: > On Tue, Jul 26, 2016 at 12:06 PM, sth 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: > > If this comes from a function result, are you certain that its restype > is ctypes.c_void_p? I commonly see typos here such as setting > "restypes" instead of "restype". > > > [[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-element array > > shape = (10, 2) > > array_size = np.prod(shape) > > mem_size = 8 * array_size > > array_str = ctypes.string_at(ptr, mem_size) > > # convert to NumPy array,and copy to a list > > ls = np.frombuffer(array_str, dtype="float64", count=array_size).reshape(shape).tolist() > > # return pointer so it can be freed > > drop_array(ptr) > > return ls > > > > This works correctly and consistently on Linux and OSX using NumPy 1.11.0, but fails on > > Windows 32 bit and 64-bit about 50% of the time, returning nonsense values. Am I doing > > something wrong? Is there a better way to do this? > > numpy.ctypeslib facilitates working with ctypes functions, pointers > and arrays via the factory functions as_array, as_ctypes, and > ndpointer. > > ndpointer creates a c_void_p subclass that overrides the default > from_param method to allow passing arrays as arguments to ctypes > functions and also implements the _check_retval_ hook to automatically > convert a pointer result to a numpy array. > > The from_param method validates an array argument to ensure it has the > proper data type, shape, and memory layout. For example: > > g = ctypes.CDLL(None) # Unix only > Base = np.ctypeslib.ndpointer(dtype='B', shape=(4,)) > > # strchr example > g.strchr.argtypes = (Base, ctypes.c_char) > g.strchr.restype = ctypes.c_char_p > > d = np.array(list(b'012\0'), dtype='B') > e = np.array(list(b'0123\0'), dtype='B') # wrong shape > > >>> g.strchr(d, b'0'[0]) > b'012' > >>> g.strchr(e, b'0'[0]) > Traceback (most recent call last): > File "", line 1, in > ctypes.ArgumentError: argument 1: : > array must have shape (4,) > > The _check_retval_ hook of an ndpointer calls numpy.array on the > result of a function. Its __array_interface__ property is used to > create a copy with the defined data type and shape. For example: > > g.strchr.restype = Base > > >>> d.ctypes._as_parameter_ # source address > c_void_p(24657952) > >>> a = g.strchr(d, b'0'[0]) > >>> a > array([48, 49, 50, 0], dtype=uint8) > >>> a.ctypes._as_parameter_ # it's a copy > c_void_p(19303504) > > As a copy, the array owns its data: > > >>> a.flags > C_CONTIGUOUS : True > F_CONTIGUOUS : True > OWNDATA : True > WRITEABLE : True > ALIGNED : True > UPDATEIFCOPY : False > > You can subclass the ndpointer type to have _check_retval_ instead > return a view of the result (i.e. copy=False), which may be desirable > for a large result array but probably isn't worth it for small arrays. > For example: > > class Result(Base): > @classmethod > def _check_retval_(cls, result): > return np.array(result, copy=False) > > g.strchr.restype = Result > > >>> a = g.strchr(d, b'0'[0]) > >>> a.ctypes._as_parameter_ # it's NOT a copy > c_void_p(24657952) > > Because it's not a copy, the array view doesn't own the data, but note > that it's not a read-only view: > > >>> a.flags > C_CONTIGUOUS : True > F_CONTIGUOUS : True > OWNDATA : False > WRITEABLE : True > ALIGNED : True > UPDATEIFCOPY : False The restype is a ctypes Structure instance with a single __fields__ entry (coords), which is a Structure with two fields (len and data) which are the FFI array's length and the void pointer to its memory: https://github.com/urschrei/pypolyline/blob/master/pypolyline/util.py#L109-L117 I'm only half-following your explanation of how ctypeslib works, but it seems clear that I'm doing something wrong. From best_lay at yahoo.com Tue Jul 26 14:47:27 2016 From: best_lay at yahoo.com (Wildman) Date: Tue, 26 Jul 2016 13:47:27 -0500 Subject: making executables smaller References: Message-ID: On Tue, 26 Jul 2016 12:22:16 -0500, Carter Temm wrote: > Hi, > I?m writing a couple different projects at the moment, and when I > compile it into a single executable using pyinstaller, it becomes > extremely large. I?m guessing this is because of the modules used. > Because I?m not that skilled at python, I put stuff like for example, > import sys. I imagine the final project could be made smaller by > specifying from something import something_else. but the thing is, > I don?t know what smaller I could import with these set of modules. > Is there a program that could tell me this. Sorry if this question > is really basic, but it?d be helpful. Try importing only the modules you actually use. For example, instead of: import os Try using: import os.path import os.environ import os.whatever -- GNU/Linux user #557453 The cow died so I don't need your bull! From tjreedy at udel.edu Tue Jul 26 16:12:07 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 26 Jul 2016 16:12:07 -0400 Subject: FW: error in python IDLE In-Reply-To: <5797a331.4500420a.e898f.59ee@mx.google.com> References: <57961e75.4508620a.6e4b5.0e91@mx.google.com> <5797a331.4500420a.e898f.59ee@mx.google.com> Message-ID: On 7/26/2016 1:51 PM, Nakirekanti Jahnavi wrote: > Sent from Mail for Windows 10 > > From: Nakirekanti Jahnavi The above is all I see. This is a text-only, no-attachment list. -- Terry Jan Reedy From phil at riverbankcomputing.com Tue Jul 26 17:16:47 2016 From: phil at riverbankcomputing.com (Phil Thompson) Date: Tue, 26 Jul 2016 22:16:47 +0100 Subject: ANN: PyQt v5.7 Released Message-ID: <946A2078-E61B-45E7-9185-2BDA8F2DDA7D@riverbankcomputing.com> PyQt v5.7 has been released. These are the Python bindings for the Qt application toolkit and runs on Linux, OS X, Windows, iOS and Android. Also released for the first time under the GPL are PyQtChart, PyQtDataVisualization and PyQtPurchasing. PyQtChart are the bindings for the Qt Charts library. This implements a set of classes for creating and manipulating 2D charts. PyQtDataVisualization are the bindings for the Qt Data Visualization library. This implements a set of classes for representing data in 3D and allowing the user to interact with the view. PyQtPurchasing are the bindings for the Qt Purchasing library. This implements a set of classes that allow applications to support in-app purchases from the Mac App Store on OS X, the App Store on iOS, and Google Play on Android. Wheels are available from PyPI and include the relevent Qt libraries - nothing else needs to be installed. Source packages and more information can be found at https://www.riverbankcomputing.com/. Phil Thompson From mike at mikesperone.com Tue Jul 26 17:26:01 2016 From: mike at mikesperone.com (Michael Sperone) Date: Tue, 26 Jul 2016 17:26:01 -0400 Subject: Is there a documented pylibpd (pure data wrapper/library) API? In-Reply-To: References: Message-ID: Hi everyone, I'm starting using the libpd wrapper/library for python (pylibpd), to load and use my pure data patches within Python. I was wondering if there was any online documentation for this python version? At the least I'm looking for a list of classes and methods. Thank you! Mike From eryksun at gmail.com Tue Jul 26 18:42:41 2016 From: eryksun at gmail.com (eryk sun) Date: Tue, 26 Jul 2016 22:42:41 +0000 Subject: NumPy frombuffer giving nonsense values when reading C float array on Windows In-Reply-To: References: <4481593b-69fe-4314-aca8-50b783847212@googlegroups.com> Message-ID: On Tue, Jul 26, 2016 at 6:31 PM, sth wrote: > > The restype is a ctypes Structure instance with a single __fields__ entry (coords), which Watch the underscores with ctypes attributes. Your code spells it correctly as "_fields_". > is a Structure with two fields (len and data) which are the FFI array's length and the void > pointer to its memory: > https://github.com/urschrei/pypolyline/blob/master/pypolyline/util.py#L109-L117 _FFIArray.__init__ isn't properly keeping a reference to the wrapped numpy array: def __init__(self, seq, data_type = c_double): ptr = POINTER(data_type) nparr = np.array(seq, dtype=np.float64) arr = nparr.ctypes.data_as(ptr) self.data = cast(arr, c_void_p) self.len = len(seq) arr doesn't have a reference to nparr, so self.data doesn't have a reference to the numpy array when it goes out of scope. For example, we can trigger a segfault here: >>> nparr = np.array(range(2**24), dtype=np.float64) >>> ptr = ctypes.POINTER(ctypes.c_double) >>> arr = nparr.ctypes.data_as(ptr) >>> arr[0], arr[2**24-1] (0.0, 16777215.0) >>> del nparr >>> arr[0], arr[2**24-1] Segmentation fault (core dumped) > I'm only half-following your explanation of how ctypeslib works, but it seems clear that I'm doing > something wrong. The library requires the data pointers wrapped in a struct with the length, so I think what you're doing to wrap and unwrap arbitrary sequences is generally fine. But you don't need the bytes copy from string_at. You can cast to a double pointer and create a numpy array from that, all without copying any data. The only copy made is for tolist(). For example: def _void_array_to_nested_list(res, func, args): """ Dereference the FFI result to a list of coordinates """ try: shape = res.coords.len, 2 ptr = cast(res.coords.data, POINTER(c_double)) array = np.ctypeslib.as_array(ptr, shape) return array.tolist() finally: drop_array(res.coords) If you're not hard coding the double data type, consider adding a simple C type string to the _FFIArray struct. For example: >>> ctypes.c_double._type_ 'd' You just need a dict to map type strings to simple C types. From nobody at nowhere.invalid Tue Jul 26 18:55:09 2016 From: nobody at nowhere.invalid (Nobody) Date: Tue, 26 Jul 2016 23:55:09 +0100 Subject: reshape with xyz ordering References: Message-ID: On Tue, 26 Jul 2016 07:10:18 -0700, 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 > maintaining the xyz ordering of the data? Is it guaranteed that the data actually *is* a 3-D array that's been converted to a list of x,y,z,val tuples? In other words, does every possible combination of x,y,z for 0<=x<=max(x), 0<=y<=max(y), 0<=z<=max(z) occur exactly once? If so, then see Peter's answer. If not, then how do you wish to handle a) (x,y,z) tuples which never occur (missing values), and b) (x,y,z) tuples which occur more than once? If the data "should" to be a 3-D array but you first wish to ensure that it actually is, you can use e.g. nx,ny,nz = max(x)+1,max(y)+1,max(z)+1 if val.shape != (nx*ny*nz,): raise ValueError i = (x*ny+y)*nz+z found = np.zeros(val.shape, dtype=bool) found[i] = True if not np.all(found): raise ValueError ind = np.lexsort((val,z,y,x)) myval = val[ind].reshape((nx,ny,nz)) From ethan at stoneleaf.us Tue Jul 26 19:48:12 2016 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 26 Jul 2016 16:48:12 -0700 Subject: Depending on enum34 from a library In-Reply-To: References: Message-ID: <5797F6BC.6060406@stoneleaf.us> On 07/24/2016 01:10 PM, Vasiliy Faronov wrote: > I'm building a Python library where I want to use Python 3.4-style > enums. Because I need to support Python 2.7, I'm considering using > enum34 [1]. But I'm not sure how to do this: > > If I simply depend on enum34, it will install a module named `enum` > even in Python 3.4+ environments, and that could shadow the stdlib > module. Personally I would be very surprised if installing a library > caused an unrelated stdlib module to be replaced with a third-party > one, even if it's "just" a backport. However, in my environments, > `sys.path` is such that stdlib comes before site-packages -- perhaps > this is normal enough that I can rely on it? > > Or I could change my setup.py to include enum34 in `install_requires` > only if running on Python 2.7. But that will make my distribution's > metadata dynamic, which doesn't sound like a good idea [2]. At the > very least, I think it will prevent me from building a universal > wheel. enum34 is kept up-to-date, as far as I am able, with the current version of enum in the stdlib. As a happy side-effect if it is found before the stdlib version Python will still run -- at least for Python 3.4 and 3.5; 3.6 is adding some new features that I am not planning on adding to enum34. For my own code I use the 'install_requires' option, plus some code that checks the Python version to see if enum34 is needed. Your other option is to use aenum [1], my other package, instead; it does not risk conflict with enum, but has the same basic behavior (plus lots of advanced behavior you can opt in to). -- ~Ethan~ [1] https://pypi.python.org/pypi/aenum From crtbraille at gmail.com Tue Jul 26 20:45:27 2016 From: crtbraille at gmail.com (Carter Temm) Date: Tue, 26 Jul 2016 19:45:27 -0500 Subject: making executables smaller In-Reply-To: References: Message-ID: <8EF019E7-E120-40CD-81F6-7DD503E26E46@gmail.com> OK. So I guess the question should be, how can I make these executables smaller in general? Sent from my iPhone > On Jul 26, 2016, at 5:13 PM, Dennis Lee Bieber wrote: > > On Tue, 26 Jul 2016 12:22:16 -0500, Carter Temm > declaimed the following: > >> Hi, >> I?m writing a couple different projects at the moment, and when I compile it into a single executable using pyinstaller, it becomes extremely large. I?m guessing this is because of the modules used. Because I?m not that skilled at python, I put stuff like for example, import sys. I imagine the final project could be made smaller > by specifying from something import something_else. but the thing is, I don?t know what smaller I could import with these set of modules. Is there a program that could tell me this. Sorry if this question is really basic, but it?d be helpful. > > "from module import name" still has to include the entire module -- > since that is the file. It is effectively the same as doing > > import module > name = module.name > del module > > Also -- anything that creates an executable file for Python will be > including the Python interpreter ITSELF. That may be a lot of the bloat you > see. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list From nextstate at gmail.com Tue Jul 26 20:49:37 2016 From: nextstate at gmail.com (Tom Brown) Date: Tue, 26 Jul 2016 17:49:37 -0700 Subject: pyinstaller In-Reply-To: References: Message-ID: I used pyinstaller quite a bit 3 years ago. I could brush off the cobwebs and see if I can help if you have not solved it already. What is the issue you are having? -Tom On Jun 21, 2016 16:57, "Larry Martell" wrote: > Anyone here have any experience with pyinstaller? I am trying to use > it, but I'm not having much success. I tried posting to the > pyinstaller ML but it said my post had to be approved first, and that > hasn't happened in a while. I'll post details if someone here thinks > they can help. > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at zip.com.au Tue Jul 26 20:58:28 2016 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 27 Jul 2016 10:58:28 +1000 Subject: Python environment on mac In-Reply-To: <950a22b5-6b34-4f99-8312-94972cb372da@googlegroups.com> References: <950a22b5-6b34-4f99-8312-94972cb372da@googlegroups.com> Message-ID: <20160727005828.GA99643@cskk.homeip.net> On 26Jul2016 06:52, Crane Ugly wrote: >Mac OS X comes with its own version of python and structure to support it. >So far it was good enough for me. Then I started to use modules that distributed through MacPorts and this is where I get lost. >I do not quite understand how Python environment is set. Or how to set it in a way of using, say MacPorts distribution alone. >For example: standard location for pip utility is /usr/local/bin/pip. MacPorts structure has it too but as a link >lrwxr-xr-x 1 root admin 67 May 23 22:32 /opt/local/bin/pip-2.7 -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip >Which means that the standard utility will be used. No, I think that means it uses the MacPorts one. Note: /opt/local vs /usr/local. >The things is that depending on a way I run pip I get different results: >$ pip list|grep pep8 >pep8 (1.7.0) >$ sudo pip list|grep pep8 >$ >pep8 was installed through macports. >In second case pip is using stripped environment and pointing to standard Mac OS Python repository. >But in a way to install anything with pip I have to use sudo. >In my profile I have variable PYTHONPATH: >PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages >It is pointing to macports structure. But when I use sudo (in case of using pip) it get stripped. >How to setup and maintain python environment in a trustful way? So it is clear >where all installed modules are? My personal habit is to use virtualenv. You could build a virtualenv based of the system Python or the MacPorts one (or make one of each). Then you can use pip (as yourself, no sudo - avoid that if possible) from the appropriate environment to install into that environment. Complete separation, and complete control for you. The executables inside a virtualenv ("python", "pip" etc) are stubs that adjust PYTHONPATH etc themselves and then invoke the python one which that particular virtualenv was based. This means that by executing that _specific_ executable you automatically and correctly use that specific virtualenv. Without having to hand maintain your own $PYTHONPATH, and therefore with needing to adjust it depending which setup you want to use. Cheers, Cameron Simpson From larry.martell at gmail.com Tue Jul 26 21:15:14 2016 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 26 Jul 2016 21:15:14 -0400 Subject: pyinstaller In-Reply-To: References: Message-ID: On Tue, Jul 26, 2016 at 8:49 PM, Tom Brown wrote: > I used pyinstaller quite a bit 3 years ago. I could brush off the cobwebs > and see if I can help if you have not solved it already. > > What is the issue you are having? If I import the requests module, then when I run the executable I get: ImportError: No module named 'requests.packages.chardet' I tried to post to the pyinstaller group, but it said my post had to be approved by the moderator, and it apparently never was. I have no idea who the moderator is, so there was no one I could contact about that. I posted an issue to github (https://github.com/pyinstaller/pyinstaller/issues/2060) and some suggestions were made, but none fixed the problem. I am on RHEL 7.2 with Python 2.7.5, and it's reproducible, just by having a 1 line script that has "import requests". Thanks for any help you could provide. > > On Jun 21, 2016 16:57, "Larry Martell" wrote: >> >> Anyone here have any experience with pyinstaller? I am trying to use >> it, but I'm not having much success. I tried posting to the >> pyinstaller ML but it said my post had to be approved first, and that >> hasn't happened in a while. I'll post details if someone here thinks >> they can help. >> -- >> https://mail.python.org/mailman/listinfo/python-list From steve at pearwood.info Tue Jul 26 22:00:41 2016 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 27 Jul 2016 12:00:41 +1000 Subject: making executables smaller References: Message-ID: <579815ca$0$1617$c3e8da3$5496439d@news.astraweb.com> On Wed, 27 Jul 2016 03:22 am, Carter Temm wrote: > Hi, > I?m writing a couple different projects at the moment, and when I compile > it into a single executable using pyinstaller, it becomes extremely large. What do you consider "extremely large"? Ten gigabytes? 500 kilobytes? Give us a clue. > I?m guessing this is because of the modules used. Maybe yes, maybe no. On my system, Python 3.3 is a little bit less than 6 MB, and the std lib under 130MB: [steve at ando ~]$ du -hs /usr/local/bin/python3.3 5.7M /usr/local/bin/python3.3 [steve at ando ~]$ du -hs /usr/local/lib/python3.3/ 129M /usr/local/lib/python3.3/ But nearly 50MB of that is the test suite: [steve at ando test]$ du -hs /usr/local/lib/python3.3/test/ 48M /usr/local/lib/python3.3/test/ I expect that on Windows or Mac OS X the sizes will be roughly the same. I'm not an expert on the pyinstaller internals, but I would expect that it would be able to drop the test suite, but will need to include the rest of the std lib as well as the interpreter, plus whatever files you have written. So I expect that a frozen executable will be of the order of 80MB, give or take. There's probably a bit of overhead needed to hold it all together, so let's say 100MB in round figures. If you're getting less than 100MB, that doesn't sound too bad to me, not for an interpreted language like Python. Anything less than that sounds really good to me. If you are getting under 20MB, that's *fantastic*. What's the problem with that? You can fit close to forty of these on a 4GB DVD-RW or USB stick. You're not hoping to fit your application on a floppy disk are you? Its 2016, not 1980. If you're working with really constrained environments, like an embedded device, then check out ?Py or PyMite: https://micropython.org/ http://deanandara.com/PyMite/ although I fear PyMite may not be under active development. > Because I?m not that > skilled at python, I put stuff like for example, import sys. I imagine the > final project could be made smaller by specifying from something import > something_else. No, it doesn't work like that. For starters, sys is built into the interpreter, so it's unlikely you'll be able to remove it. But more generally, if you use anything from a module, the entire module must be included. Even if *you* don't use a module, perhaps one of the modules you do use will in turn use that module. Of course, you can avoid all this overhead completely by *not* freezing the executable down to a single file. Just distribute your Python code as a .py file, or a .pyc file. There are other options as well, such as distributing it bundled into a zip file. What benefit do you get from using PyInstaller? > but the thing is, I don?t know what smaller I could import > with these set of modules. Is there a program that could tell me this. > Sorry if this question is really basic, but it?d be helpful. -- Steven ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From gengyangcai at gmail.com Tue Jul 26 23:45:40 2016 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 26 Jul 2016 20:45:40 -0700 (PDT) Subject: Python Print Error Message-ID: How to debug this error message ? print('You will be ' + str(int(myAge) + 1) + ' in a year.') Traceback (most recent call last): File "", line 1, in print('You will be ' + str(int(myAge) + 1) + ' in a year.') ValueError: invalid literal for int() with base 10: '' From PointedEars at web.de Wed Jul 27 00:52:58 2016 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 27 Jul 2016 06:52:58 +0200 Subject: making executables smaller References: Message-ID: <1753372.oMNUckLgyt@PointedEars.de> Carter Temm wrote: > I?m writing a couple different projects at the moment, and when I compile > it into a single executable using pyinstaller, it becomes extremely large. > I?m guessing this is because of the modules used. Because I?m not that > skilled at python, I put stuff like for example, import sys. I imagine the > final project could be made smaller by specifying from something import > something_else. but the thing is, I don?t know what smaller I could import > with these set of modules. Is there a program that could tell me this. I recommend to comment out all ?import? statements (for later reference) and then use a Python editor like PyDev to generate step by step ?from ? import ?? statements for all used symbols that are not yet defined. If it is a rather simple program where you can easily make no-ops out of modifying statements by defining mockups, you can just run it before you compile it to see where you get errors with commented-out ?import? statements. In theory, you could look for code of the form ?foo.bar? using the regular expression "(?:"")?(?:[^"\\]|\\"(?:"")?)+"(?:"")?|'(?:'')?(?:[^'\\]| \\'(?:'')?)+'(?:'')?)|((?:\w+\.)+)(\w+)?. If $1 (e.g., ?foo?) is not defined in the file, then it is likely that $2 (e.g., ?bar?) is a symbol from module $1 and you could write #----------------- from $1 import $2 ? $2 #----------------- instead of #----------------- import $1 ? $1.$2 #----------------- But there can be false positives and duplicate symbols this way. _________ ? the first two alternatives exclude Python string literals -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From jussi.piitulainen at helsinki.fi Wed Jul 27 01:54:37 2016 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 27 Jul 2016 08:54:37 +0300 Subject: Python Print Error References: Message-ID: Cai Gengyang writes: > How to debug this error message ? > > print('You will be ' + str(int(myAge) + 1) + ' in a year.') > Traceback (most recent call last): > File "", line 1, in > print('You will be ' + str(int(myAge) + 1) + ' in a year.') > ValueError: invalid literal for int() with base 10: '' The last line is the error message: ValueError: invalid literal for int() with base 10: '' It's first component, ValueError, names a class of errors. It gives you an idea (once you get used to error messages) of what might be wrong. The second component describes this particular error: invalid literal for int() with base 10 This refers to the argument to int(), and says it's an invalid "literal", which is a bit obscure term that refers to a piece in programming language syntax; it also informs you that the argument is invalid in base 10, but this turns out to be irrelevant. You should suspect that myAge is not a string of digits that form a written representation of an integer (in base 10). The third component shows you the invalid literal: '' So the error message is telling you that you tried to call int(''), and '' was an invalid thing to pass to int(). (Aside: Do not take "int()" literally. It's not the name of the function, nor is it the actual call that went wrong. It's just a shorthand indication that something went wrong in calling int, and the argument is shown as a separate component of the message.) Next you launch the interpreter and try it out: >>> int('') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '' You can be pretty confident that the error is, indeed, just this. - Try also int('ace') and int('ace', 16). That's where "base 10" is relevant. The lines before the last are the traceback. They attempt to give you an indication of where in the program the offending piece of code occurs, but they need to do it dynamically by showing what called what. Scan backwards and only pay attention to lines that you recognize (because you are not studying an obscure bug in Python itself but a trivial incident in your own program). Often it happens that the real error in your program is somewhere else, and the exception is only a symptom. In this case, you need to find where myAge gets that value, or fails to get the value that is should have. From frank at chagford.com Wed Jul 27 01:59:59 2016 From: frank at chagford.com (Frank Millman) Date: Wed, 27 Jul 2016 07:59:59 +0200 Subject: Python Print Error In-Reply-To: References: Message-ID: "Cai Gengyang" wrote in message news:c704cb09-ce62-4d83-ba72-c025835801cf at googlegroups.com... > How to debug this error message ? > print('You will be ' + str(int(myAge) + 1) + ' in a year.') > Traceback (most recent call last): > File "", line 1, in > print('You will be ' + str(int(myAge) + 1) + ' in a year.') > ValueError: invalid literal for int() with base 10: '' Very easily :-) The traceback is telling you everything you need to know. You are supplying an invalid literal for int(). There is only one place where you call int() - int(myAge) - so myAge must be an invalid literal. You could print it out and see what it is, but the traceback is already giving you that information for free. Can you see the '' at the end of the message. That is the contents of the invalid literal. HTH Frank Millman From auriocus at gmx.de Wed Jul 27 02:23:49 2016 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 27 Jul 2016 08:23:49 +0200 Subject: pyinstaller In-Reply-To: References: Message-ID: Am 27.07.16 um 03:15 schrieb Larry Martell: > On Tue, Jul 26, 2016 at 8:49 PM, Tom Brown wrote: >> I used pyinstaller quite a bit 3 years ago. I could brush off the cobwebs >> and see if I can help if you have not solved it already. >> >> What is the issue you are having? > > If I import the requests module, then when I run the executable I get: > > ImportError: No module named 'requests.packages.chardet' That's a classic issue. pyinstaller does static analysis of the program, which modules must be included. If the code computes a module dynamically, it can not always succeed. The solution is to tell pyinstaller to add this module. In previous versions, you could add these by "pyinstaller --hidden-import=requests.packages.chardet" or similar. If this doesn't work, you need to edit the spec file. See here: https://pythonhosted.org/PyInstaller/when-things-go-wrong.html#listing-hidden-imports Chrstian From steve+comp.lang.python at pearwood.info Wed Jul 27 04:11:23 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 27 Jul 2016 18:11:23 +1000 Subject: Python Print Error References: Message-ID: <57986cad$0$1521$c3e8da3$5496439d@news.astraweb.com> On Wednesday 27 July 2016 13:45, Cai Gengyang wrote: > How to debug this error message ? Start by reading the message: invalid literal for int() with base 10: '' Now try to experiment at the interactive interpreter: int('45') # works int('xyz') # ValueError: invalid literal for int() with base 10: 'xyz' int('QWE') # ValueError: invalid literal for int() with base 10: 'QWE' int('!@#') # ValueError: invalid literal for int() with base 10: '!@#' What do you think int('') will do? Try it and see. Were you right? > print('You will be ' + str(int(myAge) + 1) + ' in a year.') > Traceback (most recent call last): > File "", line 1, in > print('You will be ' + str(int(myAge) + 1) + ' in a year.') > ValueError: invalid literal for int() with base 10: '' What value do you think myAge has? Hint: you call int(myAge). That raises ValueError, and says that '' is an invalid literal for int. What value do you think myAge must have? Where does myAge get its value from? -- Steve From steve+comp.lang.python at pearwood.info Wed Jul 27 04:20:25 2016 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 27 Jul 2016 18:20:25 +1000 Subject: making executables smaller References: <1753372.oMNUckLgyt@PointedEars.de> Message-ID: <57986ecb$0$1503$c3e8da3$5496439d@news.astraweb.com> On Wednesday 27 July 2016 14:52, Thomas 'PointedEars' Lahn wrote: > Carter Temm wrote: > >> I?m writing a couple different projects at the moment, and when I compile >> it into a single executable using pyinstaller, it becomes extremely large. >> I?m guessing this is because of the modules used. Because I?m not that >> skilled at python, I put stuff like for example, import sys. I imagine the >> final project could be made smaller by specifying from something import >> something_else. but the thing is, I don?t know what smaller I could import >> with these set of modules. Is there a program that could tell me this. > > I recommend to comment out all ?import? statements (for later reference) and > then use a Python editor like PyDev to generate step by step ?from ? import > ?? statements for all used symbols that are not yet defined. What benefit do you think you will gain from changing (let's say): import collections x = collections.deque(foo) to: from collections import deque x = deque(foo) as far as executable size goes? Do you think that by using from...import... the module, and all of its dependencies, won't need to be included? Or are you just trying to save a handful of bytes ("collections.deque" in UTF-8 is 17 bytes, compared to "deque" is just 5 bytes)? Since the OP is talking about saving space, how much space do you expect to be able to save using this technique? -- Steve From moagstar at gmail.com Wed Jul 27 06:21:21 2016 From: moagstar at gmail.com (Daniel Bradburn) Date: Wed, 27 Jul 2016 12:21:21 +0200 Subject: making executables smaller In-Reply-To: <57986ecb$0$1503$c3e8da3$5496439d@news.astraweb.com> References: <1753372.oMNUckLgyt@PointedEars.de> <57986ecb$0$1503$c3e8da3$5496439d@news.astraweb.com> Message-ID: A couple of things you can try: * Generate a directory rather than onefile, on the directory you can apply du -hs * | sort -h -r (or treesize if you are using windows https://www.jam-software.com/treesize_free) to see which folders / files are taking up a lot of space. Then once you see what is taking up a lot of space you can try and figure out why it is being included, maybe you have a load of unused imports? With pyinstaller you can explicitly exclude modules you know you won't need with --exclude-module once you've optimised the directory build you can of course switch back to onefile * If all else fails you can use upx to compress your binary files (dlls + exe) which can help reduce the overall size: https://pythonhosted.org/PyInstaller/usage.html#using-upx Hope this helps. 2016-07-27 10:20 GMT+02:00 Steven D'Aprano < steve+comp.lang.python at pearwood.info>: > On Wednesday 27 July 2016 14:52, Thomas 'PointedEars' Lahn wrote: > > > Carter Temm wrote: > > > >> I?m writing a couple different projects at the moment, and when I > compile > >> it into a single executable using pyinstaller, it becomes extremely > large. > >> I?m guessing this is because of the modules used. Because I?m not that > >> skilled at python, I put stuff like for example, import sys. I imagine > the > >> final project could be made smaller by specifying from something import > >> something_else. but the thing is, I don?t know what smaller I could > import > >> with these set of modules. Is there a program that could tell me this. > > > > I recommend to comment out all ?import? statements (for later reference) > and > > then use a Python editor like PyDev to generate step by step ?from ? > import > > ?? statements for all used symbols that are not yet defined. > > What benefit do you think you will gain from changing (let's say): > > import collections > x = collections.deque(foo) > > to: > > from collections import deque > x = deque(foo) > > > as far as executable size goes? Do you think that by using > from...import... the > module, and all of its dependencies, won't need to be included? > > Or are you just trying to save a handful of bytes ("collections.deque" in > UTF-8 > is 17 bytes, compared to "deque" is just 5 bytes)? > > > Since the OP is talking about saving space, how much space do you expect > to be > able to save using this technique? > > > -- > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list > From larry.martell at gmail.com Wed Jul 27 07:25:35 2016 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 27 Jul 2016 07:25:35 -0400 Subject: pyinstaller In-Reply-To: References: Message-ID: On Wed, Jul 27, 2016 at 2:23 AM, Christian Gollwitzer wrote: > Am 27.07.16 um 03:15 schrieb Larry Martell: >> >> On Tue, Jul 26, 2016 at 8:49 PM, Tom Brown wrote: >>> >>> I used pyinstaller quite a bit 3 years ago. I could brush off the cobwebs >>> and see if I can help if you have not solved it already. >>> >>> What is the issue you are having? >> >> >> If I import the requests module, then when I run the executable I get: >> >> ImportError: No module named 'requests.packages.chardet' > > > That's a classic issue. pyinstaller does static analysis of the program, > which modules must be included. If the code computes a module dynamically, > it can not always succeed. The solution is to tell pyinstaller to add this > module. In previous versions, you could add these by "pyinstaller > --hidden-import=requests.packages.chardet" or similar. If this doesn't work, > you need to edit the spec file. See here: > > https://pythonhosted.org/PyInstaller/when-things-go-wrong.html#listing-hidden-imports Yes, I had seen that and I tried it with: --hidden-import=requests.packages.chardet and I got the same error at run time: $ dist/pyi_test/pyi_test Traceback (most recent call last): File "pyi_test.py", line 1, in import requests File "/usr/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "requests/init.py", line 58, in File "/usr/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "requests/utils.py", line 26, in File "/usr/lib/python2.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "requests/compat.py", line 7, in File "requests/packages/init.py", line 95, in load_module ImportError: No module named 'requests.packages.chardet' From davidgshi at yahoo.co.uk Wed Jul 27 07:37:01 2016 From: davidgshi at yahoo.co.uk (David Shi) Date: Wed, 27 Jul 2016 11:37:01 +0000 (UTC) Subject: Two constructive reviewers sought References: <1153663206.5528563.1469619421903.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <1153663206.5528563.1469619421903.JavaMail.yahoo@mail.yahoo.com> To promote the use of Python and formalise Python approach, I decided to publish a paper. I used geodata as a showcase. Geodata lies in the heart of geographical information science.? The management and processing of such data is of great importance. I got an email from?International Journal of Information Management. I was asked to suggest two reviewers for the following article. "Key solutions for automated data linkage, processing and generating output for big data analytics over the Internet". Nitrogen input from fertilizer use data was used as a showcase. If you like to be one of reviewers, please email?drshishaozhong at gmail.com?with your full contact details. Regards. David From python at bdurham.com Wed Jul 27 08:11:20 2016 From: python at bdurham.com (Malcolm Greene) Date: Wed, 27 Jul 2016 08:11:20 -0400 Subject: logging: getLogger() or getLogger(__name__)? Message-ID: <1469621480.3289126.678172857.169CEABC@webmail.messagingengine.com> I've read that best practice for logging is to place the following line at the top of all modules: logger = getLogger(__name__) I'm curious why the following technique wouldn't be a better choice: logger = getLogger() Are there scenarios that favor one style over another? Thank you, Malcolm From hemla21 at gmail.com Wed Jul 27 09:01:11 2016 From: hemla21 at gmail.com (Heli) Date: Wed, 27 Jul 2016 06:01:11 -0700 (PDT) Subject: reshape with xyz ordering In-Reply-To: References: Message-ID: <1208dd22-bad3-40e3-896b-a2dba97c5fad@googlegroups.com> Thanks for your replies. Let me explain my problem a little bit more. I have the following data which i read from a file using numpy.loadtxt and then i sort it using np.lexsort: x=f[:,0] # XColumn y=f[:,1] # YColumn z=f[:,2] # ZColumn val=f[:,3] # Val Column xcoord=np.sort(np.unique(f[:,0])) # XCoordinates ycoord=np.sort(np.unique(f[:,1])) # YCoordinates zcoord=np.sort(np.unique(f[:,2])) # ZCoordinates ind = np.lexsort((val,z,y,x)) val_sorted=np.array(val[ind]) I know that the val column has data sorted first by x, then by y, then by z which means that column x changes slowest and column z changes fastest. x,y,z, val 0,0,0,val1 0,0,1,val2 0,0,2,val3 .... 0,0,zn,valn ... xn,yn,zn,valfin I want to reshape val_sorted in to a 3d numpy array of (nx,ny,nz). which of the following is the correct way and why? #1 val_sorted_reshaped=val_sorted.reshape((xcoord.size,ycoord.size,zcoord.size)) #2 #val_sorted_reshaped=val_sorted.reshape((xcoord.size,ycoord.size,zcoord.size)).transpose() #3 #val_sorted_reshaped=val_sorted.reshape((zcoord.size,ycoord.size,xcoord.size)) #4 #val_sorted_reshaped=val_sorted.reshape((zcoord.size,ycoord.size,xcoord.size)).transpose() Thanks, From vostrushka at gmail.com Wed Jul 27 09:09:54 2016 From: vostrushka at gmail.com (Crane Ugly) Date: Wed, 27 Jul 2016 06:09:54 -0700 (PDT) Subject: Python environment on mac In-Reply-To: References: <950a22b5-6b34-4f99-8312-94972cb372da@googlegroups.com> <20160727005828.GA99643@cskk.homeip.net> Message-ID: <665e5869-7622-4896-8a91-bce99e035ae2@googlegroups.com> Yep, I agree. virtualenv is the best way to go so far. It solves my wishes to use python completely without root access too. Thank's a lot. Leonid From vlastimil.brom at gmail.com Wed Jul 27 09:12:46 2016 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Wed, 27 Jul 2016 15:12:46 +0200 Subject: pyinstaller In-Reply-To: References: Message-ID: 2016-07-27 3:15 GMT+02:00 Larry Martell : > On Tue, Jul 26, 2016 at 8:49 PM, Tom Brown wrote: >> I used pyinstaller quite a bit 3 years ago. I could brush off the cobwebs >> and see if I can help if you have not solved it already. >> >> What is the issue you are having? > > If I import the requests module, then when I run the executable I get: > > ImportError: No module named 'requests.packages.chardet' > > I tried to post to the pyinstaller group, but it said my post had to > be approved by the moderator, and it apparently never was. I have no > idea who the moderator is, so there was no one I could contact about > that. I posted an issue to github > (https://github.com/pyinstaller/pyinstaller/issues/2060) and some > suggestions were made, but none fixed the problem. I am on RHEL 7.2 > with Python 2.7.5, and it's reproducible, just by having a 1 line > script that has "import requests". Thanks for any help you could > provide. > > > > >> >> On Jun 21, 2016 16:57, "Larry Martell" wrote: >>> >>> Anyone here have any experience with pyinstaller? I am trying to use >>> it, but I'm not having much success. I tried posting to the >>> pyinstaller ML but it said my post had to be approved first, and that >>> hasn't happened in a while. I'll post details if someone here thinks >>> they can help. >>> -- Hi, is there a direct reference to that function in your code? On win7, python 3.5, if I use just a trivial stub source file like: import requests print(requests.packages.chardet.detect(b"qwe")) and freeze it with _path_to_\Python3\Scripts\pyinstaller.exe _path_to_\test_chardet.py --clean --noconfirm --onedir the resulting executable works ok, (it prints {'encoding': 'ascii', 'confidence': 1.0} just like the source version). However, I remember, that I had problems in the past with freezing (sub)modules or (sub)packages, that were not actually used in the source but should be made available for interactive usage on runtime within the app. I believe, manually referencing such objects helped in such cases, but I can't remember the details. Otherwise, it may be some version or platform dependent issue, of course. regards, vbr From python at bdurham.com Wed Jul 27 09:58:57 2016 From: python at bdurham.com (Malcolm Greene) Date: Wed, 27 Jul 2016 09:58:57 -0400 Subject: Behavior of tempfile temp files when scripts killed, interpreter crashes, server crashes? Message-ID: <1469627937.3315162.678210321.47361EB5@webmail.messagingengine.com> Can someone share their OS specific experience in working with tempfile generated temp files under these conditions? 1. Script killed by another process 2. Interpreter crashes 3. Server crashes (sudden loss of power) 4. Other application termination conditions ??? I'm curious which scenarios result in temp files not being automatically deleted after use and what technique you're using to cleanup temp files left over after these conditions (without affecting legitimate temp files present from the current session)? Do any OS's support a type of temp file that truly gets automatically deleted in all of the above scenarios? Thank you, Malcolm From antoon.pardon at rece.vub.ac.be Wed Jul 27 10:01:47 2016 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 27 Jul 2016 16:01:47 +0200 Subject: TypeError: '_TemporaryFileWrapper' object is not an iterator Message-ID: <5798BECB.8030800@rece.vub.ac.be> I am rewriting a program so it can work in python3. I am making progress, but now I stumble on the exception mentioned in the subject. The code still works in python2. What I'm doing is to write the results to temporary file that needs to be sorted afterwards. For as far as I understand after done writing all to the file and seeking it to the beginning I get the following when I start reading from it. Traceback (most recent call last): File "/local/home/apardon/src/fietsroutes/pymain.py", line 132, in main Exit_Nr = process(sys.argv) File "/local/home/apardon/src/fietsroutes/route.py", line 491, in program make_routes(map) File "/local/home/apardon/src/fietsroutes/route.py", line 465, in make_routes for rt in sortfile(allroutes, load, dump): File "/local/home/apardon/src/fietsroutes/filesort.py", line 129, in sortfile prv = next(itr) File "/local/home/apardon/src/fietsroutes/filesort.py", line 67, in Queuer buf = take(21, itr) File "/local/home/apardon/src/fietsroutes/filesort.py", line 21, in take ls.append(next(iterable)) File "/local/home/apardon/src/fietsroutes/filesort.py", line 35, in loading ln = load(fl) File "/local/home/apardon/src/fietsroutes/route.py", line 366, in load return greep(next(fl)) TypeError: '_TemporaryFileWrapper' object is not an iterator Locals by frame, innermost last Frame main in /local/home/apardon/src/fietsroutes/pymain.py at line 149 pn = 'route' process = Frame program in /local/home/apardon/src/fietsroutes/route.py at line 491 argv = ['route', '-r', '45'] index = 3 map = {'84Bh': {'83Bh': 17, '01Wo': 42, '85Bm': 37}, '70Rb': {'18Rb': 26, '03Zu': 91, "43Gd'": 33}, "43Gd'": { ... Frame make_routes in /local/home/apardon/src/fietsroutes/route.py at line 465 Dists = {'35HS': 204, '91Rt': 208, '79Oi': 492, "61Ch'": 347, '78AP': 479, '33Bt': 444, '241L': 429, '54Rh': 385 ... MinLength = 249 OldMin = 216 allroutes = dest = '16Pl' dist = 58 last = '86Ll' last_time = 1469626452.5767715 map = {'84Bh': {'83Bh': 17, '01Wo': 42, '85Bm': 37}, '70Rb': {'18Rb': 26, '03Zu': 91, "43Gd'": 33}, "43Gd'": { ... nr = 29 nwrt = ('16Pl', '86Ll', '80Wz', '79Bs', '59Bs', '69Vs', "70Vs'", '70Vs"', "78Th'", '78Th"', '48Th', '45Th', '01 ... nwtot = 274 prv = '80Wz' route = ('86Ll', '80Wz', '79Bs', '59Bs', '69Vs', "70Vs'", '70Vs"', "78Th'", '78Th"', '48Th', '45Th', '01Th', '04 ... start = '00Th' total = 216 vizor = '' Frame sortfile in /local/home/apardon/src/fietsroutes/filesort.py at line 129 fl = in1 = in2 = itr = ou1 = ou2 = swaps = 0 warn = Frame Queuer in /local/home/apardon/src/fietsroutes/filesort.py at line 67 fl = itr = Frame take in /local/home/apardon/src/fietsroutes/filesort.py at line 23 _ = 0 iterable = ls = [] n = 21 Frame loading in /local/home/apardon/src/fietsroutes/filesort.py at line 40 fl = Frame load in /local/home/apardon/src/fietsroutes/route.py at line 366 fl = From vostrushka at gmail.com Wed Jul 27 12:28:50 2016 From: vostrushka at gmail.com (Crane Ugly) Date: Wed, 27 Jul 2016 09:28:50 -0700 (PDT) Subject: python and open office Message-ID: I try to create some scripts that will help me to open and manipulate OpenOffice documents. Calc in particular. But I have some problems finding right packages or libraries that offer such interface. So far I was trying uno and unotools but the first step is to import them failed. Here is the output: UNO tools are installed: $ pip list | grep uno uno (0.3.3) unotools (0.3.3) Try to import them: $ python Python 2.7.12 (default, Jun 29 2016, 12:53:15) [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import uno >>> import unotools Traceback (most recent call last): File "", line 1, in File "/Volumes/home/lshanin/Dropbox/Python/ve/accounting/lib/python2.7/site-packages/unotools/__init__.py", line 16 def __init__(self, name: str): ^ SyntaxError: invalid syntax >>> I would appreciate is somebody help me to find what is wrong with untools package. Or point me to some other available libraries. I expect to work with OpenOffice (LibreOffice) files only not with MS Excel files. Regards Leonid From ckaynor at zindagigames.com Wed Jul 27 12:37:03 2016 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Wed, 27 Jul 2016 09:37:03 -0700 Subject: python and open office In-Reply-To: References: Message-ID: def __init__(self, name: str): That "name: str" syntax is called function annotations, and was added in Python 3, and you are trying to use the module in Python 2.7. There may be another variation of the module compatible with Python 2, or you'll need to upgrade your Python to a version of Python 3. Chris On Wed, Jul 27, 2016 at 9:28 AM, Crane Ugly wrote: > I try to create some scripts that will help me to open and manipulate > OpenOffice documents. Calc in particular. But I have some problems finding > right packages or libraries that offer such interface. > So far I was trying uno and unotools but the first step is to import them > failed. Here is the output: > > UNO tools are installed: > $ pip list | grep uno > uno (0.3.3) > unotools (0.3.3) > > Try to import them: > $ python > Python 2.7.12 (default, Jun 29 2016, 12:53:15) > [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import uno > >>> import unotools > Traceback (most recent call last): > File "", line 1, in > File > "/Volumes/home/lshanin/Dropbox/Python/ve/accounting/lib/python2.7/site-packages/unotools/__init__.py", > line 16 > def __init__(self, name: str): > ^ > SyntaxError: invalid syntax > >>> > > I would appreciate is somebody help me to find what is wrong with untools > package. > Or point me to some other available libraries. I expect to work with > OpenOffice (LibreOffice) files only not with MS Excel files. > > Regards > Leonid > -- > https://mail.python.org/mailman/listinfo/python-list > From laurent.pointal at free.fr Wed Jul 27 12:50:06 2016 From: laurent.pointal at free.fr (Laurent Pointal) Date: Wed, 27 Jul 2016 18:50:06 +0200 Subject: logging: getLogger() or getLogger(__name__)? References: <1469621480.3289126.678172857.169CEABC@webmail.messagingengine.com> Message-ID: <5798e63e$0$3345$426a74cc@news.free.fr> Malcolm Greene wrote: > I've read that best practice for logging is to place the following line > at the top of all modules: > > logger = getLogger(__name__) > > I'm curious why the following technique wouldn't be a better choice: > > logger = getLogger() > > Are there scenarios that favor one style over another? With __name__ you will have one logger per source file (module), with corresponding filtering possibilities, and organized hierarchically as are packages (logging use . to built its loggers hierarchy). Without __name__, you have one global default logger. > > Thank you, > Malcolm From id23092 at gmail.com Wed Jul 27 13:54:47 2016 From: id23092 at gmail.com (id23092 at gmail.com) Date: Wed, 27 Jul 2016 19:54:47 +0200 Subject: working with OpenOffice Calc Message-ID: I am looking for a library that will allow me to work with Calc documents from Python. But so far I was not able to build properly working environment for that. Here is what I already tried. Installed uno and unotools for Python 2.7, but importing unotools gives an error: UNO tools are installed: (accounting) $ pip list | grep uno uno (0.3.3) unotools (0.3.3) Try to import them: (accounting) $ python Python 2.7.12 (default, Jun 29 2016, 12:53:15) [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import uno >>> import unotools Traceback (most recent call last): File "", line 1, in File "/Python/ve/accounting/lib/python2.7/site-packages/unotools/__init__.py", line 16 def __init__(self, name: str): ^ SyntaxError: invalid syntax >>> I also tried to install pyoo, but it is also failing on import: (accounting) $ pip list |grep pyoo pyoo (1.1) (accounting) $ python Python 2.7.12 (default, Jun 29 2016, 12:53:15) [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import pyoo Traceback (most recent call last): File "", line 1, in File "/Python/ve/accounting/lib/python2.7/site-packages/pyoo.py", line 26, in FORMAT_TEXT = uno.getConstantByName('com.sun.star.i18n.NumberFormatIndex.TEXT') AttributeError: 'module' object has no attribute 'getConstantByName' >>> Could someone point me to the right direction to solve the issue. Regards Leonid From tjreedy at udel.edu Wed Jul 27 15:01:24 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Jul 2016 15:01:24 -0400 Subject: python and open office In-Reply-To: References: Message-ID: On 7/27/2016 12:37 PM, Chris Kaynor wrote: > def __init__(self, name: str): > > That "name: str" syntax is called function annotations, and was added in > Python 3, and you are trying to use the module in Python 2.7. > > There may be another variation of the module compatible with Python 2, or > you'll need to upgrade your Python to a version of Python 3. > > Chris > > On Wed, Jul 27, 2016 at 9:28 AM, Crane Ugly wrote: > >> I try to create some scripts that will help me to open and manipulate >> OpenOffice documents. Calc in particular. But I have some problems finding >> right packages or libraries that offer such interface. >> So far I was trying uno and unotools but the first step is to import them >> failed. Here is the output: >> >> UNO tools are installed: >> $ pip list | grep uno >> uno (0.3.3) >> unotools (0.3.3) >> >> Try to import them: >> $ python >> Python 2.7.12 (default, Jun 29 2016, 12:53:15) >> [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import uno >>>>> import unotools >> Traceback (most recent call last): >> File "", line 1, in >> File >> "/Volumes/home/lshanin/Dropbox/Python/ve/accounting/lib/python2.7/site-packages/unotools/__init__.py", >> line 16 >> def __init__(self, name: str): >> ^ >> SyntaxError: invalid syntax >>>>> >> >> I would appreciate is somebody help me to find what is wrong with untools >> package. >> Or point me to some other available libraries. I expect to work with >> OpenOffice (LibreOffice) files only not with MS Excel files. Are you working with OpenOffice or LibreOffice? There are *different programs*. Last I know, current LibreOffice comes with python 3.3.3 in its program directory and you need at least Python 3.3.3 for its UNO bridge, as it used the FSR unicode representation introduced in 3.3. -- Terry Jan Reedy From tjreedy at udel.edu Wed Jul 27 15:02:32 2016 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 27 Jul 2016 15:02:32 -0400 Subject: working with OpenOffice Calc In-Reply-To: References: Message-ID: On 7/27/2016 1:54 PM, id23092 at gmail.com wrote: > I am looking for a library that will allow me to work with Calc documents from Python. > But so far I was not able to build properly working environment for that. You posted this same question 1 1/2 hours before under a different name. Please don't repost, especially when a correct answer was posted 9 minutes after the first. > I also tried to install pyoo, but it is also failing on import: A different question, but the answer is still the same. Use compatible versions of python and 3rd party packages. > (accounting) $ pip list |grep pyoo > pyoo (1.1) > > (accounting) $ python > Python 2.7.12 (default, Jun 29 2016, 12:53:15) > [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import pyoo > Traceback (most recent call last): > File "", line 1, in > File "/Python/ve/accounting/lib/python2.7/site-packages/pyoo.py", line 26, in > FORMAT_TEXT = uno.getConstantByName('com.sun.star.i18n.NumberFormatIndex.TEXT') > AttributeError: 'module' object has no attribute 'getConstantByName' >>>> > > > Could someone point me to the right direction to solve the issue. > > Regards > Leonid > -- Terry Jan Reedy From pandora.forest at icloud.com Wed Jul 27 15:05:47 2016 From: pandora.forest at icloud.com (Leonid Shanin) Date: Wed, 27 Jul 2016 21:05:47 +0200 Subject: python and open office In-Reply-To: References: Message-ID: <61037929-66C6-4DC0-BE66-3930370E233E@icloud.com> I use LibreOffice. Yes, it looks like I have to switch to Python 3 in this case. I'll try v.3 then Thank you Leonid > On 27-07-2016, at 21:01, Terry Reedy wrote: > > On 7/27/2016 12:37 PM, Chris Kaynor wrote: >> def __init__(self, name: str): >> >> That "name: str" syntax is called function annotations, and was added in >> Python 3, and you are trying to use the module in Python 2.7. >> >> There may be another variation of the module compatible with Python 2, or >> you'll need to upgrade your Python to a version of Python 3. >> >> Chris >> >> On Wed, Jul 27, 2016 at 9:28 AM, Crane Ugly wrote: >> >>> I try to create some scripts that will help me to open and manipulate >>> OpenOffice documents. Calc in particular. But I have some problems finding >>> right packages or libraries that offer such interface. >>> So far I was trying uno and unotools but the first step is to import them >>> failed. Here is the output: >>> >>> UNO tools are installed: >>> $ pip list | grep uno >>> uno (0.3.3) >>> unotools (0.3.3) >>> >>> Try to import them: >>> $ python >>> Python 2.7.12 (default, Jun 29 2016, 12:53:15) >>> [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> import uno >>>>>> import unotools >>> Traceback (most recent call last): >>> File "", line 1, in >>> File >>> "/Volumes/home/lshanin/Dropbox/Python/ve/accounting/lib/python2.7/site-packages/unotools/__init__.py", >>> line 16 >>> def __init__(self, name: str): >>> ^ >>> SyntaxError: invalid syntax >>>>>> >>> >>> I would appreciate is somebody help me to find what is wrong with untools >>> package. >>> Or point me to some other available libraries. I expect to work with >>> OpenOffice (LibreOffice) files only not with MS Excel files. > > Are you working with OpenOffice or LibreOffice? There are *different programs*. Last I know, current LibreOffice comes with python 3.3.3 in its program directory and you need at least Python 3.3.3 for its UNO bridge, as it used the FSR unicode representation introduced in 3.3. > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list From huey.y.jiang at gmail.com Wed Jul 27 16:18:16 2016 From: huey.y.jiang at gmail.com (huey.y.jiang at gmail.com) Date: Wed, 27 Jul 2016 13:18:16 -0700 (PDT) Subject: Is it possible to draw a BUTTON? Message-ID: <8e075875-3a7b-467a-9f81-88eb8ac6e445@googlegroups.com> Hi Folks, It is common to put a BUTTON on a canvas by the means of coding. However, in my application, I need to draw a circle on canvas, and then make this circle to work as if it is a button. When the circle is clicked, it triggers a new image to be displayed. Somebody can help? Thanks! From larry.martell at gmail.com Wed Jul 27 17:25:43 2016 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 27 Jul 2016 17:25:43 -0400 Subject: ImportError: Import by filename is not supported when unpickleing Message-ID: When I try and unpickle an object with pickle.loads it fails with: ImportError: Import by filename is not supported when unpickleing I've never used pickle before. Why do I get this and how can I fix it? From larry.martell at gmail.com Wed Jul 27 17:28:44 2016 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 27 Jul 2016 17:28:44 -0400 Subject: pyinstaller In-Reply-To: References: Message-ID: On Wed, Jul 27, 2016 at 9:12 AM, Vlastimil Brom wrote: > 2016-07-27 3:15 GMT+02:00 Larry Martell : >> On Tue, Jul 26, 2016 at 8:49 PM, Tom Brown wrote: >>> I used pyinstaller quite a bit 3 years ago. I could brush off the cobwebs >>> and see if I can help if you have not solved it already. >>> >>> What is the issue you are having? >> >> If I import the requests module, then when I run the executable I get: >> >> ImportError: No module named 'requests.packages.chardet' >> >> I tried to post to the pyinstaller group, but it said my post had to >> be approved by the moderator, and it apparently never was. I have no >> idea who the moderator is, so there was no one I could contact about >> that. I posted an issue to github >> (https://github.com/pyinstaller/pyinstaller/issues/2060) and some >> suggestions were made, but none fixed the problem. I am on RHEL 7.2 >> with Python 2.7.5, and it's reproducible, just by having a 1 line >> script that has "import requests". Thanks for any help you could >> provide. >> >> >> >> >>> >>> On Jun 21, 2016 16:57, "Larry Martell" wrote: >>>> >>>> Anyone here have any experience with pyinstaller? I am trying to use >>>> it, but I'm not having much success. I tried posting to the >>>> pyinstaller ML but it said my post had to be approved first, and that >>>> hasn't happened in a while. I'll post details if someone here thinks >>>> they can help. >>>> -- > > Hi, > is there a direct reference to that function in your code? No there is no reference to that function. As I said, for testing I have just a single line script with import requests > > On win7, python 3.5, if I use just a trivial stub source file like: > > import requests > print(requests.packages.chardet.detect(b"qwe")) > > and freeze it with > _path_to_\Python3\Scripts\pyinstaller.exe _path_to_\test_chardet.py > --clean --noconfirm --onedir > > the resulting executable works ok, (it prints {'encoding': 'ascii', > 'confidence': 1.0} just like the source version). Yes, people have reported on git that it works on Windows. > However, I remember, that I had problems in the past with freezing > (sub)modules or (sub)packages, that were not actually used in the > source but should be made available for interactive usage on runtime > within the app. I believe, manually referencing such objects helped in > such cases, but I can't remember the details. I will try that. > Otherwise, it may be some version or platform dependent issue, of course. From hexusnexus at gmail.com Wed Jul 27 17:51:25 2016 From: hexusnexus at gmail.com (Jason Benjamin) Date: Wed, 27 Jul 2016 21:51:25 +0000 (UTC) Subject: Is it possible to draw a BUTTON? References: <8e075875-3a7b-467a-9f81-88eb8ac6e445@googlegroups.com> Message-ID: On Wed, 27 Jul 2016 13:18:16 -0700, huey.y.jiang wrote: > Hi Folks, > > It is common to put a BUTTON on a canvas by the means of coding. > However, in my application, I need to draw a circle on canvas, and then > make this circle to work as if it is a button. When the circle is > clicked, it triggers a new image to be displayed. Somebody can help? > Thanks! It depends on what GUI toolkit you use. Can you give more specific information? Since a canvas is refreshed (updated) every time the function for redraw is called, it is as simple as changing the variable for what should be drawn when a click event is sent to the canvas and the area hot-spot is the same as the area of the button. Buffered drawing is similar. -- [The Computer] was the first machine man built that assisted the power of his brain instead of the strength of his arm. - Grace Hopper From hexusnexus at gmail.com Wed Jul 27 17:54:16 2016 From: hexusnexus at gmail.com (Jason Benjamin) Date: Wed, 27 Jul 2016 21:54:16 +0000 (UTC) Subject: ImportError: Import by filename is not supported when unpickleing References: Message-ID: On Wed, 27 Jul 2016 17:25:43 -0400, Larry Martell wrote: > When I try and unpickle an object with pickle.loads it fails with: > > ImportError: Import by filename is not supported when unpickleing > > I've never used pickle before. Why do I get this and how can I fix it? Try using *pickle.load* instead of *pickle.loads*. pickle.loads is for strings. Retrieved from documentation: help(pickle) after importing pickle. -- [The Computer] was the first machine man built that assisted the power of his brain instead of the strength of his arm. - Grace Hopper From larry.martell at gmail.com Wed Jul 27 18:44:22 2016 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 27 Jul 2016 18:44:22 -0400 Subject: ImportError: Import by filename is not supported when unpickleing In-Reply-To: References: Message-ID: On Wednesday, July 27, 2016, Jason Benjamin > wrote: > On Wed, 27 Jul 2016 17:25:43 -0400, Larry Martell wrote: > > > When I try and unpickle an object with pickle.loads it fails with: > > > > ImportError: Import by filename is not supported when unpickleing > > > > I've never used pickle before. Why do I get this and how can I fix it? > > Try using *pickle.load* instead of *pickle.loads*. pickle.loads is for > strings. Retrieved from documentation: help(pickle) after importing > pickle. > I am unpickling a string created with pickle.dumps From huey.y.jiang at gmail.com Wed Jul 27 19:13:22 2016 From: huey.y.jiang at gmail.com (huey.y.jiang at gmail.com) Date: Wed, 27 Jul 2016 16:13:22 -0700 (PDT) Subject: Is it possible to draw a BUTTON? In-Reply-To: <8e075875-3a7b-467a-9f81-88eb8ac6e445@googlegroups.com> References: <8e075875-3a7b-467a-9f81-88eb8ac6e445@googlegroups.com> Message-ID: <28fab6aa-176b-49ad-9e5e-cdce2e081940@googlegroups.com> On Wednesday, July 27, 2016 at 4:18:29 PM UTC-4, huey.y... at gmail.com wrote: > Hi Folks, > > It is common to put a BUTTON on a canvas by the means of coding. However, in my application, I need to draw a circle on canvas, and then make this circle to work as if it is a button. When the circle is clicked, it triggers a new image to be displayed. Somebody can help? Thanks! ---> By the way, the GUI is TK. From larry.martell at gmail.com Wed Jul 27 19:30:03 2016 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 27 Jul 2016 19:30:03 -0400 Subject: ImportError: Import by filename is not supported when unpickleing In-Reply-To: <1469660069.15717.4@smtp.gmail.com> References: <1469660069.15717.4@smtp.gmail.com> Message-ID: On Wed, Jul 27, 2016 at 6:54 PM, Jason Benjamin wrote: > If it has and 's' on the end it will only work on strings. *dumps* refers > to a string too. Yes, I know. I have an object, which I pickle with dumps, which turns it into a string. Then I try to unpickle it with loads and I get that error. (Pdb) type(args.target) (Pdb) pickle.loads(args.target) *** ImportError: Import by filename is not supported. > On Wed, Jul 27, 2016 at 3:44 PM, Larry Martell > wrote: > > > > On Wednesday, July 27, 2016, Jason Benjamin wrote: >> >> On Wed, 27 Jul 2016 17:25:43 -0400, Larry Martell wrote: >> >> > When I try and unpickle an object with pickle.loads it fails with: >> > >> > ImportError: Import by filename is not supported when unpickleing >> > >> > I've never used pickle before. Why do I get this and how can I fix it? >> >> Try using *pickle.load* instead of *pickle.loads*. pickle.loads is for >> strings. Retrieved from documentation: help(pickle) after importing >> pickle. > > > I am unpickling a string created with pickle.dumps From python at mrabarnett.plus.com Wed Jul 27 20:14:57 2016 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 28 Jul 2016 01:14:57 +0100 Subject: Is it possible to draw a BUTTON? In-Reply-To: <28fab6aa-176b-49ad-9e5e-cdce2e081940@googlegroups.com> References: <8e075875-3a7b-467a-9f81-88eb8ac6e445@googlegroups.com> <28fab6aa-176b-49ad-9e5e-cdce2e081940@googlegroups.com> Message-ID: On 2016-07-28 00:13, huey.y.jiang at gmail.com wrote: > On Wednesday, July 27, 2016 at 4:18:29 PM UTC-4, huey.y... at gmail.com wrote: >> Hi Folks, >> >> It is common to put a BUTTON on a canvas by the means of coding. However, in my application, I need to draw a circle on canvas, and then make this circle to work as if it is a button. When the circle is clicked, it triggers a new image to be displayed. Somebody can help? Thanks! > > ---> By the way, the GUI is TK. > Here's a simple example: #! python3.5 # -*- coding: utf-8 -*- import tkinter as tk def mouse_clicked(event): dist_sq = (event.x - circle['x']) ** 2 + (event.y - circle['y']) ** 2 if dist_sq <= circle['radius'] ** 2: print('Clicked inside circle') root = tk.Tk() canvas = tk.Canvas(root, width=400, height=200) canvas.pack() circle = dict(x=60, y=60, radius=20) left = circle['x'] - circle['radius'] top = circle['y'] - circle['radius'] right = circle['x'] + circle['radius'] bottom = circle['y'] + circle['radius'] canvas.create_oval((left, top, right, bottom), outline='red', fill='red') canvas.bind('', mouse_clicked) root.mainloop() From rantingrickjohnson at gmail.com Wed Jul 27 21:59:23 2016 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 27 Jul 2016 18:59:23 -0700 (PDT) Subject: Is it possible to draw a BUTTON? In-Reply-To: References: <8e075875-3a7b-467a-9f81-88eb8ac6e445@googlegroups.com> <28fab6aa-176b-49ad-9e5e-cdce2e081940@googlegroups.com> Message-ID: On Wednesday, July 27, 2016 at 7:15:20 PM UTC-5, MRAB wrote: > On 2016-07-28 00:13, huey.y.jiang at gmail.com wrote: > > On Wednesday, July 27, 2016 at 4:18:29 PM UTC-4, huey.y... at gmail.com wrote: > >> Hi Folks, > >> > >> It is common to put a BUTTON on a canvas by the means of coding. However, in my application, I need to draw a circle on canvas, and then make this circle to work as if it is a button. When the circle is clicked, it triggers a new image to be displayed. Somebody can help? Thanks! > > > > ---> By the way, the GUI is TK. > > > Here's a simple example: > > > #! python3.5 > # -*- coding: utf-8 -*- > import tkinter as tk > > def mouse_clicked(event): > dist_sq = (event.x - circle['x']) ** 2 + (event.y - circle['y']) ** 2 > > if dist_sq <= circle['radius'] ** 2: > print('Clicked inside circle') > > root = tk.Tk() > > canvas = tk.Canvas(root, width=400, height=200) > canvas.pack() > > circle = dict(x=60, y=60, radius=20) > > left = circle['x'] - circle['radius'] > top = circle['y'] - circle['radius'] > right = circle['x'] + circle['radius'] > bottom = circle['y'] + circle['radius'] > > canvas.create_oval((left, top, right, bottom), outline='red', fill='red') > canvas.bind('', mouse_clicked) > > root.mainloop() I didn't try your code, but you can simply it by using some of the core functionality provided via "canvas.tag_bind(...)" ## START CODE ## import Tkinter as tk def cb_canvasButton(event): print 'You clicked me using button {0}'.format(event.num) canvas.move('button', 10, 10) # Little extra surprise! root = tk.Tk() canvas = tk.Canvas(root) canvas.create_oval(10,10,50,50, outline='red', fill='blue', tags=('button',) ) canvas.tag_bind('button', '