Re: Proposed new syntax

2017-08-16 Thread jmp
On 08/10/2017 04:28 PM, Steve D'Aprano wrote: Every few years, the following syntax comes up for discussion, with some people saying it isn't obvious what it would do, and others disagreeing and saying that it is obvious. So I thought I'd do an informal survey. What would you expect this syntax

Re: repeat until keypressed

2017-05-29 Thread jmp
On 05/29/2017 03:14 PM, Poul Riis wrote: In good old pascal there was this one-liner command: repeat until keypressed Apparently there is no built-in analogue for that in python. I have explored several different possibilities (pyglet, keyboard, curses, ginput (from matplotlib) and others) but

Re: Bigotry and hate speech on the python mailing list

2017-04-20 Thread jmp
On 04/18/2017 02:48 AM, Ethan Furman wrote: On 04/17/2017 03:23 PM, Ben Finney wrote: So I will continue to treat all those topics equally: peripheral comments on beliefs are just part of respectful human discourse, so long as I'm respectful of the people who may hold such beliefs. So you're o

Re: Swiss Ephemeris

2017-04-12 Thread jmp
On 04/10/2017 07:29 AM, Deborah Swanson wrote: Fully recognizing that most of what you wrote was tongue-in-cheek, I just want to say that regardless of the wonders of modern medicine, it's a pity they learn so little about successful medicines other than their own. In other academic scientific di

Re: Temporary variables in list comprehensions

2017-01-10 Thread jmp
On 01/09/2017 04:53 AM, Steven D'Aprano wrote: Suppose you have an expensive calculation that gets used two or more times in a loop. The obvious way to avoid calculating it twice in an ordinary loop is with a temporary variable: result = [] for x in data: tmp = expensive_calculation(x)

Re: Enum with only a single member

2017-01-10 Thread jmp
On 01/10/2017 05:43 AM, Steven D'Aprano wrote: Is it silly to create an enumeration with only a single member? That is, a singleton enum? Don't think so, for the same reason that lists with one element make sense. def ham(arg): if isinstance(arg, MarxBros) or arg is Unique.FOO:

Re: How to use two threads (GUI and backend)

2016-10-27 Thread jmp
On 10/27/2016 02:55 PM, Chris Angelico wrote: On Thu, Oct 27, 2016 at 11:33 PM, jmp wrote: On 10/27/2016 01:43 PM, Chris Angelico wrote: Blocked threads don't consume CPU time. Why would they? ChrisA Agreed. My point being that a blocked thread achieve nothing, except parallelism

Re: How to use two threads (GUI and backend)

2016-10-27 Thread jmp
On 10/27/2016 01:43 PM, Chris Angelico wrote: Blocked threads don't consume CPU time. Why would they? ChrisA Agreed. My point being that a blocked thread achieve nothing, except parallelism, i.e. other threads can be processed. To be more specific, if you compute factorial(51354) in a thre

Re: How to use two threads (GUI and backend)

2016-10-27 Thread jmp
On 10/27/2016 12:22 PM, pozz wrote: Anyway I don't like this approach, because the main (and single) thread should check in_waiting every X milliseconds. If X is too high, I could wait for the answer even if it is already ready in the input buffer. If X is too low, the application consumes a lot

Re: How to use two threads (GUI and backend)

2016-10-26 Thread jmp
On 10/26/2016 02:45 PM, pozz wrote: Il 26/10/2016 13:16, jmp ha scritto: [...] I suggest you write a GUI that make synchronouscalls to a remote application, if possible. If the remote app is in python, you have access to remote protocols already written for you, Pyro is one of them, you can

Re: How to use two threads (GUI and backend)

2016-10-26 Thread jmp
On 10/26/2016 12:22 PM, pozz wrote: Il 26/10/2016 09:13, pozz ha scritto: > [...] When the user press Start button (the pressed handler is in the GUI class): self.comm_active = True threading.Thread(target=self.comm_thread).start() The backend thread is: def comm_thread(self): whil

Re: default argument value is mutable

2016-10-07 Thread jmp
On 10/07/2016 03:45 PM, ast wrote: "jmp" a écrit dans le message de news:mailman.210.1475844513.30834.python-l...@python.org... On 10/07/2016 02:07 PM, ast wrote: "jmp" a écrit dans le message de news:mailman.209.1475841371.30834.python-l...@python.org... On 10/07/2

Re: default argument value is mutable

