Re: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it?

2021-06-15 Thread Greg Ewing
On 15/06/21 7:32 pm, Jach Feng wrote: But usually the list creation is not in simple way:-) for example: a = [1,2] m = [a for i in range(3)] m [[1, 2], [1, 2], [1, 2]] id(m[0]) == id(m[1]) == id(m[2]) True The first line is only executed once, so you just get one list object [1, 2]. You the

Re: optimization of rule-based model on discrete variables

2021-06-15 Thread Greg Ewing
On 15/06/21 10:07 pm, Elena wrote: After the optimization, I will use f just to predict new Xi. So you're going to use f backwards? I don't see how that will work. Where are you going to find a new yi to feed into the inverse of f? I think I don't understand what role g plays in all of this.

Re: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it?

2021-06-15 Thread Greg Ewing
On 16/06/21 12:15 pm, Avi Gross wrote: May I ask if there are any PRACTICAL differences if multiple immutable tuples share the same address or not? Only if some piece of code relies on the identity of tuples by using 'is' or id() on them. There's rarely any need to write code like that, though

Re: Where did the message go?

2021-06-16 Thread Greg Ewing
On 16/06/21 4:47 am, Chris Angelico wrote: On Wed, Jun 16, 2021 at 2:41 AM Grimble wrote: > was bouncing because haydn.. was not a registered subdomain with my ISP, whereas bach.. was registered. > > I like your naming convention :) Weirdly, the first association "haydn" trig

Re: optimization of rule-based model on discrete variables

2021-06-16 Thread Greg Ewing
On 16/06/21 10:51 pm, Elena wrote: sorry I wrote it wrongly, my bad, I will use f just to predict yi from new coming Xi. Then what do you do with the new yi? -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Optimizing Small Python Code

2021-06-22 Thread Greg Ewing
On 23/06/21 3:03 am, Kais Ayadi wrote: for n in range(1, 7): print (n) for x in range(0, n): print(" ", x) can this code be more optimised? Optimised for what? Readability? Execution speed? Code size? Memory usage? -- Greg -- https://mail.python.org/mailman/listinfo/pyt

Re: How to iterate through maildir messages in python 3?

2021-06-24 Thread Greg Ewing
On 25/06/21 7:06 am, Chris Green wrote: In python 2 one can do:- for msg in maildir: print msg # or whatever you want to do with the message However in python 3 this produces "TypeError: string argument expected, got 'bytes'". How should one iterate over a maildir in pytho

Re: i just moved from bottleframework to flask. I changes what needed to be altered to convert the code and when i run it i just get "Internal server error" Running tail -f ../logs/error_log i get no

2021-07-10 Thread Greg Ewing
On 11/07/21 2:24 am, Dennis Lee Bieber wrote: Off-hand, that looks like a BASH command, so stuff it in your .bashrc or .profile and see what happens. Or make yourself a little shell script that starts flask with the appopriate settings. -- Greg -- https://mail.python.org/mailman/listi

Re: Rotation of a cube

2021-07-29 Thread Greg Ewing
On 30/07/21 5:57 am, Michael F. Stemper wrote: I would like to animate the rotation of a 3-cube.ng each step. However, it seems to me that this is a solved problem, so there is probably a module that will do most of the scutwork for me. You might find something useful here: https://medium.com

Re: on slices, negative indices, which are the equivalent procedures?

