Re: Everything is an object in python - object class and type class
On 03/06/2015 17:29, Mark Lawrence wrote: On 03/06/2015 17:00, BartC wrote: On 03/06/2015 13:08, Marko Rauhamaa wrote: BartC b...@freeuk.com: To 'variable' and 'type', you might need to add 'value' to make it more complete. 'Value' and 'object' are indeed synonymous as long as you keep in mind that: -12 == -12 True -12 is -12 False IOW, the literal expression -12 happens to construct a fresh value/object each time CPython parses it. That's a different matter. However, you appear to be wrong. print (-12 is -12) gives True. No, you don't understand how cPython does things. Do I need to understand CPython to appreciate what difference there might be between variables, values and objects? Does anyone need to understand CPython for anything? -- Bartc -- https://mail.python.org/mailman/listinfo/python-list
Re: Keypress Input
On 06/03/2015 11:22 AM, John McKenzie wrote: Hello. Very new to Python and looking for some basic help. Would like a set-up where something happens when a key is pressed. Not propose a question, have the user type something, then hit return, then something happens, but just the R key is pressed, something happens, then something else happens if the B key is pressed, then a third thing happens if the G key is pressed. My research only served to confuse me. Firstly, I do not understand how it is possible for this to be a difficult thing not built into the system for any scripting language made within the last few decades. More to the point I am unclear on specific suggestions. Most of them seem to be for Windows only and I want this working on a Raspberry Pi. Saw getch but I am still confused if it is platform specific or not, or requires a module to be installed or not. Just get errors if I try to install getch using PIP. If you are using Python through a CLI (command line interface i.e., a shell), then in fact your request doesn't really make sense. CLIs by their nature don't support that kind of interaction. BUT don't despair. Nearly every GIU framework on the planet has a Python interface, and they all allow for a window to be opened with event processing of your choice. This are some good places to start: https://wiki.python.org/moin/GuiProgramming https://wiki.python.org/moin/GUI%20Programming%20in%20Python Several of these (Tkinter and the curses module) are distributed with Python, so you should already have them installed. Gary Herron Other suggestions seemed to be overkill and confused me to due to my beginner level knowledge and the fact these suggestions have other, more complicated elements to them. I just want a button press on a device connected to a Raspberry Pi to trigger an action. If anyone can give me some guidance on this I would appreciate it. Thank you. -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -- https://mail.python.org/mailman/listinfo/python-list
Re: Multiple thread program problem
On 2015-06-03 21:41, Mohan Mohta wrote: Hello I am trying to create multiple thread through the below program but I am getting an error #! /usr/bin/python import os import subprocess import thread import threading from thread import start_new_thread def proc(f) : com1=ssh -B com2=line.strip('\n') com3= uname -a co=str(ssh -B )+ str(com2) + str( uname -a) subprocess.call(co,shell=True) print return f = open('/tmp/python/1') for line in f: t=thread.start_new_thread(proc(f),()) t.start() f.close() c = raw_input( Type anything to quit) Execution output: Linux abc.myhomenetwork.com 2.6.18-348.25.1.el5 #1 SMP Thu Apr 10 06:32:45 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux Traceback (most recent call last): File ./readfile1.py, line 19, in module t=thread.start_new_thread(proc(f),()) TypeError: first arg must be callable The first argument should be the function. You're calling proc(f) and the passing its result. Also, start_new_thread starts the thread running immediately and returns its identifier, an int. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access the low digits of a list
On Tuesday, June 2, 2015 at 7:50:58 PM UTC+5:30, Ian wrote: On Tue, Jun 2, 2015 at 6:35 AM, Rustom Mody wrote: For that matter even this works But I am not sure whats happening or that I like it [x[-2:] for x in lines] ['12', '42', '49', '56', '25', '36', '49', '64', '81', '00'] x[-2:] selects all items in the sequence with index i such that len(x) - 2 = i len(x). For a sequence of length 2 or less, that's the entire sequence. Thanks -- learn something So it means that indices can give indexerror; slices cannot? Seems fair enough put that way, but is visually counterintuitive -- https://mail.python.org/mailman/listinfo/python-list
Multiple thread program problem
Hello I am trying to create multiple thread through the below program but I am getting an error #! /usr/bin/python import os import subprocess import thread import threading from thread import start_new_thread def proc(f) : com1=ssh -B com2=line.strip('\n') com3= uname -a co=str(ssh -B )+ str(com2) + str( uname -a) subprocess.call(co,shell=True) print return f = open('/tmp/python/1') for line in f: t=thread.start_new_thread(proc(f),()) t.start() f.close() c = raw_input( Type anything to quit) Execution output: Linux abc.myhomenetwork.com 2.6.18-348.25.1.el5 #1 SMP Thu Apr 10 06:32:45 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux Traceback (most recent call last): File ./readfile1.py, line 19, in module t=thread.start_new_thread(proc(f),()) TypeError: first arg must be callable -- https://mail.python.org/mailman/listinfo/python-list
Re: Keypress Input
Tkinter runs on raspberry pi. Get it installed, and then run this program. from Tkinter import * root = Tk() prompt = 'Press any key. Remember to keep your mouse in the cyan box. ' lab = Label(root, text=prompt, width=len(prompt), bg='cyan') lab.pack() def key(event): msg = 'event.char is %r and event.keysym is %r' % (event.char, event.keysym) lab.config(text=msg) root.bind_all('Key', key) root.mainloop() Now you will have to bind the various keys to do what it is you want. You need to read online dociumentation for tkinter to learn how to do this, as well as how to use tkinter in general. Laura -- https://mail.python.org/mailman/listinfo/python-list
[issue24376] xxlimited.c errors when building 32 and 64 bit on Windows
Mark Lawrence added the comment: Thanks for the comment David. Last time I used any kind of change system in anger was Visual Source Safe 15 years ago, and VAX/VMS CMS/MMF(?) before that. Where do I start with Mercurial? I don't even know what the difference is between setting up the now default 3.6 and 3.5? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24376 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24374] Plug refleak in set_coroutine_wrapper
Changes by Yury Selivanov yseliva...@gmail.com: Added file: http://bugs.python.org/file39611/set_coro.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24374 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Retrying to send message
On 03/06/2015 19:28, Ethan Furman wrote: On 06/03/2015 09:15 AM, Cecil Westerhof wrote: I kept the except. I like to see the message that went wrong. ;-) That's fine, but then add a `raise` after you print the error so you can see the reason that message failed. -- ~Ethan~ Why bother in the first place, especially when you're developing? Far easier to let the exception bubble up, or are we talking cross purposes? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
[issue22931] cookies with square brackets in value
Changes by Tim Pierce twpie...@gmail.com: -- nosy: +Tim Pierce ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22931 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24360] improve argparse.Namespace __repr__ for invalid identifiers.
paul j3 added the comment: An alternative would be to wrap a non-identifier name in 'repr()': def repr1(self): def fmt_name(name): if name.isidentifier(): return name else: return repr(name) type_name = type(self).__name__ arg_strings = [] for arg in self._get_args(): arg_strings.append(repr(arg)) for name, value in self._get_kwargs(): arg_strings.append('%s=%r' % (fmt_name(name), value)) return '%s(%s)' % (type_name, ', '.join(arg_strings)) This would produce lines like: Namespace(baz='one', 'foo bar'='test', 'x __y'='other') Namespace(a=1, b=2, 'double quote'='', single ' quote =') Namespace(')'=3, a=1) Namespace(a=1, 'b=2), Namespace(c'=3) With names that are deliberately messy, it is hard to say which is clearer. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24360 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Keypress Input
On 06/03/2015 11:22 AM, John McKenzie wrote: Hello. Very new to Python and looking for some basic help. Would like a set-up where something happens when a key is pressed. Not propose a question, have the user type something, then hit return, then something happens, but just the R key is pressed, something happens, then something else happens if the B key is pressed, then a third thing happens if the G key is pressed. My research only served to confuse me. Firstly, I do not understand how it is possible for this to be a difficult thing not built into the system for any scripting language made within the last few decades. More to the point I am unclear on specific suggestions. Most of them seem to be for Windows only and I want this working on a Raspberry Pi. Saw getch but I am still confused if it is platform specific or not, or requires a module to be installed or not. Just get errors if I try to install getch using PIP. If you are using Python through a CLI (command line interface i.e., a shell), then in fact your request doesn't really make sense. CLIs by their nature don't support that kind of interaction. BUT don't despair. Nearly every GIU framework on the planet has a Python interface, and they all allow for a window to be opened with event processing of your choice. This are some good places to start: https://wiki.python.org/moin/GuiProgramming https://wiki.python.org/moin/GUI%20Programming%20in%20Python Several of these (Tkinter and the curses module) are distributed with Python, so you should already have them installed. Gary Herron Other suggestions seemed to be overkill and confused me to due to my beginner level knowledge and the fact these suggestions have other, more complicated elements to them. I just want a button press on a device connected to a Raspberry Pi to trigger an action. If anyone can give me some guidance on this I would appreciate it. Thank you. -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -- https://mail.python.org/mailman/listinfo/python-list
Re: fork/exec close file descriptors
On Wed, Jun 3, 2015, at 10:43, Marko Rauhamaa wrote: However, the child process needs to be prepared for os.close() to block indefinitely because of an NFS problem or because SO_LINGER has been specified by the parent, for example. Setting the close-on-exec flag doesn't help there. Out of curiosity, does exec block in this situation? -- https://mail.python.org/mailman/listinfo/python-list
Re: fork/exec close file descriptors
On Wed, Jun 3, 2015, at 09:32, Chris Angelico wrote: Write an editor that opens a file and holds it open until the user's done with it. Have something that lets you shell out for whatever reason. Then trigger the shell-out, and instantly SIGSTOP the child process, before it does its work - or just have a really heavily loaded system, so it can't get a time slice. Now close the file in the UI, which results in the file being closed in the parent. Right, now let the child run... and there it goes, closing the file. The parent should be waiting for the child process. If it shouldn't wait for the command, then the child process should spawn a grandchild process, after closing the file descriptors. This is how the text editor I use actually works (more or less. In fact, the way to run a process it won't wait for is to run it as a background shell command. If you STOP the shell itself, the editor will be stuck waiting.) -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything is an object in python - object class and type class
On 03/06/2015 19:59, BartC wrote: Does anyone need to understand CPython for anything? No you (plural) don't. If people were to spend more time writing code and less time on hypothetical claptrap the amount of noise on this list would probably be reduced by 99%. Then knock out those who are interested in things like rugby, with Haskell being an England international, my beautiful eight month old great niece Ruby, and various other things, we might even spend some time actually talking about the Python programming langauge. Or have you all forgotten that that is what this list is about? Hardly surprising that the bulk of the core devs left years ago, is it? Oh, have to get in my obligatory mention of CORAL 66/250. If you lot can waffle of about languages in which I've no interest on this list, I'll once again mention my poor old darling who gets little or no TLC. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Multiple thread program problem
On Wednesday, June 3, 2015 at 4:01:13 PM UTC-5, Sam Raker wrote: proc(f) isn't a callable, it's whatever it returns. IIRC, you need to do something like 'start_new_thread(proc, (f,))' If I execute something like t=thread.start_new_thread(proc,(f)) I get: Traceback (most recent call last): File ./readfile1.py, line 19, in module t=thread.start_new_thread(proc,(f)) TypeError: 2nd arg must be a tuple -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access the low digits of a list
On Wed, Jun 3, 2015 at 3:08 PM, Rustom Mody rustompm...@gmail.com wrote: On Tuesday, June 2, 2015 at 7:50:58 PM UTC+5:30, Ian wrote: On Tue, Jun 2, 2015 at 6:35 AM, Rustom Mody wrote: For that matter even this works But I am not sure whats happening or that I like it [x[-2:] for x in lines] ['12', '42', '49', '56', '25', '36', '49', '64', '81', '00'] x[-2:] selects all items in the sequence with index i such that len(x) - 2 = i len(x). For a sequence of length 2 or less, that's the entire sequence. Thanks -- learn something So it means that indices can give indexerror; slices cannot? Seems fair enough put that way, but is visually counterintuitive Yes. The rule I paraphrased above is stated at https://docs.python.org/3/library/stdtypes.html#common-sequence-operations -- scroll down to note 4. I don't know if there's anything that clearly states that sequence slicing can't raise IndexError, but it is at least implied by the above, and it is certainly true of all builtin sequence types. -- https://mail.python.org/mailman/listinfo/python-list
[issue24338] In argparse adding wrong arguments makes malformed namespace
paul j3 added the comment: http://bugs.python.org/issue15125 argparse: positional arguments containing - in name not handled well Discussion on whether positionals 'dest' should translate '-' to '_'. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24338 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: fork/exec close file descriptors
random...@fastmail.us: On Wed, Jun 3, 2015, at 10:43, Marko Rauhamaa wrote: However, the child process needs to be prepared for os.close() to block indefinitely because of an NFS problem or because SO_LINGER has been specified by the parent, for example. Setting the close-on-exec flag doesn't help there. Out of curiosity, does exec block in this situation? I didn't try it, but it is apparent in the source code: void do_close_on_exec(struct files_struct *files) { unsigned i; struct fdtable *fdt; /* exec unshares first */ spin_lock(files-file_lock); for (i = 0; ; i++) { unsigned long set; unsigned fd = i * BITS_PER_LONG; fdt = files_fdtable(files); if (fd = fdt-max_fds) break; set = fdt-close_on_exec[i]; if (!set) continue; fdt-close_on_exec[i] = 0; for ( ; set ; fd++, set = 1) { struct file *file; if (!(set 1)) continue; file = fdt-fd[fd]; if (!file) continue; rcu_assign_pointer(fdt-fd[fd], NULL); __put_unused_fd(files, fd); spin_unlock(files-file_lock); filp_close(file, files); cond_resched(); spin_lock(files-file_lock); } } spin_unlock(files-file_lock); } int filp_close(struct file *filp, fl_owner_t id) { int retval = 0; if (!file_count(filp)) { printk(KERN_ERR VFS: Close: file count is 0\n); return 0; } if (filp-f_op-flush) retval = filp-f_op-flush(filp, id); if (likely(!(filp-f_mode FMODE_PATH))) { dnotify_flush(filp, id); locks_remove_posix(filp, id); } fput(filp); return retval; } Now, the kernel NFS code specifies a flush() method, which can block and even fail. Sockets don't have a flush() method. So closing a socket cannot fail. However, fput(), which decrements the reference count, may block if lingering has been specified for the socket. So I wasn't all that wrong earlier after all: whoever closes a socket last will linger. Thus, the parent (who wanted to linger) might zip through closing a socket while the unwitting child process will suffer the lingering delay before it gets to exec. However, there's this comment in inet_release(): /* [...] * If the close is due to the process exiting, we never * linger.. */ Marko -- https://mail.python.org/mailman/listinfo/python-list
[issue24268] PEP 489 -- Multi-phase extension module initialization
Petr Viktorin added the comment: I've posted a patch that fixes the remaining refleak in issue24373. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24268 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Can Python function return multiple data?
On Wednesday, June 3, 2015 at 2:57:00 PM UTC-7, Mark Lawrence wrote: On 03/06/2015 22:35, Chris Angelico wrote: On Wed, Jun 3, 2015 at 11:56 PM, Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de wrote: Am 03.06.2015 um 01:56 schrieb Chris Angelico: and it's pretty convenient. In C, the nearest equivalent is passing a number of pointers as parameters, and having the function fill out values. Python's model is a lot closer to what you're saying than C's model is :) At least, C functions can return structs... Oh, yes, I forgot about that. Thought that was C++ but not C, partly because I never do it in either language. Although in a sense, a struct is still a single thing. ChrisA Don't forget that C functions can accept structs as input. Possibly not a good idea as I found out many years ago pre ANSIC when I forgot that little old ampersand, so the compiler didn't pick it up, but then with modern computers having so much memory who really cares if you burn a little bit of stack on structures rather than pointers to structures? Now does Python pass by value or by reference? Happily sits back and waits for 10**6 emails to arrive as this is discussed for the 10**6th time. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence People actually argue that Python passes by value? This is easily proven wrong by passing a mutable object to a function and changing it within the function. -- https://mail.python.org/mailman/listinfo/python-list
[issue24360] improve argparse.Namespace __repr__ for invalid identifiers.
Matthias Bussonnier added the comment: Namespace(a=1, 'b=2), Namespace(c'=3) :-) I read that a `prime-b`=2 and `c-prime`=3. I just feel like having a repr which is closer to the constructor signature is better, but I guess it's a question of taste. Anyway, both would be fine. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24360 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Multiple thread program problem
On Wednesday, June 3, 2015 at 5:34:31 PM UTC-5, Waffle wrote: You think (f) makes a tuple, but it does not. the parentesis is not the tuple constructor, the comma is try: t=thread.start_new_thread(proc,(f,)) Thanks for the pointer waffle. The program executes now but still not the way I want it. I think I will need to tweak it a bit as the code is executing with the same argument from the file /tmp/python/1 multiple times whereas it needs to be executed only ones but in parallel. Let me figure that out. Once again thanks for all the help provided on this thread. -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything is an object in python - object class and type class
On 03/06/2015 21:58, Mark Lawrence wrote: On 03/06/2015 19:59, BartC wrote: Does anyone need to understand CPython for anything? No you (plural) don't. If people were to spend more time writing code and less time on hypothetical claptrap the amount of noise on this list would probably be reduced by 99%. Not so hypothetical in my case as I have to implement a lot of this stuff. I'm also quite interested in how Python does things. If it's a good idea I'll copy it, if not I'll try and avoid it! Then knock out those who are interested in things like rugby, with Haskell being an England international, my beautiful eight month old great niece Ruby, and various other things, we might even spend some time actually talking about the Python programming langauge. Or have you all forgotten that that is what this list is about? Hardly surprising that the bulk of the core devs left years ago, is it? (I'm accessing the 'list' (whatever that is) via usenet. Usenet itself is slowly dying. However I don't believe there weren't pointless discussions that went around in circles years ago too!) -- Bartc -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything is an object in python - object class and type class
On 03/06/2015 22:33, BartC wrote: On 03/06/2015 21:58, Mark Lawrence wrote: Not so hypothetical in my case as I have to implement a lot of this stuff. I'm also quite interested in how Python does things. If it's a good idea I'll copy it, if not I'll try and avoid it! Which implementation, cPython, Jython, IronPython...??? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Can Python function return multiple data?
On 03/06/2015 22:35, Chris Angelico wrote: On Wed, Jun 3, 2015 at 11:56 PM, Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de wrote: Am 03.06.2015 um 01:56 schrieb Chris Angelico: and it's pretty convenient. In C, the nearest equivalent is passing a number of pointers as parameters, and having the function fill out values. Python's model is a lot closer to what you're saying than C's model is :) At least, C functions can return structs... Oh, yes, I forgot about that. Thought that was C++ but not C, partly because I never do it in either language. Although in a sense, a struct is still a single thing. ChrisA Don't forget that C functions can accept structs as input. Possibly not a good idea as I found out many years ago pre ANSIC when I forgot that little old ampersand, so the compiler didn't pick it up, but then with modern computers having so much memory who really cares if you burn a little bit of stack on structures rather than pointers to structures? Now does Python pass by value or by reference? Happily sits back and waits for 10**6 emails to arrive as this is discussed for the 10**6th time. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Multiple thread program problem
You think (f) makes a tuple, but it does not. the parentesis is not the tuple constructor, the comma is try: t=thread.start_new_thread(proc,(f,)) -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access the low digits of a list
On 03/06/2015 22:08, Rustom Mody wrote: On Tuesday, June 2, 2015 at 7:50:58 PM UTC+5:30, Ian wrote: On Tue, Jun 2, 2015 at 6:35 AM, Rustom Mody wrote: For that matter even this works But I am not sure whats happening or that I like it [x[-2:] for x in lines] ['12', '42', '49', '56', '25', '36', '49', '64', '81', '00'] x[-2:] selects all items in the sequence with index i such that len(x) - 2 = i len(x). For a sequence of length 2 or less, that's the entire sequence. Thanks -- learn something So it means that indices can give indexerror; slices cannot? Seems fair enough put that way, but is visually counterintuitive Are you seriously trying to say that you teach Python but don't understand a basic that is here https://docs.python.org/3/tutorial/introduction.html, Slice indices have useful defaults; an omitted first index defaults to zero, an omitted second index defaults to the size of the string being sliced.? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything is an object in python - object class and type class
On 03/06/2015 22:49, Mark Lawrence wrote: On 03/06/2015 22:33, BartC wrote: On 03/06/2015 21:58, Mark Lawrence wrote: Not so hypothetical in my case as I have to implement a lot of this stuff. I'm also quite interested in how Python does things. If it's a good idea I'll copy it, if not I'll try and avoid it! Which implementation, cPython, Jython, IronPython...??? Mainly the language itself. But I've also been looking at the workings of CPython. (Also PyPy but obviously I'm not going to get anywhere there, although RPython sounds intriguing.) (To be clear, I'm not implementing Python, but designing and implementing a separate language. I did try tinkering with CPython, but the only thing I discovered, regarding its performance, is that the Windows version is probably 14% slower than it need be. I think due to using MS' C compiler which doesn't have gcc's computed gotos. But I think few people here use Windows so that's probably of little interest. It's not so easy to fix either.) -- Bartc -- https://mail.python.org/mailman/listinfo/python-list
Re: Multiple thread program problem
On Wednesday, June 3, 2015 at 4:45:52 PM UTC-7, M2 wrote: On Wednesday, June 3, 2015 at 5:34:31 PM UTC-5, Waffle wrote: You think (f) makes a tuple, but it does not. the parentesis is not the tuple constructor, the comma is try: t=thread.start_new_thread(proc,(f,)) Thanks for the pointer waffle. The program executes now but still not the way I want it. I think I will need to tweak it a bit as the code is executing with the same argument from the file /tmp/python/1 multiple times whereas it needs to be executed only ones but in parallel. Let me figure that out. Once again thanks for all the help provided on this thread. Check your usages of line and f. You have spots where you probably meant line instead of f, and others where you have f where you probably meant line. -- https://mail.python.org/mailman/listinfo/python-list
Re: Let's make Python into LISP
On Wednesday, June 3, 2015 at 4:27:39 AM UTC+5:30, Dr. Bigcock wrote: We can make Python like LISP: 1. Make EVERYTHING the same kind of thing (call it object). 2. Let's make a lot of meta functions like super, instead of judicious use of interpreter impositions. 3. Forget *practicality*. All hail *purity*. Wait. Someone's time machine broke. Mark Hi Mark The way you keep bringing up Lisp, λ-calculus, etc completely without relevance to anything, I wonder if you had a bad experience with someone teaching these and thereabouts? Dark Secret Everyone knows that the average student is below average. More true for the average teacher /Dark Secret Yeah disasters (of all shapes and colors) strike and leave us scarred. Isn't it more intelligent to pick up the pieces and move on than to keep putting salt on the scars? PS If you de-expletivize your name, maybe more people will pay attention to what you want to say -- https://mail.python.org/mailman/listinfo/python-list
Re: Can Python function return multiple data?
On Wed, Jun 3, 2015 at 11:56 PM, Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de wrote: Am 03.06.2015 um 01:56 schrieb Chris Angelico: and it's pretty convenient. In C, the nearest equivalent is passing a number of pointers as parameters, and having the function fill out values. Python's model is a lot closer to what you're saying than C's model is :) At least, C functions can return structs... Oh, yes, I forgot about that. Thought that was C++ but not C, partly because I never do it in either language. Although in a sense, a struct is still a single thing. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Retrying to send message
On Thu, Jun 4, 2015 at 2:15 AM, Cecil Westerhof ce...@decebal.nl wrote: And I'd also skip the bare except clause. If you get any sort of exception, whether it's a bug, a failure from libturpial, a network error, or anything else, your code will just terminate with a bland and useless message. Much better to simply let the exception bubble up. I kept the except. I like to see the message that went wrong. ;-) In that case, there's an easier way to deal with it: just raise a different exception, and let them chain. Something like this: def send_message(msg): ... try: 1/0 ... except: raise FailedMessageException(msg) ... class FailedMessageException(Exception): pass ... send_message(Test) Traceback (most recent call last): File stdin, line 2, in send_message ZeroDivisionError: division by zero During handling of the above exception, another exception occurred: Traceback (most recent call last): File stdin, line 1, in module File stdin, line 3, in send_message __main__.FailedMessageException: Test But I'd still avoid the bare except, and use except Exception: instead. I don't think you want to catch SystemExit in this way, for instance. So here's how I'd write that code: def send_message(msg): ... try: 1/0 ... except Exception as e: raise FailedMessageException(msg) from e ... send_message(Test) Traceback (most recent call last): File stdin, line 2, in send_message ZeroDivisionError: division by zero The above exception was the direct cause of the following exception: Traceback (most recent call last): File stdin, line 1, in module File stdin, line 3, in send_message __main__.FailedMessageException: Test (Also, the use of from here causes a slightly different wording, which I think is more appropriate. But that's minor.) You get the report of which message failed, plus you get the complete traceback from the original exception. Much MUCH more useful. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: fork/exec close file descriptors
On Thu, Jun 4, 2015 at 6:07 AM, random...@fastmail.us wrote: On Wed, Jun 3, 2015, at 09:32, Chris Angelico wrote: Write an editor that opens a file and holds it open until the user's done with it. Have something that lets you shell out for whatever reason. Then trigger the shell-out, and instantly SIGSTOP the child process, before it does its work - or just have a really heavily loaded system, so it can't get a time slice. Now close the file in the UI, which results in the file being closed in the parent. Right, now let the child run... and there it goes, closing the file. The parent should be waiting for the child process. If it shouldn't wait for the command, then the child process should spawn a grandchild process, after closing the file descriptors. This is how the text editor I use actually works (more or less. In fact, the way to run a process it won't wait for is to run it as a background shell command. If you STOP the shell itself, the editor will be stuck waiting.) Really? I thought forking, execing, and not immediately waiting, was a standard way to trigger an asynchronous action. My editor lets me start something and then keep working in the editor, and see the output from the command when it's ready. (Simple example: A git push might take a long time if the network's slow, and I want to know if it errors out, but most likely I'll just see the expected messages come up and that's that.) The parent definitely shouldn't immediately wait on the child; and it shouldn't disown the child via a second forking because it wants to report on the child's completion. So no, I don't think insta-waiting is right in all situations. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Multiple thread program problem
On Wednesday, June 3, 2015 at 6:56:47 PM UTC-5, sohca...@gmail.com wrote: On Wednesday, June 3, 2015 at 4:45:52 PM UTC-7, M2 wrote: On Wednesday, June 3, 2015 at 5:34:31 PM UTC-5, Waffle wrote: You think (f) makes a tuple, but it does not. the parentesis is not the tuple constructor, the comma is try: t=thread.start_new_thread(proc,(f,)) Thanks for the pointer waffle. The program executes now but still not the way I want it. I think I will need to tweak it a bit as the code is executing with the same argument from the file /tmp/python/1 multiple times whereas it needs to be executed only ones but in parallel. Let me figure that out. Once again thanks for all the help provided on this thread. Check your usages of line and f. You have spots where you probably meant line instead of f, and others where you have f where you probably meant line. Here is my logic: f is where the entire file is getting loaded which is also passed as argument in the function proc line has a single line from the file which is then stripped off the new line character and assigned to com2 variable which helps in using it in the subprocess.call -- https://mail.python.org/mailman/listinfo/python-list
[issue24294] DeprecationWarnings should be visible by default in the interactive REPL
Matthias Bussonnier added the comment: I gave that a shot. Doing it cleanly in C as the warning module is initialized much earlier. Though I'm not super used to CPython internals. Doing just before the repl by using `PyRun_SimpleString` make the patch relatively small. -- keywords: +patch nosy: +mbussonn Added file: http://bugs.python.org/file39612/enable_deprecation_warnings_in_repl.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24294 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Multiple thread program problem
On 03Jun2015 17:04, M2 mohan.mo...@gmail.com wrote: On Wednesday, June 3, 2015 at 6:56:47 PM UTC-5, sohca...@gmail.com wrote: On Wednesday, June 3, 2015 at 4:45:52 PM UTC-7, M2 wrote: On Wednesday, June 3, 2015 at 5:34:31 PM UTC-5, Waffle wrote: You think (f) makes a tuple, but it does not. the parentesis is not the tuple constructor, the comma is try: t=thread.start_new_thread(proc,(f,)) Thanks for the pointer waffle. The program executes now but still not the way I want it. I think I will need to tweak it a bit as the code is executing with the same argument from the file /tmp/python/1 multiple times whereas it needs to be executed only ones but in parallel. Let me figure that out. Once again thanks for all the help provided on this thread. Check your usages of line and f. You have spots where you probably meant line instead of f, and others where you have f where you probably meant line. Here is my logic: f is where the entire file is getting loaded In the main code, yes. which is also passed as argument in the function proc But why? f is not using in proc. Only line is. line has a single line from the file which is then stripped off the new line character and assigned to com2 variable which helps in using it in the subprocess.call That end is fine. I would be passing only line to proc, not f at all. Suggestion: move your main code into its own function. That will make all the variables in it local. Your proc function is presently relying on line being global, which generally bad and a recipe for disaster in multithreaded code. Moving the main code into its own function will (1) get rid of the global variables and (2) force you to consider exactly what you need to pass to proc, and that will help reveal various logic issues. Cheers, Cameron Simpson c...@zip.com.au How do you blip the throttle and wave? Do you blip it real high, then wave before the revs drop back? Blip = right hand; Wave = left hand. Do both simultaneously. QED. Doesnt this make the bike lurch forward thru the intersection? Not if the disk lock is in place... - Dean Woodward de...@agora.rdrop.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Let's make Python into LISP
On 03/06/2015 22:22, Rustom Mody wrote: On Wednesday, June 3, 2015 at 4:27:39 AM UTC+5:30, Dr. Bigcock wrote: We can make Python like LISP: 1. Make EVERYTHING the same kind of thing (call it object). 2. Let's make a lot of meta functions like super, instead of judicious use of interpreter impositions. 3. Forget *practicality*. All hail *purity*. Wait. Someone's time machine broke. Mark Hi Mark The way you keep bringing up Lisp, λ-calculus, etc completely without relevance to anything, I wonder if you had a bad experience with someone teaching these and thereabouts? Dark Secret Everyone knows that the average student is below average. More true for the average teacher /Dark Secret Yeah disasters (of all shapes and colors) strike and leave us scarred. Isn't it more intelligent to pick up the pieces and move on than to keep putting salt on the scars? PS If you de-expletivize your name, maybe more people will pay attention to what you want to say Please stop replying to this brain dead pot smoking hippy. My mail filters work perfectly to keep him away from my inbox, so I'm not interested in seeing his complete and utter garbage effectively forwarded on from somebody else, thank you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
[issue24338] In argparse adding wrong arguments makes malformed namespace
py.user added the comment: paul j3 wrote: It's an attempt to turn such flags into valid variable names. I'm looking at code and see that he wanted to make it handy for use in a resulting Namespace. args = argparse.parse_args(['--a-b-c']) abc = args.a_b_c If he doesn't convert, he cannot get attribute without getattr(). It's not a UNIX reason. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24338 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Retrying to send message
On 06/03/2015 01:37 PM, Mark Lawrence wrote: On 03/06/2015 19:28, Ethan Furman wrote: On 06/03/2015 09:15 AM, Cecil Westerhof wrote: I kept the except. I like to see the message that went wrong. ;-) That's fine, but then add a `raise` after you print the error so you can see the reason that message failed. Why bother in the first place, especially when you're developing? Far easier to let the exception bubble up, or are we talking cross purposes? I think Cecil means he wants to see which twitter message failed to send. The rest of us would like to also have the error itself displayed. ;) -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
[issue24338] In argparse adding wrong arguments makes malformed namespace
paul j3 added the comment: Yes, the '_' makes it accessible as an attribute name. But the presence of '-' in the option name has a UNIX history. That is a flag like '--a-b-c' is typical, '--a_b_c' is not. There is less of precedent for a flag like '@@a@b' or '--a@b'. Here's the relevant code from '_ActionContainer' class. def _get_optional_kwargs(self, *args, **kwargs): # determine short and long option strings ... for option_string in args: # error on strings that don't start with an appropriate prefix if not option_string[0] in self.prefix_chars: ... raise ValueError(msg % args) # strings starting with two prefix characters are long options option_strings.append(option_string) if option_string[0] in self.prefix_chars: if len(option_string) 1: if option_string[1] in self.prefix_chars: long_option_strings.append(option_string) # infer destination, '--foo-bar' - 'foo_bar' and '-x' - 'x' dest = kwargs.pop('dest', None) if dest is None: if long_option_strings: dest_option_string = long_option_strings[0] else: dest_option_string = option_strings[0] dest = dest_option_string.lstrip(self.prefix_chars) if not dest: msg = _('dest= is required for options like %r') raise ValueError(msg % option_string) dest = dest.replace('-', '_') Even if you need to have odd ball characters in the option flag, you don't have to settle for them in the 'dest'. You can always give the argument a nice looking 'dest'. That's a rather common pattern in 'argparse'. Provide a default handling for common cases, and provide parameters that let the user override those defaults. The net effect is to limit the complexity of the code, while increasing the complexity of the documentation. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24338 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20186] Derby #18: Convert 31 sites to Argument Clinic across 23 files
Changes by Serhiy Storchaka storch...@gmail.com: -- stage: needs patch - patch review versions: +Python 3.6 -Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20186 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20186] Derby #18: Convert 31 sites to Argument Clinic across 23 files
Tal Einat added the comment: Should Argument Clinic conversion patches still be against the 'default' branch, and not 3.5, even though they don't include any functionality changes? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20186 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18003] lzma module very slow with line-oriented reading.
Martin Panter added the comment: Looking at https://bugs.python.org/file39586/decomp-optim.patch, the “closed” property is the first of the three hunks: 1. Adds @property / def closed(self) to Lib/_compression.py 2. Adds def __iter__(self) to Lib/gzip.py 3. Adds def __iter__(self) to Lib/lzma.py -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18003 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18003] lzma module very slow with line-oriented reading.
Martin Panter added the comment: New patch just fixes the spelling error in the comment. -- stage: needs patch - patch review Added file: http://bugs.python.org/file39604/decomp-optim.v2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18003 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18003] lzma module very slow with line-oriented reading.
Larry Hastings added the comment: I don't see anything about closed in the patch you posted. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18003 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Everything is an object in python - object class and type class
On 03/06/2015 05:16, Eddilbert Macharia wrote: On Tuesday, June 2, 2015 at 2:27:31 PM UTC+3, Steven D'Aprano wrote: Eddilbert, have you programmed in any other languages? It would help you understand if you have. Sadly yes i have worked with java, and that is what is causing me so much grief.In java objects are instance of a class.pretty simple. In Python 2: - everything is an object [the general concept] - some things, but not all things, are instances of the class called object In Python 3: - everything is an object [the general concept] - everything is an instance of the class called object I think then in python object and instance of a class are entirely different things. in OOP and python - object is a representation of a real thing, or a concept .e.g a person,number and the concept of classes- which is the concept of create/representing other objects using a programming language to the machine. class - This is what is used to create/represent objects in the machine using a programming language class instance - This is the output of the classes this is a representation of an object. I have a lot of trouble with this stuff too, as my ideas are decidedly old-fashioned. (Also I'm developing a language with some OO aspects without ever having used OO!) But, it is mostly just jargon. If you go back to using 'variable' and 'type', then it becomes a bit easier: * A variable is an instance of some type. And, that's pretty much it! However, modern languages such as Python add a few more twists. So, if a static, compiled language, say, had these kinds of things: - Module - Record definition - Enum type - Label (for goto) - Function - Type which are normally entities that only the compiler are concerned with, then these can now also be values that can be stored in variables! (One or two such languages might allow pointers to Functions or Labels, but that's about it.) Exactly what it is about a Module, Record or Function that is stored in the variable is an implementation detail. The important thing is that you can use such as variable at runtime in the same way you might do at compile-time. Python of course would subsume concepts such as Records or Enums into a class, as it seems to like to unify what it considers to be untidy, separate aspects of a language. Some of us however need things separated out again in order to understand them! (This is a set of codes I'm using in a current compiler project, for a new language. Each denotes a separate kind of identifier in the input source: nullid = 0 programid = 1 moduleid = 2 extmoduleid = 3 classid = 4 procid = 5 staticid = 6 constid = 7 fieldid = 8 genfieldid = 9 enumid = 10 paramid = 11 frameid = 12 varid = 13 # ? labelid = 14 blockid = 15 attribid = 16 aliasid = 17 The language requires that each identifier is resolved at compile-time to one of the above. This makes it rather less dynamic than Python, where the bytecode compiler, as far as I know, only resolves a name as either global or local (and perhaps attribute, but I'm not an expert on its workings). (The 'varid' code was for a unresolved top-level name, which I will probably remove as that was added when I'd intended to emulate Python more. But that was too much work (and too many speed-ups were no longer trivial). Some codes such as 'nullid' and 'programid' are only used internally. 'genfield' is a field (attribute) that can't be resolved, but the possibilities have been reduced to a small, finite set which is resolved at load-time (in Python, the attribute could be anything, and you don't even know at runtime what it might be until you actually use the attribute.) In this list, then 'static', 'frame', and 'param' denote what I'd call variables. A variable, at runtime, contains a value of a certain type (another list of codes). One of those types however is a Symbol: just a reference (a symbol table index) to a resolved name in the source code. Just a different approach to things. But since the ultimate aim is to be able to write programs, not so different.) -- Bartc -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything is an object in python - object class and type class
On 03/06/2015 11:38, Chris Angelico wrote: On Wed, Jun 3, 2015 at 8:20 PM, BartC b...@freeuk.com wrote: I have a lot of trouble with this stuff too, as my ideas are decidedly old-fashioned. (Also I'm developing a language with some OO aspects without ever having used OO!) But, it is mostly just jargon. If you go back to using 'variable' and 'type', then it becomes a bit easier: * A variable is an instance of some type. And, that's pretty much it! If I have a list called stuff with three elements in it, is stuff[1] a variable? What if I return that list from a function called get_stuff()? Is get_stuff()[1] a variable? Because in Python, get_stuff()[1] is certainly going to be an object. Come on, we're trying to keep this simple. To 'variable' and 'type', you might need to add 'value' to make it more complete. An old-fashioned program will be moving values around and constructing new ones. Some of them will be loaded from variables, and some might end up being stored in variables. (With the obligatory twist in Python that variable names are not directly attached to their values, but via a 'string'. I can introduce a new term for what /is/ actually stored /with/ the variable, as it's got to be something unless Python works by magic, but I don't want to do that.) You might call such a value an 'object'. The trouble is, Python also uses 'object' to mean the base class of all classes. And it seems to use it in a more abstract sense as well to mean pretty much everything. While other languages, such as C, use object in yet another way. Which is where the term breaks down as it no longer helps in understanding. It's become meaningless. -- Bartc -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything is an object in python - object class and type class
On 03/06/2015 11:20, BartC wrote: 'genfield' is a field (attribute) that can't be resolved, but the possibilities have been reduced to a small, finite set which is resolved at load-time (in Python, the attribute could be anything, and you don't even know at runtime what it might be until you actually use the attribute.) (That's not right. What I call 'genfield' is also resolved at runtime at the point of use. But the possibilities are very small (often just two), and must be an attribute the compiler knew about. Python-like open-ended attribute names have a separate mechanism, although I haven't implemented it yet...) -- Bartc -- https://mail.python.org/mailman/listinfo/python-list
[issue18003] lzma module very slow with line-oriented reading.
Antoine Pitrou added the comment: Yes, this is right. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18003 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24363] httplib fails to handle semivalid HTTP headers
Cory Benfield added the comment: It is obvious that this case could be treated as a folded (continuation) line. But in general I think it would be better to ignore the erroneous line, or to record it as a defect so that the server module or other user can check it. Just to clarify, in an instance very similar to this one this would be *terrible* advice. The token that would be lost here is the 'Secure' field on the cookie, which is an extremely important token to have: if we don't correctly parse it, we run the risk of sending the cookie on plaintext connections. Discarding data is the problem, and while discarding *less* data is an improvement, it would be good if we could resolve this problem in such a way that we'd have correctly parsed this header. Generally speaking, if we treat these as continuation lines I think we have the best change of making a useful header out of this mess. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24363 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Everything is an object in python - object class and type class
On Wednesday 03 June 2015 05:31, Jon Ribbens wrote: On 2015-06-02, Dr. Bigcock dreamingforw...@gmail.com wrote: On Tuesday, June 2, 2015 at 1:49:03 PM UTC-5, Jon Ribbens wrote: On 2015-06-02, Dr. Bigcock dreamingforw...@gmail.com wrote: It doesn't really do anything. No one uses integers as objects. (Any dissenters?) Yes. *Everyone* uses integers as objects. Containers such as lists and dictionaries and tuples etc contain objects. If integers weren't objects then you wouldn't be able to put them in containers (and you'd end up with Java). Sorry. I meant object in the sense of OOP: something you might extend or make a derived class with. I'm not sure you get to define which properties of objects you want not to count. Your last claim, must not be true because integers were able to be placed in objects before the type/class unification with v2.6, I believe. Unless I'm misremembering, before that they were still objects, just not quite the same kind of objects as pure-Python ones. Correct. It was version 2.2, not 2.6, that unified built-in types with classes. Prior to that, Python had two distinct kinds of object, with separate hierarchies: Types (builtins, defined in C) +-- int +-- dict +-- str +-- list Classes (custom-made in Python using the class keyword) +-- Foo +-- Bar +-- FooBar +- FooBarBaz You could only subclass classes, not types. But *both* were kinds of objects. They were just separate, with slightly different characteristics. Starting with 2.2, the old-style classic classes still existed, for backwards compatibility, but Python introduced a single base-class for the built-in types, called it object, and enabled subclassing from pure-Python code: Unified types/classes (new-style classes) +-- object +-- int +-- MyInteger +-- dict +-- str +-- list +-- MyList +-- Spam Classic Classes (old-style classes) [unchanged from above] Finally, in Python 3, the classic classes were removed, and Python now has a single unified type/class hierarchy, with object at the root. But regardless of whether Python had a single type hierarchy or two separate hierarchies, all values in Python were still implemented as objects. -- Steve -- https://mail.python.org/mailman/listinfo/python-list
What sort of data structure to use?
Hi I have written a Python utility that performs a certain activity on some predefined sets of files. Here is the outline of what I have written: # File Set A pathA = 'pathA' fileListA = ['fileA1.txt', 'fileA2.txt'] # File Set B pathB = 'pathB' fileListB = ['fileB1.txt', 'fileB2.txt', 'fileB3.txt'] myFunc1(pathA, fileListA) myFunc2(pathA, fileListA) myFunc1(pathB, fileListB) myFunc2(pathB, fileListB) I want to add more file sets, so I really want to add the sets to a list and iterate over the list, calling myFunc1 myFunc2 for each item. My question is: what sort of data structure could I use to organise this, given that I want to associate a set of files with each path and that, for each set, there is an arbitrary number of files? Best regards David -- https://mail.python.org/mailman/listinfo/python-list
[issue18003] lzma module very slow with line-oriented reading.
Martin Panter added the comment: Yes that’s basically right Larry. The __iter__() was previously inherited; now I am overriding it with a custom version. Similarly for the “closed” property, but that one is only a member of objects internal to the gzip, lzma and bz2 modules. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18003 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Everything is an object in python - object class and type class
On Wed, Jun 3, 2015 at 8:20 PM, BartC b...@freeuk.com wrote: I have a lot of trouble with this stuff too, as my ideas are decidedly old-fashioned. (Also I'm developing a language with some OO aspects without ever having used OO!) But, it is mostly just jargon. If you go back to using 'variable' and 'type', then it becomes a bit easier: * A variable is an instance of some type. And, that's pretty much it! If I have a list called stuff with three elements in it, is stuff[1] a variable? What if I return that list from a function called get_stuff()? Is get_stuff()[1] a variable? Because in Python, get_stuff()[1] is certainly going to be an object. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: What sort of data structure to use?
David Aldrich wrote: Hi I have written a Python utility that performs a certain activity on some predefined sets of files. Here is the outline of what I have written: # File Set A pathA = 'pathA' fileListA = ['fileA1.txt', 'fileA2.txt'] # File Set B pathB = 'pathB' fileListB = ['fileB1.txt', 'fileB2.txt', 'fileB3.txt'] myFunc1(pathA, fileListA) myFunc2(pathA, fileListA) myFunc1(pathB, fileListB) myFunc2(pathB, fileListB) I want to add more file sets, so I really want to add the sets to a list and iterate over the list, calling myFunc1 myFunc2 for each item. My question is: what sort of data structure could I use to organise this, given that I want to associate a set of files with each path and that, for each set, there is an arbitrary number of files? I'd start simple and put (path, files) pairs into a list: path_files_pairs = [ (pathA, [fileA1.txt, fileA2.txt, ...]), (pathB, [fileB1.txt, ...]), ] for path, files in path_files_pairs: func1(path, files) func2(path, files) You can always add complications later: import glob import os class VirtualFileset: def __init__(self, folder, pattern): self.folder = folder self.pattern = pattern def __iter__(self): yield self.folder yield glob.glob(os.path.join(self.folder, self.pattern)) path_files_pairs = [ (pathA, [fileA1.txt, fileA2.txt, ...]), (pathB, [fileB1.txt, ...]), VirtualFileset(pathC, *.py), # all python files in directory pathC ] for path, files in path_files_pairs: func1(path, files) func2(path, files) -- https://mail.python.org/mailman/listinfo/python-list
Re: fork/exec close file descriptors
Chris Angelico ros...@gmail.com writes: On Wed, Jun 3, 2015 at 7:06 AM, Alain Ketterlin al...@universite-de-strasbourg.fr.invalid wrote: I've no idea what the OP's program was doing, so I'm not going to split hairs. I can't imagine why one would like to mass-close an arbitrary set of file descriptors, and I think APIs like os.closerange() are toxic and an appeal to sloppy programming. When you fork, you get a duplicate referent to every open file in both parent and child. [...] Thank you, I know this. What I mean is: what are the reasons that you cannot access your file descriptors one by one? To me closing a range of descriptors has absolutely no meaning, simply because ranges have no meaning for file descriptors (they're not ordered in any way). What if some library uses its own descriptors that happen to lie in your range? Etc. -- Alain. -- https://mail.python.org/mailman/listinfo/python-list
Re: fork/exec close file descriptors
Alain Ketterlin al...@universite-de-strasbourg.fr.invalid: Marko Rauhamaa ma...@pacujo.net writes: Maybe close() will fail for ever. Your program has to deal with this, something is going wrong, it can't just close and go on. Here's the deal: the child process is saddled with file descriptors it never wanted in the first place. It can't decline them. Now you're saying it can't even dispose of them. The reason this has been allowed to go on is that everybody just closes the file descriptors and ignores the possibility or repercussions of a failure. I haven't read about horror stories of this failing. I readily admit this is very dirty, but since the API doesn't offer a clean alternative, there's nothing you can/should do about it. Marko -- https://mail.python.org/mailman/listinfo/python-list
Calling Python Script from an SQL Proceudre
Hi All, I am trying to search on the Internet if i can call a Python Script from an SQL Procedure. All the information found on Internet is about connecting to a database from Python through a Python script.But, i want the other way round. Any Help will be appreciated -- Thanks and Regards, Amit Goutham Ph:+91-8867801035 -- https://mail.python.org/mailman/listinfo/python-list
[issue24270] PEP 485 (math.isclose) implementation
Tal Einat added the comment: Indeed, it should be. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24270 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Issuing commands using exec_command() of paramiko AND also sending commands together
Hi, Could you be more specific about your problem? Perhaps an example of something similar to what you're trying to do would be helpful. Usually the process is to instantiate paramiko.SSHCLIENT, use the connect() method with desired parameters and execute commands using the exec_command(). If you'd like to process the output of the command execution, then you would store the result of exec_command() into three variables (it return a 3-tuple of Channel objects). i.e com_stdin, com_stdout, com_stderr = my_ssh_client_instance.exec_command(command) The instance of SSHCLIENT is live until the close() method is called. Meaning subsequent commands can be executed the same way. On Wed, Jun 3, 2015 at 8:07 AM, Pythonista kukki.kanch...@gmail.com wrote: Using paramiko's exec_command(), i would like to send a command, process its output and do it for several other commands. I notice that its not quick enough or something like that. How would I handle that scenario AND also providing multiple commands together (there is 1 post on stackoverflow for issuing multiple commands but I am not sure if someone has tried it. It didnt work for me! Thanks! -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
[issue24371] configparser hate dot in option like eth2.6
New submission from Yavuz Selim Komur: [remember] eth2.6 = True eth5 = True eth5 correct but eth2.6 return exception -- components: Extension Modules, Library (Lib) messages: 244730 nosy: Yavuz Selim Komur priority: normal severity: normal status: open title: configparser hate dot in option like eth2.6 versions: Python 3.3, Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24371 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Everything is an object in python - object class and type class
On Wednesday 03 June 2015 03:59, BartC wrote: Javascript primitives include Number and String. What does Python allow to be done with its Number (int, etc) and String types that can't be done with their Javascript counterparts, that makes /them/ objects? That's a good question, and I'm not sure whether or not the answer is nothing, it's just an implementation detail. I don't *think* it is an implementation detail, but I don't know enough about Javascript to be sure. I can see that you can include Numbers in an object without explicitly boxing them: js var foo = 23; js typeof foo; number js var bar = {1: foo}; js typeof bar[1]; number I can also see that you can explicitly box numbers inside objects: js var a = 42; js var b = new Number(42); js a == b; true js a === b; false js typeof a; number js typeof b; object But I don't know enough to tell the practical differences between them. -- Steve -- https://mail.python.org/mailman/listinfo/python-list
[issue20186] Derby #18: Convert 31 sites to Argument Clinic across 23 files
Tal Einat added the comment: Attached is an updated patch for Modules/mathmodule.c. This is based on Georg's patch, updated to apply to current 3.5, with several improvements: * replaced legacy converters * converted math.ceil() and math.floor() functions * converted the new math.gcd() and math.isclose() functions * AC generated code in separate file: Modules/clinic/mathmodule.c.h * this patch doesn't change any internal variable names in the C code -- nosy: +taleinat Added file: http://bugs.python.org/file39602/issue20186.mathmodule.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20186 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Everything is an object in python - object class and type class
On Wednesday 03 June 2015 08:33, Marko Rauhamaa wrote: Grant Edwards invalid@invalid.invalid: On 2015-06-02, Ian Kelly ian.g.ke...@gmail.com wrote: Accepting for the sake of argument that something to be subclassed is a reasonable definition of object, Huh? You can't subclass an object. You can subclass a Class. More to the point: you don't need classes for objects -- even in the deepest OOP sense. That part is true. In Python, classes are little more than constructor functions. But that's not. Classes give you an inheritance hierarchy. They also hold shared state, and behaviour for the instances. -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: What sort of data structure to use?
On 03Jun2015 08:19, David Aldrich david.aldr...@emea.nec.com wrote: I have written a Python utility that performs a certain activity on some predefined sets of files. Here is the outline of what I have written: # File Set A pathA = 'pathA' fileListA = ['fileA1.txt', 'fileA2.txt'] # File Set B pathB = 'pathB' fileListB = ['fileB1.txt', 'fileB2.txt', 'fileB3.txt'] myFunc1(pathA, fileListA) myFunc2(pathA, fileListA) myFunc1(pathB, fileListB) myFunc2(pathB, fileListB) I want to add more file sets, so I really want to add the sets to a list and iterate over the list, calling myFunc1 myFunc2 for each item. My question is: what sort of data structure could I use to organise this, given that I want to associate a set of files with each path and that, for each set, there is an arbitrary number of files? Based on your description I would use a dict keyed on the path, whose values were a set of files. A set is a preprovided data type in Python. Look it up and use it. There are other alternatives, but that would be a first attempt. Cheers, Cameron Simpson c...@zip.com.au -- https://mail.python.org/mailman/listinfo/python-list
Re: What sort of data structure to use?
2015-06-03 10:19 GMT+02:00 David Aldrich david.aldr...@emea.nec.com: Hi I have written a Python utility that performs a certain activity on some predefined sets of files. Here is the outline of what I have written: # File Set A pathA = ‘pathA’ fileListA = [‘fileA1.txt’, ‘fileA2.txt’] # File Set B pathB = ‘pathB’ fileListB = [‘fileB1.txt’, ‘fileB2.txt’, ‘fileB3.txt’] myFunc1(pathA, fileListA) myFunc2(pathA, fileListA) myFunc1(pathB, fileListB) myFunc2(pathB, fileListB) I want to add more file sets, so I really want to add the sets to a list and iterate over the list, calling myFunc1 myFunc2 for each item. My question is: what sort of data structure could I use to organise this, given that I want to associate a set of files with each path and that, for each set, there is an arbitrary number of files? Best regards David -- https://mail.python.org/mailman/listinfo/python-list And if you really want to link the path to the list of files, you could define an object FileList (trivially) implementing the iterator protocol. -- https://mail.python.org/mailman/listinfo/python-list
Re: Please help on this sorted function
On 06/02/2015 01:20 PM, fl wrote: Hi, I try to learn sorted(). With the tutorial example: ff=sorted({1: 'D', 2: 'B', 3: 'B', 4: 'E', 5: 'A'}) ff [1, 2, 3, 4, 5] I don't see what sorted does in this dictionary, i.e. the sequence of 1..5 is unchanged. Could you explain it to me? Thanks, It's best to think of dictionaries as unordered collections of key/value pairs. Dictionaries are not sequences, do not have any particular ordering, and in full generality *can't* be sorted in any sensible way. For instance, this slightly odd (but perfectly legal) dictionary d = {'a':123, 456:'b'} can't be sorted sorted(d) Traceback (most recent call last): File stdin, line 1, in module TypeError: unorderable types: int() str() because it doesn't make sense to order/compare the two keys 'a' and 456. If your dictionary is a little better behaved, say d = {'a':123, 'b':456} you may be able to sort the keys sorted(d) ['a', 'b'] or the values sorted(d.values()) [123, 456] or the key/value tuples (called items) sorted(d.items()) [('a', 123), ('b', 456)] but each of those attempts to sort could fail on a general dictionary if the individual keys or values are not sortable. There is also an implementation of a type of dictionary that remembers the order in which the items are *inserted*. It's in the collections module and called OrderedDict. Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -- https://mail.python.org/mailman/listinfo/python-list
Re: should self be changed?
On Wednesday 03 June 2015 03:19, Marko Rauhamaa wrote: Steven D'Aprano st...@pearwood.info: On Fri, 29 May 2015 12:00 pm, Steven D'Aprano wrote: [...] in a language where classes are themselves values, there is no reason why a class must be instantiated, particularly if you're only using a single instance of the class. Anyone ever come across a named design pattern that involves using classes directly without instantiating them? I'm basically looking for a less inelegant term for instanceless class -- not so much a singleton as a zeroton. C# has these, and calls them static classes. I guess Python has them, too, and calls them modules. Modules play a similar role -- after all, modules and classes are both namespaces. But: - you can't (easily) use inheritance on a module to make a new module, but you can use inheritance on a class; although I think C# prohibits that. - you can't (easily) include more than one module in a single file. -- Steve -- https://mail.python.org/mailman/listinfo/python-list
[issue24270] PEP 485 (math.isclose) implementation
Changes by Berker Peksag berker.pek...@gmail.com: -- resolution: - fixed stage: - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24270 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Everything is an object in python - object class and type class
On Wednesday 03 June 2015 08:49, Dr. Bigcock wrote: You need classes for objects. Anything else, and you're confusing yourself. Not quite. https://en.wikipedia.org/wiki/Prototype-based_programming -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: fork/exec close file descriptors
On Wed, 03 Jun 2015 10:41:44 +0300, Marko Rauhamaa wrote: Alain Ketterlin al...@universite-de-strasbourg.fr.invalid: Marko Rauhamaa ma...@pacujo.net writes: Maybe close() will fail for ever. Your program has to deal with this, something is going wrong, it can't just close and go on. Here's the deal: the child process is saddled with file descriptors it never wanted in the first place. It can't decline them. Now you're saying it can't even dispose of them. No You cab dispose of them you just need to warn the user that the action did not complete correctly there may be errors with the data. Example What does your test editor do if you try to save a file back to a USB stick that has been removed? does it simply let you think the file has been successfully saved? i hope not. The reason this has been allowed to go on is that everybody just closes the file descriptors and ignores the possibility or repercussions of a failure. I haven't read about horror stories of this failing. I readily admit this is very dirty, but since the API doesn't offer a clean alternative, there's nothing you can/should do about it. Marko -- Never be afraid to tell the world who you are. -- Anonymous -- https://mail.python.org/mailman/listinfo/python-list
Re: What sort of data structure to use?
2015-06-03 10:19 GMT+02:00 David Aldrich david.aldr...@emea.nec.com: Hi I have written a Python utility that performs a certain activity on some predefined sets of files. Here is the outline of what I have written: # File Set A pathA = ‘pathA’ fileListA = [‘fileA1.txt’, ‘fileA2.txt’] # File Set B pathB = ‘pathB’ fileListB = [‘fileB1.txt’, ‘fileB2.txt’, ‘fileB3.txt’] myFunc1(pathA, fileListA) myFunc2(pathA, fileListA) myFunc1(pathB, fileListB) myFunc2(pathB, fileListB) I want to add more file sets, so I really want to add the sets to a list and iterate over the list, calling myFunc1 myFunc2 for each item. My question is: what sort of data structure could I use to organise this, given that I want to associate a set of files with each path and that, for each set, there is an arbitrary number of files? Best regards David -- https://mail.python.org/mailman/listinfo/python-list Hi, What about a for loop? paths = [pathA, pathB, pathC] functions = (myFunc1, myFunc2) file_lists = [fileListA, fileListB,fileListC] for path, file_list in zip(paths, file_lists): for f in functions: f(path, file_list) Best -- https://mail.python.org/mailman/listinfo/python-list
Re: fork/exec close file descriptors
Marko Rauhamaa ma...@pacujo.net writes: Alain Ketterlin al...@universite-de-strasbourg.fr.invalid: Marko Rauhamaa ma...@pacujo.net writes: First, if close() fails, what's a poor program to do? Warn the user? Not assume everything went well? It all depends on the application, and what the file descriptor represents. The problem here is in the system call contract, which is broken. There's no fix. The man page admonition is just hand-waving without constructive advice. Try again? Could be a good idea on NFS or other kind of mounts. Maybe close() will fail for ever. Your program has to deal with this, something is going wrong, it can't just close and go on. I can't imagine why one would like to mass-close an arbitrary set of file descriptors, That's standard practice before execking a file. [...] and I think APIs like os.closerange() are toxic and an appeal to sloppy programming. And you recommend what instead? Keeping them around and closing the ones you own, plus doing whatever is necessary to have libraires (loggers, database connectors, etc.) finish properly. And not taking the risk of messing with descriptors your program is not responsible of. -- Alain. -- https://mail.python.org/mailman/listinfo/python-list
Re: Please help on this sorted function
On Wednesday 03 June 2015 06:42, Joonas Liik wrote: my_dict = {1: 'D', 2: 'B', 3: 'A', 4: 'E', 5: 'B'} # dict.items() returns an iterator that returns pairs of (key, value) # pairs the key argument to sorted tells sorted what to sort by, operator.itemgetter is a factory function , itemgetter(1)== lambda iterable: iterable[1] sorted_dict = sorted(my_dict.items(), key=itemgetter(1)) # at this moment sorted dict is a generator of key-value tuples in the right order sorted_dict = OrderedDict(sorted_dict) # turn the generator in to an actual dict. # notice: regular dicts are NOT ORDERED, you need a special type of dict # to preserve the order, hence OrderedDict OrderedDicts preserve the *insertion order*, they don't sort the keys. Ordinary dicts are unordered. The order you see is arbitrary and unpredictable: py d = {} py d['C'] = 1; d['A'] = 2; d['B'] = 3 py d {'A': 2, 'C': 1, 'B': 3} Ordered dicts are ordered by insertion order: py from collections import OrderedDict py d = OrderedDict() py d['C'] = 1; d['A'] = 2; d['B'] = 3 py d OrderedDict([('C', 1), ('A', 2), ('B', 3)]) Python doesn't have a SortedDict, where the keys are kept in sorted order. -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything is an object in python - object class and type class
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: On Wednesday 03 June 2015 08:33, Marko Rauhamaa wrote: In Python, classes are little more than constructor functions. [...] Classes give you an inheritance hierarchy. That's encapsulated in the constructor. From the class user's point of view, it doesn't matter if the object derives its behavior through inheritance or through reimplementation. From the class implementor's point of view, inheritance is syntactic sugar. They also hold shared state, and behaviour for the instances. That's the little more I was referring to. It is Python esoterics that can safely be ignored. Marko -- https://mail.python.org/mailman/listinfo/python-list
[issue24363] httplib fails to handle semivalid HTTP headers
Cory Benfield added the comment: While we're here and I'm recommending to drop as little data as possible: we need to be really careful about not exposing ourselves to any kind of data smuggling attack here. It's really important that we don't let attackers construct bodies of requests or responses that will cause us to misinterpret header blocks. It's therefore going to be really tricky to balance those concerns. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24363 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Calling Python Script from an SQL Proceudre
Amit Goutham agn.91...@gmail.com writes: Hi All, I am trying to search on the Internet if i can call a Python Script from an SQL Procedure. All the information found on Internet is about connecting to a database from Python through a Python script.But, i want the other way round. Any Help will be appreciated Which database are you using? This is how to do it in postgresql, for example: http://www.postgresql.org/docs/current/static/plpython.html -- regards, kushal -- https://mail.python.org/mailman/listinfo/python-list
[issue20186] Derby #18: Convert 31 sites to Argument Clinic across 23 files
Tal Einat added the comment: Attached is an AC conversion patch for Objects/enumobject.c. Note that this file contains the implementations of the 'enumerate' and 'reversed' classes, but *not* the 'Enum' class. This is based on the 3.5 branch. -- Added file: http://bugs.python.org/file39603/issue20186.enumobject.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20186 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24372] Documentation for ssl.wrap_socket's ssl_version parameter is odd
Christian Heimes added the comment: I'd like to deprecate ssl.wrap_socket() in favor of SSLContext.wrap_socket(). Libraries should rather accept a context than expose the awkward interface of ssl.wrap_socket(). A context object is far more powerful and easier to use. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24372 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: python 3.4 use python-gcm can't import
Le vendredi 29 août 2014 10:35:29 UTC+2, Frank Liou a écrit : and body is b' .is empty i'm so confused.don't know it work or not Hi, you should read() before you close() the connection. conn = http.client.HTTPConnection('android.googleapis.com') conn.request('POST', '/gcm/send', jqs, headers) res = conn.getresponse() body = res.read() conn.close() print(body) David -- https://mail.python.org/mailman/listinfo/python-list
[issue24363] httplib fails to handle semivalid HTTP headers
Michael Del Monte added the comment: Given that obs-fold is technically valid, then can I recommend reading the entire header first (reading to the first blank line) and then tokenizing the individual headers using a regular expression rather than line by line? That would solve the problem more elegantly and easily than attempting to read lines on the fly and then unreading the nonconforming lines. Here's my recommendation: def readheaders(self): self.dict = {} self.unixfrom = '' self.headers = hlist = [] self.status = '' # read entire header (read until first blank line) while True: line = self.fp.readline(_MAXLINE+1) if not line: self.status = 'EOF in headers' break if len(line) _MAXLINE: raise LineTooLong(header line) hlist.append(line) if line in ('\n', '\r\n'): break if len(hlist) _MAXHEADERS: raise HTTPException(got more than %d headers % _MAXHEADERS) # reproduce and parse as string header = \n.join(hlist) self.headers = re.findall(r[^ \n][^\n]+\n(?: +[^\n]+\n)*, header) firstline = True for line in self.headers: if firstline and line.startswith('From '): self.unixfrom = self.unixfrom + line continue firstline = False if ':' in line: k,v = line.split(':',1) self.addheader(k, re.sub(\n +, , v.strip())) else: self.status = 'Non-header line where header expected' if self.dict else 'No headers' I think this handles everything you're trying to do. I don't understand the unixfrom bit, but I think I have it right. As for Cory's concern re: smuggling, _MAXLINE and _MAXHEADERS should help with that. The regexp guarantees that every line plus continuation appears as a single header. I use re.sub(\n +, , v.strip()) to clean the value and remove the continuation. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24363 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24372] Documentation for ssl.wrap_socket's ssl_version parameter is odd
Changes by Christian Heimes li...@cheimes.de: -- nosy: +christian.heimes ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24372 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23237] Interrupts are lost during readline PyOS_InputHook processing (reopening)
Michiel de Hoon added the comment: I am uploading an updated version of the patch. I'd be happy to submit a patch to the documentation also, but wasn't able to find it on Mercurial. Can somebody please point me to the right repository for the documentation? -- Added file: http://bugs.python.org/file39608/issue23237.version2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23237 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: fork/exec close file descriptors
Marko Rauhamaa ma...@pacujo.net: So the strategy you proposed is the right one: have the child process ignore any possible errors from os.close(). The parent will have an opportunity to deal with them. And now Linux is back in the good graces, only the man page is misleading. However, the child process needs to be prepared for os.close() to block indefinitely because of an NFS problem or because SO_LINGER has been specified by the parent, for example. Setting the close-on-exec flag doesn't help there. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Can Python function return multiple data?
Am 03.06.2015 um 01:56 schrieb Chris Angelico: and it's pretty convenient. In C, the nearest equivalent is passing a number of pointers as parameters, and having the function fill out values. Python's model is a lot closer to what you're saying than C's model is :) At least, C functions can return structs... Thomas -- https://mail.python.org/mailman/listinfo/python-list
[ANN] Mayavi-4.4.1 release
Hello, Enthought is pleased to announce Mayavi-4.4.1. Mayavi is a general purpose, cross-platform Python package for 2-D and 3-D scientific data visualization. Mayavi integrates seamlessly with numpy and provides a convenient Pythonic wrapper for the VTK API. It provides a high-level visualization API that sits on top of the powerful VTK (http://www.vtk.org) library. It provides a stand-alone UI to help visualize your data. Mayavi is easy to extend and embed in your own dialogs and UIs. For more information see here: http://docs.enthought.com/mayavi/mayavi/index.html Mayavi-4.4.0 is available as part of the free Canopy (https://store.enthought.com/downloads/) packages. 4.4.1 will be available soon. This is a major public release as this is the first public version of Mayavi to support VTK-6.x and also support VTK-5.x. Mayavi-4.4.1 (and 4.4.0) should work with all VTK 6.x releases as well as the latest development version. We did have a 4.4.0 release but did not announce it widely. For more details on the enhancements and fixes please see here: http://docs.enthought.com/mayavi/mayavi/auto/changes.html#mayavi-4-4-1 and here: http://docs.enthought.com/mayavi/mayavi/auto/changes.html#mayavi-4-4-0 This release is important as this will allow us to track major improvements that are part of the VTK-6.x releases. We are thankful to the following for their contributions towards this release: Deepak Surti, Prabhu Ramachandran, Robert Kern, Mark Kness, Ioannis Tziakos, Mark Dickinson, Paul Müller, Gael Varoquaux cheers, Mayavi Developers -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: for...else
On Tuesday, June 2, 2015 at 4:56:57 PM UTC+5:30, acdr wrote: Hi, Currently, in various places in my code, I have the equivalent of: for x in it: if complicated_calculation_1(): cleanup() break complicated_calculation_2() if complicated_calculation_3(): cleanup() break Obviously, I'm repeating myself by having two separate calls to cleanup(). I can't really see a nicer way to do this. (Though I see plenty of non-nice ways to do this, such as adding broken = True in front of every break, and then after the loop is done, have an if broken section.) Other solutions that I'm not particularly fond of can be found on stackexchange, where someone else is trying to do the same thing: http://stackoverflow.com/questions/3296044/opposite-of-python-for-else I'm wondering if there is a demand for expanding the for...else functionality to be expanded also have a block of code that only gets called if the loop is broken out of. I.e.: for x in it: ... then: # break was called ... else: # break was not called ... This question prompts a counter question whose answer Ive been hunting unsuccessfully for a while. The well-known Bohm-Jacopini theorem says that any goto-based program can be de-goto-ized using booleans: http://en.wikipedia.org/wiki/Structured_program_theorem. However there is a complementary theorem (due to Knuth??) that the exact details and sequence of tests performed in the unstructured and the structurized versions may be significantly different. IOW the unstructured program can be significantly more efficient. Does anyone know/have the reference to this other theorem? -- https://mail.python.org/mailman/listinfo/python-list
[issue24375] Performance regression relative to 2.7
New submission from Yury Selivanov: Attached (t.py) is a random script that I stumbled upon pretty randomly on the internet -- someone used it to test different languages VMs performance. The interesting thing is that 2.7 runs it 20-30% faster than 3.4 3.5 consistently. The script does not involve any unicode data manipulation, it's mostly abount float arithmetic and function calls. -- components: Interpreter Core files: t.py messages: 244754 nosy: benjamin.peterson, haypo, ncoghlan, pitrou, yselivanov priority: normal severity: normal status: open title: Performance regression relative to 2.7 versions: Python 3.5, Python 3.6 Added file: http://bugs.python.org/file39609/t.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24375 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Everything is an object in python - object class and type class
On Wed, Jun 3, 2015 at 2:57 AM, Marko Rauhamaa ma...@pacujo.net wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: On Wednesday 03 June 2015 08:33, Marko Rauhamaa wrote: In Python, classes are little more than constructor functions. [...] Classes give you an inheritance hierarchy. That's encapsulated in the constructor. Not entirely true. class A: ... def say_hi(self): ... print(Hello!) ... class B: ... def say_hi(self): ... print(G'day!) ... obj = A() obj.say_hi() Hello! obj.__class__ = B obj.say_hi() G'day! -- https://mail.python.org/mailman/listinfo/python-list
[issue24362] Simplify the fast nodes resize logic in C OrderedDict.
Stefan Krah added the comment: I think this is much nicer, thank you! And the XXX comment looks right, updating od_size could be moved down. I suspect that updating it too early was the cause for #24361, which is also solved by this patch. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24362 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24372] Documentation for ssl.wrap_socket's ssl_version parameter is odd
Eric V. Smith added the comment: I have a requirement to support 2.7.5, so SSLContext is currently a problem for me. I realize that 2.7 could at best get a documentation change. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24372 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24374] Plug refleak in set_coroutine_wrapper
Changes by Yury Selivanov yseliva...@gmail.com: -- nosy: +gvanrossum, haypo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24374 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24363] httplib fails to handle semivalid HTTP headers
Michael Del Monte added the comment: ... or perhaps if ':' in line and line[0] != ':': to avoid the colon-as-first-char bug that plagued this library earlier, though the only ill-effect of leaving it alone would be a header with a blank key; not the end of the world. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24363 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: fork/exec close file descriptors
alister alister.nospam.w...@ntlworld.com: I meant the program that is supplying your app with file handles willy- nilly without caring what happens to them You seem to be advocating a strategy whereby the application keeps close track of all file descriptors and closes them individually as needed. Thing is, processes can be forked by library calls. For example, you might have developed a class that converts a synchronous database API into an asynchronous one. You'll have your object fork a helper process that makes blocking calls while the object methods make sure never to block the caller. The application doesn't know the library would be starting a child process. On the other hand, the library has no idea on what files the application might have open. That's why the library traverses all file descriptors and closes them categorically after forking. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything is an object in python - object class and type class
BartC b...@freeuk.com: To 'variable' and 'type', you might need to add 'value' to make it more complete. 'Value' and 'object' are indeed synonymous as long as you keep in mind that: -12 == -12 True -12 is -12 False IOW, the literal expression -12 happens to construct a fresh value/object each time CPython parses it. You might call such a value an 'object'. The trouble is, Python also uses 'object' to mean the base class of all classes. 'object' is the class of all objects just like 'int' is the class of all integers. So no trouble at all. And it seems to use it in a more abstract sense as well to mean pretty much everything. While other languages, such as C, use object in yet another way. Which is where the term breaks down as it no longer helps in understanding. It's become meaningless. Correct! Abstractions are generalizations of specifics. You can't understand the generalizations before being bored with the specifics first. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: fork/exec close file descriptors
On Wed, 3 Jun 2015 07:38 pm, alister wrote: On Wed, 03 Jun 2015 10:41:44 +0300, Marko Rauhamaa wrote: [...] Here's the deal: the child process is saddled with file descriptors it never wanted in the first place. It can't decline them. Now you're saying it can't even dispose of them. No You cab dispose of them you just need to warn the user that the action did not complete correctly there may be errors with the data. *What* action? Pay closer attention to what Marko wrote: the child process ... How does the child process know what action didn't complete? What error message are you going to display to the user? Error when closing file descriptor 123456 What action do you think the user can take on seeing this error message? Example What does your test editor do if you try to save a file back to a USB stick that has been removed? does it simply let you think the file has been successfully saved? i hope not. Correct me if I'm wrong, but don't you get an error when you try to *open* a file on a missing USB stick? There are at least three opportunities to get an error when writing a file: * opening the file; * writing to the file; * closing the file. It's not clear what conditions will lead to the first two succeeding but the third failing, or what to do if you get such an error. If you don't know what caused close() to fail, then you can't do anything about it, and if you can't do anything about it, what's the point in reporting the error to the user who will just get frustrated and nervous and not be able to do anything about it either? I'm sure that there are circumstances where an error when closing a file is a clear and obvious fault that should be reported. But in the scenario that Marko is describing, I'm not so sure that is the case. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
RE: What sort of data structure to use?
Thanks very much for all the answers given to my question. They help me to think about the problem pythonically. Best regards David -Original Message- From: Python-list [mailto:python-list- bounces+david.aldrich=emea.nec@python.org] On Behalf Of Peter Otten Sent: 03 June 2015 11:59 To: python-list@python.org Subject: Re: What sort of data structure to use? David Aldrich wrote: Hi I have written a Python utility that performs a certain activity on some predefined sets of files. Here is the outline of what I have written: # File Set A pathA = 'pathA' fileListA = ['fileA1.txt', 'fileA2.txt'] # File Set B pathB = 'pathB' fileListB = ['fileB1.txt', 'fileB2.txt', 'fileB3.txt'] myFunc1(pathA, fileListA) myFunc2(pathA, fileListA) myFunc1(pathB, fileListB) myFunc2(pathB, fileListB) I want to add more file sets, so I really want to add the sets to a list and iterate over the list, calling myFunc1 myFunc2 for each item. My question is: what sort of data structure could I use to organise this, given that I want to associate a set of files with each path and that, for each set, there is an arbitrary number of files? I'd start simple and put (path, files) pairs into a list: path_files_pairs = [ (pathA, [fileA1.txt, fileA2.txt, ...]), (pathB, [fileB1.txt, ...]), ] for path, files in path_files_pairs: func1(path, files) func2(path, files) You can always add complications later: import glob import os class VirtualFileset: def __init__(self, folder, pattern): self.folder = folder self.pattern = pattern def __iter__(self): yield self.folder yield glob.glob(os.path.join(self.folder, self.pattern)) path_files_pairs = [ (pathA, [fileA1.txt, fileA2.txt, ...]), (pathB, [fileB1.txt, ...]), VirtualFileset(pathC, *.py), # all python files in directory pathC ] for path, files in path_files_pairs: func1(path, files) func2(path, files) -- https://mail.python.org/mailman/listinfo/python-list Click https://www.mailcontrol.com/sr/51ZWmSF1P47GX2PQPOmvUmaGI8Tu3yGr Vrr5Tv1xM3UP2MNyoKSTyt0rIsjE4onM5MUvmWbo6fT3KeH4!zzvzA== to report this email as spam. -- https://mail.python.org/mailman/listinfo/python-list
Re: Everything is an object in python - object class and type class
On 03/06/2015 13:08, BartC wrote: Come on, we're trying to keep this simple. If we really want to keep it simple, we can take this starting point: http://en.wikipedia.org/wiki/Object_(computer_science) If we agree with the Wikipedia definition: ``In the class-based object-oriented programming paradigm, object refers to a particular instance of a class...`` than we can say in Python everything is an object, because everything is an instance of a class. And of course, object is synonimous for instance: (1, 2, 3).foo Traceback (most recent call last): ... AttributeError: 'tuple' object has no attribute 'foo' -- Marco Buttu INAF-Osservatorio Astronomico di Cagliari Via della Scienza n. 5, 09047 Selargius (CA) Phone: 070 711 80 217 Email: mbu...@oa-cagliari.inaf.it -- https://mail.python.org/mailman/listinfo/python-list
Re: fork/exec close file descriptors
random...@fastmail.us: Why does the child process need to report the error at all? The parent process will find out naturally when *it* tries to close the same file descriptor. That's not how it goes. File descriptors are reference counted in the Linux kernel. Closes are no-ops except for the last one that brings the reference count to zero. If the parent should close the file before the child, no error is returned to the parent. Marko -- https://mail.python.org/mailman/listinfo/python-list