2016-10-07 Thread jmp
On 10/07/2016 02:07 PM, ast wrote: "jmp" a écrit dans le message de news:mailman.209.1475841371.30834.python-l...@python.org... On 10/07/2016 01:38 PM, Daiyue Weng wrote: So the rule of thumb for default argument value is "No mutable" Cheers, It can be used to

Re: default argument value is mutable

2016-10-07 Thread jmp
On 10/07/2016 01:38 PM, Daiyue Weng wrote: Hi, I declare two parameters for a function with default values [], def one_function(arg, arg1=[], arg2=[]): PyCharm warns me: Default argument value is mutable, what does it mean? and how to fix it? cheers You'll run into this bug def foo(a=[])

Re: User Interface Suggestions? (newbie)

2016-10-06 Thread jmp
On 10/05/2016 11:33 PM, Chris Angelico wrote: On Thu, Oct 6, 2016 at 8:19 AM, Beverly Howard wrote: Thanks for the responses... appreciated. print("value value data data data", end="\r") << That makes sense, but it also seems to suggest that there is no other way to position the cursor pri

Re: Is there a way to change the closure of a python function?

2016-09-27 Thread jmp
On 09/27/2016 04:01 PM, Peng Yu wrote: Hi, In many other functional language, one can change the closure of a function. Is it possible in python? http://ynniv.com/blog/2007/08/closures-in-python.html If I understood correctly your link: (untested) def func(x): return x+func.y func.y = 1

Re: Nested for loops and print statements

2016-09-26 Thread jmp
On 09/26/2016 06:54 PM, Cai Gengyang wrote: What is a tab and what is a space in python and what's the difference ? Which piece of code is indented with tabs and which one is indented with spaces ? Please do not top-post in this list. Put your text after the message you quote. Tabs and sp

Re: Nested for loops and print statements

2016-09-26 Thread jmp
On 09/26/2016 05:25 PM, Cai Gengyang wrote: I just wanted to note that sometimes the code works, sometimes it doesn't. (even though both are exactly the same code) ... Weird , dum dum dum for row in range(10): for column in range(10): print("*",end="") SyntaxError:

Re: sphinx (or other means to document python)

2016-09-26 Thread jmp
On 09/25/2016 03:20 AM, chitt...@uah.edu wrote: On Sunday, September 11, 2016 at 3:56:36 PM UTC-5, chit...@uah.edu wrote: (about being frustrated with sphinx) I _remain_ frustrated - even as I finally figured out how to use it (thanks to a complete example from a friend) sphinx is very picky a

Re: How to split value where is comma ?

2016-09-12 Thread jmp
On 09/11/2016 02:12 PM, Chris Angelico wrote: On Thu, Sep 8, 2016 at 7:27 PM, Joaquin Alzola wrote: I have worked places where they put stuff like this at the bottom of emails sent to the person sitting next to them :) -raising entropy-ly yrs- Robin Becker Cannot do anything about it. It is

Re: [Python-ideas] Inconsistencies

