RE: [Tutor] Getting a Process.start() error pickle.PicklingError: Can't pickle : it's not found as __builtin__.module with Python 2.7
Unfortunately, Alan, even though 2.7 was considered pickled, people keep taking it back out of the bottle and wondering why it does not work so well! There are companies like Microsoft and Samsung that let people know their OS on their devices will no longer be supported with updates and some apps may no longer work if downloaded. And, yet, I bet for years afterwards, people will refuse to upgrade because they don't want to replace equipment or even learn a new slightly different interface. Having said that, I understand many people are stuck for various reasons and are required to use whatever version is officially allowed. For some questions, answers may still be provided. There are some workarounds or even newer packages designed to do what is not otherwise available. But many of us here may not be answering the questions as we have no reason to be able to access the old software or interest. -Original Message- From: Tutor On Behalf Of Alan Gauld via Tutor Sent: Tuesday, September 3, 2024 4:41 AM To: tu...@python.org Cc: python-list@python.org Subject: Re: [Tutor] Getting a Process.start() error pickle.PicklingError: Can't pickle : it's not found as __builtin__.module with Python 2.7 On 02/09/2024 15:00, marc nicole via Python-list wrote: > Hello, > > I am using Python 2.7 on Windows 10 Others have pointed out that 2.7 is unsupported and has been for many years now. Its also inferior in most respects including its error reporting. If possible you should upgrade to 3.X > from multiprocessing import Process > def do_something(text): > print(text) > if __name__ == "__main__": > q = Process(target=do_something,args=("somecmd") ) > q.start() > # following code should execute right after the q.start() call So what does happen? If you put a print statement here does it execute before or after the error message? It might make things easier to debug(clearer error traceback) if you put the code to create the thread into a separate function? def do_Something(text)... def start(fn): q = Process q.start() if __name_ start(do_something) print('Something here') > But getting the error at the call of Process().start(): > pickle.PicklingError: Can't pickle : it's not found as > __builtin__.module But please show us the full error trace even if its not much. Also check your module naming, is there a possibility you've named your file do_something.py or similar? (I'm guessing the function is what is being pickled?) > anybody could provide an alternative to call the function do_something() in > a separate thread ? Why not just use the Threading module? If it's as simple as just running something in a thread multiprocessing is probably not needed. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - tu...@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor -- https://mail.python.org/mailman/listinfo/python-list
Re: Getting a Process.start() error pickle.PicklingError: Can't pickle : it's not found as __builtin__.module with Python 2.7
On 9/2/24 11:36, Barry Scott wrote: On 2 Sep 2024, at 15:00, marc nicole via Python-list wrote: I am using Python 2.7 on Windows 10 Why? Install Python 3.12 and it will be easier to get help and support. If you have legacy that still needs porting then you can install 3.12 along side the unsupported 3.12. Barry I think you mean alongside the unsupported 2.7. -- https://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] Getting a Process.start() error pickle.PicklingError: Can't pickle : it's not found as __builtin__.module with Python 2.7
Hello Alan, Thanks for the reply, Here's the code I tested for the debug: import time from multiprocessing import Process def do_Something(): print('hello world!') def start(fn): p = Process(target=fn, args=()) p.start() def ghello(): print ("hello world g") def fhello(): print('hello world f') if __name__ == "__main__": start(do_something) print("executed") exit(0) but neither "Hello World" or "Executed" are displayed in the console which finishes normally without returning any message. Module naming is OK and don't think it is a problem related to that. Now the question, when to use Process/Multiprocess and when to use Threading in Python?.Thread is there a distinctive use case that can showcase when to use either? are they interchangeable? to note that using Threading the console DID display the messages correctly! Thanks. Le mar. 3 sept. 2024 à 10:48, Alan Gauld via Tutor a écrit : > On 02/09/2024 15:00, marc nicole via Python-list wrote: > > Hello, > > > > I am using Python 2.7 on Windows 10 > > Others have pointed out that 2.7 is unsupported and has > been for many years now. Its also inferior in most > respects including its error reporting. > If possible you should upgrade to 3.X > > > from multiprocessing import Process > > def do_something(text): > > print(text) > > if __name__ == "__main__": > > q = Process(target=do_something,args=("somecmd") ) > > q.start() > > # following code should execute right after the q.start() call > > So what does happen? If you put a print statement here does it execute > before or after the error message? It might make things easier to > debug(clearer error traceback) if you put the code to create the thread > into a separate function? > > def do_Something(text)... > > def start(fn): > q = Process >q.start() > > if __name_ >start(do_something) >print('Something here') > > > > But getting the error at the call of Process().start(): > > pickle.PicklingError: Can't pickle : it's not found as > > __builtin__.module > > But please show us the full error trace even if its not much. > > Also check your module naming, is there a possibility > you've named your file do_something.py or similar? > (I'm guessing the function is what is being pickled?) > > > anybody could provide an alternative to call the function do_something() > in > > a separate thread ? > > Why not just use the Threading module? > If it's as simple as just running something in a > thread multiprocessing is probably not needed. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- https://mail.python.org/mailman/listinfo/python-list
Re: Getting a Process.start() error pickle.PicklingError: Can't pickle : it's not found as __builtin__.module with Python 2.7
> On 2 Sep 2024, at 15:00, marc nicole via Python-list > wrote: > > I am using Python 2.7 on Windows 10 Why? Install Python 3.12 and it will be easier to get help and support. If you have legacy that still needs porting then you can install 3.12 along side the unsupported 3.12. Barry -- https://mail.python.org/mailman/listinfo/python-list
Getting a Process.start() error pickle.PicklingError: Can't pickle : it's not found as __builtin__.module with Python 2.7
Hello, I am using Python 2.7 on Windows 10 and I want to launch a process independently of the rest of the code so that the execution continues while the started process proceeds. I am using Process().start() from Python 2.7 as follows: from multiprocessing import Process def do_something(text): print(text) if __name__ == "__main__": q = Process(target=do_something,args=("somecmd") ) q.start() # following code should execute right after the q.start() call (not until it returns) . But getting the error at the call of Process().start(): pickle.PicklingError: Can't pickle : it's not found as __builtin__.module anybody could provide an alternative to call the function do_something() in a separate thread ? -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On Sun, Nov 13, 2022 at 4:45 PM DFS wrote: > In code, list.clear is just ignored. > At the terminal, list.clear shows > > > > in code: > x = [1,2,3] > x.clear > print(len(x)) > 3 > > at terminal: > x = [1,2,3] > x.clear > > print(len(x)) > 3 > > > Caused me an hour of frustration before I noticed list.clear() was what > I needed. > > x = [1,2,3] > x.clear() > print(len(x)) > 0 > > -- > https://mail.python.org/mailman/listinfo/python-list I'm not 100% sanguine about properties, but the fact is they are part of the language: $ cat p below cmd output started 2022 Fri Nov 25 07:54:42 AM PST #!/usr/bin/env python3 class P: def __init__(self): self.count = 0 @property def increment(self): self.count += 1 def result(self): return self.count p = P() p.increment p.increment print(p.result()) above cmd output done2022 Fri Nov 25 07:54:42 AM PST dstromberg@tp-mini-c:~/src/experiments/property x86_64-pc-linux-gnu 2670 $ ./p below cmd output started 2022 Fri Nov 25 07:54:44 AM PST 2 As you can see, if the interpreter refused to do something with p.increment because it has no parens, the meaning of this code would change significantly. -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On Thu, 24 Nov 2022 at 06:26, Stefan Ram wrote: > > Jon Ribbens writes: > >If you want to catch this sort of mistake automatically then you need > >a linter such as pylint: > > output > > , line 1 > list.clear > Warning: Attribute used as statement. > > , line 5 > list.clear > Warning: Attribute used as statement. > > source code > > import ast, sys > > def check( point, source ): > if isinstance( point, ast.Expr ) and\ > type( point.value )== ast.Attribute: > print( ", line", point.lineno, file=sys.stderr ) > print( source.split( '\n' )[ point.lineno-1 ], file=sys.stderr ) > print\ > ( "Warning:", "Attribute used as statement.", file=sys.stderr ) > print() > > def mylinter( source ): > for point in ast.walk( ast.parse( example )): >check( point, source ) > > example = """\ > list.clear > list.clear() > x = list.clear > print( list.clear ) > list.clear > """ > > mylinter( example ) > Uhh, yes? You just created an extremely simplistic linter. Your point? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
RE: In code, list.clear doesn't throw error - it's just ignored
Yes, Chris, that is a REPL feature and one that people may use interactively. As you note, it does not work inside something like a function which the REPL is not trying to evaluate and print. So clearly my supposed use would not make much sense in such code. -Original Message- From: Python-list On Behalf Of Chris Angelico Sent: Tuesday, November 15, 2022 6:16 PM To: python-list@python.org Subject: Re: In code, list.clear doesn't throw error - it's just ignored On Wed, 16 Nov 2022 at 10:11, wrote: > > That is clear, Cameron, but on my python interpreter values evaluated > on the command line ARE saved: > > >>> numb = 5 > >>> 5 + numb > 10 > >>> numb > 5 > >>> _ + _ + 1 > 11 That's a REPL feature. ChrisA -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On Wed, 16 Nov 2022 at 10:11, wrote: > > That is clear, Cameron, but on my python interpreter values evaluated on the > command line ARE saved: > > >>> numb = 5 > >>> 5 + numb > 10 > >>> numb > 5 > >>> _ + _ + 1 > 11 That's a REPL feature. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
RE: In code, list.clear doesn't throw error - it's just ignored
That is clear, Cameron, but on my python interpreter values evaluated on the command line ARE saved: >>> numb = 5 >>> 5 + numb 10 >>> numb 5 >>> _ + _ + 1 11 >>> _ * 2 22 >>> The point is that a dummy variable of _ is assigned and re-assigned at each step and there can be a valid, if not very useful, reason to evaluating it and storing a result. If the darn thing is a very long name like alpha.beta.gamma.delta.epsilon then code that uses it repeatedly in the very next line can be much simpler by using _ repeatedly and perhaps more efficient. Consider: negsq = _ * -_ versus negsq = alpha.beta.gamma.delta.epsilon * - alpha.beta.gamma.delta.epsilon So does your linter now need to look ahead and see if "_" is used properly in the next line? Note it can also be used on the LHS where it means something else. Still, I grant generally a naked evaluation is generally an error. LOL! -Original Message- From: Python-list On Behalf Of Cameron Simpson Sent: Tuesday, November 15, 2022 4:13 AM To: python-list@python.org Subject: Re: In code, list.clear doesn't throw error - it's just ignored On 15Nov2022 00:45, avi.e.gr...@gmail.com wrote: >What would be the meaning of an ordering relation determining what is >MORE VALID? Are you asking what criterion would rate: clearx = x.clear as "more" valid than: x.clear on its own? I don't want to speak for the OP, but I'd think the OP's issue is that the bare `x.clear` is evaluated but not stored in a variable. As a metric, we might gather various descriptive statements we could make about these statements. They'd perhaps include "is legal Python code", "is pretty simple". The former line could include "saves the expression value in a variable for later use" and the latter could not. That's a comparison test you could use for ordering. My own opinion is that a bare: x.clear is legal and valid for all the example use cases already mentioned, but an entirely valid target for complaint by a linter, whose task is to point out dodgy looking stuff for review by the author. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 15Nov2022 00:45, avi.e.gr...@gmail.com wrote: What would be the meaning of an ordering relation determining what is MORE VALID? Are you asking what criterion would rate: clearx = x.clear as "more" valid than: x.clear on its own? I don't want to speak for the OP, but I'd think the OP's issue is that the bare `x.clear` is evaluated but not stored in a variable. As a metric, we might gather various descriptive statements we could make about these statements. They'd perhaps include "is legal Python code", "is pretty simple". The former line could include "saves the expression value in a variable for later use" and the latter could not. That's a comparison test you could use for ordering. My own opinion is that a bare: x.clear is legal and valid for all the example use cases already mentioned, but an entirely valid target for complaint by a linter, whose task is to point out dodgy looking stuff for review by the author. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
RE: In code, list.clear doesn't throw error - it's just ignored
Cameron, What would be the meaning of an ordering relation determining what is MORE VALID? As has been pointed out, not only are some uses that look odd sometimes valid, but perhaps even can be used in ways you simply may not see, such as side effects. Some examples ranging from poor to horrible are mentioned below. In some languages, trying to access a variable that is not properly existing or initialized, can generate an error, as an example, which may cause the current function to terminate if not caught and jump up the call chain till an error handler is found. Code like: 1/0 May seem meaningless as the result is not saved, but may trigger a divide by zero error. Is it an error to write code like: If x.clear: pass I suspect it is possible to write quite weird code that might pass most linters but that does nothing useful and also to write code that is useful but might be disparaged by many interpreters or linters. My example above is a fairly common code pattern while code is being written as a sort of reminder to perhaps come back later and flesh it out properly, or remove it if it is no longer applicable. If so, it would be reasonable for it to be challenged and also to ignore such warnings until later when either it is gone, or the code hint should be gone. There are many cases where short-circuit evaluation means code is not run such as "True || x" that is less obvious but equally bypassed if you set a variable to True and do not change it and use it instead of True above. But is it an error? What if again, my later goal is to add code that may change the Truth value. As it is, the statement is not evaluated. But it may be set up as a placeholder to enhance later, perhaps long after, or retain some flexibility. Insisting it be removed might be too harsh while a warning might be reasonable. Yet again, it is not always an error to not use something like declaring a variable you might need or importing a module you never use. Code is chock full of such things in mid-stream. And you can deliberately ignore some things without it being a mistake as in: ( _, mean, _) = minMeanMax(args) Sure, it may be overkill to call a function that returns three things then ignore two of them. So what? What if instead of "_" I used real variable names like min and max? Should I get error messages that two variable are set up with values but never again used? Or consider what I sometimes do when I write code that someone else will use and to test it I must use something like a different filename/path on my machine than they do on theirs. I might write code like # Comment out one or more of the below so only one exists: Place = "whatever" Place = "Some other place" Clearly if I am using the second one, I can comment the first out OR I can leave it alone and at minor expenses let the variable be unconditionally reset to the second value. Is it a bug or a feature? I could go on with other examples including some more subtle ones like declaring a variable name just to mask another variable from being accessible from a higher level and perhaps prevent the interpreter or compiler optimizing it away by using it in the meaningless way this discussion began with as it has been accessed once. One person's bug can be another person's feature. And clearly, as has been mentioned, there MAY be subtle side effects like invoking your custom setter or dunder method which also does logging or increments a count. There is a spectrum between being overly permissive and overly strict. This case almost amuses me because of the way that many a REPL works so something run directly in a console will take an expression like "varname" and PRINT the current value to the screen. If the same code is run from a file, or from inside some function, it does nothing useful and you need something like "print(varname)" instead. People often cut and paste such snippets of code and in one context they did something and in another, it seems meaningless and possibly an error. -Original Message- From: Python-list On Behalf Of Cameron Simpson Sent: Monday, November 14, 2022 9:34 PM To: python-list@python.org Subject: Re: In code, list.clear doesn't throw error - it's just ignored On 14Nov2022 19:15, Dennis Lee Bieber wrote: > There is also the minor facet that "x.clear" can be bound to a >different name... > >>>> x = [1, 2, 3.145926536, "Pie"] >>>> clearx = x.clear >>>> x >[1, 2, 3.145926536, 'Pie'] >>>> clearx() >>>> x >[] >>>> I think the OP would take the stance that this: clearx = x.clear is more valid than: x.clear which discards the return value of the expression. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 14Nov2022 19:15, Dennis Lee Bieber wrote: There is also the minor facet that "x.clear" can be bound to a different name... x = [1, 2, 3.145926536, "Pie"] clearx = x.clear x [1, 2, 3.145926536, 'Pie'] clearx() x [] I think the OP would take the stance that this: clearx = x.clear is more valid than: x.clear which discards the return value of the expression. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On Tue, 15 Nov 2022 09:11:10 +1100, Cameron Simpson declaimed the following: >On 13Nov2022 22:23, DFS wrote: >>This is an easy check for the interpreter to make. > >It really isn't, given that (a) this isn't known by the interpreter to >be a `list` until runtime and (b) that would need embedding special >knowledge that looking up an attribute on a `list` has no side effects >(versus some other things, where it is not the case). > There is also the minor facet that "x.clear" can be bound to a different name... >>> x = [1, 2, 3.145926536, "Pie"] >>> clearx = x.clear >>> x [1, 2, 3.145926536, 'Pie'] >>> clearx() >>> x [] >>> -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 13Nov2022 22:23, DFS wrote: On 11/13/2022 9:11 PM, Chris Angelico wrote: [ ... `x.clear` ... ] No part of it is invalid, so nothing causes a problem. For instance, you can write this: If it wastes time like that it's invalid. It's a valid expression. It looks to your eye like a no-op, but at actually Python _looks up the name `clear`_ on an object (which happens to be a `list`). That is a real thing to do, and can have side effects. While most of the examples here have been in the REPL where running an expression with no side effects is itself useful, because the REPL can print the result, I've personally got some real world code with a bare `some_object.attribute` line. I'm not sure where, or I'd show it, but I _think_ it was probably prepriming a cached object property. There might have been a more expressive way to do that, but it was a bare attribute lookup with side effects, _used for those side effects_. This is an easy check for the interpreter to make. It really isn't, given that (a) this isn't known by the interpreter to be a `list` until runtime and (b) that would need embedding special knowledge that looking up an attribute on a `list` has no side effects (versus some other things, where it is not the case). Linters are the best place for this: they warn about probably-mistakes idioms like this, and can have slightly deep knowledge of the code's semantics sometimes. If I submit a suggestion to python-list@python.org will it just show up here? Or do the actual Python devs intercept it? Nah, it'll go through. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On Tue, 15 Nov 2022 at 05:57, Stefan Ram wrote: > > Michael Speer writes: > >Python doesn't care what an expression returns. > > In my English, functions return values, > expression are being evaluated to a value. > The evaluation of a function yields or > produces a value. Expressions do not return, > because they are not functions. > Well, you can dispute the terminology all you like, but there's no real difference between function calls and other types of expression. They're all just expressions and they can be combined arbitrarily. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 2022-11-14, Stefan Ram wrote: > Jon Ribbens writes: >>"""Create an array and print its length""" >>array = [1, 2, 3] >>array.clear > > BTW: Above, there are /two/ expression statements > with no effect; the other one is > > """Create an array and print its length""" > > . Apparently, linters know this and will not create > a warning for such string literals. Not only do they know this, pylint will complain if you *don't* include that line, which is why I included it ;-) -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
The terminal told you what x.clear was. The Python documentation tells you how to call it: https://docs.python.org/3/tutorial/datastructures.html list.clear() Remove all items from the list. Equivalent to del a[:]. An IDE (e.g. PyCharm) will try to autocomplete the parentheses and warn you if you don’t: “Statement seems to have no effect and can be replaced with a function call to have effect” From: Python-list on behalf of DFS Date: Sunday, November 13, 2022 at 7:46 PM To: python-list@python.org Subject: In code, list.clear doesn't throw error - it's just ignored *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** In code, list.clear is just ignored. At the terminal, list.clear shows in code: x = [1,2,3] x.clear print(len(x)) 3 at terminal: x = [1,2,3] x.clear print(len(x)) 3 Caused me an hour of frustration before I noticed list.clear() was what I needed. x = [1,2,3] x.clear() print(len(x)) 0 -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!jRrjG0fRo46VyY0jLfD1Z5C6tXDiphZy8zi2AqN_N5BB1_OwBe_wxmsBWmIVOFQDdZnvbRq1JNeGnPg$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!jRrjG0fRo46VyY0jLfD1Z5C6tXDiphZy8zi2AqN_N5BB1_OwBe_wxmsBWmIVOFQDdZnvbRq1JNeGnPg$> -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
Am Mon, Nov 14, 2022 at 02:13:34AM + schrieb MRAB: > But if it's an expression where it's expecting a statement and it's not a > call, then > it's probably a bug. That "probably" makes it suitable for a linter, as was pointed out. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
Op 14/11/2022 om 4:23 schreef DFS: On 11/13/2022 9:11 PM, Chris Angelico wrote: On Mon, 14 Nov 2022 at 11:53, DFS wrote: On 11/13/2022 5:20 PM, Jon Ribbens wrote: On 2022-11-13, DFS wrote: In code, list.clear is just ignored. At the terminal, list.clear shows in code: x = [1,2,3] x.clear print(len(x)) 3 But why is it allowed in the first place? I stared at list.clear and surrounding code a dozen times and said "Looks right! Why isn't it clearing the list?!?!" 2 parens later and I'm golden! No part of it is invalid, so nothing causes a problem. For instance, you can write this: If it wastes time like that it's invalid. It's not invalid. In the REPL for example, it does something useful: >>> x = [1, 2, 3] >>> x.clear Others have shown instances where writing a method or function without calling it are useful in a script too. There are languages that handle this differently. Ruby, for example, calls the function/method even when you don't write the parens, if I'm not mistaken. Personally I don't like that; I much prefer Python's explicitness in making the difference between the value of a function and calling that function. Still, there's something to be said for warnings. I agree with others that such warnings are more the job for a linter than for the language. FWIW I've been bitten by this in C++ once. I wanted to write something like if (some_condition()) foo(); But I forgot the parens after some_condition, so C++ evaluated the function pointer (which was non-NULL so evaluated is true in a boolean context) instead of the return value, and therefore foo() got called unconditionally. -- "Don't Panic." -- Douglas Adams, The Hitchhiker's Guide to the Galaxy -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 14/11/2022 12.12, DFS wrote: On 11/13/2022 5:20 PM, Jon Ribbens wrote: On 2022-11-13, DFS wrote: In code, list.clear is just ignored. At the terminal, list.clear shows in code: x = [1,2,3] x.clear print(len(x)) 3 at terminal: x = [1,2,3] x.clear print(len(x)) 3 Caused me an hour of frustration before I noticed list.clear() was what I needed. x = [1,2,3] x.clear() print(len(x)) 0 If you want to catch this sort of mistake automatically then you need a linter such as pylint: $ cat test.py """Create an array and print its length""" array = [1, 2, 3] array.clear print(len(array)) $ pylint -s n test.py * Module test test.py:4:0: W0104: Statement seems to have no effect (pointless-statement) Thanks, I should use linters more often. But why is it allowed in the first place? I stared at list.clear and surrounding code a dozen times and said "Looks right! Why isn't it clearing the list?!?!" 2 parens later and I'm golden! It looks 'right' because it is 'right'! However, compared with what was intended, it was 'wrong'! « I really hate this d***umb machine, I wish that they would sell it. It never does quite what I want, but only what I tell it! » Lifting some text from a recent PUG-meeting: «Distinguishing functions and their names: Please remind yourself that is_odd is the name of a function, whereas is_odd() calls the function and could thus be considered a 'label' for the returned-value – either approach could be used in different situations. » In this case, the subject is a method, and accordingly has a slightly different flavor. Rather than a return-value, the impact is an effect within the scope and/or to the state of the object. However, not materially-different from the OP's question. It is assumed that there is no difficulty related to calling the function, eg len( x ). So, why would we use the function/method by name instead of its asking for its return-value? (please remember that a Python function is a "first class" object) The (above) Challenge to PUG-members was to use code which produces the Fibonacci Sequence, and out of the first 16 values, return the number of Fibonacci-values which are also odd-numbers. We started with straight-line code which mixed-up these various steps in the process. As the challenge continued, such tangling made it very difficult to enable any variations. To illustrate the SRP and DIP (Single Responsibility and Dependency Inversion Principles of SOLID Architecture), we refactored and refactored, ending-up with: values_counted = sm.sequence_select_and_project( fg.fibonacci_generator, is_odd, limit, ) sequence_select_and_project is a for-loop spanning two if-statements which count or break fibonacci_generator is self-explanatory (hopefully) is_odd returns boolean advice limit is 16 Note how the first two arguments are [generator-]function names, cf function-calls! Now for 'the magic' of a dependency-inverted plug-in architecture:- If the 16 is changed to 32, we'll be comfortable with the idea that twice as many values will be generated and considered. So, think about changing the generator to produce (say) prime numbers. Alternately, alter the program to count only values divisible by two (perhaps using "is_even" as function-name). By 'plugging-in' a different function-name, the above control-routine can be used with any suitably-lengthy sequence as its data-source, and/or selection-criteria function! Accordingly, using the name of a function can be as useful as using the result of a function-call - even if the latter is far more common. -- -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On Mon, 14 Nov 2022 at 18:00, Greg Ewing wrote: > > On 14/11/22 3:13 pm, MRAB wrote: > > But if it's an expression where it's expecting a statement and it's not > > a call, then it's probably a bug. > > The key word there is "probably". If there's any chance it > could be not a bug, it can't be an error. At most it should > be a warning, and that's what linters are for. I wouldn't > like the core interpreter to be producing a bunch of warnings > for things like this. > Notably, linters can be taught about more complex idioms, like: try: raw_input except NameError: raw_input = input which is an easy way to make polyglot Py2/Py3 code that handles the presence/absence of a particular name. Or, similarly: try: os.sendfile except AttributeError: ... # cope with sendfile not being available When os.sendfile exists, it's a completely useless expression. When it doesn't, it's an error. But the difference between those two is crucial. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 14/11/22 3:13 pm, MRAB wrote: But if it's an expression where it's expecting a statement and it's not a call, then it's probably a bug. The key word there is "probably". If there's any chance it could be not a bug, it can't be an error. At most it should be a warning, and that's what linters are for. I wouldn't like the core interpreter to be producing a bunch of warnings for things like this. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
Python doesn't care what an expression returns. You've written an expression that returns the value of the 'clear' function that is bound to that particular list. The interpreter doesn't know or care if accessing that 'clear' attribute on the class returns a function or for some reason triggers a bunch of side effects that the author decided they wanted to use __getattr__ to trigger. 'list.clear' might be a perfectly reasonable expression in some library. I'd rather it not be, but hey, there are millions of python programmers making all kinds of code out there arbitrary expressions can have arbitrary effects. just because a value isn't assigned, returned or used as an argument to a function doesn't mean it isn't doing anything. you might then want python to inspect the result of the function, but how can python know if the author isn't purposely ignoring the return value of the expression? people can call functions that return values for only their side effects. if you can't tell by the form of the expression or the value it returns, what is the linter supposed to look for? what is the interpreter supposed to look for? if you want to avoid accidentally failing to clear a list during a function, you should write tests that check that various inputs to the function produce the expected outputs. 'unit tests' are a good place to make sure that code is acting as you want it to for one-off scripts, you should always make the thing dry-run or convert from an input to an output (rather than in-place) so you can rerun them a few times and make sure they're doing what you want. sometimes making sure things are right is just on you. there will always be the occasional silly error in a script that is hard to see until you step away for a moment. stepping away and coming back is a pretty good thing to do if you're stuck on something that feels impossible. On Sun, Nov 13, 2022 at 10:33 PM DFS wrote: > On 11/13/2022 9:11 PM, Chris Angelico wrote: > > On Mon, 14 Nov 2022 at 11:53, DFS wrote: > >> > >> On 11/13/2022 5:20 PM, Jon Ribbens wrote: > >>> On 2022-11-13, DFS wrote: > >>>> In code, list.clear is just ignored. > >>>> At the terminal, list.clear shows > >>>> > >>>> > >>>> > >>>> in code: > >>>> x = [1,2,3] > >>>> x.clear > >>>> print(len(x)) > >>>> 3 > >>>> > >>>> at terminal: > >>>> x = [1,2,3] > >>>> x.clear > >>>> > >>>> print(len(x)) > >>>> 3 > >>>> > >>>> > >>>> Caused me an hour of frustration before I noticed list.clear() was > what > >>>> I needed. > >>>> > >>>> x = [1,2,3] > >>>> x.clear() > >>>> print(len(x)) > >>>> 0 > >>> > >>> If you want to catch this sort of mistake automatically then you need > >>> a linter such as pylint: > >>> > >>> $ cat test.py > >>> """Create an array and print its length""" > >>> > >>> array = [1, 2, 3] > >>> array.clear > >>> print(len(array)) > >>> $ pylint -s n test.py > >>> * Module test > >>> test.py:4:0: W0104: Statement seems to have no effect > (pointless-statement) > >> > >> > >> Thanks, I should use linters more often. > >> > >> But why is it allowed in the first place? > >> > >> I stared at list.clear and surrounding code a dozen times and said > >> "Looks right! Why isn't it clearing the list?!?!" > >> > >> 2 parens later and I'm golden! > >> > > > > No part of it is invalid, so nothing causes a problem. For instance, > > you can write this: > > > If it wastes time like that it's invalid. > > This is an easy check for the interpreter to make. > > If I submit a suggestion to python-list@python.org will it just show up > here? Or do the actual Python devs intercept it? > > > > > > > >>>> 1 > > > > And you can write this: > > > >>>> 1 + 2 > > > > And you can write this: > > > >>>> print(1 + 2) > > > > But only one of those is useful in a script. Should the other two be > > errors? No. But linters WILL usually catch them, so if you have a good > > linter (especially built into your editor), you can notice these > > things. > > > ran pylint against it and got 0.0/10. > > > --disable= > invalid-name > multiple-statements > bad-indentation > line-too-long > trailing-whitespace > missing-module-docstring > missing-function-docstring > too-many-lines > fixme > > > and got 8.9/10. > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 11/13/2022 9:11 PM, Chris Angelico wrote: On Mon, 14 Nov 2022 at 11:53, DFS wrote: On 11/13/2022 5:20 PM, Jon Ribbens wrote: On 2022-11-13, DFS wrote: In code, list.clear is just ignored. At the terminal, list.clear shows in code: x = [1,2,3] x.clear print(len(x)) 3 at terminal: x = [1,2,3] x.clear print(len(x)) 3 Caused me an hour of frustration before I noticed list.clear() was what I needed. x = [1,2,3] x.clear() print(len(x)) 0 If you want to catch this sort of mistake automatically then you need a linter such as pylint: $ cat test.py """Create an array and print its length""" array = [1, 2, 3] array.clear print(len(array)) $ pylint -s n test.py * Module test test.py:4:0: W0104: Statement seems to have no effect (pointless-statement) Thanks, I should use linters more often. But why is it allowed in the first place? I stared at list.clear and surrounding code a dozen times and said "Looks right! Why isn't it clearing the list?!?!" 2 parens later and I'm golden! No part of it is invalid, so nothing causes a problem. For instance, you can write this: If it wastes time like that it's invalid. This is an easy check for the interpreter to make. If I submit a suggestion to python-list@python.org will it just show up here? Or do the actual Python devs intercept it? 1 And you can write this: 1 + 2 And you can write this: print(1 + 2) But only one of those is useful in a script. Should the other two be errors? No. But linters WILL usually catch them, so if you have a good linter (especially built into your editor), you can notice these things. ran pylint against it and got 0.0/10. --disable= invalid-name multiple-statements bad-indentation line-too-long trailing-whitespace missing-module-docstring missing-function-docstring too-many-lines fixme and got 8.9/10. -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 2022-11-14, Greg Ewing wrote: > On 14/11/22 1:31 pm, Jon Ribbens wrote: >> On 2022-11-13, DFS wrote: >>> But why is it allowed in the first place? >> >> Because it's an expression, and you're allowed to execute expressions. > > To put it a bit more clearly, you're allowed to evaluate > an expression and ignore the result. ... because it may have side effects, and it's not possible to determine whether it will or not in advance. -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On Mon, 14 Nov 2022 at 13:18, MRAB wrote: > > On 2022-11-14 00:55, Greg Ewing wrote: > > On 14/11/22 1:31 pm, Jon Ribbens wrote: > >> On 2022-11-13, DFS wrote: > >>> But why is it allowed in the first place? > >> > >> Because it's an expression, and you're allowed to execute expressions. > > > > To put it a bit more clearly, you're allowed to evaluate > > an expression and ignore the result. > > > But if it's an expression where it's expecting a statement and it's not > a call, then it's probably a bug. Maybe, but I'd be dubious of making it that simplistic. For instance, which of these is more likely to be useless? spam or ham() spam() or ham Syntactically, both of them are 'or' expressions, but one of them is almost certainly unnecessary, while the other is just an oddly-written conditional statement and most definitely useful. In any case, this is the job of linters, NOT the language itself. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 2022-11-14 00:55, Greg Ewing wrote: On 14/11/22 1:31 pm, Jon Ribbens wrote: On 2022-11-13, DFS wrote: But why is it allowed in the first place? Because it's an expression, and you're allowed to execute expressions. To put it a bit more clearly, you're allowed to evaluate an expression and ignore the result. But if it's an expression where it's expecting a statement and it's not a call, then it's probably a bug. -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On Mon, 14 Nov 2022 at 11:53, DFS wrote: > > On 11/13/2022 5:20 PM, Jon Ribbens wrote: > > On 2022-11-13, DFS wrote: > >> In code, list.clear is just ignored. > >> At the terminal, list.clear shows > >> > >> > >> > >> in code: > >> x = [1,2,3] > >> x.clear > >> print(len(x)) > >> 3 > >> > >> at terminal: > >> x = [1,2,3] > >> x.clear > >> > >> print(len(x)) > >> 3 > >> > >> > >> Caused me an hour of frustration before I noticed list.clear() was what > >> I needed. > >> > >> x = [1,2,3] > >> x.clear() > >> print(len(x)) > >> 0 > > > > If you want to catch this sort of mistake automatically then you need > > a linter such as pylint: > > > >$ cat test.py > >"""Create an array and print its length""" > > > >array = [1, 2, 3] > >array.clear > >print(len(array)) > >$ pylint -s n test.py > >* Module test > >test.py:4:0: W0104: Statement seems to have no effect > > (pointless-statement) > > > Thanks, I should use linters more often. > > But why is it allowed in the first place? > > I stared at list.clear and surrounding code a dozen times and said > "Looks right! Why isn't it clearing the list?!?!" > > 2 parens later and I'm golden! > No part of it is invalid, so nothing causes a problem. For instance, you can write this: >>> 1 And you can write this: >>> 1 + 2 And you can write this: >>> print(1 + 2) But only one of those is useful in a script. Should the other two be errors? No. But linters WILL usually catch them, so if you have a good linter (especially built into your editor), you can notice these things. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 14/11/22 1:31 pm, Jon Ribbens wrote: On 2022-11-13, DFS wrote: But why is it allowed in the first place? Because it's an expression, and you're allowed to execute expressions. To put it a bit more clearly, you're allowed to evaluate an expression and ignore the result. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 2022-11-13, DFS wrote: > On 11/13/2022 5:20 PM, Jon Ribbens wrote: >> On 2022-11-13, DFS wrote: >>> In code, list.clear is just ignored. >>> At the terminal, list.clear shows >>> >>> >>> >>> in code: >>> x = [1,2,3] >>> x.clear >>> print(len(x)) >>> 3 >>> >>> at terminal: >>> x = [1,2,3] >>> x.clear >>> >>> print(len(x)) >>> 3 >>> >>> >>> Caused me an hour of frustration before I noticed list.clear() was what >>> I needed. >>> >>> x = [1,2,3] >>> x.clear() >>> print(len(x)) >>> 0 >> >> If you want to catch this sort of mistake automatically then you need >> a linter such as pylint: >> >>$ cat test.py >>"""Create an array and print its length""" >> >>array = [1, 2, 3] >>array.clear >>print(len(array)) >>$ pylint -s n test.py >>* Module test >>test.py:4:0: W0104: Statement seems to have no effect >> (pointless-statement) > > > Thanks, I should use linters more often. > > But why is it allowed in the first place? Because it's an expression, and you're allowed to execute expressions. -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 11/13/2022 5:20 PM, Jon Ribbens wrote: On 2022-11-13, DFS wrote: In code, list.clear is just ignored. At the terminal, list.clear shows in code: x = [1,2,3] x.clear print(len(x)) 3 at terminal: x = [1,2,3] x.clear print(len(x)) 3 Caused me an hour of frustration before I noticed list.clear() was what I needed. x = [1,2,3] x.clear() print(len(x)) 0 If you want to catch this sort of mistake automatically then you need a linter such as pylint: $ cat test.py """Create an array and print its length""" array = [1, 2, 3] array.clear print(len(array)) $ pylint -s n test.py * Module test test.py:4:0: W0104: Statement seems to have no effect (pointless-statement) Thanks, I should use linters more often. But why is it allowed in the first place? I stared at list.clear and surrounding code a dozen times and said "Looks right! Why isn't it clearing the list?!?!" 2 parens later and I'm golden! -- https://mail.python.org/mailman/listinfo/python-list
Re: In code, list.clear doesn't throw error - it's just ignored
On 2022-11-13, DFS wrote: > In code, list.clear is just ignored. > At the terminal, list.clear shows > > > > in code: > x = [1,2,3] > x.clear > print(len(x)) > 3 > > at terminal: > x = [1,2,3] > x.clear > > print(len(x)) > 3 > > > Caused me an hour of frustration before I noticed list.clear() was what > I needed. > > x = [1,2,3] > x.clear() > print(len(x)) > 0 If you want to catch this sort of mistake automatically then you need a linter such as pylint: $ cat test.py """Create an array and print its length""" array = [1, 2, 3] array.clear print(len(array)) $ pylint -s n test.py * Module test test.py:4:0: W0104: Statement seems to have no effect (pointless-statement) -- https://mail.python.org/mailman/listinfo/python-list
In code, list.clear doesn't throw error - it's just ignored
In code, list.clear is just ignored. At the terminal, list.clear shows in code: x = [1,2,3] x.clear print(len(x)) 3 at terminal: x = [1,2,3] x.clear print(len(x)) 3 Caused me an hour of frustration before I noticed list.clear() was what I needed. x = [1,2,3] x.clear() print(len(x)) 0 -- https://mail.python.org/mailman/listinfo/python-list
Re: when I open a python idle it's constantly showing subprocess connection error
On 9/20/22 09:36, asika wrote: Sent from [1]Mail for Windows References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 dunno if you were trying to send screenshots or something, that doesn't work here. Try: https://docs.python.org/3/library/idle.html#startup-failure Hint: you usually named a file you were working on the same as something IDLE uses, that's the usual cause these days. -- https://mail.python.org/mailman/listinfo/python-list
when I open a python idle it's constantly showing subprocess connection error
Sent from [1]Mail for Windows References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 -- https://mail.python.org/mailman/listinfo/python-list
Re: when the new version of XPN py2 newsreader src-tarball hits alt.binaries, the world will hold it's breath
py2 now, gotta fix that one -- https://mail.python.org/mailman/listinfo/python-list
when the new version of XPN py2 newsreader src-tarball hits alt.binaries, the world will hold it's breath
when the new version of XPN py2 newsreader src-tarball hits alt.binaries, the world will hold it's breath. major usability overhaul is ongoing. release will be in style in usenet binary newsgroup. full autoconfigure, no bs asked. -- https://mail.python.org/mailman/listinfo/python-list
Re: How does CPython build it's NEWS or changelog?
Stefan Behnel writes: > https://docs.python.org/devguide/committing.html#what-s-new-and-news-entries > > https://github.com/larryhastings/blurb Also of interest is the more general-use Town Crier tool: towncrier is a utility to produce useful, summarised news files for your project. Rather than reading the Git history as some newer tools to produce it, or having one single file which developers all write to, towncrier reads “news fragments” which contain information useful to end users. https://pypi.python.org/pypi/towncrier/> -- \ “The Initial Mystery that attends any journey is: how did the | `\ traveller reach his starting point in the first place?” —Louise | _o__) Bogan, _Journey Around My Room_ | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: How does CPython build it's NEWS or changelog?
Hartmut Goebel schrieb am 21.09.2017 um 10:59: > I just discovered that CPython now uses Misc/NEWS.d/next to collect > changes an there are a lot of Misc/NEWS/*.rst files for the respective > released version. I'm investigating whether to adopt this for PyInstaller. > > What is the tooling for this? Is there some documentation, maybe a > mailingslist-diskussion or a but-report? https://docs.python.org/devguide/committing.html#what-s-new-and-news-entries https://github.com/larryhastings/blurb Stefan -- https://mail.python.org/mailman/listinfo/python-list
Re: How does CPython build it's NEWS or changelog?
On 21 September 2017 at 09:59, Hartmut Goebel wrote: > Hello, > > I just discovered that CPython now uses Misc/NEWS.d/next to collect > changes an there are a lot of Misc/NEWS/*.rst files for the respective > released version. I'm investigating whether to adopt this for PyInstaller. > > What is the tooling for this? Is there some documentation, maybe a > mailingslist-diskussion or a but-report? There's a tool "blurb" (available from PyPI) used for this. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: How does CPython build it's NEWS or changelog?
> I just discovered that CPython now uses Misc/NEWS.d/next to collect > changes an there are a lot of Misc/NEWS/*.rst files for the respective > released version. I'm investigating whether to adopt this for PyInstaller. > > What is the tooling for this? Is there some documentation, maybe a > mailingslist-diskussion or a but-report? Check Tools/scripts/patchcheck.py in the CPython repo. There is also a patchcheck target in the top level Makefile.pre.in file. I imagine this stuff is only exercised by the release process, so the various release managers probably know this stuff best. In theory, python-...@python.org might be the best place to contact them, though I suspect that's not quite the right place for an extended discussion of the topic. Skip -- https://mail.python.org/mailman/listinfo/python-list
How does CPython build it's NEWS or changelog?
Hello, I just discovered that CPython now uses Misc/NEWS.d/next to collect changes an there are a lot of Misc/NEWS/*.rst files for the respective released version. I'm investigating whether to adopt this for PyInstaller. What is the tooling for this? Is there some documentation, maybe a mailingslist-diskussion or a but-report? -- Regards Hartmut Goebel | Hartmut Goebel | h.goe...@crazy-compilers.com | | www.crazy-compilers.com | compilers which you thought are impossible | -- https://mail.python.org/mailman/listinfo/python-list
Embedding python, run a function and get it's result
Hello, I'm messing around with the embedded python and I can get parts to work. What I'm having a hard time is getting my head around calling a function in the python string and getting it's result. Question, how do I load the python script and call runMe() and get it's value? Thanks! Example Works Obj-C Code: Py_Initialize(); PyObject *py_main, *py_dict; py_main = PyImport_AddModule("__main__"); py_dict = PyModule_GetDict(py_main); // Run the python source code PyRun_String([auditScript UTF8String], Py_file_input, py_dict, py_dict); PyObject *pythonString = PyDict_GetItemString(py_dict, "x") ; if (!pythonString) { NSLog(@"pythonString returned NULL"); return "NO"; } // Convert the unpickled Python string to a C string char *cString = PyString_AsString(pythonString); Py_DECREF(pythonString); f (!cString) { NSLog(@"Failed converting pythonString string to C string"); return 1; } NSLog(@"answer: %@",[NSString cString]); Python Code: x = "NA" def runMe(): return "YES" x = runMe() -- https://mail.python.org/mailman/listinfo/python-list
it's posible? raw audio encoder to vorbis
Receipt from websocket server audio raw and I want to encode ogg help! :( from websocket_server import WebsocketServer # Called when a client sends a messagedef data_received(client, server, datos): #HERE encoder "datos" to ogg and save data PORT=9001 server = WebsocketServer(PORT) server.set_fn_message_received(data_received) server.run_forever() -- https://mail.python.org/mailman/listinfo/python-list
Re: (Still OT) It's not the size of the vocabulary that matters, but what you do with it [was Re: Python Worst Practices]
On Mon, Mar 2, 2015 at 2:18 PM, Paul Rubin wrote: > Steven D'Aprano writes: >> The Aussie replies “Ah yes, I had a car like that once. American-made, is >> it?” > > Is it true that in Australia, the number of the beast is 999? Wouldn't know. Out here, we're not afraid of the beast - why should we be? We have spiders, and snakes, and kangaroos, and weather, and desert, and ants, and spiders, and drop bears, and spiders, and "jelly" (gelignite), and I nearly forgot to mention that we have spiders. If you feel like disposing of an unwanted Beast, you could do worse than deposit him somewhere in the Western Australian desert. It's kinda like sending him to hell, only the postage is cheaper. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: (Still OT) It's not the size of the vocabulary that matters, but what you do with it [was Re: Python Worst Practices]
Steven D'Aprano writes: > The Aussie replies “Ah yes, I had a car like that once. American-made, is > it?” Is it true that in Australia, the number of the beast is 999? -- https://mail.python.org/mailman/listinfo/python-list
(Still OT) It's not the size of the vocabulary that matters, but what you do with it [was Re: Python Worst Practices]
Dennis Lee Bieber wrote: > Well... when we've got states bigger than some countries... A Texan farmer goes to Australia on vacation. There he meets an Aussie farmer and gets to talking. They walk around the farm a little, and the Aussie shows off his herd of cattle. The Texan immediately replies, “Our Texan longhorns are at least twice as large as your cows.” The Aussie shows off his big wheat field and the Texan says, “In Texas, our wheat fields are ten times as big as that!” Just then a herd of kangaroos hop through the field. The Texan does a double-take and says "What in San Quentin are those?” The Aussie replies “Don’t you have any grasshoppers in Texas?” The Texan recovers quickly and says “Of course we do, I’ve just never seen them that color before. You’ve got a nice farm, but it’s a bit small. Back home, when I drive around the ranch checking the fences, I get in my SUV at 4 in the morning, and don’t get back home until 11 the next night.” The Aussie replies “Ah yes, I had a car like that once. American-made, is it?” -- Steve -- https://mail.python.org/mailman/listinfo/python-list
SMITHSONIAN HAS IT'S LAST WORDS...
=== A TOUCHY SUBJECT... === > A WILY THRINAXODON SUED THE SMITHSONIAN FIVE HUNDRED DOLLARS FOR SUPPRESSION OF FREEDOM OF EXPRESSION. > "This is a blow to evolutionism," SAID RICHARD DAWKINS. > ONE WHOM THRINAXODON HAS HAD SEVERAL *long* RUNNING FEUDS OVER THE PAST 40 YEARS. > THE SMITHSONIAN IS BEING TORN DOWN. > THE SPECIMENS BURNED, BOOKS REWRITTEN, etc. > "This never happened with Ed Conrad," SAID BARACK OBAMA. > EVOLUTIONISTS ALL OVER THE WORLD GET SUNK IN TEARS AS ONE OF THE MAJOR CORPORATIONS GET SHUT DOWN... > > I KNOW, I KNOW...YOU NEED A RESOURCE FOR THIS SCIENCE. > WELL TYPE IN news://sci.bio.paleontology, news://sci.skeptic, news://dc.smithsonian, etc ON YOUR WEB BROWSER. > === > http://thrinaxodon.wordpress.com/ > === > THRINAXODON IS NOW ON TWITTER. -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError: expected an indented block but it's there
On Wed, May 29, 2013 at 2:53 AM, Peter Otten <__pete...@web.de> wrote: > Chris Angelico wrote: > >> On Wed, May 29, 2013 at 2:19 AM, Peter Otten <__pete...@web.de> wrote: >>> Solution: configure your editor to use four spaces for indentation. >> >> ITYM eight spaces. > > I meant: one hit of the Tab key should add spaces up to the next multiple of > four. Which implies > >> But the real solution is to not mix tabs and >> spaces. Stick to one or the other and you're safe. Sure. If you configure your tab *key* to not insert a tab *character*, then you're fine. Or alternatively, if you always use \t for indentation, you can tweak the displayed width of it. (Or, as I do, just let it be eight wide. On today's screens that's not much of a problem.) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError: expected an indented block but it's there
Chris Angelico wrote: > On Wed, May 29, 2013 at 2:19 AM, Peter Otten <__pete...@web.de> wrote: >> Solution: configure your editor to use four spaces for indentation. > > ITYM eight spaces. I meant: one hit of the Tab key should add spaces up to the next multiple of four. Which implies > But the real solution is to not mix tabs and > spaces. Stick to one or the other and you're safe. -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError: expected an indented block but it's there
On Wed, May 29, 2013 at 2:19 AM, Peter Otten <__pete...@web.de> wrote: > Solution: configure your editor to use four spaces for indentation. ITYM eight spaces. But the real solution is to not mix tabs and spaces. Stick to one or the other and you're safe. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError: expected an indented block but it's there
JackM wrote: > Having a problem getting a py script to execute. Got this error: > > File "/scripts/blockIPv4.py", line 19 > ip = line.split(';')[0] > ^ > IndentationError: expected an indented block > > > I'm perplexed because the code that the error refers to *is* indented: > > > > with open('/var/www/html/mydomain.com/banlist.txt','r') as inFile: > for line in inFile.readlines(): > ip = line.split(';')[0] > output = os.popen( '/etc/sysconfig/iptables -A INPUT -s ' + ip > + ' -j REJECT' ) > logFile.write(ip+' - Has been blocked\n') > > > What am I missing here? If you are mixing tabs and spaces to indent your code and have your editor configured with a tab width other than eight your code may look correct when it isn't. A simulation in the interactive interpreter: The actual file contents: >>> s = "if 1:\n\tif 2:\n\tprint 'hi'" What you see: >>> print s.expandtabs(4) if 1: if 2: print 'hi' >>> exec s.expandtabs(4) hi What Python "sees": >>> print s.expandtabs(8) if 1: if 2: print 'hi' >>> exec s Traceback (most recent call last): File "", line 1, in File "", line 3 print 'hi' ^ IndentationError: expected an indented block Solution: configure your editor to use four spaces for indentation. -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError: expected an indented block but it's there
On Tue, 28 May 2013 11:32:06 -0400, JackM wrote: > Having a problem getting a py script to execute. Got this error: > > File "/scripts/blockIPv4.py", line 19 > ip = line.split(';')[0] > ^ > IndentationError: expected an indented block > > > I'm perplexed because the code that the error refers to *is* indented: Whenever you get perplexing indentation errors, suspect an inconsistency due to mixed tabs and spaces. Tabs good. Spaces good. Tabs and spaces together, bad. You can run the tabnanny module over your source code: python -m tabnanny to convert indentation to all spaces. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: IndentationError: expected an indented block but it's there
On 05/28/2013 09:32 AM, JackM wrote: > Having a problem getting a py script to execute. Got this error: > > File "/scripts/blockIPv4.py", line 19 > ip = line.split(';')[0] > ^ > IndentationError: expected an indented block > I'm perplexed because the code that the error refers to *is* indented: > with open('/var/www/html/mydomain.com/banlist.txt','r') as inFile: > for line in inFile.readlines(): > ip = line.split(';')[0] > output = os.popen( '/etc/sysconfig/iptables -A INPUT -s ' + ip > + ' -j REJECT' ) > logFile.write(ip+' - Has been blocked\n') > > > What am I missing here? Indentation has to be consistent. likely the for line is indented with spaces and the next line with a tab. You can use tabs and spaces, but you have to be consistent with how you use them. IE if level 1 is indented with spaces, then level 2 has to be indented with spaces up to level 1 as well. Hope that makes sense. -- http://mail.python.org/mailman/listinfo/python-list
IndentationError: expected an indented block but it's there
Having a problem getting a py script to execute. Got this error: File "/scripts/blockIPv4.py", line 19 ip = line.split(';')[0] ^ IndentationError: expected an indented block I'm perplexed because the code that the error refers to *is* indented: with open('/var/www/html/mydomain.com/banlist.txt','r') as inFile: for line in inFile.readlines(): ip = line.split(';')[0] output = os.popen( '/etc/sysconfig/iptables -A INPUT -s ' + ip + ' -j REJECT' ) logFile.write(ip+' - Has been blocked\n') What am I missing here? -- My email address on the header is a non-monitored spam catching account. I can be reached via http://www.wvnh.net/contact.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing user input as it's entered
On 26 March 2013 14:41, Arnaud Delobelle wrote: > On 26 March 2013 10:07, Sven wrote: > > Hello, > > > > Is there a way (ideally cross platform but a *nix OS solution would be > > great) to process user input as they type? > > What I aim to achieve is to count the number of characters a user has > > entered and display it while they are typing. The entered text will also > > need to be captured once the user has finished typing. > > > > This is a gui-less CLI tool for python 2.7 > > > > I've seen some information on tty.setraw but I'm not sure how you'd go > about > > wiring that up. > > Can you use curses (http://docs.python.org/2/library/curses.html This could work. I've not used it before so I am having some issues echoing out the text. I assume I can use this without having to create an ncurses UI? -- ./Sven -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing user input as it's entered
On 26 March 2013 10:07, Sven wrote: > Hello, > > Is there a way (ideally cross platform but a *nix OS solution would be > great) to process user input as they type? > What I aim to achieve is to count the number of characters a user has > entered and display it while they are typing. The entered text will also > need to be captured once the user has finished typing. > > This is a gui-less CLI tool for python 2.7 > > I've seen some information on tty.setraw but I'm not sure how you'd go about > wiring that up. Can you use curses (http://docs.python.org/2/library/curses.html) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Processing user input as it's entered
Hello, Is there a way (ideally cross platform but a *nix OS solution would be great) to process user input as they type? What I aim to achieve is to count the number of characters a user has entered and display it while they are typing. The entered text will also need to be captured once the user has finished typing. This is a gui-less CLI tool for python 2.7 I've seen some information on tty.setraw but I'm not sure how you'd go about wiring that up. Thanks -- ./Sven -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a number back to it's original string (that was hashed to generate that number)
Τη Τετάρτη, 23 Ιανουαρίου 2013 3:58:45 μ.μ. UTC+2, ο χρήστης Dave Angel έγραψε: > On 01/23/2013 08:38 AM, Ferrous Cranus wrote: > > > Please DON'T tell me to save both the pin <=> filepath and associate them > > (that can be done by SQL commands, i know) > > > I will not create any kind of primary/unique keys to the database. > > > I will not store the filepath into the database, just the number which > > indicates the filepath(html page). > > > Also no external table associating fielpaths and numbers. > > > i want this to be solved only by Python Code, not database oriented. > > > > > > > > > That is: I need to be able to map both ways, in a one to one relation, > > 5-digit-integer <=> string > > > > > > int( hex ( string ) ) can encode a string to a number. Can this be decoded > > back? I gues that can also be decoded-converted back because its not losing > > any information. Its encoding, not compressing. > > > > > > But it's the % modulo that breaks the forth/back association. > > > > > > So, the question is: > > > > > > HOW to map both ways, in a one to one relation, (5-digit-integer <=> > > string) without losing any information? > > > > > > > Simple. Predefine the 100,000 legal strings, and don't let the user use > > anything else. One way to do that would be to require a path string of > > no more than 5 characters, and require them all to be of a restricted > > alphabet of 10 characters. (eg. the alphabet could be 0-9, which is > > obvious, or it could be ".aehilmpst" (no uppercase, no underscore, no > > digits, no non-ascii, etc.) > > > > In the realistic case of file paths or URLs, it CANNOT be done. OK, its not doable. I'll stop asking for it. CHANGE of plans. i will use the database solution which is the most easy wau to do it: # insert new page record in table counters or update it if already exists try: cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) except MySQLdb.Error, e: print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) # update existing visitor record if same pin and same host found try: cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros = %s, browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, browser, date, page, host)) except MySQLdb.Error, e: print ( "Error %d: %s" % (e.args[0], e.args[1]) ) # insert new visitor record if above update did not affect a row if cursor.rowcount == 0: cursor.execute( '''INSERT INTO visitors(hits, host, useros, browser, date) VALUES(%s, %s, %s, %s, %s)''', (1, host, useros, browser, date) ) I can INSERT a row to the table "counter" I cannot UPDATE or INSERT into the table "visitors" without knowing the "pin" primary key number the database created. Can you help on this please? -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a number back to it's original string (that was hashed to generate that number)
On 01/23/2013 08:38 AM, Ferrous Cranus wrote: Please DON'T tell me to save both the pin <=> filepath and associate them (that can be done by SQL commands, i know) I will not create any kind of primary/unique keys to the database. I will not store the filepath into the database, just the number which indicates the filepath(html page). Also no external table associating fielpaths and numbers. i want this to be solved only by Python Code, not database oriented. That is: I need to be able to map both ways, in a one to one relation, 5-digit-integer <=> string int( hex ( string ) ) can encode a string to a number. Can this be decoded back? I gues that can also be decoded-converted back because its not losing any information. Its encoding, not compressing. But it's the % modulo that breaks the forth/back association. So, the question is: HOW to map both ways, in a one to one relation, (5-digit-integer <=> string) without losing any information? Simple. Predefine the 100,000 legal strings, and don't let the user use anything else. One way to do that would be to require a path string of no more than 5 characters, and require them all to be of a restricted alphabet of 10 characters. (eg. the alphabet could be 0-9, which is obvious, or it could be ".aehilmpst" (no uppercase, no underscore, no digits, no non-ascii, etc.) In the realistic case of file paths or URLs, it CANNOT be done. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a number back to it's original string (that was hashed to generate that number)
Please DON'T tell me to save both the pin <=> filepath and associate them (that can be done by SQL commands, i know) I will not create any kind of primary/unique keys to the database. I will not store the filepath into the database, just the number which indicates the filepath(html page). Also no external table associating fielpaths and numbers. i want this to be solved only by Python Code, not database oriented. That is: I need to be able to map both ways, in a one to one relation, 5-digit-integer <=> string int( hex ( string ) ) can encode a string to a number. Can this be decoded back? I gues that can also be decoded-converted back because its not losing any information. Its encoding, not compressing. But it's the % modulo that breaks the forth/back association. So, the question is: HOW to map both ways, in a one to one relation, (5-digit-integer <=> string) without losing any information? -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a number back to it's original string (that was hashed to generate that number)
please don't feed the troll. cu, Kurt -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a number back to it's original string (that was hashed to generate that number)
Ferrous Cranus writes: > pin = int( htmlpage.encode("hex"), 16 ) % 10 > > Now i need the opposite procedure. As already said several times by different persons in this thread, there is no way you can get the original string that originated a particular “pin”: the function you are using is “lossy”, that is, information gets lost in order to reduce a BIG string into a SMALL five-digits integer number. > Will hex.decode(number) convert back to the original string? NO. As people demonstrated you, you are going to meet collisions very fast, if you insist going this way (even you thought a “smarter” way to get a checksum out of your string by using a different weight for the single characters, there is still high chances of collisions, not counting the final “modulo” operation). Once you get such a collision, there is not enough information in that single tiny number to get back a single string that generated it. Imagine that, instead of using an integer checksum of your full path, you “shrink” it by replacing each name in the path with its starting letter, that is: /home/ferrous/public_html/index.html => /h/f/p/i That is evidently way shorter of the original, but you LOST information, and you cannot write code in any language that eventually reproduce the original. The only way out is either use the fullpath as the primary key of your table, or using a mapping table with a bi-directional univoke mapping between any single fullpath to the corresponding "short" integer value. ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it | -- Fortunato Depero, 1929. -- http://mail.python.org/mailman/listinfo/python-list
Converting a number back to it's original string (that was hashed to generate that number)
Now my website finally works as intended. Just visit the following links plz. -- 1. http://superhost.gr 2. http://superhost.gr/?show=log 3. http://i.imgur.com/89Eqmtf.png (this displays the database's column 'pin', a 5-digit number acting as a filepath indicator) 4. http://i.imgur.com/9js4Pz0.png (this is the detailed html page's information associated to 'pin' column indicator instead of something like '/home/nikos/public_html/index.html' Isn't it a nice solution? I beleive it is. but what happens when: http://superhost.gr/?show=stats I just see the number that correspons to a specific html page and hence i need to convert that number back to its original string. # == # generating an 5-digit integer based on filepath, for to identify the current html page # == pin = int( htmlpage.encode("hex"), 16 ) % 10 Now i need the opposite procedure. Will hex.decode(number) convert back to the original string? I think not because this isnt a hash procedure. But how can it be done then? -- http://mail.python.org/mailman/listinfo/python-list
Re: it's really strange.how does it work?
On Tue, Aug 14, 2012 at 10:07 PM, levi nie wrote: > ok,what does "start, stop = 0, start" in the code mean? > it's really strange.how does it work? It's just parallel assignment (http://en.wikipedia.org/wiki/Assignment_%28computer_science%29#Parallel_assignment ). As to exactly how it works: http://docs.python.org/reference/simple_stmts.html#assignment-statements : "If the target [of the assignment] is a comma-separated list: The [value being stored] must be an iterable with the same number of items as there are targets in the target list, and the items are assigned, from left to right, to the corresponding targets." [not a completely direct quote] Tuples are iterable (e.g. we can write `for item in some_tuple:`; in laymen's terms, it's similar to being a sequence). Recall that commas, and not parentheses, are what create tuples according to Python's syntax: $ python Python 2.7.2 (default, Jun 20 2012, 16:23:33) Type "help", "copyright", "credits" or "license" for more information. >>> x = 1,2 >>> x (1, 2) >>> type(x) >>> So, your code snippet creates an anonymous temporary tuple of length 2 [i.e. (0, start) ], and the assignment then unpacks that tuple into the 2 respective variables. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: it's really strange.how does it work?
Even I got confused a bit: explaination: this is called iterable unpacking `start, stop = 0, start` is the same as: temp = start start = 0 stop = temp On 15 August 2012 10:37, levi nie wrote: > ok,what does "start, stop = 0, start" in the code mean? > it's really strange.how does it work? > > code: > def interval(start, stop=None, step=1): > 'Imitates range() for step > 0' > if stop is None: > start, stop = 0, start > result = [] > i = start > while i < stop: > result.append(i) > i += step > return result > > print interval(10) > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://mail.python.org/mailman/listinfo/python-list
it's really strange.how does it work?
ok,what does "start, stop = 0, start" in the code mean? it's really strange.how does it work? code: def interval(start, stop=None, step=1): 'Imitates range() for step > 0' if stop is None: start, stop = 0, start result = [] i = start while i < stop: result.append(i) i += step return result print interval(10) -- http://mail.python.org/mailman/listinfo/python-list
Strings show as brackets with a 'u'. Hi, ...[u'174'] ...Probably newbie question but not sure how suppress the brackets and the 'u' ? I assume pyhon is telling me it's a unicode string in the n variab
http://123maza.com/65/beauty147/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you print a string after it's been searched for an RE?
On Jun 23, 4:47 pm, "Thomas L. Shinnick" wrote: > There is also > print(match_obj.string) > which gives you a copy of the string searched. See end of section > 6.2.5. Match Objects I tried that, but the only time I wanted the string printed was when there *wasn't* a match, so the match object was a NoneType. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you print a string after it's been searched for an RE?
There is also print(match_obj.string) which gives you a copy of the string searched. See end of section 6.2.5. Match Objects At 02:58 PM 6/23/2011, John Salerno wrote: After I've run the re.search function on a string and no match was found, how can I access that string? When I try to print it directly, it's an empty string, I assume because it has been "consumed." How do I prevent this? It seems to work fine for this 2.x code: import urllib.request import re next_nothing = '12345' pc_url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php? nothing=' pattern = re.compile(r'[0-9]+') while True: page = urllib.request.urlopen(pc_url + next_nothing) match_obj = pattern.search(page.read().decode()) if match_obj: next_nothing = match_obj.group() print(next_nothing) else: print(page.read().decode()) break But when I try it with my own code (3.2), it won't print the text of the page: import urllib.request import re next_nothing = '12345' pc_url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php? nothing=' pattern = re.compile(r'[0-9]+') while True: page = urllib.request.urlopen(pc_url + next_nothing) match_obj = pattern.search(page.read().decode()) if match_obj: next_nothing = match_obj.group() print(next_nothing) else: print(page.read().decode()) break P.S. I plan to clean up my code, I know it's not great right now. But my immediate goal is to just figure out why the 2.x code can print "text", but my own code can't print "page," which are basically the same thing, unless something significant has changed with either the urllib.request module, or the way it's decoded, or something, or is it just an RE issue? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you print a string after it's been searched for an RE?
On Jun 23, 3:47 pm, Ian Kelly wrote: > On Thu, Jun 23, 2011 at 1:58 PM, John Salerno wrote: > > After I've run the re.search function on a string and no match was > > found, how can I access that string? When I try to print it directly, > > it's an empty string, I assume because it has been "consumed." How do > > I prevent this? > > This has nothing to do with regular expressions. It would appear that > page.read() is letting you read the response body multiple times in > 2.x but not in 3.x, probably due to a change in buffering. Just store > the string in a variable and avoid calling page.read() multiple times. Thank you. That worked, and as a result I think my code will look cleaner. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you print a string after it's been searched for an RE?
On Thu, Jun 23, 2011 at 1:58 PM, John Salerno wrote: > After I've run the re.search function on a string and no match was > found, how can I access that string? When I try to print it directly, > it's an empty string, I assume because it has been "consumed." How do > I prevent this? This has nothing to do with regular expressions. It would appear that page.read() is letting you read the response body multiple times in 2.x but not in 3.x, probably due to a change in buffering. Just store the string in a variable and avoid calling page.read() multiple times. -- http://mail.python.org/mailman/listinfo/python-list
How do you print a string after it's been searched for an RE?
After I've run the re.search function on a string and no match was found, how can I access that string? When I try to print it directly, it's an empty string, I assume because it has been "consumed." How do I prevent this? It seems to work fine for this 2.x code: import urllib.request import re next_nothing = '12345' pc_url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php? nothing=' pattern = re.compile(r'[0-9]+') while True: page = urllib.request.urlopen(pc_url + next_nothing) match_obj = pattern.search(page.read().decode()) if match_obj: next_nothing = match_obj.group() print(next_nothing) else: print(page.read().decode()) break But when I try it with my own code (3.2), it won't print the text of the page: import urllib.request import re next_nothing = '12345' pc_url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php? nothing=' pattern = re.compile(r'[0-9]+') while True: page = urllib.request.urlopen(pc_url + next_nothing) match_obj = pattern.search(page.read().decode()) if match_obj: next_nothing = match_obj.group() print(next_nothing) else: print(page.read().decode()) break P.S. I plan to clean up my code, I know it's not great right now. But my immediate goal is to just figure out why the 2.x code can print "text", but my own code can't print "page," which are basically the same thing, unless something significant has changed with either the urllib.request module, or the way it's decoded, or something, or is it just an RE issue? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Standardizing RPython - it's time.
Hi John, John Nagle animats.com> writes: > All attempts to make the dialect defined by CPython significantly > faster have failed. PyPy did not achieve much of a speed > improvement over CPython, and is sometimes slower. This is not true. While PyPy is indeed sometimes slower than CPython, there is a significant speedup for many synthetic and real-life benchmarks. PyPy with a JIT is up to 20 times faster than CPython for synthetic benchmarks like richards, but still something like 6 times faster for Django. It also beats Psyco in almost all benchmarks. For detailed measurements, please visit our benchmarking site: http://speed.pypy.org All these numbers are also only the current state, PyPy is still continuously improving. Cheers, Carl Friedrich -- http://mail.python.org/mailman/listinfo/python-list
Re: Standardizing RPython - it's time.
Stefan Behnel, 12.10.2010 09:18: If you implemented an RPython to CPython extension compiler, [...] BTW, if anyone wanted to do that, it might be a good idea to start with Cython, adapt its type inference layer and add the few missing Python language features (or pay the core developers to do it for you). That would likely be the fastest way to get this rolling. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Standardizing RPython - it's time.
On 10/12/2010 05:18 PM, Nils Ruettershoff wrote: Hi, On 10/12/2010 07:41 AM, John Nagle wrote: [...] With Unladen Swallow looking like a failed IT project, a year behind schedule and not delivering anything like the promised performance, Google management may pull the plug on funding. Since there hasn't been a "quarterly release" in a year, that may already have effectively happened. are you sure that the project has failed? Yes the project page is outdated, but there is also pep-3146 [1] "Merging Unladen Swallow into CPython" Regarding the accepted pep, the merge is planed for Python 3.3. So for me it looks like the development itself has finished and the merging has started... I've just found a statement from Collin Winter [1]. He says, that he is working on other google projects, but they are still targeting the merge Unladen Swallow with cPython 3.3. The last commitmend to the branch (py3-jit) was in June this year So I would say the project is not dead or has failed, but delayed. Cheers, Nils [1] http://groups.google.com/group/unladen-swallow/browse_thread/thread/f2011129c4414d04 -- http://mail.python.org/mailman/listinfo/python-list
Re: Standardizing RPython - it's time.
Hi, On 10/12/2010 07:41 AM, John Nagle wrote: [...] With Unladen Swallow looking like a failed IT project, a year behind schedule and not delivering anything like the promised performance, Google management may pull the plug on funding. Since there hasn't been a "quarterly release" in a year, that may already have effectively happened. are you sure that the project has failed? Yes the project page is outdated, but there is also pep-3146 [1] "Merging Unladen Swallow into CPython" Regarding the accepted pep, the merge is planed for Python 3.3. So for me it looks like the development itself has finished and the merging has started... Does anyone has more details? Regrads, Nils [1] http://www.python.org/dev/peps/pep-3146/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Standardizing RPython - it's time.
John Nagle, 11.10.2010 22:01: It may be time to standardize "RPython". There are at least three implementations of "RPython" variants - PyPy, Shed Skin, and RPython for LLVM. The first two are up and running. The thing is, while RPython can be seen as a general purpose programming language, it lacks much of what larger applications would need. It doesn't have access to the CPython ecosystem, for one. Not at all in the case of Shedskin, and only part of it in the case of PyPy (ironically, excluding mostly those parts that were written for high performance). Don't know about the LLVM implementation, which seems to be far from mature anyway. If you implemented an RPython to CPython extension compiler, I'd expect that at least some people would use it. Lacking that, however, I don't see a major interest in writing code in RPython that doesn't have access to all of the CPython ecosystem. I'm not saying it can't be useful in certain cases, especially when you can be sure in advance that you won't need that ecosystem. But I don't really see the general purpose applicability of RPython to application development. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Standardizing RPython - it's time.
John Nagle wrote: > All the schemes to speed up Python as defined by CPython seem to hit > a wall on speed improvement. Some of the numeric benchmarks go faster > on implementations that don't box all numbers, but 2x seems to be about > as good as it gets, even with a JIT compiler. That hasn't been the case with PyPy for quite some time: http://goo.gl/dA7v (link to specific speed.pypy.org comparison). Comparing the latest PyPy+JIT to CPython 2.6.2, there are 6 tests that perform worse and 12 that perform better. Of the 12 improvements, 9 are of an improvement of 3x or better, with one exceeding 12x and one 15x. The django benchmark is 6x faster under PyPy+JIT than CPython. (The PyPy guys have done a fantastic job with http://speed.pypy.org to help show the gains that they're getting.) Don't be so quick to condemn PyPy, especially as they're _actively_ working on this project, not just engaging in endless online rhetoric about how great life would be if only Python was faster. Achieving performance gains _without_ sacrificing the power of the language should be the ultimate goal. -- http://mail.python.org/mailman/listinfo/python-list
Re: Standardizing RPython - it's time.
On 10/11/2010 1:47 PM, Ryan Kelly wrote: On Mon, 2010-10-11 at 13:01 -0700, John Nagle wrote: It may be time to standardize "RPython". There are at least three implementations of "RPython" variants - PyPy, Shed Skin, and RPython for LLVM. The first two are up and running. There's a theory paper on the subject: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.142.1457&rep=rep1&type=pdf All three have somewhat different restrictions: PyPy's Rpython: http://codespeak.net/pypy/dist/pypy/doc/coding-guide.html Shed Skin: file:///C:/Users/nagle/AppData/Local/Temp/shedskin-tutorial-0.3.html Rpython for LLVM: http://code.google.com/p/rpython/ So a language standardization effort, independent of CPython, would be useful. A similar topic was recently discussed on the pypy-dev mailing list: http://codespeak.net/pipermail/pypy-dev/2010q3/006170.html My interpretation is that the pypy devs are -0 on such a standardisation effort, as it would give them less flexibility in moulding rpython for their specific needs. Adding features to rpython that make it better as a general-purpose programming language could actually make it *worse* as a specialised language for building pypy. OTOH, there does seem to be a growing interest in using rpython as a stand-alone language. I've used it for some small projects and it worked out great. But the intersection of (people who want rpython as a general-purpose language) and (people who have the ability to make that happen) seems to be approximately zero at the moment... With Unladen Swallow looking like a failed IT project, a year behind schedule and not delivering anything like the promised performance, Google management may pull the plug on funding. Since there hasn't been a "quarterly release" in a year, that may already have effectively happened. All the schemes to speed up Python as defined by CPython seem to hit a wall on speed improvement. Some of the numeric benchmarks go faster on implementations that don't box all numbers, but 2x seems to be about as good as it gets, even with a JIT compiler. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Standardizing RPython - it's time.
On Mon, 2010-10-11 at 13:01 -0700, John Nagle wrote: > It may be time to standardize "RPython". > >There are at least three implementations of "RPython" variants - PyPy, > Shed Skin, and RPython for LLVM. The first two are up and running. > There's a theory paper on the subject: > > http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.142.1457&rep=rep1&type=pdf > >All three have somewhat different restrictions: > > PyPy's Rpython: > http://codespeak.net/pypy/dist/pypy/doc/coding-guide.html > > Shed Skin: > file:///C:/Users/nagle/AppData/Local/Temp/shedskin-tutorial-0.3.html > > Rpython for LLVM: > http://code.google.com/p/rpython/ > > So a language standardization effort, independent of CPython, > would be useful. A similar topic was recently discussed on the pypy-dev mailing list: http://codespeak.net/pipermail/pypy-dev/2010q3/006170.html My interpretation is that the pypy devs are -0 on such a standardisation effort, as it would give them less flexibility in moulding rpython for their specific needs. Adding features to rpython that make it better as a general-purpose programming language could actually make it *worse* as a specialised language for building pypy. OTOH, there does seem to be a growing interest in using rpython as a stand-alone language. I've used it for some small projects and it worked out great. But the intersection of (people who want rpython as a general-purpose language) and (people who have the ability to make that happen) seems to be approximately zero at the moment... Ryan -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit r...@rfk.id.au| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-list
Re: Standardizing RPython - it's time.
On 10/11/2010 1:01 PM, John Nagle wrote: (Correct Shed Skin tutorial link) > Shed Skin: > http://shedskin.googlecode.com/files/shedskin-tutorial-0.3.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Standardizing RPython - it's time.
On Mon, Oct 11, 2010 at 4:01 PM, John Nagle wrote: > file:///C:/Users/nagle/AppData/Local/Temp/shedskin-tutorial-0.3.html This gives me a 404. Your Web server is broken! Fix it! ;) Temporarily mirrored: http://jedsmith.org/tmp/shedskin-tutorial-0.5.html -- Jed Smith j...@jedsmith.org -- http://mail.python.org/mailman/listinfo/python-list
Standardizing RPython - it's time.
It may be time to standardize "RPython". There are at least three implementations of "RPython" variants - PyPy, Shed Skin, and RPython for LLVM. The first two are up and running. There's a theory paper on the subject: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.142.1457&rep=rep1&type=pdf All three have somewhat different restrictions: PyPy's Rpython: http://codespeak.net/pypy/dist/pypy/doc/coding-guide.html Shed Skin: file:///C:/Users/nagle/AppData/Local/Temp/shedskin-tutorial-0.3.html Rpython for LLVM: http://code.google.com/p/rpython/ So a language standardization effort, independent of CPython, would be useful. All attempts to make the dialect defined by CPython significantly faster have failed. PyPy did not achieve much of a speed improvement over CPython, and is sometimes slower. Unladen Swallow has not achieved a significant speedup, and is now a year behind on quarterly releases, indicating that the project is in serious trouble. PyPy's RPython, Psyco, and Shed Skin, on the other hand, all achieved order of magnitude or better speedups over CPython. So this is the way to go for higher performance. RPython may be the future of Python, a "golden middle way" between statically and dynamically typed languages. A basic concept of RPython is that it is declaration-free, like the CPython dialect, but limits the ability to change the type of an object at run time. Both PyPy's RPython and Shed Skin use type inference to determine the types of objects. PyPy's RPython has the best defined set of restrictions. Most of the restrictions are for speed, such as the unique-type restriction. A few simply reflect unimplemented features, such as generators. (Generators are not inherently inefficient.) A significant advantage of having a well defined set of restrictions is that it encourages writing Python libraries which will run under both RPython and CPython. This makes migration to a faster system much easier. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
[SOLVED]: Copying a file with a question mark in it's name in Windows
On Aug 12, 9:16 am, Aleksey wrote: > On 12 авг, 18:49,drodrig wrote: > > > A python script I use to backup files on a Windows 2003 server > > occasionally fails to retrieve the size of a file with a question mark > > in the name. The exception I get is "OSError #123 The filename, > > directory name, or volume label syntax is incorrect". I realize that > > technically a question mark in the name of a file on Windows is > > illegal, but nevertheless these files exist on the file system. It > > seems that they are created by Office 2007 Word, for the most part. (Sorry for the late reply) Thank you. The questions marks are indeed placeholders for unprintable characters. The glob module did the trick. > > If "?" is a placeholder for an unprintable character you can try view > real file name in IDLE: > > import glob > print glob.glob(u'e:/full/path/to/file?') > > In path to file you must instead question use wild "?". > Will be printed all like files. > > - > Under Windows I too have similar problem: windows sometimes (from any > programs - e.g. Firefox) save files with wrong names, but later > do not manipulate with it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Copying a file with a question mark in it's name in Windows
On 12 авг, 18:49, drodrig wrote: > A python script I use to backup files on a Windows 2003 server > occasionally fails to retrieve the size of a file with a question mark > in the name. The exception I get is "OSError #123 The filename, > directory name, or volume label syntax is incorrect". I realize that > technically a question mark in the name of a file on Windows is > illegal, but nevertheless these files exist on the file system. It > seems that they are created by Office 2007 Word, for the most part. If "?" is a placeholder for an unprintable character you can try view real file name in IDLE: import glob print glob.glob(u'e:/full/path/to/file?') In path to file you must instead question use wild "?". Will be printed all like files. - Under Windows I too have similar problem: windows sometimes (from any programs - e.g. Firefox) save files with wrong names, but later do not manipulate with it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Copying a file with a question mark in it's name in Windows
On 12/08/2010 12:49, drodrig wrote: A python script I use to backup files on a Windows 2003 server occasionally fails to retrieve the size of a file with a question mark in the name. The exception I get is "OSError #123 The filename, directory name, or volume label syntax is incorrect". I realize that technically a question mark in the name of a file on Windows is illegal, but nevertheless these files exist on the file system. It seems that they are created by Office 2007 Word, for the most part. Could you show us the script you're using? I'm not aware of any way to get a question mark into a file name; even using the file namespace prefix \\?\ doesn't allow it as far as I can tell. Where are you seeing the question mark? Is it possible it's a placeholder for an unprintable character rather than an actual question mark? TJG -- http://mail.python.org/mailman/listinfo/python-list
Copying a file with a question mark in it's name in Windows
A python script I use to backup files on a Windows 2003 server occasionally fails to retrieve the size of a file with a question mark in the name. The exception I get is "OSError #123 The filename, directory name, or volume label syntax is incorrect". I realize that technically a question mark in the name of a file on Windows is illegal, but nevertheless these files exist on the file system. It seems that they are created by Office 2007 Word, for the most part. The line that fails is: os.path.getsize(source) Where source is the full path to the file with the question mark in it's name. Any idea how to retrieve the file's size? Also, I imagine that after I overcome this hurdle, I'll need help finding a way to copy the file (assuming copy2() doesn't work). I've tried escaping the question mark ("\\?"). Same result. Although I could use the Windows "dir" command, parsing the results to find the size of the file then use the Windows "copy" command, I'd rather stay away from this type of solution. Any help is appreciated! -- http://mail.python.org/mailman/listinfo/python-list
It's a fact not lost on the opportunity to see yourself
http://www.google.com/url?sa=D&q=http://osamah2000.jeeran.com/daauageralmuslmeen1.htm&usg=AFQjCNGQhhGz-1TGv9Y7gE8zKwHHustJCg -- http://mail.python.org/mailman/listinfo/python-list
It's a fact not lost on the opportunity to see yourself
http://www.google.com/url?sa=D&q=http://osamah2000.jeeran.com/daauageralmuslmeen1.htm&usg=AFQjCNGQhhGz-1TGv9Y7gE8zKwHHustJCg -- http://mail.python.org/mailman/listinfo/python-list
It's a fact not lost on the opportunity to see yourself
http://www.google.com/url?sa=D&q=http://www.google.com/url%3Fsa%3DD%26q%3Dhttp://osamah2000.jeeran.com/daauageralmuslmeen1.htm%26usg%3DAFQjCNGQhhGz-1TGv9Y7gE8zKwHHustJCg&usg=AFQjCNH5ZzXRqkh5EGL1dsjQxcjNQCmAEQ -- http://mail.python.org/mailman/listinfo/python-list
Re: installing something to a virtualenv when it's already in site-packages
On Fri, Mar 19, 2010 at 4:05 AM, nbv4 wrote: > I have ipython installed via apt. I can go to the command line and > type 'ipython' and it will work. If I try to install ipython to a > virtualenv, I get this: > > $ pip install -E env/ ipython > Requirement already satisfied: ipython in /usr/share/pyshared > Installing collected packages: ipython > Successfully installed ipython > > I want ipython in both site-packages as well as in my virtualenv. This > is bad because when I activate the virtualenv, site-packages > disappears and ipython is not available. A work around is to uninstall > ipython from apt, install to the virtualenv, then reinstall in apt. Is > there a better way? I use -U (--upgrade) to force the installation within virtualenv. e.g: $ pip install -E env/ -U ipython Regards, Rolando -- http://mail.python.org/mailman/listinfo/python-list
installing something to a virtualenv when it's already in site-packages
I have ipython installed via apt. I can go to the command line and type 'ipython' and it will work. If I try to install ipython to a virtualenv, I get this: $ pip install -E env/ ipython Requirement already satisfied: ipython in /usr/share/pyshared Installing collected packages: ipython Successfully installed ipython I want ipython in both site-packages as well as in my virtualenv. This is bad because when I activate the virtualenv, site-packages disappears and ipython is not available. A work around is to uninstall ipython from apt, install to the virtualenv, then reinstall in apt. Is there a better way? -- http://mail.python.org/mailman/listinfo/python-list
Hi, I know it's stupid, but does your foreigner do a lot of OT work?
I'm Chinese, I'm working in a famous vendor company which let employee do a lot of OT work, 2 more hours per day, and sometime work in weekend. Is that the same in USA and European? -- http://mail.python.org/mailman/listinfo/python-list
Re: __import__ returns module without it's attributes?
En Fri, 13 Nov 2009 20:27:29 -0300, Zac Burns escribió: I've overloaded __import__ to modify modules after they are imported... but running dir(module) on the result only returns __builtins__, __doc__, __file__, __name__, __package__, and __path__. Why is this? More importantly, where can I hook in that would allow me to see the contents of the module? Post some code. This works for me: py> import __builtin__ py> builtin_import = __builtin__.__import__ py> def __import__(*args): ... module = builtin_import(*args) ... module.__signature__ = "kilroywashere" ... return module ... py> __builtin__.__import__ = __import__ py> py> import htmllib py> dir(htmllib) ['AS_IS', 'HTMLParseError', 'HTMLParser', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__signature__', 'sgmllib', 'test'] py> htmllib.__signature__ 'kilroywashere' -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: __import__ returns module without it's attributes?
Zac Burns wrote: I've overloaded __import__ to modify modules after they are imported... but running dir(module) on the result only returns __builtins__, __doc__, __file__, __name__, __package__, and __path__. Why is this? More importantly, where can I hook in that would allow me to see the contents of the module? -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games I'm probably not the one to give you the actual answer (at least not in the next couple of days), but I could help you ask a better question. Provide a simple example of your code, and what it does. Describe the python version and OS platform you're running it on. And detail the contents of any extra files or environment values that are needed to reproduce the problem. (You may find http://www.catb.org/~esr/faqs/smart-questions.html useful) BTW, I don't know of any method __import__(), only a builtin function, so I don't see how you can overload it. But your example should make it clear what you really meant. HTH DaveA -- http://mail.python.org/mailman/listinfo/python-list
__import__ returns module without it's attributes?
I've overloaded __import__ to modify modules after they are imported... but running dir(module) on the result only returns __builtins__, __doc__, __file__, __name__, __package__, and __path__. Why is this? More importantly, where can I hook in that would allow me to see the contents of the module? -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games -- http://mail.python.org/mailman/listinfo/python-list
Why does Python not stop when it's supposed to?
So, I'm playing around with Python (running 2.6 and 3.1 versions of IDLE). After I shut everything down and close the windows, I notice the Task Manager's activity light is still glowing. In looking at the Process window I see this: Image...User Name CPU Memory(... Description pythonw.exe mensanator 00 224 K pythonw.exe pythonw.exe mensanator 00 216 K pythonw.exe pythonw.exe mensanator 00 220 K pythonw.exe pythonw.exe mensanator 00 220 K pythonw.exe pythonw.exe mensanator 00 408 K pythonw.exe pythonw.exe mensanator 00 180 K pythonw.exe pythonw.exe mensanator 50 66,156 K pythonw.exe pythonw.exe mensanator 00 600 K pythonw.exe pythonw.exe mensanator 00 228 K pythonw.exe pythonw.exe mensanator 00 208 K pythonw.exe pythonw.exe mensanator 00 224 K pythonw.exe pythonw.exe mensanator 00 224 K pythonw.exe pythonw.exe mensanator 00 192 K pythonw.exe pythonw.exe mensanator 00 224 K pythonw.exe pythonw.exe mensanator 00 180 K pythonw.exe pythonw.exe mensanator 008,672 K pythonw.exe I can't seem to reproduce this. Opening IDLE causes two copies to appear. When RUN, a third appears for a few moments and drops back to two. Doing a RESTART SHELL also launches another copy which also goes away momentarily. So, with a 2.6 and a 3.1 IDLE running simultaneously, there could be 6 copies at once. And they eventually all go away when the windows are closed. How is it I end up with 16 copies, one of them still running after all the windows are closed? I had to manually do an [end process] on all of them. If I was doing something wrong, i sure would like to know what it is. -- http://mail.python.org/mailman/listinfo/python-list
Re: way for a function to understand whether it's being run through a OnCreate callback or not
On Fri, Jul 10, 2009 at 8:18 AM, slamdunk wrote: > is there a way for a function to understand whether it's being run > through a OnCreate callback or not? > I have working functions that I want to recycle through the OnCreate > but need to catch the "nuke.thisNode()" bit inside them so they can > still function when called manually through other scripts functions. I suppose you're programming for The Foundry's Nuke. Python is used in lots of different contexts, and most people on this list use Python for something totally unrelated to video. As an attempt at answering your question, you can add a parameter to your function that tells from where it's called. I.e. you put True in the parameter when it is called from OnCreate, False when it is not. But that isn't a very good design. A function should not need to care from where it is called. You probably want to have the node as a parameter to the function instead of calling nuke.thisNode inside of it. I can't find documentation for the OnCreate function online. Do you mean that you can only call nuke.thisNode() from inside OnCreate? Here's my guess of what I think you want to do: def OnCreate(): # call your function with the current node as argument your_function(nuke.thisNode()) def your_function(node): # The function takes a node as an argument. # Do whatever you want here For more Nuke-specific questions, you'd probably get better results by asking on the Nuke-python mailing list: http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python -- mar...@librador.com http://www.librador.com -- http://mail.python.org/mailman/listinfo/python-list