Re: Errin when executing a cgi script that sets a cookie in the browser
On 06/08/2013 10:56 AM, Νικόλαος Κούρας wrote: its very tedious to always triming everything for me and i know it is for you to ead it assuc. Damn google groups, why is it behaving as such? Dont the programmers know about it? Most of us on the list don't use google groups. A number of us use plain old e-mail to post to the list. If you set up folders and rules in your e-mail client (or labels and filter in Gmail), then messages can go into their own folder. Any way what did you say and i havent understand you correctly? What path do you want me to show to you? He means that you should configure apache to use the real path on your file system, not the symlink. IE if www is just a symlink to public_html, reconfigure apache to not use www at all and use public_html. That way you can avoid these kinds of errors. What does this error means anyway? It means that Apache is unable to find your cgi script. It's turning the url into a file path, but it can't find the file path. Sometimes Apache is configured to not follow symlinks. It's confusing too because you have two apaches installed. The system default one and the one that comes with cPanel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-using copyrighted code
On 06/09/2013 11:18 AM, Mark Janssen wrote: I understand that I have to pick a license for my package. You actually do not. Attaching a legal document is purely a secondary protection from those who would take away right already granted by US copyright. You are correct, except that the OP has already stated he wishes to have his code distributed. Without granting a license, the code cannot be distributed beyond the people he personally gives the code too. PyPi cannot legally allow others to download it without a license. Here's how the GPL puts it, and of course this applies to any and all licenses, even proprietary ones: However, nothing else [besides the License] grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying... -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-using copyrighted code
On 06/09/2013 02:32 PM, Mark Janssen wrote: PyPi. But if you are *publishing*, there's no court which can protect your IP afterwards from redistribution, unless you explicitly *restrict* it. I am not a lawyer, and I haven't read the copyright act in its entirety, nor have I studied all the case law surrounding copyright, but your statement is exactly backwards of anything I've ever read on US copyright. What relevant case law supports this view? It's a very interesting opinion. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-using copyrighted code
On 06/09/2013 08:30 PM, Mark Janssen wrote: Can you provide any citations for your interpretation? Besides that's what the law should be, I mean. I don't think I even have to: the legal code you're citing above is not very clear, consistent, or well-defined at all. As such, it shows that this area remains an area that has yet to be worked out by all parties involved. I would happily volunteer for any interested parties to such a broken system. Alternatively, I've been working on a real fix to IP protections in the form of a unified data model for the internet and data ecosystem. Except that's now how law works in the US. All laws are unclear, inconsistent or ill-defined. Many laws even contradict existing laws. That's why there's a long history and tradition (for good or ill) of courts establishing case law to clarify and codify the implementation of law, and to resolve incompatibilities and consistencies. So while your views may be logical to you, and even common sense, unless case law backs you up, your opinions are irrelevant to the actual implementation of copyright law. As much as many of us are open source or even free software advocates, we do have to live within the copyright law currently, and use (or exploit) it to our benefit and to preserve our rights. Meaning if I as a developer produce code, and if I wish this code to be of use to others while still protecting my own rights under copyright law, I have to adopt a suitable distribution license. And if I use existing code that is already under license, I have to take that into consideration. It's not fair use. It's code license. That is why this issue does matter, and why the original poster asked his questions in the first place. -- http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On 06/11/2013 02:20 PM, Νικόλαος Κούρας wrote: [code] if not re.search( '=', name ) and not re.search( '=', month ) and not re.search( '=', year ): What do each of these functions return? When you print out re.search('=', name) what happens? When you're debugging you should print each of these out. Also make a standalone program (NOT A CGI SCRIPT) for debugging. You can test various inputs by simply going: name = My test name month = Thirteenth year = 2013 One thing I do is to make my code into functions and then at the bottom of each script I have something like this: if __name__ == __main__: # run some test code here # or alternatively do the CGI stuff depending on what # mode you're in. You could even put in debugging flags (apologies to Rick who recently raved against needing to resort to this sort of thing). Consider this code: -- do_something.py --- debug = False def do_something(name, month, year): if debug: print re.re.search( '=', name ) print not re.search( '=', month ) print not re.search( '=', year ) if not re.search( '=', name ) and not re.search( '=', month ) and not re.search( '=', year ): print gonna do query # code follows if __name__ == __main__ debug = True do_something(bob, None, 2012) do_something(None, None, None) do_something(big, Octember, 2067) # other use cases here - Then in your cgi script itself, you just do this: --- my_cgi_script.py --- import do_something # handle cgi stuff # get name, month year dosomething.dosomething(name, month, year) Now to test your code you can just run the module directly with python, and once you've got it working, the CGI will also work, since it pulls in the same code. If this concept is new to you, I strongly urge you to stop development and read through a good python tutorial or get a good python book. -- http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On 06/11/2013 10:49 PM, Michael Torrie wrote: --- my_cgi_script.py --- import do_something # handle cgi stuff # get name, month year dosomething.dosomething(name, month, year) Make that do_something.do_something -- http://mail.python.org/mailman/listinfo/python-list
Re: Eval of expr with 'or' and 'and' within
On 06/14/2013 03:50 AM, Nick the Gr33k wrote: print(name or month or year) abcd print(name and month and year) ijkl Interesting. I'd have thought a boolean expression would return True or False, not a string. Learn something new every day. -- http://mail.python.org/mailman/listinfo/python-list
Re: Eval of expr with 'or' and 'and' within
On 06/14/2013 10:49 AM, Steven D'Aprano wrote: Correct. In Python, all boolean expressions are duck-typed: they aren't restricted to True and False, but to any true-ish and false-ish value, or as the Javascript people call them, truthy and falsey values. snip There are a couple of anomalies -- the timestamp representing midnight is falsey, because it is implemented as a zero number of seconds; also exhausted iterators and generators ought to be considered falsey, since they are empty, but because they don't know they are empty until called, they are actually treated as truthy. But otherwise, the model is very clean. Good explanation! Definitely enlightened me. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On 06/15/2013 07:07 AM, Nick the Gr33k wrote: result = mylist (since its a no-emoty list) result.append('bar') result is mylist True Never seen the last statement before. What does that mean? result is mylist Yes. Surprisingling good question. http://docs.python.org/3.3/reference/expressions.html#is http://docs.python.org/3/reference/datamodel.html One thing that you may find interesting is that what we often call variables in Python, and which from your code's point of view look and act like variables are in fact names. Whereas in C, assignment can be thought of as copy (a = b in C means that b's value is copied to a), in Python assignment is associating a name with an object. Thus a = b in Python means that now the names a and b both are bound (reference to) the same object. That's why the is operator is there, to help one know if two names point to the same object. I bring this up on the list from time to time because I find it really interesting and intellectually appealing the way Python works. Hearkens back to my class at uni on programming language theory. -- http://mail.python.org/mailman/listinfo/python-list
Re: A certainl part of an if() structure never gets executed.
On 06/15/2013 10:18 AM, Nick the Gr33k wrote: a and b you say are names, which still are memory chunks Yes no matter how you look at it, a dictionary of names and objects is memory and variables in that sense. But at a higher level, we can consider the differences with how a language like C defines variables. In both situations we still have 2 memory units holding values, so hows that different? Perhaps one could think of python names as more like pointers or references in C. But python references are counted and garbage-collected (more like a C++ reference-counting pointer type). For example, a = 4 makes the name a be a reference to the object int(4), which will never ever change in its lifetime (indeed it wouldn't make sense for the integer 4 to change otherwise it wouldn't be a 4). Thus a = a + 1 creates a new object that represents the integer value of 4 + 1, and throws the old object away. a = 5 id(a) 2857664 a = a + 1 id (a) 2857680 Note that the identity (object) of a has changed. If a were a variable in the same sense as C, the identity of a would not change. A mutable object like a list acts more like a variable in some ways: b = [] id(b) 3076765292 b.append(3) id(b) 3076765292 In many cases the distinction is little more than intellectual for all intents and purposes, though it some cases the idea is very powerful. But there a couple of cases where the difference between a variable and a name referencing an object does bite people in Python: http://effbot.org/zone/default-values.htm http://stackoverflow.com/questions/986006/python-how-do-i-pass-a-variable-by-reference -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't feed the troll...
On 06/15/2013 11:30 AM, Nick the Gr33k wrote: You are spamming my thread. No he's not. The subject is changed on this branch of the thread, so it's easy to see in any good e-mail reader that this sub-thread or branch is diverting. This is proper list etiquette. -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 06/17/2013 05:34 AM, Simpleton wrote: So is it safe to say that in Python a == a ? ( stands for memory address) is the above correct? It might be partially equivalent inside the interpreter, but it's not something you should concern yourself with. And in general, no it's not safe to say, since Python is a reference-counted, garbage-collected object system and pointers in C certainly are not. I say this because here you said that: Instead, there is a namespace, which is anassociation between some name and some value: When you say that you mean that a is associated to some value as in memory location or to that memory location's address? In python just think of assignment as making a name *be* an object. And if you assign one name to another name, that makes both names be the same object. When names are unbound (either they go out of scope or you manually unbind them), the objects they are bound to are garbage collected. Forget about the details of how the interpreter might doing at a low level. -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 06/18/2013 03:51 AM, Νίκος wrote: Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε: Names are *always* linked to objects, not to other names. a = [] b = a # Now a and b refer to the same list a = {} # Now a refers to a dict, and b refers to the same list as before I see, thank you Steven. But since this is a fact how do you create complicated data structures that rely on various variables pointing one to another liek we did in C++(cannot recall their names) ? As Steve said Python provides all manner of data structures and the means to create data structures. Any data structure (trees, lists, etc) can all be made easily in Python using Python's basic data structures, if the built-in data structures are not sufficient. It turns out that lists, hashes (dicts), and classes can pretty much do anything with having to much about with C-style pointers and such. Do yourself a favor and forget about the low-level stuff in Python for now. You'll be more frustrated if you don't. The real power and expressivity of Python comes from embracing the abstractions that Python provides to your advantage. There's a certain elegance and beauty that comes from such things, which I believe really comes from the elegance and beauty of LISP, some of which manages to shine forth in Python, despite its deficiencies. When I first learned Python, I was impressed that some of the elegance that I remember from Scheme (how to use lists as a basic type for example) was there, but in a form that appealed to me. -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 06/19/2013 11:16 PM, Michael Torrie wrote: It turns out that lists, hashes (dicts), and classes can pretty much do anything with having to much about with C-style pointers and such. Oh wow. Parse error. should read, pretty much do anything without having to muck about with C-style pointers and such. -- http://mail.python.org/mailman/listinfo/python-list
Re: Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]
On 06/19/2013 11:48 PM, Steven D'Aprano wrote: On Wed, 19 Jun 2013 23:16:51 -0600, Michael Torrie wrote: The real power and expressivity of Python comes from embracing the abstractions that Python provides to your advantage. There's a certain elegance and beauty that comes from such things, which I believe really comes from the elegance and beauty of LISP, some of which manages to shine forth in Python, despite its deficiencies. When I first learned Python, I was impressed that some of the elegance that I remember from Scheme (how to use lists as a basic type for example) was there, but in a form that appealed to me. Well said! Glad you made sense of it... the bit about LISP and Scheme came out a wee bit muddled. In fact thinking about it, perhaps LISPers would say about Python what a bible passage says about having the form of Godliness but denying the power thereof! For example, Python's lambda functions, and Python's functional programming capabilities in general. But since the LISP never really got a form beyond S-expressions, leaving us with lots of parenthesis everywhere, Python wins much as the Hitchhiker's Guide to the Galaxy wins. -- http://mail.python.org/mailman/listinfo/python-list
Re: Default Value
On 06/21/2013 07:41 PM, Chris Angelico wrote: While we're at it, I would like to petition for a function terminates(f, args) that I can use to determine whether a function will terminate before I actually call it. Nice idea from a theoretical point of view, but practicality beats purity, and most people know their functions will terminate (that's what Ctrl-C is for). No, I want a function isbuggy(f) to find out whether a function is, well, buggy. We could abolish all unit-testing if we had that. That's awesome. I laughed out loud when I read Ian's comment, though it took me longer than I should have needed to notice your tongue firmly in your cheek as well. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python development tools
On 06/23/2013 02:40 PM, cutems93 wrote: What else do I need? Also, which software is used in daily base? I know version control software and bug tracking software are used almost everyday by developers. Which software is used less often? Phew that's quite a list you have there. Are you coming from Windows development? I personally do all my development with vim, git, and a web browser for reference (or Python in a nutshell book). Dunno why things necessarily have to be complicated. Also, I will use GUI interface for Python. What kind of widget toolkits do you recommend? I know there are GTK+ and Qt. Yes I recommend a nice GUI toolkit. Pick one and try it out. -- http://mail.python.org/mailman/listinfo/python-list
Re: Making a pass form cgi = webpy framework
On 06/23/2013 07:44 PM, Νίκος wrote: Why use mako's approach which requires 2 files(an html template and the actual python script rendering the data) when i can have simple print statements inside 1 files(my files.py script) ? After all its only one html table i wish to display. Sooner or later your needs grow to the point where your single python CGI file is mixing so much html and python code that it becomes unwieldy. And if we wanted to to compare an html template method to a web framework solution? A web framework gives you database abstractions so you can easily target most SQL servers without changing code (MySQL, MS SQL, PostgreSQL, Oracle, etc), and they also provide frameworks for doing authentication and authorization. Authorization in particular becomes unwieldy quickly if you have to do it all in CGI. With a framework it's relatively easy to decorate a view with a wrapper that can only allow the view to be displayed if a web client has logged in with a particular set of permissions (stored in your user database of coures). What are the benefits of one over the other? If you need to do user logins, a framework is going to become rather essential, in my opinion. At least if you need to support fine-grained permissions, which is what most enterprise web apps require (at least the ones I worked on). I know you dont use the latter but this questios is for averybody that does. Personally I feel that a templating engine is essential for any web development, CGI or not. Mixing html and code leads to an unmaintainable mess. A framework is not essential, but often desired. If you don't use a framework, eventually you'll find yourself creating your own framework in essence, though often not nearly as robustly or as flexibly. -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 05:44 AM, cts.private.ya...@gmail.com wrote: Alas, one reason it's a weak workaround is that it doesn't work - at least, not how I wish it would: $ cat ptrs x = 34 def p1 (a1): a1[0] += 12 p1 ([x]) print (x) $ python ptrs 34 you'll have to use it more like this (and also changing your names to be a bit more sane): x = [ 34, ] def test_func( out ): out[0] += 12 test_func(x) print (x) -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 05:21 AM, cts.private.ya...@gmail.com wrote: Thank you. You reminded me of the (weak) workaround of using arrays and confirmed my suspicion that I although I can read the variable, I won't be able to write to it. I still don't understand why not, though... The real problem here is that you don't understand how python variables work. And in fact, python does not have variables. It has names that bind to objects. If you assign a value to a name, you're not overwriting a variable, you're rebinding a name to a new object in the default scope (unless it's declared global, or nonlocal in python 3, the latter I assume uses the same scope in which it was first declared, but I could be wrong). Since the name is in the local scope, the original name in the caller's scope is still bound to its original object. Furthermore, most primitive objects in python (strings, ints, etc) are immutable, which means they can *never change*. Writing to a variable simply dereferences the old object (which may still be referenced in the caller's scope) and creates a new object and binds it to the name. A list is mutable, which is why it's one solution to emulate a variable. As for python 3 ... nonlocal? I see I'm not alone in picking obnoxious names ... nonlocal at least has meaning. -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 11:02 AM, Antoon Pardon wrote: Op 29-06-13 16:02, Michael Torrie schreef: The real problem here is that you don't understand how python variables work. And in fact, python does not have variables. It has names that bind to objects. I don't understand why members of this list keep saying this. Sure the variables in python behave differently than those in C and algol But they behave similarly as those in smalltalk and lisp and I haven't seen anyone claim that smalltalk and lisp don't have variables. We might as well say that C doesn't have variables, it has names pointing to memory locations or value containers or something like that. Sure but a memory location that contains say an int in C *is* a variable, with or without a name. You can change the int stored in that memory address at will, as part of your normal course. Python's basic data types are immutable. At best we could say they are read-only variables. So no, saying Python doesn't have variables is not the same as saying C doesn't have variables but only memory locations. They are different concepts entirely, though on the surface they look similar. AFAICS there is no reason why variable wouldn't be appropiate for python names as opposed to C names. Sure I see your point, but then again, calling them variables is what led to the OP's issue in the first place. So yes they look like variables, and for the most part act like them, except when they don't. Hence the confusion and why I bring up the difference between python's name binding mechanism and how a variable works. It's exactly the concept that was tripping up the OP. -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 07:56 AM, Michael Torrie wrote: x = [ 34, ] def test_func( out ): out[0] += 12 test_func(x) print (x) Well, actually print (x[0]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 12:37 PM, cts.private.ya...@gmail.com wrote: :) Thank you guys for saying what I was biting my tongue about (thanks everybody for the help, BTW!). Sometimes it's best to state the actual problem you're trying to solve and see if there's a pythonic solution that fits it rather than to hack a solution transliterated from C. I'm curious as to if you did get something working and what you ended up with. This python-think stuff was starting to get on my nerves - but then it occurred to me that - although having many powerful features - it has so many weird restrictions that it requires a special way of thinking and problem solving. Interesting point of view. Pythonic ways of programming is in my mind the number one appeal of Python. It's quite clean yet practical. Has enough of the intellectual purity of LISP, Smalltalk, and functional languages to be appealing, yet the practicality of a traditional procedural language. In any language, though you have to grasp the data model. Usually the criticisms of Python come from not a failure to do this, either because it's hard to learn at first, or because people dislike learning something different than what they are used to. A while back we had a fairly pleasant gentleman come on the list from a C# background. His frustrations with Python stemmed from wanting it to be like C#, which of course it isn't. He did not have much success and I'm afraid was left with a sour taste of Python, which of course had nothing to do with the language itself. Python certainly has inconsistencies and there are newbie behavioral gotchas. I have to work with perl's object-orientation stuff again for awhile, in order to see if either has an advantage. Your original post mentioned nothing about object-orientation, so I have no idea how you intend to use OO design, but I think you'll find Python's model fairly workable and consistent. -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 12:51 PM, Steven D'Aprano wrote: You are absolutely correct in principle. But in practice, there are ten bazillion C, Pascal, COBOL, and BASIC programmers who understand the word variable to mean a named memory location, for every Smalltalk or Lisp programmer who understands a variable as a name binding. So it's pure weight of numbers thing. The average Lisp programmer will be completely aware that variable can mean various things, and take care to determine what the word means in Python. She will immediately grok what we mean, even if she thinks that the no variables part is just an affectation (Heh, those wacky Python dudes think they don't have variables!) but at least she'll understand the name binding part. On the other hand, the average C programmer is barely aware that there are other languages at all, let alone that some of them differ from C in semantics as well as syntax. So by emphasising the differences (Python has no variables? It has name bindings?) we increase the likelihood that he'll learn the differences in semantics as well as syntax. So, in a very practical sense, Python has no variables, it has name bindings is completely wrong except in the sense that really matters: Python's variables don't behave identically to C variables. Very good points. Thank you. Good tips for how to better explain things next time it comes up. I'll avoid simply saying Python has no variables. -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 01:19 PM, Steven D'Aprano wrote: Python's basic data types are not necessarily immutable. Lists and dicts are not immutable. Being a high-level language, the idea of primitives like int, double, float, etc from C doesn't really apply. A Python dict is not made up from Python ints. Both int and dict are equally basic. Indeed. Sorry for not being more clear. I was referring primarily to numeric objects and strings. -- http://mail.python.org/mailman/listinfo/python-list
Re: Closures in leu of pointers?
On 06/29/2013 01:20 PM, cts.private.ya...@gmail.com wrote: exactly that. Without wanting to analyze it in too much depth now, I would want a local keyword to allow me to know I was protecting my variables, and a way to specify other scopes, without so much implied scoping in non-intuitive ways... The technical thing you are trying to accomplish, is, as far as I know, not easily doable in Python, except if you use a mutable object like a list. Now everybody is gonna tell me how wrong I am, but you asked what I want, and that's what keeps aggrevating me with python. I presume you're answering the question of what is it you're trying to do. Can't be sure. But chances are good. Far be it from me to tell you how wrong you are. I'm still not even sure what you're trying to do ultimately. -- http://mail.python.org/mailman/listinfo/python-list
Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte
On 07/04/2013 02:25 PM, Ferrous Cranus wrote: try: host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] except: host = Reverse DNS Failed Is there a way to write the above so i cna print the error return when it fails? Do you know what IP address causes the failure? If so write a little python program that does the socket.gethostbyaddr and run it on the command line! Debugging through the CGI interface sucks. Have you been writing python tests that you can run on the command line during your development these last weeks? -- http://mail.python.org/mailman/listinfo/python-list
Re: Stack Overflow moderator “animuson”
On 07/10/2013 06:22 AM, Mats Peterson wrote: You're showing by these examples what regular expressions mean to you. Chris is showing no such thing. And you are simply trolling. What do you want us to do, fall down and worship you and admit that Python is a horrible language and we should all use Perl? What is your point? Are you looking for an admission of Python's slowness compared to Perl? If so, then yes it's slower. For what I need it for, it does not matter. Maybe you could write a better regex engine for python. Then we'd have the best of both worlds. -- http://mail.python.org/mailman/listinfo/python-list
Re: Stack Overflow bans Mats Peterson (was Re: Stack Overflow moderator “animuson”)
On 07/10/2013 06:06 AM, Mats Peterson wrote: I haven't provided a real-world example, since I expect you Python Einsteins to be able do an A/B test between Python and Perl yourselves (provided you know Perl, of course, which I'm afraid is not always the case). And why would I use any custom version of Python, when I don't have to do that with Perl? Oh wow. You really do sound like Ranting Rick. Always wanting someone else to do the work and carry the burden of proof. Since you don't use Python, don't like Python, and don't promote Python, why are you here on this list? Are you evangelizing Perl? Apologies to the list; I hope I'm done. -- http://mail.python.org/mailman/listinfo/python-list
Re: Stack Overflow moderator “animuson”
On 07/10/2013 02:43 AM, Mats Peterson wrote: I fear you don’t even know what a regular expression is. Then this will of course not affect you. Hmm, and your stack exchange posts had a similar tone, hmm? I for one have never ready any of your posts on this forum before, so it looks like you've come here solely to troll. Perhaps your time would be better spent contributing a faster regex engine to the Python standard library. -- http://mail.python.org/mailman/listinfo/python-list
Re: RE Module Performance
On 07/12/2013 09:59 AM, Joshua Landau wrote: If you're interested, the basic of it is that strings now use a variable number of bytes to encode their values depending on whether values outside of the ASCII range and some other range are used, as an optimisation. Variable number of bytes is a problematic way to saying it. UTF-8 is a variable-number-of-bytes encoding scheme where each character can be 1, 2, 4, or more bytes, depending on the unicode character. As you can imagine this sort of encoding scheme would be very slow to do slicing with (looking up a character at a certain position). Python uses fixed-width encoding schemes, so they preserve the O(n) lookup speeds, but python will use 1, 2, or 4 bytes per every character in the string, depending on what is needed. Just in case the OP might have misunderstood what you are saying. jmf sees the case where a string is promoted from one width to another, and thinks that the brief slowdown in string operations to accomplish this is a problem. In reality I have never seen anyone use the types of string operations his pseudo benchmarks use, and in general Python 3's string behavior is pretty fast. And apparently much more correct than if jmf's ideas of unicode were implemented. -- http://mail.python.org/mailman/listinfo/python-list
Re: GeoIP2 for retrieving city and region ?
On 07/13/2013 12:23 PM, Νικόλας wrote: Do you know a way of implementing anyone of these methods to a script? Yes. Modern browsers all support a location API in the browser for javascript. See this: http://diveintohtml5.info/geolocation.html -- http://mail.python.org/mailman/listinfo/python-list
Re: GeoIP2 for retrieving city and region ?
On 07/12/2013 10:32 AM, Νικόλας wrote: So, my question now is, if there is some way we can get an accurate Geo City database. As has been said pretty much by every other poster, there is no way to do get an accurate location database. Period. The databases that do exist were built by hand, and also guessed at based on routing information. The best you can really do is region, or country, and even that fails sometimes. If you want to know a visitor's city you should ask them using the new browser location apis available to javascript. http://diveintohtml5.info/geolocation.html Since IPs can be dynamic, sometimes even assigned across a region, there's no way to accurately map ip addresses to a city with the reliability that you seem to want. Google is pretty accurate because they've spent a lot of time building up their own database, and also convincing users to reveal their locations to them. Unless you do the same thing, you have to just get by with what others have provided for you. -- http://mail.python.org/mailman/listinfo/python-list
Re: GeoIP2 for retrieving city and region ?
On 07/15/2013 06:34 PM, Dennis Lee Bieber wrote: I have no idea how to implement the solution you proposed. These are nice ideas we need to have a way of implement them within a script. I have no way of grasping a map of cell towers of a map of wi-fi hotspots. You don't... The phone company knows where their towers are, THEY do the triangulation based on signal strength from cell phones on their network, and they provide that position to the phone. The phone can then use that data to respond to applications running ON the phone that request location information using the phone's OS API (which is different for an Android phone vs Blackberry vs Apple). I've posted a link to detailed information on this no less than three times, yet Nikos has not read any of it, sadly. -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter redraw rates
On 07/17/2013 05:08 AM, fronag...@gmail.com wrote: Ok. Well, what I'm currently doing, based on advice from this thread, is to create a new thread that handles the downloading, as well as updating a variable for text display on the GUI, and in the main thread, just after the thread is created, a while loop that updates the GUI while the thread is running. Not sure what you mean by while loop. In an event-driven paradigm, one technique would be to set a timeout event that fires every so many ms. Then in the event callback, you update the widget according to the new value of the variable. At least this is how i'd do it in Qt or GTK. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why on CentOS, python consumes too much memory ?
On 07/18/2013 03:13 AM, William Bai wrote: I found that it was caused by not by python but by /usr/lib/locale/locale-archive, the same problem as that described in http://illiterat.livejournal.com/4615.html. Too funny. So in other words there isn't a problem at all. What you thought was RAM usage was really just a memory-mapped file. That's why Antoine said that using VSS to determine memory usage is not valid at all in determining memory footprint. VSS shows all kinds of things from shared libraries to locale archives that have zero impact on RAM usage. Every app will show at least the size of glibc in its VSS number. What is too much memory anyway? What do you mean by consume too much memory? Now if your script has a resource leak and is long-running, then that's a problem, but the solution is to fix your resource leak, not have the OS kill your app when it exceeds the RLIMIT. -- http://mail.python.org/mailman/listinfo/python-list
Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project)
On 07/17/2013 11:39 PM, Eric S. Johansson wrote: Not discourage you but this is a been there, done that kind of project. You could learn more from reading somebody else is code. What hasn't been done, and this would be very cool, is a chat program that works peer-to-peer with no central server. To do this, you would probably need to know about distributed hash tables and methods of piercing address translation firewalls (think UDP). University CS curricula across the world would disagree with your assessment of the usefulness of been there, done that. Indeed that's how you learn by doing simple things that have been done many times before, and discovering the magic of programming and software design. My uni's CS undergrad degree consists of dozens of contrived projects that have been done before. Web crawlers, compilers, expert systems, chat systems, word counters, etc. And that's the same way with all fields of endeavor. Indeed it'd be silly to tell an enthused hobby builder that building a shed is pointless as it's been done before. The shed itself, which would arguably be useful, is beside the point. -- http://mail.python.org/mailman/listinfo/python-list
Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project)
On 07/18/2013 12:19 PM, Owen Marshall wrote: Huh - I (foolishly) didn't realize gmane actually had NNTP, I've always used it to search mailing lists. If the list dumped to usenet (much like c.l.python) I'd post through sunsite.dk, which is a very nice usenet provider. But that still meant several annoying mailing list subscriptions. ... man, I'm really glad I read your post :-) I'm a bit confused. This list *is* c.l.python (I happen to read via e-mail through the mailing list). So you can reach it from sunsite.dk can you not? -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I make this piece of code even faster?
On 07/21/2013 04:19 AM, pablobarhamal...@gmail.com wrote: Thank's for all the replies! I've tried some of the imporovements you suggested (using math.exp() and sum() or math.fsum()). None of that made the code faster, because they are functions you are calling lots of times, and function calling is quite time expensive (same as x**(1/2) is faster than math.sqrt(x)). I'm going to try to convert tu numpy now (I have no idea how to do it at the moment), thank's again to everyone. Perhaps you'd have better results if you'd post a runnable piece of code. Otherwise we're just guessing since no one has the ability to actually run your code. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/21/2013 10:19 AM, Gilles wrote: So, does someone know of a good, SMTP server just to send e-mails? What you're looking for is not an SMTP server but a Mail Transfer Agent, called an MTA. Pretty much all distros ship with an MTA by default, even if the SMTP server part of it isn't installed or running. And often the MTA is, for compatibility reasons, /usr/sbin/sendmail. http://stackoverflow.com/questions/73781/sending-mail-via-sendmail-from-python I'm sure there are MTA's implemented in python. Now that you know what they are called (not SMTP servers!) you can search for them. Dennis is correct, though, that most ISPs do block outbound port 25 connections for security and spam reasons, and require you to use their SMTP server, which precludes the use of the local MTA. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/21/2013 02:34 PM, Gilles wrote: Thanks for the infos. Ideally, I was looking for a simple Windows app as MTA, but a Python script is OK. The Sendmail MTA has been ported to many platforms including windows. But... I'm not sure my ISP blocks outbound port 25 connections. I'll experiment with a small Linux box. Having spent a long time managing e-mail servers, everything Ivan said in his reply is true as well. I had forgotten a lot of that since I haven't been running my own mail server (MTA or server part) in a while. I've sold my soul to Google for e-mail now with Google Apps for my domain. I wist they would use a smarter SPAM filter that wouldn't flag perfectly legit-looking outgoing e-mails. But then how would it know that legit-looking e-mails aren't in fact SPAM? E-mail is starting to be an almost intractable problem. No wonder the younger generations are just abandoning it entirely in favor of centralized, cathedral-style messaging systems such as facebook. -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner - GUI devlopment in Tkinter - Any IDE with drag and drop feature like Visual Studio?
On 07/21/2013 05:20 AM, Chris “Kwpolska” Warrick wrote: On Sun, Jul 21, 2013 at 1:14 PM, Dave Cook davec...@nowhere.net wrote: On 2013-07-20, Aseem Bansal asmbans...@gmail.com wrote: Do I need to use QtCreator with PySide if I want drag-and-drop feature for GUI development? No, you just need the layout part of QtCreator, called QtDesigner, and any decent Python editor or IDE (e.g. Idle): …and one more thing: pyside-uic, for transforming the .ui files into (ugly) .py files. It seems to be in /PythonXY/Scripts according to Stack Overflow if you have PySide installed. I don't think you want to be converting ui files into python classes. Just use the PySide Qt api for loading them at runtime. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/22/2013 06:51 AM, Chris Angelico wrote: Thanks for the tip. I didn't know about SPF http://en.wikipedia.org/wiki/Sender_Policy_Framework It's a great way of detecting legit vs forged mail. If anyone tries to send mail purporting to be from anyth...@kepl.com.au and the receiving mail server is checking SPF records, it'll be rejected after one cheap DNS lookup. It's a simple and cacheable way to ask the owning server, Is this guy allowed to send mail for you?. (The 192.168 block in my SPF record above is permitted to allow some intranet conveniences; omit it unless you need it.) Yes setting SPF records will help your mail be accepted by other servers, but I disagree with your appeal to make mail server SPF handling as strict as your server does. SPF has problems in a number of situations which could cause legitimate mail to be rejected. In my last job I could only use SPF as one spam factor, not as a basis for rejection. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/22/2013 06:19 AM, Gilles wrote: On Sun, 21 Jul 2013 21:01:09 + (UTC), Grant Edwards invalid@invalid.invalid wrote: Unless you've got a static IP address, a domain name, and a valid MX record that will match up when they do a reverse DNS lookup, it's pretty unlikely that you're going to have much luck running an SMTP server. Most other SMTP servers are probably going to ignore or reject your attempts to transfer mail from your own SMTP server. Incidently, how do ISP MTAs find whether the remote MTA is legit or running on some regular user's computer? 1. Query Reverse DNS for IP 2. Find domain 3. Query DNS for MX 4. ? My mail server did a number of things: 1. ensure IP address of sending server has a reverse name (domain didn't particularly matter) 2. ensure the HELO address in SMTP matches IP address of sending server 3. check sender IP address against spam blacklists, which includes netblocks of home ISPs, some entire countries, flagged subnets 4. greylist sender IP if the recipient requested it. First connection always fails with a nonfatal server error, next connection must wait at least 5 minutes. If a reconnection happened too quickly, the IP was temporarily black listed. After success, IP address is whitelisted for a time. A commandline MTA will not be able to get through greylisting; only a mail server with queuing could. Spambots tend to give up on the first error, even now. Cheaper targets I guess. 5. spamassassin checked SPF (DNS) and domainkeys (message itself) and weighted the spam factor accordingly I think there were other basic rules that sendmail applied to the sender, but I can't remember all of what they are. This is well and truly off topic now for the python list, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/22/2013 06:11 AM, Gilles wrote: On Sun, 21 Jul 2013 18:28:27 -0600, Michael Torrie torr...@gmail.com wrote: The Sendmail MTA has been ported to many platforms including windows. But... Thanks for the tip. Since I couldn't find a good, basic, native Windows app, I was indeed about to look at eg. Exim + Cygwin, and resort to a Linux appliance if none footed the bill. Where did you look? Here's one I found. It's not the real sendmail program, but it implements the interface which is all you need: http://glob.com.au/sendmail/ I just googled for sendmail win32 -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/22/2013 08:15 AM, Chris Angelico wrote: If legit mail is rejected for failing an SPF check, it's the sending admin's problem, not yours. You should never have problems with it if it's set up correctly. And since rejected mail gets reported to the transmitting MTA, you don't need to drop it in a spambox or anything. It's not spam, it's simply invalid mail (equivalent to something sent to a dud address). Sure. Tell that to the people you work for who depend on e-mail. When I was a sysadmin (quite recently), I'd have gotten fired for enforcing such an arbitrary policy. Indeed when mail wasn't coming through that someone in the organization was expecting and wanting, regardless of SPF, it was indeed *my* problem and my job was on the line. BOFH attitudes simply aren't going to change that reality. SPF is just one more of the many things that are contributing overall to absolutely breaking and demise of SMTP. I'm afraid when it does finally cease to work, it's going to be replaced with less open, centrally-controlled messaging systems like facebook. Which is unfortunate. -- http://mail.python.org/mailman/listinfo/python-list
[OT] SPF - was Re: Simple Python script as SMTP server for outgoing e-mails?
On 07/23/2013 03:30 AM, Chris Angelico wrote: On Tue, Jul 23, 2013 at 7:19 PM, Chris Angelico ros...@gmail.com wrote: Ah, there's a solution to this one. You simply use your own envelope-from address; SPF shouldn't be being checked for the From: header. There's an example, by the way, of this exact technique right here - python-list@python.org sends mail to me with an envelope-from of python-list-bounces+rosuav=gmail@python.org - which passes SPF, since python.org has a TXT record designating the sending IP as one of theirs. It doesn't matter that invalid.invalid (your supposed domain) doesn't have an SPF record, nor would it be a problem if it had one that said v=spf1 -all, because that domain wasn't checked. Mailing lists are doing the same sort of forwarding that you're doing. This is good and all, and I think I will modify my local postfix mail server I use for personal stuff, just for correctness' sake. I hadn't spent much time studying SPF in depth before, but after reading your comments (which were insightful) I'm now more convinced that SPF is worthless than ever, at least as a spam prevention mechanism. Spammers can use throwaway domains that publish very non-strict SPF records, and spam to their hearts content with random forged from addresses and SPF checks pass. The only way around that is to enforce SPF on the From: header in the e-mail itself, which we all agree is broken. I've been reading this: http://www.openspf.org/FAQ/SPF_is_not_about_spam Not very encouraging. When the other expensive options for going after spammers who have valid SPF records, they propose domain blacklists as a solution. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Python's import statement and the history of external dependencies
On 11/21/2014 11:24 AM, Rick Johnson wrote: Why am *i* the fool when it's obvious that the creators of Python were either shortsighted and/or careless with the designs? The only people who suffer are those who put their trust in the designer, and not the designer himself -- something is wrong with this picture! So if you know how to create the perfect language that has a solution to these very difficult problems, please come forward with it. Until such time, it's okay to identify problems with the language as you see them, but to cast aspersion on the developers is out of line. Do you know Guido personally to know that he's short-sighted or careless? I certainly don't, but from what I can see he is neither. Not perfect, but pretty darn smart. Much smarter than I am (despite the fact I can also recognize several of Python's flaws). The same goes for many other core developers. They tend to be smart, articulate, and know how to communicate with people. Everything is about trade-offs and the ones Python makes work very well for most people. Perhaps the problem with the picture is that you are unable to see it clearly. I assure you that Python developers not only create Python, they use it too, for their own purposes. Why would think they are some sort of cabal getting kicks from leading the poor masses of Python programmers at their whim? -- https://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Python's import statement and the history of external dependencies
On 11/21/2014 01:29 PM, Rick Johnson wrote: Not personally. But how will we *ever* know if he refuses to participate in these discussions? Why should he participate in these discussions? Why should you be in charge of said discussions? By the way, Python has more than certainly borne fruit, and the vast majority of it is very good indeed. -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI toolkit(s) status
On 11/20/2014 02:17 AM, Chris Angelico wrote: But I agree about the issues with tkinter. So, let's see. Shall we wait for Tcl/Tk Unicode support? Recommend people switch to PyGTK? To PyQt? To wxPython? To something else? Personally, I'm quite happy with GTK2 (though that's with Pike, not Python), and it does have full Unicode support; but there are some issues with the interface that make it feel a bit clunky. Every other windowing toolkit has its own flaws. Even if one of them were to be blessed into the stdlib (which would remove the whole but it's an external dependency problem), there's still no perfect option, and every toolkit will have its staunch supporters. GTK2 and GTK3 are pretty sweet to work with in Python. The bindings are very nice and fairly idiomatic. So it feels natural. However GTK is not really cross-platform in any usable way. It's really Unix-only, though more and more it's moving towards Linux-only. Due to a lack of manpower and demand, the Windows port lags far behind X11, and despite decent theming support (I think it can employ mstheme.dll to draw widgets), it feels foreign and clunky. On Mac things are even worse, as far as I can see. Just not enough people who can and want to contribute there. I can't speak for wxWidgets, but when I last looked at it years ago it fairly reeked of MFC-style GUI programming with event tables instead of a nice, flexible signal/callback interface. Has this changed? My current recommendation is to use PyQt or PySide. I'm going to look at PySide soon, but PyQt feels a bit foreign on Python. Code comes out looking like C++ using Python keywords. It has its own facilities for many things as well that overlap Python's standard libraries. But all in all it is the most cross-platform of any that I've seen. It looks and can act fairly native on Windows and Mac. Ironically I find Qt looks best on Linux when using the GTK theme engine. -- https://mail.python.org/mailman/listinfo/python-list
Re: SQLite3 in Python 2.7 Rejecting Foreign Key Insert
On 11/22/2014 08:54 PM, llanitedave wrote: Well that DID make a difference! I used the %r marker, and the logger line gave me back: INFO:Related borehole_id is u'testbh3', of_borehole is 'testbh3' So it looks like I need to change my foreign key string to a unicode string. I'll be working on that... Or manually encode it to a UTF-8 byte string (just call .encode() on it). Sqlite probably only knows about UTF-8 when it comes to unicode. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why do I keep getting emails from Dennis?
On 11/23/2014 08:21 PM, Sayth Renshaw wrote: I keep receiving emails from Dennis and it appears Dennis only on this list, I am signed up to comp.lang.python and am unsure why I keep getting Dennis' s emails. If you post to the newsgroup, using your e-mail address as the from address, when people who use this list via e-mail respond, and click reply all it will go back to the list and to your e-mail address. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Signal/Slot + QThred code analysis
On 11/24/2014 06:25 AM, Juan Christian wrote: Oh, and this code I made by myself, I didn't copy. That's why I want you guys to see if everything is ok. Looks alright. Does it work? -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Python Signal/Slot + QThred code analysis
On 11/25/2014 02:36 PM, Juan Christian wrote: So guys, I had to change to approach, I read that using Qt I can't do multiple inheritance. So my Outpost class can't be like 'Outpost(QObject, QThred)'. I had to change the code a bit: snip So, let's see the problems: Traceback (most recent call last): File D:/.../main.py, line 44, in output_slot outpost = Outpost('12345') File D:\...\outpost.py, line 27, in __init__ self.received.emit(worker) TypeError: received() only accepts 0 arguments, 2 given! You're going to have to post a complete, but small, code example, I think. Working with fragments of code is very difficult if not impossible to assist with, resulting in obtuse, obvious replies from folks. -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI toolkit(s) status
On 11/26/2014 02:40 AM, Dave Cook wrote: On 2014-11-22, Michael Torrie torr...@gmail.com wrote: I can't speak for wxWidgets, but when I last looked at it years ago it fairly reeked of MFC-style GUI programming with event tables instead of a nice, flexible signal/callback interface. Has this changed? In Python? I've been using wxpython for 6 or 7 years, and it's always used callbacks in Python. The API is not as polished or extensive as Qt, but it's still very capable. I think it's easier to write custom widgets in wxpython because there are so many examples to follow. Recently I decided to use PyQt for a project that was required to run on win32 and OS X, and for some reason my layout, wich was fine under win32, was screwed up on OS X. I switched back to wxpython 3.0, which looks very good under OS X. What kind of layout did you use? I've never had this problem with Qt or Gtk. Even when the font sizes and screen resolution changes. That's the beauty of the self-adjusting layouts. -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Python Signal/Slot + QThred code analysis
On 11/26/2014 02:55 PM, Juan Christian wrote: On Wed Nov 26 2014 at 1:16:11 AM Michael Torrie torr...@gmail.com wrote: You're going to have to post a complete, but small, code example, I think. Working with fragments of code is very difficult if not impossible to assist with, resulting in obtuse, obvious replies from folks. As asked, here is all the code: outpost module: http://pastebin.com/H3K9UUWi main module: http://pastebin.com/dFzums9W I was trying to do other things there but I ended up screwing everything. I'm sorry I can't run the code you posted. I don't seem to have any modules named request on Python 3 or Python 2 and your Trader.py seems to require it. You might want to remove the url downloading and Beautiful Soup stuff and put in some kind of nop loop instead to simulate it. For example, in the Trader module you can remove everything in run() and just have it return dummy values, maybe putting in a delay to simulate the work of downloading and parsing. Just an observation from looking at the main module code. You only need to attach a callback to a signal once. output_slot() seems to attach the callback each and every time the timer fires. This is surely wrong. I'll give it some further study this evening. -- https://mail.python.org/mailman/listinfo/python-list
Re: Issues installing Python 2.7
To further explain my terse post from before (from my phone), see below. On 11/26/2014 10:09 AM, billyfurl...@gmail.com wrote: Now the installation worked fine but shouldn't I see that it's using the correct version??? I also did try to run /opt/python2.7/bin/python2.7 and it give me this. [root@wmy machine bin]# python2.7 python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory Please help the newb. He's frustrated. So the longer answer is that only certain directories are searched by Linux for shared libraries. Python happens to provide a shared library, which it depends on, which is installed by the source tarball in /opt along with the binaries. There are a number of ways you can solve this: - Create a file in /etc/ld.so.conf.d/python2.7.conf and place in it the following path: /opt/python2.7/lib - before running /opt/python2.7/bin/python2.7, set the LD_LIBRARY_PATH environment variable (example in bash): $ LD_LIBRARY_PATH=/opt/python2.7/lib /opt/python2.7/bin/python2.7 - create a wrapper script in /usr/bin that sets LD_LIBRARY_PATH and execs python2.7 I recommend the first as a permanent solution. -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Python Signal/Slot + QThred code analysis
On 11/26/2014 08:57 PM, Michael Torrie wrote: On 11/26/2014 02:55 PM, Juan Christian wrote: On Wed Nov 26 2014 at 1:16:11 AM Michael Torrie torr...@gmail.com wrote: You're going to have to post a complete, but small, code example, I think. Working with fragments of code is very difficult if not impossible to assist with, resulting in obtuse, obvious replies from folks. As asked, here is all the code: outpost module: http://pastebin.com/H3K9UUWi main module: http://pastebin.com/dFzums9W I was trying to do other things there but I ended up screwing everything. I'm sorry I can't run the code you posted. I don't seem to have any modules named request on Python 3 or Python 2 and your Trader.py seems to require it. You might want to remove the url downloading and Beautiful Soup stuff and put in some kind of nop loop instead to simulate it. For example, in the Trader module you can remove everything in run() and just have it return dummy values, maybe putting in a delay to simulate the work of downloading and parsing. Just an observation from looking at the main module code. You only need to attach a callback to a signal once. output_slot() seems to attach the callback each and every time the timer fires. This is surely wrong. I'll give it some further study this evening. Hmm, I hit a wall. There's no main.ui file. Can you rework your code so that you have a single file (plus a separate ui file that's okay), that simulates the url request, that I can execute easily. Here's how you can simulate the web page load: from PySide.QtCore import QObject, QThread, Signal import random import time class Worker(QThread): def __init__(self, url, *args, **kwargs): super().__init__(*args, **kwargs) self.trades = 'NODATA' self.posts = 'NODATA' self.url = url self.start() def run(self): # simulate a web request by sleeping a random time and returning # random strings. time.sleep(random.random() * 2) self.trades = str(random.random() * 25) self.posts = str(random.random() * 100) return self -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Python Signal/Slot + QThred code analysis
On 11/27/2014 04:58 AM, Juan Christian wrote: What I have in mind is simple (I think), have the Outpost get the data using QThread, and when it got everything needed emit a signal. So when I have something like 'var = Outpost('123')', when I get the signal I'll know that I can call 'var.trades, var.posts' and it won't give me NullErrors or something like that. So there are a number of logic problems in your code. The main one is that the call to create your worker class returns immediately. It's not part of the thread itself. So your signal logic will never work. This was a good excuse for me to dive into Qt a bit more. So it turns out that QThread objects can have their own event loops. This turns out to be quite ideal for what you want. So here's a Worker class does everything you want, but with only one instance, and uses signals properly: class Worker(QThread): # This is the signal that we'll emit every time # we load a new set of values from the url new_value = Signal(str,str) def __init__(self, url, *args, **kwargs): super(Worker, self).__init__(*args, **kwargs) self.url = url self.start() def run(self): # Since we're going to run a mini event loop in the thread # we can create and use a timer here self.timer = QTimer() self.timer.start(5000) self.timer.timeout.connect(self.fetch_url) # Start the thread's event loop self.exec_() def fetch_url(self): # Doesn't matter how long this takes because it only # blocks the thread's event loop, not the GUI time.sleep(random.random() * 2) trades = str(random.random() * 25) posts = str(random.random() * 100) # communicate the values via the signal self.new_value.emit(trades, posts) So with this, you can instantiate it once, then tie the new_value signal to a callback in the main loop. So no need for the Outlook object, and no intermediate callbacks. The thread signals directly. And the callback receives the data directly, so no check for NODATA values and such: def create_topic(trades, posts): box = QGroupBox() grid = QGridLayout() nickname = QTextEdit() box.setFixedHeight(200) nickname.setText(%s : %s % (trades, posts)) grid.addWidget(nickname) box.setLayout(grid) # Access global variable MainWindow, defined below MainWindow.vlay.addWidget(box) Hope this helps. Here's complete working code, minus the .ui file: http://pastebin.com/VhmSFX2t -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Python Signal/Slot + QThred code analysis
On 11/27/2014 04:29 PM, Juan Christian wrote: So, instantly I found one issue, you said that this code won't block the GUI, only the thread event loop, but if we keep moving the window while it's open, every time new info is printed the GUI freezes for like 1-2 seconds. Correct. The thread does not block the GUI. I cannot replicate your problem on my machine here. Maybe we're finding a problem with Windows and Qt. I can drag the window around and it keeps on a going. And why this approach of a single instance is better? I mean, I'll have to call Outpost every time I get new data from my other API, because there will be different users, so I need to create different instances so I call the site with a new ID, don't I? Just seems wasteful, that's all. Why not instantiate Outpost from the worker thread? Especially if your thread only does one thing every 5 seconds. Starting up a new thread and destroying seems like a waste. But it certainly can be done that way. Maybe the answer for that question is that you using a timer that is ALWAYS active and ALWAYS calling the the outpost site, so I'll have something like: var = Outpost('12345') var.posts - 100 var.setID('67893') var.posts - 35 Is that right? But I don't think that always calling the site this way is good for them and for me, sometimes I may not get new users for like 10~15 minutes, so I would have wasted a lot of calls for nothing. That's why I only instantiate/call the site when I get new users. I was simply using the logic you originally provided. I have no idea what Outpost does or how you use it. Your original code just grabbed some data every 5 seconds, so that's what I got it to do in the most efficient way. You'll have to adapt it to your real needs. -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Python Signal/Slot + QThred code analysis
On 11/27/2014 04:29 PM, Juan Christian wrote: Is that right? But I don't think that always calling the site this way is good for them and for me, sometimes I may not get new users for like 10~15 minutes, so I would have wasted a lot of calls for nothing. That's why I only instantiate/call the site when I get new users. So the real problem with instantiating a worker thread for every request is that you have to hold onto a reference to the worker long enough for the work to be done. Your original code was not doing this, so had it worked, the thread would have been aborted before it even started its work, as soon as the worker instance went out of scope. -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Python Signal/Slot + QThred code analysis
On 11/27/2014 04:29 PM, Juan Christian wrote: Is that right? But I don't think that always calling the site this way is good for them and for me, sometimes I may not get new users for like 10~15 minutes, so I would have wasted a lot of calls for nothing. That's why I only instantiate/call the site when I get new users. Okay, here's a reworking of the code that invokes a new QThread instance each time. Note the QThread instance has to be bound to the MainWindow so that it won't be destroyed when it goes out of scope. Also the Worker thread sends a signal with the data, so there's no need to check worker.trades and risk it being invalid data. Perhaps this would be more what you had in mind. You may want to look into asynchronous I/O as well. That does not require threads at all. Fire off a request to load a url, and then get a callback when it's done. Anyway, here's the code (too lazy to post it to pastebin): import time import random from PySide.QtCore import QObject, QThread, Signal, QFile, QTimer, Qt from PySide.QtGui import QGroupBox, QGridLayout, QTextEdit, QApplication from PySide.QtUiTools import QUiLoader class Worker(QThread): # This is the signal that we'll emit every time # we load a new set of values from the url new_value = Signal(QThread, str,str) def __init__(self, url, *args, **kwargs): super(Worker, self).__init__(*args, **kwargs) self.url = url self.start() def run(self): # Doesn't matter how long this takes because it only # blocks the thread's event loop, not the GUI print ('Starting work...') time.sleep(random.random() * 2) trades = str(random.random() * 25) posts = str(random.random() * 100) print ('Finished work.') # communicate the values via the signal # we have to pass self so that the callback # can properly clean up after the thread. self.new_value.emit(self, trades, posts) def loadui(file_name): loader = QUiLoader() uifile = QFile(file_name) uifile.open(QFile.ReadOnly) ui = loader.load(uifile) uifile.close() return ui if __name__ == __main__: import sys # Putting this in here because it requires access to MainWindow # which only exists if this part of the code runs. def create_topic(worker, trades, posts): box = QGroupBox() grid = QGridLayout() nickname = QTextEdit() box.setFixedHeight(200) nickname.setText(%s : %s % (trades, posts)) grid.addWidget(nickname) box.setLayout(grid) # Access global variable MainWindow, defined below MainWindow.vlay.addWidget(box) # clean up the worker to prevent resource leak. worker.quit() worker.wait() def output_slot(): # in order for the thread to stay running, we have to bind it to the # Main Window, which we worker = Worker('http://www.tf2outpost.com/user /' + id64, MainWindow) worker.new_value.connect(create_topic) app = QApplication(sys.argv) MainWindow = loadui(main.ui) MainWindow.vlay.setAlignment(Qt.AlignTop) timer = QTimer() timer.start(5000) timer.timeout.connect(output_slot) id64 = '123' MainWindow.show() app.exec_() -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: Python Signal/Slot + QThred code analysis
On 11/28/2014 06:06 AM, Juan Christian wrote: Which one would be better in performance, having a single 'Worker' to call all URLs, having inside this worker functions for each stuff, or having 3~5 different workers doing different stuff. In the end I'll only print the data when I have them all. The problem is that I would have a long new_value = Signal(QThread, str, str), with more then 10 values, is it possible to pass objects here like new_value = Signal(QThread, ObjA, ObjB, ...) so that in the 'create_topic' I would get the objects and call methods in order to get all the data? Yes you can pass objects through signals. You could pass a dict, or an instance of one of your own classes. You could also go back to your first architecture and pass in an Outpost class instance to the worker thread when instantiating it, and then the worker could use the outpost instance to perform the work, then pass it back to your handler through the signal. This approach would be better, because I may be adding more stuff and I wouldn't need to add tons and tons of new stuff in my signal, only one object. You don't need to redo the code, I just need to know if it's a 'good approach' and if it's possible, from here I can work my way. Yeah sounds alright. I'm sure there are multiple ways of doing this that would work. -- https://mail.python.org/mailman/listinfo/python-list
Re: Iterate over text file, discarding some lines via context manager
On 11/28/2014 08:04 AM, fetchinson . wrote: Hi all, I have a feeling that I should solve this by a context manager but since I've never used them I'm not sure what the optimal (in the python sense) solution is. So basically what I do all the time is this: I'd personally do it with a generator function. def filter(input): for line in input: if not line: # discard empty lines continue if line.startswith( '#' ): # discard lines starting with # continue items = line.split( ) if not items: # discard lines with only spaces, tabs, etc continue yield items for line_items in filter(open( 'myfile' )): process( items ) For an excellent presentation on this sort of thing, see: http://www.dabeaz.com/generators/ -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Unicode decode exception
On 11/30/2014 09:19 PM, balaji marisetti wrote: The default encoding is UTF-8. It works if I do: with open(filename, errors=ignore) as f: So I think Python2, by default, ignores all errors whereas Python3 doesn't Do you mean that the file is supposed to be utf-8 but isn't? Because if it is, you need to tell open about it in Python3 to make sure that's the decoding scheme it uses. Otherwise you will see this decode error. Also I'm not sure you posted the full traceback. Usually a UnicodeDecodeError says something about an invalid byte while using a specific unicode decoding scheme (say, ASCII, which can't handle utf-8 bytes). -- https://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI development
On 12/01/2014 08:49 PM, Ganesh Pal wrote: Thanks for the bunch of suggestion , I have decided to go with PYQt for now : ) If the licensing of PyQt is not appropriate for you (it's GPL only, unless you buy a license), you can use PySide, which is almost a drop-in replacement for it, that's licensed more liberally under the LGPL which does allow its use in a non-GPL program. Not sure if this matters to you, but if you're planning to release your code ever, or sell a product some day, you'll need to be aware of this. -- https://mail.python.org/mailman/listinfo/python-list
Re: Proposed new conditional operator: or else
On 12/02/2014 10:18 AM, Roy Smith wrote: In the process of refactoring some code, I serendipitously created what I think is an essential new bit of Python syntax. The “or else” statement. I ended up with: sites_string = args.sites or else self.config['sites'] But isn't that syntactically equivalent of this? sites_string = args.sites or self.config['sites'] Seems to be what you're looking for with or else unless I misunderstand what you're proposing. Doing a bit of testing in the interpreter and I find that a combination of Python's truthiness semantics and short-circuit evaluation seems to give a consistent result. Consider: 'a word' or False = 'a word' 'a word' or True = 'a word' False or 'a word' = 'a word' True or 'a word' = True Is this similar to what you'd expect with or else? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On 12/02/2014 07:27 PM, Skybuck Flying wrote: Excuse is: bad programming style. I don't need snot telling me how to program after 20 years of programming experience. This is so far the only thing pissing me off in python. Now I have to declare global in front of these variables every where I want to use em: Only if you want to overwrite them, though. Python has support for any number of programming paradigms. That many global variables is screaming for some kind of organization and Python has good mechanisms for doing this in a much neater way. Might I suggest you use a namespace instead? Put all your globals in a module, and refer to them via the module. For example (converting to pep8 which looks better to me): import globals as g def some_func(): g.ship_ability_distribute_shield_power = 5 A whole lot cleaner than trying to use the global keyword everywhere. If you've really been programming for 20 years, surely you're familiar with programming patterns. The fact that you have 6 variables all prefixed with ShipAbility should suggest something to you. Like maybe all of these attributes could be encapsulated in one ship object. Python is very flexible in how you use objects. You can program in strict java-style if you want, or adopt a more freeform approach: ship = object() ship.ability = object() ship.ability.distribute_shield_power = 5 etc. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On 12/02/2014 09:32 PM, Skybuck Flying wrote: Some issues I'd like to address to you: 1. Structured programming requires more programming time. 2. Structured programming implies structure which might be less flexible. 3. Python objects require self keyword to be used everywhere, and other akwardness wich leads to more typing/programming/writing time. You forgot to mention that horrible white-space being syntax! Surely that is inflexible and awkward! I used to program in Delphi, there I would do everything OO and modular. Python allows you to explicitly use an OO paradigm if you wish, or use a more procedural form, or functional form (to a degree anyway). All the while using and exploiting object-oriented characteristics (modules, attributes, etc) throughout. It's really the best of both worlds. Lastly I also don't like the module approach in python because the sikuli ide doesn't really support working with multiple files that well. A poor craftsman blames his tools for his own shortcomings. I suggest you change tools to something a little more flexible (just about anything really) Even if it did, having all code in one big file is a pretty big adventage. Not really. Keeping things as simple as possible and modular is easier to debug, easier to test, add features to, and easier to understand three months from now. I can tell by your opinions that you've never done any medium to large-scale development before. So features I miss in python are: labels goto statements and repeat until. Python is newbie friendly (mostly), but it is a far, far more powerful, capable, and expressive language than Delphi ever was. Take a theory of computer languages class some time (create your own language even... Scheme is a good place to start). It might open your eyes a lot. Python is not just a scripting language, it's a powerful application development language that allows me to create code rapidly that actually works. I'm far more productive in Python than in any language I've used to date. Funny thing is these goto statements would be very handy for bot programming, so it's a painfull feature to miss. Haven't heard that argued in many years. And I don't see how. Python has very powerful ways of dispatching execution including dictionaries of functions, callable objects, etc. Sounds like you're programming in a very primitive way, reinventing many structures that Python already has. I know that some low-level C programming does rely on and use goto, but in Python I've never needed it. You're not the first person to not grasp Python fundamentals (such as how variables work with name binding vs the Delphi idea of named boxes that can actually be change; python variables can only be rebound to new objects, unless you call a method on a mutable object), who ends up fighting the language and being really frustrated with it. Sounds like you're trying to code Pascal (or some other language) in Python. This is going to be frustrating. I suggest you learn what it means to code in a Pythonic way and you'll find you are really productive and having a lot of fun. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python handles globals badly.
On 12/03/2014 08:57 PM, Dennis Lee Bieber wrote: On Wed, 3 Dec 2014 10:16:18 -0800 (PST), sohcahto...@gmail.com declaimed the following: I'm surprised other people haven't picked up on how obvious of a troll this Skybuck Flying guy is. He claims 20 years programming experience, then uses an absurd amount of globals, many of which are related, without using a data structure of some kind. My initial impression is of 20 years of KemenyKurtz BASIC... Of the 70s... with everything global. BASIC was slow in changing, that's for sure. I have used BASIC a lot over the years, and it's been highly structured with modern scoping rules since about the mid 80s. Certainly Borland's Turbo BASIC provided real functions and subroutines, private variables, block structures, etc. Sadly BASIC dialects tended to try to maintain backwards compatibility so even modern dialects like FreeBASIC can be coerced into executing spaghetti code. Sad that the OP is stuck in this style of programming. Whatever works for him. Maybe instead of Python he should use FreeBASIC with the -lang qb flag. Actually, more appropriate might be PC Basic [1] which is a GW BASIC clone actually written in Python. Nothing better than executing spaghetti code in an interpreter written in an interpreted language! Python indeed must be powerful indeed. [1] http://sourceforge.net/projects/pcbasic -- https://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing
On 12/04/2014 03:27 AM, Albert van der Horst wrote: That doesn't help. I'm a very experienced programmer and work in routinely a dozen languages. Sometimes I do python. I want to do numeric work. I remember the name numpy. It is important, everybody knows it, it is all over the place. So I want to find its docs, or some lead, whatever. I go to the official Python site, http://docs.python.org and type in numpy in the search machine. It is embarassing, try it! That would indeed be embarrassing if numpy was a part of Python or had anything to do with the python.org project. In fact it doesn't. It's a third-party library for use with python. As a beginner I would type in numpy to google and see what happens. Would you expect to go to Microsoft MSDN to find information on a third-party library, such as, say, SDL or Allegro, that you use in Visual Studio? Plain google is far superior in finding information. Of course, since the information you are looking is third-party to python.org for a start. And you tell me that writing yet another tutorial would improve that? No, there is just one way. The powers that be should look critically at their website, and test it with a beginners hat on. Your ire is misplaced. The GP was saying that if there is a deficiency in the Python docs you can help fix that. If there's a deficiency in the numpy docs, you can ask them about fixing that's what he means. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tabs for indentation Spaces for alignment in Python 3?
On 12/05/2014 07:31 PM, Ned Batchelder wrote: This is a perfect example! The code (with tabs as --- and leading spaces as .) is: ---if (!list_empty(pending)) --ret = list_first_entry(pending, struct async_entry, ...domain_list)-cookie; Now, display it in your editor with tabs set to four spaces: ---if (!list_empty(pending)) --ret = list_first_entry(pending, struct async_entry, ...domain_list)-cookie; However, a conscientious programmer knows that tabs could be arbitrarily sized, so he would never do that. Instead he would do: ---if (!list_empty(pending)) --ret = list_first_entry(pending, struct async_entry, --...domain_list)-cookie; Which under the heretical tab size of 4: ---if (!list_empty(pending)) --ret = list_first_entry(pending, struct async_entry, --...domain_list)-cookie; In fact a decent editor that is auto-indenting code would, at least in C or C++ mode, do that automatically. Maybe I misread, but I would think this is what the OP had in mind. Of course maybe kernel programmers think differently. Ahh well. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tabs for indentation Spaces for alignment in Python 3?
On 12/06/2014 01:40 AM, Marko Rauhamaa wrote: Michael Torrie torr...@gmail.com: In fact a decent editor that is auto-indenting code would, at least in C or C++ mode, do that automatically. A decent editor frees you from this dilemma entirely: (custom-set-variables '(indent-tabs-mode nil)) What dilemma? Do you mean you can avoid the drama of tabs by going all spaces? Of course in Python this is the recommended course. But that's typically not what I, or most people, use in C or C++. And one of the OP's points is that by using tabs for indent, and spaces for alignment, you can have the best of both worlds. Programmers can set their tab size to anything they want, and it still looks good (except of Linux kernel source code, which only will ever look right at tabs equivalent to 8 spaces). He wanted to know if he could still do that in Python3, and the answer is yes although we recommend highly just sticking to pep8 4 space characters per indent and no tabs whatsoever. Of course any validly-formatted Python code (or C code) can be made to look right and work right by running autopep8[1] on it. Just like indent can make your C code fit whatever style guide you need. [1] https://pypi.python.org/pypi/autopep8/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Tabs for indentation Spaces for alignment in Python 3?
On 12/06/2014 09:57 AM, Marko Rauhamaa wrote: And one of the OP's points is that by using tabs for indent, and spaces for alignment, you can have the best of both worlds. I certainly doesn't sound that way. Why is that? Programmers can set their tab size to anything they want, and it still looks good That's anything but true. I see zigzaggy diffs all the time. You're not reading what I'm writing, at least understanding it. The idea behind using tabs for indent and spaces for alignment are clear enough: --blah (one, --..two So obviously your zigzaggy diffs are showing that the person who wrote the code is *not* using tabs for indent and spaces for alignment. Must just be using tabs. Since tabs and spaces are not visibly distinguished, it's not readily apparent when one is properly using tabs and spaces together, and not apparent that your editor is doing it properly, so in Python most people recommend never mixing tabs and spaces, although you *can* do that in the way I've described if you really want to. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tabs for indentation Spaces for alignment in Python 3?
On 12/06/2014 10:12 AM, Simon Ward wrote: Not every programmer is as conscientious in the first of place, and that's far easier to get wrong than just agreeing to stick to one thing. This is why (often more rigid) style guides (or rather policies) exist. Sure, but in the world of braces languages, reformatting crappy code is fairly trivial Maybe we should sack such programmers regardless of their other abilities instead of forcing all, including the conscientious, programmers to adhere to strict style policies? While I like the idea, I think that a slap on the wrist and a bit of re-indentation/re-alignment is all that is necessary (although I have worked with people who consider pure style changes to be a sin too). I suppose if an employee continually submits commits that violate the coding standard after being asked time and again to not do that, and is too lazy to run his code through GNU indent probably should be fired. -- https://mail.python.org/mailman/listinfo/python-list
Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor
On 12/10/2014 09:52 PM, iMath wrote: I think the user interface shouldn't be freezed when using concurrent.futures.ThreadPoolExecutor here,as it executes asynchronously , but it doesn't meet my expectations,anyone can explain why ? any other solutions here to not let user interface freezed? code is here http://stackoverflow.com/questions/27393533/user-interface-freezed-when-using-concurrent-futures-threadpoolexecutor In most any GUI framework, regardless of your use of threads, your callbacks must return control to the main loop immediately (whether an on-click or an on-timer event), or the GUI *will* freeze. You are spawning threads to download the urls, then sitting there waiting for them to finish in the callback. Of course the GUI will freeze; your callback is blocking it. What you should be doing is spawning the threads to do the download, then have the threads (using a proper QThread mechanism or some other semaphore mechanism) raise a signal to indicate they are done, which you will then catch in the main loop as a normal callback. And really when it comes to I/O and GUIs, asynchronous calls are always better than threads. Not sure what Qt has in the way of asynchronous i/o calls, and I'm not familiar enough with the various async i/o frameworks in Python to speak to that, though I did use Python-Twisted once... very powerful once you get your head wrapped around it. Look through the list archives because in the last 3 or 4 weeks I and another Python user talked proper thread use with PyQt or PySide, with code examples. -- https://mail.python.org/mailman/listinfo/python-list
Re: beautifulsoup VS lxml
On 12/11/2014 07:02 PM, iMath wrote: which is more easy and elegant for pulling data out of HTML? Beautiful Soup is specialized for HTML parsing, and it can deal with badly formed HTML, but if I recall correctly BeautifulSoup can use the lxml engine under the hood, so maybe it's the way to go for you, is it gives you the most flexibility. It certainly has a good API that's easy to use for data scraping. Try it and see if it's acceptable. -- https://mail.python.org/mailman/listinfo/python-list
Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor
On 12/11/2014 08:20 PM, iMath wrote: 在 2014年12月11日星期四UTC+8下午1时25分41秒,Michael Torrie写道: On 12/10/2014 09:52 PM, iMath wrote: when it comes to I/O and GUIs, asynchronous calls are always better than threads. I cannot grasp your meaning here, IMO, asynchronous calls are done by using threads. Not in your code. All your I/O calls are synchronous; they block until they are finished. But if you mean that calling synchronous calls while in a thread has a similar effect to an asynchronous call, you are correct. But the way you're waiting for the threads to finish, you're blocking your gui. An asynchronous API lets you start long-running I/O calls and define a function that is automatically called upon completion. In other words it's event-driven. Qt may provide everything you need already in an asynchronous form. Check the docs. And use google. Here's a link I found from a google search that illustrates how to fetch a url in Qt using an asynchronous method. You could fire off as many of these as you want, then just wait for signals. http://qt-project.org/wiki/Download_Data_from_URL -- https://mail.python.org/mailman/listinfo/python-list
Re: encrypt the http request url on the local machine
On 12/12/2014 08:53 AM, iMath wrote: After some retinking on my question ,I found what I am really want is not let any other guys using packet analyzer software know the server name (host name) my software is sending data to . so I translate the host name to IP address format, it somewhat hides the host name. Another question is : for common sites, is the IP address under the host name hardly changing ? I don't see what that will accomplish. Of what value is the hostname vs the IP address? Many servers have proper reverse entries in DNS to map IP addresses back to host names. Furthermore a packet trace can show exactly what the HTTP request was, and that doesn't matter whether you do IP address or hostname. As for whether the IP address changes often, depends on the server. Sometimes some web sites use a cluster of servers and each name lookup will give you a different IP address (round robin lookup). -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On 12/14/2014 07:47 PM, Mark Lawrence wrote: I didn't realise that Python was so smart. It can indicate a syntax error at the final 't' in print before it gets to the opening bracket that is required for the print function in Python 3 (and Python 2 if you're using from __future__ import print_function)? Not really. Python2 just interprets print (value) as an expression to the print statement. It's like saying a=(value) and then print a. Redundant but works. However print(value) is interpreted as a function call, and if you haven't imported it from future, it will error out on Python2. Python 3, on the other hand treats spaces between a function and its opening paren to be optional whitespace. Thus to python3, print(value) and print (value) are the same. So if you always put a space between print and (value) you can achieve some measure of cross-version compatibility with print. However by including print_function from __future__ you are guaranteeing you won't forget to add the parens. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On 12/14/2014 10:32 PM, Chris Angelico wrote: Did you actually test that? Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32 Type copyright, credits or license() for more information. print(hello) hello Since print is a keyword when not imported from future, there's no way for print(value) to be parsed as a function call. Thought I had indirectly, since I've been using this print technique for the last few days. Good to know it works either way, though. Guess the future import is only to make not having parens and error. -- https://mail.python.org/mailman/listinfo/python-list
Re: PyQt: user interface freezed when using concurrent.futures.ThreadPoolExecutor
On 12/18/2014 04:16 AM, Mark Summerfield wrote: It looks to me that what you are doing is sharing a single core between your GUI and your processing. Threading isn't usually a good approach to Python concurrency that is CPU-bound. Except that his code was not CPU-bound to begin with. His real problem is that his callback is starting *and* waiting for all the threads to do their work without returning to the main loop, thus blocking the GUI. As for the threads, they are I/O bound--he's simply trying to do concurrent HTTP downloads. So blocking in the GIL is not the issue here. In fact, in lieu of using proper asynchronous I/O, threading of some kind is probably not a bad solution here, but he has to do it within the Qt Framework, using signals to notify the GUI when a thread is finished, or using a synchronization primitive such as a queue, as recommended by your book in fact. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On 12/18/2014 09:19 AM, Simon Evans wrote: @Steven D'Aprano, I input the following to Python 2.7, which got the following:- from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup= next(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ... Traceback (most recent call last): File stdin, line 1, in module IOError: [Errno 2] No such file or directory: 'ecologicalpyramid.html' ^^^ This is the problem here. And it's not a syntax error. - I kept to your instructions to input the 'Enter' after the fourth line and then before the fifth line, ie between the indented block and the unindented one, which as above, doesn't give me a chance to actually input the fifth line. If I do it both ways, ie: pressing enter after the fourth and before the fifth or just pressing enter after the fourth and then after the fifth line of input, which again it won't actually let me input because before I do, I still get an error return. Did you read the actual error message? In this case it's not a syntax error. Do you understand what the error actually is and why it's happening? (IE did your read what the error was? Hint. It's not the same as your previous errors.) -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to schedule my script?
On 12/17/2014 01:42 PM, Juan Christian wrote: On Wed Dec 17 2014 at 6:25:39 PM John Gordon gor...@panix.com wrote: If you want to solve your problem entirely within Python, look at the scheduler module. (Although even this isn't a complete solution, as you still have to make sure the program is running in the first place...) My script is running fine, Win/OSX/Linux and I don't want to ruin that using system specific things. Wrong. You don't have to change or ruin your script. If your script is done right, you put all the real work inside of callable functions anyway, and probably have some sort of main function that gets called in a manner similar to this: if __name__==__main__: my_main() If so, then you create platform-dependent code in another file that simply imports your existing, working script as a module and runs that main function. On Windows you write a service API wrapper. On Linux you can run the script directly from cron. On Mac you can just bundle a launchd control file (or use cron). If your script is not coded in such a fashion as to make turning it into an importable module easy, I highly recommend changing your to work in this way. Once my python programs get halfway useful I always try to reorganize my code in such a way that it can be used as a module. Because invariable I find that I do want to add another layer, and the modules are ideal for this. Nearly every script has the if __name__=='__main__' block at the end of the file, where it provides standalone features such as a command-line interface, or provides testing of the module's features. -- https://mail.python.org/mailman/listinfo/python-list
Re: [ANN] EasyGUI_Qt version 0.9
On 01/03/2015 10:11 AM, André Roberge wrote: Would you care to elaborate? All the code I have written works correctly on all the tests I have done. I do have reports from a user using a Mac with Python 2.7 for which some widgets did not quite work properly ... but that's all I have heard about problems with it. I would like to hear about the problems you know about either here, on by filing an issue at https://github.com/aroberge/easygui_qt/issues It's not clear to me that jmf even understands what easygui is intended to do. So I wouldn't worry too much about what he says. So I'd just ignore what he has to say. If someone needs a full event-driven GUI, they can use an appropriate toolkit. For quick and dirty little utilities I can see how easygui fits the bill, and being Qt-based is good news. By the way, I'm not seeing jmf's emails; I think they are being filtered at the mailing list level. I think enough people got tired of his trolling that they banned him, though on USENET he's still getting through. -- https://mail.python.org/mailman/listinfo/python-list
[issue1205] urllib fail to read URL contents, urllib2 crash Python
Michael Torrie added the comment: I had a situation where I was talking to a Sharp MFD printer. Their web server apparently does not serve chunked data properly. However the patch posted here put it in an infinite loop. Somewhere around line 525 in the python 2.4 version of httplib.py, I had to make it look like this: while True: line = self.fp.readline() if line == '\r\n' or not line: break I added or not line to the if statement. The blank line in the chunked http was confusing the _last_chunk thing, but even when it was set to zero, since there was no more data, this loop to eat up crlfs was never ending. Is this really a proper fix? I'm in favor of changing urllib2 to be less strict because, despite the RFCs, we're stuck talking to all kinds of web servers (embedded ones in particular) that simply can't easily be changed. -- nosy: +torriem __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1205 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: HTTP over Asynchronous AF_UNIX Socket in python
On 01/26/2015 06:32 AM, Norah Jones wrote: Now my problem is the HTTP request which to be sent must go through AF_UNIX socket. The Python Twisted framework may be of use to you. It's got a very steep learning curve, but it's fairly easy to change the underlying byte transport for any protocol they have implemented. In fact in the Twisted docs, they show a web client accessing an HTTP server over a unix socket (scroll down to the bottom of the page): http://twisted.readthedocs.org/en/latest/web/howto/client.html They show a client connecting to a Docker server which is speaking HTTP over a unix socket. Twisted is very powerful and flexible, and event-driven. -- https://mail.python.org/mailman/listinfo/python-list
Re: ANN: unpyc3 - a python bytecode decompiler for Python3
On 02/04/2015 05:19 PM, sohcahto...@gmail.com wrote: They can take your computer and it doesn't matter if you've got your files on Dropbox. My dog ate my USB stick. :-) I never used a USB stick for school work. At this point, I'm probably sounding like a shill for Dropbox, but I'm really not. I imagine Google Drive offers the same features. Access to your files from the web, synchronization of local files among computers with access to it, and the ability to retrieve and restore files from previous versions. In my mind, they are all tools. And no one tool should be used and trusted above all others. Anyone that's programming should be using version control, period. But that's not for backup, and backup can and should be used as well as version control. Everything I work on I commit to git regularly because of the utility git gives me. If I end up trying something that doesn't pan out, I can retrace my steps (that's what branches are for). I don't have to dig through two weeks of hourly backups to find out where it was when I started making a change. Backup and git serve two complementary but different purposes. As well as regularly committing code to Git, I run CrashPlan and on a regular schedule (hourly perhaps) it copies all changes, committed or not, and including the git repo itself to the cloud, and also to my other computer, as well as my parents' computer. CrashPlan makes this stuff easy, so there's no reason not have redundancy. As well, I semi-regularly run a manual rsync backup to three different USB hard drives on a rotating backup. Is this overkill? I don't believe so. It requires virtually no work on my part. I don't see any one cloud service as the best product. Why not use them all? Encrypt if you need to, and sync hourly snapshots to google drive, drop box, and any other free cloud service. -- https://mail.python.org/mailman/listinfo/python-list
Re: [OT] fortran lib which provide python like data type
On 01/30/2015 09:27 AM, Rustom Mody wrote: ... if I restate that in other words it says that sufficiently complex data structures will be beyond the reach of the standard RAII infrastructure. Of course this only brings up one side of memory-mgmt problems viz. unreclaimable memory. What about dangling pointers? C++ apps are prone to segfault. Seems to suggest (to me at least) that the memory-management infrastructure is not right. Stroustrup talks of the fact that C++ is suitable for lightweight abstractions. In view of the segfault-proneness I'd say they are rather leaky abstractions. But as I said at the outset I dont understand C++ Yes I can tell you haven't used C++. Compared to C, I've always found memory management in C++ to be quite a lot easier. The main reason is that C++ guarantees objects will be destroyed when going out of scope. So when designing a class, you put any allocation routines in the constructor, and put deallocation routines in the destructor. And it just works. This is something I miss in other languages, even Python. And for many things, though it's not quite as efficient, when dealing with objects you can forgo pointers altogether and just use copy constructors, instead of the blah *a = new blah_with_label(hello) //allocate on heap //forget to delete a and it leaks the heap *and* anything //that class blah allocated on construction. just simply declare objects directly and use them: blah a(hello) //assuming there's a constructor that takes a string //deletes everything when it goes out of scope So for the lightweight abstractions Stroustrup talks about, this works very well. And you'll rarely have a memory leak (only in the class itself) and no dangling pointers. For other things, though, you have to dynamically create objects. But the C++ reference-counting smart pointers offer much of the same destruction semantics as using static objects. It's really a slick system. Almost makes memory management a non-issue. Circular references will still leak (just like they do on Python). But it certainly makes life a lot more pleasant than in C from a memory management perspective. -- https://mail.python.org/mailman/listinfo/python-list
Re: Downloading videos (in flash applications) using python
On 02/02/2015 12:30 PM, Gabriel Ferreira wrote: Hi Paul, I presume the stream operator doesn't want to prevent me from downloading or recording the videos. I just wanna know more about some lib that could be used to deal with Flash Player Applications... Or possibly, anything that could lead me to be able to get those streaming videos. You can't do it directly with any Python library that I know of. You can, however, use the tools that come with rtmpdump: https://rtmpdump.mplayerhq.hu/ It's not automatic, and requires some iptables tricks, but once you get the stream information, you can always download it via rtmpdump. -- https://mail.python.org/mailman/listinfo/python-list
Re: Downloading videos (in flash applications) using python
On 02/02/2015 04:21 PM, Gabriel Ferreira wrote: The problem is that this particular website uses a flash player application do broadcast the live images of the urban areas. I'm not too familiar with Flash Applications. I don't know how to deal with them using Python. I was wondering if someone could help me solve this problem. The goal is recording downloading those videos, from the mentioned website. And, yes, it has to be an automated program (no manual work). As I said before you need to look into the RTP protocol. There are utilities for proxying and dumping the stream parameters. Once they are known you can pull them in using rtmpdump. Sometimes the stream parameters can be determined from the web page. get_iplayer, for instance, can create rtp parameters for BBC programs and then stream them with rtmpdump, since the parameters seem to be well defined and consistent. But every streaming site is going to be different. I posted the link to the rtmpdump utilities in my other post. You may be to drive rtmpdump from Python. -- https://mail.python.org/mailman/listinfo/python-list
Re: [OT] fortran lib which provide python like data type
On 02/02/2015 12:39 AM, Marko Rauhamaa wrote: Michael Torrie torr...@gmail.com: http://en.cppreference.com/w/cpp/utility/functional/function Thus if we were to shoehorn your example into C++, the result would be idiomatically very similar to what you have in your Python code. I can understand why you wouldn't write out my example in C++: I wouldn't write it out because it's a contrived example, and why should I waste my time? You have no intention of being impressed with C++, let alone simply learn about it. using std::placeholders::_1; std::functionvoid(int) f_add_display2 = std::bind( Foo::print_add, foo, _1 ); Looks okay to me. That's normal C++ that would be clear to any C++ programmer. And for a statically compiled language, that's incredibly powerful while providing for a measure of safety. You may shudder, but it's a really good statically compiled solution, given the constraints of C++ and its compiler. But like I said, idiomatically in C++, this isn't normally what you'd do anyway. You'd store a std::ostream object. vs f_add_display2 = foo.print_add The cherry on top: _1! The C++ compiler figures out template types heroically but can't wrap its head around the arity of the method. std::bind is a generic function that works with undecorated function pointers. There's no possible way for the compiler to know the arity of the function without you telling it (how else would you do it? I honestly want to know.). That you would find this fact to be incredulous suggests that you have very little understanding of compilers in general. Python being a dynamic, interpreted language can examine a function at runtime. Python is a very expressive language compared to C++ that can do things at runtime that C++ cannot. It's also an interpreted, dynamically-typed language, whereas C++ is a statically-typed language that is clearly faster at many things than Python is. It's a matter of different tools for different jobs. For most of my jobs Python is the right tool. But I can see why people would still want to pick a compiled language, and I can understand why some people still use C++. It's a very powerful language. I'm a little unclear as to why you're even bringing up the comparison with C++. What's your point? To feel superior? -- https://mail.python.org/mailman/listinfo/python-list
Re: [OT] fortran lib which provide python like data type
On 02/02/2015 10:57 AM, Marko Rauhamaa wrote: I really don't understand why you are taking all of this so personally. We are just discussing different aspects of different programming languages. Fair enough. You raise good points. I am not taking it personally; your emails, lacking emotional context, just seemed a bit unnecessarily argumentative. For example, The cherry on top: _1! The C++ compiler figures out template types heroically but can't wrap its head around the arity of the method. -- https://mail.python.org/mailman/listinfo/python-list
Re: Ghost vulnerability
On 02/03/2015 04:19 AM, Steven D'Aprano wrote: Anssi Saari wrote: Rustom Mody rustompm...@gmail.com writes: How many people (actually machines) out here are vulnerable? http://security.stackexchange.com/questions/80210/ghost-bug-is-there-a-simple-way-to-test-if-my-system-is-secure shows a python 1-liner to check Does that check actually work for anyone? That code didn't segfalt on my vulnerable Debian system but it did on my router which isn't (since the router doesn't use glibc). Oh and of course I can't comment on stinkexchange since I don't have whatever mana points they require... Here's the one-liner: python -c 'import socket;y=0*5000;socket.gethostbyname(y)' I think it is likely that y=0*5000 would segfault due to lack of memory on many machines. I wouldn't trust this as a test. I ran it on both my servers (each running a different version of the OS) which were recently updated to Red Hat's latest version of glibc that fixes the problem, and both of them segfault with this one liner. -- https://mail.python.org/mailman/listinfo/python-list
Re: lambdak: multi-line lambda implementation in native Python
On 01/15/2015 10:29 PM, Ian Kelly wrote: On Thu, Jan 15, 2015 at 9:00 PM, Chris Angelico ros...@gmail.com wrote: My first response was going to be Well, you can always add another layer of indirection to try to solve your problem, but then I went and looked up builders on Wikipedia. Now I'm confused. What can you do with a builder that you can't do with a constructor? In Java you have to write a separate constructor for every conceivable combination of arguments. If there are a lot of optional arguments, that's an exponentially large number of constructors. The builder pattern provides a solution to that problem. In Python you just have one initializer with defaults for the optional arguments, so it's not an issue. Which seems to confirm my understanding that these patterns are in large part a response to limitations in the language, which certainly doesn't engender a fondness for the Java. -- https://mail.python.org/mailman/listinfo/python-list
Re: Hello World
On 01/17/2015 07:51 AM, Albert van der Horst wrote: In article mailman.17471.1420721626.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: SNIP But sure. If you want to cut out complication, dispense with user accounts altogether and run everything as root. That's WAY simpler! I didn't except this strawman argument from you. Of course you need a distinction between doing system things as root, and working as a normal user. You just don't need sudo. I just don't see the distinction. What's the difference between having to type in a root password and having to type in your own administrative user password? Guess we're all just struggling to understand your logic here. On my laptop sudo has a huge advantage over su, and that is I can use my fingerprint reader to access root. Now I could set up root to accept a fingerprint as well which would work with su, but the sudo solution is much quicker to configure. -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
On 01/19/2015 04:08 PM, Steven D'Aprano wrote: Zachary Gilmartin wrote: Why aren't there trees in the python standard library? Possibly because they aren't needed? Under what circumstances would you use a tree instead of a list or a dict or combination of both? That's not a rhetorical question. I am genuinely curious, what task do you have that you think must be solved by a tree? Also, what sort of tree? Binary tree? Binary search tree? Red/black tree? AVL tree? Splay tree? B-tree? T-tree? Scapegoat tree? General n-ary tree? Every possible type of tree yet invented? Don't forget left-child,right-sibling trees. As I go through your list of trees, I can't find any tree type that cannot be easily and efficiently constructed with lists, possibly with dicts. -- https://mail.python.org/mailman/listinfo/python-list
Re: What killed Smalltalk could kill Python
On 01/21/2015 04:37 PM, Tim Daneliuk wrote: On 01/21/2015 10:34 AM, Steven D'Aprano wrote: In 2009, Robert Martin gave a talk at RailsConf titled What Killed Smalltalk Could Kill Ruby. (No cheering, that sort of attitude is one of the things that killed Smalltalk.) Although Martin discusses Ruby, the lessons could also apply to Python. I find these kinds of discussions sort of silly. Once there is a critical mass of installed base, no language EVER dies. I suspect the real reason Smalltalk sort of got kicked to the curb is because a) It clung to a kind of OO purity that simply is at odds with the practice of programming at large scale and b) It thus never built the aforementioned critical mass. I suspect Smalltalk lost relevance mainly because it never integrated very well into any computing system. Everything ran in a virtual machine in its own image in isolation as it were. The IDE and the runtime environment were inseparable, and as OS's developed their own environments it just never tried to fit in. It's almost as if Smalltalk was the language, runtime, your program source code, *and* operating system. That's what he meant in his talk about the problem with smalltalk being the image. The only way to distribute your smalltalk programs was to distribute the image file, which was basically a memory dump. When you wanted to list out a smalltalk program you were basically decompiling it to the editor widget. So this integrated nature of smalltalk (source code, editor, live objects, etc) was its most powerful feature, but ultimately its downfall too in my opinion. And at the same time we regularly pine for some of those features. -- https://mail.python.org/mailman/listinfo/python-list
Re: Hello World
On 01/17/2015 11:47 AM, Michael Ströder wrote: sudo makes administrators careless, lazy and it is not simple at all. Admins must have separate accounts with separate credentials for administrative work and must be careful when using an administrative account. Right. This is not a bad idea in a large organization. In any case, Sudo is more auditable than su in my opinion, but more importantly, it's much easier to revoke. With su, if I fire an admin, I have to change root passwords on every machine, and redistribute the new password to every admin that needs it. With sudo, I might still change the root password, but I'll lock the root password up in a safe box somewhere, and life goes on for everyone else. In fact with root disabled entirely, the whole root password needing to be changed when a person leaves the company is completely eliminated. sudo allows us (especially with the idea about separate admin credentials) to have multiple, controllable, auditable, root passwords in effect. Surely the benefit of this can be seen. Another good alternative to sudo is ksu, which is a kerberized su. This also provides an excellent audit trail, and is easy to revoke. This may be more to Mr. van der Horst's liking, as normally ksu is configured to accept only principals with a /admin suffix (arbitrarily chosen). So admins would have their normal principal, and their admin principal. It's a pretty slick system if you have Kerberos up and running. -- https://mail.python.org/mailman/listinfo/python-list
Re: lambdak: multi-line lambda implementation in native Python
On 01/15/2015 06:34 PM, Roy Smith wrote: The ebb and flow of technology has recently brought me someplace I never thought I'd be. Java-land. And what I've discovered is that factories are so last year. Apparently builders are the new thing. It's never clear to me whether all these fancy design patterns are to make up for a deficient language, or whether some people just get their kicks from layer upon layer of abstraction. Certainly it's this sort of thing that turns me right off of Java. -- https://mail.python.org/mailman/listinfo/python-list