2016-09-12 Thread jmp
On 09/12/2016 03:11 AM, Chris Angelico wrote: On Mon, Sep 12, 2016 at 6:30 AM, Sven R. Kunze wrote: I could not agree more with what you said above, so I hope this will put the discussion in better perspective, especially when people here trying to be overly absolute in their views (which was

Re: What you can do about legalese nonsense on email

2016-09-09 Thread jmp
On 09/08/2016 10:52 PM, Ben Finney wrote: Joaquin Alzola writes: That's not true; you can do more than we. Added by the MTA of the company not by my client. Right. So, here are things you can do (that we cannot) about this: * Complain, with reasoned explanation, to the management respon

Re: Suggestions to improve a code

2016-09-09 Thread jmp
On 09/06/2016 04:55 PM, GP wrote: I have a list: shelves2 =[{'Part No': '1', 'Length': 610.0, 'Width': 50.0}, {'Part No': '2', 'Length': 2319.0, 'Width': 465.0 }, {'Part No': '3', 'Length': 5.0,'Width': 465.0}] The length of shelf is calculated as follows: 1. Calculate the max

Re: listdir

2016-09-05 Thread jmp
On 09/05/2016 05:41 PM, Smith wrote: Il 05/09/2016 17:34, Rustom Mody ha scritto: So what do you get when you replace the if-else with a simple: print(file) a = input("search for files with the extension .py into directory: ") for file in os.listdir(a): if file.endswith(".py"):

Re: listdir

2016-09-05 Thread jmp
On 09/05/2016 05:27 PM, Smith wrote: Hello to all, I wanted to know because even though the files are present on the directory I write input gives me "file not found". You can help me? Thank you a = input("Digita la directory dove vuoi trovare i file py: ") for file in os.listdir(a): if fi

Re: Namespaces are one honking great idea

2016-07-04 Thread jmp
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 re

Re: Namespaces are one honking great idea

2016-07-04 Thread jmp
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"

Re: Summary grid

2016-06-22 Thread jmp
On 06/22/2016 04:46 PM, Jignesh Sutar wrote: Say I have list of data as given in the example code below, I want to find all the unique categories (alphabetic letters) and unique IDs (numbers) and then produce a summary grid as manually entered in the "results". How could I code this? Many thanks

Re: OT: limit number of connections from browser to my server?

2016-05-17 Thread jmp
On 05/16/2016 09:31 PM, Grant Edwards wrote: On 2016-05-16, jmp wrote: Have you considered upgrading the device with a recent CPU ? Or is it completely out of the picture ? Not an option. We have to continue to support devices that are in the field. The newer models that are coming out

Re: OT: limit number of connections from browser to my server?

2016-05-16 Thread jmp
On 05/16/2016 06:06 PM, Grant Edwards wrote: This is not Python specific, though I'm turning to Python to do some experimentation and to try to prototype a solution. Is there any way to limit the number of connections a browser uses to download a web page? Browser writers seems to assume that a

Re: What should a decorator do if an attribute already exists?

2016-05-16 Thread jmp
se an exception, otherwise I don't know :o) It seems to me that over-writing silently (or not) may lead to bugs difficult to spot. jmp -- https://mail.python.org/mailman/listinfo/python-list

Re: Client support automation and self service

2016-05-03 Thread jmp
On 05/03/2016 10:02 AM, musoke wilson wrote: Hi Guys Currently working with a team to automate business operations and client support for a small enterprise. Key requirements: Clients to register, log queries and initiate service request through The Web and/or Mobile APP Clear tracking by the

Re: Enum questions.

2016-04-13 Thread jmp
On 04/13/2016 12:12 PM, Antoon Pardon wrote: I have been looking at the enum documentation and it seems enums are missing two features I rather find important. 1) Given an Enum value, someway to get the next/previous one 2) Given two Enum values, iterate over the values between them. D

Re: Encapsulation in Python

2016-03-11 Thread jmp
On 03/10/2016 02:41 PM, Ben Mezger wrote: Hi all, I've been studying Object Oriented Theory using Java. Theoretically, all attributes should be private, meaning no one except the methods itself can access the attribute; public class Foo { private int bar; ... Normally in Java, we wou

Re: context managers inline?