2021-08-07 Thread Greg Ewing
On 6/08/21 12:00 pm, Jack Brandom wrote: It seems that I'd begin at position 3 (that's "k" which I save somewhere), then I subtract 1 from 3, getting 2 (that's "c", which I save somewhere), then I subtract 1 from 2, getting 1 (that's "a", ...), then I subtract 1 from 1, getting 0 (that's J, ...),

Re: some problems for an introductory python test

2021-08-11 Thread Greg Ewing
On 11/08/21 3:22 pm, Terry Reedy wrote: Python is a little looser about whitespace than one might expect from reading 'normal' code when the result is unambiguous in that it cannot really mean anything other than what it does. >>> if3: print('yes!') yes! That may not be doing what you think

Re: some problems for an introductory python test

2021-08-12 Thread Greg Ewing
On 13/08/21 11:42 am, Cameron Simpson wrote: 2: It took me a while to see, but this is a type annotiation. Interestingly, it seems to be parsed as a form of assignment with a missing RHS. >>> from ast import parse, dump >>> dump(parse("if0: print('yes!')")) "Module(body=[AnnAssign(target=Name(

Re: some problems for an introductory python test

2021-08-12 Thread Greg Ewing
On 13/08/21 5:52 am, Grant Edwards wrote: I think what he's talking about is allowing the user to attach arbitrary _metadata_ to the file ... IOW, something similar to the > "resource fork" that MacOS used to have. The resource fork was used for more than just metadata, it was often the entire

Re: on perhaps unloading modules?

2021-08-16 Thread Greg Ewing
On 16/08/21 1:50 am, Hope Rouselle wrote: By the way, I'm aware that what I'm doing here is totally unsafe and I could get my system destroyed. I'm not planning on using this --- thank you for your concern. I'm just interested in understanding more about modules. Okay, I'll assume all the sec

Re: Regarding inability of Python Module Winsound to produce beep in decimal frequency

2021-08-18 Thread Greg Ewing
On 18/08/21 4:43 pm, Steve wrote: "The HAL (hardware abstraction layer) function HalMakeBeep()" Is the beep that opens the pod bay doors? def HalMakeBeepUsingPCSpeaker(): raise IOError("I'm sorry, I can't do that, Dave.") -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: question on trax

2021-08-18 Thread Greg Ewing
On 19/08/21 3:59 am, joseph pareti wrote: Another question is on this line: z = add((x, y)) If I code: z = add(x, y) Then the following exception occurs : *Expected input to be a tuple or list; instead got .* What exactly is your question? Does add((x, y)) not do what you want? If not, you'll

Re: on perhaps unloading modules?

2021-08-20 Thread Greg Ewing
On 21/08/21 6:15 am, Hope Rouselle wrote: code() 'def p():\n import math\n return math.e\n' exec(code()) p p() 2.718281828459045 Note that this pollutes the globals of the module that you're calling exec() from. For better isolation you can pass in an explicit globals dict: g = {} exec

Re: on perhaps unloading modules?

2021-08-21 Thread Greg Ewing
On 21/08/21 1:36 pm, Hope Rouselle wrote: I wish I could restrict their syntax too, though, but I fear that's not possible. For instance, it would be very useful if I could remove loops. Actually you could, using ast.parse to get an AST and then walk it looking for things you don't want to all

Re: on floating-point numbers

2021-09-04 Thread Greg Ewing
On 3/09/21 8:11 pm, Christian Gollwitzer wrote: Unless you have special numbers like NaN or signed zeros etc., a+b=b+a and a*b=b*a holds also for floats. The only exception I'm aware of is for NaNs, and it's kind of pendantic: you can't say that x + NaN == NaN + x, but only because NaNs never c

Re: on floating-point numbers

2021-09-04 Thread Greg Ewing
On 5/09/21 2:42 am, Hope Rouselle wrote: Here's what I did on this case. The REPL is telling me that 7.23 = 2035064081618043/281474976710656 If 7.23 were exactly representable, you would have got 723/1000. Contrast this with something that *is* exactly representable: >>> 7.875.as_integer

Re: on writing a while loop for rolling two dice

2021-09-07 Thread Greg Ewing
On 7/09/21 11:38 am, Avi Gross wrote: #define INDEFINITELY_LOOP while (true) So, how to do something like that in python, is a challenge left to the user 😉 def hell_frozen_over(): return False while not hell_frozen_over(): -- Greg -- https://mail.python.org/mailman/listinfo/py

Re: on writing a while loop for rolling two dice

2021-09-07 Thread Greg Ewing
On 8/09/21 2:53 am, Grant Edwards wrote: #define IF if ( #define THEN ) { #define ELSE } else { #define ENDIF } ... I gather that early versions of some of the Unix utilities were written by someone who liked using macros to make C resemble Algol. I guess you can get away with t

Re: Friday Finking: Contorted loops

2021-09-10 Thread Greg Ewing
On 10/09/21 11:47 am, Terry Reedy wrote: 2. It is rare useful.  For loops are common.  While loops are occasional (nearly an order of magnitude less common than for loops.  Fractional loop constructs are rare. I would say that fractional loops are more common than loops which truly need to exe

Re: Change the display style of the text on the STACKLINE.

2021-09-10 Thread Greg Ewing
On 10/09/21 6:11 pm, Roland Mueller wrote: When I call print(s) it even shows ABCD and D is underscored. But copying the output to mail looses the underscore ... If the terminal understands unicode, Combining Low Line: U+0332 might help -- Greg -- https://mail.python.org/mailman/listinfo/pyth

Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-16 Thread Greg Ewing
On 16/09/21 4:23 am, Mostowski Collapse wrote: I really wonder why my Python implementation is a factor 40 slower than my JavaScript implementation. There are Javascript implementations around nowadays that are blazingly fast. Partly that's because a lot of effort has been put into them, but it

Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-16 Thread Greg Ewing
On 16/09/21 2:56 pm, Mostowski Collapse wrote: I can access the functor of a compound via: obj.functor but when I flatten Compound into arrays, it would become: obj[0] Should I declare a constant FUNCTOR = 0? You could, but keep in mind that access to a global in Python is somew

Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-17 Thread Greg Ewing
On 16/09/21 6:56 am, Mostowski Collapse wrote: What could be slow, repeatedly requesting the "args" field. Maybe I should do: help = term.args i = 0 while i < len(help) - 1: mark_term(help[i]) i += 1 term = help[i] Yes, that will certainly help. But you're still evaluating len(help) -

Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-18 Thread Greg Ewing
On 17/09/21 7:56 am, Mostowski Collapse wrote: The trail in Dogelog Runtime is a single linked list:     -->[ A ]-->[ B ]-->[ C ]--> Now if B becomes unused, you need to rewire the trail, it should then look like:     -->[ A ]-->[ C ]--> Python has a way of creating weak references

Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-18 Thread Greg Ewing
On 17/09/21 8:41 pm, Mostowski Collapse wrote: Are exceptions blocks in Python cheap or expensive? Are they like in Java, some code annotation, or like in Go programming language pushing some panic handler? They're not free, but they're not hugely expensive either. Don't be afraid to use them w

Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-18 Thread Greg Ewing
On 16/09/21 6:13 am, Mostowski Collapse wrote: So in Python I now do the following: peek = kb.get(functor, NotImplemented) if peek is not NotImplemented: If you're able to use None instead of NotImplemented, you could simplify that to peek = kb.get(functor) if peek: ..

Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-20 Thread Greg Ewing
On Mon, Sep 20, 2021 at 3:19 AM Mostowski Collapse wrote: On the other hand if I would use the trigger from Python, I possibly would need a double linked list, to remove an element. Here's another idea: Put weak references in the trail, but don't bother with the scanning -- just skip over dea

Re: Type annotation pitfall

2021-09-24 Thread Greg Ewing
On 24/09/21 5:48 pm, Robert Latest wrote: Never use mutable types in type hint, No, the lesson is: Don't mutate a shared object if you don't want the changes to be shared. If you want each instance to have its own set object, you need to create one for it in the __init__ method, e.g. class Fo

Re: Different "look and feel" of some built-in functions

2021-09-24 Thread Greg Ewing
On 25/09/21 10:15 am, Steve Keller wrote: BTW, I like how the min() and max() functions allow both ways of being called. That wouldn't work for set.union and set.intersection, because as was pointed out, they're actually methods, so set.union(some_seq) is a type error: >>> a = {1, 2} >>> b = {

Re: XML Considered Harmful

2021-09-24 Thread Greg Ewing
On 25/09/21 6:29 am, Peter J. Holzer wrote: don't forget that XML was intended to replace SGML, and that SGML was intended to mark up text, not represent any data. And for me this is the number one reason why XML is the wrong tool for almost everything it's used for nowadays. It's bizarre. It'

Re: XML Considered Harmful

2021-09-24 Thread Greg Ewing
On 25/09/21 6:34 am, Peter J. Holzer wrote: Several hundred genes were recently renamed because Excel was unable to read their names as simply strings and insisted on interpreting them as something else (e.g. dates). Another fun one I've come across is interpreting phone numbers as floating poi

Re: XML Considered Harmful

2021-09-24 Thread Greg Ewing
On 25/09/21 10:51 am, dn wrote: XML: Originally invented for text markup, and that shows. Can represent different types (via tags), can define those types (via DTD and/or schemas), can identify schemas in a globally-unique way and you can mix them all in a single document (and there are tools ava

Re: XML Considered Harmful

2021-09-24 Thread Greg Ewing
On 25/09/21 11:00 am, Chris Angelico wrote: On Sat, Sep 25, 2021 at 8:53 AM dn via Python-list wrote: and YAML? Invented because there weren't enough markup languages, so we needed another? There were *too many* markup languages, so we invented another! -- Greg -- https://mail.python.org/

Re: XML Considered Harmful

2021-09-28 Thread Greg Ewing
On 29/09/21 4:37 am, Michael F. Stemper wrote: I'm talking about something made from tons of iron and copper that is oil-filled and rotates at 1800 rpm. To avoid confusion, we should rename them "electricity comprehensions". -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: OT: AttributeError

2021-09-28 Thread Greg Ewing
On 29/09/21 12:21 pm, Chris Angelico wrote: to the extent that you automatically read 65 and 0x41 as the same number. Am I too geeky for reading both of them as 'A'? -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: OT: AttributeError

2021-09-29 Thread Greg Ewing
On 29/09/21 3:03 pm, 2qdxy4rzwzuui...@potatochowder.com wrote: Who thinks in little endian? (I was raised on 6502s and 680XX CPUs; 8080s and Z80s always did things backwards.) The first CPU I wrote code for was a National SC/MP, which doesn't have an endianness, since it never deals with more

Re: OT: AttributeError

2021-09-29 Thread Greg Ewing
On 30/09/21 7:28 am, dn wrote: Oh yes! The D2 kit - I kept those books for years... https://www.electronixandmore.com/adam/temp/6800trainer/mek6800d2.html My 6800 system was nowhere near as fancy as that! It was the result of replacing the CPU in my homebrew Miniscamp. -- Greg -- https://mai

Re: New assignmens ...

2021-10-22 Thread Greg Ewing
On 23/10/21 8:49 am, dn wrote: Whereas, creating a list (or tuple...) is legal because the structure's name is an "identifier"! No, the restriction only applies to the LHS. The list construction is on the RHS. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Get a Joke in Python

2021-10-28 Thread Greg Ewing
On 29/10/21 11:34 am, Chris Angelico wrote: On Fri, Oct 29, 2021 at 7:31 AM Mostowski Collapse wrote: QA engineer walks into a bar. Orders a beer. Orders 0 beers. Orders 9 beers. Orders a lizard. Orders -1 beers. Orders a sfdeljknesv. Orders 1 пиво and is served a пиво. QA engin

Re: Getting Directory of Command Line Entry Point For Packages

2021-11-12 Thread Greg Ewing
On 13/11/21 10:51 am, Abdur-Rahmaan Janhangeer wrote: ow do i get the path from which miaw the command is called from? What exactly do you mean by "called from"? If you want the user's working directory, os.getcwd() will give you that. If you want something else, you'll have to give us more d

Re: Getting Directory of Command Line Entry Point For Packages

2021-11-13 Thread Greg Ewing
On 13/11/21 7:23 pm, Abdur-Rahmaan Janhangeer wrote: os.getcwd is giving the path of site-packages and not the directory from which the command is run from. Something must be changing the working directory before getcwd is called. Once that happens there's no way I know of to find out what it w

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Greg Ewing
On 21/11/21 2:18 pm, Grant Edwards wrote: My recollection is that it was quite common back in the days before FP hardware was "a thing" on small computers. CPM and DOS compilers for various languages often gave the user a choice between binary FP and decimal (BCD) FP. It's also very common for

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-21 Thread Greg Ewing
On 22/11/21 4:58 am, Grant Edwards wrote: Yep, IIRC, it was a 4 bit processor because 4 bits is what it takes to represent one decimal digit. That was the Saturn, first used in the HP-71B. The original architecture (known as the "Nut")was weirder than that. It operated serially on 56 bit words

Re: Negative subscripts

2021-11-26 Thread Greg Ewing
On 2021-11-26 11:17 AM, Frank Millman wrote: Are there any other techniques anyone can suggest, or is the only alternative to use if...then...else to cater for y = 0? x[:-y or None] Seems to work: >>> l ['a', 'b', 'c', 'd', 'e'] >>> def f(x): return l[:-x or None] ... >>> f(3) ['a', 'b'] >>>

Re: problem reading a CSV file

2021-12-13 Thread Greg Ewing
On 14/12/21 7:07 am, MRAB wrote: It's difficult to say what the problem is when you haven't given us the code! Note: Attachments do not make it to this list. You will need to insert the code into the message as text. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Installation problems

2021-12-13 Thread Greg Ewing
On 13/12/21 8:25 pm, Cristiano Loro wrote: In production I performed a custom installation defining "for all users", but the modules are placed elsewhere and this is perhaps the problem. How can I put the modules in the correct folder? How are you installing the modules? Are you doing it with

Re: What to write or search on github to get the code for what is written below:

2022-01-13 Thread Greg Ewing
On 14/01/22 12:23 pm, dn wrote: On 14/01/2022 09.48, Dennis Lee Bieber wrote: On Thu, 13 Jan 2022 15:22:50 -0500, Dennis Lee Bieber declaimed the following: Talking to myself in public again... Bad habit... Recommend that you not start any arguments then - they will be unwinnable!

Re: Writing a string with comma in one column of CSV file

2022-01-16 Thread Greg Ewing
On 17/01/22 4:18 am, Mats Wichmann wrote: the convention for Excel, which is usually the reason people are using csv, is you can enclose the entire comma-containing field in "quote marks" (afaik it must be double-quote). And to include a double quote in a field, quote the field and double the d

Re: Puzzling behaviour of Py_IncRef

2022-01-20 Thread Greg Ewing
On 20/01/22 12:09 am, Chris Angelico wrote: At this point, the refcount has indeed been increased. return self; } And then you say "my return value is this object". So you're incrementing the refcount, then returning it without incrementing the refcount. Your code is actually

Re: Puzzling behaviour of Py_IncRef

2022-01-26 Thread Greg Ewing
The convention for refcounting in CPython is that a function takes borrowed references as arguments and returns a new reference. The 'self' argument passed in is a borrowed reference. If you want to return it, you need to create a new reference by increfing it. So what you have written is just t

Re: Pypy with Cython

2022-02-03 Thread Greg Ewing
On 4/02/22 5:07 am, Albert-Jan Roskam wrote: On Feb 3, 2022 17:01, Dan Stromberg wrote: What profiler do you recommend If it runs for that long, just measuring execution time should be enough. Python comes with a "timeit" module to help with that, or you can use whatever your OS provi

Re: Best way to check if there is internet?

2022-02-07 Thread Greg Ewing
On 8/02/22 8:51 am, Chris Angelico wrote: Some day, we'll have people on Mars. They won't have TCP connections - at least, not unless servers start supporting connection timeouts measured in minutes or hours - but it wouldn't surprise me if some sort of caching proxy system is deployed. Or the

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Greg Ewing
On 21/02/22 6:27 am, Abdur-Rahmaan Janhangeer wrote: Well Python deliberately throws an exception if we do not pass in a function name. Just wanted to know why it should. As the above case is a 100% pure anonymous function. The syntax for a function definition is defined in the grammar as requi

Re: Threading question .. am I doing this right?

2022-02-25 Thread Greg Ewing
On 25/02/22 1:08 am, Robert Latest wrote: My question is: Is this a solid approach? Am I forgetting something? I can see a few of problems: * If more than one thread calls get_data() during the initial cache filling, it looks like only one of them will wait for the thread -- the others will sk

Re: Best way to check if there is internet?

2022-02-25 Thread Greg Ewing
On 26/02/22 11:22 am, Chris Angelico wrote: What's the best language for swearing in? Ah, that one I can't help you with, although I've heard good things about French. :) Russian seems to be quite good for it too, judging by certain dashcam footage channels. -- Greg -- https://mail.python.org/

Re: SQLAlchemy: JSON vs. PickleType vs. raw string for serialised data

2022-02-28 Thread Greg Ewing
On 1/03/22 6:13 am, Albert-Jan Roskam wrote: I think you need a BLOB.  https://docs.sqlalchemy.org/en/14/core/type_basics.html#sqlalchemy.types.LargeBinary That won't help on its own, since you still need to choose a serialisation format to store in the blob. I'd be inclined to use JSO

Re: Behavior of the for-else construct

2022-03-03 Thread Greg Ewing
On 4/03/22 1:55 pm, Chris Angelico wrote: It's much better to treat arguments as a vector of strings rather than a single string, as the start command tries to. It would be nice if you could, but as I understand it, Windows always passes arguments to a program as a single string, and then it's

Re: Execute in a multiprocessing child dynamic code loaded by the parent process

2022-03-06 Thread Greg Ewing
On 7/03/22 9:36 am, Martin Di Paola wrote: It *would* be my fault if multiprocessing.Process fails only because I'm loading the code dynamically. I'm not so sure about that. The author of the plugin knows they're writing code that will be dynamically loaded, and can therefore expect the kind of

Re: Reportlab / platypus bug?

2022-03-15 Thread Greg Ewing
On 16/03/22 2:20 am, Les wrote: I tried to subscribe (twice), but never got the confirmation email. Checked in the spam folder too, but it is nowhere to be found. Is there any chance your email provider has some kind of quarantine system separate from your spam folder? The University of Canter

Re: Best practice for caching hash

2022-03-16 Thread Greg Ewing
On 16/03/22 6:58 pm, Chris Angelico wrote: And Python's own integers hash to themselves, > which isn't what I'd call "widely distributed", but which > works well in practice. Not exactly, they seem to be limited to 60 bits: >>> hex(hash(0xfff)) '0xfff' >>> hex(hash(0x1f

Re: Reducing "yield from" overhead in recursive generators

2022-03-18 Thread Greg Ewing
On 19/03/22 9:40 am, Rathmann wrote: The other challenge/question would be to see if there is a way to implement this basic approach with lower overhead. My original implementation of yield-from didn't have this problem, because it didn't enter any of the intermediate frames -- it just ran down

Re: convenience

2022-03-22 Thread Greg Ewing
On 23/03/22 7:00 am, Avi Gross wrote: But are there costs or even errors if you approach an inner part of an object directly? Can there be dunder methods not invoked that would be from the standard approach? What kind of inadvertent errors can creep in? The attribute could be a property that r

Re: Reducing "yield from" overhead in recursive generators

2022-03-22 Thread Greg Ewing
On 23/03/22 11:44 am, Rathmann wrote: So that sounds like the original CPython implementation had an O(depth) component, but with a lower constant factor than the current version? Yes, but so much lower that I would expect it to be unmeasurable. -- Greg -- https://mail.python.org/mailman/list

Re: What to do to correct the error written below:

2022-04-12 Thread Greg Ewing
On 12/04/22 2:28 am, Peter Pearson wrote: By looping over elements in "books" and incrementing counter i, which is used as an index both for "books" and for "students", you will produce an error whenever the number of books exceeds the number of students. More fundamentally, it assumes there is

Re: Python app on a Mac

2022-04-15 Thread Greg Ewing
On 15/04/22 10:51 pm, Alan Gauld wrote: Does anyone know how to launch a Python program from the desktop without a Terminal window (or at least with an iconified one!) Does it require Applescript or somesuch? The easiest and most reliable way is probably to use Automator with a Run Shell Script

Re: FULLSCREEN and DOUBLEBUF

2018-06-12 Thread Greg Ewing
Paul St George wrote: I had considered meddling with the config.txt to try to enable* HWSURFACE but from what you say, this is unnecessary. I don't really have much idea what effect HWSURFACE would have, if any. It will certainly depend a lot on your hardware and drivers. My suggestion would b

Re: low-level csv

2019-11-17 Thread Greg Ewing
On 18/11/19 9:30 am, Dave Cinege wrote: The few times I looked at CSV module it never looked useful to me. I seem to use shlex for everything. For example: def csv_split (s): lex = shlex.shlex(s, posix=True) lex.whitespace_split = True lex.whitespace = ',' return list(lex)

Re: Python Resources related with web security

2019-11-27 Thread Greg Ewing
On 27/11/19 10:54 am, Mr. Gentooer wrote: why would I be a troll? I have never used usenet. I am honestly and genuinely curious. The reason people are asking is that wanting a manual on how to search the Web is a bit like wanting a manual on how to walk. Most people pick it up by watching othe

Re: Aw: Re: stuck on time

2019-12-08 Thread Greg Ewing
On 9/12/19 7:47 am, RobH wrote: I wanted it to work as is, like it did for the author, without changing anything. So why should I now start to learn how python works. There are many, many reasons a piece of code could work in one environment but not another. Figuring out why requires actual u

Re: stuck on time

2019-12-08 Thread Greg Ewing
On 9/12/19 7:46 am, Dennis Lee Bieber wrote: Minecraftia appears to be a monospaced font meant to look like the character set of old 8-bit gaming systems from the 80s. From the name, it's probably mean to resemble the font in Minecraft. As used in the game it's not actually monospaced,

Re: python 2 to 3 converter

2019-12-08 Thread Greg Ewing
On 8/12/19 9:30 pm, songbird wrote: wouldn't it make more sense to just go back and fix the converter program than to have to manually convert all this python2 code? Anything that isn't already fixed by 2to3 is probably somewhere between very difficult and impossible to fix using an automate

Re: Python3 - How do I import a class from another file

2019-12-08 Thread Greg Ewing
On 9/12/19 6:28 am, R.Wieser wrote: Are you sure there's a difference between classes and functions here? Yes, quite sure. And we're even more sure that there isn't. :-) Try it with a test module containing a class definition, a function definition and some top-level code that does somethin

Re: Python3 - How do I import a class from another file

2019-12-09 Thread Greg Ewing
On 9/12/19 9:15 pm, R.Wieser wrote: To be honest, I was not aware/did not assume that I could delete a class definition that way (I even find it a bit weird, but as I'm a newbie in regard to Python that does not say much). Python is very dynamic. The class statement is actually an executable st

Re: Python3 - How do I import a class from another file

2019-12-10 Thread Greg Ewing
On 10/12/19 9:45 pm, R.Wieser wrote: In my case deleting the instance was needed to release its hold on something that was taken when the instance was initialised (in my case a GPIO pin on a Raspberry Pi). I did not even think of garbage collection. In that case, it was only working by accid

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Greg Ewing
On 11/12/19 7:47 am, R.Wieser wrote: what happens when the reference becomes zero: is the __del__ method called directly (as I find logical), or is it only called when the garbage collector actually removes the instance from memory (which Chris thinks what happens) ? In CPython, these are the s

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Greg Ewing
On 12/12/19 3:50 am, R.Wieser wrote: I was rather clear about what my used version of Python was-and-is. I have no idea why that was ignored. :-( I think we've all been talking at cross purposes for a while. What I meant to say originally was that you were relying on an implementation detail

Re: Python3 - How do I import a class from another file

2019-12-11 Thread Greg Ewing
On 12/12/19 2:17 pm, Python wrote: I was very impressed back in the day when the with statement and context manager protocol appeared in Python. I've always wondered from what language(s) it was borrowed from It was partly inspired by the RAII pattern often used in C++, but as far as I know, al

Re: Python3 - How do I import a class from another file

2019-12-13 Thread Greg Ewing
On 14/12/19 5:13 pm, boB Stepp wrote: is it true that CPython itself is free to implement these behaviors differently in its own future versions? Yes. That's why it's not a good idea to rely on them even if you only intend to run your code on CPython. -- Greg -- https://mail.python.org/mailman

Re: Cython, producing different modules from the same .pyx

2019-12-19 Thread Greg Ewing
On 20/12/19 2:16 am, Lele Gaifax wrote: My first approach has been duplicating the Extension() entry in the setup.py(*), changing the first argument (that is, the name of the module). Although that did produce the alternative binary module, it could not be loaded because it contains the wrong PyI

Re: How to extend an object?

2019-12-20 Thread Greg Ewing
On 21/12/19 1:59 am, Stefan Ram wrote: I would like to add a method to a string. This is not possible in Python? It's not possible. Built-in classes can't have methods added to them. You can define your own subclass of str and give it whatever methods you want. But in your case: for

Re: Friday Finking: Source code organisation

2019-12-28 Thread Greg Ewing
On 29/12/19 11:35 am, DL Neil wrote: if our mythical collection of module-functions has an internal-reference, eg b() requires a(), then function a() MUST exist, ie be defined, 'before' function b(). Not true in Python -- a() must exist by the time b() is run, but they can be written in the fi

Re: Friday Finking: Source code organisation

2019-12-28 Thread Greg Ewing
On 29/12/19 11:49 am, Chris Angelico wrote: "Define before use" is a broad principle that I try to follow, even when the code itself doesn't mandate this. I tend to do this too, although it's probably just a habit carried over from languages such as Pascal and C where you have to go out of your

Re: Friday Finking: Source code organisation

2019-12-30 Thread Greg Ewing
On 31/12/19 3:47 am, Barry Scott wrote: "define before use" is basically email top-posting for code isn't it? It means that the first things that you read in a module are the least interesting. That's not a big problem for top-level code, since you can easily scroll down to the bottom of the

Re: Python, Be Bold!

2020-01-02 Thread Greg Ewing
It looks like what the OP is after already exists: https://docs.python.org/3/library/zipapp.html "This module provides tools to manage the creation of zip files containing Python code, which can be executed directly by the Python interpreter." -- Greg -- https://mail.python.org/mailman/list

Re: A small quiz

2020-01-03 Thread Greg Ewing
On 4/01/20 5:41 am, Alan Bawden wrote: So I was looking for a predefined object from the standard library that already /is/ an iterator (with no need to use »iter«). Why are you so intent on introducing either next() or iter() to beginning students? I'd have thought they were somewhat

Re: Python, Be Bold!

2020-01-03 Thread Greg Ewing
On 3/01/20 3:31 pm, Abdur-Rahmaan Janhangeer wrote: But, this proposal is not about native executables. It's about a .jar like executable. You can pass a zip file with a .pyz extension to the python interpreter and it will look for a __main__.py file and run it. That seems to give you all th

Re: Extension type inherit from Python int

2020-01-16 Thread Greg Ewing
On 17/01/20 11:12 am, Random832 wrote: pure-python types that derive from int place __dict__ at the end of the object, I don't know if it's possible for you to do the same with the fields you intend to add (for some reason it isn't done with __slots__), but if all else fails you could do the sam

Re: IDLE, TCP/IP problem.

2020-01-16 Thread Greg Ewing
On 16/01/20 10:06 pm, Muju's message wrote: “IDLE cannot bind to a TCP/IP port, which is necessary to communicate with its Python execution server. This might be because no networking is installed on this computer. There might be firewall settings or anti-virus software preventing the port fro

Re: Sandboxing eval()

2020-01-21 Thread Greg Ewing
On 21/01/20 6:57 pm, mus...@posteo.org wrote: If I start with empty global and local dicts, and an empty __builtins__, and I screen the input string so it can't contain the string "import", is it still possible to have "targeted" malicious attacks? Yes. Python 3.7.3 (default, Apr 8 2019, 22:2

Re: Nested Loop Code Help

2020-01-26 Thread Greg Ewing
On 27/01/20 4:15 am, ferzan saglam wrote: for x in range ( 0, 10): stars = 'x' count = 0 By the way, this 'for' loop is unnecessary. The end result is just to give initial values to three names. You don't need a loop at all for that, just three assignment statements.

Re: How to read the original data line by line from stdin in python 3 just like python 2?

2020-01-28 Thread Greg Ewing
On 29/01/20 6:27 pm, Peng Yu wrote: Suppose that I use this to read from stdin. But `line` contains decoded data in python 3. In python 2, it contains the original data. What is the best way to get the original data in python 3? Read from stdin.buffer, which is a stream of bytes. -- Greg -- ht

Re: JavaScript's void operator in Python?

2020-02-02 Thread Greg Ewing
On 3/02/20 3:38 am, Stefan Ram wrote: void( ( print( 2 ), print( 3 ))) If the functions you're calling all return None, you can do this: >>> print(2); print(3) 2 3 -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Asyncio question

2020-02-21 Thread Greg Ewing
On 21/02/20 7:59 pm, Frank Millman wrote: My first attempt was to create a background task for each session which runs for the life-time of the session, and 'awaits' its queue. It works, but I was concerned about having a lot a background tasks active at the same time. The whole point of asyn

Re: encapsulating a global variable

2020-02-25 Thread Greg Ewing
On 26/02/20 4:06 am, BlindAnagram wrote: My interest in this stems from wanting to keep the dictionary only available to the function that uses it and also a worry about being called from threaded code. Doing this won't make any difference to the way threaded code behaves. Threading problems ne

Re: encapsulating a global variable

2020-02-25 Thread Greg Ewing
On 26/02/20 3:56 am, BlindAnagram wrote: Does that not have the advantage of preventing the global directory being directly fiddled with elsewhere? That depends on what you mean by "prevent". There is nothing to stop any code from directly accessing the .seen attribute of the class. It might m

Re: `async def` breaks encapsulation?

2020-03-17 Thread Greg Ewing
On 4/03/20 12:52 pm, Marco Sulla wrote: Why can't an asynchronous coroutine be simply a coroutine that has an `async` or an `await` in its code, without `async` in the signature? That wouldn't help as much as you seem to think. You still need to use 'await' whenever you call a coroutine, so swi

<    1   2   3   4   5   >