2016-03-11 Thread jmp
On 03/10/2016 07:59 PM, Neal Becker wrote: sohcahto...@gmail.com wrote: On Thursday, March 10, 2016 at 10:33:47 AM UTC-8, Neal Becker wrote: Is there a way to ensure resource cleanup with a construct such as: x = load (open ('my file', 'rb)) Is there a way to ensure this file gets closed?

Re: Pythonic love

2016-03-08 Thread jmp
On 03/08/2016 05:49 PM, justin walters wrote: Correct me if I'm wrong, but don't python generators usually use the yield statement so they can be used in list comprehensions? Hello, Please don't top post. Generator expressions are different from generator functions. They are both generators

Re: Pythonic love

2016-03-08 Thread jmp
On 03/07/2016 11:51 PM, Fillmore wrote: learning Python from Perl here. Want to do things as Pythonicly as possible. I am reading a TSV, but need to skip the first 5 lines. The following works, but wonder if there's a more pythonc way to do things. Thanks ctr = 0 with open(prfile,mode="rt",enc

Re: How to get which attribute causes the AttributeError except inspecting strings?

2016-03-07 Thread jmp
On 03/07/2016 09:46 AM, ZhangXiang wrote: In python3, when I write code like this: try: fields = [getattr(Product, field) for field in fields.split(',')] except AttributeError as e: raise HTTPError(...) I want to raise a new type of error giving a string telling the user which attrib

Re: Suggested datatype for getting latest information from log files

2016-02-11 Thread jmp
On 02/11/2016 07:07 PM, ltomassm...@gmail.com wrote: I thought a dictionary would be a good idea because of the key restrictions ensuring no duplicates, so the data would always update - However because they are unordered and I need to do some more processing on the data afterwards I'm having

Re: Changing logging level only for my code?

2016-02-08 Thread jmp
On 02/08/2016 12:29 PM, egarr...@gmail.com wrote: I am using the "logging" module for my own package, but changing the level from "INFO" to "DEBUG" enables debugging statements from third-party libraries as well. How can I avoid them? Here is the code I am using: import logging lo

Re: class attribute

2016-01-28 Thread jmp
On 01/28/2016 02:15 PM, ast wrote: hello Here is a class from django framework from django.db import models class Article(models.Model): titre = models.CharField(max_length=100) auteur = models.CharField(max_length=42) contenu = models.TextField(null=True) date = models.DateT

Re: Writing a stream of bytes

2016-01-15 Thread jmp
On 01/15/2016 05:08 PM, Tim Chase wrote: [sorry, toddler on my lap clicked before I could type] import struct with open('toto', 'wb') as f: f.write(struct.pack('<4B', *[1,2,3,4])) This one does what you want. The problem resides in your check: I always end up with the following bytes on f

Writing a stream of bytes

2016-01-15 Thread jmp
Hi pyple ! I'd like to write a stream of bytes into a file. I'd like to use the struct (instead of bytearray) module because I will have to write more than bytes. let's say I want a file with 4 bytes in that order: 01 02 03 04 None of these work: import struct with open('toto', 'wb') as

Re: Newbie XML problem

2015-12-22 Thread jmp
On 12/22/2015 05:29 AM, KP wrote: From my first foray into XML with Python: I would like to retrieve this list from the XML upon searching for the 'config' with id attribute = 'B' config = {id: 1, canvas: (3840, 1024), comment: "a comment", {id: 4, gate: 3, (0,0, 1280, 102

Re: Try: rather than if :

2015-12-15 Thread jmp
On 12/14/2015 11:38 PM, Vincent Davis wrote: In the code below try is used to check if handle has the attribute name. It seems an if statement could be used. Is there reason one way would be better than another? def write_header(self): handle = self.handle try: handle.write("#

Re: filter a list of strings

2015-12-03 Thread jmp
On 12/03/2015 10:27 AM, c.bu...@posteo.jp wrote: I often saw constructions like this x for x in y if ... But I don't understand that combination of the Python keywords (for, in, if) I allready know. It is to complex to imagine what there really happen. I understand this for x in y: if

Re: teacher need help!

2015-10-19 Thread jmp
On 10/19/2015 03:42 PM, Storey, Geneva wrote: Our technician will be here this morning to take a look. I'll let you know what we find. Thanks again, Geneva Storey import turtle print turtle.__file__ may help you find the offending file. jm -- https://mail.python.org/mailman/listinfo/pyt

Re: Create a .lua fle from Python

2015-10-02 Thread jmp
On 10/01/2015 09:12 PM, Steven D'Aprano wrote: On Wed, 30 Sep 2015 07:21 pm, jmp wrote: Is Ariel's xml file user-supplied? If so, how does your suggestion prevent the resulting lua script from executing arbitrary code? It does not. Like it doesn't fulfill the milli

Re: Create a .lua fle from Python

2015-09-30 Thread jmp
On 09/29/2015 07:28 PM, Peter Otten wrote: jmp wrote: import bs4 import jinja2 xml = """ BuenosAires 30 Seatle 25 """ lua_template = """ cities_temps ={ {%- for city, temp i

Re: Create a .lua fle from Python

2015-09-29 Thread jmp
On 09/28/2015 11:41 PM, Ariel Argañaraz wrote: Hi, This is my first post, I would like to know if a library that can help me with this. I want to parse a XML fle with Python and save the data into a Lua table called for example "newTable", then I want to create a "table.lua" fle with the "newTa

Re: Question re class variable

2015-09-29 Thread jmp
On 09/29/2015 01:02 PM, jmp wrote: class GameObject: @property def id(self): return id(self) #use the builtin id function print GameObject().id Cheers, JM I should add that until you don't serialize your object you're fine. If you need to serialize it, you may want

Re: Question re class variable

2015-09-29 Thread jmp
On 09/29/2015 11:27 AM, ple...@gmail.com wrote: I have a perplexing problem with Python 3 class variables. Your problem is that when assigning values to your class attribute, you are actually creating a instance attribute. class Foo: bar = "I'm a class attribute" def __init__(self):

Re: Idiosyncratic python

2015-09-24 Thread jmp
On 09/24/2015 04:26 PM, Ian Kelly wrote: On Thu, Sep 24, 2015 at 8:07 AM, jmp wrote: result = getResult() For the later, the original weird form come from a C habit to allocate returned structures within the caller and provide a pointer to it so the function can fill the data in, otherwise

Re: Python, convert an integer into an index?

2015-09-24 Thread jmp
On 09/24/2015 03:45 PM, paul.hermeneu...@gmail.com wrote: >> I'm suprised. Why not just: >> >> list(str(results)) >> >> In other words, is there something else the list constructor should do >> with a string other than convert it to a list? >> > The OP wanted the result to be a list of in

Re: Idiosyncratic python

2015-09-24 Thread jmp
On 09/24/2015 02:50 PM, paul.hermeneu...@gmail.com wrote: > A lot of our in base weird python comes from heavily C-wired people: > > The classic > for i in range(len(alist)): > print alist[i] > > with its twin brother > > i=0 > while i < len(alist): > print alist[i] > i += 1 >

Re: Idiosyncratic python

2015-09-24 Thread jmp
On 09/24/2015 08:02 AM, Steven D'Aprano wrote: I was looking at an in-house code base today, and the author seems to have a rather idiosyncratic approach to Python. For example: for k, v in mydict.items(): del(k) ... instead of the more obvious for v in mydict.values(): ...

Re: True == 1 weirdness

2015-09-21 Thread jmp
On 09/16/2015 02:53 PM, Jussi Piitulainen wrote: But now I expect to see a long thread about whether chained comparisons are a natural thing to have in the language. Nice forecast by the way. JM -- https://mail.python.org/mailman/listinfo/python-list

Re: True == 1 weirdness

2015-09-16 Thread jmp
On 09/16/2015 02:16 PM, Blake T. Garretson wrote: 1 in {1:1} == 1 #test2 The second test yield False, because True does not equal 1, apparently. Fair enough. No, it yields False because {1:1} == 1 is false. Test 2 looks actually like (1 in {1:1}) and ({1:1} == 1). Which in your example

Re: From logging to files to a better solution: syslog, Sentry, Logstash, ....

2015-09-15 Thread jmp
On 09/15/2015 11:35 AM, Thomas Güttler wrote: Yes, I could do it this way. But somehow I am not happy with this solution. I think the filtering should be outside of python. [snip] Can you understand my concerns? Thomas Güttler No, not really. I showed you how it can be done in p

Re: From logging to files to a better solution: syslog, Sentry, Logstash, ....

2015-09-11 Thread jmp
On 09/11/2015 09:22 AM, Thomas Güttler wrote: I want INFO to be logged and stored on the remote host. Therefore I must not filter INFO messages. I don't want to pull INFO messages over the VPN. Ergo, the filtering at Python level does not help in my use case. Or I am missing something. Proba

Re: issue while doing pexpect ssh

2015-09-08 Thread jmp
On 09/08/2015 03:57 PM, Chris Angelico wrote: On Tue, Sep 8, 2015 at 9:37 PM, wrote: Some where i am missing simple logic :) = child = pexpect.spawn('ssh hari@hostname') child.logfile = sys.stdout child.expect('hari\'s Password: ') = getting error as follows: child.e

Re: How to compare lists

2015-09-01 Thread jmp
On 09/01/2015 07:08 AM, Jahn wrote: 1. How can I save 256 lists, each list has 32 values( hexadecimal numbers) 2. How to compare the saved lists with another 256 lists ( that are read online and have the same structure as the list one)? ( the first list must be saved in the previous step) E.

Re: OFF-TOPIC Ben's sig monster quote [was Re: Parametrized Unit Tests]

2015-08-28 Thread jmp
On 08/28/2015 11:24 AM, Marko Rauhamaa wrote: Would you rather be an powerful, armed war hero admired and feared by your nation or a foresaken unemployed drunkard who rots in jail? Marko Time to quote the most famous general in the galaxy: “Ohhh. Great warrior.Wars not make one great.” ;) J

Re: Please don't make unfounded legalistic demands

2015-08-27 Thread jmp
On 08/26/2015 11:20 PM, Terry Reedy wrote: On 8/26/2015 12:36 PM, Jean-Michel Pichavant wrote: [snip] Are you allowed to use a newsreader or a mail+newsreader (Outlook Express, Thunderbird, )? If so post through newsgroup gmane.comp.python.general at news.gmane.org (as I am). I screwed alread