From rosuav at gmail.com Tue Sep 1 00:07:37 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Sep 2015 14:07:37 +1000 Subject: AttributeError: 'module' object has no attribute '__path__' In-Reply-To: <84d4336f-a6bc-4c3f-9550-a4ff2e3e7901@googlegroups.com> References: <97927258-d389-4bd6-a861-e122e4247ac0@googlegroups.com> <201508312017.t7VKHG8O020529@fido.openend.se> <84d4336f-a6bc-4c3f-9550-a4ff2e3e7901@googlegroups.com> Message-ID: On Tue, Sep 1, 2015 at 1:32 PM, Rustom Mody wrote: > On Tuesday, September 1, 2015 at 3:46:15 AM UTC+5:30, Laura Creighton wrote: >> Can you make the effort to move your cursor to the bottom of >> the mail you are replying to, before you start typing, >> so that your reply comes after what was said before, instead of >> first thing, and thus before what was said before. > > In gmail its trivially simple but not all that obvious: > There are 3 tiny little dots below which conceal the earlier context. > You have to click that to open it. And then start entering below that > > [Thanks to ChrisA I now know you can also Ctrl-A to open it. > Where does Chris find out such arcana I wonder?!] It was an accident! (I'm sorry, Anna!) I use Gmail too, and one day I happened to hit Ctrl-A. Since then, I've used it fairly often. ChrisA From dunric29a at gmail.com Tue Sep 1 00:56:46 2015 From: dunric29a at gmail.com (dunric29a at gmail.com) Date: Mon, 31 Aug 2015 21:56:46 -0700 (PDT) Subject: Extra AttributeError inside property - possible bug ? Message-ID: <3e6ca589-475d-4f26-9d90-582011fb3aeb@googlegroups.com> Hello, bellow is a simple Python2 example of a class which defines __getattr__ method and a property, where AttributeError exception is raised: from __future__ import print_function class MyClass(object): def __getattr__(self, name): print('__getattr__ <<', name) raise AttributeError(name) return 'need know the question' @property def myproperty(self): print(self.missing_attribute) return 42 my_inst = MyClass() print(my_inst.myproperty) # produces following output __getattr__ << missing_attribute __getattr__ << myproperty Traceback (most recent call last): File "a.py", line 84, in main() File "a.py", line 74, in main print('==', my_inst.myproperty) File "a.py", line 36, in __getattr__ raise AttributeError(name) AttributeError: myproperty By the documentation https://docs.python.org/2/reference/datamodel.html#object.__getattr__ , if class defines __getattr__ method, it gets called at AttributeError exception and should return a computed value for name, or raise (new) AttributeError exception. Why is __getattr__ called 2nd time, with 'myproperty' argument ?!? self.myproperty does exist and also at first call of __getattr__ new AttributeException with 'missing_attribute' is raised. I can't see any reason for this behavior. From jana1972 at centrum.cz Tue Sep 1 01:08:48 2015 From: jana1972 at centrum.cz (Jahn) Date: Tue, 01 Sep 2015 07:08:48 +0200 Subject: How to compare lists Message-ID: <55E54F00.15583.2941C4EC@jana1972.centrum.cz> 1. How can I save 256 lists, each list has 32 values( hexadecimal numbers) 2. How to compare the saved lists with another 256 lists ( that are read online and have the same structure as the list one)? ( the first list must be saved in the previous step) E.g Thanks From otlucaDELETE at DELETEyahoo.it Tue Sep 1 01:45:26 2015 From: otlucaDELETE at DELETEyahoo.it (Luca Menegotto) Date: Tue, 1 Sep 2015 07:45:26 +0200 Subject: Why Python is not both an interpreter and a compiler? References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> Message-ID: Il 31/08/2015 19:48, Mahan Marwat ha scritto: > If it hasn't been considered all that useful, then why > the tools like cx_freeze, pytoexe are doing very hard! Well, I consider those tools useless at all! I appreciate Python because, taken one or two precautions, I can easily port my code from one OS to another with no pain. So, why should I loose this wonderful freedom? -- Ciao! Luca From dieter at handshake.de Tue Sep 1 01:48:50 2015 From: dieter at handshake.de (dieter) Date: Tue, 01 Sep 2015 07:48:50 +0200 Subject: more itertools References: Message-ID: <87bndmadvh.fsf@handshake.de> Mark Lawrence writes: > ... > can you try a search on pypi, as I know I've found > it that way in the past, but literally not right now. I have recently made a similar experience with "Products.CMFPlacefulWorkflow". Searching for this product does not find the package but "https://pypi.python.org/pypi/Products.CMFPlacefulWorkflow" leads to the package page. Apparently, the "PyPI" search started to behave strangely. Someone may need to file a bug report. From dieter at handshake.de Tue Sep 1 01:53:01 2015 From: dieter at handshake.de (dieter) Date: Tue, 01 Sep 2015 07:53:01 +0200 Subject: more itertools References: Message-ID: <877foaadoi.fsf@handshake.de> Mark Lawrence writes: > ... > But then you go to check > which bug tracker and what do you find but > https://bitbucket.org/pypa/pypi/issues/326/some-packages-not-showing-up-when Thus, the reporting is already done. Hope, there will be a fix soon :-) From __peter__ at web.de Tue Sep 1 03:08:56 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 01 Sep 2015 09:08:56 +0200 Subject: Extra AttributeError inside property - possible bug ? References: <3e6ca589-475d-4f26-9d90-582011fb3aeb@googlegroups.com> Message-ID: dunric29a at gmail.com wrote: > Hello, > > bellow is a simple Python2 example of a class which defines __getattr__ > method and a property, where AttributeError exception is raised: > > from __future__ import print_function > > class MyClass(object): > def __getattr__(self, name): > print('__getattr__ <<', name) > raise AttributeError(name) > return 'need know the question' > > @property > def myproperty(self): > print(self.missing_attribute) > return 42 > > my_inst = MyClass() > print(my_inst.myproperty) > > # produces following output > __getattr__ << missing_attribute > __getattr__ << myproperty > Traceback (most recent call last): > File "a.py", line 84, in > main() > File "a.py", line 74, in main > print('==', my_inst.myproperty) > File "a.py", line 36, in __getattr__ > raise AttributeError(name) > AttributeError: myproperty > > > By the documentation > https://docs.python.org/2/reference/datamodel.html#object.__getattr__ , if > class defines __getattr__ method, it gets called at AttributeError > exception and should return a computed value for name, or raise (new) > AttributeError exception. > > Why is __getattr__ called 2nd time, with 'myproperty' argument ?!? > self.myproperty does exist and also at first call of __getattr__ new > AttributeException with 'missing_attribute' is raised. I can't see any > reason for this behavior. I believe this is an implementation accident, the code is not keeping track of the exact origin of the AttributeError. Until recently generators showed analogous behaviour and swallowed StopIterations: $ cat stopiteration.py from __future__ import generator_stop def stop(): raise StopIteration def f(items): for item in items: yield item stop() for item in f("abc"): print(item) $ python3.5 -x stopiteration.py # abusing -x to skip the __future__ import a $ python3.5 stopiteration.py a Traceback (most recent call last): File "stopiteration.py", line 10, in f stop() File "stopiteration.py", line 4, in stop raise StopIteration StopIteration The above exception was the direct cause of the following exception: Traceback (most recent call last): File "stopiteration.py", line 13, in for item in f("abc"): RuntimeError: generator raised StopIteration If the AttributeError behaviour were to be changed a similar transition period would be required, so no Python prior to 3.6 would be affected. From rosuav at gmail.com Tue Sep 1 03:30:55 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Sep 2015 17:30:55 +1000 Subject: How to compare lists In-Reply-To: <55E54F00.15583.2941C4EC@jana1972.centrum.cz> References: <55E54F00.15583.2941C4EC@jana1972.centrum.cz> Message-ID: On Tue, Sep 1, 2015 at 3:08 PM, Jahn wrote: > 1. > How can I save 256 lists, each list has 32 values( hexadecimal numbers) > 2. > How to compare the saved lists with another 256 lists ( that are read online and have the > same structure as the list one)? > ( the first list must be saved in the previous step) > > E.g You seem to have missed out your example, but I'll guess at what you're talking about. Correct me if I'm wrong, and we'll move on from there. You want to take a sequence of 32 numbers and see if it's exactly the same sequence as some others. The easiest way to do this is with a tuple, rather than a list; then you can simply do an equality check, and they'll be checked recursively. If you want to ask, more simply, "does this 32-value unit exist in my collection of 256 acceptable 32-value units", then a set will serve you well. You can stuff tuples of integers into your set, and then query the set for a particular tuple. Does that help at all? If not, guide me to the problem you're actually solving. :) ChrisA From __peter__ at web.de Tue Sep 1 03:51:04 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 01 Sep 2015 09:51:04 +0200 Subject: How to compare lists References: <55E54F00.15583.2941C4EC@jana1972.centrum.cz> Message-ID: Jahn wrote: > 1. > How can I save 256 lists, each list has 32 values( hexadecimal numbers) > 2. > How to compare the saved lists with another 256 lists ( that are read > online and have the same structure as the list one)? > ( the first list must be saved in the previous step) You are giving details, but they aren't significant. You can save 256 lists with 32 numbers just like you would save 257 or 2560 with 23 numbers. How you should save them is largely dependent on how you are using them later. Simple methods are pickle.dump() or json.dump(). But what is the problem you are trying to solve by comparing these lists? Are you just looking online for lists matching the local ones? Do you want to find missing/extra lists? Or are you even looking for changes within the lists? How are the online lists provided? Are they text files, is there an API, or do you have to screenscrape them from web pages? Please provide a little more context. From lac at openend.se Tue Sep 1 03:51:10 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 01 Sep 2015 09:51:10 +0200 Subject: Why Python is not both an interpreter and a compiler? In-Reply-To: References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> Message-ID: <201509010751.t817pAfL000456@fido.openend.se> If I understand what you are saying, then I think what you are looking for is not a compiler, but docker. see: https://www.docker.com/ in particular https://www.docker.com/whatisdocker PyPy used this to produce portable PyPy binaries. See: https://github.com/squeaky-pl/portable-pypy/blob/master/README.rst Why did we need to make portable PyPy binaries? >From the PyPy downloads page: Linux binaries and common distributions Linux binaries are dynamically linked, as is usual, and thus might not be usable due to the sad story of linux binary compatibility. This means that Linux binaries are only usable on the distributions where they were created unless you're ready to hack your system by adding symlinks to the libraries it tries to open. We had to make versions for debian stable and unstable, and all the different versions of RHEL, and Centos, and Suse and .... every time we turned around somebody made a new linux distribution, with new and different versions of shared libraries, located in some new creative idea of where the best place was to put such things. And we had to make 32 bit and 64 bit versions, and versions for x86 and for ARM and the list went on, and on, and on. This made releases far harder than they needed to be, and, from the user end meant that people had to work rather hard just to figure out what version of pypy they should download from our site. Lots of people never could quite figure it out, though we tried to help them on the pypy mailing list and over irc ... So finally, we used docker to make a portable version of pypy, which you can use to biuld your own version of pypy from the nightly sources, for instance. I think that this is what you are looking for, as well. But go read up on docker and see if it suits. Laura From dfnsonfsduifb at gmx.de Tue Sep 1 04:58:40 2015 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Tue, 01 Sep 2015 10:58:40 +0200 Subject: RPI.GPIO Help In-Reply-To: References: Message-ID: On 31.08.2015 19:41, John McKenzie wrote: > Still checking here and am discussing all this in the Raspberry pi > newsgroup. Thanks to the several people who mentioned it. > > Again, still listening here if anyone has any more to add. I've had the problem to use interrupt-driven GPIOs on the Pi about two years back. Here's how I solved it: http://pastebin.com/gdJaJByU To explain the message you're getting: If you want to handle GPIOs in the most resource-efficient way, you use interrupt-driven handling. Interrupts for GPIOs can be configured to be off, level-triggered or edge-triggered. For edge-triggering I'm also pretty sure that the type of edge (rising, falling, both) can be specified. IIRC (and I might not, been quite some time), these interrupts are bundled together in GPIO ports ("channels"). All GPIOs in one channel need to have the same configuration. You cannot have conflicing configuration between two pins which belong to the same GPIO (and apparently, your framework is trying to do it). The code I posted does it all by hand (and it's not really hard, as you can see). I used input and output functionality and do the interrupt configuration myself (this works through the /proc filesystem on the Pi). Hope this helps, Cheers, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From jeanmichel at sequans.com Tue Sep 1 05:00:21 2015 From: jeanmichel at sequans.com (jmp) Date: Tue, 01 Sep 2015 11:00:21 +0200 Subject: How to compare lists In-Reply-To: <55E54F00.15583.2941C4EC@jana1972.centrum.cz> References: <55E54F00.15583.2941C4EC@jana1972.centrum.cz> Message-ID: On 09/01/2015 07:08 AM, Jahn wrote: > > > 1. > How can I save 256 lists, each list has 32 values( hexadecimal numbers) > 2. > How to compare the saved lists with another 256 lists ( that are read online and have the > same structure as the list one)? > ( the first list must be saved in the previous step) > > E.g > > > Thanks > Dumb down your problem to something simpler. saving 2 lists of 2 numbers. 1/ for saving/loading the list, use pickle if *you* will do the saving *and* the loading (don't load from an untrusted file) 2/ To compare 2 lists, simply use the == operator In [4]: [[1,2], [1,2]] == [[1,2], [1,3]] Out[4]: False In [5]: [[1,2], [1,2]] == [[1,2], [1,2]] Out[5]: True JM From lac at openend.se Tue Sep 1 05:29:28 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 01 Sep 2015 11:29:28 +0200 Subject: How to compare lists In-Reply-To: <55E54F00.15583.2941C4EC@jana1972.centrum.cz> References: <55E54F00.15583.2941C4EC@jana1972.centrum.cz> Message-ID: <201509010929.t819TSE5025519@fido.openend.se> In a message of Tue, 01 Sep 2015 07:08:48 +0200, "Jahn" writes: >1. >How can I save 256 lists, each list has 32 values( hexadecimal numbers) >2. >How to compare the saved lists with another 256 lists ( that are read online and have the >same structure as the list one)? >( the first list must be saved in the previous step) 'Saving' can mean many things, depending on context. You can save a reference to your list which will last as long as that reference is in scope in your program. If you only need to save it for as long as it takes you to read in another value, also done in the same scope of your program, this will be fine. If, on the other hand you want to get your next values you want to compare things to, by running a program, either this one or a different one, tomorrow, next week, then you will probably want to save your list in a file somewhere. And if you want to save it in a way that you won't lose the data, even if your disk drive breaks, your house burns down and all your posessions are destroyed ... then you probably want to save it in the cloud someplace -- and make sure that the data is mirrored because data centres burn down, on occasion, as well. So that is the first problem. 'What do you mean by save?' which is related to 'How and when are you getting these lists, anyway?' The next problem is similar. 'What do you mean by same?' Here is a list: ['Anders', 'Sigbritt', 'Eva'] and here is another list: ['Eva', 'Sigbritt', 'Anders'] They aren't equal. But are they 'the same'? This isn't a programming question, but a question of 'How is your problem defined?' You need to know the answer to this before you can write your code, which may mean asking the problem giver to clarify what he or she meant by 'same'. Laura From denismfmcmahon at gmail.com Tue Sep 1 07:58:42 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 1 Sep 2015 11:58:42 +0000 (UTC) Subject: How to compare lists References: Message-ID: On Tue, 01 Sep 2015 07:08:48 +0200, Jahn wrote: > 1. > How can I save 256 lists, each list has 32 values( hexadecimal numbers) > 2. > How to compare the saved lists with another 256 lists ( that are read > online and have the same structure as the list one)? > ( the first list must be saved in the previous step) Develop code that works for smaller lists. Test it. When it works, try it on bigger lists. For example, you seem to have two very separate requirements: Save (and presumably read) a list. My favourite mechanism for saving data structures is json. Read the json module help. Gogling "python store list data" might bring you other suggestions. Comparing two lists. One method is to step through the members of each list in turn, and see if it is in the other list. Another method is to check that the lists are the same length, and have the same value at each element position. Both may have flaws depending on the exact nature of your requirement - and what you consider to be identical lists. Googling "python compare lists" may lead you to some ideas. When you have written and tested your code, if it's not doing what you expect, you could come back here and post your code with a description of what you think it should do, what it actually does, and why you think that's wrong, and we'll try and help you fix. What we won't do is write your application from scratch. -- Denis McMahon, denismfmcmahon at gmail.com From harirammanohar159 at gmail.com Tue Sep 1 08:16:48 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Tue, 1 Sep 2015 05:16:48 -0700 (PDT) Subject: execute commands as su on remote server In-Reply-To: References: Message-ID: <23e7c934-e8f1-4c8f-a44a-fcbb390381b4@googlegroups.com> On Tuesday, 18 August 2015 08:27:33 UTC+5:30, hariramm... at gmail.com wrote: > execute commands as su on remote server > > Postby hariram ? Mon Aug 17, 2015 4:02 am > Needed: > I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python? > I googled and came to know that its not possible, so just for confirmation asking again, is it possible ? > > Already Tried: > Tried paramiko that's too not working. Hey Laura, fabric doesnt work for me as fabric works with only up to python 2.7 and we are using python 3.3, so we may miss major functionalists if we use 2.7 again in the entire project... From lac at openend.se Tue Sep 1 09:25:42 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 01 Sep 2015 15:25:42 +0200 Subject: execute commands as su on remote server In-Reply-To: <23e7c934-e8f1-4c8f-a44a-fcbb390381b4@googlegroups.com> References: <23e7c934-e8f1-4c8f-a44a-fcbb390381b4@googlegroups.com> Message-ID: <201509011325.t81DPggE019323@fido.openend.se> In a message of Tue, 01 Sep 2015 05:16:48 -0700, harirammanohar159 at gmail.com wr ites: >On Tuesday, 18 August 2015 08:27:33 UTC+5:30, hariramm... at gmail.com wrote: >> execute commands as su on remote server >> >> Postby hariram ? Mon Aug 17, 2015 4:02 am >> Needed: >> I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python? >> I googled and came to know that its not possible, so just for confirmation asking again, is it possible ? >> >> Already Tried: >> Tried paramiko that's too not working. > >Hey Laura, > >fabric doesnt work for me as fabric works with only up to python 2.7 and we are using python 3.3, so we may miss major functionalists if we use 2.7 again in the entire project... >-- >https://mail.python.org/mailman/listinfo/python-list Over here is a Python 3 fork of fabric. https://github.com/pashinin/fabric It is not complete -- i.e. he disabled some tests so some things aren't working. But most of it is reported to work, so maybe it will work well enough for you to use until fabric gets ported for real. Laura From steve at pearwood.info Tue Sep 1 10:45:00 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 02 Sep 2015 00:45:00 +1000 Subject: Does mkstemp open files only if they don't already exist? Message-ID: <55e5b9ec$0$1649$c3e8da3$5496439d@news.astraweb.com> I assume the answer is "Yes", but is it safe to expect that tempfile.mkstemp() will only create a file that doesn't already exist? I presume that there's no chance of it over-writing an existing file (say, due to a race-condition). -- Steven From steve at pearwood.info Tue Sep 1 10:57:22 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 02 Sep 2015 00:57:22 +1000 Subject: Low level file descriptors and high-level Python files Message-ID: <55e5bcd3$0$1639$c3e8da3$5496439d@news.astraweb.com> Let's suppose somebody passes me a file descriptor to work with. It could come from somewhere else, but for the sake of discussion let's pretend I create it myself this way: import os fd = os.open("some path", "w") I then turn it into a file object: file_obj = os.fdopen(fd, mode) Q1: In this example, I know that I opened the fd in write mode, because I did it myself. But since I'm not actually opening it, how do I know what mode to use in the call to fdopen? Is there something I can call to find out what mode a file descriptor has been opened with? Now let's suppose I solve that problem, process the file_obj, and close it: file_obj.close() Q2: Do I still have to close the file descriptor with os.close(fd)? (I think not.) Q3: I could probably answer Q2 myself if I knew how to check whether a fd was open or not. With a file object, I can inspect file_obj.closed and it will tell me whether the file is open or not. Is there an equivalent for file descriptors? -- Steven From rosuav at gmail.com Tue Sep 1 10:57:45 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Sep 2015 00:57:45 +1000 Subject: Does mkstemp open files only if they don't already exist? In-Reply-To: <55e5b9ec$0$1649$c3e8da3$5496439d@news.astraweb.com> References: <55e5b9ec$0$1649$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 2, 2015 at 12:45 AM, Steven D'Aprano wrote: > I assume the answer is "Yes", but is it safe to expect that > tempfile.mkstemp() will only create a file that doesn't already exist? I > presume that there's no chance of it over-writing an existing file (say, > due to a race-condition). It depends on OS support, but with that, yes, it is guaranteed to be safe; the file is opened with an exclusivity flag. Check your system's man pages for details, or here: http://linux.die.net/man/3/open O_EXCL|O_CREATE makes an "atomic file creation" operation which will fail if another process is doing the same thing. I'm not sure how mkstemp() handles that failure, but my guess/expectation is that it would pick a different file name and try again. ChrisA From steve at pearwood.info Tue Sep 1 11:20:00 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 02 Sep 2015 01:20:00 +1000 Subject: Why Python is not both an interpreter and a compiler? References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> Message-ID: <55e5c220$0$1641$c3e8da3$5496439d@news.astraweb.com> On Tue, 1 Sep 2015 03:48 am, Mahan Marwat wrote: >> Python programs *could* easily be compiled the same way, but it generally >> hasn't been considered all that useful. > > If it hasn't been considered all that useful, then why the tools like > cx_freeze, pytoexe are doing very hard! And if it is really easy, then why > cx_freeze, pytoexe developer are doing it in such a rubbish way instead of > creating one (compiler)? I believe that Marko is wrong. It is not so easy to compile Python to machine language for real machines. That's why the compiler targets a virtual machine instead. Let's take the simple case of adding two numbers: x + y With a real machine, this will probably compile down to a handful of assembly language statements. But, x will have to be an integer of a certain type, say, 32 bits, and y likewise will also have to be the same size. And what happens if the addition overflows? Some machines may overflow to a negative value, some might return the largest positive value. Python addition does not do that. With Python, it doesn't matter whether x and y are the same size, or different. In fact, Python integers are BigNums which support numbers as big as you like, limited only by the amount of memory. Or they could be floats, complex numbers, or fractions. Or x might be a string, and y a list, and the + operator has to safely raise an exception, not dump core, or worse. So to compile Python into assembly language for a real CPU would be very hard. Even simple instructions would require a large, complex chunk of machine code. If only we could design our own machine with a CPU that understood commands like "add two values together" without caring that the values are compatible (real) machine types. And that's what we do. Python runs in a virtual machine with "assembly language" commands that are far, far more complex than real assembly for real CPUs. Those commands, of course, eventually end up executing machine code in the real CPU, but it usually does so by calling the Python runtime engine. There is another reason why frozen Python code is so large. It has to include a full Python interpreter. The Python language includes a few commands for compiling and interpreting Python source code: - eval - exec - compile so the Python runtime has to include the Python compiler and interpreter, which effectively means that the Python runtime has to be *all* of Python, or at least nearly all. There may be projects that will compile Python down to machine code for a real machine (perhaps Cython?) but doing so isn't easy, which is why most compilers don't do it. -- Steven From random832 at fastmail.us Tue Sep 1 11:56:04 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 01 Sep 2015 11:56:04 -0400 Subject: Low level file descriptors and high-level Python files In-Reply-To: <55e5bcd3$0$1639$c3e8da3$5496439d@news.astraweb.com> References: <55e5bcd3$0$1639$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1441122964.2424706.371812753.75CE734E@webmail.messagingengine.com> On Tue, Sep 1, 2015, at 10:57, Steven D'Aprano wrote: > Q1: In this example, I know that I opened the fd in write mode, because > I > did it myself. But since I'm not actually opening it, how do I know what > mode to use in the call to fdopen? Is there something I can call to find > out what mode a file descriptor has been opened with? In principle, you can find out with fcntl. In practice, don't you already know what kind of processing you intend to do with the file? If your "processing" involves writing, just try writing to it, and if it doesn't work then it's the caller's fault for passing in a read-only file handle. > Now let's suppose I solve that problem, process the file_obj, and close > it: > > file_obj.close() > > Q2: Do I still have to close the file descriptor with os.close(fd)? > (I think not.) You do not. > Q3: I could probably answer Q2 myself if I knew how to check whether a > fd > was open or not. With a file object, I can inspect file_obj.closed and it > will tell me whether the file is open or not. Is there an equivalent for > file descriptors? Well, if you try to call os.close, or any other operation for that matter, it will raise an OSError with errno=EBADF. Note that if the file _has_ been closed it may be reused by the next open call, so it's best not to use this test method in production code. From marko at pacujo.net Tue Sep 1 12:20:51 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 01 Sep 2015 19:20:51 +0300 Subject: Why Python is not both an interpreter and a compiler? References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> <55e5c220$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87io7uun4s.fsf@elektro.pacujo.net> Steven D'Aprano : > I believe that Marko is wrong. It is not so easy to compile Python to > machine language for real machines. That's why the compiler targets a > virtual machine instead. Somehow Guile manages it even though Scheme is at least as dynamic a language as Python. I never said a compiler would translate Python to (analogous) machine language. I said you could easily turn CPython into a dynamic library (run-time environment) and write a small bootstrapper that you package into an executable archive with the Python code (whether .py or .pyc). What results is a single executable that you can run analogously to any other command. In fact, the shebang notation turns any single .py file into such an executable. The problem is if you break your program into modules. Java, of course, solved a similar problem with .jar files (but still wouldn't jump over the final hurdle of making the .jar files executable). Marko From rosuav at gmail.com Tue Sep 1 13:06:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Sep 2015 03:06:06 +1000 Subject: Why Python is not both an interpreter and a compiler? In-Reply-To: <87io7uun4s.fsf@elektro.pacujo.net> References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> <55e5c220$0$1641$c3e8da3$5496439d@news.astraweb.com> <87io7uun4s.fsf@elektro.pacujo.net> Message-ID: On Wed, Sep 2, 2015 at 2:20 AM, Marko Rauhamaa wrote: > In fact, the shebang notation turns any single .py file into such an > executable. The problem is if you break your program into modules. Java, > of course, solved a similar problem with .jar files (but still wouldn't > jump over the final hurdle of making the .jar files executable). The time machine strikes again! Python supports zip file execution, which gives you the same benefit as a .jar file, plus you can slap on a shebang and run the whole thing! Anyone for some pyzza? https://www.python.org/dev/peps/pep-0441/ ChrisA From lac at openend.se Tue Sep 1 13:09:10 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 01 Sep 2015 19:09:10 +0200 Subject: Does mkstemp open files only if they don't already exist? In-Reply-To: References: <55e5b9ec$0$1649$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201509011709.t81H9Al0010938@fido.openend.se> In a message of Wed, 02 Sep 2015 00:57:45 +1000, Chris Angelico writes: >On Wed, Sep 2, 2015 at 12:45 AM, Steven D'Aprano wrote: >> I assume the answer is "Yes", but is it safe to expect that >> tempfile.mkstemp() will only create a file that doesn't already exist? I >> presume that there's no chance of it over-writing an existing file (say, >> due to a race-condition). > >It depends on OS support, but with that, yes, it is guaranteed to be >safe; the file is opened with an exclusivity flag. Check your system's >man pages for details, or here: > >http://linux.die.net/man/3/open > >O_EXCL|O_CREATE makes an "atomic file creation" operation which will >fail if another process is doing the same thing. I'm not sure how >mkstemp() handles that failure, but my guess/expectation is that it >would pick a different file name and try again. > >ChrisA >-- >https://mail.python.org/mailman/listinfo/python-list I remember discussion on the mercurial mailing list about somebody who had a problem with this in conjunction with a virus scanner that really wanted to get in and do things to the poor temp files. see: https://selenic.com/pipermail/mercurial-devel/2009-February/010197.html for a very, very long thread about it. Apparantly, you can get windows to complain that you cannot create a file because it already exists, and it doesn't go back and try this again for you. But at the time I found the discussion puzzling, as my thought was 'why are these people using mkstemp directly, instead of tempfile.NamedTemporaryFile which seems to be what they want. But I found this thread looking for a different problem with a mercurial repository that we had that was corrupted, a year or so after the thread was written, so I didn't want to go back and ask them about it _then_. Then in the general excitement --"Your raid system is buggy! It is inserting sludge in your files!" I forgot about this puzzlement. Until now. Laura From esj at harvee.org Tue Sep 1 13:09:49 2015 From: esj at harvee.org (eric) Date: Tue, 01 Sep 2015 13:09:49 -0400 Subject: Why Python is not both an interpreter and a compiler? In-Reply-To: <87io7uun4s.fsf@elektro.pacujo.net> References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> <55e5c220$0$1641$c3e8da3$5496439d@news.astraweb.com> <87io7uun4s.fsf@elektro.pacujo.net> Message-ID: <1441127389.5516.0@z.eggo.org> On Tue, Sep 1, 2015 at 12:20 PM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> I believe that Marko is wrong. It is not so easy to compile Python >> to >> machine language for real machines. That's why the compiler targets >> a >> virtual machine instead. > > Somehow Guile manages it even though Scheme is at least as dynamic a > language as Python. I'm wondering if any of the VM lessons learned with forth environments would help? https://en.wikipedia.org/wiki/Threaded_code -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Sep 1 13:21:13 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 1 Sep 2015 11:21:13 -0600 Subject: Why Python is not both an interpreter and a compiler? In-Reply-To: References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> Message-ID: On Mon, Aug 31, 2015 at 11:45 PM, Luca Menegotto wrote: > Il 31/08/2015 19:48, Mahan Marwat ha scritto: > >> If it hasn't been considered all that useful, then why > >> the tools like cx_freeze, pytoexe are doing very hard! > > Well, I consider those tools useless at all! > I appreciate Python because, taken one or two precautions, I can easily port > my code from one OS to another with no pain. > So, why should I loose this wonderful freedom? You don't. You can still take your unbundled code and port it just as easily as before. What is gained from those tools is the ability to easily distribute your code to (Windows) users who aren't knowledgable or interested in maintaining a Python installation on their system. It's something that you don't likely use unless you have a specific need to do that, however. At my previous job where IT had everybody on Windows, we published our code with batch file launchers onto the internal file server and maintained several Python installations there to run them with, rather than maintain them on the systems of 200+ users plus lab computers. With that setup we didn't require cx_freeze, but we used it in some cases for better network performance (it's typically faster to download one large file from the network than hundreds of small files). From jorge.conrado at cptec.inpe.br Tue Sep 1 13:23:34 2015 From: jorge.conrado at cptec.inpe.br (jorge.conrado at cptec.inpe.br) Date: Tue, 01 Sep 2015 14:23:34 -0300 Subject: netcdf read Message-ID: <2af7b4226f66390b7027cca674bf0bcb@cptec.inpe.br> Hi, I'm starting in the Python scripts. I run this script: import numpy as np import netCDF4 f = netCDF4.Dataset('uwnd.mon.ltm.nc','r') f.variables and I had the message: netcdf4.py Traceback (most recent call last): File "", line 1, in NameError: name 'netcdf4' is not defined What can I do to solve this. I typed this three lines: import netCD4 f = netCDF4.Dataset('uwnd.mon.ltm.nc','r') f.variables and it work. Please, why my script didn't work. Conrado From rustompmody at gmail.com Tue Sep 1 13:26:57 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 1 Sep 2015 10:26:57 -0700 (PDT) Subject: How to compare lists In-Reply-To: References: Message-ID: <0abed2f9-927e-47b7-ae3a-b13209e415c8@googlegroups.com> On Tuesday, September 1, 2015 at 12:54:08 PM UTC+5:30, Jahn wrote: > 1. > How can I save 256 lists, each list has 32 values( hexadecimal numbers) > 2. > How to compare the saved lists with another 256 lists ( that are read online and have the > same structure as the list one)? > ( the first list must be saved in the previous step) To add to what the others have said/asked: Many times programmers want sets but they are programmed(!!) to think "Lists!" This can be because for example >>> [1,2,3] == [2,1,3] False >>> {1,2,3} == {2,1,3} True >>> [1,2,3,3] == [1,2,3] False >>> {1,2,3,3} == {1,2,3} True >>> list(set([1,2,1,3,4,4,])) [1, 2, 3, 4] [Though theres no guarantee of the order of the last (that I know) ] ie you may prefer sets to lists when order and/or repetition dont signify > > E.g ??? From lac at openend.se Tue Sep 1 13:33:06 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 01 Sep 2015 19:33:06 +0200 Subject: Why Python is not both an interpreter and a compiler? In-Reply-To: <87io7uun4s.fsf@elektro.pacujo.net> References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> <55e5c220$0$1641$c3e8da3$5496439d@news.astraweb.com> <87io7uun4s.fsf@elektro.pacujo.net> Message-ID: <201509011733.t81HX65r016928@fido.openend.se> In a message of Tue, 01 Sep 2015 19:20:51 +0300, Marko Rauhamaa writes: >Somehow Guile manages it even though Scheme is at least as dynamic a >language as Python. But are Guile programs small? I the OP made a categorisation error, confusing correlation with causation. (i.e. the presence of feathers makes a animal able to fly). Laura From lac at openend.se Tue Sep 1 13:41:42 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 01 Sep 2015 19:41:42 +0200 Subject: Low level file descriptors and high-level Python files In-Reply-To: <55e5bcd3$0$1639$c3e8da3$5496439d@news.astraweb.com> References: <55e5bcd3$0$1639$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201509011741.t81HfgVe019128@fido.openend.se> In a message of Wed, 02 Sep 2015 00:57:22 +1000, "Steven D'Aprano" writes: >Let's suppose somebody passes me a file descriptor to work with. It could >come from somewhere else, but for the sake of discussion let's pretend I >create it myself this way: >Q1: In this example, I know that I opened the fd in write mode, because I >did it myself. But since I'm not actually opening it, how do I know what >mode to use in the call to fdopen? Is there something I can call to find >out what mode a file descriptor has been opened with? for POSIX things use fnclt. YOu have to parese the bits yourself and I always have to look that up to see what the grubby details are. No clue what you do on windows. Don't go around closing things you don't know are open. They could be some other processes' thing. Laura From lac at openend.se Tue Sep 1 13:52:04 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 01 Sep 2015 19:52:04 +0200 Subject: Why Python is not both an interpreter and a compiler? In-Reply-To: <201509011733.t81HX65r016928@fido.openend.se> References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> <55e5c220$0$1641$c3e8da3$5496439d@news.astraweb.com> <87io7uun4s.fsf@elektro.pacujo.net> <201509011733.t81HX65r016928@fido.openend.se> Message-ID: <201509011752.t81Hq4jk021782@fido.openend.se> >But are Guile programs small? I the OP made a categorisation error, >confusing correlation with causation. (i.e. the presence of >feathers makes a animal able to fly). s/I the/I think the/ From rosuav at gmail.com Tue Sep 1 14:07:52 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Sep 2015 04:07:52 +1000 Subject: netcdf read In-Reply-To: <2af7b4226f66390b7027cca674bf0bcb@cptec.inpe.br> References: <2af7b4226f66390b7027cca674bf0bcb@cptec.inpe.br> Message-ID: On Wed, Sep 2, 2015 at 3:23 AM, wrote: > I'm starting in the Python scripts. I run this script: > > > import numpy as np > > import netCDF4 > > f = netCDF4.Dataset('uwnd.mon.ltm.nc','r') > > > f.variables > > > and I had the message: > > > netcdf4.py > Traceback (most recent call last): > File "", line 1, in > NameError: name 'netcdf4' is not defined > > > What can I do to solve this. My crystal ball tells me you're probably running Windows. On Windows, there's no difference between "netcdf4.py" and "netCDF4.py", so when you ask Python to "import netCDF4", it finds your program and imports that. To resolve this, just rename your script to something else, and delete any "netcdf4.pyc" or related files. Then try running it under the new name, and you should be fine. ChrisA From marko at pacujo.net Tue Sep 1 16:08:07 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 01 Sep 2015 23:08:07 +0300 Subject: Why Python is not both an interpreter and a compiler? References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> <55e5c220$0$1641$c3e8da3$5496439d@news.astraweb.com> <87io7uun4s.fsf@elektro.pacujo.net> Message-ID: <87egihvr6g.fsf@elektro.pacujo.net> Laura Creighton : > But are Guile programs small? They can be tiny because libguile-2.0.so, the interpreter, is a dynamic library and is installed on the computer. It's barely different from how compiled C programs can be a few kilobytes in size because libc.so is dynamic. Emacs is a lisp interpreter. As part of its installation, emacs dumps core, and the executable core file is installed as the editor we know and love. That way, the most useful lisp modules are already preloaded in the binary, executable image of the editor. On my machine, the emacs executable is 15 megabytes in size. Marko From jason.swails at gmail.com Tue Sep 1 17:10:45 2015 From: jason.swails at gmail.com (Jason Swails) Date: Tue, 1 Sep 2015 17:10:45 -0400 Subject: netcdf read In-Reply-To: References: <2af7b4226f66390b7027cca674bf0bcb@cptec.inpe.br> Message-ID: On Tue, Sep 1, 2015 at 2:07 PM, Chris Angelico wrote: > On Wed, Sep 2, 2015 at 3:23 AM, wrote: > > I'm starting in the Python scripts. I run this script: > > > > > > import numpy as np > > > > import netCDF4 > > > > f = netCDF4.Dataset('uwnd.mon.ltm.nc','r') > > > > > > f.variables > > > > > > and I had the message: > > > > > > netcdf4.py > > Traceback (most recent call last): > > File "", line 1, in > > NameError: name 'netcdf4' is not defined > > > > > > What can I do to solve this. > > My crystal ball tells me you're probably running Windows. > ?Or Mac OS X. Unless you go out of your way to specify otherwise, the default OS X filesystem is case-insensitive. All the best, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Tue Sep 1 18:01:42 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 2 Sep 2015 08:01:42 +1000 Subject: Low level file descriptors and high-level Python files In-Reply-To: <1441122964.2424706.371812753.75CE734E@webmail.messagingengine.com> References: <1441122964.2424706.371812753.75CE734E@webmail.messagingengine.com> Message-ID: <20150901220142.GA36428@cskk.homeip.net> On 01Sep2015 11:56, random832 at fastmail.us wrote: >On Tue, Sep 1, 2015, at 10:57, Steven D'Aprano wrote: >> Q3: I could probably answer Q2 myself if I knew how to check whether a >> fd >> was open or not. With a file object, I can inspect file_obj.closed and it >> will tell me whether the file is open or not. Is there an equivalent for >> file descriptors? > >Well, if you try to call os.close, or any other operation for that >matter, it will raise an OSError with errno=EBADF. os.fstat might be safer. It won't have side effects. As additional remarks: Underwhat circumstances would you imagine probing an fd like this? For what purpose? It feels like a code smell for know having enough situational awareness, and then you're into guesswork world. One circumstance where you might use fdopen and _not_ want .close to close the underlying service is when you're handed a file descriptor over which you're supposed to perform some I/O, and the I/O library functions use high level files. In that case you might want code like this: fd2 = os.dup(fd) fp = open(fd2, 'a+b') # or whatever mode ... do stuff, perhaps passing fp to a library function ... fp.close() fd2 is not closed, but fd is still open for further use. Cheers, Cameron Simpson This is not a bug. It's just the way it works, and makes perfect sense. - Tom Christiansen I like that line. I hope my boss falls for it. - Chaim Frenkel From invalid at invalid.invalid Tue Sep 1 18:19:15 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 1 Sep 2015 22:19:15 +0000 (UTC) Subject: Low level file descriptors and high-level Python files References: <55e5bcd3$0$1639$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2015-09-01, Laura Creighton wrote: > Don't go around closing things you don't know are open. They > could be some other processes' thing. I don't understand. Closing a file descriptor that isn't open is harmless, isn't it? Closing one that _is_ open only affects the current process. If other processes had the same fd open, it's still open for them. -- Grant Edwards grant.b.edwards Yow! FUN is never having to at say you're SUSHI!! gmail.com From rosuav at gmail.com Tue Sep 1 20:50:15 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Sep 2015 10:50:15 +1000 Subject: Why Python is not both an interpreter and a compiler? In-Reply-To: <87egihvr6g.fsf@elektro.pacujo.net> References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> <55e5c220$0$1641$c3e8da3$5496439d@news.astraweb.com> <87io7uun4s.fsf@elektro.pacujo.net> <87egihvr6g.fsf@elektro.pacujo.net> Message-ID: On Wed, Sep 2, 2015 at 6:08 AM, Marko Rauhamaa wrote: > Laura Creighton : > >> But are Guile programs small? > > They can be tiny because libguile-2.0.so, the interpreter, is a dynamic > library and is installed on the computer. It's barely different from how > compiled C programs can be a few kilobytes in size because libc.so is > dynamic. And compiled C programs are notoriously hard to distribute. Can you pick up a Guile binary and carry it to another computer? Do you have to absolutely perfectly match the libguile version, architecture, build settings, etc? Also... how is this different from distributing .pyc files and expecting people to have a Python interpreter? ChrisA From rhills at medimorphosis.com.au Tue Sep 1 22:03:53 2015 From: rhills at medimorphosis.com.au (Rob Hills) Date: Wed, 2 Sep 2015 10:03:53 +0800 Subject: Reading \n unescaped from a file Message-ID: <55E65909.2080507@medimorphosis.com.au> Hi, I am developing code (Python 3.4) that transforms text data from one format to another. As part of the process, I had a set of hard-coded str.replace(...) functions that I used to clean up the incoming text into the desired output format, something like this: dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds dataIn = dataIn.replace('<','<') # Tidy up < character dataIn = dataIn.replace('>','>') # Tidy up < character dataIn = dataIn.replace('o','o') # No idea why but lots of these: convert to 'o' character dataIn = dataIn.replace('f','f') # .. and these: convert to 'f' character dataIn = dataIn.replace('e','e') # .. 'e' dataIn = dataIn.replace('O','O') # .. 'O' These statements transform my data correctly, but the list of statements grows as I test the data so I thought it made sense to store the replacement mappings in a file, read them into a dict and loop through that to do the cleaning up, like this: with open(fileName, 'r+t', encoding='utf-8') as mapFile: for line in mapFile: line = line.strip() try: if (line) and not line.startswith('#'): line = line.split('#')[:1][0].strip() # trim any trailing comments name, value = line.split('=') name = name.strip() self.filterMap[name]=value.strip() except: self.logger.error('exception occurred parsing line [{0}] in file [{1}]'.format(line, fileName)) raise Elsewhere, I use the following code to do the actual cleaning up: def filter(self, dataIn): if dataIn: for token, replacement in self.filterMap.items(): dataIn = dataIn.replace(token, replacement) return dataIn My mapping file contents look like this: \r = \\n ??? = " < = < > = > ' = ' F = F o = o f = f e = e O = O This all works "as advertised" */except/* for the '\r' => '\\n' replacement. Debugging the code, I see that my '\r' character is "escaped" to '\\r' and the '\\n' to '\\\\n' when they are read in from the file. I've been googling hard and reading the Python docs, trying to get my head around character encoding, but I just can't figure out how to get these bits of code to do what I want. It seems to me that I need to either: * change the way I represent '\r' and '\\n' in my mapping file; or * transform them somehow when I read them in However, I haven't figured out how to do either of these. TIA, -- Rob Hills Waikiki, Western Australia -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Tue Sep 1 22:08:03 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 2 Sep 2015 12:08:03 +1000 Subject: Low level file descriptors and high-level Python files In-Reply-To: <20150901220142.GA36428@cskk.homeip.net> References: <20150901220142.GA36428@cskk.homeip.net> Message-ID: <20150902020803.GA92244@cskk.homeip.net> On 02Sep2015 08:01, Cameron Simpson wrote: >One circumstance where you might use fdopen and _not_ want .close to close the underlying service is when you're handed a file descriptor over which you're supposed to perform some I/O, and the I/O library functions use high level files. In that case you might want code like this: > > fd2 = os.dup(fd) > fp = open(fd2, 'a+b') # or whatever mode > ... do stuff, perhaps passing fp to a library function ... > fp.close() > >fd2 is not closed, but fd is still open for further use. Um, "fd2 _is_ closed". Whoops. Cheers, Cameron Simpson Freedom is the right to be wrong, not the right to do wrong. - John G. Riefenbaker From steve at pearwood.info Tue Sep 1 22:49:24 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 02 Sep 2015 12:49:24 +1000 Subject: Why Python is not both an interpreter and a compiler? References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> <55e5c220$0$1641$c3e8da3$5496439d@news.astraweb.com> <87io7uun4s.fsf@elektro.pacujo.net> Message-ID: <55e663b5$0$1668$c3e8da3$5496439d@news.astraweb.com> On Wed, 2 Sep 2015 02:20 am, Marko Rauhamaa wrote: > Steven D'Aprano : > >> I believe that Marko is wrong. It is not so easy to compile Python to >> machine language for real machines. That's why the compiler targets a >> virtual machine instead. > > Somehow Guile manages it even though Scheme is at least as dynamic a > language as Python. It's not about the dynamicism precisely, it's about what counts as primitive data types and operations. What are the primitives in Scheme? In Python, the primitives are pretty complex. I don't know how accurate this page is: https://en.wikibooks.org/wiki/Scheme_Programming/Scheme_Datatypes but it suggests that Scheme primitives are quite close to the machine. That may keep the runtime small. > I never said a compiler would translate Python to (analogous) machine > language. I said you could easily turn CPython into a dynamic library > (run-time environment) and write a small bootstrapper that you package > into an executable archive with the Python code (whether .py or .pyc). > What results is a single executable that you can run analogously to any > other command. Provided you have the correct version of the dynamic library installed in the correct place. But this doesn't solve the problem of being able to distribute a single executable file that requires no pre-installed libraries, which is the problem cx_freeze and pytoexe are made to solve. They solve the case when you can't assume that there is a Python run-time environment available. If you are going to require a Python run-time environment, let's call it "pylib", then you might as well require the python compiler and standard library be installed. (In the case of C, that's not the case, a distinct run-time environment makes sense, as the compile-time and run-time environments are sharply delineated in C. One certainly wouldn't want to have to re-compile the average C application each and every time you run it.) Maybe you could separate the REPL and remove it from pylib, but that's probably quite small, it might not make that much of a difference to the total size. Maybe you could build a pylib that was significantly smaller than the Python interpreter plus stdlib. That's fine, I'm not arguing it can't be done. I'm arguing that it's not *easy*, if it were easy somebody likely would have done it by now. I don't know the state of the art here. Does Cython work in this space? How about Nuitka? > In fact, the shebang notation turns any single .py file into such an > executable. I trust that you're not actually arguing that distributing .py files meets the requirement for a standalone application. > The problem is if you break your program into modules. Java, > of course, solved a similar problem with .jar files (but still wouldn't > jump over the final hurdle of making the .jar files executable). You can distribute your Python app as a zip file, except of course you still need the Python interpreter to be installed. -- Steven From torriem at gmail.com Tue Sep 1 23:46:14 2015 From: torriem at gmail.com (Michael Torrie) Date: Tue, 01 Sep 2015 21:46:14 -0600 Subject: Why Python is not both an interpreter and a compiler? In-Reply-To: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> Message-ID: <55E67106.7050707@gmail.com> On 08/31/2015 02:35 AM, Mahan Marwat wrote: > What I know about an interpreter and a compiler is: they both convert > source code to machine code and the only difference is, an > interpreter convert it, line by line while compiler convert the whole > source file. Now if we compile a C source file on C compiler, it will > produce a small executable file. But if we compile (freeze) a Python > source file on Python interpreter (using cx_freeze), it will produce > a big executable file. Now the thing is C compiler does not embed a C > compiler inside our program, while the Python interpreter (cx_freeze, > pytoexe) embed Python interpreter inside our program, what is the > reason? The question is, why cx_freeze etc... embed Python > interpreter inside our programs, they are unable to produce machine > code like C compiler do? Cant we program a language, which is both > interpreted and compiled? The core developer cant add the compiling > functionality to Python? It think your questions have been well answered by others. But there are several attempts at making an actual python compiler. Often this involve less-dynamic subset of Python. For example, pypy has a dialect called rpython which compiles straight to C++ code, and then to machine code. Another subset compiler is cython, which is somewhat of a specialized compiler. It compiles a subset of Python to a binary shared library that can be imported into a Python program running in the normal interpreter. The dynamic nature of Python means that probably your best route to speed is going to be through just-in-time compilation. The pypy project is an attempt to do JIT with Python. So far the results are very promising. Pretty cool since pypy is written in Python and bootstraps from the standard python interpreter. Lastly, one attempt at a compiler is nuitka (google it). It produces self-contained executables. Nuitka compiles what it can, and interprets the rest (if I understand it correctly) by embedding libpython itself in the executable. At this time, nuitka isn't focusing on performance, more correctness. GvR doesn't really think much of nuitka, but I think it's a cool project and the developer is a nice guy. Maybe have its uses. So far I haven't had a use for nuikta; cPython is enough for me, with cython for compiling functions that need some more raw speed. I tend to use more conventional optimization techniques that work just fine with the interpreter. And often the results are fast enough. For example I implemented a simple memoization wrapper for a particularly expensive function that was called a lot, often over the same inputs several times. Runtime went from 10 seconds to less than 1. Enough for me! From marko at pacujo.net Tue Sep 1 23:58:54 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 02 Sep 2015 06:58:54 +0300 Subject: Why Python is not both an interpreter and a compiler? References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> <55e5c220$0$1641$c3e8da3$5496439d@news.astraweb.com> <87io7uun4s.fsf@elektro.pacujo.net> <55e663b5$0$1668$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zj15tqtd.fsf@elektro.pacujo.net> Steven D'Aprano : > On Wed, 2 Sep 2015 02:20 am, Marko Rauhamaa wrote: >> I never said a compiler would translate Python to (analogous) machine >> language. I said you could easily turn CPython into a dynamic library >> (run-time environment) and write a small bootstrapper that you >> package into an executable archive with the Python code (whether .py >> or .pyc). What results is a single executable that you can run >> analogously to any other command. > > Provided you have the correct version of the dynamic library installed > in the correct place. Yes, virtually all Linux software builds upon dynamic libraries that have been introduced to the linker via ldconfig. > But this doesn't solve the problem of being able to distribute a single > executable file that requires no pre-installed libraries, which is the > problem cx_freeze and pytoexe are made to solve. I wasn't trying to solve that particular problem. I was simply stating you could compile (translate, turn) a Python program into a single, executable file. > I trust that you're not actually arguing that distributing .py files > meets the requirement for a standalone application. If your application consists of a single .py file, why not? >> The problem is if you break your program into modules. Java, of >> course, solved a similar problem with .jar files (but still wouldn't >> jump over the final hurdle of making the .jar files executable). > > You can distribute your Python app as a zip file, except of course you > still need the Python interpreter to be installed. Again, having a Python interpreter around is not the issue I'm talking about. I'm talking about the possibility to compile (translate, turn) a Python program into a single, executable file. Now, even C programs can suffer from the module problem: you sometimes need to ship extra dynamic libraries ("modules") with your binary. Marko From harvesting at makes.address.invalid Wed Sep 2 01:59:56 2015 From: harvesting at makes.address.invalid (Jussi Piitulainen) Date: Wed, 02 Sep 2015 08:59:56 +0300 Subject: Why Python is not both an interpreter and a compiler? References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> <55e5c220$0$1641$c3e8da3$5496439d@news.astraweb.com> <87io7uun4s.fsf@elektro.pacujo.net> <55e663b5$0$1668$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Wed, 2 Sep 2015 02:20 am, Marko Rauhamaa wrote: >> Steven D'Aprano: >> >>> I believe that Marko is wrong. It is not so easy to compile Python >>> to machine language for real machines. That's why the compiler >>> targets a virtual machine instead. >> >> Somehow Guile manages it even though Scheme is at least as dynamic a >> language as Python. > > It's not about the dynamicism precisely, it's about what counts as > primitive data types and operations. > > What are the primitives in Scheme? In Python, the primitives are > pretty complex. I don't know how accurate this page is: > > https://en.wikibooks.org/wiki/Scheme_Programming/Scheme_Datatypes > > but it suggests that Scheme primitives are quite close to the > machine. That may keep the runtime small. I think I spotted a tiny inaccuracy, but the real problem with that page is that it's *very* incomplete: no mention of exact integers and rationals, strings appear in text but not as an entry, were vectors even mentioned?, nothing about procedures!, let alone reified continuations, nothing about input/output ports. Also records (definable types with named fields) are now officially in for some time already, so that's another kind of structured types. Many implementations have object systems, possibly modules as objects. It's quite analogous to Python's objects. Eval in Scheme is more restricted. Procedure internals are not accessible at all, and implementations typically offer ways to declare that standard names in a compilation unit indeed have their standard meaning and variables will not be assigned outside the given compilation unit, so the compiler can propagate information about expected argument types around, infer more types, inline code, and lot's of things that are way beyond me. Some Scheme implementations use quite aggressive compilation techniques. Guile is one, I think. Gambit and Larceny are two others. [- -] From lac at openend.se Wed Sep 2 03:02:24 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 02 Sep 2015 09:02:24 +0200 Subject: Low level file descriptors and high-level Python files In-Reply-To: References: <55e5bcd3$0$1639$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201509020702.t8272OHs024932@fido.openend.se> In a message of Tue, 01 Sep 2015 22:19:15 -0000, Grant Edwards writes: >On 2015-09-01, Laura Creighton wrote: > >> Don't go around closing things you don't know are open. They >> could be some other processes' thing. > >I don't understand. Closing a file descriptor that isn't open is >harmless, isn't it? Closing one that _is_ open only affects the >current process. If other processes had the same fd open, it's still >open for them. > >-- >Grant Edwards grant.b.edwards Yow! FUN is never having to > at say you're SUSHI!! > gmail.com This is me being tired and not saying things properly. What I meant was don't go around closing mkstemp files thinking you can reopen them later, because in between the time you use mkstemp to make the file and you open it up again later somebody else may have replaced that file. Including some other program running mkstemp which was desparate to make the exact same filename you did. But that's not what I said ... so thank you. Laura From antoon.pardon at rece.vub.ac.be Wed Sep 2 03:05:30 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 02 Sep 2015 09:05:30 +0200 Subject: execute commands as su on remote server In-Reply-To: References: Message-ID: <55E69FBA.4030903@rece.vub.ac.be> Op 18-08-15 om 04:57 schreef harirammanohar159 at gmail.com: > execute commands as su on remote server > > Postby hariram ? Mon Aug 17, 2015 4:02 am > Needed: > I need to execute commands after doing su to other user on remote server(not sudo which doesn't require password) how i can achieve this using python? > I googled and came to know that its not possible, so just for confirmation asking again, is it possible ? > > Already Tried: > Tried paramiko that's too not working. What about pexpect: https://pypi.python.org/pypi/pexpect/ It's been a long time since I used it, but it was for something similar. -- Antoon Pardon From lac at openend.se Wed Sep 2 03:09:55 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 02 Sep 2015 09:09:55 +0200 Subject: Why Python is not both an interpreter and a compiler? In-Reply-To: References: <3e541d13-bc86-456c-8590-4ffd1af9cfd0@googlegroups.com> <87twrftw4w.fsf@elektro.pacujo.net> <55e5c220$0$1641$c3e8da3$5496439d@news.astraweb.com> <87io7uun4s.fsf@elektro.pacujo.net> <87egihvr6g.fsf@elektro.pacujo.net> Message-ID: <201509020709.t8279t0X026808@fido.openend.se> In a message of Wed, 02 Sep 2015 10:50:15 +1000, Chris Angelico writes: >And compiled C programs are notoriously hard to distribute. Can you >pick up a Guile binary and carry it to another computer? Do you have >to absolutely perfectly match the libguile version, architecture, >build settings, etc? This is the problem that docker has set out to solve. https://www.docker.com/whatisdocker I think it is pretty neat stuff, myself. Laura From antoon.pardon at rece.vub.ac.be Wed Sep 2 05:14:57 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 02 Sep 2015 11:14:57 +0200 Subject: Getting the logging level from text representation Message-ID: <55E6BE11.4050607@rece.vub.ac.be> I am writing an application that will do the necessary logging. However I want the level of logging to be deciced by a value in a config file. Like the following: loglevel = WARNING But I can't find a function that does this. The reverse is possible with logging.getLevelName. The documentation also states this: Changed in version 3.4: In Python versions earlier than 3.4, this function could also be passed a text level, and would return the corresponding numeric value of the level. This undocumented behaviour was considered a mistake, and was removed in Python 3.4, but reinstated in 3.4.2 due to retain backward compatibility. So what is the supposed correct way to handle this? Preferably one that works when additional levels have been introduced. -- Antoon Pardon From __peter__ at web.de Wed Sep 2 05:50:38 2015 From: __peter__ at web.de (Peter Otten) Date: Wed, 02 Sep 2015 11:50:38 +0200 Subject: Getting the logging level from text representation References: <55E6BE11.4050607@rece.vub.ac.be> Message-ID: Antoon Pardon wrote: > I am writing an application that will do the necessary logging. > However I want the level of logging to be deciced by a value > in a config file. Like the following: > > loglevel = WARNING > > But I can't find a function that does this. > > The reverse is possible with logging.getLevelName. The documentation > also states this: > > Changed in version 3.4: In Python versions earlier than 3.4, this function > could also be passed a text level, and would return the corresponding > numeric value of the level. This undocumented behaviour was considered > a mistake, and was removed in Python 3.4, but reinstated in 3.4.2 due > to retain backward compatibility. > > So what is the supposed correct way to handle this? Preferably one > that works when additional levels have been introduced. Why do you want to convert the name into a number? You can use it directly: >>> import logging >>> root = logging.getLogger() >>> root.level 30 >>> root.setLevel("INFO") >>> root.level 20 >>> root.setLevel("ROCKET") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/logging/__init__.py", line 1236, in setLevel self.level = _checkLevel(level) File "/usr/lib/python3.4/logging/__init__.py", line 179, in _checkLevel raise ValueError("Unknown level: %r" % level) ValueError: Unknown level: 'ROCKET' >>> logging.addLevelName(10987654321, "ROCKET") >>> root.setLevel("ROCKET") >>> root.level 10987654321 From antoon.pardon at rece.vub.ac.be Wed Sep 2 06:01:40 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 02 Sep 2015 12:01:40 +0200 Subject: packing unpacking depends on order. Message-ID: <55E6C904.3020602@rece.vub.ac.be> >>> a = [1, 2, 3, 4, 5] >>> b = 1 >>> b, a[b] = a[b], b >>> a [1, 2, 1, 4, 5] >>> a = [1, 2, 3, 4, 5] >>> b = 1 >>> a[b], b = b, a[b] >>> a [1, 1, 3, 4, 5] I think I understand how it gets these results but I'm not really happy with them. I think python should give the second result in both cases. -- Antoon Pardon From victorhooi at gmail.com Wed Sep 2 06:04:36 2015 From: victorhooi at gmail.com (Victor Hooi) Date: Wed, 2 Sep 2015 03:04:36 -0700 (PDT) Subject: Using enumerate to get line-numbers with itertools grouper? Message-ID: I'm using grouper() to iterate over a textfile in groups of lines: def grouper(iterable, n, fillvalue=None): "Collect data into fixed-length chunks or blocks" # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx args = [iter(iterable)] * n return zip_longest(fillvalue=fillvalue, *args) However, I'd also like to know the line-number that I'm up to, for printing out in informational or error messages. Is there a way to use enumerate with grouper to achieve this? The below won't work, as enumerate will give me the index of the group, rather than of the lines themselves: _BATCH_SIZE = 50 with open(args.input_file, 'r') as f: for line_number, chunk in enumerate(grouper(f, _BATCH_SIZE)): print(line_number) I'm thinking I could do something to modify grouper, maybe, but I'm sure there's an easier way? From antoon.pardon at rece.vub.ac.be Wed Sep 2 06:14:44 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 02 Sep 2015 12:14:44 +0200 Subject: Getting the logging level from text representation In-Reply-To: References: <55E6BE11.4050607@rece.vub.ac.be> Message-ID: <55E6CC14.8010703@rece.vub.ac.be> Op 02-09-15 om 11:50 schreef Peter Otten: > Antoon Pardon wrote: > >> I am writing an application that will do the necessary logging. >> However I want the level of logging to be deciced by a value >> in a config file. Like the following: >> >> loglevel = WARNING >> >> But I can't find a function that does this. >> >> The reverse is possible with logging.getLevelName. The documentation >> also states this: >> >> Changed in version 3.4: In Python versions earlier than 3.4, this function >> could also be passed a text level, and would return the corresponding >> numeric value of the level. This undocumented behaviour was considered >> a mistake, and was removed in Python 3.4, but reinstated in 3.4.2 due >> to retain backward compatibility. >> >> So what is the supposed correct way to handle this? Preferably one >> that works when additional levels have been introduced. > Why do you want to convert the name into a number? You can use it directly: Well because that is a recent change and I didn't know about it and I missed it while browsing the documentation. I think this kind of documenation should be part of the proper description and not part of the history. It also doesn't work for everything. Logger.isEnabledFor(lvl) expect a number. But for the moment it serves my needs, so thanks for pointing it out. -- Antoon Pardon. From nick.a.sarbicki at gmail.com Wed Sep 2 06:22:10 2015 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Wed, 02 Sep 2015 10:22:10 +0000 Subject: packing unpacking depends on order. In-Reply-To: <55E6C904.3020602@rece.vub.ac.be> References: <55E6C904.3020602@rece.vub.ac.be> Message-ID: That's interesting. I agree with you, I'd prefer the second result in both cases. But makes sense as it evaluates left to right and seems to break up the unpacking into separate statements. Could be useful if you want to hold the results of a generator in sequence, can call the same function multiple times and unpack as above. On Wed, Sep 2, 2015 at 11:07 AM Antoon Pardon wrote: > > >>> a = [1, 2, 3, 4, 5] > >>> b = 1 > >>> b, a[b] = a[b], b > >>> a > [1, 2, 1, 4, 5] > >>> a = [1, 2, 3, 4, 5] > >>> b = 1 > >>> a[b], b = b, a[b] > >>> a > [1, 1, 3, 4, 5] > > I think I understand how it gets these results > but I'm not really happy with them. I think python > should give the second result in both cases. > > -- > Antoon Pardon > > -- > https://mail.python.org/mailman/listinfo/python-list > -- - Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Sep 2 06:36:25 2015 From: __peter__ at web.de (Peter Otten) Date: Wed, 02 Sep 2015 12:36:25 +0200 Subject: Using enumerate to get line-numbers with itertools grouper? References: Message-ID: Victor Hooi wrote: > I'm using grouper() to iterate over a textfile in groups of lines: > > def grouper(iterable, n, fillvalue=None): > "Collect data into fixed-length chunks or blocks" > # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx > args = [iter(iterable)] * n > return zip_longest(fillvalue=fillvalue, *args) > > However, I'd also like to know the line-number that I'm up to, for > printing out in informational or error messages. > > Is there a way to use enumerate with grouper to achieve this? > > The below won't work, as enumerate will give me the index of the group, > rather than of the lines themselves: > > _BATCH_SIZE = 50 > > with open(args.input_file, 'r') as f: > for line_number, chunk in enumerate(grouper(f, _BATCH_SIZE)): > print(line_number) > > I'm thinking I could do something to modify grouper, maybe, but I'm sure > there's an easier way? print(line_number * _BATCH_SIZE) Eureka ;) From lac at openend.se Wed Sep 2 07:21:31 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 02 Sep 2015 13:21:31 +0200 Subject: Getting the logging level from text representation In-Reply-To: <55E6CC14.8010703@rece.vub.ac.be> References: <55E6BE11.4050607@rece.vub.ac.be> <55E6CC14.8010703@rece.vub.ac.be> Message-ID: <201509021121.t82BLVsF024954@fido.openend.se> In a message of Wed, 02 Sep 2015 12:14:44 +0200, Antoon Pardon writes: See: https://docs.python.org/3.5/library/logging.html#levels you can just use 30 everywhere for warning, and that is what Logger.getEffectiveLevel() will tell you even if you initialised it with the text form. Laura From victorhooi at gmail.com Wed Sep 2 07:49:21 2015 From: victorhooi at gmail.com (Victor Hooi) Date: Wed, 2 Sep 2015 04:49:21 -0700 (PDT) Subject: for loop over function that returns a tuple? Message-ID: <09ff717a-8634-4fe7-84e1-f84ed4cf1f21@googlegroups.com> I have a function which is meant to return a tuple: def get_metrics(server_status_json, metrics_to_extract, line_number): return ((timestamp, "serverstatus", values, tags)) I also have: def create_point(timestamp, metric_name, values, tags): return { "measurement": _MEASUREMENT_PREFIX + metric_name, "tags": tags, "time": timestamp, "fields": values } I am calling get_metric in a for loop like so: for metric_data in get_metrics(server_status_json, mmapv1_metrics, line_number): json_points.append(create_point(*metric_data)) I was hoping to use tuple unpacking to pass metric_data straight from get_metrics through to create_point. However, in this case, metric_data only contains timestamp. I suppose I could assign multiple variables like, and pass them through: for timestamp, metric_name, value, tags in get_metrics(server_status_json, common_metrics, line_number): However, that seems unnecessarily verbose, and I'm sure there's a simple way to do this with tuple unpacking? From victorhooi at gmail.com Wed Sep 2 08:03:17 2015 From: victorhooi at gmail.com (Victor Hooi) Date: Wed, 2 Sep 2015 05:03:17 -0700 (PDT) Subject: Using enumerate to get line-numbers with itertools grouper? In-Reply-To: References: Message-ID: <0a373caf-9022-41ca-8533-eb8ba2a1843a@googlegroups.com> Hi Peter, Hmm, are you sure that will work? The indexes returned by enumerate will start from zero. Also, I've realised line_number is a bit of a misnomer here - it's actually the index for the chunks that grouper() is returning. So say I had a 10-line textfile, and I was using a _BATCH_SIZE of 50. If I do: print(line_number * _BATCH_SIZE) I'd just get (0 * 50) = 0 printed out 10 times. Even if I add one: print((line_number + 1) * _BATCH_SIZE) I will just get 50 printed out 10 times. My understanding is that the file handle f is being passed to grouper, which is then passing another iterable to enumerate - I'm just not sure of the best way to get the line numbers from the original iterable f, and pass this through the chain? On Wednesday, 2 September 2015 20:37:01 UTC+10, Peter Otten wrote: > Victor Hooi wrote: > > > I'm using grouper() to iterate over a textfile in groups of lines: > > > > def grouper(iterable, n, fillvalue=None): > > "Collect data into fixed-length chunks or blocks" > > # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx > > args = [iter(iterable)] * n > > return zip_longest(fillvalue=fillvalue, *args) > > > > However, I'd also like to know the line-number that I'm up to, for > > printing out in informational or error messages. > > > > Is there a way to use enumerate with grouper to achieve this? > > > > The below won't work, as enumerate will give me the index of the group, > > rather than of the lines themselves: > > > > _BATCH_SIZE = 50 > > > > with open(args.input_file, 'r') as f: > > for line_number, chunk in enumerate(grouper(f, _BATCH_SIZE)): > > print(line_number) > > > > I'm thinking I could do something to modify grouper, maybe, but I'm sure > > there's an easier way? > > print(line_number * _BATCH_SIZE) > > Eureka ;) From harvesting at makes.address.invalid Wed Sep 2 08:24:28 2015 From: harvesting at makes.address.invalid (Jussi Piitulainen) Date: Wed, 02 Sep 2015 15:24:28 +0300 Subject: for loop over function that returns a tuple? References: <09ff717a-8634-4fe7-84e1-f84ed4cf1f21@googlegroups.com> Message-ID: Victor Hooi writes: > I have a function which is meant to return a tuple: > > def get_metrics(server_status_json, metrics_to_extract, line_number): > > return ((timestamp, "serverstatus", values, tags)) That returns a single tuple of four values. The double parentheses are redundant. > I also have: > > def create_point(timestamp, metric_name, values, tags): That can take the four values in the tuple returned by get_metrics, ok. > I am calling get_metric in a for loop like so: > > for metric_data in get_metrics(server_status_json, mmapv1_metrics, line_number): > json_points.append(create_point(*metric_data)) That sets metric_data to each of the four values in the one tuple in turn. You seem to want just: json_points.append(create_point(*get_metrics(...))) > I was hoping to use tuple unpacking to pass metric_data straight from > get_metrics through to create_point. That should be cool. It's the loop that's a little bit too much. (If you want get_metrics to return a singleton tuple containing the four-tuple, you need an extra comma in there: (x) is just x; (x,) is a tuple containing x. From steve at pearwood.info Wed Sep 2 08:26:08 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 02 Sep 2015 22:26:08 +1000 Subject: packing unpacking depends on order. References: Message-ID: <55e6eadf$0$1652$c3e8da3$5496439d@news.astraweb.com> On Wed, 2 Sep 2015 08:01 pm, Antoon Pardon wrote: > >>>> a = [1, 2, 3, 4, 5] >>>> b = 1 >>>> b, a[b] = a[b], b >>>> a > [1, 2, 1, 4, 5] Equivalent to: temp1 = a[b] # a[1] == 2 temp2 = b # 1 b = temp1 # b = 2 a[b] = temp2 # a[2] = 1 Or using a queue (FIFO) rather than temp variables: push a[b] push b b = pop a[b] = pop which seems sensible to me. The right hand side of the assignment is evaluated left-to-right, and then the assignments are made, from left-to-right. Which I believe matches the documented order. >>>> a = [1, 2, 3, 4, 5] >>>> b = 1 >>>> a[b], b = b, a[b] >>>> a > [1, 1, 3, 4, 5] Likewise: temp1 = b # 1 temp2 = a[b] # a[1] == 2 a[b] = temp1 # a[1] = 1 b = temp2 # b = 2 > I think I understand how it gets these results > but I'm not really happy with them. I think python > should give the second result in both cases. Apart from breaking backwards compatibility, how would you implement such a thing? A simple left-to-right assignment rule is easy to implement and easy to understand even when the targets depend on each other. -- Steven From rosuav at gmail.com Wed Sep 2 08:45:07 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 2 Sep 2015 22:45:07 +1000 Subject: packing unpacking depends on order. In-Reply-To: <55e6eadf$0$1652$c3e8da3$5496439d@news.astraweb.com> References: <55e6eadf$0$1652$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 2, 2015 at 10:26 PM, Steven D'Aprano wrote: >> I think I understand how it gets these results >> but I'm not really happy with them. I think python >> should give the second result in both cases. > > Apart from breaking backwards compatibility, how would you implement such a > thing? A simple left-to-right assignment rule is easy to implement and easy > to understand even when the targets depend on each other. I don't think this is really a question of implementation - it's a design question of "should". The current behaviour is reasonably sane. But if you're confused by it, there's a simple solution: Don't reference the same "thing" more than once on the LHS. ChrisA From __peter__ at web.de Wed Sep 2 09:09:29 2015 From: __peter__ at web.de (Peter Otten) Date: Wed, 02 Sep 2015 15:09:29 +0200 Subject: Using enumerate to get line-numbers with itertools grouper? References: <0a373caf-9022-41ca-8533-eb8ba2a1843a@googlegroups.com> Message-ID: Victor Hooi wrote: > Hi Peter, > > Hmm, are you sure that will work? If you want the starting line for the batch, yes: $ cat tmp.txt alpha (line #1) beta (line #2) gamma (line #3) delta (line #4) epsilon (line #5) zeta (line #6) eta (line #7) theta (line #8) iota (line #9) kappa (line #10) $ cat grouper_demo.py from itertools import zip_longest def grouper(iterable, n, fillvalue=None): args = [iter(iterable)] * n return zip_longest(fillvalue=fillvalue, *args) _BATCH_SIZE = 3 with open("tmp.txt", 'r') as f: for index, chunk in enumerate(grouper(f, _BATCH_SIZE)): print("batch starting at line", index * _BATCH_SIZE + 1) print(chunk) $ python3 grouper_demo.py batch starting at line 1 ('alpha (line #1)\n', 'beta (line #2)\n', 'gamma (line #3)\n') batch starting at line 4 ('delta (line #4)\n', 'epsilon (line #5)\n', 'zeta (line #6)\n') batch starting at line 7 ('eta (line #7)\n', 'theta (line #8)\n', 'iota (line #9)\n') batch starting at line 10 ('kappa (line #10)\n', None, None) > The indexes returned by enumerate will start from zero. > > Also, I've realised line_number is a bit of a misnomer here - it's > actually the index for the chunks that grouper() is returning. > > So say I had a 10-line textfile, and I was using a _BATCH_SIZE of 50. > > If I do: > > print(line_number * _BATCH_SIZE) > > I'd just get (0 * 50) = 0 printed out 10 times. > > Even if I add one: > > print((line_number + 1) * _BATCH_SIZE) > > I will just get 50 printed out 10 times. So you are trying to solve a slightly different problem. You can attack that by moving the enumerate() call: $ cat grouper_demo2.py from itertools import zip_longest def grouper(iterable, n, fillvalue=None): args = [iter(iterable)] * n return zip_longest(fillvalue=fillvalue, *args) _BATCH_SIZE = 3 with open("tmp.txt", 'r') as f: for chunk in grouper( enumerate(f, 1), _BATCH_SIZE, fillvalue=(None, None)): print("--- batch ---") for index, line in chunk: if index is None: break print(index, line, end="") print() $ python3 grouper_demo2.py --- batch --- 1 alpha (line #1) 2 beta (line #2) 3 gamma (line #3) --- batch --- 4 delta (line #4) 5 epsilon (line #5) 6 zeta (line #6) --- batch --- 7 eta (line #7) 8 theta (line #8) 9 iota (line #9) --- batch --- 10 kappa (line #10) $ From antoon.pardon at rece.vub.ac.be Wed Sep 2 09:59:26 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 02 Sep 2015 15:59:26 +0200 Subject: packing unpacking depends on order. In-Reply-To: References: <55e6eadf$0$1652$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55E700BE.8050309@rece.vub.ac.be> Op 02-09-15 om 14:45 schreef Chris Angelico: > On Wed, Sep 2, 2015 at 10:26 PM, Steven D'Aprano wrote: >>> I think I understand how it gets these results >>> but I'm not really happy with them. I think python >>> should give the second result in both cases. >> Apart from breaking backwards compatibility, how would you implement such a >> thing? A simple left-to-right assignment rule is easy to implement and easy >> to understand even when the targets depend on each other. > I don't think this is really a question of implementation - it's a > design question of "should". > > The current behaviour is reasonably sane. Yes it is reasonable sane, I just think the alternative would be saner. > But if you're confused by > it, there's a simple solution: Don't reference the same "thing" more > than once on the LHS. That is rather extreme. It would mean we avoid the following: a[i], b[i] = b[i], a[i] # references i twice on the LHS. a[i], a[j] = a[j], a[i] # references a twice on the LHS. I think a better rule would be: Don't reference and bind the same "thing" on the LHS. -- Antoon Pardon From rosuav at gmail.com Wed Sep 2 10:12:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Sep 2015 00:12:06 +1000 Subject: packing unpacking depends on order. In-Reply-To: <55E700BE.8050309@rece.vub.ac.be> References: <55e6eadf$0$1652$c3e8da3$5496439d@news.astraweb.com> <55E700BE.8050309@rece.vub.ac.be> Message-ID: On Wed, Sep 2, 2015 at 11:59 PM, Antoon Pardon wrote: >> But if you're confused by >> it, there's a simple solution: Don't reference the same "thing" more >> than once on the LHS. > > That is rather extreme. It would mean we avoid the following: > > a[i], b[i] = b[i], a[i] # references i twice on the LHS. > a[i], a[j] = a[j], a[i] # references a twice on the LHS. > > I think a better rule would be: Don't reference and bind > the same "thing" on the LHS. Sure. In any case, it's a programmer's choice; the language has well-defined behaviour even if you don't follow a rule like this, so it's just to help you keep things safe in your own head. ChrisA From steve at pearwood.info Wed Sep 2 10:49:35 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 03 Sep 2015 00:49:35 +1000 Subject: for loop over function that returns a tuple? References: <09ff717a-8634-4fe7-84e1-f84ed4cf1f21@googlegroups.com> Message-ID: <55e70c80$0$1638$c3e8da3$5496439d@news.astraweb.com> On Wed, 2 Sep 2015 09:49 pm, Victor Hooi wrote: > I have a function which is meant to return a tuple: > > def get_metrics(server_status_json, metrics_to_extract, line_number): > > return ((timestamp, "serverstatus", values, tags)) No need for the second pair of parentheses. Technically, no need for any parens, this will do: return timestamp, "serverstatus", values, tags but putting a single pair of parens around the four items is acceptable for aesthetic reasons. > I also have: > > def create_point(timestamp, metric_name, values, tags): This function requires four separate values. So you have to either pass four values, using tuple unpacking, or re-write the function to accept a single tuple, then unpack it inside the function: def create_point(items): timestamp, metric_name, values, tags = items ... Another possibility is to be clever (perhaps too clever?) and accept either four arguments or a single tuple of four arguments: def create_point(*args): if len(args) == 1: timestamp, metric_name, values, tags = args[0] elif len(args) == 4: timestamp, metric_name, values, tags = args else: raise TypeError('too many or too few arguments') ... But your current solution seems good to me. The create_point function is self-documenting with four named arguments. You can pass the items directly: pt = create_point(this, that, other, another) or by unpacking a sequence: pt = create_point(*fourvalues) Whatever you do, *something* has to unpack the four values. So why not do it when you call the function? There is one last possibility. I hesitate to mention it, because it is for Python 2 only and is not supported in Python 3, but you can also do this: # Python 2 only def create_point((timestamp, metric_name, values, tags)): ... Notice the extra pair of parens? This means that create_point now takes a single argument, which is automatically unpacked into the four names given. It is equivalent to the following version: # Python 3 or Python 2 def create_point(items): timestamp, metric_name, values, tags = items ... which I already showed. > I am calling get_metric in a for loop like so: > > for metric_data in get_metrics(server_status_json, mmapv1_metrics, > line_number): > json_points.append(create_point(*metric_data)) This version looks fine to me. You're going to have to unpack the data somewhere, this is as good as place as any other. Or you could write this: # use nicer names, of course for a, b, c, d in get_metrics( server_status_json, mmapv1_metrics, line_number): json_points.append(create_point(a, b, c, d)) It's all much the same whichever way you do it. I doubt there is any efficiency difference, pick the version you like to read the most. > I was hoping to use tuple unpacking to pass metric_data straight from > get_metrics through to create_point. > > However, in this case, metric_data only contains timestamp. I don't understand this. -- Steven From harvesting at makes.address.invalid Wed Sep 2 11:50:02 2015 From: harvesting at makes.address.invalid (Jussi Piitulainen) Date: Wed, 02 Sep 2015 18:50:02 +0300 Subject: for loop over function that returns a tuple? References: <09ff717a-8634-4fe7-84e1-f84ed4cf1f21@googlegroups.com> <55e70c80$0$1638$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Wed, 2 Sep 2015 09:49 pm, Victor Hooi wrote: > >> I have a function which is meant to return a tuple: >> >> def get_metrics(server_status_json, metrics_to_extract, line_number): >> >> return ((timestamp, "serverstatus", values, tags)) [- -] >> I am calling get_metric in a for loop like so: >> >> for metric_data in get_metrics(server_status_json, mmapv1_metrics, >> line_number): >> json_points.append(create_point(*metric_data)) [- -] >> I was hoping to use tuple unpacking to pass metric_data straight from >> get_metrics through to create_point. >> >> However, in this case, metric_data only contains timestamp. > > I don't understand this. Like so: for metric_data in (timestamp, "serverstatus", values, tags): foo(*metric_data) Because get_metrics returns a single tuple. If it's really essential to "loop" just once, perhaps wrap the one tuple in a list: for metric_data in [get_metrics(server_status_json, mmapv1_metrics, line_number)]: json_points.append(create_point(*metric_data)) From steve at pearwood.info Wed Sep 2 12:09:05 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 03 Sep 2015 02:09:05 +1000 Subject: for loop over function that returns a tuple? References: <09ff717a-8634-4fe7-84e1-f84ed4cf1f21@googlegroups.com> Message-ID: <55e71f21$0$1648$c3e8da3$5496439d@news.astraweb.com> On Wed, 2 Sep 2015 09:49 pm, Victor Hooi wrote: > I have a function which is meant to return a tuple: > > def get_metrics(server_status_json, metrics_to_extract, line_number): > > return ((timestamp, "serverstatus", values, tags)) > > I also have: > > def create_point(timestamp, metric_name, values, tags): > return { > "measurement": _MEASUREMENT_PREFIX + metric_name, > "tags": tags, > "time": timestamp, > "fields": values > } > > I am calling get_metric in a for loop like so: > > for metric_data in get_metrics(server_status_json, mmapv1_metrics, > line_number): > json_points.append(create_point(*metric_data)) Ah, now I see what's happening! Sorry for being so dim, I thought that get_metrics returned a list or sequence of tuples: [(timestamp, "serverstatus", values, tags), (timestamp, "serverstatus", values, tags), ... (timestamp, "serverstatus", values, tags)] and you were iterating over the list, so that each time you would get a tuple of four values: metric_data = (timestamp, "serverstatus", values, tags) which you can then pass to create_point: create_point(*metric_data) So you confused me by saying that metric_data held only the timestamp. But now I see that I was mistaken, and you are doing this: for metric_data in get_metrics( ... ): # returns a single tuple # first time through the loop, metric_data = timestamp; # second time through the loop, metric_data = "serverstatus" # third time through the loop, metric_data = values # final time through the loop, metric_data = tags Get rid of the loop, and write this: metric_data = get_metrics(server_status_json, mmapv1_metrics, line_number) json_points.append(create_point(*metric_data)) -- Steven From steve at pearwood.info Wed Sep 2 12:15:29 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 03 Sep 2015 02:15:29 +1000 Subject: Raymond Hettinger is now featured on ActiveState Message-ID: <55e720a1$0$1638$c3e8da3$5496439d@news.astraweb.com> I'm not sure how long this has been the case, but Raymond Hettinger is now featured on the ActiveState page with a link direct to his recipes. https://code.activestate.com/ Raymond has long been one of the most productive and popular recipe writers on ActiveState, with many of his recipes being among the most popular, most viewed, and most upvoted on the site. (Some of them have ended up in the standard library as well.) While the quality of recipes at ActiveState varies greatly, beginners and experts alike can learn a lot from Raymond's recipes. https://code.activestate.com/recipes/users/178123/ -- Steven From breamoreboy at yahoo.co.uk Wed Sep 2 12:40:55 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 2 Sep 2015 17:40:55 +0100 Subject: packing unpacking depends on order. In-Reply-To: <55E6C904.3020602@rece.vub.ac.be> References: <55E6C904.3020602@rece.vub.ac.be> Message-ID: On 02/09/2015 11:01, Antoon Pardon wrote: > >>>> a = [1, 2, 3, 4, 5] >>>> b = 1 >>>> b, a[b] = a[b], b >>>> a > [1, 2, 1, 4, 5] >>>> a = [1, 2, 3, 4, 5] >>>> b = 1 >>>> a[b], b = b, a[b] >>>> a > [1, 1, 3, 4, 5] > > I think I understand how it gets these results > but I'm not really happy with them. I think python > should give the second result in both cases. > You might find this interesting https://www.cyphar.com/blog/post/tuple-unpacking-oddness -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Wed Sep 2 12:44:44 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 2 Sep 2015 17:44:44 +0100 Subject: Using enumerate to get line-numbers with itertools grouper? In-Reply-To: <0a373caf-9022-41ca-8533-eb8ba2a1843a@googlegroups.com> References: <0a373caf-9022-41ca-8533-eb8ba2a1843a@googlegroups.com> Message-ID: On 02/09/2015 13:03, Victor Hooi wrote: How many times do people have to be asked before they stop top posting? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Wed Sep 2 13:26:43 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 2 Sep 2015 13:26:43 -0400 Subject: packing unpacking depends on order. In-Reply-To: <55e6eadf$0$1652$c3e8da3$5496439d@news.astraweb.com> References: <55e6eadf$0$1652$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/2/2015 8:26 AM, Steven D'Aprano wrote: > On Wed, 2 Sep 2015 08:01 pm, Antoon Pardon wrote: > >> >>>>> a = [1, 2, 3, 4, 5] >>>>> b = 1 >>>>> b, a[b] = a[b], b >>>>> a >> [1, 2, 1, 4, 5] > > Equivalent to: > > temp1 = a[b] # a[1] == 2 > temp2 = b # 1 > b = temp1 # b = 2 > a[b] = temp2 # a[2] = 1 > > > Or using a queue (FIFO) rather than temp variables: > > push a[b] > push b > b = pop > a[b] = pop > > > which seems sensible to me. The right hand side of the assignment is > evaluated left-to-right, and then the assignments are made, from > left-to-right. Which I believe matches the documented order. It does, and '7.2 Assignment statements' ends with this example: """ For instance, the following program prints [0, 2]: x = [0, 1] i = 0 i, x[i] = 1, 2 # i is updated, then x[i] is updated print(x) """ -- Terry Jan Reedy From srkunze at mail.de Wed Sep 2 13:26:49 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 02 Sep 2015 19:26:49 +0200 Subject: packing unpacking depends on order. In-Reply-To: References: <55E6C904.3020602@rece.vub.ac.be> Message-ID: <55E73159.4050508@mail.de> I agree as well. First evaluate the right side, then assign it to the left side at once. On 02.09.2015 12:22, Nick Sarbicki wrote: > That's interesting. I agree with you, I'd prefer the second result in > both cases. > > But makes sense as it evaluates left to right and seems to break up > the unpacking into separate statements. > > Could be useful if you want to hold the results of a generator in > sequence, can call the same function multiple times and unpack as above. > > On Wed, Sep 2, 2015 at 11:07 AM Antoon Pardon > > > wrote: > > > >>> a = [1, 2, 3, 4, 5] > >>> b = 1 > >>> b, a[b] = a[b], b > >>> a > [1, 2, 1, 4, 5] > >>> a = [1, 2, 3, 4, 5] > >>> b = 1 > >>> a[b], b = b, a[b] > >>> a > [1, 1, 3, 4, 5] > > I think I understand how it gets these results > but I'm not really happy with them. I think python > should give the second result in both cases. > > -- > Antoon Pardon > > -- > https://mail.python.org/mailman/listinfo/python-list > > -- > - Nick > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Sep 2 13:42:58 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 2 Sep 2015 13:42:58 -0400 Subject: packing unpacking depends on order. In-Reply-To: <55E6C904.3020602@rece.vub.ac.be> References: <55E6C904.3020602@rece.vub.ac.be> Message-ID: On 9/2/2015 6:01 AM, Antoon Pardon wrote: > >>>> a = [1, 2, 3, 4, 5] >>>> b = 1 >>>> b, a[b] = a[b], b >>>> a > [1, 2, 1, 4, 5] >>>> a = [1, 2, 3, 4, 5] >>>> b = 1 >>>> a[b], b = b, a[b] >>>> a > [1, 1, 3, 4, 5] > > I think I understand how it gets these results > but I'm not really happy with them. I think python > should give the second result in both cases. I do not want the choice taken away from me. -- Terry Jan Reedy From tjreedy at udel.edu Wed Sep 2 13:48:31 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 2 Sep 2015 13:48:31 -0400 Subject: Using enumerate to get line-numbers with itertools grouper? In-Reply-To: References: Message-ID: On 9/2/2015 6:04 AM, Victor Hooi wrote: > I'm using grouper() to iterate over a textfile in groups of lines: > > def grouper(iterable, n, fillvalue=None): > "Collect data into fixed-length chunks or blocks" > # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx > args = [iter(iterable)] * n > return zip_longest(fillvalue=fillvalue, *args) > > However, I'd also like to know the line-number that I'm up to, for printing out in informational or error messages. > > Is there a way to use enumerate with grouper to achieve this? Without a runnable test example, it is hard to be sure what you want. However, I believe replacing 'iter(iterable)' with 'enumerate(iterable, 1)', and taking into account that you will get (line_number, line) tuples instead of lines, will do what you want. -- Terry Jan Reedy From steve at pearwood.info Wed Sep 2 14:02:43 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 03 Sep 2015 04:02:43 +1000 Subject: Atomic file save -- code review and comments requested Message-ID: <55e739c3$0$1670$c3e8da3$5496439d@news.astraweb.com> Howdy, I have a utility function for performing atomic file saves, and I'd like to ask for a code review and comments. I have published this on ActiveState: https://code.activestate.com/recipes/579097-safely-and-atomically-write-to-a-file/ under an MIT licence. You should read the version there, I discuss the use-case for the function and include an extensive doc string. Feel free to comment either here or on the ActiveState site. Here is the function, minus the docstring (for brevity): import contextlib import os import stat import tempfile @contextlib.contextmanager def atomic_write(filename, text=True, keep=True, owner=None, group=None, perms=None, suffix='.bak', prefix='tmp'): t = (uid, gid, mod) = (owner, group, perms) if any(x is None for x in t): info = os.stat(filename) if uid is None: uid = info.st_uid if gid is None: gid = info.st_gid if mod is None: mod = stat.S_IMODE(info.st_mode) path = os.path.dirname(filename) fd, tmp = tempfile.mkstemp( suffix=suffix, prefix=prefix, dir=path, text=text) try: with os.fdopen(fd, 'w' if text else 'wb') as f: yield f os.rename(tmp, filename) tmp = None os.chown(filename, uid, gid) os.chmod(filename, mod) finally: if (tmp is not None) and (not keep): # Silently delete the temporary file. Ignore any errors. try: os.unlink(tmp) except: pass Usage is: with atomic_write("mydata.txt") as f: f.write("some data") # if an error occurs in here, mydata.txt is preserved # if no error occurs and the with-block exits cleanly, # mydata.txt is atomically overwritten with the new contents. The function is written for Python 2.6, but should work on 2.7 as well. I'm looking for a review of the code, and any general comments. In particular, have I missed any ways that the function may fail and lose data? One question comes to mind -- should I perform a flush and/or sync of the file before the rename? Thanks in advance for all constructive comments. -- Steven From ian.g.kelly at gmail.com Wed Sep 2 14:06:32 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 2 Sep 2015 12:06:32 -0600 Subject: packing unpacking depends on order. In-Reply-To: References: <55E6C904.3020602@rece.vub.ac.be> Message-ID: On Wed, Sep 2, 2015 at 11:42 AM, Terry Reedy wrote: > On 9/2/2015 6:01 AM, Antoon Pardon wrote: >> >> >>>>> a = [1, 2, 3, 4, 5] >>>>> b = 1 >>>>> b, a[b] = a[b], b >>>>> a >> >> [1, 2, 1, 4, 5] >>>>> >>>>> a = [1, 2, 3, 4, 5] >>>>> b = 1 >>>>> a[b], b = b, a[b] >>>>> a >> >> [1, 1, 3, 4, 5] >> >> I think I understand how it gets these results >> but I'm not really happy with them. I think python >> should give the second result in both cases. > > > I do not want the choice taken away from me. I do. I think the former behavior is surprising, and that relying on it would result in confusing, hard-to-read code. If you really want the former, you can easily reproduce it with: temp = a[b] b, a[temp] = temp, b From jorge.conrado at cptec.inpe.br Wed Sep 2 14:18:43 2015 From: jorge.conrado at cptec.inpe.br (jorge.conrado at cptec.inpe.br) Date: Wed, 02 Sep 2015 15:18:43 -0300 Subject: error Message-ID: <3ffa1cef71ad34dd0fece7e983ecb987@cptec.inpe.br> Hi, I have a Python version: Python 2.7.8 I'm runing it on: Fedora release 21 Yesterday I a sent a question: I'm starting in the Python scripts. I run this script: import numpy as np import netCDF4 f = netCDF4.Dataset('uwnd.mon.ltm.nc','r') f.variables and I had the message: netcdf4.py Traceback (most recent call last): File "", line 1, in NameError: name 'netcdf4' is not defined I had two answers to my question. But I could not understand them. I don't have expericence with Python. So I downloaded from the Web a code to calcluate the dew point temperature: import sys import numpy as np # approximation valid for # 0 degC < T < 60 degC # 1% < RH < 100% # 0 degC < Td < 50 degC # constants a = 17.271 b = 237.7 # degC # sys.argv[0] is program name T=float(sys.argv[1]) RH=float(sys.argv[2]) def dewpoint_approximation(T,RH): Td = (b * gamma(T,RH)) / (a - gamma(T,RH)) return Td def gamma(T,RH): g = (a * T / (b + T)) + np.log(RH/100.0) return g Td = dewpoint_approximation(T,RH) print 'T, RH',T,RH print 'Td=',Td Then I run it and I had the message: p2.py Traceback (most recent call last): File "", line 1, in NameError: name 'p2' is not defined Like the same error that I had for my first run. Please, someone can help me. I have a commercial software and I would like to use Python. In advance. Thanks, Conrado From lac at openend.se Wed Sep 2 14:42:11 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 02 Sep 2015 20:42:11 +0200 Subject: error In-Reply-To: <3ffa1cef71ad34dd0fece7e983ecb987@cptec.inpe.br> References: <3ffa1cef71ad34dd0fece7e983ecb987@cptec.inpe.br> Message-ID: <201509021842.t82IgBDW006869@fido.openend.se> >import numpy as np > >import netCDF4 > >f = netCDF4.Dataset('uwnd.mon.ltm.nc','r') > > >f.variables > > >and I had the message: > > >netcdf4.py >Traceback (most recent call last): > File "", line 1, in >NameError: name 'netcdf4' is not defined You have a file called netcdf4.py It contains the line: import netCDF4 python comes along, reads "import netCDF4" and goes looking for something named netCDF4 or netCdf4 or netcdf4 or NETDCF4 or NeTcDf4 -- the rules of your file system say that filenames are case-insensitive ... so all the above are equivalent. The first place it looks is your home directory. Then it looks in your PYTHONPATH. Then it looks in the system modules you nicely loaded for it. Unfortunately for you, it finds the file netcdf4.py in your home directory and thinks that is the one you wanted to import. BANG. Solution -- stop naming your python files as lower-cased versions of things you want to import. Renaming it to mynetcdf4.py should work fine, for instance. Laura From nick.a.sarbicki at gmail.com Wed Sep 2 14:44:04 2015 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Wed, 02 Sep 2015 18:44:04 +0000 Subject: error In-Reply-To: <3ffa1cef71ad34dd0fece7e983ecb987@cptec.inpe.br> References: <3ffa1cef71ad34dd0fece7e983ecb987@cptec.inpe.br> Message-ID: Where are you running the code from? The interactive prompt? (E.g. idle, or after you type "python" at the terminal) or from the terminal? (as in by typing "python p2.py" at the terminal). It looks like you're trying to load a file while in the interactive prompt which won't work that way (it will work if you type "import p2"). When you should be using "python p2.py" at the terminal. - Nick On Wed, 2 Sep 2015 19:20 wrote: > Hi, > > > I have a Python version: Python 2.7.8 > > I'm runing it on: Fedora release 21 > > > Yesterday I a sent a question: > > > I'm starting in the Python scripts. I run this script: > > > import numpy as np > > import netCDF4 > > f = netCDF4.Dataset('uwnd.mon.ltm.nc','r') > > > f.variables > > > and I had the message: > > > netcdf4.py > Traceback (most recent call last): > File "", line 1, in > NameError: name 'netcdf4' is not defined > > > I had two answers to my question. But I could not understand them. I > don't have expericence with Python. So I downloaded from the Web a code > to calcluate the dew point temperature: > > > import sys > import numpy as np > > # approximation valid for > # 0 degC < T < 60 degC > # 1% < RH < 100% > # 0 degC < Td < 50 degC > > # constants > a = 17.271 > b = 237.7 # degC > > # sys.argv[0] is program name > T=float(sys.argv[1]) > RH=float(sys.argv[2]) > > > def dewpoint_approximation(T,RH): > > Td = (b * gamma(T,RH)) / (a - gamma(T,RH)) > > return Td > > > def gamma(T,RH): > > g = (a * T / (b + T)) + np.log(RH/100.0) > > return g > > > Td = dewpoint_approximation(T,RH) > print 'T, RH',T,RH > print 'Td=',Td > > > Then I run it and I had the message: > > p2.py > > > Traceback (most recent call last): > File "", line 1, in > NameError: name 'p2' is not defined > > > Like the same error that I had for my first run. > > Please, someone can help me. I have a commercial software and I would > like to use Python. > > In advance. Thanks, > > Conrado > > -- > https://mail.python.org/mailman/listinfo/python-list > -- - Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From tdev at freenet.de Wed Sep 2 14:47:44 2015 From: tdev at freenet.de (tdev at freenet.de) Date: Wed, 2 Sep 2015 11:47:44 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: References: Message-ID: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> I agree with Skybuck Flying. I am aware if a var is a module function var or a module global var. If I want read or write a global var. Using the keyword global inside each(!) function only to mark the global var writeable in each of the functions is really an over-regulation and very annoying from my point of view. Especially cause a module is a singleton. And globals are only module aware vars. Even Java (type-safe language) need not such things for its static or member vars. I have disliked this already in PHP where one has to do exact the same thing as in Python (and hoped Python does it better, but not). And using an import here is no solution, cause this is something which relates only to the scope and state of a module itself. I therefore would like to see a PEP which allows also writing global module vars inside module functions without the need for explicit setting the keyword "global" in more or less each(!) module function as the first line of code. I hope a lot can/will agree and a new PEP will arise to give this small responsibility back to the developer. Thanks. From davros at bellaliant.net Wed Sep 2 14:50:36 2015 From: davros at bellaliant.net (John McKenzie) Date: Wed, 02 Sep 2015 18:50:36 GMT Subject: RPI.GPIO Help References: Message-ID: <0yHFx.3758$_H1.2845@fx23.iad> Hakugin: Thanks for the correction. Someone elsewhere showed me example code that was very close to yours, with that being the main difference. His gave an error message that red_button was undefined so I moved the code block below the callbacks. After that it ran without producing errors but it was unresponsive. Will try your updated version tomorrow and will keep fiddling with his. Thank you all for warning me about debouncing. The RPi.GPIO library has built in debouncing. You can even adjust the timing of it. Turns out I got one thing right. Someone who knows better than I explained that GPIO.Cleanup() does go at the bottom and outside the def exit_handler() code block like I had it originally. Johannes: Thanks for sharing that. I will take a look at it when I have more time. Must head to the hospital for my treatment in a few minutes. >Are you still calling GPIO.add_event_detect in a while loop? MRAB, apparently yes. Hakugin noticed and update his example code. From oscar.j.benjamin at gmail.com Wed Sep 2 15:12:45 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 02 Sep 2015 19:12:45 +0000 Subject: Atomic file save -- code review and comments requested In-Reply-To: <55e739c3$0$1670$c3e8da3$5496439d@news.astraweb.com> References: <55e739c3$0$1670$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 2 Sep 2015 19:06 Steven D'Aprano wrote: Howdy, I have a utility function for performing atomic file saves, and I'd like to ask for a code review and comments. I have published this on ActiveState: https://code.activestate.com/recipes/579097-safely-and-atomically-write-to-a-file/ under an MIT licence. You should read the version there, I discuss the use-case for the function and include an extensive doc string. Feel free to comment either here or on the ActiveState site. Here is the function, minus the docstring (for brevity): import contextlib import os import stat import tempfile @contextlib.contextmanager def atomic_write(filename, text=True, keep=True, owner=None, group=None, perms=None, suffix='.bak', prefix='tmp'): t = (uid, gid, mod) = (owner, group, perms) if any(x is None for x in t): info = os.stat(filename) if uid is None: uid = info.st_uid if gid is None: gid = info.st_gid if mod is None: mod = stat.S_IMODE(info.st_mode) path = os.path.dirname(filename) fd, tmp = tempfile.mkstemp( suffix=suffix, prefix=prefix, dir=path, text=text) try: with os.fdopen(fd, 'w' if text else 'wb') as f: yield f os.rename(tmp, filename) tmp = None os.chown(filename, uid, gid) os.chmod(filename, mod) finally: if (tmp is not None) and (not keep): # Silently delete the temporary file. Ignore any errors. try: os.unlink(tmp) except: pass Usage is: with atomic_write("mydata.txt") as f: f.write("some data") # if an error occurs in here, mydata.txt is preserved # if no error occurs and the with-block exits cleanly, # mydata.txt is atomically overwritten with the new contents. The function is written for Python 2.6, but should work on 2.7 as well. I'm looking for a review of the code, and any general comments. In particular, have I missed any ways that the function may fail and lose data? One question comes to mind -- should I perform a flush and/or sync of the file before the rename? Your with statement will close the file so that shouldn't be necessary. Not an expert on these things but maybe it makes sense to call chown/chmod before the rename so that a failure can't result in the replaced file's permissions being changed. -- Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From stehlampen at arcor.de Wed Sep 2 15:30:30 2015 From: stehlampen at arcor.de (stehlampen at arcor.de) Date: Wed, 2 Sep 2015 21:30:30 +0200 (CEST) Subject: Location of an Error Message Message-ID: <1331973293.1064548.1441222230547.JavaMail.ngmail@webmail12.arcor-online.net> Where are the error messages stored? E. g., in which (source code) file is the message "NameError: name 'sdfe' is not defined" stored (except for variable arguments like "sdfe")? I do know that I can throw exceptions for myself, but this question came to my mind in thinking about translating the error messages to improve Python's learning curve for newbies. Additionally, I would be grateful if you would give to me the file name (e. g. in hg.python.org) which is the Interpreter's first piece of source code which deals with the error strings. Many thanks in advance! From tdev at freenet.de Wed Sep 2 15:32:33 2015 From: tdev at freenet.de (tdev at freenet.de) Date: Wed, 2 Sep 2015 12:32:33 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> Message-ID: <8a9529b6-5ba8-4750-992b-5bcf5e93f4ac@googlegroups.com> And to clarify: I have not spoken about sharing constants global (spanning over modules), where the solution provided here using imports is the solution. I have spoken from module vars which are named or are "globals" and its read/write access constraints inside module functions. So even the naming "globals" is something what I dislike, cause it is about module scope. With all other I can agree with Skybuck Flying too: "There is so far nothing else annoying!" (Maybe a missing switch statement). Thanks. From emile at fenx.com Wed Sep 2 15:34:23 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 2 Sep 2015 12:34:23 -0700 Subject: Python handles globals badly. In-Reply-To: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> Message-ID: On 9/2/2015 11:47 AM, tdev at freenet.de wrote: > I therefore would like to see a PEP which allows also writing > global module vars inside module functions without the need > for explicit setting the keyword "global" in more or less each(!) > module function as the first line of code. If you're feeling like you need to add global statements to a lot of functions to enable variable sharing/access, it may be codesmell indicating it's time to make a class of things. Emile From ian.g.kelly at gmail.com Wed Sep 2 15:38:01 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 2 Sep 2015 13:38:01 -0600 Subject: Python handles globals badly. In-Reply-To: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> Message-ID: On Wed, Sep 2, 2015 at 12:47 PM, wrote: > Using the keyword global inside each(!) function only > to mark the global var writeable in each of the functions > is really an over-regulation and very annoying from my point of view. To me, marking a variable as global in a large number of functions is a code smell that indicates that you're probably overusing globals. Lua is an example of a language that takes the opposite approach: in Lua, every variable is global unless you explicitly mark it as local. Lua is a fine language overall, but that is one of my pet peeves with it as it is all too easy to fall into the trap of neglecting to mark your local variables, and then you end up with too many global variables and a disaster of a code base. > Especially cause a module is a singleton. > And globals are only module aware vars. > Even Java (type-safe language) need not such things for its static or member vars. Because Java has static typing. It can determine that a variable is static simply by observing that the variable is declared as such in the class and isn't declared in the function. Would you prefer to have to declare all your local variables as "local" just so that you don't have to explicitly declare the (few, I hope) global ones? From srkunze at mail.de Wed Sep 2 16:08:17 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 02 Sep 2015 22:08:17 +0200 Subject: Python handles globals badly. In-Reply-To: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> Message-ID: <55E75731.9000609@mail.de> On 02.09.2015 20:47, tdev at freenet.de wrote: > I agree with Skybuck Flying. > I am aware if a var is a module function var or a module global var. > If I want read or write a global var. > > Using the keyword global inside each(!) function only > to mark the global var writeable in each of the functions > is really an over-regulation and very annoying from my point of view. It reflects the collective experience of programmers, computer scientists, and so forth of the last decades. Globals are evil. Stay away from them. Best, Sven From amka1791 at gmail.com Wed Sep 2 16:12:55 2015 From: amka1791 at gmail.com (amka1791 at gmail.com) Date: Wed, 2 Sep 2015 13:12:55 -0700 (PDT) Subject: dxfwrite spline problem Message-ID: Hi everyone, I need to do splines in a dxf file with a script, so I use python dxfwrite : It seems that it is the best thing that exists... But impossible to be sure. But I have a problem with : when I run this sample script : --------------------------- #!/usr/bin/python from dxfwrite import DXFEngine as dxf spline1 = [(0.0, 0.0), (1.0, 0.0), (2.0, -1.0)] dwg = dxf.drawing('spline.dxf') dwg.add(dxf.spline(spline1)) dwg.save() --------------------------- I have this output : amel at debian:~/job/RR/pl/06$ ./spline.py Traceback (most recent call last): File "./spline.py", line 9, in dwg.save() File "/usr/local/lib/python2.7/dist-packages/dxfwrite/drawing.py", line 131, in save self.save_to_fileobj(fileobj) File "/usr/local/lib/python2.7/dist-packages/dxfwrite/drawing.py", line 137, in save_to_fileobj writetags(fileobj, self.__dxftags__(), self.ENCODING) File "/usr/local/lib/python2.7/dist-packages/dxfwrite/base.py", line 53, in writetags for dxftag in iterdxftags(dxfobj): File "/usr/local/lib/python2.7/dist-packages/dxfwrite/base.py", line 31, in iterdxftags for subtag in iterdxftags(tag): File "/usr/local/lib/python2.7/dist-packages/dxfwrite/base.py", line 31, in iterdxftags for subtag in iterdxftags(tag): File "/usr/local/lib/python2.7/dist-packages/dxfwrite/base.py", line 31, in iterdxftags for subtag in iterdxftags(tag): File "/usr/local/lib/python2.7/dist-packages/dxfwrite/base.py", line 31, in iterdxftags for subtag in iterdxftags(tag): File "/usr/local/lib/python2.7/dist-packages/dxfwrite/base.py", line 30, in iterdxftags for tag in dxfobj.__dxftags__(): File "/usr/local/lib/python2.7/dist-packages/dxfwrite/curves.py", line 157, in __dxftags__ linetype = self.linetype) File "/usr/local/lib/python2.7/dist-packages/dxfwrite/entities.py", line 593, in __init__ self.add_vertices(points) File "/usr/local/lib/python2.7/dist-packages/dxfwrite/entities.py", line 614, in add_vertices for point in points: File "/usr/local/lib/python2.7/dist-packages/dxfwrite/algebra/cspline.py", line 98, in _cubic_spline a = get_a(k, m, delta_t) File "/usr/local/lib/python2.7/dist-packages/dxfwrite/algebra/cspline.py", line 76, in get_a a[n-1] = (h * k[n-2] + k[n-1]) / m[n-1] ZeroDivisionError: float division by zero amel at debian:~/job/RR/pl/06$ --------------------------- Can somebody please help me ? Thanks, best regards, Amka From srkunze at mail.de Wed Sep 2 16:14:27 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 02 Sep 2015 22:14:27 +0200 Subject: packing unpacking depends on order. In-Reply-To: References: <55E6C904.3020602@rece.vub.ac.be> Message-ID: <55E758A3.30602@mail.de> On 02.09.2015 19:42, Terry Reedy wrote: > On 9/2/2015 6:01 AM, Antoon Pardon wrote: >> >>>>> a = [1, 2, 3, 4, 5] >>>>> b = 1 >>>>> b, a[b] = a[b], b >>>>> a >> [1, 2, 1, 4, 5] >>>>> a = [1, 2, 3, 4, 5] >>>>> b = 1 >>>>> a[b], b = b, a[b] >>>>> a >> [1, 1, 3, 4, 5] >> >> I think I understand how it gets these results >> but I'm not really happy with them. I think python >> should give the second result in both cases. > > I do not want the choice taken away from me. > I do as readability and maintainability comes first for me. Btw. you would still be able to perform your choice but more explicitly. However, I fear this would be a very hard break of backwards compatibility. :/ So, what I take away from this thread right now is that one should avoid this type of construction whenever possible as long as Python handles it that way. Best, Sven From python at mrabarnett.plus.com Wed Sep 2 16:22:08 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 2 Sep 2015 21:22:08 +0100 Subject: Python handles globals badly. In-Reply-To: <55E75731.9000609@mail.de> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55E75731.9000609@mail.de> Message-ID: <55E75A70.1020607@mrabarnett.plus.com> On 2015-09-02 21:08, Sven R. Kunze wrote: > On 02.09.2015 20:47, tdev at freenet.de wrote: >> I agree with Skybuck Flying. >> I am aware if a var is a module function var or a module global var. >> If I want read or write a global var. >> >> Using the keyword global inside each(!) function only >> to mark the global var writeable in each of the functions >> is really an over-regulation and very annoying from my point of view. > > It reflects the collective experience of programmers, computer > scientists, and so forth of the last decades. > > > Globals are evil. Stay away from them. > I think it's like that sometimes-misquoted saying "money is the root of all evil". It's "the love of money is the root of all evil". Similarly, it's the love (or misuse or overuse) of globals that's evil, IMHO. From breamoreboy at yahoo.co.uk Wed Sep 2 17:19:15 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 2 Sep 2015 22:19:15 +0100 Subject: Python handles globals badly. In-Reply-To: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> Message-ID: On 02/09/2015 19:47, tdev at freenet.de wrote: > I agree with Skybuck Flying. First problem. > Using the keyword global inside each(!) function only > to mark the global var writeable in each of the functions > is really an over-regulation and very annoying from my point of view. > Second problem. Any chance of shooting yourself *BEFORE* your code escapes from the laboratory? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ian.g.kelly at gmail.com Wed Sep 2 17:23:46 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 2 Sep 2015 15:23:46 -0600 Subject: Location of an Error Message In-Reply-To: <1331973293.1064548.1441222230547.JavaMail.ngmail@webmail12.arcor-online.net> References: <1331973293.1064548.1441222230547.JavaMail.ngmail@webmail12.arcor-online.net> Message-ID: On Wed, Sep 2, 2015 at 1:30 PM, wrote: > Where are the error messages stored? E. g., in which (source code) file is the message "NameError: name 'sdfe' is not defined" stored (except for variable arguments like "sdfe")? I do know that I can throw exceptions for myself, but this question came to my mind in thinking about translating the error messages to improve Python's learning curve for newbies. Grepping the source turns up this: https://hg.python.org/cpython/file/tip/Python/ceval.c#l150 > Additionally, I would be grateful if you would give to me the file name (e. g. in hg.python.org) which is the Interpreter's first piece of source code which deals with the error strings. What do you mean by "first"? I don't think the error messages are centralized anywhere. From rosuav at gmail.com Wed Sep 2 18:10:28 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Sep 2015 08:10:28 +1000 Subject: Reading \n unescaped from a file In-Reply-To: <55E65909.2080507@medimorphosis.com.au> References: <55E65909.2080507@medimorphosis.com.au> Message-ID: On Wed, Sep 2, 2015 at 12:03 PM, Rob Hills wrote: > My mapping file contents look like this: > > \r = \\n > ??? = " Oh, lovely. Code page 1252 when you're expecting UTF-8. Sadly, you're likely to have to cope with a whole pile of other mojibake if that happens :( You have my sympathy. > < = < > > = > > ' = ' > F = F > o = o > f = f > e = e > O = O > > This all works "as advertised" except for the '\r' => '\\n' replacement. > Debugging the code, I see that my '\r' character is "escaped" to '\\r' and > the '\\n' to '\\\\n' when they are read in from the file. Technically, what's happening is that your "\r" is literally a backslash followed by the letter r; the transformation of backslash sequences into single characters is part of Python source code parsing. (Incidentally, why do you want to change a carriage return into backslash-n? Seems odd.) Probably the easiest solution would be a simple and naive replace(), looking for some very specific strings and ignoring everything else. Easy to do, but potentially confusing down the track if someone tries something fancy :) line = line.split('#')[:1][0].strip() # trim any trailing comments line = line.replace(r"\r", "\r") # repeat this for as many backslash escapes as you want to handle Be aware that this, while simple, is NOT capable of handling escaped backslashes. In Python, "\\r" comes out the same as r"\r", but with this parser, it would come out the same as "\\\r". But it might be sufficient for you. ChrisA From ahlusar.ahluwalia at gmail.com Wed Sep 2 18:15:32 2015 From: ahlusar.ahluwalia at gmail.com (kbtyo) Date: Wed, 2 Sep 2015 15:15:32 -0700 (PDT) Subject: How to decipher error "Nonetype" Error Message-ID: <6c0af13a-a07d-4c29-b1fd-dd53768e6408@googlegroups.com> I am currently using Jupyter and Pythopn 3.4. I am currently using the following script to parse and convert XML data structures, nested in a CSV - formatted file, convert into a dictionary and then append write it back into the same CSV. I am using the following (I added comments to explain the thought process): https://gist.github.com/ahlusar1989/de2381c1fb77e96ae601 However, when I hit line 40 (referencing the gist), I receive the following error: --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in () 23 # to ensure that the field names in the XML don't match (and override) the 24 # field names already in the dictionary ---> 25 row.update(xml_data) 26 # ensure that the headers have all the right fields 27 headers.update(row.keys()) TypeError: 'NoneType' object is not iterable I can only infer I am passing or converting an empty key or empty row. I welcome feedback. From tdev at freenet.de Wed Sep 2 18:25:46 2015 From: tdev at freenet.de (tdev at freenet.de) Date: Wed, 2 Sep 2015 15:25:46 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: References: Message-ID: <253e3584-1d4d-4e6f-b42f-2cdbfa4ad785@googlegroups.com> Reflecting the answers I want to add following: Considering class usage is something I thought about but is not the way I want use Python so far. If so, I could stay on oo-scripting languages as well. It is the good idea of Python about modules which are singletons and therefore have already its state (so in some way they are already somehow like classes - except the bad annoying thing with the "global" statement). That said, it is not an overusing of globals cause globals are module vars only. Or have you never written singletons or other classes in e.g Java, C++ with lots of static and class members and methods using this members. With globals in Python are not meant traditional globals (app spanning vars) as already said. Globals in Python are like class-members and statics in OO-languages. Globals are module scope! And therefore it is not the devil or evil problem or code desaster problem or LUA's opposite approach. (local/nonlocal statements I think are needed cause of lambda functionality and is not what I try to discuss here) Hopefully this clarifies a bit more my point of view and you can now agree that using "global" is not only over-regulated but also ugly code. At least the developer should be free to use the "global"-statement (if one really need this?) or not (myself, and hopefully a lot other). Therefore still hoping a new PEP will arise. @Mark Lawrence This response I have not checked. Can you provide arguments or clarify your statement? From rosuav at gmail.com Wed Sep 2 18:28:45 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Sep 2015 08:28:45 +1000 Subject: How to decipher error "Nonetype" Error In-Reply-To: <6c0af13a-a07d-4c29-b1fd-dd53768e6408@googlegroups.com> References: <6c0af13a-a07d-4c29-b1fd-dd53768e6408@googlegroups.com> Message-ID: On Thu, Sep 3, 2015 at 8:15 AM, kbtyo wrote: > However, when I hit line 40 (referencing the gist), I receive the following error: > > --------------------------------------------------------------------------- > TypeError Traceback (most recent call last) > in () > 23 # to ensure that the field names in the XML don't match (and override) the > 24 # field names already in the dictionary > ---> 25 row.update(xml_data) > 26 # ensure that the headers have all the right fields > 27 headers.update(row.keys()) > > TypeError: 'NoneType' object is not iterable > > I can only infer I am passing or converting an empty key or empty row. I welcome feedback. NoneType is the type of the singleton object None. So what this means is that xml_data is None at this point. In your just_xml_data() function, which is what provides xml_data at that point, there are two code branches that matter here: one is the "else: return xml", and the other is the implicit "return None" at the end of the function. If you catch an exception, you print out a message and then allow the function to return None. Is that really your intention? It seems an odd way to do things, but if that is what you want, you'll need to cope with the None return in the main routine. BTW, your gist has a couple of non-comments on lines 48 and 49. If you can make sure that your code is functionally correct, it'll be easier for us to test. (Even more so if you can include a sample input file in the gist, though preferably not a huge one.) At the moment, I'm just eyeballing the code itself, but if someone can actually run the script and reproduce the exact error you're seeing, it makes debugging that much easier. All the best! ChrisA From gordon at panix.com Wed Sep 2 18:30:05 2015 From: gordon at panix.com (John Gordon) Date: Wed, 2 Sep 2015 22:30:05 +0000 (UTC) Subject: How to decipher error "Nonetype" Error References: <6c0af13a-a07d-4c29-b1fd-dd53768e6408@googlegroups.com> Message-ID: In <6c0af13a-a07d-4c29-b1fd-dd53768e6408 at googlegroups.com> kbtyo writes: > https://gist.github.com/ahlusar1989/de2381c1fb77e96ae601 Are you sure this is the actual code you're running? Lines 48 and 49 are clearly meant to be comments, but they do not begin with a hash sign. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From python at mrabarnett.plus.com Wed Sep 2 18:31:35 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 2 Sep 2015 23:31:35 +0100 Subject: Reading \n unescaped from a file In-Reply-To: <55E65909.2080507@medimorphosis.com.au> References: <55E65909.2080507@medimorphosis.com.au> Message-ID: <55E778C7.7050802@mrabarnett.plus.com> On 2015-09-02 03:03, Rob Hills wrote: > Hi, > > I am developing code (Python 3.4) that transforms text data from one > format to another. > > As part of the process, I had a set of hard-coded str.replace(...) > functions that I used to clean up the incoming text into the desired > output format, something like this: > > dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds > dataIn = dataIn.replace('<','<') # Tidy up < character > dataIn = dataIn.replace('>','>') # Tidy up < character > dataIn = dataIn.replace('o','o') # No idea why but lots of these: convert to 'o' character > dataIn = dataIn.replace('f','f') # .. and these: convert to 'f' character > dataIn = dataIn.replace('e','e') # .. 'e' > dataIn = dataIn.replace('O','O') # .. 'O' > The problem with this approach is that the order of the replacements matters. For example, changing '<' to '<' and then '&' to '&' can give a different result to changing '&' to '&' and then '<' to '<'. If you started with the string '&lt;', then the first order would go '&lt;' => '&lt;' => '<', whereas the second order would go '&lt;' => '<' => '<'. > These statements transform my data correctly, but the list of statements > grows as I test the data so I thought it made sense to store the > replacement mappings in a file, read them into a dict and loop through > that to do the cleaning up, like this: > > with open(fileName, 'r+t', encoding='utf-8') as mapFile: > for line in mapFile: > line = line.strip() > try: > if (line) and not line.startswith('#'): > line = line.split('#')[:1][0].strip() # trim any trailing comments > name, value = line.split('=') > name = name.strip() > self.filterMap[name]=value.strip() > except: > self.logger.error('exception occurred parsing line [{0}] in file [{1}]'.format(line, fileName)) > raise > > Elsewhere, I use the following code to do the actual cleaning up: > > def filter(self, dataIn): > if dataIn: > for token, replacement in self.filterMap.items(): > dataIn = dataIn.replace(token, replacement) > return dataIn > > > My mapping file contents look like this: > > \r = \\n > ??? = " > < = < > > = > > ' = ' > F = F > o = o > f = f > e = e > O = O > > This all works "as advertised" */except/* for the '\r' => '\\n' > replacement. Debugging the code, I see that my '\r' character is > "escaped" to '\\r' and the '\\n' to '\\\\n' when they are read in from > the file. > > I've been googling hard and reading the Python docs, trying to get my > head around character encoding, but I just can't figure out how to get > these bits of code to do what I want. > > It seems to me that I need to either: > > * change the way I represent '\r' and '\\n' in my mapping file; or > * transform them somehow when I read them in > > However, I haven't figured out how to do either of these. > Try ast.literal_eval, although you'd need to make it look like a string literal first: >>> import ast >>> line = r'\r = \\n' >>> print(line) \r = \\n >>> old, sep, new = line.partition(' = ') >>> print(old) \r >>> print(new) \\n >>> ast.literal_eval('"%s"' % old) '\r' >>> ast.literal_eval('"%s"' % new) '\\n' >>> I wouldn't put the &#...; forms into the mappings file (except for the ' one) because they can all be recognised and done in code ('F' is chr(int('070')), for example). From p.h.phan2006 at gmail.com Wed Sep 2 18:31:55 2015 From: p.h.phan2006 at gmail.com (Phuong Phan) Date: Wed, 02 Sep 2015 22:31:55 +0000 Subject: Hello Message-ID: Hi Python community, I am new to Python and currently taking one online course of computer science and programming using Python. I really like Python because it is simple and clarity but powerful to me. I just joint Python mailing list and i hope to enjoy Python programming discussion with you all. Thank you, phuong phan -------------- next part -------------- An HTML attachment was scrubbed... URL: From ahlusar.ahluwalia at gmail.com Wed Sep 2 18:50:20 2015 From: ahlusar.ahluwalia at gmail.com (kbtyo) Date: Wed, 2 Sep 2015 15:50:20 -0700 (PDT) Subject: How to decipher error "Nonetype" Error In-Reply-To: References: <6c0af13a-a07d-4c29-b1fd-dd53768e6408@googlegroups.com> Message-ID: <30132531-1695-43e8-88ff-d94ca0da9168@googlegroups.com> On Wednesday, September 2, 2015 at 6:29:05 PM UTC-4, Chris Angelico wrote: > On Thu, Sep 3, 2015 at 8:15 AM, kbtyo wrote: > > However, when I hit line 40 (referencing the gist), I receive the following error: > > > > --------------------------------------------------------------------------- > > TypeError Traceback (most recent call last) > > in () > > 23 # to ensure that the field names in the XML don't match (and override) the > > 24 # field names already in the dictionary > > ---> 25 row.update(xml_data) > > 26 # ensure that the headers have all the right fields > > 27 headers.update(row.keys()) > > > > TypeError: 'NoneType' object is not iterable > > > > I can only infer I am passing or converting an empty key or empty row. I welcome feedback. > > NoneType is the type of the singleton object None. So what this means > is that xml_data is None at this point. > > In your just_xml_data() function, which is what provides xml_data at > that point, there are two code branches that matter here: one is the > "else: return xml", and the other is the implicit "return None" at the > end of the function. If you catch an exception, you print out a > message and then allow the function to return None. Is that really > your intention? It seems an odd way to do things, but if that is what > you want, you'll need to cope with the None return in the main > routine. > > BTW, your gist has a couple of non-comments on lines 48 and 49. If you > can make sure that your code is functionally correct, it'll be easier > for us to test. (Even more so if you can include a sample input file > in the gist, though preferably not a huge one.) At the moment, I'm > just eyeballing the code itself, but if someone can actually run the > script and reproduce the exact error you're seeing, it makes debugging > that much easier. > > All the best! > > ChrisA Hi Chris: I made changes to the gist: https://gist.github.com/ahlusar1989/de2381c1fb77e96ae601 Ahhhhhh!!!! Thanks for catching that. No, I want to skip over the Exception and return the xml_data in the try block. I didn't realize that was the behaviour. I don't want to break the iterative loop. Any advice on how to absolve this? Thanks. From __peter__ at web.de Wed Sep 2 18:54:12 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 03 Sep 2015 00:54:12 +0200 Subject: Reading \n unescaped from a file References: <55E65909.2080507@medimorphosis.com.au> <55E778C7.7050802@mrabarnett.plus.com> Message-ID: MRAB wrote: > On 2015-09-02 03:03, Rob Hills wrote: >> Hi, >> >> I am developing code (Python 3.4) that transforms text data from one >> format to another. >> >> As part of the process, I had a set of hard-coded str.replace(...) >> functions that I used to clean up the incoming text into the desired >> output format, something like this: >> >> dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds >> dataIn = dataIn.replace('<','<') # Tidy up < character >> dataIn = dataIn.replace('>','>') # Tidy up < character >> dataIn = dataIn.replace('o','o') # No idea why but lots of >> these: convert to 'o' character dataIn = >> dataIn.replace('f','f') # .. and these: convert to 'f' >> character >> dataIn = dataIn.replace('e','e') # .. 'e' >> dataIn = dataIn.replace('O','O') # .. 'O' >> > The problem with this approach is that the order of the replacements > matters. For example, changing '<' to '<' and then '&' to '&' > can give a different result to changing '&' to '&' and then '<' > to '<'. If you started with the string '&lt;', then the first order > would go '&lt;' => '&lt;' => '<', whereas the second order > would go '&lt;' => '<' => '<'. > >> These statements transform my data correctly, but the list of statements >> grows as I test the data so I thought it made sense to store the >> replacement mappings in a file, read them into a dict and loop through >> that to do the cleaning up, like this: >> >> with open(fileName, 'r+t', encoding='utf-8') as mapFile: >> for line in mapFile: >> line = line.strip() >> try: >> if (line) and not line.startswith('#'): >> line = line.split('#')[:1][0].strip() # trim any >> trailing comments name, value = line.split('=') >> name = name.strip() >> self.filterMap[name]=value.strip() >> except: >> self.logger.error('exception occurred parsing line >> [{0}] in file [{1}]'.format(line, fileName)) raise >> >> Elsewhere, I use the following code to do the actual cleaning up: >> >> def filter(self, dataIn): >> if dataIn: >> for token, replacement in self.filterMap.items(): >> dataIn = dataIn.replace(token, replacement) >> return dataIn >> >> >> My mapping file contents look like this: >> >> \r = \\n >> ??? = " >> < = < >> > = > >> ' = ' >> F = F >> o = o >> f = f >> e = e >> O = O >> >> This all works "as advertised" */except/* for the '\r' => '\\n' >> replacement. Debugging the code, I see that my '\r' character is >> "escaped" to '\\r' and the '\\n' to '\\\\n' when they are read in from >> the file. >> >> I've been googling hard and reading the Python docs, trying to get my >> head around character encoding, but I just can't figure out how to get >> these bits of code to do what I want. >> >> It seems to me that I need to either: >> >> * change the way I represent '\r' and '\\n' in my mapping file; or >> * transform them somehow when I read them in >> >> However, I haven't figured out how to do either of these. >> > Try ast.literal_eval, although you'd need to make it look like a string > literal first: > > >>> import ast > >>> line = r'\r = \\n' > >>> print(line) > \r = \\n > >>> old, sep, new = line.partition(' = ') > >>> print(old) > \r > >>> print(new) > \\n > >>> ast.literal_eval('"%s"' % old) > '\r' > >>> ast.literal_eval('"%s"' % new) > '\\n' > >>> There's also codecs.decode(): >>> codecs.decode(r"\r = \\n", "unicode-escape") '\r = \\n' > I wouldn't put the &#...; forms into the mappings file (except for the > ' one) because they can all be recognised and done in code > ('F' is chr(int('070')), for example). Or >>> import html >>> html.unescape("< ö F") '< ? F' Even if you cannot use unescape() directly you might steal the implementation. From ian.g.kelly at gmail.com Wed Sep 2 18:57:16 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 2 Sep 2015 16:57:16 -0600 Subject: Python handles globals badly. In-Reply-To: <253e3584-1d4d-4e6f-b42f-2cdbfa4ad785@googlegroups.com> References: <253e3584-1d4d-4e6f-b42f-2cdbfa4ad785@googlegroups.com> Message-ID: On Wed, Sep 2, 2015 at 4:25 PM, wrote: > That said, it is not an overusing of globals cause globals are module vars only. > Or have you never written singletons or other classes in e.g Java, C++ with > lots of static and class members and methods using this members. I do use lots of static members in Java. 99.99% of them are constants, which if translated to Python globals would not require a global declaration anyway. Class members are not like Python globals. Class members are like Python class attributes. > With globals in Python are not meant traditional globals (app spanning vars) as already said. > Globals in Python are like class-members and statics in OO-languages. Globals are module scope! > And therefore it is not the devil or evil problem or code desaster problem > or LUA's opposite approach. > > (local/nonlocal statements I think are needed cause of lambda functionality and > is not what I try to discuss here) The local statement I was talking about has nothing to do with closures, which I think is what you mean. Within a given function, the compiler needs to have some way of knowing whether a given name is local or global. Currently that's done by the "global" keyword and by checking whether the name is ever assigned within the function. If the "global" keyword is no longer required, then there would have to be some other way for the compiler to distinguish locals from globals. The obvious solution would be to use a "local" keyword instead. That seems to me like it would be a lot more annoying. From kmisoft at gmail.com Wed Sep 2 19:58:50 2015 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Wed, 2 Sep 2015 19:58:50 -0400 Subject: packing unpacking depends on order. In-Reply-To: <55E758A3.30602@mail.de> References: <55E6C904.3020602@rece.vub.ac.be> <55E758A3.30602@mail.de> Message-ID: >>>> b, a[b] = a[b], b Nice. If I ever notice that kind of code in our codebase I'll 1) check file history to find out the "author" 2) ask that guy to remove it immediately :-) Vladimir http://itunes.apple.com/us/app/python-code-samples/id1025613117 From kmisoft at gmail.com Wed Sep 2 20:16:47 2015 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Wed, 2 Sep 2015 20:16:47 -0400 Subject: Python handles globals badly. In-Reply-To: References: <253e3584-1d4d-4e6f-b42f-2cdbfa4ad785@googlegroups.com> Message-ID: Hi, my 0.02 I don't personally use globals. And don't like "object oriented" code (my code more inclined toward "functional" style). But sometimes I feel like passing various minor values (like settings) all around app via regular parameters is just too much work. So I use "pseudo-global" object which holds various stuff in its attributes. And I pass that object around my code. But that is just one parameter, not myriads of them. Vladimir http://itunes.apple.com/us/app/python-code-samples/id1025613117 From breamoreboy at yahoo.co.uk Wed Sep 2 21:10:54 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 3 Sep 2015 02:10:54 +0100 Subject: Python handles globals badly. In-Reply-To: References: <253e3584-1d4d-4e6f-b42f-2cdbfa4ad785@googlegroups.com> Message-ID: On 03/09/2015 01:16, Vladimir Ignatov wrote: > Hi, > > my 0.02 > > I don't personally use globals. And don't like "object oriented" code > (my code more inclined toward "functional" style). But sometimes I > feel like passing various minor values (like settings) all around app > via regular parameters is just too much work. So I use > "pseudo-global" object which holds various stuff in its attributes. > And I pass that object around my code. But that is just one parameter, > not myriads of them. > > Vladimir > > http://itunes.apple.com/us/app/python-code-samples/id1025613117 > Conceptually something like this https://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named ? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Wed Sep 2 21:15:16 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 3 Sep 2015 02:15:16 +0100 Subject: Python handles globals badly. In-Reply-To: <253e3584-1d4d-4e6f-b42f-2cdbfa4ad785@googlegroups.com> References: <253e3584-1d4d-4e6f-b42f-2cdbfa4ad785@googlegroups.com> Message-ID: On 02/09/2015 23:25, tdev at freenet.de wrote: > Therefore still hoping a new PEP will arise. > > @Mark Lawrence > This response I have not checked. Can you provide arguments or clarify your statement? > The over use of globals is never to be encouraged, which is precisely what this would do. You could try raising this on python-ideas but I suspect you'd be wasting your time, so writing a PEP would almost certainly be a waste of time. Still, if you've got free time go ahead, I won't stop you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Wed Sep 2 21:16:51 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 3 Sep 2015 02:16:51 +0100 Subject: Python handles globals badly. In-Reply-To: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> Message-ID: On 02/09/2015 19:47, tdev at freenet.de wrote: > Even Java (type-safe language) need not such things for its static or member vars. By this comment are you stating that Python is not type safe? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From random832 at fastmail.us Wed Sep 2 21:17:25 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Wed, 02 Sep 2015 21:17:25 -0400 Subject: packing unpacking depends on order. In-Reply-To: <55E73159.4050508@mail.de> References: <55E6C904.3020602@rece.vub.ac.be> <55E73159.4050508@mail.de> Message-ID: <1441243045.413788.373350650.5DF79DE2@webmail.messagingengine.com> On Wed, Sep 2, 2015, at 13:26, Sven R. Kunze wrote: > I agree as well. First evaluate the right side, then assign it to the > left side at once. The behavior, if it's *not* "first evaluating the right side", is indistinguishable from it by this test. Assigning the RHS of each case to a separate list yields the same result: >>> a, b = [1, 2, 3, 4, 5], 1 >>> abb = a[b], b >>> bab = b, a[b] >>> b, a[b] = abb >>> a [1, 2, 1, 4, 5] >>> a, b = [1, 2, 3, 4, 5], 1 >>> a[b], b = bab >>> a [1, 1, 3, 4, 5] What's happening is this: >>> abb = a[b], b # 2, 1 >>> bab = b, a[b] # 1, 2 then >>> b, a[b] = abb # b = 2; a[2] = 1 or >>> a[b], b = bab # a[1] = 1; b = 2 The question is what does "assign it to the left side at once" even *mean* in the presence of subscripts? Build up a list of object-subscript pairs (evaluating all the subscripts, including if any may have side effects) before executing any __setitem__? Why is the right side evaluated first? Why not build up this "assignment destination list" first, before evaluating the right side? They wouldn't be distinguished by this test, since the RHS has no side effects, but it'd be easy enough to devise such a test case. From astroshed at gmail.com Wed Sep 2 21:32:15 2015 From: astroshed at gmail.com (astroshed at gmail.com) Date: Wed, 2 Sep 2015 18:32:15 -0700 (PDT) Subject: KB 2670838 - The EVIL UPDATE In-Reply-To: References: <850ad$550259dc$5419aafe$25863@news.ziggo.nl> Message-ID: On Saturday, 14 March 2015 02:36:01 UTC+10, David H. Lipman wrote: > > > > KB 2670838 - The EVIL UPDATE > > > < snip > > > > > GOODBYE, > > FAILURE TO DO SO PUTS YOUR SYSTEMS AT RISK ! > > > > > > Bye, > > Skybuck. > > I hope you like the taste of shoe leather. > > KB2670838 ==> 2013 ! > > It was not a part of the March '15 Patch tuesday release. > > > -- > Dave > Multi-AV Scanning Tool - http://multi-av.thespykiller.co.uk > http://www.pctipp.ch/downloads/dl/35905.asp Maybe so, but this EVIL update continues to wreak havoc. It's completely screwed my development environment 3 times since it was released. The first time, it's evilness was unknown and it took me down for weeks. Complete Windows reinstall didn't even work as it would just be installed again with the same result. The second time was a year later later after a system image restore and the latest was June 2015 after another recovery from the same system image. Because the recovery image doesn't have the update installed, Windows merrily goes ahead and installs it immediately after recovery and takes down Visual Studio. No amount of logging/debugging will help. This update does something that can only be remedied by uninstalling it. I'm onto it now, but the first time it happened I was ready to go all United States Postal Service on Microsoft. ha! From steve at pearwood.info Wed Sep 2 21:45:53 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 03 Sep 2015 11:45:53 +1000 Subject: packing unpacking depends on order. References: <55E6C904.3020602@rece.vub.ac.be> Message-ID: <55e7a652$0$1672$c3e8da3$5496439d@news.astraweb.com> On Thu, 3 Sep 2015 04:06 am, Ian Kelly wrote: > On Wed, Sep 2, 2015 at 11:42 AM, Terry Reedy wrote: >> On 9/2/2015 6:01 AM, Antoon Pardon wrote: >>> >>> >>>>>> a = [1, 2, 3, 4, 5] >>>>>> b = 1 >>>>>> b, a[b] = a[b], b >>>>>> a >>> >>> [1, 2, 1, 4, 5] [...] > I do. I think the former behavior is surprising, and that relying on > it would result in confusing, hard-to-read code. If you really want > the former, you can easily reproduce it with: Of course it's confusing, but the alternative is even more confusing. b, a[b] = 1, 2 currently has simple, predictable semantics: evaluate the right hand side from left to right, then assign to the left hand side bindings from left to right. The order of assignments does not depend on where the right hand side values come from, or whether a or b already exist. This will work fine: assert "a" not in locals() and "b" not in locals() b, a, a[b] = 1, "CORD".split(), "A" What's the alternative? I asked this question earlier, and got no answer -- apparently at least three people prefer behaviour that they cannot explain how to get the results they want :-) As far as I am concerned, having both of these: b, a[b] = a[b], b a[b], b = b, a[b] result in the same bindings is not only hard to implement, but hard to explain and hard to think about. Try to write an algorithm that gives the result you want, one which supports all the cases including the case where one or both of a and b don't exist prior to the assignments. -- Steven From steve at pearwood.info Wed Sep 2 21:49:39 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 03 Sep 2015 11:49:39 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> Message-ID: <55e7a733$0$1672$c3e8da3$5496439d@news.astraweb.com> On Thu, 3 Sep 2015 04:47 am, tdev at freenet.de wrote: > I agree with Skybuck Flying. > I am aware if a var is a module function var or a module global var. Congratulations! But you're not the Python compiler, which doesn't have your superior insight and intuition. Inside a function, how is the compiler supposed to know whether "x = 1" refers to a global or local? If you can explain that, then your proposal has the tiniest chance of success. Without that explanation, it has no hope at all. [...] > Especially cause a module is a singleton. What does that have to do with anything? > And globals are only module aware vars. What does that even mean? > Even Java (type-safe language) need not such things for its static or > member vars. Java has different rules for variables -- all variables are statically defined in Java and known to the compiler, that is not the case with dynamic languages like Lua, Python, Javascript, PHP. You can't do this in Java: name = random.choice(["foo", "bar", "baz"]) exec ("%s = 42" % name+"abc", globals()) globals()[name.upper()] = 999 So tell me, what global variables do you have now? > I have disliked this already in PHP where one has to do > exact the same thing as in Python (and hoped Python does it better, but > not). And using an import here is no solution, cause this is > something which relates only to the scope and state of a module itself. Again, I don't understand what your comment even means. -- Steven From ian.g.kelly at gmail.com Wed Sep 2 23:32:39 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 2 Sep 2015 21:32:39 -0600 Subject: packing unpacking depends on order. In-Reply-To: <55e7a652$0$1672$c3e8da3$5496439d@news.astraweb.com> References: <55E6C904.3020602@rece.vub.ac.be> <55e7a652$0$1672$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sep 2, 2015 7:51 PM, "Steven D'Aprano" wrote: > > What's the alternative? I asked this question earlier, and got no answer -- > apparently at least three people prefer behaviour that they cannot explain > how to get the results they want :-) > > As far as I am concerned, having both of these: > > b, a[b] = a[b], b > a[b], b = b, a[b] > > result in the same bindings is not only hard to implement, but hard to > explain and hard to think about. Try to write an algorithm that gives the > result you want, I don't think it's really all that difficult. 1) Evaluate the RHS from left to right as is already done, collecting the values to be assigned. 2) Evaluate the LHS from left to right. Note there are only three different types of assignments: assignments to names, assignments to attributes (i.e. using __setattr__), and assignments to items (i.e. using __setitem__). a) For assignments to names, there is nothing to evaluate. b) For assignments to attributes, the expression to the left of the . must be evaluated and stored. c) For assignments to items, the expression before the square brackets and the expression inside the square brackets must be evaluated (probably in that order, although it doesn't much matter as long as it's consistent) and stored. 3) Perform the assignments, again from left to right. There can still be ordering effects, e.g. if you do a, b.c = d, e and b's __setattr__ references a, or if one of the expressions has side effects. The same is also true on the RHS, as it is today. I'm not really concerned with that possibility. > one which supports all the cases including the case where > one or both of a and b don't exist prior to the assignments. That's a red herring. If either a or b don't exist prior to the assignments, then the result of assigning to a[b] *should* be an error. From uday3prakash at gmail.com Thu Sep 3 01:04:03 2015 From: uday3prakash at gmail.com (uday3prakash at gmail.com) Date: Wed, 2 Sep 2015 22:04:03 -0700 (PDT) Subject: .py to .html generation Message-ID: <9aa631c6-485e-4ba6-9bb1-59feecdd608d@googlegroups.com> Hi friends! Can some one help me with the best module and/or its tutorial, to generate html reports for python scripts? I tried pyreport and sphc; but, i am getting errors. From lac at openend.se Thu Sep 3 03:22:27 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 03 Sep 2015 09:22:27 +0200 Subject: .py to .html generation In-Reply-To: <9aa631c6-485e-4ba6-9bb1-59feecdd608d@googlegroups.com> References: <9aa631c6-485e-4ba6-9bb1-59feecdd608d@googlegroups.com> Message-ID: <201509030722.t837MRNa001905@fido.openend.se> In a message of Wed, 02 Sep 2015 22:04:03 -0700, uday3prakash at gmail.com writes: >Hi friends! > >Can some one help me with the best module and/or its tutorial, to generate html reports for python scripts? > >I tried pyreport and sphc; but, i am getting errors. >-- >https://mail.python.org/mailman/listinfo/python-list Whenever I want to generate html, I use sphinx. http://sphinx-doc.org/ It has great documentation. http://sphinx-doc.org/contents.html There is a mini-tutorial in there. http://sphinx-doc.org/tutorial.html There is also a report generator implemented as an extension to sphinx. https://github.com/AndreasHeger/CGATReport Interfaces nicely with ipython. Makes it easy to stick matplotlib graphs into your report. HTH, Laura From lac at openend.se Thu Sep 3 03:44:27 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 03 Sep 2015 09:44:27 +0200 Subject: .py to .html generation In-Reply-To: <201509030722.t837MRNa001905@fido.openend.se> References: <9aa631c6-485e-4ba6-9bb1-59feecdd608d@googlegroups.com> <201509030722.t837MRNa001905@fido.openend.se> Message-ID: <201509030744.t837iRnF007963@fido.openend.se> In a message of Thu, 03 Sep 2015 09:22:27 +0200, Laura Creighton writes: >There is also a report generator implemented as an extension to sphinx. >https://github.com/AndreasHeger/CGATReport >Interfaces nicely with ipython. Makes it easy to stick matplotlib >graphs into your report. I forgot about the 'searching on pip is temporarily broken problem' yes, there is a pip packagex for this, you do not have to get it from source. https://pypi.python.org/pypi/SphinxReport Laura From anthra.norell at bluewin.ch Thu Sep 3 04:40:47 2015 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Thu, 03 Sep 2015 10:40:47 +0200 Subject: Reading \n unescaped from a file In-Reply-To: <55E65909.2080507@medimorphosis.com.au> References: <55E65909.2080507@medimorphosis.com.au> Message-ID: <55E8078F.7090502@bluewin.ch> On 09/02/2015 04:03 AM, Rob Hills wrote: > Hi, > > I am developing code (Python 3.4) that transforms text data from one > format to another. > > As part of the process, I had a set of hard-coded str.replace(...) > functions that I used to clean up the incoming text into the desired > output format, something like this: > > dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds > dataIn = dataIn.replace('<','<') # Tidy up < character > dataIn = dataIn.replace('>','>') # Tidy up < character > dataIn = dataIn.replace('o','o') # No idea why but lots of these: convert to 'o' character > dataIn = dataIn.replace('f','f') # .. and these: convert to 'f' character > dataIn = dataIn.replace('e','e') # .. 'e' > dataIn = dataIn.replace('O','O') # .. 'O' > > These statements transform my data correctly, but the list of statements > grows as I test the data so I thought it made sense to store the > replacement mappings in a file, read them into a dict and loop through > that to do the cleaning up, like this: > > with open(fileName, 'r+t', encoding='utf-8') as mapFile: > for line in mapFile: > line = line.strip() > try: > if (line) and not line.startswith('#'): > line = line.split('#')[:1][0].strip() # trim any trailing comments > name, value = line.split('=') > name = name.strip() > self.filterMap[name]=value.strip() > except: > self.logger.error('exception occurred parsing line [{0}] in file [{1}]'.format(line, fileName)) > raise > > Elsewhere, I use the following code to do the actual cleaning up: > > def filter(self, dataIn): > if dataIn: > for token, replacement in self.filterMap.items(): > dataIn = dataIn.replace(token, replacement) > return dataIn > > > My mapping file contents look like this: > > \r = \\n > ??? = " > < = < > > = > > ' = ' > F = F > o = o > f = f > e = e > O = O > > This all works "as advertised" */except/* for the '\r' => '\\n' > replacement. Debugging the code, I see that my '\r' character is > "escaped" to '\\r' and the '\\n' to '\\\\n' when they are read in from > the file. > > I've been googling hard and reading the Python docs, trying to get my > head around character encoding, but I just can't figure out how to get > these bits of code to do what I want. > > It seems to me that I need to either: > > * change the way I represent '\r' and '\\n' in my mapping file; or > * transform them somehow when I read them in > > However, I haven't figured out how to do either of these. > > TIA, > > I have had this problem too and can propose a solution ready to run out of my toolbox: class editor: def compile (self, replacements): targets, substitutes = zip (*replacements) re_targets = [re.escape (item) for item in targets] re_targets.sort (reverse = True) self.targets_set = set (targets) self.table = dict (replacements) regex_string = '|'.join (re_targets) self.regex = re.compile (regex_string, re.DOTALL) def edit (self, text, eat = False): hits = self.regex.findall (text) nohits = self.regex.split (text) valid_hits = set (hits) & self.targets_set # Ignore targets with illegal re modifiers. if valid_hits: substitutes = [self.table [item] for item in hits if item in valid_hits] + [] # Make lengths equal for zip to work right if eat: output = ''.join (substitutes) else: zipped = zip (nohits, substitutes) output = ''.join (list (reduce (lambda a, b: a + b, [zipped][0]))) + nohits [-1] else: if eat: output = '' else: output = input return output >>> substitutions = ( ('\r', '\n'), ('<', '<'), ('>', '>'), ('o', 'o'), ('f', 'f'), ('e', 'e'), ('O', 'O'), ) Order doesn't matter. Add new ones at the end. >>> e = editor () >>> e.compile (substitutions) A simple way of testing is running the substitutions through the editor >>> print e.edit (repr (substitutions)) (('\r', '\n'), ('<', '<'), ('>', '>'), ('o', 'o'), ('f', 'f'), ('e', 'e'), ('O', 'O')) The escapes need to be tested separately >>> print e.edit ('abc\rdef') abc def Note: This editor's compiler compiles the substitution list to a regular expression which the editor uses to find all matches in the text passed to edit. There has got to be a limit to the size of a text which a regular expression can handle. I don't know what this limit is. To be on the safe side, edit a large text line by line or at least in sensible chunks. Frederic From __peter__ at web.de Thu Sep 3 05:24:30 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 03 Sep 2015 11:24:30 +0200 Subject: Reading \n unescaped from a file References: <55E65909.2080507@medimorphosis.com.au> <55E8078F.7090502@bluewin.ch> Message-ID: Friedrich Rentsch wrote: > > > On 09/02/2015 04:03 AM, Rob Hills wrote: >> Hi, >> >> I am developing code (Python 3.4) that transforms text data from one >> format to another. >> >> As part of the process, I had a set of hard-coded str.replace(...) >> functions that I used to clean up the incoming text into the desired >> output format, something like this: >> >> dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds >> dataIn = dataIn.replace('<','<') # Tidy up < character >> dataIn = dataIn.replace('>','>') # Tidy up < character >> dataIn = dataIn.replace('o','o') # No idea why but lots of >> these: convert to 'o' character dataIn = >> dataIn.replace('f','f') # .. and these: convert to 'f' >> character >> dataIn = dataIn.replace('e','e') # .. 'e' >> dataIn = dataIn.replace('O','O') # .. 'O' >> >> These statements transform my data correctly, but the list of statements >> grows as I test the data so I thought it made sense to store the >> replacement mappings in a file, read them into a dict and loop through >> that to do the cleaning up, like this: >> >> with open(fileName, 'r+t', encoding='utf-8') as mapFile: >> for line in mapFile: >> line = line.strip() >> try: >> if (line) and not line.startswith('#'): >> line = line.split('#')[:1][0].strip() # trim any >> trailing comments name, value = line.split('=') >> name = name.strip() >> self.filterMap[name]=value.strip() >> except: >> self.logger.error('exception occurred parsing line >> [{0}] in file [{1}]'.format(line, fileName)) raise >> >> Elsewhere, I use the following code to do the actual cleaning up: >> >> def filter(self, dataIn): >> if dataIn: >> for token, replacement in self.filterMap.items(): >> dataIn = dataIn.replace(token, replacement) >> return dataIn >> >> >> My mapping file contents look like this: >> >> \r = \\n >> ??? = " >> < = < >> > = > >> ' = ' >> F = F >> o = o >> f = f >> e = e >> O = O >> >> This all works "as advertised" */except/* for the '\r' => '\\n' >> replacement. Debugging the code, I see that my '\r' character is >> "escaped" to '\\r' and the '\\n' to '\\\\n' when they are read in from >> the file. >> >> I've been googling hard and reading the Python docs, trying to get my >> head around character encoding, but I just can't figure out how to get >> these bits of code to do what I want. >> >> It seems to me that I need to either: >> >> * change the way I represent '\r' and '\\n' in my mapping file; or >> * transform them somehow when I read them in >> >> However, I haven't figured out how to do either of these. >> >> TIA, >> >> > > I have had this problem too and can propose a solution ready to run out > of my toolbox: > > > class editor: > > def compile (self, replacements): > targets, substitutes = zip (*replacements) > re_targets = [re.escape (item) for item in targets] > re_targets.sort (reverse = True) > self.targets_set = set (targets) > self.table = dict (replacements) > regex_string = '|'.join (re_targets) > self.regex = re.compile (regex_string, re.DOTALL) > > def edit (self, text, eat = False): > hits = self.regex.findall (text) > nohits = self.regex.split (text) > valid_hits = set (hits) & self.targets_set # Ignore targets > with illegal re modifiers. Can you give an example of an ignored target? I don't see the light... > if valid_hits: > substitutes = [self.table [item] for item in hits if item > in valid_hits] + [] # Make lengths equal for zip to work right That looks wrong... > if eat: > output = ''.join (substitutes) > else: > zipped = zip (nohits, substitutes) > output = ''.join (list (reduce (lambda a, b: a + b, > [zipped][0]))) + nohits [-1] > else: > if eat: > output = '' > else: > output = input ...and so does this. > return output > > >>> substitutions = ( > ('\r', '\n'), > ('<', '<'), > ('>', '>'), > ('o', 'o'), > ('f', 'f'), > ('e', 'e'), > ('O', 'O'), > ) > > Order doesn't matter. Add new ones at the end. > > >>> e = editor () > >>> e.compile (substitutions) > > A simple way of testing is running the substitutions through the editor > > >>> print e.edit (repr (substitutions)) > (('\r', '\n'), ('<', '<'), ('>', '>'), ('o', 'o'), ('f', 'f'), ('e', > 'e'), ('O', 'O')) > > The escapes need to be tested separately > > >>> print e.edit ('abc\rdef') > abc > def > > Note: This editor's compiler compiles the substitution list to a regular > expression which the editor uses to find all matches in the text passed > to edit. There has got to be a limit to the size of a text which a > regular expression can handle. I don't know what this limit is. To be on > the safe side, edit a large text line by line or at least in sensible > chunks. > > Frederic > From nomail at invalid.com Thu Sep 3 08:20:06 2015 From: nomail at invalid.com (ast) Date: Thu, 3 Sep 2015 14:20:06 +0200 Subject: Strange location for a comma Message-ID: <55e83afb$0$3157$426a74cc@news.free.fr> Hello, At the end of the last line of the following program, there is a comma, I dont understand why ? Thx from cx_Freeze import setup, Executable # On appelle la fonction setup setup( name = "salut", version = "0.1", description = "Ce programme vous dit bonjour", executables = [Executable("salut.py")], # <--- HERE ) From nomail at invalid.com Thu Sep 3 08:28:11 2015 From: nomail at invalid.com (ast) Date: Thu, 3 Sep 2015 14:28:11 +0200 Subject: Strange location for a comma In-Reply-To: <55e83afb$0$3157$426a74cc@news.free.fr> References: <55e83afb$0$3157$426a74cc@news.free.fr> Message-ID: <55e83ce3$0$3327$426a74cc@news.free.fr> "ast" a ?crit dans le message de news:55e83afb$0$3157$426a74cc at news.free.fr... > Hello, > At the end of the last line of the following program, > there is a comma, I dont understand why ? > > Thx > > > from cx_Freeze import setup, Executable > > # On appelle la fonction setup > setup( > name = "salut", > version = "0.1", > description = "Ce programme vous dit bonjour", > executables = [Executable("salut.py")], # <--- HERE > ) > > Ok its understood, it's a 1 element only tuple example: >>> A = 5, >>> A (5,) >>> A = (6) >>> A 6 From larry.martell at gmail.com Thu Sep 3 08:30:35 2015 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 3 Sep 2015 08:30:35 -0400 Subject: sending push notifications Message-ID: I'm looking for people's experiences with the different ways to send push notifications to mobile devices. I have an app that will be running on Amazon, so I can use their SNS API or I can do it myself. >From googling there appear to be a few different packages but PyAPNs and python-gcm seem to be the most popular. And for interfacing to SNS boto seems to be the choice. Anyone here used any of these or other packages? From martin at mkomon.cz Thu Sep 3 08:34:05 2015 From: martin at mkomon.cz (=?UTF-8?Q?Martin_Komo=c5=88?=) Date: Thu, 3 Sep 2015 14:34:05 +0200 Subject: Strange location for a comma In-Reply-To: <55e83ce3$0$3327$426a74cc@news.free.fr> References: <55e83afb$0$3157$426a74cc@news.free.fr> <55e83ce3$0$3327$426a74cc@news.free.fr> Message-ID: <55E83E3D.8040506@mkomon.cz> In this case those are not tuples but rather arguments in a function call. The extra comma does not change the evaluation, my guess is that it is there for easier adding/removing arguments without having to care about trailing commas. Martin On 03/09/15 14:28, ast wrote: > > "ast" a ?crit dans le message de > news:55e83afb$0$3157$426a74cc at news.free.fr... >> Hello, >> At the end of the last line of the following program, >> there is a comma, I dont understand why ? >> >> Thx >> >> >> from cx_Freeze import setup, Executable >> >> # On appelle la fonction setup >> setup( >> name = "salut", >> version = "0.1", >> description = "Ce programme vous dit bonjour", >> executables = [Executable("salut.py")], # <--- HERE >> ) >> >> > > Ok its understood, it's a 1 element only tuple > > example: > >>>> A = 5, >>>> A > (5,) > >>>> A = (6) >>>> A > 6 > From lac at openend.se Thu Sep 3 08:40:34 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 03 Sep 2015 14:40:34 +0200 Subject: Strange location for a comma In-Reply-To: <55e83afb$0$3157$426a74cc@news.free.fr> References: <55e83afb$0$3157$426a74cc@news.free.fr> Message-ID: <201509031240.t83CeYVR017632@fido.openend.se> In a message of Thu, 03 Sep 2015 14:20:06 +0200, "ast" writes: >Hello, > >At the end of the last line of the following program, >there is a comma, I dont understand why ? > >Thx > > >from cx_Freeze import setup, Executable > ># On appelle la fonction setup >setup( > name = "salut", > version = "0.1", > description = "Ce programme vous dit bonjour", > executables = [Executable("salut.py")], # <--- HERE >) In python a tuple consists of a number of values separated by commas. see: https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences or https://docs.python.org/2/tutorial/datastructures.html#tuples-and-sequences for Python 2. The round parentheses aren't significant. So: >>> def Executable(arg): ... return arg ... >>> executables = [Executable("salut.py")], >>> executables (['salut.py'],) >>> Laura From __peter__ at web.de Thu Sep 3 08:48:03 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 03 Sep 2015 14:48:03 +0200 Subject: Strange location for a comma References: <55e83afb$0$3157$426a74cc@news.free.fr> <55e83ce3$0$3327$426a74cc@news.free.fr> Message-ID: ast wrote: > > "ast" a ?crit dans le message de > news:55e83afb$0$3157$426a74cc at news.free.fr... >> Hello, >> At the end of the last line of the following program, >> there is a comma, I dont understand why ? >> >> Thx >> >> >> from cx_Freeze import setup, Executable >> >> # On appelle la fonction setup >> setup( >> name = "salut", >> version = "0.1", >> description = "Ce programme vous dit bonjour", >> executables = [Executable("salut.py")], # <--- HERE >> ) >> >> > > Ok its understood, it's a 1 element only tuple > > example: > >>>> A = 5, >>>> A > (5,) > >>>> A = (6) >>>> A > 6 > No, in a function call an extra comma has no effect: >>> def f(x): return x ... >>> f(42) 42 >>> f(42,) 42 >>> f(x=42) 42 >>> f(x=42,) 42 The only reason I see to add an extra comma are smaller and easier to read diffs when you make a change: $ cat before.py func( arg_one=1, arg_two=2 ) func( arg_one=1, arg_two=2, ) $ cat after.py func( arg_one=1, arg_two=2, arg_three=3 ) func( arg_one=1, arg_two=2, arg_three=3, ) $ diff -u before.py after.py --- before.py 2015-09-03 14:44:27.709735075 +0200 +++ after.py 2015-09-03 14:44:55.275958331 +0200 @@ -1,9 +1,11 @@ func( arg_one=1, - arg_two=2 + arg_two=2, + arg_three=3 ) func( arg_one=1, arg_two=2, + arg_three=3, ) From python at mrabarnett.plus.com Thu Sep 3 08:50:41 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 3 Sep 2015 13:50:41 +0100 Subject: Strange location for a comma In-Reply-To: <55e83ce3$0$3327$426a74cc@news.free.fr> References: <55e83afb$0$3157$426a74cc@news.free.fr> <55e83ce3$0$3327$426a74cc@news.free.fr> Message-ID: <55E84221.6080102@mrabarnett.plus.com> On 2015-09-03 13:28, ast wrote: > > "ast" a ?crit dans le message de news:55e83afb$0$3157$426a74cc at news.free.fr... >> Hello, >> At the end of the last line of the following program, >> there is a comma, I dont understand why ? >> >> Thx >> >> >> from cx_Freeze import setup, Executable >> >> # On appelle la fonction setup >> setup( >> name = "salut", >> version = "0.1", >> description = "Ce programme vous dit bonjour", >> executables = [Executable("salut.py")], # <--- HERE >> ) >> >> > > Ok its understood, it's a 1 element only tuple > > example: > >>>> A = 5, >>>> A > (5,) > >>>> A = (6) >>>> A > 6 > No, it's not a tuple, because it's part of the argument list of 'setup'. A trailing comma is allowed in argument lists, tuples, lists, etc. >>> (1, 2, ) (1, 2) >>> [1, 2, ] [1, 2] >>> {1, 2, } {1, 2} >>> print(1, 2, ) 1 2 >>> {'1': 'one', '2': 'two', } {'2': 'two', '1': 'one'} It's nice to be able to do that because if you write the items on separate lines, like in your example, it's simpler when editing: all of the lines can end with a comma; if you add a new line, you don't also have to add a comma to the end of the previous line (a new line is added, and that's that); when removing a line, you don't also have to remove the comma from the end of the previous line (an old line is removed, and that's that). From kmisoft at gmail.com Thu Sep 3 08:50:54 2015 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Thu, 3 Sep 2015 08:50:54 -0400 Subject: Fwd: Strange location for a comma In-Reply-To: References: <55e83afb$0$3157$426a74cc@news.free.fr> <55e83ce3$0$3327$426a74cc@news.free.fr> Message-ID: >> >> # On appelle la fonction setup >> setup( >> name = "salut", >> version = "0.1", >> description = "Ce programme vous dit bonjour", >> executables = [Executable("salut.py")], # <--- HERE >> ) >> >> > > Ok its understood, it's a 1 element only tuple > > example: > >>>> A = 5, >>>> A > > (5,) > >>>> A = (6) >>>> A > > 6 No. It's not a tuple in your case (calling 'setup' function) a = 1,2, # <- extra comma print a b = 1, # <- extra comma print b => (1, 2) # ignored (1,) # made tuple and def f(a, b): print a,b f(1,2,) # <- extra comma => 1 2 # ignored Under some circumstances python ignores "excess" comma. At least inside list definition [1,2,3,] and function calls f(1,2,) Vladimir http://itunes.apple.com/us/app/python-code-samples/id1025613117 From lac at openend.se Thu Sep 3 08:54:25 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 03 Sep 2015 14:54:25 +0200 Subject: sending push notifications In-Reply-To: References: Message-ID: <201509031254.t83CsPL4021367@fido.openend.se> In a message of Thu, 03 Sep 2015 08:30:35 -0400, Larry Martell writes: >I'm looking for people's experiences with the different ways to send >push notifications to mobile devices. I have an app that will be >running on Amazon, so I can use their SNS API or I can do it myself. >>From googling there appear to be a few different packages but PyAPNs >and python-gcm seem to be the most popular. And for interfacing to SNS >boto seems to be the choice. Anyone here used any of these or other >packages? You might want to try this question on the very quiet, but not dead yet https://mail.python.org/mailman/listinfo/mobile-sig/ Laura From nomail at invalid.com Thu Sep 3 09:01:47 2015 From: nomail at invalid.com (ast) Date: Thu, 3 Sep 2015 15:01:47 +0200 Subject: Strange location for a comma In-Reply-To: <55e83afb$0$3157$426a74cc@news.free.fr> References: <55e83afb$0$3157$426a74cc@news.free.fr> Message-ID: <55e844c3$0$3356$426a74cc@news.free.fr> "ast" a ?crit dans le message de news:55e83afb$0$3157$426a74cc at news.free.fr... > Hello, > At the end of the last line of the following program, > there is a comma, I dont understand why ? > > Thx > > > from cx_Freeze import setup, Executable > > # On appelle la fonction setup > setup( > name = "salut", > version = "0.1", > description = "Ce programme vous dit bonjour", > executables = [Executable("salut.py")], # <--- HERE > ) > > understood Thx all From lac at openend.se Thu Sep 3 09:02:14 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 03 Sep 2015 15:02:14 +0200 Subject: Strange location for a comma In-Reply-To: <201509031240.t83CeYVR017632@fido.openend.se> References: <55e83afb$0$3157$426a74cc@news.free.fr> <201509031240.t83CeYVR017632@fido.openend.se> Message-ID: <201509031302.t83D2Ect023519@fido.openend.se> No, I am wrong. You are in the middle of a fuction definition. You are correct, that is a wierd place for a comma, though I can see doing that if you anticipate adding more arguments to the function in the near future. Laura From tdev at freenet.de Thu Sep 3 09:22:29 2015 From: tdev at freenet.de (tdev at freenet.de) Date: Thu, 3 Sep 2015 06:22:29 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: References: Message-ID: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> Reflecting the answers I want to add following first: I should have better started a new thread. But now it is here, I want just clarify something before I move on (later) with repsonding. I think this has lead to some confusing. There are now two main topics in this thread. First topic: "sharing globals between modules" Where globals is meant as vars used throughout the app. This is the topic why Skybuck starts the thread. And yes I agree globals can be bad design and it is solved via outsourcing to an extra module and used via imports. I misinterpreted this topic a little by thinking the focus is more about the use of the badly "global" keyword (in my point of view) and added therefore my post here as Second topic: "Forced to use "global" for write-access inside functions is over-regulation and should be removed." This topic has nothing todo with sharing globals. It is about in the scope of a single module only. When I have written globals in this topic I have meant and mean vars defined in a module outside functions and used inside function blocks. Sorry if this has lead to confusion, but so long I have read docs I would say that these vars are often named as globals although I meant module vars. Reason is that module scope is the highest scope and often referred as the global scope. That is also why I dislike the word "global" too. I talk about this construct: Sample "Bad": module A _x = 0 def y(): global x _x=1 and I aim for - it would be nicer to allow for simplicity writing this without the keyword "global" and give this small responsibility ("write protection") back to the developer: Sample "Good": module A _x = 0 def y(): _x=1 why - this I have tried and try to explain in my and your posts in the hope a PEP will arise which frees me and hopefully a lot other developers getting forced to use "global" (If developers need this "global" - ok, but I and hopefully more want not to be forced with that code-contaminator, especially having a lot more vars) Said that, I will not respond to comments about sharing globals From anthra.norell at bluewin.ch Thu Sep 3 09:37:35 2015 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Thu, 03 Sep 2015 15:37:35 +0200 Subject: Reading \n unescaped from a file In-Reply-To: References: <55E65909.2080507@medimorphosis.com.au> <55E8078F.7090502@bluewin.ch> Message-ID: <55E84D1F.5040205@bluewin.ch> On 09/03/2015 11:24 AM, Peter Otten wrote: > Friedrich Rentsch wrote: > >> >> On 09/02/2015 04:03 AM, Rob Hills wrote: >>> Hi, >>> >>> I am developing code (Python 3.4) that transforms text data from one >>> format to another. >>> >>> As part of the process, I had a set of hard-coded str.replace(...) >>> functions that I used to clean up the incoming text into the desired >>> output format, something like this: >>> >>> dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds >>> dataIn = dataIn.replace('<','<') # Tidy up < character >>> dataIn = dataIn.replace('>','>') # Tidy up < character >>> dataIn = dataIn.replace('o','o') # No idea why but lots of >>> these: convert to 'o' character dataIn = >>> dataIn.replace('f','f') # .. and these: convert to 'f' >>> character >>> dataIn = dataIn.replace('e','e') # .. 'e' >>> dataIn = dataIn.replace('O','O') # .. 'O' >>> >>> These statements transform my data correctly, but the list of statements >>> grows as I test the data so I thought it made sense to store the >>> replacement mappings in a file, read them into a dict and loop through >>> that to do the cleaning up, like this: >>> >>> with open(fileName, 'r+t', encoding='utf-8') as mapFile: >>> for line in mapFile: >>> line = line.strip() >>> try: >>> if (line) and not line.startswith('#'): >>> line = line.split('#')[:1][0].strip() # trim any >>> trailing comments name, value = line.split('=') >>> name = name.strip() >>> self.filterMap[name]=value.strip() >>> except: >>> self.logger.error('exception occurred parsing line >>> [{0}] in file [{1}]'.format(line, fileName)) raise >>> >>> Elsewhere, I use the following code to do the actual cleaning up: >>> >>> def filter(self, dataIn): >>> if dataIn: >>> for token, replacement in self.filterMap.items(): >>> dataIn = dataIn.replace(token, replacement) >>> return dataIn >>> >>> >>> My mapping file contents look like this: >>> >>> \r = \\n >>> ??? = " >>> < = < >>> > = > >>> ' = ' >>> F = F >>> o = o >>> f = f >>> e = e >>> O = O >>> >>> This all works "as advertised" */except/* for the '\r' => '\\n' >>> replacement. Debugging the code, I see that my '\r' character is >>> "escaped" to '\\r' and the '\\n' to '\\\\n' when they are read in from >>> the file. >>> >>> I've been googling hard and reading the Python docs, trying to get my >>> head around character encoding, but I just can't figure out how to get >>> these bits of code to do what I want. >>> >>> It seems to me that I need to either: >>> >>> * change the way I represent '\r' and '\\n' in my mapping file; or >>> * transform them somehow when I read them in >>> >>> However, I haven't figured out how to do either of these. >>> >>> TIA, >>> >>> >> I have had this problem too and can propose a solution ready to run out >> of my toolbox: >> >> >> class editor: >> >> def compile (self, replacements): >> targets, substitutes = zip (*replacements) >> re_targets = [re.escape (item) for item in targets] >> re_targets.sort (reverse = True) >> self.targets_set = set (targets) >> self.table = dict (replacements) >> regex_string = '|'.join (re_targets) >> self.regex = re.compile (regex_string, re.DOTALL) >> >> def edit (self, text, eat = False): >> hits = self.regex.findall (text) >> nohits = self.regex.split (text) >> valid_hits = set (hits) & self.targets_set # Ignore targets >> with illegal re modifiers. > Can you give an example of an ignored target? I don't see the light... > >> if valid_hits: >> substitutes = [self.table [item] for item in hits if item >> in valid_hits] + [] # Make lengths equal for zip to work right > That looks wrong... > >> if eat: >> output = ''.join (substitutes) >> else: >> zipped = zip (nohits, substitutes) >> output = ''.join (list (reduce (lambda a, b: a + b, >> [zipped][0]))) + nohits [-1] >> else: >> if eat: >> output = '' >> else: >> output = input > ...and so does this. > >> return output >> >> >>> substitutions = ( >> ('\r', '\n'), >> ('<', '<'), >> ('>', '>'), >> ('o', 'o'), >> ('f', 'f'), >> ('e', 'e'), >> ('O', 'O'), >> ) >> >> Order doesn't matter. Add new ones at the end. >> >> >>> e = editor () >> >>> e.compile (substitutions) >> >> A simple way of testing is running the substitutions through the editor >> >> >>> print e.edit (repr (substitutions)) >> (('\r', '\n'), ('<', '<'), ('>', '>'), ('o', 'o'), ('f', 'f'), ('e', >> 'e'), ('O', 'O')) >> >> The escapes need to be tested separately >> >> >>> print e.edit ('abc\rdef') >> abc >> def >> >> Note: This editor's compiler compiles the substitution list to a regular >> expression which the editor uses to find all matches in the text passed >> to edit. There has got to be a limit to the size of a text which a >> regular expression can handle. I don't know what this limit is. To be on >> the safe side, edit a large text line by line or at least in sensible >> chunks. >> >> Frederic >> >> Peter, thanks for your comments. Valid hits is the intersection of targets compiled and targets matched. In the list comprehension it ensures that no matches get into the lookup that are not literally in the substitution targets, as might happen with repetition symbols (?,*,+). Although the compiler escapes those, only omniscient developers know all contingencies in advance. I appreciate your identifying two mistakes. I am curious to know what they are. Frederic From rosuav at gmail.com Thu Sep 3 10:03:49 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 00:03:49 +1000 Subject: Python handles globals badly. In-Reply-To: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> References: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> Message-ID: On Thu, Sep 3, 2015 at 11:22 PM, wrote: > Sample "Good": > module A > _x = 0 > > def y(): > _x=1 > > > why - this I have tried and try to explain in my and your posts > in the hope a PEP will arise which frees me and hopefully > a lot other developers getting forced to use "global" > (If developers need this "global" - ok, but I and > hopefully more want not to be forced with that > code-contaminator, especially having a lot more vars) Okay. Let's suppose that some magic is worked out that makes this work. Now let's try this example: def x(q): for word in generate_words(): if word.matches(q): return word def y(): word = x("blue") otherword = x("green") if word < otherword: return otherword return x("red") How would you reason about this code? Would you not expect that the instances of 'word' in each function are completely independent? (And while this is a contrived example, the exact same thing happens *a lot*, where the name used in a "return" statement is the same as the name that thing gets assigned to. After all, if it's a logical name for that thing in one place, it's likely a logical name in the other, too.) According to your proposal, they would cease to be independent if the module grows an attribute 'word'. Since, in Python, such attributes can be injected from outside, there is literally no way to reason about this code in isolation. That makes it very difficult to track down problems. Definitely do not like this. ChrisA From __peter__ at web.de Thu Sep 3 10:24:03 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 03 Sep 2015 16:24:03 +0200 Subject: Reading \n unescaped from a file References: <55E65909.2080507@medimorphosis.com.au> <55E8078F.7090502@bluewin.ch> <55E84D1F.5040205@bluewin.ch> Message-ID: Friedrich Rentsch wrote: > On 09/03/2015 11:24 AM, Peter Otten wrote: >> Friedrich Rentsch wrote: > I appreciate your identifying two mistakes. I am curious to know what > they are. Sorry for not being explicit. >>> substitutes = [self.table [item] for item in hits if item >>> in valid_hits] + [] # Make lengths equal for zip to work right >> That looks wrong... You are adding an empty list here. I wondered what you were trying to achieve with that. >>> output = input >> ...and so does this. That seems to be the only occurence of the name "input" in your code. Did you mean "text" or do you really want to return the built-in? From hemla21 at gmail.com Thu Sep 3 10:32:55 2015 From: hemla21 at gmail.com (Heli Nix) Date: Thu, 3 Sep 2015 07:32:55 -0700 (PDT) Subject: Porting Python Application to a new linux machine Message-ID: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Dear all, I have my python scripts that use several python libraries such as h5py, pyside, numpy.... In Windows I have an installer that will install python locally on user machine and so my program gets access to this local python and runs successfully. How can I do this in Linux ? ( I want to install python plus my program on the user machine.) I do not want to use the user?s python or to install python on the user?s machine on root. Thanks in Advance for your help, From python.list at tim.thechases.com Thu Sep 3 10:36:23 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 3 Sep 2015 09:36:23 -0500 Subject: Strange location for a comma In-Reply-To: References: <55e83afb$0$3157$426a74cc@news.free.fr> <55e83ce3$0$3327$426a74cc@news.free.fr> Message-ID: <20150903093623.646428f8@bigbox.christie.dr> On 2015-09-03 14:48, Peter Otten wrote: > The only reason I see to add an extra comma are smaller and easier > to read diffs when you make a change: While that's the primary reason I do it, it's also helpful if you have a bunch of named keyword arguments and want sort/rearrange them (usually for clarity/grouping). You don't have to worry about finding the previous-last-item and adding a comma to it and then finding the new-last-item and removing its comma. Also, when adding a new item, you can just copy an existing line, paste it, and modify the salient parts without needing to append a comma to one line or delete it from the pasted line. But the improvement in diff output? That's a big win for me. I notice it most when I *can't* use it, like in writing SQL: SELECT col1, col2, col3, -- grr, can't do this FROM tblExample so my SQL diffs are the "removed this line and replaced it with something almost identical except it now has a comma". Harumph. -tkc From anthony at cajuntechie.org Thu Sep 3 10:38:24 2015 From: anthony at cajuntechie.org (Anthony Papillion) Date: Thu, 03 Sep 2015 09:38:24 -0500 Subject: How do I real a SSL certs serial number using Python? Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 I'm writing a simple tool that needs to read the serial number of a remote SSL certificate. I've poked around Google for a bit but can't find anything that fits the bill. Is this possible in Python? If so, would someone point me in the general direction of how to do it? Thanks, Anthony Papillion - -- Phone: 1-(845) 666-1114 VoIP: 17772471988 at in.callcentric.com Skype: CajunTechie -----BEGIN PGP SIGNATURE----- Version: APG v1.1.1 iQJJBAEBCgAzBQJV6FtfLBxBbnRob255IFBhcGlsbGlvbiA8YW50aG9ueUBjYWp1 bnRlY2hpZS5vcmc+AAoJEEKq2nfie1EM5EIP/jUdLg03pPWksQcXOqiMtYAW65E8 43J5yYgJmjTM7a87s0CyYhKxJN9VO/trBptCPvowrwZ9AdDbPxQUzRvSni4Trzfh TTZi0K9rpoKqUcwX+z2EwRWDlyiDKWpq7DzdisLmqACL02pz/xQcBM/LPj9TvhKB NYhIY0jw4S0oISMWz/eqVyCd1RMHvxsDOM3wKVbwXKN2r5Bx+AC2F2S0qOneUcNX f9GNhbjDKleQPifrBQ2q3k6hnUaUbATELUHqsa3/p3/UIVv8OZ7ONKe17Ofh8Cxf 0mtmMuH7a5gAeCwwPQnU/nI6g9QXEDv/yRdqWX3bi11xw88jmMEBq2ybQyvAiAmm 2Czphjk87tkbdrYu6QKxLFLmaeAh8scl2XOlk+X8+hVasiG/px0nvvgPSy1s/nC8 pEMIiyUoFliq6IszuMshzHU6JCmvBKP0AmoVIodnJal1rR7vh2aoh9tKU92nrHGV e33tdP8JobfmFHQesHVUZVBvdsxO0othuQKKADMdmm31BfrSEydNdcA+9aTXwbUT ef8sz5eu7MzUu4aq63k/qwyaflP/TBNhTk6ByePvI/g4l1gDxGHskAt8tPBO2gT1 rTKYLOk2ckFh4TutD0IvdL3EyyxzrhlSfprjUJV8X3RWcyYDooPQN+STG4sBJUC2 vAc5oUGXdaHIWsbd =oAPu -----END PGP SIGNATURE----- From ahlusar.ahluwalia at gmail.com Thu Sep 3 11:05:31 2015 From: ahlusar.ahluwalia at gmail.com (kbtyo) Date: Thu, 3 Sep 2015 08:05:31 -0700 (PDT) Subject: continue vs. pass in this IO reading and writing Message-ID: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> Good Morning: I am experimenting with many exception handling and utilizing continue vs pass. After pouring over a lot of material on SO and other forums I am still unclear as to the difference when setting variables and applying functions within multiple "for" loops. Specifically, I understand that the general format in the case of pass and using else is the following: try: doSomething() except Exception: pass else: stuffDoneIf() TryClauseSucceeds() However, I am uncertain as to how this executes in a context like this: import glob import csv from collections import OrderedDict interesting_files = glob.glob("*.csv") header_saved = False with open('merged_output_mod.csv','w') as fout: for filename in interesting_files: print("execution here again") with open(filename) as fin: try: header = next(fin) print("Entering Try and Except") except: StopIteration continue else: if not header_saved: fout.write(header) header_saved = True print("We got here") for line in fin: fout.write(line) My questions are (for some reason my interpreter does not print out any readout): 1. after the exception is raised does the continue return back up to the beginning of the for loop (and the "else" conditional is not even encountered)? 2. How would a pass behave in this situation? Thanks for your feedback. Sincerely, Saran From tdev at freenet.de Thu Sep 3 11:16:26 2015 From: tdev at freenet.de (tdev at freenet.de) Date: Thu, 3 Sep 2015 08:16:26 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: References: Message-ID: <1fc39ce9-7f92-46f1-a78d-694ba1f0cc90@googlegroups.com> Before responding (later) I have to add something additional first: About the OO comments (Note again for this 2nd main topic of this thread: the term "globals" - it is meant only as the vars of a module outside functions and not sharing vars throughout the app the term "global" - Python keyword for write access inside functions) Yes OO is a solution but Python invites also developers using functional or procedural style. I have used OO-terms to make it more visible to OO-developers or simply cause it is common knowlegde: I dont have and wanted not compare OO terminology with Python OO structure. When I have compared OO class members with Python globals or when I have used e.g. the term singleton than I have described the behaviour of a module from OO point of view and to show that OO languages need no"global"-keyword to fulfil its tasks, and to show that procedural style used in that manner is like nearby an OO-solution. So you dont need OO under all circumstances. There is a procedural/functional way too. Even other comparisons like type-safety is nothing else but to show that such languages need no "global" keyword. So, mainly with my comparison I tried to argue that there is no no need for a "global" keyword. Said that, I will not respond to comments about using OO or about comparisons made with other languages. (And by the way, OO in Python has something similiar (a.k.a "self"-keyword)) From rosuav at gmail.com Thu Sep 3 11:27:13 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 01:27:13 +1000 Subject: continue vs. pass in this IO reading and writing In-Reply-To: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> References: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 1:05 AM, kbtyo wrote: > However, I am uncertain as to how this executes in a context like this: > > import glob > import csv > from collections import OrderedDict > > interesting_files = glob.glob("*.csv") > > header_saved = False > with open('merged_output_mod.csv','w') as fout: > > for filename in interesting_files: > print("execution here again") > with open(filename) as fin: > try: > header = next(fin) > print("Entering Try and Except") > except: > StopIteration > continue I think what you want here is: except StopIteration: continue The code you have will catch _any_ exception, and then look up the name StopIteration (and discard it). > else: > if not header_saved: > fout.write(header) > header_saved = True > print("We got here") > for line in fin: > fout.write(line) > > My questions are (for some reason my interpreter does not print out any readout): > > 1. after the exception is raised does the continue return back up to the beginning of the for loop (and the "else" conditional is not even encountered)? > > 2. How would a pass behave in this situation? The continue statement means "skip the rest of this loop's body and go to the next iteration of the loop, if there is one". In this case, there's no further body, so it's going to be the same as "pass" (which means "do nothing"). For the rest, I think your code should be broadly functional. Of course, it assumes that your files all have compatible headers, but presumably you know that that's safe. ChrisA From joel.goldstick at gmail.com Thu Sep 3 11:27:28 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 3 Sep 2015 11:27:28 -0400 Subject: Porting Python Application to a new linux machine In-Reply-To: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: On Thu, Sep 3, 2015 at 10:32 AM, Heli Nix wrote: > Dear all, > > I have my python scripts that use several python libraries such as h5py, pyside, numpy.... > > In Windows I have an installer that will install python locally on user machine and so my program gets access to this local python and runs successfully. > > How can I do this in Linux ? ( I want to install python plus my program on the user machine.) I do not want to use the user?s python or to install python on the user?s machine on root. > > Thanks in Advance for your help, > > -- > https://mail.python.org/mailman/listinfo/python-list Look into virtualenv or virtualenvwrapper. It will let you load a local python engine along with local copies of the modules you need to run your application. Pip is the weapon of choice to load the libraries, or pip3 with python 3.x -- Joel Goldstick http://joelgoldstick.com From otlucaDELETE at DELETEyahoo.it Thu Sep 3 11:31:47 2015 From: otlucaDELETE at DELETEyahoo.it (Luca Menegotto) Date: Thu, 3 Sep 2015 17:31:47 +0200 Subject: Porting Python Application to a new linux machine References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: Il 03/09/2015 16:32, Heli Nix ha scritto: > How can I do this in Linux ? As far as I know, in general a Linux distro comes with Python already installed. All you have to do is check if the installed version matches your needs. Tipically, you'll find Python 2.7; however, I know there are distros with Python3.x as default (Fedora?) -- Ciao! Luca From ahlusar.ahluwalia at gmail.com Thu Sep 3 11:38:55 2015 From: ahlusar.ahluwalia at gmail.com (kbtyo) Date: Thu, 3 Sep 2015 08:38:55 -0700 (PDT) Subject: continue vs. pass in this IO reading and writing In-Reply-To: References: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> Message-ID: <53c5301c-2833-446f-a7d1-6c0ef9314928@googlegroups.com> On Thursday, September 3, 2015 at 11:27:58 AM UTC-4, Chris Angelico wrote: > On Fri, Sep 4, 2015 at 1:05 AM, kbtyo wrote: > > However, I am uncertain as to how this executes in a context like this: > > > > import glob > > import csv > > from collections import OrderedDict > > > > interesting_files = glob.glob("*.csv") > > > > header_saved = False > > with open('merged_output_mod.csv','w') as fout: > > > > for filename in interesting_files: > > print("execution here again") > > with open(filename) as fin: > > try: > > header = next(fin) > > print("Entering Try and Except") > > except: > > StopIteration > > continue > > I think what you want here is: > > except StopIteration: > continue > > The code you have will catch _any_ exception, and then look up the > name StopIteration (and discard it). > > > else: > > if not header_saved: > > fout.write(header) > > header_saved = True > > print("We got here") > > for line in fin: > > fout.write(line) > > > > My questions are (for some reason my interpreter does not print out any readout): > > > > 1. after the exception is raised does the continue return back up to the beginning of the for loop (and the "else" conditional is not even encountered)? > > > > 2. How would a pass behave in this situation? > > The continue statement means "skip the rest of this loop's body and go > to the next iteration of the loop, if there is one". In this case, > there's no further body, so it's going to be the same as "pass" (which > means "do nothing"). > > For the rest, I think your code should be broadly functional. Of > course, it assumes that your files all have compatible headers, but > presumably you know that that's safe. > > ChrisA Hi ChrisA: Thank you for the elaboration. So, what I hear you saying is that (citing, "In this case, there's no further body, so it's going to be the same as "pass" (which means "do nothing")") that the else block is not entered. For exma Do you mind elaborating on what you meant by "compatible headers?". The files that I am processing may or may not have the same headers (but if they do they should add the respective values only). From rosuav at gmail.com Thu Sep 3 11:39:12 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 01:39:12 +1000 Subject: Porting Python Application to a new linux machine In-Reply-To: References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 1:31 AM, Luca Menegotto wrote: > Il 03/09/2015 16:32, Heli Nix ha scritto: > >> How can I do this in Linux ? > > > As far as I know, in general a Linux distro comes with Python already > installed. > All you have to do is check if the installed version matches your needs. > Tipically, you'll find Python 2.7; however, I know there are distros with > Python3.x as default (Fedora?) Also Ubuntu. If you want to work across multiple Linux distros, the easiest way is to tell people to install either "python2" or "python3" using their system package manager, and then use that. ChrisA From ahlusar.ahluwalia at gmail.com Thu Sep 3 11:49:43 2015 From: ahlusar.ahluwalia at gmail.com (kbtyo) Date: Thu, 3 Sep 2015 08:49:43 -0700 (PDT) Subject: continue vs. pass in this IO reading and writing In-Reply-To: References: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> Message-ID: <3be8f66b-38b8-4e32-ae8e-4ac613560677@googlegroups.com> On Thursday, September 3, 2015 at 11:27:58 AM UTC-4, Chris Angelico wrote: > On Fri, Sep 4, 2015 at 1:05 AM, kbtyo wrote: > > However, I am uncertain as to how this executes in a context like this: > > > > import glob > > import csv > > from collections import OrderedDict > > > > interesting_files = glob.glob("*.csv") > > > > header_saved = False > > with open('merged_output_mod.csv','w') as fout: > > > > for filename in interesting_files: > > print("execution here again") > > with open(filename) as fin: > > try: > > header = next(fin) > > print("Entering Try and Except") > > except: > > StopIteration > > continue > > I think what you want here is: > > except StopIteration: > continue > > The code you have will catch _any_ exception, and then look up the > name StopIteration (and discard it). > > > else: > > if not header_saved: > > fout.write(header) > > header_saved = True > > print("We got here") > > for line in fin: > > fout.write(line) > > > > My questions are (for some reason my interpreter does not print out any readout): > > > > 1. after the exception is raised does the continue return back up to the beginning of the for loop (and the "else" conditional is not even encountered)? > > > > 2. How would a pass behave in this situation? > > The continue statement means "skip the rest of this loop's body and go > to the next iteration of the loop, if there is one". In this case, > there's no further body, so it's going to be the same as "pass" (which > means "do nothing"). So what I hear you saying is I am not entering the else" block? Hence, when each file is read, the rest of the suite is not applied - specifically, if not header_saved: fout.write(header) header_saved = True print("We got here") > > For the rest, I think your code should be broadly functional. Of > course, it assumes that your files all have compatible headers, but > presumably you know that that's safe. > > ChrisA Would you mind elaborating on what you meant by "compatible headers"? I have files that may have different headers. If they are different, they should be appended (along with their values). If there are duplicate headers, then their values should just be added. From torriem at gmail.com Thu Sep 3 11:50:46 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 03 Sep 2015 09:50:46 -0600 Subject: Python handles globals badly. In-Reply-To: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> References: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> Message-ID: <55E86C56.2020008@gmail.com> On 09/03/2015 07:22 AM, tdev at freenet.de wrote: > First topic: > "sharing globals between modules" > Where globals is meant as vars used throughout the app. > > This is the topic why Skybuck starts the thread. The answer to this is simple and elegant. Use a third module to store globals. Each module that needs it can simply import it. From nick.a.sarbicki at gmail.com Thu Sep 3 11:51:33 2015 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Thu, 03 Sep 2015 15:51:33 +0000 Subject: Strange location for a comma In-Reply-To: <20150903093623.646428f8@bigbox.christie.dr> References: <55e83afb$0$3157$426a74cc@news.free.fr> <55e83ce3$0$3327$426a74cc@news.free.fr> <20150903093623.646428f8@bigbox.christie.dr> Message-ID: Tim, Doesn't work for the first column in SQL, but we tend to put the comma and a space before the column name. It makes it easier to move things around and (debateably) more readable. It is also very obvious when you have missed a comma this way. - Nick On Thu, 3 Sep 2015 16:14 Tim Chase wrote: > On 2015-09-03 14:48, Peter Otten wrote: > > The only reason I see to add an extra comma are smaller and easier > > to read diffs when you make a change: > > While that's the primary reason I do it, it's also helpful if you > have a bunch of named keyword arguments and want sort/rearrange them > (usually for clarity/grouping). You don't have to worry about finding > the previous-last-item and adding a comma to it and then finding the > new-last-item and removing its comma. Also, when adding a new > item, you can just copy an existing line, paste it, and modify the > salient parts without needing to append a comma to one line or > delete it from the pasted line. > > But the improvement in diff output? That's a big win for me. > > I notice it most when I *can't* use it, like in writing SQL: > > SELECT > col1, > col2, > col3, -- grr, can't do this > FROM tblExample > > so my SQL diffs are the "removed this line and replaced it with > something almost identical except it now has a comma". Harumph. > > -tkc > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- - Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Sep 3 11:51:57 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 01:51:57 +1000 Subject: continue vs. pass in this IO reading and writing In-Reply-To: <53c5301c-2833-446f-a7d1-6c0ef9314928@googlegroups.com> References: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> <53c5301c-2833-446f-a7d1-6c0ef9314928@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 1:38 AM, kbtyo wrote: > Thank you for the elaboration. So, what I hear you saying is that (citing, "In this case, there's no further body, so it's going to be the same as "pass" (which > means "do nothing")") that the else block is not entered. For exma Seems like a cut-off paragraph here, but yes. In a try/except/else block, the 'else' block executes only if the 'try' didn't raise an exception of the specified type(s). > Do you mind elaborating on what you meant by "compatible headers?". The files that I am processing may or may not have the same headers (but if they do they should add the respective values only). > Your algorithm is basically: Take the entire first file, including its header, and then append all other files after skipping their first lines. If you want a smarter form of CSV merge, I would recommend using the 'csv' module, and probably doing a quick check of all files before you begin, so as to collect up the full set of headers. That'll also save you the hassle of playing around with StopIteration as you read in the headers. ChrisA From nick.a.sarbicki at gmail.com Thu Sep 3 11:53:24 2015 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Thu, 03 Sep 2015 15:53:24 +0000 Subject: Porting Python Application to a new linux machine In-Reply-To: References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: Is 3.x the default on ubuntu now? My 14.10 is still 2.7. Although it does have python3 installed. On Thu, 3 Sep 2015 16:40 Chris Angelico wrote: > On Fri, Sep 4, 2015 at 1:31 AM, Luca Menegotto > wrote: > > Il 03/09/2015 16:32, Heli Nix ha scritto: > > > >> How can I do this in Linux ? > > > > > > As far as I know, in general a Linux distro comes with Python already > > installed. > > All you have to do is check if the installed version matches your needs. > > Tipically, you'll find Python 2.7; however, I know there are distros with > > Python3.x as default (Fedora?) > > Also Ubuntu. If you want to work across multiple Linux distros, the > easiest way is to tell people to install either "python2" or "python3" > using their system package manager, and then use that. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- - Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From larry.martell at gmail.com Thu Sep 3 11:54:46 2015 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 3 Sep 2015 11:54:46 -0400 Subject: sending push notifications In-Reply-To: <201509031254.t83CsPL4021367@fido.openend.se> References: <201509031254.t83CsPL4021367@fido.openend.se> Message-ID: On Thu, Sep 3, 2015 at 8:54 AM, Laura Creighton wrote: > In a message of Thu, 03 Sep 2015 08:30:35 -0400, Larry Martell writes: >>I'm looking for people's experiences with the different ways to send >>push notifications to mobile devices. I have an app that will be >>running on Amazon, so I can use their SNS API or I can do it myself. >>>From googling there appear to be a few different packages but PyAPNs >>and python-gcm seem to be the most popular. And for interfacing to SNS >>boto seems to be the choice. Anyone here used any of these or other >>packages? > > You might want to try this question on the very quiet, but not dead > yet https://mail.python.org/mailman/listinfo/mobile-sig/ Will do. Thanks. From rosuav at gmail.com Thu Sep 3 11:55:53 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 01:55:53 +1000 Subject: Porting Python Application to a new linux machine In-Reply-To: References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 1:53 AM, Nick Sarbicki wrote: > Is 3.x the default on ubuntu now? My 14.10 is still 2.7. Although it does > have python3 installed. I'm not sure. I think I read somewhere that the newest Ubuntus would ship with python3 preinstalled, but python2 not (though of course it'd be just an apt-get away). Maybe I'm wrong, and that's still in the future, but certainly it's the intention. ChrisA From ahlusar.ahluwalia at gmail.com Thu Sep 3 11:57:30 2015 From: ahlusar.ahluwalia at gmail.com (kbtyo) Date: Thu, 3 Sep 2015 08:57:30 -0700 (PDT) Subject: continue vs. pass in this IO reading and writing In-Reply-To: References: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> <53c5301c-2833-446f-a7d1-6c0ef9314928@googlegroups.com> Message-ID: <652bbe97-aef5-41dc-8f4c-cfa47bcfd120@googlegroups.com> On Thursday, September 3, 2015 at 11:52:16 AM UTC-4, Chris Angelico wrote: > On Fri, Sep 4, 2015 at 1:38 AM, kbtyo wrote: > > Thank you for the elaboration. So, what I hear you saying is that (citing, "In this case, there's no further body, so it's going to be the same as "pass" (which > > means "do nothing")") that the else block is not entered. For exma > > Seems like a cut-off paragraph here, but yes. In a try/except/else > block, the 'else' block executes only if the 'try' didn't raise an > exception of the specified type(s). > > > Do you mind elaborating on what you meant by "compatible headers?". The files that I am processing may or may not have the same headers (but if they do they should add the respective values only). > > > > Your algorithm is basically: Take the entire first file, including its > header, and then append all other files after skipping their first > lines. If you want a smarter form of CSV merge, I would recommend > using the 'csv' module, and probably doing a quick check of all files > before you begin, so as to collect up the full set of headers. That'll > also save you the hassle of playing around with StopIteration as you > read in the headers. > > ChrisA I have files that may have different headers. If they are different, they should be appended (along with their values). If there are duplicate headers, then their values should just be added. I have used CSV and collections. For some reason when I apply this algorithm, all of my files are not added (the output is ridiculously small considering how much goes in - think KB output vs MB input): from glob import iglob import csv from collections import OrderedDict files = sorted(iglob('*.csv')) header = OrderedDict() data = [] for filename in files: with open(filename, 'r') as fin: csvin = csv.DictReader(fin) header.update(OrderedDict.fromkeys(csvin.fieldnames)) data.append(next(csvin)) with open('output_filename_version2.csv', 'w') as fout: csvout = csv.DictWriter(fout, fieldnames=list(header)) csvout.writeheader() csvout.writerows(data) From tjreedy at udel.edu Thu Sep 3 12:05:28 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 3 Sep 2015 12:05:28 -0400 Subject: continue vs. pass in this IO reading and writing In-Reply-To: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> References: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> Message-ID: On 9/3/2015 11:05 AM, kbtyo wrote: > I am experimenting with many exception handling and utilizing continue vs pass. 'pass' is a do-nothing place holder. 'continue' and 'break' are jump statements [snip] > However, I am uncertain as to how this executes in a context like this: > > import glob > import csv > from collections import OrderedDict > > interesting_files = glob.glob("*.csv") > > header_saved = False > with open('merged_output_mod.csv','w') as fout: > > for filename in interesting_files: > print("execution here again") > with open(filename) as fin: > try: > header = next(fin) > print("Entering Try and Except") > except: > StopIteration > continue > else: > if not header_saved: > fout.write(header) > header_saved = True > print("We got here") > for line in fin: > fout.write(line) > > My questions are (for some reason my interpreter does not print out any readout): > > 1. after the exception is raised does the continue return back up to the beginning of the for loop (and the "else" conditional is not even encountered)? > > 2. How would a pass behave in this situation? Try it for yourself. Copy the following into a python shell or editor (and run) see what you get. for i in [-1, 0, 1]: try: j = 2//i except ZeroDivisionError: print('infinity') continue else: print(j) Change 'continue' to 'pass' and run again. -- Terry Jan Reedy From rosuav at gmail.com Thu Sep 3 12:11:27 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 02:11:27 +1000 Subject: continue vs. pass in this IO reading and writing In-Reply-To: <652bbe97-aef5-41dc-8f4c-cfa47bcfd120@googlegroups.com> References: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> <53c5301c-2833-446f-a7d1-6c0ef9314928@googlegroups.com> <652bbe97-aef5-41dc-8f4c-cfa47bcfd120@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 1:57 AM, kbtyo wrote: > I have used CSV and collections. For some reason when I apply this algorithm, all of my files are not added (the output is ridiculously small considering how much goes in - think KB output vs MB input): > > from glob import iglob > import csv > from collections import OrderedDict > > files = sorted(iglob('*.csv')) > header = OrderedDict() > data = [] > > for filename in files: > with open(filename, 'r') as fin: > csvin = csv.DictReader(fin) > header.update(OrderedDict.fromkeys(csvin.fieldnames)) > data.append(next(csvin)) > > with open('output_filename_version2.csv', 'w') as fout: > csvout = csv.DictWriter(fout, fieldnames=list(header)) > csvout.writeheader() > csvout.writerows(data) You're collecting up just one row from each file. Since you say your input is measured in MB (not GB or anything bigger), the simplest approach is probably fine: instead of "data.append(next(csvin))", just use "data.extend(csvin)", which should grab them all. That'll store all your input data in memory, which should be fine if it's only a few meg, and probably not a problem for anything under a few hundred meg. ChrisA From rhills at medimorphosis.com.au Thu Sep 3 12:12:27 2015 From: rhills at medimorphosis.com.au (Rob Hills) Date: Fri, 4 Sep 2015 00:12:27 +0800 Subject: Reading \n unescaped from a file In-Reply-To: <55E8078F.7090502@bluewin.ch> References: <55E65909.2080507@medimorphosis.com.au> <55E8078F.7090502@bluewin.ch> Message-ID: <55E8716B.4080600@medimorphosis.com.au> Hi Friedrich, On 03/09/15 16:40, Friedrich Rentsch wrote: > > On 09/02/2015 04:03 AM, Rob Hills wrote: >> Hi, >> >> I am developing code (Python 3.4) that transforms text data from one >> format to another. >> >> As part of the process, I had a set of hard-coded str.replace(...) >> functions that I used to clean up the incoming text into the desired >> output format, something like this: >> >> dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds >> dataIn = dataIn.replace('<','<') # Tidy up < character >> dataIn = dataIn.replace('>','>') # Tidy up < character >> dataIn = dataIn.replace('o','o') # No idea why but lots of >> these: convert to 'o' character >> dataIn = dataIn.replace('f','f') # .. and these: convert to >> 'f' character >> dataIn = dataIn.replace('e','e') # .. 'e' >> dataIn = dataIn.replace('O','O') # .. 'O' >> >> These statements transform my data correctly, but the list of statements >> grows as I test the data so I thought it made sense to store the >> replacement mappings in a file, read them into a dict and loop through >> that to do the cleaning up, like this: >> >> with open(fileName, 'r+t', encoding='utf-8') as mapFile: >> for line in mapFile: >> line = line.strip() >> try: >> if (line) and not line.startswith('#'): >> line = line.split('#')[:1][0].strip() # trim >> any trailing comments >> name, value = line.split('=') >> name = name.strip() >> self.filterMap[name]=value.strip() >> except: >> self.logger.error('exception occurred parsing >> line [{0}] in file [{1}]'.format(line, fileName)) >> raise >> >> Elsewhere, I use the following code to do the actual cleaning up: >> >> def filter(self, dataIn): >> if dataIn: >> for token, replacement in self.filterMap.items(): >> dataIn = dataIn.replace(token, replacement) >> return dataIn >> >> >> My mapping file contents look like this: >> >> \r = \\n >> ??? = " >> < = < >> > = > >> ' = ' >> F = F >> o = o >> f = f >> e = e >> O = O >> >> This all works "as advertised" */except/* for the '\r' => '\\n' >> replacement. Debugging the code, I see that my '\r' character is >> "escaped" to '\\r' and the '\\n' to '\\\\n' when they are read in from >> the file. >> >> I've been googling hard and reading the Python docs, trying to get my >> head around character encoding, but I just can't figure out how to get >> these bits of code to do what I want. >> >> It seems to me that I need to either: >> >> * change the way I represent '\r' and '\\n' in my mapping file; or >> * transform them somehow when I read them in >> >> However, I haven't figured out how to do either of these. >> >> TIA, >> >> > > I have had this problem too and can propose a solution ready to run > out of my toolbox: > > > class editor: > > def compile (self, replacements): > targets, substitutes = zip (*replacements) > re_targets = [re.escape (item) for item in targets] > re_targets.sort (reverse = True) > self.targets_set = set (targets) > self.table = dict (replacements) > regex_string = '|'.join (re_targets) > self.regex = re.compile (regex_string, re.DOTALL) > > def edit (self, text, eat = False): > hits = self.regex.findall (text) > nohits = self.regex.split (text) > valid_hits = set (hits) & self.targets_set # Ignore targets > with illegal re modifiers. > if valid_hits: > substitutes = [self.table [item] for item in hits if item > in valid_hits] + [] # Make lengths equal for zip to work right > if eat: > output = ''.join (substitutes) > else: > zipped = zip (nohits, substitutes) > output = ''.join (list (reduce (lambda a, b: a + b, > [zipped][0]))) + nohits [-1] > else: > if eat: > output = '' > else: > output = input > return output > > >>> substitutions = ( > ('\r', '\n'), > ('<', '<'), > ('>', '>'), > ('o', 'o'), > ('f', 'f'), > ('e', 'e'), > ('O', 'O'), > ) > > Order doesn't matter. Add new ones at the end. > > >>> e = editor () > >>> e.compile (substitutions) > > A simple way of testing is running the substitutions through the editor > > >>> print e.edit (repr (substitutions)) > (('\r', '\n'), ('<', '<'), ('>', '>'), ('o', 'o'), ('f', 'f'), ('e', > 'e'), ('O', 'O')) > > The escapes need to be tested separately > > >>> print e.edit ('abc\rdef') > abc > def > > Note: This editor's compiler compiles the substitution list to a > regular expression which the editor uses to find all matches in the > text passed to edit. There has got to be a limit to the size of a text > which a regular expression can handle. I don't know what this limit > is. To be on the safe side, edit a large text line by line or at least > in sensible chunks. > > Frederic > Thanks for the suggestion. I had originally done a simple set of hard-coded str.replace() functions which worked fine and are fast enough for me not to have to delve into the complexity and obscurity of regex. I had also contemplated simply declaring my replacement dict in its own .py file and then importing it. I ended up stubbornly pursuing the idea of loading everything from a text file just because I didn't understand why it wasn't working. Cheers, -- Rob Hills Waikiki, Western Australia From ian.g.kelly at gmail.com Thu Sep 3 12:15:28 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 Sep 2015 10:15:28 -0600 Subject: Python handles globals badly. In-Reply-To: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> References: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> Message-ID: On Thu, Sep 3, 2015 at 7:22 AM, wrote: > I think this has lead to some confusing. I don't think so. > First topic: > "sharing globals between modules" > Where globals is meant as vars used throughout the app. > > This is the topic why Skybuck starts the thread. > And yes I agree globals can be bad design > and it is solved via outsourcing to an extra module and used via imports. > > I misinterpreted this topic a little by thinking > the focus is more about the use of the badly "global" keyword > (in my point of view) and added therefore my post here as The only person whom I see talking about this in this thread is you disclaiming that you're not talking about it. (And I guess Skybuck is talking about it, but I don't see those.) > Said that, I will not respond to comments about sharing globals > Said that, I will not respond to comments about using OO or about comparisons made with other languages. I don't know what comments about using OO you're referring to either. I only see one suggestion to use classes, and you've already responded to that. As far as comparisons to other languages, you're the one who brought up the comparison to Java in the first place. You seem to be spending a lot of time talking about what you won't talk about, and very little time talking about your proposal, such as by what magic you expect the compiler to distinguish globals from locals without declarations. From bkugler at gmail.com Thu Sep 3 12:19:37 2015 From: bkugler at gmail.com (Brett Kugler) Date: Thu, 3 Sep 2015 11:19:37 -0500 Subject: Porting Python Application to a new linux machine In-Reply-To: References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: On Thu, Sep 3, 2015 at 10:39 AM, Chris Angelico wrote: > On Fri, Sep 4, 2015 at 1:31 AM, Luca Menegotto > wrote: > > Il 03/09/2015 16:32, Heli Nix ha scritto: > > > >> How can I do this in Linux ? > > > > > > As far as I know, in general a Linux distro comes with Python already > > installed. > > All you have to do is check if the installed version matches your needs. > > Tipically, you'll find Python 2.7; however, I know there are distros with > > Python3.x as default (Fedora?) > > Also Ubuntu. If you want to work across multiple Linux distros, the > easiest way is to tell people to install either "python2" or "python3" > using their system package manager, and then use that. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > You could also look into a more robust solution like placing your application environment into something like a Docker container. This would require your customer machine to be running Docker, but it makes deployments highly portable as the container will sit on top of just about any Linux flavor and can be entirely self contained. Brett -------------- next part -------------- An HTML attachment was scrubbed... URL: From otlucaDELETE at DELETEyahoo.it Thu Sep 3 12:23:43 2015 From: otlucaDELETE at DELETEyahoo.it (Luca Menegotto) Date: Thu, 3 Sep 2015 18:23:43 +0200 Subject: Porting Python Application to a new linux machine References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: Il 03/09/2015 17:53, Nick Sarbicki ha scritto: > Is 3.x the default on ubuntu now? My 14.10 is still 2.7. Although it > does have python3 installed. I've checked my Ubuntu 15.04, and the default is 2.7.9. There is also Python3 (3.4.3), but sorry, I can't remember if I've manually installed it or not. -- Ciao! Luca From rhills at medimorphosis.com.au Thu Sep 3 12:24:49 2015 From: rhills at medimorphosis.com.au (Rob Hills) Date: Fri, 4 Sep 2015 00:24:49 +0800 Subject: Reading \n unescaped from a file In-Reply-To: References: <55E65909.2080507@medimorphosis.com.au> Message-ID: <55E87451.3090904@medimorphosis.com.au> Hi Chris, On 03/09/15 06:10, Chris Angelico wrote: > On Wed, Sep 2, 2015 at 12:03 PM, Rob Hills wrote: >> My mapping file contents look like this: >> >> \r = \\n >> ??? = " > Oh, lovely. Code page 1252 when you're expecting UTF-8. Sadly, you're > likely to have to cope with a whole pile of other mojibake if that > happens :( Yeah, tell me about it!!! > Technically, what's happening is that your "\r" is literally a > backslash followed by the letter r; the transformation of backslash > sequences into single characters is part of Python source code > parsing. (Incidentally, why do you want to change a carriage return > into backslash-n? Seems odd.) > > Probably the easiest solution would be a simple and naive replace(), > looking for some very specific strings and ignoring everything else. > Easy to do, but potentially confusing down the track if someone tries > something fancy :) > > line = line.split('#')[:1][0].strip() # trim any trailing comments > line = line.replace(r"\r", "\r") # repeat this for as many backslash > escapes as you want to handle > > Be aware that this, while simple, is NOT capable of handling escaped > backslashes. In Python, "\\r" comes out the same as r"\r", but with > this parser, it would come out the same as "\\\r". But it might be > sufficient for you. Thanks for the explanation which has helped me understand the problem. I also tried your approach but wound up with output data that somehow had every single character escaped :-( I've since decided I was being too obsessive trying to load *everything* from my mapping file and have simply hard-coded my two escaped character replacements for now and moved on to more important problems (ie the Windoze Character soup that comprises my data and which I have to clean up!). Thanks again, -- Rob Hills Waikiki, Western Australia From rhills at medimorphosis.com.au Thu Sep 3 12:32:30 2015 From: rhills at medimorphosis.com.au (Rob Hills) Date: Fri, 4 Sep 2015 00:32:30 +0800 Subject: Reading \n unescaped from a file In-Reply-To: <55E778C7.7050802@mrabarnett.plus.com> References: <55E65909.2080507@medimorphosis.com.au> <55E778C7.7050802@mrabarnett.plus.com> Message-ID: <55E8761E.2090001@medimorphosis.com.au> Hi, On 03/09/15 06:31, MRAB wrote: > On 2015-09-02 03:03, Rob Hills wrote: >> I am developing code (Python 3.4) that transforms text data from one >> format to another. >> >> As part of the process, I had a set of hard-coded str.replace(...) >> functions that I used to clean up the incoming text into the desired >> output format, something like this: >> >> dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds >> dataIn = dataIn.replace('<','<') # Tidy up < character >> dataIn = dataIn.replace('>','>') # Tidy up < character >> dataIn = dataIn.replace('o','o') # No idea why but lots of >> these: convert to 'o' character >> dataIn = dataIn.replace('f','f') # .. and these: convert to >> 'f' character >> dataIn = dataIn.replace('e','e') # .. 'e' >> dataIn = dataIn.replace('O','O') # .. 'O' >> > The problem with this approach is that the order of the replacements > matters. For example, changing '<' to '<' and then '&' to '&' > can give a different result to changing '&' to '&' and then '<' > to '<'. If you started with the string '&lt;', then the first order > would go '&lt;' => '&lt;' => '<', whereas the second order > would go '&lt;' => '<' => '<'. Ah yes, thanks for reminding me about that. I've since modified my code to use a collections.OrderedDict to store my mappings. ... >> This all works "as advertised" */except/* for the '\r' => '\\n' >> replacement. Debugging the code, I see that my '\r' character is >> "escaped" to '\\r' and the '\\n' to '\\\\n' when they are read in from >> the file. >> >> I've been googling hard and reading the Python docs, trying to get my >> head around character encoding, but I just can't figure out how to get >> these bits of code to do what I want. >> >> It seems to me that I need to either: >> >> * change the way I represent '\r' and '\\n' in my mapping file; or >> * transform them somehow when I read them in >> >> However, I haven't figured out how to do either of these. >> > Try ast.literal_eval, although you'd need to make it look like a string > literal first: Thanks for the suggestion. For now, I've decided I was being too pedantic trying to load my two escaped strings from a file and I've simply hard coded them and moved on to other issues. I'll try this idea later on though. Cheers, -- Rob Hills Waikiki, Western Australia From ahlusar.ahluwalia at gmail.com Thu Sep 3 12:35:11 2015 From: ahlusar.ahluwalia at gmail.com (kbtyo) Date: Thu, 3 Sep 2015 09:35:11 -0700 (PDT) Subject: continue vs. pass in this IO reading and writing In-Reply-To: References: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> <53c5301c-2833-446f-a7d1-6c0ef9314928@googlegroups.com> <652bbe97-aef5-41dc-8f4c-cfa47bcfd120@googlegroups.com> Message-ID: <6abd12de-2b10-4cc9-86db-a2f144ecc56a@googlegroups.com> On Thursday, September 3, 2015 at 12:12:04 PM UTC-4, Chris Angelico wrote: > On Fri, Sep 4, 2015 at 1:57 AM, kbtyo wrote: > > I have used CSV and collections. For some reason when I apply this algorithm, all of my files are not added (the output is ridiculously small considering how much goes in - think KB output vs MB input): > > > > from glob import iglob > > import csv > > from collections import OrderedDict > > > > files = sorted(iglob('*.csv')) > > header = OrderedDict() > > data = [] > > > > for filename in files: > > with open(filename, 'r') as fin: > > csvin = csv.DictReader(fin) > > header.update(OrderedDict.fromkeys(csvin.fieldnames)) > > data.append(next(csvin)) > > > > with open('output_filename_version2.csv', 'w') as fout: > > csvout = csv.DictWriter(fout, fieldnames=list(header)) > > csvout.writeheader() > > csvout.writerows(data) > > You're collecting up just one row from each file. Since you say your > input is measured in MB (not GB or anything bigger), the simplest > approach is probably fine: instead of "data.append(next(csvin))", just > use "data.extend(csvin)", which should grab them all. That'll store > all your input data in memory, which should be fine if it's only a few > meg, and probably not a problem for anything under a few hundred meg. > > ChrisA Hmmmm - good point. However, I may have to deal with larger files, but thank you for the tip. I am also wondering, based on what you stated, you are only "collecting up just one row from each file".... I am fulfilling this, correct? "I have files that may have different headers. If they are different, they should be appended (along with their values) into the output. If there are duplicate headers, then their values should just be added sequentially." I am wondering how DictReader can skip empty rows by default and that this may be happening that also extrapolates to the other rows. From otlucaDELETE at DELETEyahoo.it Thu Sep 3 12:37:56 2015 From: otlucaDELETE at DELETEyahoo.it (Luca Menegotto) Date: Thu, 3 Sep 2015 18:37:56 +0200 Subject: continue vs. pass in this IO reading and writing References: <19ca6361-95fe-4a5d-84d6-c72d7941745c@googlegroups.com> Message-ID: Il 03/09/2015 17:05, kbtyo ha scritto: > I am experimenting with many exception handling and utilizing > continue vs pass. After pouring over a lot of material on SO > and other forums I am still unclear as to the difference when > setting variables and applying functions within multiple "for" > loops. 'pass' and 'continue' have two very different meanings. 'pass' means 'don't do anything'; it's useful when you _have_ to put a statement but you _don't_need_ to put a statement. You can use it everywhere you want, with no other damage then adding a little weight to your code. A stupid example: if i == 0: pass else: do_something() 'continue', to be used in a loop (for or while) means 'ignore the rest of the code and go immediatly to the next iteration'. The statement refers to the nearest loop; so, if you have two nested loops, it refers to the inner one; another stupid example: for i in range(10): for j in range(10): if j < 5: continue do_something(i, j) # called only if j >= 5 -- Ciao! Luca From torriem at gmail.com Thu Sep 3 12:43:43 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 03 Sep 2015 10:43:43 -0600 Subject: Python handles globals badly. In-Reply-To: References: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> Message-ID: <55E878BF.4050507@gmail.com> On 09/03/2015 10:15 AM, Ian Kelly wrote: > The only person whom I see talking about this in this thread is you > disclaiming that you're not talking about it. (And I guess Skybuck is > talking about it, but I don't see those.) I have a vague memory of Skybuck talking about globals over a year ago. That must be what tdev's responding to. Sadly Skybuck probably ditched Python a long time ago as he was spending his time trying to make it into Java rather than taking advantage of idiomatic Python programming. Those that try to program Java style in Python are going to be frustrated. From rosuav at gmail.com Thu Sep 3 12:49:08 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 02:49:08 +1000 Subject: Porting Python Application to a new linux machine In-Reply-To: References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 2:23 AM, Luca Menegotto wrote: > Il 03/09/2015 17:53, Nick Sarbicki ha scritto: >> >> Is 3.x the default on ubuntu now? My 14.10 is still 2.7. Although it >> does have python3 installed. > > > I've checked my Ubuntu 15.04, and the default is 2.7.9. > There is also Python3 (3.4.3), but sorry, I can't remember if I've manually > installed it or not. If you mean that typing "python" runs 2.7, then that's PEP 394 at work. For compatibility reasons, 'python' doesn't ever run Python 3. (At least, not any time soon.) The question is more: What comes installed on a fresh system? Anything can be dragged in as a dependency of some other package, but a normal Ubuntu desktop installation won't depend on Python 2 for anything. Or at least, that's the plan; I don't know whether it's been accomplished yet or not. ChrisA From palpandi111 at gmail.com Thu Sep 3 12:54:49 2015 From: palpandi111 at gmail.com (Palpandi) Date: Thu, 3 Sep 2015 09:54:49 -0700 (PDT) Subject: XML Binding Message-ID: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> Hi All, Is there any module available in python standard library for XML binding? If not, any other suggestions. Which is good for parsing large file? 1. XML binding 2. Creating our own classes Thanks, Palpandi From otlucaDELETE at DELETEyahoo.it Thu Sep 3 13:29:05 2015 From: otlucaDELETE at DELETEyahoo.it (Luca Menegotto) Date: Thu, 3 Sep 2015 19:29:05 +0200 Subject: Porting Python Application to a new linux machine References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: Il 03/09/2015 18:49, Chris Angelico ha scritto: > If you mean that typing "python" runs 2.7, then that's PEP 394 at > work. For compatibility reasons, 'python' doesn't ever run Python 3. Please forgive me, Il make it clearer. I'm pretty shure that Ubuntu 15.04 comes with Python 2.7. I don't remember if Python 3 was preinstalled or if I had to install it manually. -- Ciao! Luca From rosuav at gmail.com Thu Sep 3 13:33:27 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 03:33:27 +1000 Subject: Porting Python Application to a new linux machine In-Reply-To: References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 3:29 AM, Luca Menegotto wrote: > Il 03/09/2015 18:49, Chris Angelico ha scritto: > >> If you mean that typing "python" runs 2.7, then that's PEP 394 at >> work. For compatibility reasons, 'python' doesn't ever run Python 3. > > > Please forgive me, Il make it clearer. > I'm pretty shure that Ubuntu 15.04 comes with Python 2.7. > I don't remember if Python 3 was preinstalled or if I had to install it > manually. Okay. I don't run any current Ubuntu anywhere, so I don't know. And I can't even find back the page now where the plans were being discussed; best I can find is this, about a year out of date now: https://wiki.ubuntu.com/Python/3 ChrisA From nick.a.sarbicki at gmail.com Thu Sep 3 13:40:23 2015 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Thu, 03 Sep 2015 17:40:23 +0000 Subject: Porting Python Application to a new linux machine In-Reply-To: References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: I run ubuntu everywhere at home and python3 has come preinstalled since at least ubuntu 12.10. This article kind of covers it: https://wiki.ubuntu.com/Python Looks like they're suggesting that it's not been fully transitioned although definitely moving that way. On Thu, 3 Sep 2015 18:34 Chris Angelico wrote: > On Fri, Sep 4, 2015 at 3:29 AM, Luca Menegotto > wrote: > > Il 03/09/2015 18:49, Chris Angelico ha scritto: > > > >> If you mean that typing "python" runs 2.7, then that's PEP 394 at > >> work. For compatibility reasons, 'python' doesn't ever run Python 3. > > > > > > Please forgive me, Il make it clearer. > > I'm pretty shure that Ubuntu 15.04 comes with Python 2.7. > > I don't remember if Python 3 was preinstalled or if I had to install it > > manually. > > Okay. I don't run any current Ubuntu anywhere, so I don't know. And I > can't even find back the page now where the plans were being > discussed; best I can find is this, about a year out of date now: > > https://wiki.ubuntu.com/Python/3 > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- - Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Sep 3 14:29:48 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 3 Sep 2015 19:29:48 +0100 Subject: Python handles globals badly. In-Reply-To: <55E878BF.4050507@gmail.com> References: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> <55E878BF.4050507@gmail.com> Message-ID: <55E8919C.1070909@mrabarnett.plus.com> On 2015-09-03 17:43, Michael Torrie wrote: > On 09/03/2015 10:15 AM, Ian Kelly wrote: >> The only person whom I see talking about this in this thread is you >> disclaiming that you're not talking about it. (And I guess Skybuck is >> talking about it, but I don't see those.) > > I have a vague memory of Skybuck talking about globals over a year ago. > That must be what tdev's responding to. > It wasn't as long ago as that; it's been only 9 months! :-) > Sadly Skybuck probably ditched Python a long time ago as he was spending > his time trying to make it into Java rather than taking advantage of > idiomatic Python programming. Those that try to program Java style in > Python are going to be frustrated. > From tdev at freenet.de Thu Sep 3 15:05:18 2015 From: tdev at freenet.de (tdev at freenet.de) Date: Thu, 3 Sep 2015 12:05:18 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: References: Message-ID: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> Now I want reflecting the latest answers: I have the position of a high-level view (cause of lack of Python knowledge internals and compiler stuff, but also cause I think a language should be as far as possible user-friendly without knowing too much internals, and yes clearly cause of knowing OO-languages where I do not need such code-contamination) So, my high-level understanding of the "global"-keyword so far is: Give write access to a global var if this is set to this var inside a current code block. And this specific syntax construction is probably defined not cause it is really needed but cause it is assumed to help the developer avoiding mistakes, which I think is too much over-regulation. But from the answers given I maybe have to rethink about the global keyword. It seems to be an absolute need from low-level point of view - meaning the designer had no other choice as to invent the keyword "global": Two main reasons for the need of keyword "global" have been posted: Compiler - Python compiler or compiler at all cannot hide this from the developer? (It seems really a scripting problem. PHP has it, LUA has it vice versa, ...) Although I cannot really believe it, that technical reasons lead to this design. E.g recognizing if it is local or global: If this would be under the developer responsibility than this is simply achieved by giving well-written var names. And a compiler can surely recognize if a defined var xxx outside is not a var yyy inside a function. Or does anyone really name a global var xxx and a function var xxx? I am sure no one at all will do it. I dont want read such a code. Function calls (?) - I have to admit I did not really get the problematic from the sample provided by Chris Angelico. What I can see or mean to see is: it has nothing to do with global-keyword from the high level point of view: give write access, probably to the vars word and otherword. And yes, I see the vars independant. And cause you set no "global" they are simple local vars (readable+writeable) This is more about let me assume function call stack and closures things(?) which I think is handled automatically. But as said - here I cannot really respond. This have to be answered from more experienced users. My conclusion: -------------- My intention was to bring this into discussion and see what comes out and see what are the reasons for this keyword. I am not the user who can open the PEP, but maybe the community out decides to do so. But if this two problems really exists from low-level point of view, then ok, there is no other way than to use this keyword "global". I have not the experience to answer that. I can accept low-level problems if so. But then I ask you from high-level point of view (if my high level view is correct at all): Would you remove this keyword if it would be technically possible or is good for you from high level point of view to have a keyword "global"? My answer is clear: remove it. [The same e.g. with switch statement: add it] Then this is my question now! Thanks. From ian.g.kelly at gmail.com Thu Sep 3 15:47:32 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 Sep 2015 13:47:32 -0600 Subject: Python handles globals badly. In-Reply-To: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> Message-ID: On Thu, Sep 3, 2015 at 1:05 PM, wrote: > If this would be under the developer responsibility than this > is simply achieved by giving well-written var names. So, adopt a rule whereby you prefix all your global variable names with "global" or "g_"? How is this superior to just declaring them once per function that needs to set them? You're just shifting the extra typing from one place to another. > Or does anyone really name a global var xxx and a function var xxx? > I am sure no one at all will do it. I dont want read such a code. Intentionally, it's probably rare. But if I'm adding a new variable, I shouldn't need to first make sure that it's safe to do so by scanning over the entire file to make sure that the name hasn't already been used elsewhere in the opposite scope. > Function calls (?) - > I have to admit I did not really get the problematic from > the sample provided by Chris Angelico. > > What I can see or mean to see is: > it has nothing to do with global-keyword from the high level point of > view: give write access, probably to the vars word and otherword. > > And yes, I see the vars independant. > And cause you set no "global" they are simple local vars > (readable+writeable) So in order for something to be global, it would have to be referenced at least once in the global scope? Currently it's possible to do this: def set_foo(value): global foo foo = value def get_foo(): return foo With your proposal that would change to: foo = None def set_foo(value): foo = value def get_foo(): return foo So again the declaration has just been moved from one place to another. > But then I ask you from high-level point of view > (if my high level view is correct at all): > Would you remove this keyword if it would be technically possible > or is good for you from high level point of view to have a keyword "global"? Provided that the proposal doesn't open up the possibility of unintentionally creating a global variable where I wanted a local, I'd be okay with it. From ian.g.kelly at gmail.com Thu Sep 3 15:51:56 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 Sep 2015 13:51:56 -0600 Subject: Python handles globals badly. In-Reply-To: References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> Message-ID: On Thu, Sep 3, 2015 at 1:47 PM, Ian Kelly wrote: > On Thu, Sep 3, 2015 at 1:05 PM, wrote: > >> But then I ask you from high-level point of view >> (if my high level view is correct at all): >> Would you remove this keyword if it would be technically possible >> or is good for you from high level point of view to have a keyword "global"? > > Provided that the proposal doesn't open up the possibility of > unintentionally creating a global variable where I wanted a local, I'd > be okay with it. Let me clarify that I'd be okay with making the keyword optional. It should probably still be kept around for the occasional use like this: exec("""def function(): global {0} {0} = 42 """.format('x')) where the compiler would have little hope of figuring out that the variable was meant to be global without it. From burak.arslan at arskom.com.tr Thu Sep 3 15:54:54 2015 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Thu, 3 Sep 2015 22:54:54 +0300 Subject: XML Binding In-Reply-To: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> References: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> Message-ID: <55E8A58E.8000002@arskom.com.tr> Hello, On 09/03/15 19:54, Palpandi wrote: > Hi All, > > Is there any module available in python standard library for XML binding? If not, any other suggestions. lxml is the right xml library to use. You can use lxml's objectify or Spyne. Here are some examples: http://stackoverflow.com/questions/19545067/python-joining-and-writing-xml-etrees-trees-stored-in-a-list > Which is good for parsing large file? > 1. XML binding > 2. Creating our own classes If you're dealing with huge files, I suggest using just lxml and work with raw data. Deserializing xml objects to python classes sure is nicer but has performance overhead that gets more and more visible as the amount of data you deal with grows. Best, Burak From anthra.norell at bluewin.ch Thu Sep 3 16:21:32 2015 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Thu, 03 Sep 2015 22:21:32 +0200 Subject: Reading \n unescaped from a file In-Reply-To: <55E8716B.4080600@medimorphosis.com.au> References: <55E65909.2080507@medimorphosis.com.au> <55E8078F.7090502@bluewin.ch> <55E8716B.4080600@medimorphosis.com.au> Message-ID: <55E8ABCC.7080101@bluewin.ch> On 09/03/2015 06:12 PM, Rob Hills wrote: > Hi Friedrich, > > On 03/09/15 16:40, Friedrich Rentsch wrote: >> On 09/02/2015 04:03 AM, Rob Hills wrote: >>> Hi, >>> >>> I am developing code (Python 3.4) that transforms text data from one >>> format to another. >>> >>> As part of the process, I had a set of hard-coded str.replace(...) >>> functions that I used to clean up the incoming text into the desired >>> output format, something like this: >>> >>> dataIn = dataIn.replace('\r', '\\n') # Tidy up linefeeds >>> dataIn = dataIn.replace('<','<') # Tidy up < character >>> dataIn = dataIn.replace('>','>') # Tidy up < character >>> dataIn = dataIn.replace('o','o') # No idea why but lots of >>> these: convert to 'o' character >>> dataIn = dataIn.replace('f','f') # .. and these: convert to >>> 'f' character >>> dataIn = dataIn.replace('e','e') # .. 'e' >>> dataIn = dataIn.replace('O','O') # .. 'O' >>> >>> These statements transform my data correctly, but the list of statements >>> grows as I test the data so I thought it made sense to store the >>> replacement mappings in a file, read them into a dict and loop through >>> that to do the cleaning up, like this: >>> >>> with open(fileName, 'r+t', encoding='utf-8') as mapFile: >>> for line in mapFile: >>> line = line.strip() >>> try: >>> if (line) and not line.startswith('#'): >>> line = line.split('#')[:1][0].strip() # trim >>> any trailing comments >>> name, value = line.split('=') >>> name = name.strip() >>> self.filterMap[name]=value.strip() >>> except: >>> self.logger.error('exception occurred parsing >>> line [{0}] in file [{1}]'.format(line, fileName)) >>> raise >>> >>> Elsewhere, I use the following code to do the actual cleaning up: >>> >>> def filter(self, dataIn): >>> if dataIn: >>> for token, replacement in self.filterMap.items(): >>> dataIn = dataIn.replace(token, replacement) >>> return dataIn >>> >>> >>> My mapping file contents look like this: >>> >>> \r = \\n >>> ??? = " >>> < = < >>> > = > >>> ' = ' >>> F = F >>> o = o >>> f = f >>> e = e >>> O = O >>> >>> This all works "as advertised" */except/* for the '\r' => '\\n' >>> replacement. Debugging the code, I see that my '\r' character is >>> "escaped" to '\\r' and the '\\n' to '\\\\n' when they are read in from >>> the file. >>> >>> I've been googling hard and reading the Python docs, trying to get my >>> head around character encoding, but I just can't figure out how to get >>> these bits of code to do what I want. >>> >>> It seems to me that I need to either: >>> >>> * change the way I represent '\r' and '\\n' in my mapping file; or >>> * transform them somehow when I read them in >>> >>> However, I haven't figured out how to do either of these. >>> >>> TIA, >>> >>> >> I have had this problem too and can propose a solution ready to run >> out of my toolbox: >> >> >> class editor: >> >> def compile (self, replacements): >> targets, substitutes = zip (*replacements) >> re_targets = [re.escape (item) for item in targets] >> re_targets.sort (reverse = True) >> self.targets_set = set (targets) >> self.table = dict (replacements) >> regex_string = '|'.join (re_targets) >> self.regex = re.compile (regex_string, re.DOTALL) >> >> def edit (self, text, eat = False): >> hits = self.regex.findall (text) >> nohits = self.regex.split (text) >> valid_hits = set (hits) & self.targets_set # Ignore targets >> with illegal re modifiers. >> if valid_hits: >> substitutes = [self.table [item] for item in hits if item >> in valid_hits] + [] # Make lengths equal for zip to work right >> if eat: >> output = ''.join (substitutes) >> else: >> zipped = zip (nohits, substitutes) >> output = ''.join (list (reduce (lambda a, b: a + b, >> [zipped][0]))) + nohits [-1] >> else: >> if eat: >> output = '' >> else: >> output = input >> return output >> >>>>> substitutions = ( >> ('\r', '\n'), >> ('<', '<'), >> ('>', '>'), >> ('o', 'o'), >> ('f', 'f'), >> ('e', 'e'), >> ('O', 'O'), >> ) >> >> Order doesn't matter. Add new ones at the end. >> >>>>> e = editor () >>>>> e.compile (substitutions) >> A simple way of testing is running the substitutions through the editor >> >>>>> print e.edit (repr (substitutions)) >> (('\r', '\n'), ('<', '<'), ('>', '>'), ('o', 'o'), ('f', 'f'), ('e', >> 'e'), ('O', 'O')) >> >> The escapes need to be tested separately >> >>>>> print e.edit ('abc\rdef') >> abc >> def >> >> Note: This editor's compiler compiles the substitution list to a >> regular expression which the editor uses to find all matches in the >> text passed to edit. There has got to be a limit to the size of a text >> which a regular expression can handle. I don't know what this limit >> is. To be on the safe side, edit a large text line by line or at least >> in sensible chunks. >> >> Frederic >> > Thanks for the suggestion. I had originally done a simple set of > hard-coded str.replace() functions which worked fine and are fast enough > for me not to have to delve into the complexity and obscurity of regex. > > I had also contemplated simply declaring my replacement dict in its own > .py file and then importing it. > > I ended up stubbornly pursuing the idea of loading everything from a > text file just because I didn't understand why it wasn't working. > > Cheers, > I'm sure you can do it with replace, except if your replacements add up into the dozens, it gets awkward, as you do the substitutions one by one on the whole text. But the real problem with this approach is that you are responsible for doing the replacements in the right sequence. It has been pointed out that order matters. What you want with overlapping targets is upstream takes precedence over downstream and longer over shorter. My suggestion automates this as it automates the construction of the regex. Peter Otten found one rough sport and one mistake: substitutes = [self.table [item] for item in hits if item in valid_hits] + [] Adding an empty list is totally useless and can be omitted. output = input Second last line should be; output = text Regards Frederic From lac at openend.se Thu Sep 3 18:10:43 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 04 Sep 2015 00:10:43 +0200 Subject: How do I real a SSL certs serial number using Python? In-Reply-To: References: Message-ID: <201509032210.t83MAhqi031175@fido.openend.se> Is this a good enough point? https://pyopenssl.readthedocs.org/en/stable/api/crypto.html?highlight=serial%20number#OpenSSL.crypto.X509.get_serial_number Write back if you need more help. Laura From breamoreboy at yahoo.co.uk Thu Sep 3 18:13:12 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 3 Sep 2015 23:13:12 +0100 Subject: Python handles globals badly. In-Reply-To: References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> Message-ID: On 03/09/2015 20:47, Ian Kelly wrote: > On Thu, Sep 3, 2015 at 1:05 PM, wrote: >> Or does anyone really name a global var xxx and a function var xxx? >> I am sure no one at all will do it. I dont want read such a code. > > Intentionally, it's probably rare. But if I'm adding a new variable, I > shouldn't need to first make sure that it's safe to do so by scanning > over the entire file to make sure that the name hasn't already been > used elsewhere in the opposite scope. > I'm just curious as I've never used it myself, but how does nonlocal https://docs.python.org/3/reference/simple_stmts.html#the-nonlocal-statement fit into this? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steveburrus28 at gmail.com Thu Sep 3 18:20:01 2015 From: steveburrus28 at gmail.com (Steve Burrus) Date: Thu, 3 Sep 2015 15:20:01 -0700 (PDT) Subject: Need Help w. PIP! Message-ID: Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? From lac at openend.se Thu Sep 3 18:26:46 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 04 Sep 2015 00:26:46 +0200 Subject: Porting Python Application to a new linux machine In-Reply-To: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: <201509032226.t83MQljK002749@fido.openend.se> In a message of Thu, 03 Sep 2015 07:32:55 -0700, Heli Nix writes: >Dear all, > >I have my python scripts that use several python libraries such as h5py, pyside, numpy.... > >In Windows I have an installer that will install python locally on user machine and so my program gets access to this local python and runs successfully. > >How can I do this in Linux ? ( I want to install python plus my program on the user machine.) I do not want to use the user?s python or to install python on the user?s machine on root. > >Thanks in Advance for your help, There are several approaches here. One is to get your users to run things in a virtualenv. see:https://virtualenv.pypa.io/en/latest/ and https://virtualenvwrapper.readthedocs.org/en/latest/ This works really well, but you have to have users who are capable of setting up a virtualenv in the first place. You will still run into problems of 'my shared library is different from your shared library'. YOu can also use PyInstaller (which you may have used to make windows binaries) to make linux ones. I've never done this, only made windows ones -- but that is what it says on the label. https://github.com/pyinstaller/pyinstaller/wiki I think you will still have to have a set of different files to download for different linux distributions, but I could be wrong about that. And if that problem is unacceptable, then you need docker. https://www.docker.com/ I've just started playing with it, and I think it is really neat, but it is too soon for me to have any clue what the problems/tradeoffs are with it. Laura From ian.g.kelly at gmail.com Thu Sep 3 18:45:37 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 3 Sep 2015 16:45:37 -0600 Subject: Python handles globals badly. In-Reply-To: References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> Message-ID: On Thu, Sep 3, 2015 at 4:13 PM, Mark Lawrence wrote: > On 03/09/2015 20:47, Ian Kelly wrote: >> >> On Thu, Sep 3, 2015 at 1:05 PM, wrote: >>> >>> Or does anyone really name a global var xxx and a function var xxx? >>> I am sure no one at all will do it. I dont want read such a code. >> >> >> Intentionally, it's probably rare. But if I'm adding a new variable, I >> shouldn't need to first make sure that it's safe to do so by scanning >> over the entire file to make sure that the name hasn't already been >> used elsewhere in the opposite scope. >> > > I'm just curious as I've never used it myself, but how does nonlocal > https://docs.python.org/3/reference/simple_stmts.html#the-nonlocal-statement > fit into this? I don't know whether the proposal also applies to nonlocals, but such conflicts would be less of an issue since you would only need to check the outermost function scope (and also, nested functions aren't really all that common). From srkunze at mail.de Thu Sep 3 19:01:16 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Fri, 04 Sep 2015 01:01:16 +0200 Subject: Strange location for a comma In-Reply-To: <55e83afb$0$3157$426a74cc@news.free.fr> References: <55e83afb$0$3157$426a74cc@news.free.fr> Message-ID: <55E8D13C.4030300@mail.de> On 03.09.2015 14:20, ast wrote: > Hello, > At the end of the last line of the following program, > there is a comma, I dont understand why ? > > Thx > > > from cx_Freeze import setup, Executable > > # On appelle la fonction setup > setup( > name = "salut", > version = "0.1", > description = "Ce programme vous dit bonjour", > executables = [Executable("salut.py")], # <--- HERE > ) > I know of several projects having this convention because when using a repository software like git, it leads to smaller and thus more readable diffs. Best, Sven From srkunze at mail.de Thu Sep 3 19:06:46 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Fri, 04 Sep 2015 01:06:46 +0200 Subject: Python handles globals badly. In-Reply-To: <253e3584-1d4d-4e6f-b42f-2cdbfa4ad785@googlegroups.com> References: <253e3584-1d4d-4e6f-b42f-2cdbfa4ad785@googlegroups.com> Message-ID: <55E8D286.3010403@mail.de> On 03.09.2015 00:25, tdev at freenet.de wrote: > It is the good idea of Python about modules which are singletons > and therefore have already its state (so in some way they are already somehow > like classes - except the bad annoying thing with the "global" statement). So, what you really want is a better language support for singletons? From srkunze at mail.de Thu Sep 3 19:25:08 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Fri, 04 Sep 2015 01:25:08 +0200 Subject: packing unpacking depends on order. In-Reply-To: <1441243045.413788.373350650.5DF79DE2@webmail.messagingengine.com> References: <55E6C904.3020602@rece.vub.ac.be> <55E73159.4050508@mail.de> <1441243045.413788.373350650.5DF79DE2@webmail.messagingengine.com> Message-ID: <55E8D6D4.20209@mail.de> On 03.09.2015 03:17, random832 at fastmail.us wrote: > > The question is what does "assign it to the left side at once" even > *mean* in the presence of subscripts? Build up a list of > object-subscript pairs (evaluating all the subscripts, including if any > may have side effects) before executing any __setitem__? I think Ian described how it could be done. > Why is the right side evaluated first? Because that's how things normally work. Evaluate the RHS and assign the value to the LHS. Currently, the generalization of a simple assignment is more like hopping back and forth around the "=". You mentioned side-effects. That is true. Right now, however, the side-effects even fire back to the RHS of the assignment. That is really weird. To me, and as it seems to some other folks here, the RHS should be at least independent of the LHS and vice versa. Both sides may have side-effects, but at least independently from each other. That's at least how I feel about it. Best, Sven From breamoreboy at yahoo.co.uk Thu Sep 3 20:05:17 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 4 Sep 2015 01:05:17 +0100 Subject: Need Help w. PIP! In-Reply-To: References: Message-ID: On 03/09/2015 23:20, Steve Burrus wrote: > Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? As always my main and spare crystal balls are at the menders due to overwork, so I'll have to ask, what happened when you tried the 'pip', 'get-pip.py' and 'easy-install.py' commands? What OS are you on? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From torriem at gmail.com Thu Sep 3 20:06:50 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 03 Sep 2015 18:06:50 -0600 Subject: Python handles globals badly. In-Reply-To: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> Message-ID: <55E8E09A.3080309@gmail.com> On 09/03/2015 01:05 PM, tdev at freenet.de wrote: > And a compiler can surely recognize if a defined var xxx outside is > not a var yyy inside a function. At issue here is the idea of Python namespaces and how Python uses them in a consistent way with your code. The consistency is that binding of a name to an object within a function is in the function's namespace. Makes things fast and simple. To facilitate writing to the module's namespace the global keyword is an elegant way of preserving consistency. But this has been said a few times I'm sure so we're going in circles here. > Or does anyone really name a global var xxx and a function var xxx? I > am sure no one at all will do it. Not sure I follow you here. What do the names programmers choose have to do with it? If I'm looking at a function, which should never be more than a screen of code long, if I see a reference to a variable that has never been assigned, I know it's defined in a parent scope. If I see as assignment, then I know it's local. If I see the word global then I know that any assignments are to the global namespace. Doesn't matter what the name is. It's consistent and explicit, which is one of Python's mantras, so I feel justified in defending this quirk/foible/feature of the language. > My answer is clear: remove it. But the global keyword serves a purpose. It's just different from the purpose you think you need. I get the impression you'd rather bend Python to your will, rather than work with it and learn the powerful Python idioms, which is just going to end in frustration. I don't think anyone would support a PEP to change python as you suggest (and it couldn't be done anytime soon until Python 4000 anyway). Seems a rather Quixote-esque quest you are on here. Spend some time to understand how Python variables differ from variables in other languages (most python "variables" are names bound to immutable objects like numbers). > [The same e.g. with switch statement: add it] Switch is a nice-to-have thing, but definitely not essential. A PEP here (probably already has been several) would at least be read anyway. However, there are several idiomatic ways of accomplishing the same thing that are often good enough and familiar to any Python programmer out there. Since functions are first-class objects, often a dispatch table is the best way to go here. From breamoreboy at yahoo.co.uk Thu Sep 3 20:47:32 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 4 Sep 2015 01:47:32 +0100 Subject: Python handles globals badly. In-Reply-To: <55E8E09A.3080309@gmail.com> References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> <55E8E09A.3080309@gmail.com> Message-ID: On 04/09/2015 01:06, Michael Torrie wrote: > On 09/03/2015 01:05 PM, tdev at freenet.de wrote: > >> [The same e.g. with switch statement: add it] > > Switch is a nice-to-have thing, but definitely not essential. A PEP here > (probably already has been several) would at least be read anyway. > However, there are several idiomatic ways of accomplishing the same > thing that are often good enough and familiar to any Python programmer > out there. Since functions are first-class objects, often a dispatch > table is the best way to go here. > https://www.python.org/dev/peps/pep-3103/ "A Switch/Case Statement" by Guido van Rossum, "Rejection Notice - A quick poll during my keynote presentation at PyCon 2007 shows this proposal has no popular support. I therefore reject it". https://www.python.org/dev/peps/pep-0275/ "Switching on Multiple Values" by Marc-Andr? Lemburg, "Rejection Notice - A similar PEP for Python 3000, PEP 3103 [2], was already rejected, so this proposal has no chance of being accepted either." -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steveburrus28 at gmail.com Thu Sep 3 21:04:33 2015 From: steveburrus28 at gmail.com (Steve Burrus) Date: Thu, 3 Sep 2015 18:04:33 -0700 (PDT) Subject: Need Help w. PIP! In-Reply-To: References: Message-ID: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> On Thursday, September 3, 2015 at 7:06:27 PM UTC-5, Mark Lawrence wrote: > On 03/09/2015 23:20, Steve Burrus wrote: > > Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? > > As always my main and spare crystal balls are at the menders due to > overwork, so I'll have to ask, what happened when you tried the 'pip', > 'get-pip.py' and 'easy-install.py' commands? What OS are you on? > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. From python at mrabarnett.plus.com Thu Sep 3 21:44:19 2015 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 4 Sep 2015 02:44:19 +0100 Subject: Need Help w. PIP! In-Reply-To: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> Message-ID: <55E8F773.1010500@mrabarnett.plus.com> On 2015-09-04 02:04, Steve Burrus wrote: > On Thursday, September 3, 2015 at 7:06:27 PM UTC-5, Mark Lawrence wrote: >> On 03/09/2015 23:20, Steve Burrus wrote: >> > Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? >> >> As always my main and spare crystal balls are at the menders due to >> overwork, so I'll have to ask, what happened when you tried the 'pip', >> 'get-pip.py' and 'easy-install.py' commands? What OS are you on? >> >> -- >> My fellow Pythonistas, ask not what our language can do for you, ask >> what you can do for our language. >> >> Mark Lawrence > > I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. > If you have Python 3.4, then you already have pip. It's in the "Scripts" subfolder of the Python 3.4 folder. From rosuav at gmail.com Thu Sep 3 21:55:32 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 11:55:32 +1000 Subject: Need Help w. PIP! In-Reply-To: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus wrote: > I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. > What happens if you type "python -m pip" ? Or "python3 -m pip"? Does that invoke pip? ChrisA From vincent.vande.vyvre at telenet.be Thu Sep 3 21:56:04 2015 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Fri, 4 Sep 2015 03:56:04 +0200 Subject: No request in module urllib ? Message-ID: <55E8FA34.8060600@telenet.be> Hi, Python 3.2.3 (default, Jun 18 2015, 21:46:42) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib >>> urllib.request.urlopen('http://example.org') Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'request' Same error with Python 3.4.0 From rosuav at gmail.com Thu Sep 3 22:04:13 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 12:04:13 +1000 Subject: packing unpacking depends on order. In-Reply-To: <55E8D6D4.20209@mail.de> References: <55E6C904.3020602@rece.vub.ac.be> <55E73159.4050508@mail.de> <1441243045.413788.373350650.5DF79DE2@webmail.messagingengine.com> <55E8D6D4.20209@mail.de> Message-ID: On Fri, Sep 4, 2015 at 9:25 AM, Sven R. Kunze wrote: > Both sides may have side-effects, but at least independently from each > other. That's at least how I feel about it. You can't do that, though. Every piece of Python code can cause arbitrary code to execute, and unless you run them in separate interpreters, they can affect each other. So Python MUST have a well-defined order of evaluation. ChrisA From steve at pearwood.info Thu Sep 3 22:05:41 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 04 Sep 2015 12:05:41 +1000 Subject: Python handles globals badly. References: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> Message-ID: <55e8fc75$0$1644$c3e8da3$5496439d@news.astraweb.com> On Fri, 4 Sep 2015 02:43 am, Michael Torrie wrote: > Sadly Skybuck probably ditched Python a long time ago "Sadly"? -- Steven From rosuav at gmail.com Thu Sep 3 22:08:07 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 12:08:07 +1000 Subject: No request in module urllib ? In-Reply-To: <55E8FA34.8060600@telenet.be> References: <55E8FA34.8060600@telenet.be> Message-ID: On Fri, Sep 4, 2015 at 11:56 AM, Vincent Vande Vyvre wrote: > Python 3.2.3 (default, Jun 18 2015, 21:46:42) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import urllib >>>> urllib.request.urlopen('http://example.org') > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute 'request' > > Same error with Python 3.4.0 With packages, like this, you sometimes need to explicitly import the piece you want. That way, the urllib module doesn't have to load everything up just because you wanted one small part. Try this instead: import urllib.request urllib.request.urlopen('http://example.org') Hope that helps! ChrisA From vincent.vande.vyvre at telenet.be Thu Sep 3 22:17:43 2015 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Fri, 4 Sep 2015 04:17:43 +0200 Subject: No request in module urllib ? In-Reply-To: References: <55E8FA34.8060600@telenet.be> Message-ID: <55E8FF47.409@telenet.be> Le 04/09/2015 04:08, Chris Angelico a ?crit : > On Fri, Sep 4, 2015 at 11:56 AM, Vincent Vande Vyvre > wrote: >> Python 3.2.3 (default, Jun 18 2015, 21:46:42) >> [GCC 4.6.3] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import urllib >>>>> urllib.request.urlopen('http://example.org') >> Traceback (most recent call last): >> File "", line 1, in >> AttributeError: 'module' object has no attribute 'request' >> >> Same error with Python 3.4.0 > With packages, like this, you sometimes need to explicitly import the > piece you want. That way, the urllib module doesn't have to load > everything up just because you wanted one small part. Try this > instead: > > import urllib.request > urllib.request.urlopen('http://example.org') > > Hope that helps! > > ChrisA Thanks, that works with 3.4.0. No with 3.2.3 Vincent From steve at pearwood.info Thu Sep 3 22:27:01 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 04 Sep 2015 12:27:01 +1000 Subject: Python handles globals badly. References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> Message-ID: <55e90175$0$1644$c3e8da3$5496439d@news.astraweb.com> On Fri, 4 Sep 2015 05:05 am, tdev at freenet.de wrote: > Or does anyone really name a global var xxx and a function var xxx? > I am sure no one at all will do it. I dont want read such a code. You should reflect on the purpose of namespaces and local variables. Some programming languages do not distinguish local and global variables. There are only variables, and they are shared by the entire program. That is terrible for encapsulation, because every time you use a variable, you have to stop and think whether that name is already being used *anywhere* else: def function(x): ... y = x + 1 What if y is being used somewhere else? You have just over-written the value of y that another part of the program relies on. Instead, most languages over the last 40 or 50 years have separate namespaces for variables. Each function's local variables are separate from every other function's locals: writing "y = x + 1" inside a function *cannot possibly* affect another function, if y is a local variable. So when writing a function, and creating local variables, you do not need to care whether the names you use have been used elsewhere. There is no need for every name in the entire program to be unique. The only time you need care is to avoid using the same name for a local and a global *that you intend to use*. If you don't intend to use it, there is no possible harm. Think about a program where last week I have written a function: def function(x): ... y = x + 1 y here is local to the function. Most commercial programs have dozens or hundreds of developers working on them (for something big like Microsoft Windows). Open source software might have thousands of developers. So today you come along and work on the same program as me, and you add a global variable: y = 999 What do you expect to happen? Do you think it is a good idea for your change *outside* of the function to suddenly change the meaning of the line "y = x + 1" *inside* the function? Fortunately, in Python, nothing changes. My function continues to work as before. You adding a global variable that happens to have the same name as one of my local variables does not break my function. Local variables are completely isolated to the function they are in. Which is exactly the way it should be. Worrying about local variables using the same name as globals is silly. The only time that is harmful is if you intend to use the global in a function but have a local of the same name. -- Steven From rosuav at gmail.com Thu Sep 3 22:30:47 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 12:30:47 +1000 Subject: No request in module urllib ? In-Reply-To: <55E8FF47.409@telenet.be> References: <55E8FA34.8060600@telenet.be> <55E8FF47.409@telenet.be> Message-ID: On Fri, Sep 4, 2015 at 12:17 PM, Vincent Vande Vyvre wrote: >> import urllib.request >> urllib.request.urlopen('http://example.org') >> > > Thanks, that works with 3.4.0. No with 3.2.3 Hmm, not sure why it wouldn't. According to the docs [1] it should be available. But I don't have a 3.2 anywhere around me now, so I can't check. (Steven D'Aprano no doubt can!) What happens when you try? ImportError? AttributeError? ChrisA [1] https://docs.python.org/3.2/library/urllib.request.html From steve at pearwood.info Thu Sep 3 22:33:53 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 04 Sep 2015 12:33:53 +1000 Subject: Python handles globals badly. References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> Message-ID: <55e90311$0$1641$c3e8da3$5496439d@news.astraweb.com> On Fri, 4 Sep 2015 05:05 am, tdev at freenet.de wrote: > Would you remove this keyword if it would be technically possible Absolutely not. I do not believe that it is technically possible, but even if it were, I would still argue that the Zen of Python applies: Explicit is better than implicit. Local variables should be the default, and you should explicitly declare any time you want to write to a global. Not the other way around, like Lua does. I've always thought that was silly: you should make the *desirable* thing easy to do, and the *dangerous* think (using globals) possible but not easy to do by accident. > or is good for you from high level point of view to have a keyword > "global"? Yes. > My answer is clear: remove it. > [The same e.g. with switch statement: add it] What would a switch statement do? How will it be different from if...elif? Out of the dozen or so different switch statements offered by other languages, which would you choose? -- Steven From python at mrabarnett.plus.com Thu Sep 3 22:41:07 2015 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 4 Sep 2015 03:41:07 +0100 Subject: No request in module urllib ? In-Reply-To: <55E8FF47.409@telenet.be> References: <55E8FA34.8060600@telenet.be> <55E8FF47.409@telenet.be> Message-ID: <55E904C3.3060606@mrabarnett.plus.com> On 2015-09-04 03:17, Vincent Vande Vyvre wrote: > Le 04/09/2015 04:08, Chris Angelico a ?crit : >> On Fri, Sep 4, 2015 at 11:56 AM, Vincent Vande Vyvre >> wrote: >>> Python 3.2.3 (default, Jun 18 2015, 21:46:42) >>> [GCC 4.6.3] on linux2 >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> import urllib >>>>>> urllib.request.urlopen('http://example.org') >>> Traceback (most recent call last): >>> File "", line 1, in >>> AttributeError: 'module' object has no attribute 'request' >>> >>> Same error with Python 3.4.0 >> With packages, like this, you sometimes need to explicitly import the >> piece you want. That way, the urllib module doesn't have to load >> everything up just because you wanted one small part. Try this >> instead: >> >> import urllib.request >> urllib.request.urlopen('http://example.org') >> >> Hope that helps! >> >> ChrisA > Thanks, that works with 3.4.0. No with 3.2.3 > It works for me with Python 3.2.5 on Windows. From vincent.vande.vyvre at telenet.be Thu Sep 3 22:49:31 2015 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Fri, 4 Sep 2015 04:49:31 +0200 Subject: No request in module urllib ? In-Reply-To: References: <55E8FA34.8060600@telenet.be> <55E8FF47.409@telenet.be> Message-ID: <55E906BB.8010807@telenet.be> Le 04/09/2015 04:30, Chris Angelico a ?crit : > On Fri, Sep 4, 2015 at 12:17 PM, Vincent Vande Vyvre > wrote: >>> import urllib.request >>> urllib.request.urlopen('http://example.org') >>> >> Thanks, that works with 3.4.0. No with 3.2.3 > Hmm, not sure why it wouldn't. According to the docs [1] it should be > available. But I don't have a 3.2 anywhere around me now, so I can't > check. (Steven D'Aprano no doubt can!) What happens when you try? > ImportError? AttributeError? > > ChrisA > > [1] https://docs.python.org/3.2/library/urllib.request.html Sorry, my fault, a typo in the import line. Vincent From breamoreboy at yahoo.co.uk Thu Sep 3 23:04:21 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 4 Sep 2015 04:04:21 +0100 Subject: Need Help w. PIP! In-Reply-To: References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> Message-ID: On 04/09/2015 02:55, Chris Angelico wrote: > On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus wrote: >> I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. >> > > What happens if you type "python -m pip" ? Or "python3 -m pip"? Does > that invoke pip? > > ChrisA > "python3 xyz" won't go on Windows. There are now three pip executables in the "Scripts" subfolder under the Python3.4 installation, pip.exe, pip3.exe and pip3.4.exe. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steveburrus28 at gmail.com Thu Sep 3 23:07:40 2015 From: steveburrus28 at gmail.com (Steve Burrus) Date: Thu, 3 Sep 2015 20:07:40 -0700 (PDT) Subject: Need Help w. PIP! In-Reply-To: References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> Message-ID: On Thursday, September 3, 2015 at 8:55:52 PM UTC-5, Chris Angelico wrote: > On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus wrote: > > I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. > > > > What happens if you type "python -m pip" ? Or "python3 -m pip"? Does > that invoke pip? > > ChrisA Well chris when I typed in"python -m pip" it worked but nopt with "python3 - m pip"! Why do you think that is? From rosuav at gmail.com Thu Sep 3 23:08:30 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 13:08:30 +1000 Subject: Need Help w. PIP! In-Reply-To: References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 1:04 PM, Mark Lawrence wrote: > On 04/09/2015 02:55, Chris Angelico wrote: >> >> On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus >> wrote: >>> >>> I have tried the 'python get-pip.py' command over amnd over again in my >>> command prompt and the 'python easy-install.py" command a little less. I >>> swear I have set ALL of the env. variables correctly! My OS is Windows 10 >>> Beta Preview Build 10074. >>> >> >> What happens if you type "python -m pip" ? Or "python3 -m pip"? Does >> that invoke pip? >> >> ChrisA >> > > "python3 xyz" won't go on Windows. There are now three pip executables in > the "Scripts" subfolder under the Python3.4 installation, pip.exe, pip3.exe > and pip3.4.exe. Not sure what you mean by "won't go", but I was just curious about whether there was some pathing issue that meant that the Scripts subfolder wasn't accessible, yet the main Python binary might have been. ChrisA From breamoreboy at yahoo.co.uk Thu Sep 3 23:11:35 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 4 Sep 2015 04:11:35 +0100 Subject: Need Help w. PIP! In-Reply-To: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> Message-ID: On 04/09/2015 02:04, Steve Burrus wrote: > On Thursday, September 3, 2015 at 7:06:27 PM UTC-5, Mark Lawrence wrote: >> On 03/09/2015 23:20, Steve Burrus wrote: >>> Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? >> >> As always my main and spare crystal balls are at the menders due to >> overwork, so I'll have to ask, what happened when you tried the 'pip', >> 'get-pip.py' and 'easy-install.py' commands? What OS are you on? >> >> -- >> My fellow Pythonistas, ask not what our language can do for you, ask >> what you can do for our language. >> >> Mark Lawrence > > I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. > I'm awfully sorry, but my crystal balls still aren't back from the menders, so let's try again. Precisely explain what happened when you tried the 'pip', 'get-pip.py' and 'easy-install.py' commands? Could it have been nuclear holocaust, ice cream dripping down your shirt front, something like "pip isn't recognised as a Windows command", or whatever the wording actually is, or even a Python traceback, in which case please cut and paste it, in full, here? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Thu Sep 3 23:16:00 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 13:16:00 +1000 Subject: Need Help w. PIP! In-Reply-To: References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 1:07 PM, Steve Burrus wrote: > On Thursday, September 3, 2015 at 8:55:52 PM UTC-5, Chris Angelico wrote: >> On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus wrote: >> > I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. >> > >> >> What happens if you type "python -m pip" ? Or "python3 -m pip"? Does >> that invoke pip? >> >> ChrisA > > Well chris when I typed in"python -m pip" it worked but nopt with "python3 > - m pip"! Why do you think that is? As Mark says, you're forcing us to use our crystal balls here. Just whether or not something "worked" is not sufficient; what happened? In XKCD 722 terms, what is the pattern of lights, and what are you expecting it to be? If I had to guess, I would suspect a problem with pathing in your Python 3 installation. ChrisA From breamoreboy at yahoo.co.uk Thu Sep 3 23:19:05 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 4 Sep 2015 04:19:05 +0100 Subject: No request in module urllib ? In-Reply-To: References: <55E8FA34.8060600@telenet.be> <55E8FF47.409@telenet.be> Message-ID: On 04/09/2015 03:30, Chris Angelico wrote: > On Fri, Sep 4, 2015 at 12:17 PM, Vincent Vande Vyvre > wrote: >>> import urllib.request >>> urllib.request.urlopen('http://example.org') >>> >> >> Thanks, that works with 3.4.0. No with 3.2.3 > > Hmm, not sure why it wouldn't. According to the docs [1] it should be > available. But I don't have a 3.2 anywhere around me now, so I can't > check. (Steven D'Aprano no doubt can!) What happens when you try? > ImportError? AttributeError? > > ChrisA > > [1] https://docs.python.org/3.2/library/urllib.request.html > If my understanding is correct, owing to the way the time machine works, Steven still has Python versions -3.6 to -0.1 running. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Thu Sep 3 23:27:47 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 4 Sep 2015 04:27:47 +0100 Subject: Need Help w. PIP! In-Reply-To: References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> Message-ID: On 04/09/2015 04:08, Chris Angelico wrote: > On Fri, Sep 4, 2015 at 1:04 PM, Mark Lawrence wrote: >> On 04/09/2015 02:55, Chris Angelico wrote: >>> >>> On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus >>> wrote: >>>> >>>> I have tried the 'python get-pip.py' command over amnd over again in my >>>> command prompt and the 'python easy-install.py" command a little less. I >>>> swear I have set ALL of the env. variables correctly! My OS is Windows 10 >>>> Beta Preview Build 10074. >>>> >>> >>> What happens if you type "python -m pip" ? Or "python3 -m pip"? Does >>> that invoke pip? >>> >>> ChrisA >>> >> >> "python3 xyz" won't go on Windows. There are now three pip executables in >> the "Scripts" subfolder under the Python3.4 installation, pip.exe, pip3.exe >> and pip3.4.exe. > > Not sure what you mean by "won't go", but I was just curious about > whether there was some pathing issue that meant that the Scripts > subfolder wasn't accessible, yet the main Python binary might have > been. > > ChrisA > python3 just doesn't exist on Windows, it's always python.exe or pythonw.exe. Not that I'd recommend using them in this day and age, py.exe or pyw.exe and specify your version via the command line or a shebang line in your script is certainly my preferred way of doing things. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Thu Sep 3 23:32:44 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 13:32:44 +1000 Subject: Need Help w. PIP! In-Reply-To: References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 1:27 PM, Mark Lawrence wrote: > python3 just doesn't exist on Windows, it's always python.exe or > pythonw.exe. Not that I'd recommend using them in this day and age, py.exe > or pyw.exe and specify your version via the command line or a shebang line > in your script is certainly my preferred way of doing things. Ohh. My bad. Sorry, Steve, I led you astray! Silly Windows, making it hard for people to just guess and be right. :) ChrisA From random832 at fastmail.us Thu Sep 3 23:36:40 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 03 Sep 2015 23:36:40 -0400 Subject: packing unpacking depends on order. In-Reply-To: <55E8D6D4.20209@mail.de> References: <55E6C904.3020602@rece.vub.ac.be> <55E73159.4050508@mail.de> <1441243045.413788.373350650.5DF79DE2@webmail.messagingengine.com> <55E8D6D4.20209@mail.de> Message-ID: <1441337800.230412.374445465.16C12305@webmail.messagingengine.com> On Thu, Sep 3, 2015, at 19:25, Sven R. Kunze wrote: > You mentioned side-effects. That is true. Right now, however, the > side-effects even fire back to the RHS of the assignment. That is really > weird. To me, and as it seems to some other folks here, the RHS should > be at least independent of the LHS and vice versa. You haven't demonstrated that the RHS is affected by anything. The sample code in the original post of this thread behaves identically if the RHS is a simple tuple of (2, 1) [or (1, 2)] respectively. If you have another sample that shows different behavior please post it. From palpandi111 at gmail.com Fri Sep 4 01:21:29 2015 From: palpandi111 at gmail.com (Palpandi) Date: Thu, 3 Sep 2015 22:21:29 -0700 (PDT) Subject: XML Binding In-Reply-To: References: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> Message-ID: <5f812239-e1f2-4ba6-aff3-59cf9758a787@googlegroups.com> Thanks Burak. lmxl is good. But it is not supported with python 2.5. Any other option? From rosuav at gmail.com Fri Sep 4 01:36:59 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 4 Sep 2015 15:36:59 +1000 Subject: XML Binding In-Reply-To: <5f812239-e1f2-4ba6-aff3-59cf9758a787@googlegroups.com> References: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> <5f812239-e1f2-4ba6-aff3-59cf9758a787@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 3:21 PM, Palpandi wrote: > Thanks Burak. > > lmxl is good. But it is not supported with python 2.5. Any other option? The latest version isn't. But PyPI has an older version which is: https://pypi.python.org/pypi/lxml/3.3.6 You should be able to install that into a Python 2.5. Though if you possibly can, I would recommend upgrading to 2.7. ChrisA From auriocus at gmx.de Fri Sep 4 01:43:19 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 04 Sep 2015 07:43:19 +0200 Subject: Porting Python Application to a new linux machine In-Reply-To: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: Am 03.09.15 um 16:32 schrieb Heli Nix: > I have my python scripts that use several python libraries such as > h5py, pyside, numpy.... > > In Windows I have an installer that will install python locally on > user machine and so my program gets access to this local python and > runs successfully. > > How can I do this in Linux ? ( I want to install python plus my > program on the user machine.) I do not want to use the user?s python > or to install python on the user?s machine on root. Another variant is the use of pyinstaller. It can generate a single directory with a copy of Python and all needed libraries. You can copy that to a different machine, and often it works - unless libc or some very basic library is different. Beware that this pulls in half of your system, so you'll end up with ~100 MB. Christian From nomail at invalid.com Fri Sep 4 02:16:10 2015 From: nomail at invalid.com (ast) Date: Fri, 4 Sep 2015 08:16:10 +0200 Subject: Need Help w. PIP! In-Reply-To: References: Message-ID: <55e9372e$0$3019$426a34cc@news.free.fr> "Steve Burrus" a ?crit dans le message de news:f0876c48-010e-4bf0-b687-dceefba97637 at googlegroups.com... Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? I am using python 3.4 on windows too and to run pip I just enter in a command window: py -m pip From nomail at invalid.com Fri Sep 4 02:24:38 2015 From: nomail at invalid.com (ast) Date: Fri, 4 Sep 2015 08:24:38 +0200 Subject: Need Help w. PIP! In-Reply-To: <55e9372e$0$3019$426a34cc@news.free.fr> References: <55e9372e$0$3019$426a34cc@news.free.fr> Message-ID: <55e9392b$0$3163$426a34cc@news.free.fr> "ast" a ?crit dans le message de news:55e9372e$0$3019$426a34cc at news.free.fr... > > "Steve Burrus" a ?crit dans le message de > news:f0876c48-010e-4bf0-b687-dceefba97637 at googlegroups.com... > Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having > the most extreme problems with simply typing "pip" into my command prompt and then getting back > the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file > then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of > the proper env. variables set. Can someone please help me? > > > I am using python 3.4 on windows too and to run pip I just enter in a command window: > > py -m pip > Just typing 'pip' as you do does't work because pip.exe is located in Python\Scripts directory which in not included on variable %PATH% From nick.a.sarbicki at gmail.com Fri Sep 4 02:43:10 2015 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Fri, 04 Sep 2015 06:43:10 +0000 Subject: Need Help w. PIP! In-Reply-To: <55e9392b$0$3163$426a34cc@news.free.fr> References: <55e9372e$0$3019$426a34cc@news.free.fr> <55e9392b$0$3163$426a34cc@news.free.fr> Message-ID: > Just typing 'pip' as you do does't work because pip.exe is located in Python\Scripts directory which in not included on variable %PATH% Is that new for win10? Just "pip" works fine on my win7 install. Although maybe I had to extend the path and forgot... - Nick On Fri, 4 Sep 2015 07:26 ast wrote: > > "ast" a ?crit dans le message de > news:55e9372e$0$3019$426a34cc at news.free.fr... > > > > "Steve Burrus" a ?crit dans le message de > > news:f0876c48-010e-4bf0-b687-dceefba97637 at googlegroups.com... > > Well I hjave certainly noted more than once that pip is cont ained in > Python 3.4. But I am having > > the most extreme problems with simply typing "pip" into my command > prompt and then getting back > > the normal information on pip! I have repeatedly downloaded [to my > Desktop] that get-pip.py file > > then ran it. I even downloaded that easy-install.py and ran that but to > no success! I have all of > > the proper env. variables set. Can someone please help me? > > > > > > I am using python 3.4 on windows too and to run pip I just enter in a > command window: > > > > py -m pip > > > > Just typing 'pip' as you do does't work because pip.exe is located in > Python\Scripts > directory which in not included on variable %PATH% > > -- > https://mail.python.org/mailman/listinfo/python-list > -- - Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Fri Sep 4 02:46:33 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 04 Sep 2015 08:46:33 +0200 Subject: XML Binding In-Reply-To: <5f812239-e1f2-4ba6-aff3-59cf9758a787@googlegroups.com> References: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> <5f812239-e1f2-4ba6-aff3-59cf9758a787@googlegroups.com> Message-ID: <201509040646.t846kXSS031674@fido.openend.se> In a message of Thu, 03 Sep 2015 22:21:29 -0700, Palpandi writes: >Thanks Burak. > >lmxl is good. But it is not supported with python 2.5. Any other option? >-- >https://mail.python.org/mailman/listinfo/python-list check and see what python you have. If 2.6 or more recent, use lxml If you have 2.5 use the slower elementtree. https://docs.python.org/2/library/xml.etree.elementtree.html If you pay attention to this http://lxml.de/compatibility.html you can mostly get away with writing your code once. Laura From lac at openend.se Fri Sep 4 02:54:57 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 04 Sep 2015 08:54:57 +0200 Subject: XML Binding In-Reply-To: <201509040646.t846kXSS031674@fido.openend.se> References: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> <5f812239-e1f2-4ba6-aff3-59cf9758a787@googlegroups.com> <201509040646.t846kXSS031674@fido.openend.se> Message-ID: <201509040654.t846svrr001471@fido.openend.se> In a message of Fri, 04 Sep 2015 08:46:33 +0200, Laura Creighton writes: >In a message of Thu, 03 Sep 2015 22:21:29 -0700, Palpandi writes: >>Thanks Burak. >> >>lmxl is good. But it is not supported with python 2.5. Any other option? >>-- >>https://mail.python.org/mailman/listinfo/python-list > >check and see what python you have. If 2.6 or more recent, use lxml >If you have 2.5 use the slower elementtree. >https://docs.python.org/2/library/xml.etree.elementtree.html > >If you pay attention to this >http://lxml.de/compatibility.html >you can mostly get away with writing your code once. > >Laura I didn't know about the old versions still available from pip. That is probably a better idea. Laura From lorenzofsutton at gmail.com Fri Sep 4 04:11:20 2015 From: lorenzofsutton at gmail.com (Lorenzo Sutton) Date: Fri, 4 Sep 2015 10:11:20 +0200 Subject: XML Binding In-Reply-To: <55E8A58E.8000002@arskom.com.tr> References: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> <55E8A58E.8000002@arskom.com.tr> Message-ID: <55E95228.4060804@gmail.com> Hi, On 03/09/2015 21:54, Burak Arslan wrote: > Hello, > > On 09/03/15 19:54, Palpandi wrote: >> Hi All, >> >> Is there any module available in python standard library for XML binding? If not, any other suggestions. > > lxml is the right xml library to use. You can use lxml's objectify or Spyne. I second lxml.. [...] >> Which is good for parsing large file? How large is large? I have used lxml (coupled with pygtk) with very good results on XML files up to around 250Mb. Lorenzo. From moinakb at gmail.com Fri Sep 4 05:36:55 2015 From: moinakb at gmail.com (moinakb at gmail.com) Date: Fri, 4 Sep 2015 02:36:55 -0700 (PDT) Subject: Python Package installation causing [Error 13] Permission Denied on Windows 7 Message-ID: <3edf469f-7062-4cbc-b9fa-f284ab2b10f3@googlegroups.com> I am running Python 3.4 on Windows 7 and is facing [Error 13] Permission Denied while installing Python packages such as SciPy, NumPy etc; here are the facts that I tried but failed: 1. I have admin privileges in my machine 2. The folder where pip/easy_install copies contents have full write for the user 3. I have tried Powershell with Unrestricted/RemoteSigned options This is the line in *.py code that is causing exception with open(target, 'wb') as f: f.write(data) What do I need to do to make this work? I am a windows domain user and obviously cannot run scripts with domain admin privileges. From anthra.norell at bluewin.ch Fri Sep 4 05:38:37 2015 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Fri, 04 Sep 2015 11:38:37 +0200 Subject: Reading \n unescaped from a file In-Reply-To: References: <55E65909.2080507@medimorphosis.com.au> <55E8078F.7090502@bluewin.ch> <55E84D1F.5040205@bluewin.ch> Message-ID: <55E9669D.8030209@bluewin.ch> My response was meant for the list, but went to Peter by mistake. So I repeat it with some delay: On 09/03/2015 04:24 PM, Peter Otten wrote: > Friedrich Rentsch wrote: > >> On 09/03/2015 11:24 AM, Peter Otten wrote: >>> Friedrich Rentsch wrote: >> I appreciate your identifying two mistakes. I am curious to know what >> they are. > Sorry for not being explicit. > >>>> substitutes = [self.table [item] for item in hits if item >>>> in valid_hits] + [] # Make lengths equal for zip to work right >>> That looks wrong... > You are adding an empty list here. I wondered what you were trying to > achieve with that. Right you are! It doesn't do anything. I remember my idea was to pad the substitutes list by one, because the list of intervening text segments is longer by one element and zip uses the least common length, discarding all overhang. The remedy was totally ineffective and, what's more, not needed, judging by the way the editor performs as expected. >>>> output = input >>> ...and so does this. > That seems to be the only occurence of the name "input" in your code. Did > you mean "text" or do you really want to return the built-in? > Right you are again! I did mean text. I changed a few names to make them more suggestive, and apparently missed this one. Frederic -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Fri Sep 4 06:27:05 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 04 Sep 2015 12:27:05 +0200 Subject: Python Package installation causing [Error 13] Permission Denied on Windows 7 In-Reply-To: <3edf469f-7062-4cbc-b9fa-f284ab2b10f3@googlegroups.com> References: <3edf469f-7062-4cbc-b9fa-f284ab2b10f3@googlegroups.com> Message-ID: <201509041027.t84AR5Ff022384@fido.openend.se> Over in the physics lab we have a big sign, which (translated) says: 'For windows 7, it is not enough to _be_ an admininstrator to install packages. When opening up the command prompt you also have to select the 'run as administrator' option.' No windows system here to test, but maybe this is your problem too. Laura From Dwight at GoldWinde.com Fri Sep 4 06:50:11 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Fri, 04 Sep 2015 18:50:11 +0800 Subject: Permission denied error in download nltk_data... Message-ID: Please help?(my apologizes?I got a response to this before, but I CANNOT find it now)? Using this code: import nltk nltk.download('maxent_treebank_pos_tagger?) I get this error: [nltk_data] Downloading package maxent_treebank_pos_tagger to [nltk_data] /Users/dwightgoldwindex/nltk_data... Traceback (most recent call last): File "test short.py", line 18, in nltk.download('maxent_treebank_pos_tagger') File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packag es/nltk/downloader.py", line 664, in download for msg in self.incr_download(info_or_id, download_dir, force): File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packag es/nltk/downloader.py", line 549, in incr_download for msg in self._download_package(info, download_dir, force): File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packag es/nltk/downloader.py", line 604, in _download_package os.mkdir(download_dir) PermissionError: [Errno 13] Permission denied: '/Users/dwightgoldwindex/nltk_data' BIG SMILE... Always, Dwight www.3forliving.key.to (video playlist on YouTube) www.couragebooks.key.to (all my books on Amazon) -- https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From moinakb at gmail.com Fri Sep 4 06:55:46 2015 From: moinakb at gmail.com (moinakb at gmail.com) Date: Fri, 4 Sep 2015 03:55:46 -0700 (PDT) Subject: Python Package installation causing [Error 13] Permission Denied on Windows 7 In-Reply-To: <3edf469f-7062-4cbc-b9fa-f284ab2b10f3@googlegroups.com> References: <3edf469f-7062-4cbc-b9fa-f284ab2b10f3@googlegroups.com> Message-ID: <97e5b9bd-97d1-4e3f-80fa-fb48a23f51b4@googlegroups.com> On Friday, September 4, 2015 at 3:07:19 PM UTC+5:30, moi... at gmail.com wrote: > I am running Python 3.4 on Windows 7 and is facing [Error 13] Permission Denied while installing Python packages such as SciPy, NumPy etc; here are the facts that I tried but failed: > 1. I have admin privileges in my machine > 2. The folder where pip/easy_install copies contents have full write for the user > 3. I have tried Powershell with Unrestricted/RemoteSigned options > This is the line in *.py code that is causing exception > > with open(target, 'wb') as f: > f.write(data) > > What do I need to do to make this work? I am a windows domain user and obviously cannot run scripts with domain admin privileges. And Yes, I do run command prompt with Admin privileges as well, but still it fails From lac at openend.se Fri Sep 4 08:11:18 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 04 Sep 2015 14:11:18 +0200 Subject: Permission denied error in download nltk_data... In-Reply-To: References: Message-ID: <201509041211.t84CBI9u015653@fido.openend.se> In a message of Fri, 04 Sep 2015 18:50:11 +0800, Dwight GoldWinde writes: >Please help?(my apologizes?I got a response to this before, but I CANNOT >find it now)? https://mail.python.org/pipermail/python-list/2015-August/695546.html Laura From joel.goldstick at gmail.com Fri Sep 4 09:00:22 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 4 Sep 2015 09:00:22 -0400 Subject: Permission denied error in download nltk_data... In-Reply-To: <201509041211.t84CBI9u015653@fido.openend.se> References: <201509041211.t84CBI9u015653@fido.openend.se> Message-ID: On Fri, Sep 4, 2015 at 8:11 AM, Laura Creighton wrote: > In a message of Fri, 04 Sep 2015 18:50:11 +0800, Dwight GoldWinde writes: >>Please help?(my apologizes?I got a response to this before, but I CANNOT >>find it now)? > > https://mail.python.org/pipermail/python-list/2015-August/695546.html > > Laura > -- > https://mail.python.org/mailman/listinfo/python-list Dwight, Please post in text only format. You seem to be using rich text format. Your email program can be configured not to do that. As to the error, what is the permission set for the file in question? Is your program logged in as a different user? -- Joel Goldstick http://joelgoldstick.com From invalid at invalid.invalid Fri Sep 4 09:16:15 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 4 Sep 2015 13:16:15 +0000 (UTC) Subject: Porting Python Application to a new linux machine References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: On 2015-09-04, Christian Gollwitzer wrote: > Am 03.09.15 um 16:32 schrieb Heli Nix: > >> I have my python scripts that use several python libraries such as >> h5py, pyside, numpy.... >> >> In Windows I have an installer that will install python locally on >> user machine and so my program gets access to this local python and >> runs successfully. >> >> How can I do this in Linux ? ( I want to install python plus my >> program on the user machine.) I do not want to use the user?s python >> or to install python on the user?s machine on root. > > Another variant is the use of pyinstaller. It can generate a single > directory with a copy of Python and all needed libraries. You can copy > that to a different machine, and often it works - unless libc or some > very basic library is different. Beware that this pulls in half of your > system, so you'll end up with ~100 MB. As an end-user of a number of largish Python applications on Linux, I don't think any of them use anything like pyinstaller (and I would not be very happy if they did -- I've likely got almost all of the required libraries already installed, and I don't need another copy of all that stuff on my machine that then has to be backed up). The normal way to distribute even large Python apps with a lot of required libraries is either as just the Python sources with a 'setup.py' file or as a package that tells the system what dependancies and libraries are required. If you don't want to ship bare sources, the "right" way to distribute a Python app for Linux is as an .rpm, .ebuild, or .deb. -- Grant Edwards grant.b.edwards Yow! An Italian is COMBING at his hair in suburban DES gmail.com MOINES! From srkunze at mail.de Fri Sep 4 10:25:12 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Fri, 04 Sep 2015 16:25:12 +0200 Subject: packing unpacking depends on order. In-Reply-To: <1441337800.230412.374445465.16C12305@webmail.messagingengine.com> References: <55E6C904.3020602@rece.vub.ac.be> <55E73159.4050508@mail.de> <1441243045.413788.373350650.5DF79DE2@webmail.messagingengine.com> <55E8D6D4.20209@mail.de> <1441337800.230412.374445465.16C12305@webmail.messagingengine.com> Message-ID: <55E9A9C8.2090300@mail.de> On 04.09.2015 05:36, random832 at fastmail.us wrote: > You haven't demonstrated that the RHS is affected by anything. The > sample code in the original post of this thread behaves identically if > the RHS is a simple tuple of (2, 1) [or (1, 2)] respectively. If you > have another sample that shows different behavior please post it. You are right. I was reconstructing the example and see what exactly happened here. Not sure what made me think the assignment would be broken up into its parts. That's definitely not the case. So, everything is fine. Side-effects happening on either side are unavoidable. Best, Sven From kwpolska at gmail.com Fri Sep 4 10:30:17 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Fri, 4 Sep 2015 16:30:17 +0200 Subject: Need Help w. PIP! In-Reply-To: References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> Message-ID: On 4 September 2015 at 15:14, Dennis Lee Bieber wrote: > On Fri, 4 Sep 2015 04:27:47 +0100, Mark Lawrence > declaimed the following: > > >>python3 just doesn't exist on Windows, it's always python.exe or > > Really? > > [snip] > 09/17/2013 12:37 AM 40,448 python.exe > 09/17/2013 12:37 AM 40,448 python3.3.exe > 09/17/2013 12:37 AM 40,448 python3.exe > 09/17/2013 12:37 AM 40,960 pythonw.exe > 09/17/2013 12:37 AM 40,960 pythonw3.3.exe > 09/17/2013 12:37 AM 40,960 pythonw3.exe > [snip] > > I did not create those variant files, they were part of my original > install from ActiveState. You are using an unofficial build of Python; the official one (from python.org) does not have `python3.exe`. -- Chris Warrick PGP: 5EAAEA16 From steveburrus28 at gmail.com Fri Sep 4 12:04:22 2015 From: steveburrus28 at gmail.com (Steve Burrus) Date: Fri, 4 Sep 2015 09:04:22 -0700 (PDT) Subject: Need Help w. PIP! In-Reply-To: References: Message-ID: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> On Thursday, September 3, 2015 at 5:20:17 PM UTC-5, Steve Burrus wrote: > Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? Well I think that this is a Win 10 "thing" befcause using previous versions of Windows all I had to do was to type in "pip" to get the pip info. but now apparently it's "python -m pip". Can someone please "set me straight" about the path I should be using if I have a "pathing" problem? From cody.piersall at gmail.com Fri Sep 4 12:35:00 2015 From: cody.piersall at gmail.com (Cody Piersall) Date: Fri, 4 Sep 2015 11:35:00 -0500 Subject: Need Help w. PIP! In-Reply-To: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 11:04 AM, Steve Burrus wrote: > > Well I think that this is a Win 10 "thing" befcause using previous versions of Windows all I had to do was to type in "pip" to get the pip info. but now apparently it's "python -m pip". Can someone please "set me straight" about the path I should be using if I have a "pathing" problem? If you installed Python to the default location, you should be able to find pip at "C:\Python34\Scripts\pip.exe". If you type "C:\Python34\Scripts\pip.exe" at the command prompt, you should be able to find pip. It seems pretty likely that your system path does not include that folder. You need to add that directory to your path if you want to be able to just type "pip". Cody -------------- next part -------------- An HTML attachment was scrubbed... URL: From steveburrus28 at gmail.com Fri Sep 4 12:35:11 2015 From: steveburrus28 at gmail.com (Steve Burrus) Date: Fri, 4 Sep 2015 09:35:11 -0700 (PDT) Subject: Need Help w. PIP! In-Reply-To: References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> Message-ID: <7c793e45-3a4c-4b37-8111-ed16382e1551@googlegroups.com> On Thursday, September 3, 2015 at 10:12:23 PM UTC-5, Mark Lawrence wrote: > On 04/09/2015 02:04, Steve Burrus wrote: > > On Thursday, September 3, 2015 at 7:06:27 PM UTC-5, Mark Lawrence wrote: > >> On 03/09/2015 23:20, Steve Burrus wrote: > >>> Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? > >> > >> As always my main and spare crystal balls are at the menders due to > >> overwork, so I'll have to ask, what happened when you tried the 'pip', > >> 'get-pip.py' and 'easy-install.py' commands? What OS are you on? > >> > >> -- > >> My fellow Pythonistas, ask not what our language can do for you, ask > >> what you can do for our language. > >> > >> Mark Lawrence > > > > I have tried the 'python get-pip.py' command over amnd over again in my command prompt and the 'python easy-install.py" command a little less. I swear I have set ALL of the env. variables correctly! My OS is Windows 10 Beta Preview Build 10074. > > > > I'm awfully sorry, but my crystal balls still aren't back from the > menders, so let's try again. Precisely explain what happened when you > tried the 'pip', 'get-pip.py' and 'easy-install.py' commands? Could it > have been nuclear holocaust, ice cream dripping down your shirt front, > something like "pip isn't recognised as a Windows command", or whatever > the wording actually is, or even a Python traceback, in which case > please cut and paste it, in full, here? > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence okay Mark her is what you haVE wanted of me : "C:\Users\SteveB>py -m pip Job information querying failed C:\Users\SteveB>python -m pip Usage: C:\Python34\python.exe -m pip [options] Commands: install Install packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. search Search PyPI for packages. wheel Build wheels from your requirements. help Show help for commands. General Options: -h, --help Show help. --isolated Run pip in an isolated mode, ignoring environment variables and user configuration. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. --log Path to a verbose appending log. --proxy Specify a proxy in the form [user:passwd@]proxy.server:port. --retries Maximum number of retries each connection should attempt (default 5 times). --timeout Set the socket timeout (default 15 seconds). --exists-action Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup. --trusted-host Mark this host as trusted, even though it does not have valid or any HTTPS. --cert Path to alternate CA bundle. --client-cert Path to SSL client certificate, a single file containing the private key and the certificate in PEM format. --cache-dir Store the cache data in . --no-cache-dir Disable the cache. --disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index." so why is it that the "python -m pip" command works but not the "py -m pip" command? And someone said I have a "pathing" problem [with my pip installation] can you please help me with that? From nick.a.sarbicki at gmail.com Fri Sep 4 12:44:20 2015 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Fri, 04 Sep 2015 16:44:20 +0000 Subject: Need Help w. PIP! In-Reply-To: <7c793e45-3a4c-4b37-8111-ed16382e1551@googlegroups.com> References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> <7c793e45-3a4c-4b37-8111-ed16382e1551@googlegroups.com> Message-ID: In the cmd "echo %path%" and send us the output. Also try to run "pip" as opposed to "python -m pip". Nick. On Fri, 4 Sep 2015 17:41 Steve Burrus wrote: > On Thursday, September 3, 2015 at 10:12:23 PM UTC-5, Mark Lawrence wrote: > > On 04/09/2015 02:04, Steve Burrus wrote: > > > On Thursday, September 3, 2015 at 7:06:27 PM UTC-5, Mark Lawrence > wrote: > > >> On 03/09/2015 23:20, Steve Burrus wrote: > > >>> Well I hjave certainly noted more than once that pip is cont ained > in Python 3.4. But I am having the most extreme problems with simply typing > "pip" into my command prompt and then getting back the normal information > on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file > then ran it. I even downloaded that easy-install.py and ran that but to no > success! I have all of the proper env. variables set. Can someone please > help me? > > >> > > >> As always my main and spare crystal balls are at the menders due to > > >> overwork, so I'll have to ask, what happened when you tried the 'pip', > > >> 'get-pip.py' and 'easy-install.py' commands? What OS are you on? > > >> > > >> -- > > >> My fellow Pythonistas, ask not what our language can do for you, ask > > >> what you can do for our language. > > >> > > >> Mark Lawrence > > > > > > I have tried the 'python get-pip.py' command over amnd over again in > my command prompt and the 'python easy-install.py" command a little less. I > swear I have set ALL of the env. variables correctly! My OS is Windows 10 > Beta Preview Build 10074. > > > > > > > I'm awfully sorry, but my crystal balls still aren't back from the > > menders, so let's try again. Precisely explain what happened when you > > tried the 'pip', 'get-pip.py' and 'easy-install.py' commands? Could it > > have been nuclear holocaust, ice cream dripping down your shirt front, > > something like "pip isn't recognised as a Windows command", or whatever > > the wording actually is, or even a Python traceback, in which case > > please cut and paste it, in full, here? > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > > > Mark Lawrence > > okay Mark her is what you haVE wanted of me : > > "C:\Users\SteveB>py -m pip > Job information querying failed > > C:\Users\SteveB>python -m pip > > Usage: > C:\Python34\python.exe -m pip [options] > > Commands: > install Install packages. > uninstall Uninstall packages. > freeze Output installed packages in requirements > format. > list List installed packages. > show Show information about installed packages. > search Search PyPI for packages. > wheel Build wheels from your requirements. > help Show help for commands. > > General Options: > -h, --help Show help. > --isolated Run pip in an isolated mode, ignoring > environment variables and user configuration. > -v, --verbose Give more output. Option is additive, and > can be > used up to 3 times. > -V, --version Show version and exit. > -q, --quiet Give less output. > --log Path to a verbose appending log. > --proxy Specify a proxy in the form > [user:passwd@]proxy.server:port. > --retries Maximum number of retries each connection > should > attempt (default 5 times). > --timeout Set the socket timeout (default 15 seconds). > --exists-action Default action when a path already exists: > (s)witch, (i)gnore, (w)ipe, (b)ackup. > --trusted-host Mark this host as trusted, even though it > does > not have valid or any HTTPS. > --cert Path to alternate CA bundle. > --client-cert Path to SSL client certificate, a single file > containing the private key and the > certificate > in PEM format. > --cache-dir Store the cache data in . > --no-cache-dir Disable the cache. > --disable-pip-version-check > Don't periodically check PyPI to determine > whether a new version of pip is available for > download. Implied with --no-index." > > so why is it that the "python -m pip" command works but not the "py -m > pip" command? And someone said I have a "pathing" problem [with my pip > installation] can you please help me with that? > -- > https://mail.python.org/mailman/listinfo/python-list > -- - Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From tdev at freenet.de Fri Sep 4 12:55:13 2015 From: tdev at freenet.de (tdev at freenet.de) Date: Fri, 4 Sep 2015 09:55:13 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: References: Message-ID: <83b54738-95d0-4d4a-b8e3-810894ed8388@googlegroups.com> Before responding (later) I have to add something additional first: Cause of complaints and while still exists and again and again: When I mentioned maybe OO first than for also this reason cause Python is a powerful language and supports procedural and OO features and many more. And cause a Python module is conceptually a singleton I recognized this as another feature of this language, nearly similiar to an OO-construct. So it is Pyhton itself what brings me to OO thaughts. >From knowing e.g Java as OO language I had no need to set such a keyword "global" to get write access to class members. And now the main point: Cause all of the features and especially the singleton construct, I could not believe that Python does nearly all for me but forces me then to use such a "ugly" keyword "global" in comparison to other OO languages. So OO and other comparisons where only to demonstrate how it is in other languages (and maybe for OO developers to enter this talk more easily) but not written to give comments going aside from this topic. But I agree, I should have better never mentioned it. Please lay OO and sharing globals aside. It is really about procedural programming and "global"-keyword only. That said I will really give no longer any comments about this. From cody.piersall at gmail.com Fri Sep 4 13:10:39 2015 From: cody.piersall at gmail.com (Cody Piersall) Date: Fri, 4 Sep 2015 12:10:39 -0500 Subject: Need Help w. PIP! In-Reply-To: References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 11:54 AM, Steve Burrus wrote: > I mcan assure you that the Scripts folder is in both my Users and the System path! I even haVE the folder "C:\Python34\lib\site-packages\django\bin" in the Path. But I still cannot simply type out "pip" without getti ng the usual error message! > > On Fri, Sep 4, 2015 at 11:35 AM, Cody Piersall wrote: >> If you installed Python to the default location, you should be able to find pip at "C:\Python34\Scripts\pip.exe". If you type "C:\Python34\Scripts\pip.exe" at the command prompt, you should be able to find pip. It seems pretty likely that your system path does not include that folder. You need to add that directory to your path if you want to be able to just type "pip". >> >> Cody > > (Responding on-list) I know you keep assuring us that your path is great, but we're not going to stop talking about it until you prove it to us, unfortunately. If you do this, you will prove it to us. In cmd, type "echo %PATH%", and then copy and paste both the command and the output. Like this: D:\Dropbox (Univ. of Oklahoma)\toshiba\hail\data>echo %PATH% C:\tools\ConEmu\ConEmu;C:\tools\ConEmu;C:\ProgramData\Oracle\Java\javapath;C:\tools;C:\MinGW\msys\1.0\bin;C:\MinGW\bin;C:\Python34\;C:\Python34\Scripts;C:\Python27\;C:\Python27\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin\;C:\Program Files\IVI Foundation\VISA\Win64\Bin\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin;C:\Program Files (x86)\IVI Foundation\IVI\bin;C:\Program Files\IVI Foundation\IVI\bin;C:\Program Files\TortoiseHg\;C:\Program Files (x86)\Git\cmd;C:\Program Files\MATLAB\R2014b\runtime\win64;C:\Program Files\MATLAB\R2014b\bin;C:\HashiCorp\Vagrant\bin;C:\Program Files (x86)\NSIS;C:\MinGW\msys\1.0;;C:\Program Files (x86)\Heroku\bin;C:\Program Files (x86)\git\cmd;C:\Users\pier3595\AppData\Local\atom\bin While you're at it, go ahead and type "pip" and show us the output of that too. Use copy and paste to do it. If you're not sure how to copy and paste with cmd, follow the instructions here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/windows_dos_copy.mspx?mfr=true -------------- next part -------------- An HTML attachment was scrubbed... URL: From cody.piersall at gmail.com Fri Sep 4 13:47:09 2015 From: cody.piersall at gmail.com (Cody Piersall) Date: Fri, 4 Sep 2015 12:47:09 -0500 Subject: Need Help w. PIP! In-Reply-To: References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 12:40 PM, Steve Burrus wrote: > > "C:\Python34\Tools\Scripts>python checkpip.py > The latest version of setuptools on PyPI is 18.2, but ensurepip has 12.0.5 > The latest version of pip on PyPI is 7.1.2, but ensurepip has 6.0.8" > > I ran this pythpon file, checkpip.py, and got the results above. Does that contribute to my inability to type "pip" normally? > Nah, I get the same thing. > On Fri, Sep 4, 2015 at 12:22 PM, Steve Burrus wrote: >> >> well I jhave already done this for Nick [Sarbicki] but here is the result of echo %path% : >> >> "echo %path% >> >> C:\Python34;C:\Python34\python.exe;C:\Python34\Scripts;C:\Python34\Lib\site-packages\django\bin;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\ProgramData\Oracle\Java\javapath;C:\Users\SteveB;C:\Users\SteveB;C:\OracleInst\app\oracle\product\11.2.0\server\bin;C:\Program Files\Broadcom\Broadcom 802.11\Driver;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;c:\Program Files (x86)\AMD APP\bin\x86_64;c:\Program Files (x86)\AMD APP\bin\x86;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Common Files\Roxio Shared\12.0\DLLShared\ ;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Go\bin;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files\Google\Cloud SDK\google-cloud-sdk\bin;C:\Users\SteveB\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files (x86)\bin;C:\bin;C:\Program Files\nodejs\;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\Brackets\command;C:\Program Files (x86)\Subversion\bin;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.4 >> >> Steve Burrus Your path looks right to me. Do you have pip.exe in C:\Python34\Scripts? Cody -------------- next part -------------- An HTML attachment was scrubbed... URL: From cody.piersall at gmail.com Fri Sep 4 14:03:57 2015 From: cody.piersall at gmail.com (Cody Piersall) Date: Fri, 4 Sep 2015 13:03:57 -0500 Subject: Need Help w. PIP! In-Reply-To: References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 12:50 PM, Steve Burrus wrote: > > "Do you have pip.exe in C:\Python34\Scripts?" well I remember seeing it in thar folder the other day but not now! D oes this mean I have to re-install python or just pip? Please respond to the list as well as the person you're actually talking to. It works out better for everyone that way. (You should just have to "reply all" instead of "reply"). You just need to reinstall pip: type python -m pip install --upgrade pip and you're set. Cody -------------- next part -------------- An HTML attachment was scrubbed... URL: From srkunze at mail.de Fri Sep 4 14:05:07 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Fri, 4 Sep 2015 20:05:07 +0200 Subject: Python handles globals badly. In-Reply-To: <83b54738-95d0-4d4a-b8e3-810894ed8388@googlegroups.com> References: <83b54738-95d0-4d4a-b8e3-810894ed8388@googlegroups.com> Message-ID: <55E9DD53.6080307@mail.de> On 04.09.2015 18:55, tdev at freenet.de wrote: > From knowing e.g Java as OO language I had no need to set > such a keyword "global" to get write access to class members. It is true and I really dislike Java for having this. Please consider this class MyClass: @classmethod def method(cls):attribute = 'a' cls.myattribute = 1234 As you see, even when using a class for the purpose, you still need to reference the class object somehow. > And now the main point: Cause all of the features and especially > the singleton construct, I could not believe that Python > does nearly all for me but forces me then to use such > a "ugly" keyword "global" in comparison to other OO languages. It is ugly, that is true. Would something like this help you? @modulemethod def method(mod): attribute = 'a' mod.myattribute = 123 Works like classmethod but on module level. You still need to explicitly specify from which namespace you want myattribute but that's the Python way I think. It applies to instance methods, class methods and all other types of Python code. > But I agree, I should have better never mentioned it. > Please lay OO and sharing globals aside. > > It is really about procedural programming and "global"-keyword only. > That said I will really give no longer any comments about this. That is sad. :( I at least would like to know if my suggestion would help? :) Best, Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From tdev at freenet.de Fri Sep 4 15:11:18 2015 From: tdev at freenet.de (tdev at freenet.de) Date: Fri, 4 Sep 2015 12:11:18 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: References: Message-ID: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> Now I want reflecting the latest answers: I think mostly everything is said. Maybe you skip directly to my conclusion on the end. -- Nevertheless I want grasp some points out where I think I could give a respective answer: "You are shifting declaration from one to another place" I would not say so: maybe it is a special prefix, but that you write once and not in every function (with additonal at least one "ugly" line of code). See no shifting here. And I think it cannot be duplicated elswhere cause you are in your single module's namespace. See no conflicts here. "You would create than all in one scope" (or "You would create namespace vulnerabilities") I would not say so: An enclosed code block has still its own scope. But if there is a global module var (e.g. recognized by a distinct name) inside this block than this var is from scope global. See no conflicts here. "Learn better Python" I am sure I am not alone (although the thread seems to isolate my opinion) And you maybe have recognized I have accepted that there is a need for "global". But admit I have to chew hard. See my conclusion. "Java have it ugly too" I would not say so: The examples providing with one var and one function does not reflecting real scenarios. Guess mostly classes have about 10 members and 10 functions. Each member about 10 chars long with 10 lines of code per function. seeing the global var inline is more readable than looking on the top of the function if the var is global or not + the addtional lines of code onyl cause making it global. I dislike @xxxx too (also in Java). See the contamination in that point still in Python. -- Conclusion: ----------- I think we can agree - that there are (unfortunately) low-level issues that makes the removing of "global" impossible. !? - and there are also special (dynamic) programming constructs where a keyword "global" makes sense and should be available !? I think for a scripting language this would be a good solution: when used then the compiler should definitive look in the global namespace, otherwise the compiler has some "magic" to distinct global from local (probably simply by varname and scope of birth) And yes it is not that I want change Python mantras. But Python philospy is so far I know: "There's a most understandable way to do something and that is how it should be done" But that says not: Do not change things that makes the life easier for a developer (escpecially who wants to do simple or powerful procedural/functional scripting). So for me there are 6 things that is somehow "masochistic" in Python cause with all its powerful features it is remarkable that it is not addable. So, If I had the power I would include following features (especially as we talk about scripting and cause why not (?), it would not harm anyone who does not want to use it (!)): all is optional (so hardcore Pythonier would probabyl deny to make use of it): 1. optional keyword "global" (if technical possible) 2. switch statement 3. less restrictive indentation (as if it would really matter forgetting an empty space somewhere if something is intended more right than is the context clear for me) 4. universal scope 5. goto label 6- "include" script statement (extending namespace to another script, like PHP) I think this would make Python even more popular than it is now. Not to say: I would really love it then. Last but not least: Why does javascript, as sripting language too, need not such things like a keyword "global". It also very powerful language with dynamic binding, OO, ... This is my question now. From steveburrus28 at gmail.com Fri Sep 4 15:31:15 2015 From: steveburrus28 at gmail.com (Steve Burrus) Date: Fri, 4 Sep 2015 14:31:15 -0500 Subject: Need Help w. PIP! In-Reply-To: References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> Message-ID: Well actually pip [at least a foolder called pip] is in the "C:\lib\site-packages" folder but not in any Scripts folder. Should it be in the Scripts folder? On Fri, Sep 4, 2015 at 1:03 PM, Cody Piersall wrote: > > > On Fri, Sep 4, 2015 at 12:50 PM, Steve Burrus > wrote: > > > > "Do you have pip.exe in C:\Python34\Scripts?" well I remember seeing it > in thar folder the other day but not now! D oes this mean I have to > re-install python or just pip? > > Please respond to the list as well as the person you're actually talking > to. It works out better for everyone that way. (You should just have to > "reply all" instead of "reply"). > > You just need to reinstall pip: type > > python -m pip install --upgrade pip > > and you're set. > > Cody > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Fri Sep 4 15:48:35 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 4 Sep 2015 13:48:35 -0600 Subject: Python handles globals badly. In-Reply-To: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 1:11 PM, wrote: > 6- "include" script statement (extending namespace to another script, like PHP) def include(filename): exec(open(filename).read()) > Last but not least: > Why does javascript, as sripting language too, need not such things like > a keyword "global". It also very powerful language with dynamic binding, OO, ... I thought you didn't want to talk about comparisons to other languages. :-P Javascript uses the same stupid system that Lua does, where *everything* is automatically global/nonlocal unless you specifically declare it as local. From ian.g.kelly at gmail.com Fri Sep 4 15:52:22 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 4 Sep 2015 13:52:22 -0600 Subject: Python handles globals badly. In-Reply-To: References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 1:48 PM, Ian Kelly wrote: > On Fri, Sep 4, 2015 at 1:11 PM, wrote: >> 6- "include" script statement (extending namespace to another script, like PHP) > > def include(filename): > exec(open(filename).read()) Sorry, that doesn't work because it takes locals from the include function. You probably need something more like this: def include(filename, globals): exec(open(filename).read(), globals) To be called like: include("foo.py", globals()) If you want to get fancy you could probably have include inspect the stack to pull the globals from the parent stack frame instead of explicitly passing them in. From breamoreboy at yahoo.co.uk Fri Sep 4 16:46:42 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 4 Sep 2015 21:46:42 +0100 Subject: Need Help w. PIP! In-Reply-To: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> Message-ID: On 04/09/2015 17:04, Steve Burrus wrote: > On Thursday, September 3, 2015 at 5:20:17 PM UTC-5, Steve Burrus wrote: >> Well I hjave certainly noted more than once that pip is cont ained in Python 3.4. But I am having the most extreme problems with simply typing "pip" into my command prompt and then getting back the normal information on pip! I have repeatedly downloaded [to my Desktop] that get-pip.py file then ran it. I even downloaded that easy-install.py and ran that but to no success! I have all of the proper env. variables set. Can someone please help me? > > Well I think that this is a Win 10 "thing" befcause using previous versions of Windows all I had to do was to type in "pip" to get the pip info. but now apparently it's "python -m pip". Can someone please "set me straight" about the path I should be using if I have a "pathing" problem? > Read https://docs.python.org/3/using/windows.html#excursus-setting-environment-variables and if you can install the Rapid Environment Editor http://www.rapidee.com/en/about -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Fri Sep 4 16:55:02 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 4 Sep 2015 21:55:02 +0100 Subject: Need Help w. PIP! In-Reply-To: References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> <7c793e45-3a4c-4b37-8111-ed16382e1551@googlegroups.com> Message-ID: On 04/09/2015 17:44, Nick Sarbicki wrote: > In the cmd "echo %path%" and send us the output. > > Also try to run "pip" as opposed to "python -m pip". > > Nick. > Will you please stop top posting, it's driving me nuts, thank you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From eryksun at gmail.com Fri Sep 4 17:50:41 2015 From: eryksun at gmail.com (eryksun) Date: Fri, 4 Sep 2015 16:50:41 -0500 Subject: Need Help w. PIP! In-Reply-To: <7c793e45-3a4c-4b37-8111-ed16382e1551@googlegroups.com> References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> <7c793e45-3a4c-4b37-8111-ed16382e1551@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 11:35 AM, Steve Burrus wrote: > > "C:\Users\SteveB>py -m pip > Job information querying failed You're using build 10074, an old build of Windows 10 that had a buggy Job object API. This was fixed in build 10159: http://bugs.python.org/issue24127 FYI, the py launcher runs Python in a job that's configured to kill Python if the the launcher gets killed. This is necessary if py.exe is started by a console shell such as cmd.exe or powershell.exe. The shell waits on py.exe, not python.exe. If the job didn't kill python.exe, then Python would compete with the shell for console input. From victorhooi at gmail.com Fri Sep 4 18:09:00 2015 From: victorhooi at gmail.com (Victor Hooi) Date: Fri, 4 Sep 2015 15:09:00 -0700 (PDT) Subject: Accumulating points in batch for sending off Message-ID: Hi, I'm using Python to parse out metrics from logfiles, and ship them off to a database called InfluxDB, using their Python driver (https://github.com/influxdb/influxdb-python). With InfluxDB, it's more efficient if you pack in more points into each message. Hence, I'm using the grouper() recipe from the itertools documentation (https://docs.python.org/3.6/library/itertools.html), to process the data in chunks, and then shipping off the points at the end of each chunk: def grouper(iterable, n, fillvalue=None): "Collect data into fixed-length chunks or blocks" # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx args = [iter(iterable)] * n return zip_longest(fillvalue=fillvalue, *args) .... for chunk in grouper(parse_iostat(f), 500): json_points = [] for block in chunk: if block: try: for i, line in enumerate(block): # DO SOME STUFF except ValueError as e: print("Bad output seen - skipping") client.write_points(json_points) print("Wrote in {} points to InfluxDB".format(len(json_points))) However, for some parsers, not every line will yield a datapoint. I'm wondering if perhaps rather than trying to chunk the input, it might be better off just calling len() on the points list each time, and sending it off when it's ready. E.g.: #!/usr/bin/env python3 json_points = [] _BATCH_SIZE = 2 for line_number, line in enumerate(open('blah.txt', 'r')): if 'cat' in line: print('Found cat on line {}'.format(line_number + 1 )) json_points.append(line_number) print("json_points contains {} points".format(len(json_points))) if len(json_points) >= _BATCH_SIZE: # print("json_points contains {} points".format(len(json_points))) print('Sending off points!') json_points = [] print("Loop finished. json_points contains {} points".format(len(json_points))) print('Sending off points!') Does the above seem reasonable? Any issues you see? Or are there any other more efficient approaches to doing this? From steveburrus28 at gmail.com Fri Sep 4 18:10:08 2015 From: steveburrus28 at gmail.com (Steve Burrus) Date: Fri, 4 Sep 2015 17:10:08 -0500 Subject: Need Help w. PIP! In-Reply-To: References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> <7c793e45-3a4c-4b37-8111-ed16382e1551@googlegroups.com> Message-ID: *so what is my hopefully sinple solution anyway? i do n't see myself anytime soon getting off of Build 10074 of Win 10. i don't have pip in the Scripts folder where I was told it should be. I was thinking of doing a complete disinstall/reinstall of Python 3.4 to see if that helps. * *On Fri, Sep 4, 2015 at 4:50 PM, eryksun > wrote:* > > > > > > > > > > > > > > > > > > *On Fri, Sep 4, 2015 at 11:35 AM, Steve Burrus > wrote: > > "C:\Users\SteveB>py -m pip > Job > information querying failed You're using build 10074, an old build of > Windows 10 that had a buggy Job object API. This was fixed in build 10159: > http://bugs.python.org/issue24127 FYI, > the py launcher runs Python in a job that's configured to kill Python if > the the launcher gets killed. This is necessary if py.exe is started by a > console shell such as cmd.exe or powershell.exe. The shell waits on py.exe, > not python.exe. If the job didn't kill python.exe, then Python would > compete with the shell for console input. * -------------- next part -------------- An HTML attachment was scrubbed... URL: From eryksun at gmail.com Fri Sep 4 18:48:14 2015 From: eryksun at gmail.com (eryksun) Date: Fri, 4 Sep 2015 17:48:14 -0500 Subject: Need Help w. PIP! In-Reply-To: References: <3b82cc84-d51b-4b62-bf84-47a06c585bc3@googlegroups.com> <7c793e45-3a4c-4b37-8111-ed16382e1551@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 5:10 PM, Steve Burrus wrote: > so what is my hopefully sinple solution anyway? i do n't see myself anytime > soon getting off of Build 10074 of Win 10. Script wrappers such as pip.exe are simple versions of the py launcher that execute an embedded script. For example, here's the script embedded in pip.exe on my system: #!"C:\Program Files\Python34\python.exe" # -*- coding: utf-8 -*- import re import sys from pip import main if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) sys.exit(main()) So, as with py.exe, the child python.exe process has to be assigned to a job object. That won't work as long as you're using build 10074 of Windows 10. But you can still run pip using `python -m pip`. Also, since the py launcher doesn't work on your system, you'll have to ensure that scripts are associated with python.exe / pythonw.exe instead of py.exe / pyw.exe. If you installed for all users you can do that in an elevated command prompt (cmd.exe) using the ftype command: ftype Python.File="C:\Python34\python.exe" "%1" %* ftype Python.NoConFile="C:\Python34\pythonw.exe" "%1" %* From kmisoft at gmail.com Fri Sep 4 20:05:47 2015 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Fri, 4 Sep 2015 20:05:47 -0400 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> Message-ID: > To me, marking a variable as global in a large number of functions is > a code smell that indicates that you're probably overusing globals. > Lua is an example of a language that takes the opposite approach: in > Lua, every variable is global unless you explicitly mark it as local. > Lua is a fine language overall, but that is one of my pet peeves with I had some experience programming in Lua and I'd say - that language is bad example to follow. Indexes start with 1 (I am not kidding) Single data type ("table") which could suddenly flip from "list" to "map" because you deleted one item. Has objects but has no classes. and so on... Vladimir http://itunes.apple.com/us/app/python-code-samples/id1025613117 From rosuav at gmail.com Fri Sep 4 20:27:05 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Sep 2015 10:27:05 +1000 Subject: Python handles globals badly. In-Reply-To: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> Message-ID: On Sat, Sep 5, 2015 at 5:11 AM, wrote: > 1. optional keyword "global" (if technical possible) As we've been saying in this thread, the problem isn't the technicalities of implementation, but the ambiguity of syntax. To eliminate the global statement, you need to either (a) declare all your globals at module level, the way C-like languages do, or (b) adorn every usage with either a magic naming convention or a dot-lookup. If you want the first one, well, there are languages like that, and you're welcome to use those. For the latter, it's easy enough to do something like this: import types _g = types.SimpleNamespace() def accumulate(x): _g.accum += x return _g.accum Look, Ma! No global statement! > 2. switch statement Check out the suggestions in PEP 3103. There are some plausible options, and the known problems with them. > 3. less restrictive indentation > (as if it would really matter forgetting an empty space somewhere > if something is intended more right than is the context clear for me) In the face of ambiguity, refuse the temptation to guess. Can you imagine the horrors if Python started guessing at indentation? count = 0 for file in files: for line in open(file): process(line) count += 1 It's obvious that process(line) goes inside the nested loop. What about the counter? Literally the only difference between "count the lines processed" and "count the files processed" is the indentation of one line. You could make these kinds of things unambiguous, but only by adding some other rule, like "always have a blank line at the end of a loop", which would be just as restrictive. > 4. universal scope You can inject stuff into the built-ins, is that good enough? > 5. goto label Already exists! http://entrian.com/goto/ > 6- "include" script statement (extending namespace to another script, like PHP) Ugh. There are a number of ways you can describe the semantics of "include", and you picked what is, in my opinion, the very worst. PHP's include operation switches back to HTML mode, which isn't itself unreasonable, but it highlights the fact that "starting in HTML mode" is stupid for any system of the size and complexity to want include(); but notably, it is *not* a simple text inclusion. You can include at top level, and that works fine (I think). You can include inside a function, and that mostly works (but it's not the same as dumping the source code in at that point). But you can't, for some bizarre reason, include inside a class definition. Not at all. Fortunately, it's easy enough to preprocess source code. And if you want that functionality in Python, that's probably the best way to do it, too. The only special I can think of would be to indent the file to the exact level that the #include directive is indented. (And yes, I think using "#include" in Python would be correct; that way, syntax highlighters read it as a comment.) Most of what you want can be done already. If you want the language to grow these features, you need to explain how the feature is different from what can already be done. ChrisA From rhills at medimorphosis.com.au Fri Sep 4 20:35:37 2015 From: rhills at medimorphosis.com.au (Rob Hills) Date: Sat, 5 Sep 2015 08:35:37 +0800 Subject: Need Help w. PIP! In-Reply-To: References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> Message-ID: <55EA38D9.6000303@medimorphosis.com.au> On 05/09/15 01:47, Cody Piersall wrote: > > On Fri, Sep 4, 2015 at 12:22 PM, Steve Burrus > > wrote: > <..> > >> "echo %path% > >> > >> C:\Python34;C:\Python34\python.exe;C:\Python34\Scripts; It's a long time since I last used Windoze in anger, but that second path entry (C:\Python34\python.exe;) looks wrong to me. Unless Windoze has changed recently, you shouldn't have a program name in your path. IIRC, that's going to break all path entries that follow it, so it could be the cause of your problem (ie the "C:\Python34\Scripts;" part won't be accessible. Perhaps try deleting the "C:\Python34\python.exe;" entry from your PATH environment variable and see what happens. HTH, -- Rob Hills Waikiki, Western Australia -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Sep 4 20:55:46 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 5 Sep 2015 01:55:46 +0100 Subject: Need Help w. PIP! In-Reply-To: <55EA38D9.6000303@medimorphosis.com.au> References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <55EA38D9.6000303@medimorphosis.com.au> Message-ID: <55EA3D92.5090702@mrabarnett.plus.com> On 2015-09-05 01:35, Rob Hills wrote: > On 05/09/15 01:47, Cody Piersall wrote: >> > On Fri, Sep 4, 2015 at 12:22 PM, Steve Burrus >> > wrote: >> > <..> >> >> "echo %path% >> >> >> >> C:\Python34;C:\Python34\python.exe;C:\Python34\Scripts; > > It's a long time since I last used Windoze in anger, but that second > path entry (C:\Python34\python.exe;) looks wrong to me. Unless Windoze > has changed recently, you shouldn't have a program name in your path. > IIRC, that's going to break all path entries that follow it, so it could > be the cause of your problem (ie the "C:\Python34\Scripts;" part won't > be accessible. > > Perhaps try deleting the "C:\Python34\python.exe;" entry from your PATH > environment variable and see what happens. > It should be a list of folder paths. Including a file path doesn't appear to break it, and, in fact, I'd be surprised if it did; it should just keep searching, much like it should if the folder were missing. From torriem at gmail.com Fri Sep 4 21:42:21 2015 From: torriem at gmail.com (Michael Torrie) Date: Fri, 04 Sep 2015 19:42:21 -0600 Subject: Python handles globals badly. In-Reply-To: References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> Message-ID: <55EA487D.2010807@gmail.com> On 09/04/2015 06:27 PM, Chris Angelico wrote: > If you want the first one, well, there are languages like that, and > you're welcome to use those. For the latter, it's easy enough to do > something like this: > > import types > _g = types.SimpleNamespace() > > def accumulate(x): > _g.accum += x > return _g.accum > > Look, Ma! No global statement! Since most of the time for me when I need a global, I need it to be an app global (more than just one module) and I use it to store configuration. So I just use another module for that. import my_global_module as _g _g.some_setting = 5 I get the impression, thought, that our esteemed poster is still trying to battle the Java windmill, but in Python now and will never accept anything we try to tell him about the Python way. Python does have its warts, but often attempts to fix the warts would just make things a lot worse. So I accept them as part of Python's character and try to use them to my advantage. From rosuav at gmail.com Fri Sep 4 21:54:30 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Sep 2015 11:54:30 +1000 Subject: Python handles globals badly. In-Reply-To: <55EA487D.2010807@gmail.com> References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> <55EA487D.2010807@gmail.com> Message-ID: On Sat, Sep 5, 2015 at 11:42 AM, Michael Torrie wrote: > On 09/04/2015 06:27 PM, Chris Angelico wrote: >> If you want the first one, well, there are languages like that, and >> you're welcome to use those. For the latter, it's easy enough to do >> something like this: >> >> import types >> _g = types.SimpleNamespace() >> >> def accumulate(x): >> _g.accum += x >> return _g.accum >> >> Look, Ma! No global statement! > > Since most of the time for me when I need a global, I need it to be an > app global (more than just one module) and I use it to store > configuration. So I just use another module for that. > > import my_global_module as _g > > _g.some_setting = 5 Yeah. Comes to the same thing; if you use a dotted lookup, it's not assigning to the global. Of course, you still have all the other concerns about globals. You've just buried them behind a level of indirection. > I get the impression, thought, that our esteemed poster is still trying > to battle the Java windmill, but in Python now and will never accept > anything we try to tell him about the Python way. Python does have its > warts, but often attempts to fix the warts would just make things a lot > worse. So I accept them as part of Python's character and try to use > them to my advantage. Indeed. The key to being a good programmer is not "write your code despite the language you're using", but "write the code in the language you're using". ChrisA From rhills at medimorphosis.com.au Fri Sep 4 22:19:55 2015 From: rhills at medimorphosis.com.au (Rob Hills) Date: Sat, 5 Sep 2015 10:19:55 +0800 Subject: Need Help w. PIP! In-Reply-To: <55EA3D92.5090702@mrabarnett.plus.com> References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <55EA38D9.6000303@medimorphosis.com.au> <55EA3D92.5090702@mrabarnett.plus.com> Message-ID: <55EA514B.4040801@medimorphosis.com.au> On 05/09/15 08:55, MRAB wrote: > On 2015-09-05 01:35, Rob Hills wrote: >> On 05/09/15 01:47, Cody Piersall wrote: >>> > On Fri, Sep 4, 2015 at 12:22 PM, Steve Burrus >>> > wrote: >>> >> <..> >>> >> "echo %path% >>> >> >>> >> C:\Python34;C:\Python34\python.exe;C:\Python34\Scripts; >> >> It's a long time since I last used Windoze in anger, but that second >> path entry (C:\Python34\python.exe;) looks wrong to me. Unless Windoze >> has changed recently, you shouldn't have a program name in your path. >> IIRC, that's going to break all path entries that follow it, so it could >> be the cause of your problem (ie the "C:\Python34\Scripts;" part won't >> be accessible. >> >> Perhaps try deleting the "C:\Python34\python.exe;" entry from your PATH >> environment variable and see what happens. >> > It should be a list of folder paths. Including a file path doesn't > appear to break it, and, in fact, I'd be surprised if it did; it should > just keep searching, much like it should if the folder were missing. You're probably right, but my recollection of Windoze is that it was very easily broken, hence my migration to Linux many moons ago. I reckon it wouldn't hurt to try getting rid of the invalid path entry anyway. Cheers, -- Rob Hills Waikiki, Western Australia From rustompmody at gmail.com Fri Sep 4 22:44:54 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 4 Sep 2015 19:44:54 -0700 (PDT) Subject: Hello In-Reply-To: References: Message-ID: On Thursday, September 3, 2015 at 10:37:04 AM UTC+5:30, Phuong Phan wrote: > Hi Python community, Hi Phuong Phan > I am new to Python and currently taking one online course of computer science and programming using Python. I really like Python because it is simple and clarity but powerful to me. > I just joint Python mailing list and i hope to enjoy Python programming discussion with you all. > Thank you, > phuong phan You're welcome! You may find the tutor list more useful for you if you are just beginning https://mail.python.org/mailman/listinfo/tutor From steveburrus28 at gmail.com Fri Sep 4 23:07:44 2015 From: steveburrus28 at gmail.com (Steve Burrus) Date: Fri, 4 Sep 2015 20:07:44 -0700 (PDT) Subject: Need Help w. PIP! In-Reply-To: References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <55EA38D9.6000303@medimorphosis.com.au> <55EA3D92.5090702@mrabarnett.plus.com> Message-ID: <6c8eba79-682e-4f78-a867-0da285ba754b@googlegroups.com> On Friday, September 4, 2015 at 9:20:14 PM UTC-5, Rob Hills wrote: > On 05/09/15 08:55, MRAB wrote: > > On 2015-09-05 01:35, Rob Hills wrote: > >> On 05/09/15 01:47, Cody Piersall wrote: > >>> > On Fri, Sep 4, 2015 at 12:22 PM, Steve Burrus > >>> > wrote: > >>> > >> <..> > >>> >> "echo %path% > >>> >> > >>> >> C:\Python34;C:\Python34\python.exe;C:\Python34\Scripts; > >> > >> It's a long time since I last used Windoze in anger, but that second > >> path entry (C:\Python34\python.exe;) looks wrong to me. Unless Windoze > >> has changed recently, you shouldn't have a program name in your path. > >> IIRC, that's going to break all path entries that follow it, so it could > >> be the cause of your problem (ie the "C:\Python34\Scripts;" part won't > >> be accessible. > >> > >> Perhaps try deleting the "C:\Python34\python.exe;" entry from your PATH > >> environment variable and see what happens. > >> > > It should be a list of folder paths. Including a file path doesn't > > appear to break it, and, in fact, I'd be surprised if it did; it should > > just keep searching, much like it should if the folder were missing. > > You're probably right, but my recollection of Windoze is that it was > very easily broken, hence my migration to Linux many moons ago. I > reckon it wouldn't hurt to try getting rid of the invalid path entry anyway. > well everyone there must be sometjhing about upgrading Python up to version 3.5 rc because everything works just fine now, beyond my wildest dreams! I am even able now to type in "pip" and get the usual info. on it and I have connected to the Django server and configured the admin so thanx for eveyone who tried to help me. From rustompmody at gmail.com Fri Sep 4 23:18:08 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 4 Sep 2015 20:18:08 -0700 (PDT) Subject: Program in or into (was Python handles globals badly) In-Reply-To: References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> <55EA487D.2010807@gmail.com> Message-ID: <03c53b53-4103-4fd8-8851-caeccda8e016@googlegroups.com> On Saturday, September 5, 2015 at 7:24:47 AM UTC+5:30, Chris Angelico wrote: > Indeed. The key to being a good programmer is not "write your code > despite the language you're using", but "write the code in the > language you're using". > A thought experiment for you Chris! Here's mergesort written in various languages http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort You could look at the java if you like but I think C# takes the cake. And of course also there's the python Now the thought experiment: For some reason you need to code in C# [You need to do this part of the experiment honestly!!] Would you write the C# code? Or would you write the python-ish code in C# ? From rosuav at gmail.com Fri Sep 4 23:31:53 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 5 Sep 2015 13:31:53 +1000 Subject: Program in or into (was Python handles globals badly) In-Reply-To: <03c53b53-4103-4fd8-8851-caeccda8e016@googlegroups.com> References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> <55EA487D.2010807@gmail.com> <03c53b53-4103-4fd8-8851-caeccda8e016@googlegroups.com> Message-ID: On Sat, Sep 5, 2015 at 1:18 PM, Rustom Mody wrote: > Now the thought experiment: > > For some reason you need to code in C# > [You need to do this part of the experiment honestly!!] > > Would you write the C# code? > Or would you write the python-ish code in C# ? As I'm not familiar with C#, I'd probably end up writing Python-style code in C#. But I wouldn't then complain that C# isn't sufficiently like Python; if I want Python, I know where to find it. ChrisA From eryksun at gmail.com Sat Sep 5 02:30:23 2015 From: eryksun at gmail.com (eryksun) Date: Sat, 5 Sep 2015 01:30:23 -0500 Subject: Need Help w. PIP! In-Reply-To: <6c8eba79-682e-4f78-a867-0da285ba754b@googlegroups.com> References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <55EA38D9.6000303@medimorphosis.com.au> <55EA3D92.5090702@mrabarnett.plus.com> <6c8eba79-682e-4f78-a867-0da285ba754b@googlegroups.com> Message-ID: On Fri, Sep 4, 2015 at 10:07 PM, Steve Burrus wrote: > well everyone there must be sometjhing about upgrading Python up to version 3.5 rc > because everything works just fine now, beyond my wildest dreams! I am even able > now to type in "pip" and get the usual info. on it and I have connected to the Django > server and configured the admin so thanx for eveyone who tried to help me. I just tested running pip.exe on a VM with Windows 10, build 10074. It surprised me that it worked, so I checked the source code of Vinay's [simple launcher][1]. Apparently the simpler launcher merely asserts that creating the job object succeeds, so it will only fail in a debug build. (See run_child in launcher.c). Depending on the nature of the script it could be confusing if there's no job object and the launcher gets killed. This leaves python.exe and the shell competing for console input. That said, it shouldn't really matter for a simple program such as pip. But the full py.exe launcher used by Python always fails if creating the job object doesn't succeed. (Oddly, it doesn't fail if *assigning* the child to the job fails; I guess because Windows 7 lacks support for job hierarchies, but still, it makes no sense to care about creating something that you don't care about using.) So for build 10074 of Windows 10, ensure the filetypes for .py and .pyw scripts (installed as Python.File and Python.NoConFile) run python.exe and pythonw.exe instead of py.exe and pyw.exe. Otherwise you won't be able to run scripts directly at the command prompt or by double clicking them in Explorer. [1]: https://bitbucket.org/vinay.sajip/simple_launcher/src From PointedEars at web.de Sat Sep 5 04:14:34 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Sat, 05 Sep 2015 10:14:34 +0200 Subject: Need Help w. PIP! References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> Message-ID: <2579215.WiH7nXzSoB@PointedEars.de> Cody Piersall wrote: > Please respond to the list as well as the person you're actually talking > to. It works out better for everyone that way. (You should just have to > "reply all" instead of "reply"). ?Better? as in ?getting/reading/downloading the same message *twice*?? The rule of thumb is: write here, read here. Please see my sig and reconsider. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From steveburrus28 at gmail.com Sat Sep 5 11:06:40 2015 From: steveburrus28 at gmail.com (Steve Burrus) Date: Sat, 5 Sep 2015 10:06:40 -0500 Subject: Need Help w. PIP! In-Reply-To: References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <55EA38D9.6000303@medimorphosis.com.au> <55EA3D92.5090702@mrabarnett.plus.com> <6c8eba79-682e-4f78-a867-0da285ba754b@googlegroups.com> Message-ID: *Boy "eryksun" I can certsainly tell that you are quite a technically - minded person! All that matters to me is that I can simply type "pip" at the command prompt without any problems. Well another [lesser] concern is that I can't use the regular Windows 10 instead of this Build 10074 of it.* * Steve Burrus * *On Sat, Sep 5, 2015 at 1:30 AM, eryksun > wrote:* > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > *On Fri, Sep 4, 2015 at 10:07 PM, Steve Burrus > wrote: > well everyone there must be sometjhing > about upgrading Python up to version 3.5 rc > because everything works just > fine now, beyond my wildest dreams! I am even able > now to type in "pip" > and get the usual info. on it and I have connected to the Django > server > and configured the admin so thanx for eveyone who tried to help me. I just > tested running pip.exe on a VM with Windows 10, build 10074. It surprised > me that it worked, so I checked the source code of Vinay's [simple > launcher][1]. Apparently the simpler launcher merely asserts that creating > the job object succeeds, so it will only fail in a debug build. (See > run_child in launcher.c). Depending on the nature of the script it could be > confusing if there's no job object and the launcher gets killed. This > leaves python.exe and the shell competing for console input. That said, it > shouldn't really matter for a simple program such as pip. But the full > py.exe launcher used by Python always fails if creating the job object > doesn't succeed. (Oddly, it doesn't fail if *assigning* the child to the > job fails; I guess because Windows 7 lacks support for job hierarchies, but > still, it makes no sense to care about creating something that you don't > care about using.) So for build 10074 of Windows 10, ensure the filetypes > for .py and .pyw scripts (installed as Python.File and Python.NoConFile) > run python.exe and pythonw.exe instead of py.exe and pyw.exe. Otherwise you > won't be able to run scripts directly at the command prompt or by double > clicking them in Explorer. [1]: > https://bitbucket.org/vinay.sajip/simple_launcher/src > * -------------- next part -------------- An HTML attachment was scrubbed... URL: From injectnique at gmail.com Sat Sep 5 12:45:47 2015 From: injectnique at gmail.com (injectnique at gmail.com) Date: Sat, 5 Sep 2015 09:45:47 -0700 (PDT) Subject: .py to .html generation In-Reply-To: <9aa631c6-485e-4ba6-9bb1-59feecdd608d@googlegroups.com> References: <9aa631c6-485e-4ba6-9bb1-59feecdd608d@googlegroups.com> Message-ID: On Thursday, September 3, 2015 at 1:04:45 AM UTC-4, uday3p... at gmail.com wrote: > Hi friends! > > Can some one help me with the best module and/or its tutorial, to generate html reports for python scripts? > > I tried pyreport and sphc; but, i am getting errors. https://github.com/dddomodossola/gui From steve at pearwood.info Sat Sep 5 22:35:09 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 06 Sep 2015 12:35:09 +1000 Subject: Program in or into (was Python handles globals badly) References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> <55EA487D.2010807@gmail.com> <03c53b53-4103-4fd8-8851-caeccda8e016@googlegroups.com> Message-ID: <55eba65d$0$1665$c3e8da3$5496439d@news.astraweb.com> On Sat, 5 Sep 2015 01:18 pm, Rustom Mody wrote: > Here's mergesort written in various languages > http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort > > You could look at the java if you like but I think C# takes the cake. > And of course also there's the python > > Now the thought experiment: > > For some reason you need to code in C# > [You need to do this part of the experiment honestly!!] > > Would you write the C# code? > Or would you write the python-ish code in C# ? That depends. Is the example C# code idiomatic for the language? Or was it written by somebody ignorant of C#, and consequently is a poor example of badly-written and unidiomatic "Java in C#"? If the first, then I expect I would write the C# code, because it is idiomatic and works. What would you do? It is certainly true that C# appears to be a more verbose language than Python. Based on this example, it prefers to use classes with methods rather than stand-alone functions, it requires static declarations, there's a lot of boilerplate needed to get things to work. It seems to lack some nice semantic features of Python, such as list slices and the ability to treat lists/arrays as first class values, that make Python so easy to work with. If C# lacks those features, how do you expect to use them? Lacking some of those features (or at least having significant downsides to the use of them) is why idiomatic C# or Java code looks the way it does. -- Steven From python at mrabarnett.plus.com Sat Sep 5 22:54:53 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 6 Sep 2015 03:54:53 +0100 Subject: Program in or into (was Python handles globals badly) In-Reply-To: <55eba65d$0$1665$c3e8da3$5496439d@news.astraweb.com> References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> <55EA487D.2010807@gmail.com> <03c53b53-4103-4fd8-8851-caeccda8e016@googlegroups.com> <55eba65d$0$1665$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55EBAAFD.4090902@mrabarnett.plus.com> On 2015-09-06 03:35, Steven D'Aprano wrote: > On Sat, 5 Sep 2015 01:18 pm, Rustom Mody wrote: > >> Here's mergesort written in various languages >> http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort >> >> You could look at the java if you like but I think C# takes the cake. >> And of course also there's the python >> >> Now the thought experiment: >> >> For some reason you need to code in C# >> [You need to do this part of the experiment honestly!!] >> >> Would you write the C# code? >> Or would you write the python-ish code in C# ? > > > That depends. Is the example C# code idiomatic for the language? Or was it > written by somebody ignorant of C#, and consequently is a poor example of > badly-written and unidiomatic "Java in C#"? > > If the first, then I expect I would write the C# code, because it is > idiomatic and works. What would you do? > > It is certainly true that C# appears to be a more verbose language than > Python. Based on this example, it prefers to use classes with methods > rather than stand-alone functions, it requires static declarations, there's > a lot of boilerplate needed to get things to work. It seems to lack some > nice semantic features of Python, such as list slices and the ability to > treat lists/arrays as first class values, that make Python so easy to work > with. If C# lacks those features, how do you expect to use them? > > Lacking some of those features (or at least having significant downsides to > the use of them) is why idiomatic C# or Java code looks the way it does. > C# and Java don't have functions. The closest you can get is static (class) methods. Note: C programs start with the "main" function. Java tries to follow that pattern, except that it doesn't have functions, so a static method "main" is used instead, which means that it also requires a class to hold it. Similarly, C has "sin" and "cos" functions. Java tries to follow that pattern, except that it doesn't have functions, so a static methods are used instead, which means that it also requires a class to hold them. And C# follows what Java does. From rustompmody at gmail.com Sun Sep 6 00:35:30 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 5 Sep 2015 21:35:30 -0700 (PDT) Subject: Program in or into (was Python handles globals badly) In-Reply-To: <55eba65d$0$1665$c3e8da3$5496439d@news.astraweb.com> References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> <55EA487D.2010807@gmail.com> <03c53b53-4103-4fd8-8851-caeccda8e016@googlegroups.com> <55eba65d$0$1665$c3e8da3$5496439d@news.astraweb.com> Message-ID: <19e2222b-83d8-450a-9943-aab0083cd101@googlegroups.com> On Sunday, September 6, 2015 at 8:05:28 AM UTC+5:30, Steven D'Aprano wrote: > On Sat, 5 Sep 2015 01:18 pm, Rustom Mody wrote: > > > Here's mergesort written in various languages > > http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort > > > > You could look at the java if you like but I think C# takes the cake. > > And of course also there's the python > > > > Now the thought experiment: > > > > For some reason you need to code in C# > > [You need to do this part of the experiment honestly!!] > > > > Would you write the C# code? > > Or would you write the python-ish code in C# ? > > > That depends. Is the example C# code idiomatic for the language? Or was it > written by somebody ignorant of C#, and consequently is a poor example of > badly-written and unidiomatic "Java in C#"? > > If the first, then I expect I would write the C# code, because it is > idiomatic and works. What would you do? I'd cringe And suspect malefide intent on the part of those who wrote that code to show C# in bad light :-) Thats partly joke because the java looks somewhat better and C# and Java are not very different My main point of course was that between the two extremes: 1. What the language mandates eg python mandates a ':' after the if condition C mandates that it be parenthesized 2. Matters of free personal taste there is a large in-between grey area where the language's 'keepers' recommend best (and not) practices which may not exactly be the best for a programmer. eg Consider perl and python. As for regex support they are mostly the same Yet a typical pythonista takes pride that he wrote a 10 line re-free function where a 2-line re would have sufficed A typical perl guy will take pleasure in exactly the opposite achievement A programmer wanting to get his job done need not believe any of these fads&fancies From random832 at fastmail.us Sun Sep 6 01:26:43 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Sun, 06 Sep 2015 01:26:43 -0400 Subject: Program in or into (was Python handles globals badly) In-Reply-To: <55eba65d$0$1665$c3e8da3$5496439d@news.astraweb.com> References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> <55EA487D.2010807@gmail.com> <03c53b53-4103-4fd8-8851-caeccda8e016@googlegroups.com> <55eba65d$0$1665$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1441517203.433414.375868617.213E33F1@webmail.messagingengine.com> Steven D'Aprano writes: > That depends. Is the example C# code idiomatic for the language? Not in the least. My first clue was Int32 - nobody actually uses those names. > Or was it > written by somebody ignorant of C#, and consequently is a poor example of > badly-written and unidiomatic "Java in C#"? > > If the first, then I expect I would write the C# code, because it is > idiomatic and works. What would you do? > > It is certainly true that C# appears to be a more verbose language than > Python. Based on this example, it prefers to use classes with methods > rather than stand-alone functions, You certainly need to put methods in a class, but it's absurd that they made it an actual instantiable class with instance properties for the variables they required for sorting, rather than there being a class that's just there as a container for the functions. I wouldn't do that in Java, either. They also gave it features a lot of the shorter versions on the page don't have; the ability to fall back to insertion sort for short lists, and the ability to tune exactly how it does that, and how many subsequences to sort and merge. From __peter__ at web.de Sun Sep 6 03:51:01 2015 From: __peter__ at web.de (Peter Otten) Date: Sun, 06 Sep 2015 09:51:01 +0200 Subject: Reading \n unescaped from a file References: <55E65909.2080507@medimorphosis.com.au> <55E8078F.7090502@bluewin.ch> <55E84D1F.5040205@bluewin.ch> <55E9669D.8030209@bluewin.ch> Message-ID: Friedrich Rentsch wrote: > My response was meant for the list, but went to Peter by mistake. So I > repeat it with some delay: > > On 09/03/2015 04:24 PM, Peter Otten wrote: >> Friedrich Rentsch wrote: >> >>> On 09/03/2015 11:24 AM, Peter Otten wrote: >>>> Friedrich Rentsch wrote: >>> I appreciate your identifying two mistakes. I am curious to know what >>> they are. >> Sorry for not being explicit. >> >>>>> substitutes = [self.table [item] for item in hits if >>>>> item >>>>> in valid_hits] + [] # Make lengths equal for zip to work right >>>> That looks wrong... >> You are adding an empty list here. I wondered what you were trying to >> achieve with that. > Right you are! It doesn't do anything. I remember my idea was to pad the > substitutes list by one, because the list of intervening text segments > is longer by one element and zip uses the least common length, > discarding all overhang. The remedy was totally ineffective and, what's > more, not needed, judging by the way the editor performs as expected. That's because you are getting the same effect later by adding nohits[-1] You could avoid that by replacing [] with [""]. >>> substitutes = list("12") >>> nohits = list("abc") >>> zipped = zip(nohits, substitutes) >>> "".join(list(reduce(lambda a, b: a+b, [zipped][0]))) + nohits[-1] 'a1b2c' >>> zipped = zip(nohits, substitutes + [""]) >>> "".join(list(reduce(lambda a, b: a+b, [zipped][0]))) 'a1b2c' By the way, even those who are into functional programming might find >>> "".join(map("".join, zipped)) 'a1b2c' more readable. But there's a more general change that I suggest: instead of processing the string twice, first to search for matches, then for the surrounding text you could achieve the same in one pass with a cool feature of the re.sub() method -- it accepts a function: >>> def replace(text, replacements): ... table = dict(replacements) ... def substitute(match): ... return table[match.group()] ... regex = "|".join(re.escape(find) for find, replace in replacements) ... return re.compile(regex).sub(substitute, text) ... >>> replace("1 foo 2 bar 1 baz", [("1", "one"), ("2", "two")]) 'one foo two bar one baz' From tropical.dude.net at gmail.com Sun Sep 6 07:50:23 2015 From: tropical.dude.net at gmail.com (tropical.dude.net at gmail.com) Date: Sun, 6 Sep 2015 04:50:23 -0700 (PDT) Subject: Can anyone help me run python scripts with http.server? Message-ID: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> Hello everyone, I want to use python for web development but I could not configure my Apache server to run python with the guides I found on the internet. Can anyone help me configure http.server to run python scripts? I ran the command python -m http.server --cgi to start the http server, and if I put index.html, I will see the page but if I use index.py, it doesn't show the page, I can only see the directory listing of the files and when I click on index.py, it doesn't run the code, I can see it just like in the editor. Can anyone help me out? Thanks in advance. From lac at openend.se Sun Sep 6 08:15:39 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 06 Sep 2015 14:15:39 +0200 Subject: Can anyone help me run python scripts with http.server? In-Reply-To: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> Message-ID: <201509061215.t86CFdXm028006@fido.openend.se> In a message of Sun, 06 Sep 2015 04:50:23 -0700, tropical.dude.net at gmail.com wr ites: >Hello everyone, > >I want to use python for web development but I >could not configure my Apache server to run python >with the guides I found on the internet. > >Can anyone help me configure http.server >to run python scripts? > >I ran the command python -m http.server --cgi to start the http server, >and if I put index.html, I will see the page but if I use >index.py, it doesn't show the page, I can only see the >directory listing of the files and when I click on >index.py, it doesn't run the code, I can see it just >like in the editor. > >Can anyone help me out? > >Thanks in advance. What operating system are you running? It sounds to me as if you haven't configured apache to add a Handler for python scripts, or you have, but forgot to restart apache after you did so. Laura From kwpolska at gmail.com Sun Sep 6 08:16:37 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Sun, 6 Sep 2015 14:16:37 +0200 Subject: Can anyone help me run python scripts with http.server? In-Reply-To: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> Message-ID: On 6 September 2015 at 13:50, wrote: > Hello everyone, > > I want to use python for web development but I > could not configure my Apache server to run python > with the guides I found on the internet. > > Can anyone help me configure http.server > to run python scripts? > > I ran the command python -m http.server --cgi to start the http server, > and if I put index.html, I will see the page but if I use > index.py, it doesn't show the page, I can only see the > directory listing of the files and when I click on > index.py, it doesn't run the code, I can see it just > like in the editor. > > Can anyone help me out? > > Thanks in advance. > -- > https://mail.python.org/mailman/listinfo/python-list Don?t use http.server. Don?t use CGI. This is not how things work in Python. In Python, you should use a web framework to write your code. Web frameworks include Flask, Django, Pyramid? Find one that?s popular and that you like, and learn that. You won?t have any `.py` URLs, instead you will have modern pretty URLs with no extensions. And a lot of things will be abstracted ? no manual header creation, help with safe forms and databases. And then you will need to figure out how to run it. I personally use nginx and uwsgi for this, you may need to look for something else. Examples for Django: https://docs.djangoproject.com/en/1.8/#first-steps https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ -- Chris Warrick PGP: 5EAAEA16 From lac at openend.se Sun Sep 6 08:28:26 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 06 Sep 2015 14:28:26 +0200 Subject: Can anyone help me run python scripts with http.server? In-Reply-To: References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> Message-ID: <201509061228.t86CSQOw031115@fido.openend.se> In a message of Sun, 06 Sep 2015 14:16:37 +0200, Chris Warrick writes: >Don?t use http.server. Don?t use CGI. This is not how things work in Python. > >In Python, you should use a web framework to write your code. Web >frameworks include Flask, Django, Pyramid? Find one that?s popular and >that you like, and learn that. You won?t have any `.py` URLs, instead >you will have modern pretty URLs with no extensions. And a lot of >things will be abstracted ? no manual header creation, help with safe >forms and databases. This is really great advice, and if your idea is 'but I don't want anything as _big_ as a framework, look at flask http://flask.pocoo.org/ and bottle http://bottlepy.org/docs/dev/index.html both of which are tiny microframeworks. Laura From __peter__ at web.de Sun Sep 6 08:32:06 2015 From: __peter__ at web.de (Peter Otten) Date: Sun, 06 Sep 2015 14:32:06 +0200 Subject: Can anyone help me run python scripts with http.server? References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> Message-ID: tropical.dude.net at gmail.com wrote: > I want to use python for web development but I > could not configure my Apache server to run python > with the guides I found on the internet. > > Can anyone help me configure http.server > to run python scripts? > > I ran the command python -m http.server --cgi to start the http server, > and if I put index.html, I will see the page but if I use > index.py, it doesn't show the page, I can only see the > directory listing of the files and when I click on > index.py, it doesn't run the code, I can see it just > like in the editor. > > Can anyone help me out? While in the long run you're better off if you follow Chris' advice here's a minimal cgi script run with http.server (I'm using curl instead of a browser). $ mkdir cgi-bin $ echo -e '#!/usr/bin/env python3\nprint("Content-type:text/plain")\nprint()\nprint("Hello, world")' > cgi-bin/index.py $ chmod u+x cgi-bin/index.py $ python3 -m http.server --cgi & [1] 12345 $ Serving HTTP on 0.0.0.0 port 8000 ... $ curl http://localhost:8000/cgi-bin/index.py 127.0.0.1 - - [06/Sep/2015 14:30:23] "GET /cgi-bin/index.py HTTP/1.1" 200 - Hello, world $ From tropical.dude.net at gmail.com Sun Sep 6 08:35:49 2015 From: tropical.dude.net at gmail.com (tropical.dude.net at gmail.com) Date: Sun, 6 Sep 2015 05:35:49 -0700 (PDT) Subject: Can anyone help me run python scripts with http.server? In-Reply-To: References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> Message-ID: On Sunday, September 6, 2015 at 2:16:04 PM UTC+2, Laura Creighton wrote: > In a message of Sun, 06 Sep 2015 04:50:23 -0700, tropical.dude.net at gmail.com wr > ites: > >Hello everyone, > > > >I want to use python for web development but I > >could not configure my Apache server to run python > >with the guides I found on the internet. > > > >Can anyone help me configure http.server > >to run python scripts? > > > >I ran the command python -m http.server --cgi to start the http server, > >and if I put index.html, I will see the page but if I use > >index.py, it doesn't show the page, I can only see the > >directory listing of the files and when I click on > >index.py, it doesn't run the code, I can see it just > >like in the editor. > > > >Can anyone help me out? > > > >Thanks in advance. > > What operating system are you running? It sounds to me as if you haven't > configured apache to add a Handler for python scripts, or you have, but > forgot to restart apache after you did so. > > Laura I am using Windows 7, I followed the instructions, modified httpd.conf many times, restarted apache many times till I gave up From tropical.dude.net at gmail.com Sun Sep 6 08:38:50 2015 From: tropical.dude.net at gmail.com (tropical.dude.net at gmail.com) Date: Sun, 6 Sep 2015 05:38:50 -0700 (PDT) Subject: Can anyone help me run python scripts with http.server? In-Reply-To: References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> Message-ID: <31ec836b-4cb0-4079-8c12-f6b66a5cd143@googlegroups.com> On Sunday, September 6, 2015 at 2:16:04 PM UTC+2, Laura Creighton wrote: > In a message of Sun, 06 Sep 2015 04:50:23 -0700, tropical.dude.net at gmail.com wr > ites: > >Hello everyone, > > > >I want to use python for web development but I > >could not configure my Apache server to run python > >with the guides I found on the internet. > > > >Can anyone help me configure http.server > >to run python scripts? > > > >I ran the command python -m http.server --cgi to start the http server, > >and if I put index.html, I will see the page but if I use > >index.py, it doesn't show the page, I can only see the > >directory listing of the files and when I click on > >index.py, it doesn't run the code, I can see it just > >like in the editor. > > > >Can anyone help me out? > > > >Thanks in advance. > > What operating system are you running? It sounds to me as if you haven't > configured apache to add a Handler for python scripts, or you have, but > forgot to restart apache after you did so. > > Laura I am using Windows 7, I followed the instructions, modified httpd.conf many times, restarted apache many times till I gave up From tropical.dude.net at gmail.com Sun Sep 6 08:42:23 2015 From: tropical.dude.net at gmail.com (tropical.dude.net at gmail.com) Date: Sun, 6 Sep 2015 05:42:23 -0700 (PDT) Subject: Can anyone help me run python scripts with http.server? In-Reply-To: References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> Message-ID: <75f7fbea-ef68-48cc-b3b7-512e7febdd77@googlegroups.com> On Sunday, September 6, 2015 at 2:16:04 PM UTC+2, Laura Creighton wrote: > In a message of Sun, 06 Sep 2015 04:50:23 -0700, wr > ites: > >Hello everyone, > > > >I want to use python for web development but I > >could not configure my Apache server to run python > >with the guides I found on the internet. > > > >Can anyone help me configure http.server > >to run python scripts? > > > >I ran the command python -m http.server --cgi to start the http server, > >and if I put index.html, I will see the page but if I use > >index.py, it doesn't show the page, I can only see the > >directory listing of the files and when I click on > >index.py, it doesn't run the code, I can see it just > >like in the editor. > > > >Can anyone help me out? > > > >Thanks in advance. > > What operating system are you running? It sounds to me as if you haven't > configured apache to add a Handler for python scripts, or you have, but > forgot to restart apache after you did so. > > Laura I am using Windows 7, I followed the instructions, modified httpd.conf many times, restarted apache many times till I gave up From __peter__ at web.de Sun Sep 6 08:43:21 2015 From: __peter__ at web.de (Peter Otten) Date: Sun, 06 Sep 2015 14:43:21 +0200 Subject: Can anyone help me run python scripts with http.server? References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> Message-ID: Peter Otten wrote: > tropical.dude.net at gmail.com wrote: > >> I want to use python for web development but I >> could not configure my Apache server to run python >> with the guides I found on the internet. >> >> Can anyone help me configure http.server >> to run python scripts? >> >> I ran the command python -m http.server --cgi to start the http server, >> and if I put index.html, I will see the page but if I use >> index.py, it doesn't show the page, I can only see the >> directory listing of the files and when I click on >> index.py, it doesn't run the code, I can see it just >> like in the editor. >> >> Can anyone help me out? > > While in the long run you're better off if you follow Chris' advice here's and also in the short run (using the already mentioned bottle): $ echo '#!/usr/bin/env python3 > import bottle > @bottle.route("/into/the/blue/") > def demo(name): > return bottle.template("Hello, {{name}}", name=name) > bottle.run()' > demo.py $ python3 demo.py & [2] 54321 $ Bottle v0.12.7 server starting up (using WSGIRefServer())... Listening on http://127.0.0.1:8080/ Hit Ctrl-C to quit. $ curl "http://localhost:8080/into/the/blue/Mountain" 127.0.0.1 - - [06/Sep/2015 14:41:44] "GET /into/the/blue/Mountain HTTP/1.1" 200 15 Hello, Mountain$ curl "http://localhost:8080/into/the/blue/Green%20Pastries" 127.0.0.1 - - [06/Sep/2015 14:41:47] "GET /into/the/blue/Green%20Pastries HTTP/1.1" 200 21 Hello, Green Pastries$ > a minimal cgi script run with http.server (I'm using curl instead of a > browser). > > $ mkdir cgi-bin > $ echo -e '#!/usr/bin/env > python3\nprint("Content-type:text/plain")\nprint()\nprint("Hello, world")' > > cgi-bin/index.py $ chmod u+x cgi-bin/index.py $ python3 -m http.server > --cgi & > [1] 12345 > $ Serving HTTP on 0.0.0.0 port 8000 ... > > $ curl http://localhost:8000/cgi-bin/index.py > 127.0.0.1 - - [06/Sep/2015 14:30:23] "GET /cgi-bin/index.py HTTP/1.1" 200 > - Hello, world > $ From anthra.norell at bluewin.ch Sun Sep 6 08:43:37 2015 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Sun, 06 Sep 2015 14:43:37 +0200 Subject: Reading \n unescaped from a file In-Reply-To: References: <55E65909.2080507@medimorphosis.com.au> <55E8078F.7090502@bluewin.ch> <55E84D1F.5040205@bluewin.ch> <55E9669D.8030209@bluewin.ch> Message-ID: <55EC34F9.4030108@bluewin.ch> On 09/06/2015 09:51 AM, Peter Otten wrote: > Friedrich Rentsch wrote: > >> My response was meant for the list, but went to Peter by mistake. So I >> repeat it with some delay: >> >> On 09/03/2015 04:24 PM, Peter Otten wrote: >>> Friedrich Rentsch wrote: >>> >>>> On 09/03/2015 11:24 AM, Peter Otten wrote: >>>>> Friedrich Rentsch wrote: >>>> I appreciate your identifying two mistakes. I am curious to know what >>>> they are. >>> Sorry for not being explicit. >>> >>>>>> substitutes = [self.table [item] for item in hits if >>>>>> item >>>>>> in valid_hits] + [] # Make lengths equal for zip to work right >>>>> That looks wrong... >>> You are adding an empty list here. I wondered what you were trying to >>> achieve with that. >> Right you are! It doesn't do anything. I remember my idea was to pad the >> substitutes list by one, because the list of intervening text segments >> is longer by one element and zip uses the least common length, >> discarding all overhang. The remedy was totally ineffective and, what's >> more, not needed, judging by the way the editor performs as expected. > That's because you are getting the same effect later by adding > > nohits[-1] > > You could avoid that by replacing [] with [""]. > >>>> substitutes = list("12") >>>> nohits = list("abc") >>>> zipped = zip(nohits, substitutes) >>>> "".join(list(reduce(lambda a, b: a+b, [zipped][0]))) + nohits[-1] > 'a1b2c' >>>> zipped = zip(nohits, substitutes + [""]) >>>> "".join(list(reduce(lambda a, b: a+b, [zipped][0]))) > 'a1b2c' > > By the way, even those who are into functional programming might find > >>>> "".join(map("".join, zipped)) > 'a1b2c' > > more readable. > > But there's a more general change that I suggest: instead of processing the > string twice, first to search for matches, then for the surrounding text you > could achieve the same in one pass with a cool feature of the re.sub() > method -- it accepts a function: > >>>> def replace(text, replacements): > ... table = dict(replacements) > ... def substitute(match): > ... return table[match.group()] > ... regex = "|".join(re.escape(find) for find, replace in replacements) > ... return re.compile(regex).sub(substitute, text) > ... >>>> replace("1 foo 2 bar 1 baz", [("1", "one"), ("2", "two")]) > 'one foo two bar one baz' > > I didn't think of using sub. But you're right. It is better, likely faster too. Building the regex reversed sorted will make it handle overlapping targets correctly, e.g.: r = ( ("1", "one"), ("2", "two"), ("12", "twelve"), ) Your function as posted: replace ('1 foo 2 bar 12 baz', r) 'one foo two bar onetwo baz' regex = "|".join(re.escape(find) for find, replace in reversed (sorted (replacements))) replace ('1 foo 2 bar 12 baz', r) 'one foo two bar twelve baz' Thanks for the hints Frederic From lac at openend.se Sun Sep 6 08:45:36 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 06 Sep 2015 14:45:36 +0200 Subject: Can anyone help me run python scripts with http.server? In-Reply-To: <31ec836b-4cb0-4079-8c12-f6b66a5cd143@googlegroups.com> References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> <31ec836b-4cb0-4079-8c12-f6b66a5cd143@googlegroups.com> Message-ID: <201509061245.t86CjaXd002900@fido.openend.se> In a message of Sun, 06 Sep 2015 05:38:50 -0700, tropical.dude.net at gmail.com wr ites: >> What operating system are you running? It sounds to me as if you haven't >> configured apache to add a Handler for python scripts, or you have, but >> forgot to restart apache after you did so. >> >> Laura > >I am using Windows 7, I followed the instructions, modified httpd.conf >many times, restarted apache many times till I gave up I'm not a Windows user. You are going to have to get help with this from somebody else. Though I forgot to send you this list: https://wiki.python.org/moin/WebFrameworks/ if you decide that investigating Python web frameworks is what you want to do. Laura From tropical.dude.net at gmail.com Sun Sep 6 08:47:42 2015 From: tropical.dude.net at gmail.com (tropical.dude.net at gmail.com) Date: Sun, 6 Sep 2015 05:47:42 -0700 (PDT) Subject: Can anyone help me run python scripts with http.server? In-Reply-To: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> Message-ID: On Sunday, September 6, 2015 at 1:51:00 PM UTC+2, tropical... at gmail.com wrote: > Hello everyone, > > I want to use python for web development but I > could not configure my Apache server to run python > with the guides I found on the internet. > > Can anyone help me configure http.server > to run python scripts? > > I ran the command python -m http.server --cgi to start the http server, > and if I put index.html, I will see the page but if I use > index.py, it doesn't show the page, I can only see the > directory listing of the files and when I click on > index.py, it doesn't run the code, I can see it just > like in the editor. > > Can anyone help me out? > > Thanks in advance. Thanks for the replies, I know of django, I even saw some youtube videos about it but it seems very complicated to me. From tropical.dude.net at gmail.com Sun Sep 6 09:07:05 2015 From: tropical.dude.net at gmail.com (tropical.dude.net at gmail.com) Date: Sun, 6 Sep 2015 06:07:05 -0700 (PDT) Subject: Can anyone help me run python scripts with http.server? In-Reply-To: References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> <31ec836b-4cb0-4079-8c12-f6b66a5cd143@googlegroups.com> Message-ID: <361cf277-b469-4873-891d-0153498794ef@googlegroups.com> On Sunday, September 6, 2015 at 2:46:42 PM UTC+2, Laura Creighton wrote: > In a message of Sun, 06 Sep 2015 05:38:50 -0700, tropical.dude.net at gmail.com wr > ites: > > >> What operating system are you running? It sounds to me as if you haven't > >> configured apache to add a Handler for python scripts, or you have, but > >> forgot to restart apache after you did so. > >> > >> Laura > > > >I am using Windows 7, I followed the instructions, modified httpd.conf > >many times, restarted apache many times till I gave up > > I'm not a Windows user. You are going to have to get help with this > from somebody else. > > Though I forgot to send you this list: > https://wiki.python.org/moin/WebFrameworks/ > > if you decide that investigating Python web frameworks is what you want to > do. > > Laura Thank you very much. I will definitely look into python web frameworks in the future, they seem complicated to me compared to php for example. I am looking for the simplest way to test my python scripts till I understand better how it works and when I can configure my own web server to run the framework because I want develop my stuff offline. From rosuav at gmail.com Sun Sep 6 09:23:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 6 Sep 2015 23:23:14 +1000 Subject: Can anyone help me run python scripts with http.server? In-Reply-To: <361cf277-b469-4873-891d-0153498794ef@googlegroups.com> References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> <31ec836b-4cb0-4079-8c12-f6b66a5cd143@googlegroups.com> <361cf277-b469-4873-891d-0153498794ef@googlegroups.com> Message-ID: On Sun, Sep 6, 2015 at 11:07 PM, wrote: > I will definitely look into python web frameworks in the future, they seem > complicated to me compared to php for example. I am looking for the simplest > way to test my python scripts till I understand better how it works and when > I can configure my own web server to run the framework because I want develop my > stuff offline. Look into Flask. You can do something really simple: https://github.com/Rosuav/MinstrelHall All the code is in one file for simplicity, though for a larger project, you can break it up as required. (Compared to PHP, where you're _forced_ to have exactly one file per entry-point, this is a nice flexibility.) Then I just have one line in my Apache config file that looks something like this: WSGIScriptAlias / /path/to/scripts/MinstrelHall/mh.wsgi and Apache does all the rest. There's some cruft in that code to get around a few oddities, but for the most part, writing a page is as simple as writing a function, decorated to manage routing, that returns render_template("somefile.html"). It's pretty easy. ChrisA From lac at openend.se Sun Sep 6 11:03:40 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 06 Sep 2015 17:03:40 +0200 Subject: Can anyone help me run python scripts with http.server? In-Reply-To: <361cf277-b469-4873-891d-0153498794ef@googlegroups.com> References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> <31ec836b-4cb0-4079-8c12-f6b66a5cd143@googlegroups.com> <361cf277-b469-4873-891d-0153498794ef@googlegroups.com> Message-ID: <201509061503.t86F3em8004355@fido.openend.se> In a message of Sun, 06 Sep 2015 06:07:05 -0700, tropical.dude.net at gmail.com wr ites: >Thank you very much. > >I will definitely look into python web frameworks in the future, they seem >complicated to me compared to php for example. I am looking for the simplest >way to test my python scripts till I understand better how it works and when >I can configure my own web server to run the framework because I want develop my >stuff offline. I think that bottle or flask won't seem complicated to you .... As I was walking around town it occurred to me to ask if you have made your something.py file executable? I don't even know if apache on windows cares about such things, though if you are using cgi and a unix like system you will need to do this. Laura From rosuav at gmail.com Sun Sep 6 11:13:36 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Sep 2015 01:13:36 +1000 Subject: Can anyone help me run python scripts with http.server? In-Reply-To: <201509061503.t86F3em8004355@fido.openend.se> References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> <31ec836b-4cb0-4079-8c12-f6b66a5cd143@googlegroups.com> <361cf277-b469-4873-891d-0153498794ef@googlegroups.com> <201509061503.t86F3em8004355@fido.openend.se> Message-ID: On Mon, Sep 7, 2015 at 1:03 AM, Laura Creighton wrote: > As I was walking around town it occurred to me to ask if you have > made your something.py file executable? I don't even know if > apache on windows cares about such things, though if you are using cgi > and a unix like system you will need to do this. Windows doesn't have that concept, so it's not necessary. ChrisA From srkunze at mail.de Sun Sep 6 13:33:29 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Sun, 6 Sep 2015 19:33:29 +0200 Subject: Wheels For ... Message-ID: <55EC78E9.1050300@mail.de> Hi folks, currently, I came across http://pythonwheels.com/ during researching how to make a proper Python distribution for PyPI. I thought it would be great idea to tell other maintainers to upload their content as wheels so I approached a couple of them. Some of them already provided wheels. Happy being able to have built my own distribution, I discussed the issue at hand with some people and I would like to share my findings and propose some ideas: 1) documentation is weirdly split up/distributed and references old material 2) once up and running (setup.cfg, setup.py etc. etc.) it works but everybody needs to do it on their own 3) more than one way to do (upload, wheel, source/binary etc.) it (sigh) 4) making contact to propose wheels on github or per email is easy otherwise almost impossible or very tedious 5) reactions went evenly split from "none", "yes", "when ready" to "nope" None: well, okay yes: that's good when ready: well, okay nope: what a pity for wheels; example: https://github.com/simplejson/simplejson/issues/122 I personally find the situation not satisfying. Someone proposes the following solution in form of a question: Why do developers need to build their distribution themselves? I had not real answer to him, but pondering a while over it, I found it really insightful. Viewing this from a different angle, packaging your own distribution is actually a waste of time. It is a tedious, error-prone task involving no creativity whatsoever. Developers on the other hand are actually people with very little time and a lot of creativity at hand which should spend better. The logical conclusion would be that PyPI should build wheels for the developers for every python/platform combination necessary. With this post, I would like raise awareness of the people in charge of the Python infrastructure. Best, Sven From bussonniermatthias at gmail.com Sun Sep 6 14:29:59 2015 From: bussonniermatthias at gmail.com (Matthias Bussonnier) Date: Sun, 6 Sep 2015 11:29:59 -0700 Subject: [Python-ideas] Wheels For ... In-Reply-To: <55EC78E9.1050300@mail.de> References: <55EC78E9.1050300@mail.de> Message-ID: Hi Sven, Just adding a few comments inline: On Sun, Sep 6, 2015 at 7:33 PM, Sven R. Kunze wrote: > 3) more than one way to do (upload, wheel, source/binary etc.) it (sigh) And most are uploading/registering over http (sight) > nope: what a pity for wheels; example: > https://github.com/simplejson/simplejson/issues/122 But that's for non pure-python wheels, wheel can be universal, in which case they are easy to build. > Why do developers need to build their distribution themselves? Historical reason. On GitHub, at least it is pretty easy to make Travis-CI build your wheels, some scientific packages (which are not the easier to build) have done that, so automation is possible. And these case need really particular environements where all aspects of the builds are controlled. > > I had not real answer to him, but pondering a while over it, I found it > really insightful. Viewing this from a different angle, packaging your own > distribution is actually a waste of time. It is a tedious, error-prone task > involving no creativity whatsoever. Developers on the other hand are > actually people with very little time and a lot of creativity at hand which > should spend better. The logical conclusion would be that PyPI should build > wheels for the developers for every python/platform combination necessary. I think that some of that could be done by warehouse at some point: https://github.com/pypa/warehouse But you will never be able to cover all. I'm sure people will ask PyPI to build for windows 98 server version otherwise. Personally for pure python packages I know use https://pypi.python.org/pypi/flit which is one of the only packaging tools for which I can remember all the step to get a package on PyPI without reading the docs. -- M [Sven, sorry for duplicate :-) ] From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Sun Sep 6 14:47:25 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Sun, 6 Sep 2015 19:47:25 +0100 Subject: Trying pmw with python3: Lots of crashes! Message-ID: Hi! I took a look at tkinter. It is pretty simple but it's very hard to construct some relatively more complex widgets. So I looked at pmw. Because my system only have pmw for python2, I downloaded pmw2 from its site and installed it manually using pysetup.py install. Trying the examples ...: Some run fine. Some just segfault! Others crash with the folloing message: "No such Pmw version 'on3-pmw-doc'. Using default version '2.0.0'" Is there anybody using pmw who can explain possible reasons for this? Should I use it for small apps that need: 1 or more canvas scrollable windows? 1 scrollable list with several (few) column editable fields? Do I need to go to more complex system like wxwidgets or pyside (QT)? I looked at the last one but, from the 1st steps, it seems too complex. Thanks. From torriem at gmail.com Sun Sep 6 15:20:48 2015 From: torriem at gmail.com (Michael Torrie) Date: Sun, 06 Sep 2015 13:20:48 -0600 Subject: Trying pmw with python3: Lots of crashes! In-Reply-To: References: Message-ID: <55EC9210.7090704@gmail.com> On 09/06/2015 12:47 PM, Paulo da Silva wrote: > Do I need to go to more complex system like wxwidgets or pyside (QT)? > I looked at the last one but, from the 1st steps, it seems too complex. Before anyone can suggest toolkits to look at, what kind of GUI are you trying to build? What kind of "complex" widgets are you trying to construct? By their very nature "complex" widgets are going to be, well, complex. Do you need data-driven forms? From lac at openend.se Sun Sep 6 15:27:24 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 06 Sep 2015 21:27:24 +0200 Subject: Trying pmw with python3: Lots of crashes! In-Reply-To: References: Message-ID: <201509061927.t86JRODO004702@fido.openend.se> In a message of Sun, 06 Sep 2015 19:47:25 +0100, Paulo da Silva writes: >Hi! > >I took a look at tkinter. It is pretty simple but it's very hard to >construct some relatively more complex widgets. > >So I looked at pmw. >Because my system only have pmw for python2, I downloaded pmw2 from its >site and installed it manually using pysetup.py install. > >Trying the examples ...: >Some run fine. >Some just segfault! >Others crash with the folloing message: > "No such Pmw version 'on3-pmw-doc'. Using default version '2.0.0'" > >Is there anybody using pmw who can explain possible reasons for this? > >Should I use it for small apps that need: > 1 or more canvas scrollable windows? > 1 scrollable list with several (few) column editable fields? > >Do I need to go to more complex system like wxwidgets or pyside (QT)? >I looked at the last one but, from the 1st steps, it seems too complex. > >Thanks. Did you get it from PyPI? https://pypi.python.org/pypi/Pmw/2.0.0 ? Last I heard Andy Robinson of reportlab had made it work with Python3.0, so you might ask him about bizarre crashes. You might also want to look at kivy, which works on desktops as well as on mobile devices. Get the examples directory and run the demos to see if what it can do looks like what you want. Laura From tjreedy at udel.edu Sun Sep 6 15:31:16 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 6 Sep 2015 15:31:16 -0400 Subject: Wheels For ... In-Reply-To: <55EC78E9.1050300@mail.de> References: <55EC78E9.1050300@mail.de> Message-ID: On 9/6/2015 1:33 PM, Sven R. Kunze wrote: > Hi folks, > > currently, I came across http://pythonwheels.com/ during researching how > to make a proper Python distribution for PyPI. I thought it would be > great idea to tell other maintainers to upload their content as wheels > so I approached a couple of them. Some of them already provided wheels. > > Happy being able to have built my own distribution, I discussed the > issue at hand with some people and I would like to share my findings and > propose some ideas: > > 1) documentation is weirdly split up/distributed and references old > material > 2) once up and running (setup.cfg, setup.py etc. etc.) it works but > everybody needs to do it on their own > 3) more than one way to do (upload, wheel, source/binary etc.) it (sigh) > 4) making contact to propose wheels on github or per email is easy > otherwise almost impossible or very tedious > 5) reactions went evenly split from "none", "yes", "when ready" to "nope" > > None: well, okay > yes: that's good > when ready: well, okay > nope: what a pity for wheels; example: > https://github.com/simplejson/simplejson/issues/122 > > I personally find the situation not satisfying. Someone proposes the > following solution in form of a question: > > Why do developers need to build their distribution themselves? > > I had not real answer to him, but pondering a while over it, I found it > really insightful. Viewing this from a different angle, packaging your > own distribution is actually a waste of time. It is a tedious, > error-prone task involving no creativity whatsoever. Developers on the > other hand are actually people with very little time and a lot of > creativity at hand which should spend better. The logical conclusion > would be that PyPI should build wheels for the developers for every > python/platform combination necessary. > > > With this post, I would like raise awareness of the people in charge of > the Python infrastructure. pypa is in charge of packaging. https://github.com/pypa I believe the google groups link is their discussion forum. -- Terry Jan Reedy From tjreedy at udel.edu Sun Sep 6 15:33:49 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 6 Sep 2015 15:33:49 -0400 Subject: Trying pmw with python3: Lots of crashes! In-Reply-To: References: Message-ID: On 9/6/2015 2:47 PM, Paulo da Silva wrote: > Hi! > > I took a look at tkinter. It is pretty simple but it's very hard to > construct some relatively more complex widgets. > > So I looked at pmw. > Because my system only have pmw for python2, I downloaded pmw2 from its > site and installed it manually using pysetup.py install. > Trying the examples ...: First run Tools/Script/2to3.py to convert 2.x code to 3.x code. See the docstring. > Some run fine. > Some just segfault! > Others crash with the folloing message: > "No such Pmw version 'on3-pmw-doc'. Using default version '2.0.0'" > > Is there anybody using pmw who can explain possible reasons for this? > > Should I use it for small apps that need: > 1 or more canvas scrollable windows? > 1 scrollable list with several (few) column editable fields? > > Do I need to go to more complex system like wxwidgets or pyside (QT)? > I looked at the last one but, from the 1st steps, it seems too complex. > > Thanks. > -- Terry Jan Reedy From lac at openend.se Sun Sep 6 15:54:51 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 06 Sep 2015 21:54:51 +0200 Subject: Wheels For ... In-Reply-To: References: <55EC78E9.1050300@mail.de> Message-ID: <201509061954.t86Jspjg011546@fido.openend.se> In a message of Sun, 06 Sep 2015 15:31:16 -0400, Terry Reedy writes: >On 9/6/2015 1:33 PM, Sven R. Kunze wrote: >> >> With this post, I would like raise awareness of the people in charge of >> the Python infrastructure. > >pypa is in charge of packaging. https://github.com/pypa >I believe the google groups link is their discussion forum. They have one -- https://groups.google.com/forum/#!forum/pypa-dev but you can also get them at the disutils mailing list. https://mail.python.org/mailman/listinfo/distutils-sig I think, rather than discussion, it is 'people willing to write code' that they are short of ... Laura From breamoreboy at yahoo.co.uk Sun Sep 6 16:03:23 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 6 Sep 2015 21:03:23 +0100 Subject: Wheels For ... In-Reply-To: References: <55EC78E9.1050300@mail.de> Message-ID: On 06/09/2015 20:31, Terry Reedy wrote: > On 9/6/2015 1:33 PM, Sven R. Kunze wrote: >> With this post, I would like raise awareness of the people in charge of >> the Python infrastructure. > > pypa is in charge of packaging. https://github.com/pypa > I believe the google groups link is their discussion forum. > Or gmane.comp.python.pypa.devel -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From denismfmcmahon at gmail.com Sun Sep 6 16:04:33 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 6 Sep 2015 20:04:33 +0000 (UTC) Subject: Can anyone help me run python scripts with http.server? References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> <31ec836b-4cb0-4079-8c12-f6b66a5cd143@googlegroups.com> <361cf277-b469-4873-891d-0153498794ef@googlegroups.com> Message-ID: On Sun, 06 Sep 2015 23:23:14 +1000, Chris Angelico wrote: > WSGIScriptAlias / /path/to/scripts/MinstrelHall/mh.wsgi One wonders if the OP has mod_wsgi installed. https://code.google.com/p/modwsgi/wiki/WhereToGetHelp might be useful too. -- Denis McMahon, denismfmcmahon at gmail.com From ned at nedbatchelder.com Sun Sep 6 16:06:05 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 6 Sep 2015 13:06:05 -0700 (PDT) Subject: Wheels For ... In-Reply-To: References: Message-ID: On Sunday, September 6, 2015 at 1:33:58 PM UTC-4, Sven R. Kunze wrote: > > Why do developers need to build their distribution themselves? > > ... > > With this post, I would like raise awareness of the people in charge of > the Python infrastructure. Sven, you ask a question, and then say you are trying to raise awareness. Are you making a proposal? It sounds like you might be implying that it would be better if some central infrastructure group could make all the distributions? As a developer of a Python package, I don't see how this would be better. The developer would still have to get their software into some kind of uniform configuration, so the central authority could package it. You've moved the problem from, "everyone has to make wheels" to "everyone has to make a tree that's structured properly." But if we can do the second thing, the first thing is really easy. Maybe I've misunderstood? --Ned. From cmeek.dev at gmail.com Sun Sep 6 16:52:16 2015 From: cmeek.dev at gmail.com (cmeek.dev at gmail.com) Date: Sun, 6 Sep 2015 13:52:16 -0700 (PDT) Subject: Django Calendar Message-ID: <2e9eb383-401a-49a4-b902-d3b335dcdd46@googlegroups.com> Does anyone know of an easy to follow guide/tutorial to follow. I am trying to implement a calendar into my app that works as a job rota for employees. I have tried using django-scheduler and creating htmlcalendar but can not get either method to work From pepekbabi5 at gmail.com Sun Sep 6 18:35:12 2015 From: pepekbabi5 at gmail.com (pepekbabi5 at gmail.com) Date: Sun, 6 Sep 2015 15:35:12 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: References: <3bbeafa4-d756-46f8-9750-2fca29617cf4@googlegroups.com> Message-ID: idiomatic Python programming. ?Those that try to program Java style in? Python are going to be frustrated.? From pepekbabi5 at gmail.com Sun Sep 6 19:09:42 2015 From: pepekbabi5 at gmail.com (babi pepek) Date: Sun, 6 Sep 2015 16:09:42 -0700 (PDT) Subject: python Message-ID: <885eb005-27c7-4c6c-97f9-c31577bb98ce@googlegroups.com> I wand update From python.list at tim.thechases.com Sun Sep 6 19:23:34 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 6 Sep 2015 18:23:34 -0500 Subject: python In-Reply-To: <885eb005-27c7-4c6c-97f9-c31577bb98ce@googlegroups.com> References: <885eb005-27c7-4c6c-97f9-c31577bb98ce@googlegroups.com> Message-ID: <20150906182334.4e58e29b@bigbox.christie.dr> On 2015-09-06 16:09, babi pepek wrote: > I wand update Use pip. It's like a magic wand. http://stackoverflow.com/questions/2720014/upgrading-all-packages-with-pip -tkc From ian.g.kelly at gmail.com Sun Sep 6 20:19:42 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 6 Sep 2015 18:19:42 -0600 Subject: Program in or into (was Python handles globals badly) In-Reply-To: <55EBAAFD.4090902@mrabarnett.plus.com> References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> <55EA487D.2010807@gmail.com> <03c53b53-4103-4fd8-8851-caeccda8e016@googlegroups.com> <55eba65d$0$1665$c3e8da3$5496439d@news.astraweb.com> <55EBAAFD.4090902@mrabarnett.plus.com> Message-ID: On Sat, Sep 5, 2015 at 8:54 PM, MRAB wrote: > And C# follows what Java does. Except where the language designers recognized that the Java way was poorly conceived or implemented and did it better. Generally speaking, I would much prefer to work in C# over Java, if only the language weren't so closely tied to .NET. From steve at pearwood.info Sun Sep 6 21:12:41 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 07 Sep 2015 11:12:41 +1000 Subject: python References: <885eb005-27c7-4c6c-97f9-c31577bb98ce@googlegroups.com> Message-ID: <55ece48a$0$1636$c3e8da3$5496439d@news.astraweb.com> On Mon, 7 Sep 2015 09:09 am, babi pepek wrote: > I wand update Okay. Is that a question, or are you just telling us? -- Steven From rymg19 at gmail.com Sun Sep 6 21:22:27 2015 From: rymg19 at gmail.com (Ryan Gonzalez) Date: Sun, 06 Sep 2015 20:22:27 -0500 Subject: [Python-ideas] Wheels For ... In-Reply-To: <55EC78E9.1050300@mail.de> References: <55EC78E9.1050300@mail.de> Message-ID: <3B3CDE41-BB58-447D-BB86-9994EE9587FA@gmail.com> On September 6, 2015 12:33:29 PM CDT, "Sven R. Kunze" wrote: >Hi folks, > >currently, I came across http://pythonwheels.com/ during researching >how >to make a proper Python distribution for PyPI. I thought it would be >great idea to tell other maintainers to upload their content as wheels >so I approached a couple of them. Some of them already provided wheels. > >Happy being able to have built my own distribution, I discussed the >issue at hand with some people and I would like to share my findings >and >propose some ideas: > >1) documentation is weirdly split up/distributed and references old >material >2) once up and running (setup.cfg, setup.py etc. etc.) it works but >everybody needs to do it on their own >3) more than one way to do (upload, wheel, source/binary etc.) it >(sigh) >4) making contact to propose wheels on github or per email is easy >otherwise almost impossible or very tedious >5) reactions went evenly split from "none", "yes", "when ready" to >"nope" > >None: well, okay >yes: that's good >when ready: well, okay >nope: what a pity for wheels; example: >https://github.com/simplejson/simplejson/issues/122 > >I personally find the situation not satisfying. Someone proposes the >following solution in form of a question: > >Why do developers need to build their distribution themselves? > >I had not real answer to him, but pondering a while over it, I found it > >really insightful. Viewing this from a different angle, packaging your >own distribution is actually a waste of time. It is a tedious, >error-prone task involving no creativity whatsoever. Developers on the >other hand are actually people with very little time and a lot of >creativity at hand which should spend better. The logical conclusion >would be that PyPI should build wheels for the developers for every >python/platform combination necessary. > You can already do this with CI services. I wrote a post about doing that with AppVeyor: http://kirbyfan64.github.io/posts/using-appveyor-to-distribute-python-wheels.html but the idea behind it should apply easily to Travis and others. In reality, you're probably using a CI service to run your tests anyway, so it might as well build your wheels, too! > >With this post, I would like raise awareness of the people in charge of > >the Python infrastructure. > > >Best, >Sven >_______________________________________________ >Python-ideas mailing list >Python-ideas at python.org >https://mail.python.org/mailman/listinfo/python-ideas >Code of Conduct: http://python.org/psf/codeofconduct/ -- Sent from my Nexus 5 with K-9 Mail. Please excuse my brevity. From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Sun Sep 6 21:40:48 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Mon, 7 Sep 2015 02:40:48 +0100 Subject: Trying pmw with python3: Lots of crashes! References: Message-ID: ?s 20:20 de 06-09-2015, Michael Torrie escreveu: > On 09/06/2015 12:47 PM, Paulo da Silva wrote: >> Do I need to go to more complex system like wxwidgets or pyside (QT)? >> I looked at the last one but, from the 1st steps, it seems too complex. > > Before anyone can suggest toolkits to look at, what kind of GUI are you > trying to build? It's in the post. Simple widgets except for one multicolumn scrollable and editable list and, in another case, a few grouped scrollable canvas. From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Sun Sep 6 21:51:17 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Mon, 7 Sep 2015 02:51:17 +0100 Subject: Trying pmw with python3: Lots of crashes! References: Message-ID: ?s 20:27 de 06-09-2015, Laura Creighton escreveu: > In a message of Sun, 06 Sep 2015 19:47:25 +0100, Paulo da Silva writes: >> Hi! >> ... > > Did you get it from PyPI? > https://pypi.python.org/pypi/Pmw/2.0.0 ? I got it from sourceforge but I checked now and it has the same md5. > > Last I heard Andy Robinson of reportlab had made it work with Python3.0, > so you might ask him about bizarre crashes. Yes. pmw 2 works with python3. I saw in setup.py the code to install for python2 and python3 depending on the python interpreter used. And it is correctly installed in my python3 system. Some examples work perfectly. I have sent an email to Andy. > > You might also want to look at kivy, which works on desktops as well as > on mobile devices. Get the examples directory and run the demos to see > if what it can do looks like what you want. > I have just installed it and successfully was able to run the 1st. example. It has the big advantage of being portable to android!! Thank you Laura for your suggestions. From rosuav at gmail.com Sun Sep 6 22:48:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Sep 2015 12:48:38 +1000 Subject: Can anyone help me run python scripts with http.server? In-Reply-To: References: <3877a9ae-edbd-4d36-925a-5cb3789bd1bd@googlegroups.com> <31ec836b-4cb0-4079-8c12-f6b66a5cd143@googlegroups.com> <361cf277-b469-4873-891d-0153498794ef@googlegroups.com> Message-ID: On Mon, Sep 7, 2015 at 6:04 AM, Denis McMahon wrote: > On Sun, 06 Sep 2015 23:23:14 +1000, Chris Angelico wrote: > >> WSGIScriptAlias / /path/to/scripts/MinstrelHall/mh.wsgi > > One wonders if the OP has mod_wsgi installed. > > https://code.google.com/p/modwsgi/wiki/WhereToGetHelp might be useful too. Yes, that is a consideration. But hopefully the OP can explore some possibilities and get to some more specific questions like "Apache is complaining that WSGIScriptAlias is an unknown directive - how do I correct this?", which are easily answered with a web search or a quick post to some forum (preferably an Apache-related one, as this isn't a Python question). ChrisA From cs at zip.com.au Mon Sep 7 00:05:25 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 7 Sep 2015 14:05:25 +1000 Subject: Can anyone help me run python scripts with http.server? In-Reply-To: References: Message-ID: <20150907040525.GA47613@cskk.homeip.net> On 06Sep2015 23:23, Chris Angelico wrote: >On Sun, Sep 6, 2015 at 11:07 PM, wrote: >> I will definitely look into python web frameworks in the future, they seem >> complicated to me compared to php for example. I am looking for the simplest >> way to test my python scripts till I understand better how it works and when >> I can configure my own web server to run the framework because I want develop my >> stuff offline. > >Look into Flask. You can do something really simple: >https://github.com/Rosuav/MinstrelHall > >All the code is in one file for simplicity, though for a larger >project, you can break it up as required. (Compared to PHP, where >you're _forced_ to have exactly one file per entry-point, this is a >nice flexibility.) Then I just have one line in my Apache config file >that looks something like this: > >WSGIScriptAlias / /path/to/scripts/MinstrelHall/mh.wsgi > >and Apache does all the rest. There's some cruft in that code to get >around a few oddities, but for the most part, writing a page is as >simple as writing a function, decorated to manage routing, that >returns render_template("somefile.html"). It's pretty easy. Another nice thing about Flask is that you can run it standalone without Apache. I'm knocking something together right now using Flask, and I'm intending to run it without Apache at all. There'll be an haproxy in front of it for other reasons, but to get off the ground you don't even need that. Cheers, Cameron Simpson If you take something apart and put it back together again enough times, you will eventually have enough parts left over to build a second one. - Ayse Sercan From rosuav at gmail.com Mon Sep 7 00:57:17 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 7 Sep 2015 14:57:17 +1000 Subject: Can anyone help me run python scripts with http.server? In-Reply-To: <20150907040525.GA47613@cskk.homeip.net> References: <20150907040525.GA47613@cskk.homeip.net> Message-ID: On Mon, Sep 7, 2015 at 2:05 PM, Cameron Simpson wrote: > Another nice thing about Flask is that you can run it standalone without > Apache. I'm knocking something together right now using Flask, and I'm > intending to run it without Apache at all. There'll be an haproxy in front > of it for other reasons, but to get off the ground you don't even need that. Running a Flask app standalone is, if I'm not mistaken, good for low-traffic usage only. Makes it absolutely ideal for debugging, but not so great for production work. But since you don't have to change a single line of application code to slot it into Apache, and presumably likewise for working with haproxy or anything else, it's a worthwhile simplicity. I've taken a good number of students through a Python web programming course, and we use Flask all the way. Testing? "python run.py". Production? "git push heroku master". No effort required, no careful juggling of "this bit makes it work in production". ChrisA From auriocus at gmx.de Mon Sep 7 01:24:31 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 07 Sep 2015 07:24:31 +0200 Subject: Trying pmw with python3: Lots of crashes! In-Reply-To: References: Message-ID: Am 07.09.15 um 03:40 schrieb Paulo da Silva: > ?s 20:20 de 06-09-2015, Michael Torrie escreveu: >> On 09/06/2015 12:47 PM, Paulo da Silva wrote: >>> Do I need to go to more complex system like wxwidgets or pyside (QT)? >>> I looked at the last one but, from the 1st steps, it seems too complex. >> >> Before anyone can suggest toolkits to look at, what kind of GUI are you >> trying to build? > > It's in the post. > Simple widgets except for one multicolumn scrollable and editable list > and, in another case, a few grouped scrollable canvas. > For a multicolumn editable list I suggest using tablelist. There are Python bindings around. Scrolling in Tk is generally done by grouping together scrollbars and widgets in a frame and connecting the scrollbars scrollcommands with xview/yview. Christian From cs at zip.com.au Mon Sep 7 03:29:26 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 7 Sep 2015 17:29:26 +1000 Subject: Can anyone help me run python scripts with http.server? In-Reply-To: References: Message-ID: <20150907072926.GA90068@cskk.homeip.net> On 07Sep2015 14:57, Chris Angelico wrote: >On Mon, Sep 7, 2015 at 2:05 PM, Cameron Simpson wrote: >> Another nice thing about Flask is that you can run it standalone without >> Apache. I'm knocking something together right now using Flask, and I'm >> intending to run it without Apache at all. There'll be an haproxy in front >> of it for other reasons, but to get off the ground you don't even need that. > >Running a Flask app standalone is, if I'm not mistaken, good for >low-traffic usage only. I know. But the current target use is low traffic:-) Cheers, Cameron Simpson From mahanmarwat at gmail.com Mon Sep 7 04:07:14 2015 From: mahanmarwat at gmail.com (Mahan Marwat) Date: Mon, 7 Sep 2015 01:07:14 -0700 (PDT) Subject: Django Calendar In-Reply-To: <2e9eb383-401a-49a4-b902-d3b335dcdd46@googlegroups.com> References: <2e9eb383-401a-49a4-b902-d3b335dcdd46@googlegroups.com> Message-ID: Django is not Python. This question better suits to Django group: https://groups.google.com/forum/#!forum/django-users From lac at openend.se Mon Sep 7 04:58:31 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 07 Sep 2015 10:58:31 +0200 Subject: Django Calendar In-Reply-To: <2e9eb383-401a-49a4-b902-d3b335dcdd46@googlegroups.com> References: <2e9eb383-401a-49a4-b902-d3b335dcdd46@googlegroups.com> Message-ID: <201509070858.t878wVh4013533@fido.openend.se> In a message of Sun, 06 Sep 2015 13:52:16 -0700, cmeek.dev at gmail.com writes: >Does anyone know of an easy to follow guide/tutorial to follow. I am trying to implement a calendar into my app that works as a job rota for employees. I have tried using django-scheduler and creating htmlcalendar but can not get either method to work >-- >https://mail.python.org/mailman/listinfo/python-list There is a'make a calendar app' as part of 'Django by Example' http://lightbird.net/dbe/cal1.html I have no idea about the quality of Django by Example, though ... Laura From chenchao at inhand.com.cn Mon Sep 7 05:59:40 2015 From: chenchao at inhand.com.cn (chenchao at inhand.com.cn) Date: Mon, 07 Sep 2015 17:59:40 +0800 Subject: install pip Message-ID: <55ED600C.1090505@inhand.com.cn> hi: I cross compiled python2.7.10 and install python on my embedded device. But now, I may install pip on my embedded device. So, I did it as follow: 1>I execute cmd:python -m ensurepip. It ocuurs errors as follow: Traceback (most recent call last): File "/usr/lib/python/lib/python27.zip/runpy.py", line 162, in _run_module_as_main File "/usr/lib/python/lib/python27.zip/runpy.py", line 72, in _run_code File "/var/app/python/libs/ensurepip.zip/ensurepip/__main__.py", line 4, in File "/var/app/python/libs/ensurepip.zip/ensurepip/__init__.py", line 226, in _main File "/var/app/python/libs/ensurepip.zip/ensurepip/__init__.py", line 123, in bootstrap File "/var/app/python/libs/ensurepip.zip/ensurepip/__init__.py", line 45, in _run_pip File "/tmp/tmprHZPx4/pip-6.1.1-py2.py3-none-any.whl/pip/__init__.py", line 15, in File "/tmp/tmprHZPx4/pip-6.1.1-py2.py3-none-any.whl/pip/vcs/subversion.py", line 9, in File "/tmp/tmprHZPx4/pip-6.1.1-py2.py3-none-any.whl/pip/index.py", line 30, in File "/tmp/tmprHZPx4/pip-6.1.1-py2.py3-none-any.whl/pip/_vendor/__init__.py", line 92, in load_module ImportError: No module named 'pip._vendor.html5lib' The message "/tmp/tmprHZPx4/pip-6.1.1-py2.py3-none-any.whl" point out the pip package in that dir, while it is not there. 2>As a result of the above error message, I download the pip-7.1.2 package and install it on my embedded device. It ocuurs errors as follow: # python setup.py install Traceback (most recent call last): File "setup.py", line 6, in from setuptools import setup, find_packages ImportError: No module named setuptools # 3> I I download the setuptools package and execute cmd: python setup.py install.It ocuurs errors as follow: # python setup.py install Traceback (most recent call last): File "setup.py", line 6, in from setuptools import setup, find_packages File "/var/app/python/libs/setuptools.zip/setuptools/__init__.py", line 12, in File "/var/app/python/libs/setuptools.zip/setuptools/extension.py", line 8, in File "/var/app/python/libs/setuptools.zip/setuptools/dist.py", line 19, in ImportError: No module named pkg_resources So, where can i download the pkg_resources package. Is there somebody installed pip on embedded device? can you tell me how to do that? -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Mon Sep 7 06:17:00 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 07 Sep 2015 12:17:00 +0200 Subject: install pip In-Reply-To: <55ED600C.1090505@inhand.com.cn> References: <55ED600C.1090505@inhand.com.cn> Message-ID: <201509071017.t87AH0Lw001151@fido.openend.se> Try that question on disutils-sig at python.org where the authors of pip are. Laura From chenchao at inhand.com.cn Mon Sep 7 08:16:21 2015 From: chenchao at inhand.com.cn (chenchao at inhand.com.cn) Date: Mon, 07 Sep 2015 20:16:21 +0800 Subject: python---configure file Message-ID: <55ED8015.7030505@inhand.com.cn> hi: I download the python2.7.10 package and execute cmd: ./configure --help.It is messages as follow: Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-universal-archs=ARCH select architectures for universal build ("32-bit", "64-bit", "3-way", "intel" or "all") --with-framework-name=FRAMEWORK specify an alternate name of the framework built with --enable-framework .......... .......... --with(out)-ensurepip=[=OPTION] "install" or "upgrade" using bundled pip, default is "no" So, I do not know how to use package option: --with-PACKAGE[=ARG]. It(PACKAGE) means 3rd party packages which I download from website? which directory can i put it In python2.7.10 package? For example, I download pip7.1.2 from website and I put it in python2.7.10 package dir. Therefor, I add compile option --with-pip7.1.2=yes when i compile python2.7.10. Does it correct? --with(out)-ensurepip=[=OPTION], how can i use it? -------------- next part -------------- An HTML attachment was scrubbed... URL: From palpandi111 at gmail.com Mon Sep 7 09:42:45 2015 From: palpandi111 at gmail.com (Palpandi) Date: Mon, 7 Sep 2015 06:42:45 -0700 (PDT) Subject: XML Binding In-Reply-To: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> References: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> Message-ID: <9b916796-623d-45d9-abe0-8bc7934ec42b@googlegroups.com> Hi All, Is it better to use pyxb than lxml? What are the advantages of lxml and pyxb? Thanks, Palpandi From srkunze at mail.de Mon Sep 7 12:52:02 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Mon, 07 Sep 2015 18:52:02 +0200 Subject: Wheels For ... In-Reply-To: References: Message-ID: <55EDC0B2.80400@mail.de> On 06.09.2015 22:06, Ned Batchelder wrote: > As a developer of a Python package, I don't see how this would be better. > The developer would still have to get their software into some kind of > uniform configuration, so the central authority could package it. You've > moved the problem from, "everyone has to make wheels" to "everyone has to > make a tree that's structured properly." But if we can do the second > thing, the first thing is really easy. Unfortunately, I disagree with you one that and others already gave explanations why. Internally, we had this "wild-west" tree in our source as well but we moved on to a properly structured tree and it solved problems we didn't even imagine to have solved when starting this effort some years ago. Best, Sven From larry.martell at gmail.com Mon Sep 7 19:29:03 2015 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 7 Sep 2015 19:29:03 -0400 Subject: mocking request and still getting certain ones locally Message-ID: I use the getsentry/responses package (https://github.com/getsentry/responses) for mocking the requests library for unit testing. It works great but now I have a situation where I need to talk to a local server but have my remote requests mocked out. With getsentry/responses I cannot do that - all the requests go to the mock server. Has anyone done something like this with any other package? From denismfmcmahon at gmail.com Mon Sep 7 19:42:10 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 7 Sep 2015 23:42:10 +0000 (UTC) Subject: python References: <885eb005-27c7-4c6c-97f9-c31577bb98ce@googlegroups.com> Message-ID: On Sun, 06 Sep 2015 16:09:42 -0700, babi pepek wrote: > I wand update update There, now you have update. -- Denis McMahon, denismfmcmahon at gmail.com From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Mon Sep 7 21:04:33 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Tue, 8 Sep 2015 02:04:33 +0100 Subject: Trying pmw with python3: Lots of crashes! References: Message-ID: ?s 06:24 de 07-09-2015, Christian Gollwitzer escreveu: > Am 07.09.15 um 03:40 schrieb Paulo da Silva: ... >> > For a multicolumn editable list I suggest using tablelist. There are > Python bindings around. Scrolling in Tk is generally done by grouping > together scrollbars and widgets in a frame and connecting the scrollbars > scrollcommands with xview/yview. > I have found tablelist (tklib) and a wrapper to python2. May be I'll give it a try changing the wrapper to python3. For now I am trying (learning) Laura's suggestion kivy. Thanks. Paulo From larry at hastings.org Mon Sep 7 21:35:03 2015 From: larry at hastings.org (Larry Hastings) Date: Mon, 7 Sep 2015 18:35:03 -0700 Subject: [RELEASED] Python 3.5.0rc3 is now available Message-ID: <55EE3B47.7030305@hastings.org> On behalf of the Python development community and the Python 3.5 release team, I'm relieved to announce the availability of Python 3.5.0rc3, also known as Python 3.5.0 Release Candidate 3. The next release of Python 3.5 will be Python 3.5.0 final. There should be few (or no) changes to Python 3.5 between rc3 and final. This is a preview release, and its use is not recommended for production settings. You can find Python 3.5.0rc3 here: https://www.python.org/downloads/release/python-350rc3/ Windows and Mac users: please read the important platform-specific "Notes on this release" section near the end of that page. Happy hacking, //arry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From chenchao at inhand.com.cn Mon Sep 7 22:00:26 2015 From: chenchao at inhand.com.cn (chenchao at inhand.com.cn) Date: Tue, 08 Sep 2015 10:00:26 +0800 Subject: python---configure file In-Reply-To: <55ED8015.7030505@inhand.com.cn> References: <55ED8015.7030505@inhand.com.cn> Message-ID: <55EE413A.5030608@inhand.com.cn> hi: I download the python2.7.10 package and execute cmd: ./configure --help.It is messages as follow: Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-universal-archs=ARCH select architectures for universal build ("32-bit", "64-bit", "3-way", "intel" or "all") --with-framework-name=FRAMEWORK specify an alternate name of the framework built with --enable-framework .......... .......... --with(out)-ensurepip=[=OPTION] "install" or "upgrade" using bundled pip, default is "no" So, I do not know how to use package option: --with-PACKAGE[=ARG]. It(PACKAGE) means 3rd party packages which I download from website? which directory can i put it In python2.7.10 package? For example, I download pip7.1.2 from website and I put it in python2.7.10 package dir. Therefor, I add compile option --with-pip7.1.2=yes when i compile python2.7.10. Does it correct? --with(out)-ensurepip=[=OPTION], how can i use it?Is there anybody know that? -------------- next part -------------- An HTML attachment was scrubbed... URL: From antoon.pardon at rece.vub.ac.be Tue Sep 8 04:40:12 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 08 Sep 2015 10:40:12 +0200 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> Message-ID: <55EE9EEC.1060907@rece.vub.ac.be> Op 05-09-15 om 02:05 schreef Vladimir Ignatov: >> To me, marking a variable as global in a large number of functions is >> a code smell that indicates that you're probably overusing globals. >> Lua is an example of a language that takes the opposite approach: in >> Lua, every variable is global unless you explicitly mark it as local. >> Lua is a fine language overall, but that is one of my pet peeves with > I had some experience programming in Lua and I'd say - that language > is bad example to follow. > Indexes start with 1 (I am not kidding) What is so bad about that? From antoon.pardon at rece.vub.ac.be Tue Sep 8 04:59:01 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 08 Sep 2015 10:59:01 +0200 Subject: Python handles globals badly. In-Reply-To: References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> <55E8E09A.3080309@gmail.com> Message-ID: <55EEA355.3020904@rece.vub.ac.be> Op 04-09-15 om 02:47 schreef Mark Lawrence: > On 04/09/2015 01:06, Michael Torrie wrote: >> On 09/03/2015 01:05 PM, tdev at freenet.de wrote: >> >>> [The same e.g. with switch statement: add it] >> >> Switch is a nice-to-have thing, but definitely not essential. A PEP here >> (probably already has been several) would at least be read anyway. >> However, there are several idiomatic ways of accomplishing the same >> thing that are often good enough and familiar to any Python programmer >> out there. Since functions are first-class objects, often a dispatch >> table is the best way to go here. >> > > https://www.python.org/dev/peps/pep-3103/ "A Switch/Case Statement" by > Guido van Rossum, "Rejection Notice - A quick poll during my keynote > presentation at PyCon 2007 shows this proposal has no popular support. > I therefore reject it". > > https://www.python.org/dev/peps/pep-0275/ "Switching on Multiple > Values" by Marc-Andr? Lemburg, "Rejection Notice - A similar PEP for > Python 3000, PEP 3103 [2], was already rejected, so this proposal has > no chance of being accepted either." > Were those polls, like the poll he once did for the condtional expression? There the poll indicated no specific proposal had a majority, so for each specific proposal one could say it didn't have popular support, but the majority still prefered to have a conditional expression. But at that time Guido used that poll as an indication there was not enough support. So colour me a bit sceptical when Guido comes with such a poll. -- Antoon Pardon From antoon.pardon at rece.vub.ac.be Tue Sep 8 05:07:27 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 08 Sep 2015 11:07:27 +0200 Subject: Python handles globals badly. In-Reply-To: <55e90311$0$1641$c3e8da3$5496439d@news.astraweb.com> References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> <55e90311$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55EEA54F.1050604@rece.vub.ac.be> Op 04-09-15 om 04:33 schreef Steven D'Aprano: > On Fri, 4 Sep 2015 05:05 am, tdev at freenet.de wrote: > >> Would you remove this keyword if it would be technically possible > Absolutely not. > > I do not believe that it is technically possible, but even if it were, I > would still argue that the Zen of Python applies: > > Explicit is better than implicit. > > Local variables should be the default, and you should explicitly declare any > time you want to write to a global. > > Not the other way around, like Lua does. I've always thought that was silly: > you should make the *desirable* thing easy to do, and the *dangerous* think > (using globals) possible but not easy to do by accident. You are trying to have your cake and eat it. If explicit is better than implicit then declaring your variable at the scope it has to live in, is what you need to do, that is the explicit way. Not needing to declare local variables, is an implicit way, since it is behaviour depending on something not being indicated. -- Antoon Pardon From breamoreboy at yahoo.co.uk Tue Sep 8 05:22:28 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 8 Sep 2015 10:22:28 +0100 Subject: Python handles globals badly. In-Reply-To: <55EEA355.3020904@rece.vub.ac.be> References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> <55E8E09A.3080309@gmail.com> <55EEA355.3020904@rece.vub.ac.be> Message-ID: On 08/09/2015 09:59, Antoon Pardon wrote: > Op 04-09-15 om 02:47 schreef Mark Lawrence: >> On 04/09/2015 01:06, Michael Torrie wrote: >>> On 09/03/2015 01:05 PM, tdev at freenet.de wrote: >>> >>>> [The same e.g. with switch statement: add it] >>> >>> Switch is a nice-to-have thing, but definitely not essential. A PEP here >>> (probably already has been several) would at least be read anyway. >>> However, there are several idiomatic ways of accomplishing the same >>> thing that are often good enough and familiar to any Python programmer >>> out there. Since functions are first-class objects, often a dispatch >>> table is the best way to go here. >>> >> >> https://www.python.org/dev/peps/pep-3103/ "A Switch/Case Statement" by >> Guido van Rossum, "Rejection Notice - A quick poll during my keynote >> presentation at PyCon 2007 shows this proposal has no popular support. >> I therefore reject it". >> >> https://www.python.org/dev/peps/pep-0275/ "Switching on Multiple >> Values" by Marc-Andr? Lemburg, "Rejection Notice - A similar PEP for >> Python 3000, PEP 3103 [2], was already rejected, so this proposal has >> no chance of being accepted either." >> > Were those polls, like the poll he once did for the condtional expression? Polls, there is only one referred to above? > There the poll indicated no specific proposal had a majority, so for each > specific proposal one could say it didn't have popular support, but the > majority still prefered to have a conditional expression. But at that > time Guido used that poll as an indication there was not enough support. > > So colour me a bit sceptical when Guido comes with such a poll. > In that case there were either two different polls, or one of us is mistaken, as I was very much under the impression that as there was no clear winner for a conditional expression, but a majority wanted one, Guido simply picked the one he favoured. Hum, IIRC that was backed up by an analysis of the standard library. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From lac at openend.se Tue Sep 8 05:30:12 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 08 Sep 2015 11:30:12 +0200 Subject: python---configure file In-Reply-To: <55EE413A.5030608@inhand.com.cn> References: <55ED8015.7030505@inhand.com.cn> <55EE413A.5030608@inhand.com.cn> Message-ID: <201509080930.t889UCp9023023@fido.openend.se> In a message of Tue, 08 Sep 2015 10:00:26 +0800, "chenchao at inhand.com.cn" write s: > >hi: > I download the python2.7.10 package and execute cmd: ./configure >--help.It is messages as follow: > > Optional Packages: >--with-PACKAGE[=ARG] use PACKAGE [ARG=yes] >--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) > --with-universal-archs=ARCH > select architectures for universal build >("32-bit", > "64-bit", "3-way", "intel" or "all") > --with-framework-name=FRAMEWORK > specify an alternate name of the framework built > with --enable-framework > .......... > .......... >--with(out)-ensurepip=[=OPTION] > "install" or "upgrade" using bundled pip, >default is "no" > So, I do not know how to use package option: --with-PACKAGE[=ARG]. >It(PACKAGE) means 3rd party packages which I download from website? >which directory can i put it In python2.7.10 package? For example, I >download pip7.1.2 from website and I put it in python2.7.10 package dir. >Therefor, I add compile option --with-pip7.1.2=yes when i compile >python2.7.10. Does it correct? --with(out)-ensurepip=[=OPTION], how can >i use it?Is there anybody know that? > The only times I have used with-PACKAGE if you want to configure a python package, and it wants to use a package or a stand-alone executable, and you want to override the choice it would naturally make in finding one of these other packages it wants to use. the PACKAGE whose name you replace isn't the one you are trying to configure, but another one. i.e. You are setting up mod_wsgi you type ./configure mod_wsgi wants to configure apache, and looks for an executable file called apxs (or apxs2) which you should have installed wherever your distro puts such things, so for me it is /usr/bin/apxs. I don't want to use this one. I want to use my own special one, or an older version of apache, or something. I type: ./configure --with-apxs /the/full/path/name/of/the/apxs/I/want/to/use So that is what the --with-PACKAGE is for. I do not think it is something that is related to your problem at all, but I am not an expert at this. The distutils-sig https://mail.python.org/mailman/listinfo/distutils-sig (with the letter 't') is where you find the experts. Laura From nomail at invalid.com Tue Sep 8 05:33:59 2015 From: nomail at invalid.com (ast) Date: Tue, 8 Sep 2015 11:33:59 +0200 Subject: pygame basic question Message-ID: <55eeab88$0$22574$426a74cc@news.free.fr> Hi DISPLAYSURF = pygame.display.set_mode((400, 300)) pygame.display.set_caption('Hello World!') The first line opens a 400x300 pygame window. The second one writes "Hello World" on top of it. I am just wondering how function set_caption finds the windows since the window's name DISPLAYSURF is not passed as an argument It would have understood something like: DISPLAYSURF.set_caption('Hello World!') or pygame.display.set_caption(DISPLAYSURF, 'Hello World!') thx From antoon.pardon at rece.vub.ac.be Tue Sep 8 05:59:54 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 08 Sep 2015 11:59:54 +0200 Subject: Python handles globals badly. In-Reply-To: References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> <55E8E09A.3080309@gmail.com> <55EEA355.3020904@rece.vub.ac.be> Message-ID: <55EEB19A.4010703@rece.vub.ac.be> Op 08-09-15 om 11:22 schreef Mark Lawrence: > On 08/09/2015 09:59, Antoon Pardon wrote: > >> There the poll indicated no specific proposal had a majority, so for >> each >> specific proposal one could say it didn't have popular support, but the >> majority still prefered to have a conditional expression. But at that >> time Guido used that poll as an indication there was not enough support. >> >> So colour me a bit sceptical when Guido comes with such a poll. >> > > In that case there were either two different polls, or one of us is > mistaken, as I was very much under theimpression that as there was no > clear winner for a conditional expression, but a majority wanted one, > Guido simply picked the one he favoured. Hum, IIRC that was backed up > by an analysis of the standard library. > You are mistaken. Guido originally used the fact that there was no clear winner to reject the proposal for a conditional expression. And each time someone would ask for one on this list they would be referred to the "and or" construction that was proposed as an alternative. But then some time later one of the core developers was bitten by an elusive bug (in the standard library I think) because the and-or construction didn't work as expected when the middle expression evaluated to something equivallent to false. It was then that Guido decided to have a conditional expression and chose the one he favoured. -- Antoon Pardon From lac at openend.se Tue Sep 8 06:07:34 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 08 Sep 2015 12:07:34 +0200 Subject: Python handles globals badly. In-Reply-To: <55EEA355.3020904@rece.vub.ac.be> References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> <55E8E09A.3080309@gmail.com> <55EEA355.3020904@rece.vub.ac.be> Message-ID: <201509081007.t88A7Y4w032186@fido.openend.se> In a message of Tue, 08 Sep 2015 10:59:01 +0200, Antoon Pardon writes: >Were those polls, like the poll he once did for the condtional expression? >There the poll indicated no specific proposal had a majority, so for each >specific proposal one could say it didn't have popular support, but the >majority still prefered to have a conditional expression. But at that >time Guido used that poll as an indication there was not enough support. > >So colour me a bit sceptical when Guido comes with such a poll. That's not how I remember it: There were people who wanted, a conditional expression, 'preferably , but if I cannot have that, any of the other syntaxes'. These were the people who were very passionate about wantinhg a conditional expression. There were other people who wanted a conditional expression, _but only with my preferred syntax_. Given a choice between another syntax and not having it, they would prefer to not have one. A good number of these people were more in the 'I wouldn't mind ...' than passionate wanters of a conditional expression. I was in the third group. Passionately not wanting any conditional expression whatsoever. Group 2 was the largest group. Thus while 1 plus 2 outnumbered 3, for each proposed syntax 3 plus 'the members of group 2 who didn't want this syntax' outnumbered 1 plus 'the members of group 2 who did'. Thus a mess, heavily complicated by a very interesting discussion about what sort of voting method would be appropriate to make such a choice, and non-winner-take-all systems in general. Laura From lac at openend.se Tue Sep 8 06:14:16 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 08 Sep 2015 12:14:16 +0200 Subject: pygame basic question In-Reply-To: <55eeab88$0$22574$426a74cc@news.free.fr> References: <55eeab88$0$22574$426a74cc@news.free.fr> Message-ID: <201509081014.t88AEGmd001522@fido.openend.se> Try the pygame mailing list for that one. http://www.pygame.org/wiki/info?action=view&id=4890 Laura From filip at renderedtext.com Tue Sep 8 06:27:35 2015 From: filip at renderedtext.com (=?UTF-8?Q?Filip_Komnenovi=C4=87?=) Date: Tue, 8 Sep 2015 03:27:35 -0700 (PDT) Subject: Python CI and CD support available on Semaphore (feedback appreciated) Message-ID: <10731a4a-b3ce-48ce-95e8-509521601e6a@googlegroups.com> HI folks, We have recently launched Python support on our continuous integration and deployment service and are looking for communities feedback. If you're up for it, please give a test drive to our service with your Python projects and give us your thoughts on what we could further improve upon. Official blog post announcing Python support: http://bit.ly/1KYrVsT Our website: https://semaphoreci.com/ Thanks in advance! BTW we offer free plans for open source projects and have limited free plans for private projects. From Dwight at GoldWinde.com Tue Sep 8 06:56:15 2015 From: Dwight at GoldWinde.com (Dwight GoldWinde) Date: Tue, 08 Sep 2015 18:56:15 +0800 Subject: Permission denied error in download nltk_data... In-Reply-To: <<55d46fe5$0$1642$c3e8da3$5496439d@news.astraweb.com>> Message-ID: import nltk nltk.download('maxent_treebank_pos_tagger?) Is now giving the error: [nltk_data] Error loading maxent_treebank_pos_tagger: Any suggestions, please. BIG SMILE... Always, Dwight -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Tue Sep 8 07:03:11 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 8 Sep 2015 12:03:11 +0100 Subject: pygame basic question In-Reply-To: <201509081014.t88AEGmd001522@fido.openend.se> References: <55eeab88$0$22574$426a74cc@news.free.fr> <201509081014.t88AEGmd001522@fido.openend.se> Message-ID: On 08/09/2015 11:14, Laura Creighton wrote: > Try the pygame mailing list for that one. > http://www.pygame.org/wiki/info?action=view&id=4890 > > Laura > Or https://www.reddit.com/r/pygame -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From jldunn2000 at gmail.com Tue Sep 8 07:03:46 2015 From: jldunn2000 at gmail.com (loial) Date: Tue, 8 Sep 2015 04:03:46 -0700 (PDT) Subject: passing double quotes in subprocess Message-ID: <1e6570d1-42be-432d-a690-43c4e417ec00@googlegroups.com> I need to execute an external shell script via subprocess on Linux. One of the parameters needs to be passed inside double quotes But the double quotes do not appear to be passed to the script I am using : myscript = '/home/john/myscript' commandline = myscript + ' ' + '\"Hello\"' process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output,err = process.communicate() if I make the call from another shell script and escape the double quotes it works fine, but not when I use python and subprocess. I have googled this but cannot find a solution...is there one? From larry.martell at gmail.com Tue Sep 8 07:11:12 2015 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 8 Sep 2015 07:11:12 -0400 Subject: passing double quotes in subprocess In-Reply-To: <1e6570d1-42be-432d-a690-43c4e417ec00@googlegroups.com> References: <1e6570d1-42be-432d-a690-43c4e417ec00@googlegroups.com> Message-ID: On Tue, Sep 8, 2015 at 7:03 AM, loial wrote: > I need to execute an external shell script via subprocess on Linux. > > One of the parameters needs to be passed inside double quotes > > But the double quotes do not appear to be passed to the script > > I am using : > > myscript = '/home/john/myscript' > commandline = myscript + ' ' + '\"Hello\"' > > process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > output,err = process.communicate() > > > if I make the call from another shell script and escape the double quotes it works fine, but not when I use python and subprocess. > > I have googled this but cannot find a solution...is there one? Try it with 2 backslashes: commandline = myscript + ' ' + '\\"Hello\\"' From rosuav at gmail.com Tue Sep 8 07:13:32 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Sep 2015 21:13:32 +1000 Subject: passing double quotes in subprocess In-Reply-To: <1e6570d1-42be-432d-a690-43c4e417ec00@googlegroups.com> References: <1e6570d1-42be-432d-a690-43c4e417ec00@googlegroups.com> Message-ID: On Tue, Sep 8, 2015 at 9:03 PM, loial wrote: > I need to execute an external shell script via subprocess on Linux. > > One of the parameters needs to be passed inside double quotes > > But the double quotes do not appear to be passed to the script > > I am using : > > myscript = '/home/john/myscript' > commandline = myscript + ' ' + '\"Hello\"' > > process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > output,err = process.communicate() > > > if I make the call from another shell script and escape the double quotes it works fine, but not when I use python and subprocess. > > I have googled this but cannot find a solution...is there one? First off: Can you remove the shell=True and provide the command as a list, so it doesn't need to be parsed? If you can, that would be MUCH better. But if you can't, the simple fix is to use a raw string literal for your Hello. The backslashes are getting lost: >>> print('\"Hello\"') "Hello" >>> print(r'\"Hello\"') \"Hello\" If In Doubt, Print It Out. It's amazing how much you can learn with a few well-placed print() calls :) ChrisA From jldunn2000 at gmail.com Tue Sep 8 07:13:55 2015 From: jldunn2000 at gmail.com (loial) Date: Tue, 8 Sep 2015 04:13:55 -0700 (PDT) Subject: passing double quotes in subprocess In-Reply-To: <1e6570d1-42be-432d-a690-43c4e417ec00@googlegroups.com> References: <1e6570d1-42be-432d-a690-43c4e417ec00@googlegroups.com> Message-ID: Yep, that did the trick...cheers On Tuesday, September 8, 2015 at 12:04:05 PM UTC+1, loial wrote: > I need to execute an external shell script via subprocess on Linux. > > One of the parameters needs to be passed inside double quotes > > But the double quotes do not appear to be passed to the script > > I am using : > > myscript = '/home/john/myscript' > commandline = myscript + ' ' + '\"Hello\"' > > process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > output,err = process.communicate() > > > if I make the call from another shell script and escape the double quotes it works fine, but not when I use python and subprocess. > > I have googled this but cannot find a solution...is there one? From 4kir4.1i at gmail.com Tue Sep 8 07:15:55 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Tue, 08 Sep 2015 14:15:55 +0300 Subject: passing double quotes in subprocess References: <1e6570d1-42be-432d-a690-43c4e417ec00@googlegroups.com> Message-ID: <87pp1t17ro.fsf@gmail.com> loial writes: > I need to execute an external shell script via subprocess on Linux. > > One of the parameters needs to be passed inside double quotes > > But the double quotes do not appear to be passed to the script > > I am using : > > myscript = '/home/john/myscript' > commandline = myscript + ' ' + '\"Hello\"' > > process = subprocess.Popen(commandline, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) > output,err = process.communicate() > > > if I make the call from another shell script and escape the double > quotes it works fine, but not when I use python and subprocess. > > I have googled this but cannot find a solution...is there one? You don't need shell=True here: #!/usr/bin/env python3 from subprocess import Popen, PIPE cmd = ['/home/john/myscript', 'Hello'] # if myscript don't need quotes # cmd = ['/home/john/myscript', '"Hello"'] # if myscript does need quotes with Popen(cmd, stdout=PIPE, stderr=PIPE) as process: output, errors = process.communicate() In general, to preserve backslashes, use raw-string literals: >>> print('\"') " >>> print(r'\"') \" >>> print('\\"') \" >>> '\"' == '"' True >>> r'\"' == '\\"' True From harirammanohar159 at gmail.com Tue Sep 8 07:37:09 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Tue, 8 Sep 2015 04:37:09 -0700 (PDT) Subject: issue while doing pexpect ssh Message-ID: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> Some where i am missing simple logic.... :) ===== child = pexpect.spawn('ssh hari at hostname') child.logfile = sys.stdout child.expect('hari\'s Password: ') ===== getting error as follows: ============ child.expect('hari\'s Password: ') TypeError: must be str, not bytes =========== Thanks... From kmisoft at gmail.com Tue Sep 8 07:55:39 2015 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Tue, 8 Sep 2015 07:55:39 -0400 Subject: Python handles globals badly. In-Reply-To: <55EE9EEC.1060907@rece.vub.ac.be> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> Message-ID: >> I had some experience programming in Lua and I'd say - that language >> is bad example to follow. >> Indexes start with 1 (I am not kidding) > > What is so bad about that? It's different from the rest 99.9% of languages for no particular reason. ( => perfect example of "design smell" => not a good example to follow) Vladimir http://itunes.apple.com/us/app/python-code-samples/id1025613117 From lac at openend.se Tue Sep 8 08:01:02 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 08 Sep 2015 14:01:02 +0200 Subject: Permission denied error in download nltk_data... In-Reply-To: References: Message-ID: <201509081201.t88C12dl028106@fido.openend.se> In a message of Tue, 08 Sep 2015 18:56:15 +0800, Dwight GoldWinde writes: >import nltk >nltk.download('maxent_treebank_pos_tagger?) > >Is now giving the error: > >[nltk_data] Error loading maxent_treebank_pos_tagger: [nltk_data] [Errno 57] Socket is not connected> > > >Any suggestions, please. > > > > >-- >https://mail.python.org/mailman/listinfo/python-list > I think you had better ask this question over here: https://groups.google.com/forum/#!forum/nltk-users Give the people more context in the error message -- don't trim it so much. They will want the full traceback, with line numbers and all the rest. Laura From lac at openend.se Tue Sep 8 08:12:27 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 08 Sep 2015 14:12:27 +0200 Subject: issue while doing pexpect ssh In-Reply-To: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> References: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> Message-ID: <201509081212.t88CCRY3030929@fido.openend.se> In a message of Tue, 08 Sep 2015 04:37:09 -0700, harirammanohar159 at gmail.com wr ites: >Some where i am missing simple logic.... :) > >===== >child = pexpect.spawn('ssh hari at hostname') >child.logfile = sys.stdout >child.expect('hari\'s Password: ') >===== > >getting error as follows: >============ >child.expect('hari\'s Password: ') >TypeError: must be str, not bytes >=========== > >Thanks... >-- >https://mail.python.org/mailman/listinfo/python-list https://pexpect.readthedocs.org/en/latest/api/pexpect.html#run-function you want to use spawnu because you have a unicode string. Laura From 4kir4.1i at gmail.com Tue Sep 8 08:35:31 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Tue, 08 Sep 2015 15:35:31 +0300 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> Message-ID: <87lhch1430.fsf@gmail.com> Vladimir Ignatov writes: >>> I had some experience programming in Lua and I'd say - that language >>> is bad example to follow. >>> Indexes start with 1 (I am not kidding) >> >> What is so bad about that? > > It's different from the rest 99.9% of languages for no particular reason. > > ( => perfect example of "design smell" => not a good example to follow) > It is not just a matter of tradition. Even if you were to invent the very first programming language; there are reasons to prefer the zero-based indexing. See "Why numbering should start at zero" https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html From marfig at gmx.com Tue Sep 8 09:05:59 2015 From: marfig at gmx.com (Mario Figueiredo) Date: Tue, 08 Sep 2015 14:05:59 +0100 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> Message-ID: <55EEDD37.5090602@gmx.com> On 08-09-2015 12:55, Vladimir Ignatov wrote: >>> I had some experience programming in Lua and I'd say - that language >>> is bad example to follow. >>> Indexes start with 1 (I am not kidding) >> >> What is so bad about that? > > It's different from the rest 99.9% of languages for no particular reason. > > ( => perfect example of "design smell" => not a good example to follow) > Assuming that some programming language makes design choices "for no apparent reason" is your first hint you should probably reevaluate your position. People who design programming languages don't tend to throw coins to the air. Lua was based of a scientific language with a strong mathematical core, where 1-index arrays make more sense and are standard. The authors didn't expect for the language to become successful and by the time it did, you couldn't just change anymore such a core aspect of your language. 1-index arrays tend to be a problem in Lua, only for those people that don't normally program in Lua. Those that do, quickly learn to use them and they are not more difficult or easy to use than 0-index arrays. There is nothing inherently bad about 1-index arrays. They are just different, with some of the disadvantages being balanced by some of its advantages. And there either no design smell here. From the perspective of the language user (the programmer), the choice of the starting index of an array should have no impact on their ability to code. It's just another semantic aspect of the language they should learn. No different than having to learn other semantic nuances of each particular language. In fact, a great language is the one that offers the ability for the user to decide what starting index they want to use. Depending on the data structure a user sometimes is better served by a 0-index array, others by a 1-index array, and if you are doing an array with the letters of the alphabet you would love to have an array starting at 'a'. From rosuav at gmail.com Tue Sep 8 09:57:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 8 Sep 2015 23:57:41 +1000 Subject: issue while doing pexpect ssh In-Reply-To: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> References: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> Message-ID: On Tue, Sep 8, 2015 at 9:37 PM, wrote: > Some where i am missing simple logic.... :) > > ===== > child = pexpect.spawn('ssh hari at hostname') > child.logfile = sys.stdout > child.expect('hari\'s Password: ') > ===== > > getting error as follows: > ============ > child.expect('hari\'s Password: ') > TypeError: must be str, not bytes > =========== Laura's already answered your actual question. But I would recommend using public key login rather than keying in a password; it's a lot more secure, as it means you don't have to embed a password in your source code (or at very best, on your hard disk in some other readable and decryptable way). It also simplifies the transaction significantly. ChrisA From df at see.replyto.invalid Tue Sep 8 10:01:17 2015 From: df at see.replyto.invalid (Dave Farrance) Date: Tue, 08 Sep 2015 15:01:17 +0100 Subject: pygame basic question References: <55eeab88$0$22574$426a74cc@news.free.fr> Message-ID: "ast" wrote: >DISPLAYSURF = pygame.display.set_mode((400, 300)) >pygame.display.set_caption('Hello World!') > >The first line opens a 400x300 pygame window. >The second one writes "Hello World" on top of it. > >I am just wondering how function set_caption finds the windows >since the window's name DISPLAYSURF is not passed as >an argument https://www.pygame.org/docs/ref/display.html As it says, there is only *one* display surface, and any non-displayed surface must be blitted (copied) onto the display surface for visibility. So all "pygame.display" methods refer to that one display surface. Non displayed surfaces, on the other hand, do need to be instantiated with "pygame.Surface" From ian.g.kelly at gmail.com Tue Sep 8 10:12:39 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 Sep 2015 08:12:39 -0600 Subject: pygame basic question In-Reply-To: References: <55eeab88$0$22574$426a74cc@news.free.fr> Message-ID: On Tue, Sep 8, 2015 at 8:01 AM, Dave Farrance wrote: > "ast" wrote: > >>DISPLAYSURF = pygame.display.set_mode((400, 300)) >>pygame.display.set_caption('Hello World!') >> >>The first line opens a 400x300 pygame window. >>The second one writes "Hello World" on top of it. >> >>I am just wondering how function set_caption finds the windows >>since the window's name DISPLAYSURF is not passed as >>an argument > > https://www.pygame.org/docs/ref/display.html > > As it says, there is only *one* display surface, and any non-displayed > surface must be blitted (copied) onto the display surface for > visibility. So all "pygame.display" methods refer to that one display > surface. Non displayed surfaces, on the other hand, do need to be > instantiated with "pygame.Surface" Also, note that the display surface DISPLAYSURF is not the window. It's just a Surface object that pygame uses to paint the contents of the window. AFAIK pygame maintains the actual window data structures internally and does not expose them to the API. From ian.g.kelly at gmail.com Tue Sep 8 10:31:04 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 Sep 2015 08:31:04 -0600 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> Message-ID: On Tue, Sep 8, 2015 at 5:55 AM, Vladimir Ignatov wrote: >>> I had some experience programming in Lua and I'd say - that language >>> is bad example to follow. >>> Indexes start with 1 (I am not kidding) >> >> What is so bad about that? > > It's different from the rest 99.9% of languages for no particular reason. It's not "different from the rest 99.9% of languages". There are many languages that use 1-based indexing, e.g. Matlab, Pascal, Fortran. None of those are even the worst offender here, IMO. That honor goes to Visual Basic 6, where the default lower bound is 0, but the programmer has the option of declaring an array to use any lower bound they want, or even globally change the default. As a result you have to look up the array declaration to know the lower bound, and even then you can't be sure if it's not explicit. The correct way to iterate over a loop in VB 6 is thus not "FOR i = 0 TO n-1", but "FOR i = LBound(arr) TO UBound(arr)" which is overly verbose and means that you can't even be sure what indexes you're actually iterating over inside the loop. I believe this wart is fixed in VB .NET. From blindanagram at nowhere.net Tue Sep 8 10:54:09 2015 From: blindanagram at nowhere.net (Brian Gladman) Date: Tue, 8 Sep 2015 15:54:09 +0100 Subject: [RELEASED] Python 3.5.0rc3 is now available In-Reply-To: References: Message-ID: On 08/09/2015 02:35, Larry Hastings wrote: > > > On behalf of the Python development community and the Python 3.5 release > team, I'm relieved to announce the availability of Python 3.5.0rc3, also > known as Python 3.5.0 Release Candidate 3. > > The next release of Python 3.5 will be Python 3.5.0 final. There should > be few (or no) changes to Python 3.5 between rc3 and final. > > This is a preview release, and its use is not recommended for production > settings. > > > You can find Python 3.5.0rc3 here: > > https://www.python.org/downloads/release/python-350rc3/ > > Windows and Mac users: please read the important platform-specific > "Notes on this release" section near the end of that page. > > > Happy hacking, I notice that one new feature that isn't mentioned in the 'what's new' list is the addition of math.gcd() offering a faster and more generic implementation (in that it returns a positive result) of the greatest common divisor operation. Thanks for this and for all your work on Python 3.5. From jeanmichel at sequans.com Tue Sep 8 10:56:50 2015 From: jeanmichel at sequans.com (jmp) Date: Tue, 08 Sep 2015 16:56:50 +0200 Subject: issue while doing pexpect ssh In-Reply-To: References: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> Message-ID: On 09/08/2015 03:57 PM, Chris Angelico wrote: > On Tue, Sep 8, 2015 at 9:37 PM, wrote: >> Some where i am missing simple logic.... :) >> >> ===== >> child = pexpect.spawn('ssh hari at hostname') >> child.logfile = sys.stdout >> child.expect('hari\'s Password: ') >> ===== >> >> getting error as follows: >> ============ >> child.expect('hari\'s Password: ') >> TypeError: must be str, not bytes >> =========== > > Laura's already answered your actual question. But I would recommend > using public key login [snip] > > ChrisA > My 2 cents, beside the public key, use the python module paramiko, unless you really want to work at the low level yourself. http://docs.paramiko.org/en/1.15/api/client.html JM From wxjmfauth at gmail.com Tue Sep 8 11:54:30 2015 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 8 Sep 2015 08:54:30 -0700 (PDT) Subject: Silly question about pip Message-ID: <54d12451-0160-4acb-b850-b2f49838fe42@googlegroups.com> win7 / py433 How to downgrade from the latest pip (7.1.2) to the previous one? I'm sorry, I do not remember the numerous msgs I saw when updating. (Yesterday) (I'm serious) Now, what? From steve at pearwood.info Tue Sep 8 11:56:04 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 09 Sep 2015 01:56:04 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> Message-ID: <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> On Wed, 9 Sep 2015 12:31 am, Ian Kelly wrote: > On Tue, Sep 8, 2015 at 5:55 AM, Vladimir Ignatov > wrote: >>>> I had some experience programming in Lua and I'd say - that language >>>> is bad example to follow. >>>> Indexes start with 1 (I am not kidding) >>> >>> What is so bad about that? >> >> It's different from the rest 99.9% of languages for no particular reason. > > It's not "different from the rest 99.9% of languages". There are many > languages that use 1-based indexing, e.g. Matlab, Pascal, Fortran. Correct. Nearly all natural languages start counting at 1, not 0, as do quite a few programming languages, such as PL/I, Algol60 and others. You'll note that languages that are designed for mathematics (Matlab, Mathematica, Julia) tend to use 1-based indexes. This is not an accident. Guido discusses why he choose 0-based indexing like in C, instead of 1-based indexing like in ABC: http://python-history.blogspot.com.au/2013/10/why-python-uses-0-based-indexing.html He links to this fantastic discussion of why C ended up with 0-based indexing: http://exple.tive.org/blarg/2013/10/22/citation-needed/ It's a wonderful read. See also: http://c2.com/cgi/wiki?WhyNumberingShouldStartAtOne http://c2.com/cgi/wiki?WhyNumberingShouldStartAtZero Anyone who thinks that there is one right answer here simply isn't paying attention. > None of those are even the worst offender here, IMO. That honor goes > to Visual Basic 6, where the default lower bound is 0, but the > programmer has the option of declaring an array to use any lower bound > they want, or even globally change the default. I'll just point out that some algorithms are best written with 0-based arrays, and some are best with 1-based arrays. I shouldn't have to change languages to change from one to the other! -- Steven From random832 at fastmail.us Tue Sep 8 12:13:34 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Tue, 08 Sep 2015 12:13:34 -0400 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> Message-ID: <1441728814.1568525.377833137.09AE9947@webmail.messagingengine.com> On Tue, Sep 8, 2015, at 10:31, Ian Kelly wrote: > I believe this wart is fixed in VB .NET. This is apparently true, but the weird thing is it was done late enough in the design cycle that the .NET runtime still has features meant to support it. You can create such an array with the Array.CreateInstance method. For multidimensional arrays, you can even assign them to a variable of the proper type (You can't do that for single-dimension arrays since a single-dimension array with a nonzero lower bound is a different type than a normal array). And the LBound and UBound methods in the Microsoft.VisualBasic.Information class still support it. The feature is so obscure that even the compiler doesn't do well with it - if you create (via MSIL) a strongly-typed method that returns such an array, the compiler will think it returns a normal array. Of course, on the subject of warts, Dim x(5) as Integer or Dim x as Integer() = new Integer(5){} still creates an array with size 6 (upper bound is 5). You're free to use indices 0..4 or 1..5 if you want, but 0..5 are valid. From lac at openend.se Tue Sep 8 12:43:40 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 08 Sep 2015 18:43:40 +0200 Subject: issue while doing pexpect ssh In-Reply-To: References: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> Message-ID: <201509081643.t88GheQp000982@fido.openend.se> In a message of Tue, 08 Sep 2015 23:57:41 +1000, Chris Angelico writes: >On Tue, Sep 8, 2015 at 9:37 PM, wrote: >> Some where i am missing simple logic.... :) >> >> ===== >> child = pexpect.spawn('ssh hari at hostname') >> child.logfile = sys.stdout >> child.expect('hari\'s Password: ') >> ===== >> >> getting error as follows: >> ============ >> child.expect('hari\'s Password: ') >> TypeError: must be str, not bytes >> =========== > >Laura's already answered your actual question. But I would recommend >using public key login rather than keying in a password; it's a lot >more secure, as it means you don't have to embed a password in your >source code (or at very best, on your hard disk in some other readable >and decryptable way). It also simplifies the transaction >significantly. > >ChrisA This poor soul cannot login at all. He needs this hack to let him su some-other-user because of a draconian policy he cannot do anything about. If he could just log in, one heck of a lot of other things would be simpler for him ... Laura From python at mrabarnett.plus.com Tue Sep 8 13:41:45 2015 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 8 Sep 2015 18:41:45 +0100 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> Message-ID: <55EF1DD9.8080705@mrabarnett.plus.com> On 2015-09-08 15:31, Ian Kelly wrote: > On Tue, Sep 8, 2015 at 5:55 AM, Vladimir Ignatov wrote: >>>> I had some experience programming in Lua and I'd say - that language >>>> is bad example to follow. >>>> Indexes start with 1 (I am not kidding) >>> >>> What is so bad about that? >> >> It's different from the rest 99.9% of languages for no particular reason. > > It's not "different from the rest 99.9% of languages". There are many > languages that use 1-based indexing, e.g. Matlab, Pascal, Fortran. > In Pascal you specify both the lower and the upper bounds. > None of those are even the worst offender here, IMO. That honor goes > to Visual Basic 6, where the default lower bound is 0, but the > programmer has the option of declaring an array to use any lower bound > they want, or even globally change the default. As a result you have > to look up the array declaration to know the lower bound, and even > then you can't be sure if it's not explicit. The correct way to > iterate over a loop in VB 6 is thus not "FOR i = 0 TO n-1", but "FOR i > = LBound(arr) TO UBound(arr)" which is overly verbose and means that > you can't even be sure what indexes you're actually iterating over > inside the loop. > > I believe this wart is fixed in VB .NET. > From tdev at freenet.de Tue Sep 8 13:53:44 2015 From: tdev at freenet.de (tdev at freenet.de) Date: Tue, 8 Sep 2015 10:53:44 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: References: Message-ID: Before reflecting latest answers a short absolute last statement about that matter: Differ: globals (traditional, sharing vars app wide, NOT meant) globals (module vars outside functions, meant here at least when I mention this term) global (the keyword used inside functions) I did not say - make no comparions or no OO-wording. Sure, write what you have to write but hopefully especially as long as it changes not the topic of this thread. I did say - lay OO and sharing globals down (which again appears and is NOT the topic (at least not mine)). Point. Reflecting latest answers, but not the new topic ("Progam in or into") which has arrived , I want add following: """ Some statements brought into discussion (myself), read or skip down the closing """"" -- Comparison with Javscript: Saying that Javascript and LUA does it samewise seems not correct from reading the thread. LUA is said it has it vice versa: local instead of a global But Javascript does have neither local nor global keyword so far I know, but has also a local scope (block scope). The other Python-proposals aside "global": -- switch statement: PEP3103, it is PEP from Guido van Rossum! I can only say: If even a "good and senseful" PEP from Guido is denied from community I do better not comment. -- indentation: I am not sure if the sample has been changed from posting but the line "count +=1" is clearly integrated at the outer loop (at least in my browser) (even process(line) is in that post in the outer loop) No, I meant simply count = 0 for file in files: for line in open(file): # tab indent process(line) # 2 space indent count += 1 so, e.g. the first indent has 1 tab to the right, the second 2 spaces to the right. Why I am not free about this? Context is clear for me. (I want not say I do this with intent, but if it happens: Ok, shit happens, I need no script-error if it happens. Really not) -- Universal scope Yes proably ok. you mean what builtins? Or What builtins suits best? -- goto I would say ok. For the times you need such a construct it should be enough. -- include statement Not sure if we meant the same: With including I meant the virtual merge of two or more scripts (once merged it is executed as one script with one namespace: a module var X in script A is directly available in script B,C,...) Different is that including with namespaces is something special. And if you search around the web there are different pseudo-includes proposals (Side-effects unknown!?) And with scopes, namespaces and every aspects to careof (memory, efficient file reading, compiled sources, caches) are something what should be provided from Python itself and should not be a construct from the developer. According the Python philospophy ("one best way"). """ Now back to the main topic: -- "global"-keyword Main point from my side is further (compared e.g. with Javascript) Python needs the keyword "global" to give write access to a global(=module-var). Only for that reason I would NOT need a "global" keyword Though accepted that there are dynamic constructions which needs maybe a global or even (but still not really believe) technical (compiler) reasons to have it maybe, but when rethinking it, escpecially about the dynamics constructs, I still not really understand this reasons?: At the risk of going in a circle: Globals are of module-scope only. I think it is NOT possible to have same var names xxx as global and local(function-var) and use them in parallel. Even with the sample provided: exec("""def function(): global {0} {0} = 42 """.format('x')) For me this says that only: {0} is writeable. Nothing more, No distinction needed if local or global. Or is there an example out there where I really have to distinct a same var name - inside a single module I would not know? And even with more modules, than the distinction is done by namespace prefix. I see no other value in the keyword "global" except the write-protection. Proof: Each sample provided would work without global (or you get runtime failure while try to write a global). So the compiler knows the distiction between global and local already. Otherwise you would have to write in every function this keyword But this is not the case. You write it because you need write access. And this is an over-regulation. So, I say: NO need for an explicit global. Optional ok. Conclusion (for me): -------------------- So for me the reasons about dynamic constructions or compiler thinks aren'that revelant as described. "global" is provided only to help the developer not to overwrite a global by mistake, and should be removeable if this protection is not wanted (by the community), at least optional. And this (and even the other points) would not change Python, or is a matter of "Use Python language correct" or "try not to write Java". Sure not. I would rather say, this would enhance the power and flexibility of the Python language even further. Especially from the scripting point of view (without harm Python hardliner) And by the way, I still believe that these changes would let Python overrun Javascript and PHP. There would practically no more any reasons for Javascript+NodeJS and especially PHP. I even think, a huge wave of developers would change then to Python. Including webhosters which I think did not know or want not know anything about Python 3.x. Thanks. From ian.g.kelly at gmail.com Tue Sep 8 14:09:09 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 Sep 2015 12:09:09 -0600 Subject: Python handles globals badly. In-Reply-To: References: Message-ID: On Tue, Sep 8, 2015 at 11:53 AM, wrote: > -- Comparison with Javscript: > Saying that Javascript and LUA does it samewise seems not correct > from reading the thread. > LUA is said it has it vice versa: local instead of a global > But Javascript does have neither local nor global keyword so far I know, > but has also a local scope (block scope). In Javascript the keyword is "var", not "local", but it amounts to the same thing: this variable is local, and if you don't use it then your variable is not local. > so, e.g. the first indent has 1 tab to the right, the second 2 spaces to the right. > Why I am not free about this? Context is clear for me. It's clear for you in your particular editor configuration. In somebody else's editor who has tabs configured differently, it may appear completely different. The compiler has no way of knowing what your editor's tab settings are, so it considers the indentation ambiguous. > I would rather say, this would enhance the power and flexibility of the Python language even further. > Especially from the scripting point of view (without harm Python hardliner) > And by the way, I still believe that these changes would let Python overrun Javascript and PHP. > There would practically no more any reasons for Javascript+NodeJS and especially PHP. > I even think, a huge wave of developers would change then to Python. > Including webhosters which I think did not know or want not know anything about Python 3.x. I think that you greatly exaggerate the impact of these changes, which are all quite cosmetic in nature. From rosuav at gmail.com Tue Sep 8 14:13:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Sep 2015 04:13:06 +1000 Subject: Python handles globals badly. In-Reply-To: References: Message-ID: On Wed, Sep 9, 2015 at 4:09 AM, Ian Kelly wrote: >> I would rather say, this would enhance the power and flexibility of the Python language even further. >> Especially from the scripting point of view (without harm Python hardliner) >> And by the way, I still believe that these changes would let Python overrun Javascript and PHP. >> There would practically no more any reasons for Javascript+NodeJS and especially PHP. >> I even think, a huge wave of developers would change then to Python. >> Including webhosters which I think did not know or want not know anything about Python 3.x. > > I think that you greatly exaggerate the impact of these changes, which > are all quite cosmetic in nature. EVERYONE who suggests massive, sweeping changes says "hey, if you only make these changes, Python will actually become popular". It's almost mandatory. ChrisA From irmen.NOSPAM at xs4all.nl Tue Sep 8 14:16:37 2015 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Tue, 8 Sep 2015 20:16:37 +0200 Subject: Silly question about pip In-Reply-To: <54d12451-0160-4acb-b850-b2f49838fe42@googlegroups.com> References: <54d12451-0160-4acb-b850-b2f49838fe42@googlegroups.com> Message-ID: <55ef263e$0$23821$e4fe514c@news.xs4all.nl> On 8-9-2015 17:54, wxjmfauth at gmail.com wrote: > win7 / py433 > > How to downgrade from the latest pip (7.1.2) to > the previous one? > I'm sorry, I do not remember the numerous msgs > I saw when updating. (Yesterday) > > (I'm serious) > > Now, what? > I think: $ pip install --upgrade pip==7.0.0 would do the trick, where you substitute the required version number for 7.0.0. Irmen From tjreedy at udel.edu Tue Sep 8 14:46:28 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 8 Sep 2015 14:46:28 -0400 Subject: Python CI and CD support available on Semaphore (feedback appreciated) In-Reply-To: <10731a4a-b3ce-48ce-95e8-509521601e6a@googlegroups.com> References: <10731a4a-b3ce-48ce-95e8-509521601e6a@googlegroups.com> Message-ID: On 9/8/2015 6:27 AM, Filip Komnenovi? wrote: > We have recently launched Python support on our continuous integration and deployment service and are looking for communities feedback. If you're up for it, please give a test drive to our service with your Python projects and give us your thoughts on what we could further improve upon. Have you considered integrating with bitbucket as well as github? > Official blog post announcing Python support: http://bit.ly/1KYrVsT > Our website: https://semaphoreci.com/ > BTW we offer free plans for open source projects and have limited free plans for private projects. -- Terry Jan Reedy From wxjmfauth at gmail.com Tue Sep 8 14:57:00 2015 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 8 Sep 2015 11:57:00 -0700 (PDT) Subject: Silly question about pip In-Reply-To: <55ef263e$0$23821$e4fe514c@news.xs4all.nl> References: <54d12451-0160-4acb-b850-b2f49838fe42@googlegroups.com> <55ef263e$0$23821$e4fe514c@news.xs4all.nl> Message-ID: Le mardi 8 septembre 2015 20:18:20 UTC+2, Irmen de Jong a ?crit?: > On 8-9-2015 17:54, wxjmfauth at gmail.com wrote: > > win7 / py433 > > > > How to downgrade from the latest pip (7.1.2) to > > the previous one? > > I'm sorry, I do not remember the numerous msgs > > I saw when updating. (Yesterday) > > > > (I'm serious) > > > > Now, what? > > > > I think: > > $ pip install --upgrade pip==7.0.0 > > > would do the trick, where you substitute the required version number for 7.0.0. > > > Irmen I will try tomorrow. I think my previous one (on py34) was 6.0.8 It's what I have in C:\>c:\python32\scripts\pip --version pip 6.0.8 from c:\Python32\lib\site-packages (python 3.2) C:\> From wxjmfauth at gmail.com Tue Sep 8 15:02:16 2015 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 8 Sep 2015 12:02:16 -0700 (PDT) Subject: Silly question about pip In-Reply-To: <55ef263e$0$23821$e4fe514c@news.xs4all.nl> References: <54d12451-0160-4acb-b850-b2f49838fe42@googlegroups.com> <55ef263e$0$23821$e4fe514c@news.xs4all.nl> Message-ID: <39e93a61-c134-45e3-ac48-9c0af98c674f@googlegroups.com> Le mardi 8 septembre 2015 20:18:20 UTC+2, Irmen de Jong a ?crit?: > On 8-9-2015 17:54, wxjmfauth at gmail.com wrote: > > win7 / py433 > > > > How to downgrade from the latest pip (7.1.2) to > > the previous one? > > I'm sorry, I do not remember the numerous msgs > > I saw when updating. (Yesterday) > > > > (I'm serious) > > > > Now, what? > > > > I think: > > $ pip install --upgrade pip==7.0.0 > > > would do the trick, where you substitute the required version number for 7.0.0. > > > Irmen Addendum (your question) > pip install --upgrade pip which probably selects the latest version From lazlo.lebrun at googlemail.com Tue Sep 8 15:14:06 2015 From: lazlo.lebrun at googlemail.com (Laszlo Lebrun) Date: Tue, 8 Sep 2015 19:14:06 +0000 (UTC) Subject: PIP does not appear to handle diacritics correctly. Message-ID: Dear group, I do use Windows 7 and have a user name with diacritics. Whenever I am querying an extension with pip, it will fail since it does not pass on the user folder correctly. I thought PIP deals well with unicode, doesn't it? Has anyone a clue how to fix it? Thank you -- Stand up against TTIP and ISDS ! From sjeik_appie at hotmail.com Tue Sep 8 15:19:37 2015 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Tue, 8 Sep 2015 19:19:37 +0000 Subject: Python CI and CD support available on Semaphore (feedback appreciated) In-Reply-To: References: <10731a4a-b3ce-48ce-95e8-509521601e6a@googlegroups.com>, Message-ID: > To: python-list at python.org > From: tjreedy at udel.edu > Subject: Re: Python CI and CD support available on Semaphore (feedback appreciated) > Date: Tue, 8 Sep 2015 14:46:28 -0400 > > On 9/8/2015 6:27 AM, Filip Komnenovi? wrote: > > > We have recently launched Python support on our continuous integration and deployment service and are looking for communities feedback. If you're up for it, please give a test drive to our service with your Python projects and give us your thoughts on what we could further improve upon. > > Have you considered integrating with bitbucket as well as github? Bitbucket is supported, not just Github (like most CIs). The information is kinda hidden (or at least not as clearly visible as the Github integration): https://semaphoreci.com/docs/adding-github-bitbucket-project-to-semaphore.html I see Ubuntu 14.04 LTS 64-bit VMs are used. I would love to be able to run my tests on Linux, Mac OS and Windows in one go. > > > Official blog post announcing Python support: http://bit.ly/1KYrVsT > > Our website: https://semaphoreci.com/ > > > BTW we offer free plans for open source projects and have limited free plans for private projects. > > -- > Terry Jan Reedy > > > -- > https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From cody.piersall at gmail.com Tue Sep 8 18:19:49 2015 From: cody.piersall at gmail.com (Cody Piersall) Date: Tue, 8 Sep 2015 17:19:49 -0500 Subject: Need Help w. PIP! In-Reply-To: <2579215.WiH7nXzSoB@PointedEars.de> References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <2579215.WiH7nXzSoB@PointedEars.de> Message-ID: On Sat, Sep 5, 2015 at 3:14 AM, Thomas 'PointedEars' Lahn < PointedEars at web.de> wrote: > > Cody Piersall wrote: > > > Please respond to the list as well as the person you're actually talking > > to. It works out better for everyone that way. (You should just have to > > "reply all" instead of "reply"). > > ?Better? as in ?getting/reading/downloading the same message *twice*?? > > The rule of thumb is: write here, read here. Some people email the list, but aren't subscribed to it. So I guess a better rule is to just reply-to-all for the OP? Cody -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Tue Sep 8 18:35:33 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 8 Sep 2015 23:35:33 +0100 Subject: PIP does not appear to handle diacritics correctly. In-Reply-To: References: Message-ID: On 08/09/2015 20:14, Laszlo Lebrun via Python-list wrote: > > Dear group, > I do use Windows 7 and have a user name with diacritics. > > Whenever I am querying an extension with pip, it will fail since it does > not pass on the user folder correctly. > I thought PIP deals well with unicode, doesn't it? > > Has anyone a clue how to fix it? > Thank you > Can you please cut and paste exactly what you tried and the failure messages, as there's a lot of smart people around here but we're not mind readers :) Which Python and pip version are you using? Did you install pip yourself or did it come with your Python installation? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Tue Sep 8 18:41:32 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 8 Sep 2015 23:41:32 +0100 Subject: Python handles globals badly. In-Reply-To: <55EF1DD9.8080705@mrabarnett.plus.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EF1DD9.8080705@mrabarnett.plus.com> Message-ID: On 08/09/2015 18:41, MRAB wrote: > On 2015-09-08 15:31, Ian Kelly wrote: >> On Tue, Sep 8, 2015 at 5:55 AM, Vladimir Ignatov >> wrote: >>>>> I had some experience programming in Lua and I'd say - that language >>>>> is bad example to follow. >>>>> Indexes start with 1 (I am not kidding) >>>> >>>> What is so bad about that? >>> >>> It's different from the rest 99.9% of languages for no particular >>> reason. >> >> It's not "different from the rest 99.9% of languages". There are many >> languages that use 1-based indexing, e.g. Matlab, Pascal, Fortran. >> > In Pascal you specify both the lower and the upper bounds. > I vaguely recall that in CORAL66/250 you specified both bounds and the lower bound could be negative. Do other languages allow this or does the lower bound always have to be positive? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From elcarga at hotmail.com Tue Sep 8 18:44:26 2015 From: elcarga at hotmail.com (Nassim Gannoun) Date: Tue, 8 Sep 2015 17:44:26 -0500 Subject: Hi am new to python Message-ID: Hi I'm also new to Python but would like to reply. Like others have stated there is a built in function (sum) that can give the sum of the elements of a list, but if what you are trying to do is learn how to use the while command here is some code that will work. Your question: My question is in a while loop; how do l sum all the numbers in the given list (list_a)? list_a = [8, 5, 2, 4] sum_a = 0 # for storing the sum of list_a i = 0 # for looping through the list_a# Use a while loop to sum all numbers in list_a# If you store the sums into sum_a print(sum_a) # should print 19 My answer: list_a = [8, 5, 2, 4] sum_a = 0 i = 0 while i < (len(list_a)): sum_a += list_a[i] i += 1 print(sum_a) -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Tue Sep 8 19:20:27 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 9 Sep 2015 00:20:27 +0100 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EF1DD9.8080705@mrabarnett.plus.com> Message-ID: <55EF6D3B.6030106@mrabarnett.plus.com> On 2015-09-08 23:41, Mark Lawrence wrote: > On 08/09/2015 18:41, MRAB wrote: >> On 2015-09-08 15:31, Ian Kelly wrote: >>> On Tue, Sep 8, 2015 at 5:55 AM, Vladimir Ignatov >>> wrote: >>>>>> I had some experience programming in Lua and I'd say - that language >>>>>> is bad example to follow. >>>>>> Indexes start with 1 (I am not kidding) >>>>> >>>>> What is so bad about that? >>>> >>>> It's different from the rest 99.9% of languages for no particular >>>> reason. >>> >>> It's not "different from the rest 99.9% of languages". There are many >>> languages that use 1-based indexing, e.g. Matlab, Pascal, Fortran. >>> >> In Pascal you specify both the lower and the upper bounds. >> > > I vaguely recall that in CORAL66/250 you specified both bounds and the > lower bound could be negative. Do other languages allow this or does > the lower bound always have to be positive? > If you're allowed to specify both bounds, why would you be forbidden from negative ones? A better question would be whether there's a language that allows you to specify a lower bound, but insists that it's non-negative. From breamoreboy at yahoo.co.uk Tue Sep 8 19:32:37 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 9 Sep 2015 00:32:37 +0100 Subject: Python handles globals badly. In-Reply-To: <55EF6D3B.6030106@mrabarnett.plus.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EF1DD9.8080705@mrabarnett.plus.com> <55EF6D3B.6030106@mrabarnett.plus.com> Message-ID: On 09/09/2015 00:20, MRAB wrote: > On 2015-09-08 23:41, Mark Lawrence wrote: >> On 08/09/2015 18:41, MRAB wrote: >>> On 2015-09-08 15:31, Ian Kelly wrote: >>>> On Tue, Sep 8, 2015 at 5:55 AM, Vladimir Ignatov >>>> wrote: >>>>>>> I had some experience programming in Lua and I'd say - that language >>>>>>> is bad example to follow. >>>>>>> Indexes start with 1 (I am not kidding) >>>>>> >>>>>> What is so bad about that? >>>>> >>>>> It's different from the rest 99.9% of languages for no particular >>>>> reason. >>>> >>>> It's not "different from the rest 99.9% of languages". There are many >>>> languages that use 1-based indexing, e.g. Matlab, Pascal, Fortran. >>>> >>> In Pascal you specify both the lower and the upper bounds. >>> >> >> I vaguely recall that in CORAL66/250 you specified both bounds and the >> lower bound could be negative. Do other languages allow this or does >> the lower bound always have to be positive? >> > If you're allowed to specify both bounds, why would you be forbidden > from negative ones? I haven't the faintest idea :) > > A better question would be whether there's a language that allows you > to specify a lower bound, but insists that it's non-negative. > Ditto :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From torriem at gmail.com Tue Sep 8 19:55:02 2015 From: torriem at gmail.com (Michael Torrie) Date: Tue, 08 Sep 2015 17:55:02 -0600 Subject: Python handles globals badly. In-Reply-To: <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55EF7556.2090409@gmail.com> On 09/08/2015 09:56 AM, Steven D'Aprano wrote: > http://exple.tive.org/blarg/2013/10/22/citation-needed/ > > It's a wonderful read. I read this article, but I'm still uncertain to what his point actually is. It's a great review of the history of C, some batch computing, and IBM's CEO's penchant for boat racing. He tries to say that 0-based indexing made for faster compiling, but given the runtime nature of BCPL's ! operator, I don't see how it wouldn't affect runtime also. He also says that saying pointers are the reason for 0-based indexing then you're wrong, except that BCPL's creator says in this same article that array variables are essentially pointers. A few people tried to point this out in the comments but the author simply lambasted them, saying thinks like, "Thanks for leaving a comment. I'm sure it's made you feel clever." Like I say I guess I must have missed his point in there somewhere. I suppose his point is C is 0-based because BCPL was, and I'm sure that's true, but I'm also sure K&R saw some benefits to keeping this in C. In any case, 0-based indexing in Python makes a lot of sense when you bring in the slicing syntax. Especially if you think of slicing as operating on the boundaries between cells as it were. I used a 1-based indexed language (BASIC) for many years, and I was always having to subtract 1 from things. So 0-based is simply more convenient for me. From random832 at fastmail.com Tue Sep 8 20:02:24 2015 From: random832 at fastmail.com (Random832) Date: Tue, 08 Sep 2015 20:02:24 -0400 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EF1DD9.8080705@mrabarnett.plus.com> <55EF6D3B.6030106@mrabarnett.plus.com> Message-ID: MRAB writes: > If you're allowed to specify both bounds, why would you be forbidden > from negative ones? It makes it non-obvious what value should be returned from e.g. search methods that return a negative number on failure. .NET's IndexOf function returns -1, but MaxValue if the array has a negative bound. BinarySearch returns the complement of the nearest index to the value you were searching for, which requires some gymnastics if you want to make use of it for an array that has negative and positive bounds. From marfig at gmx.com Tue Sep 8 21:09:14 2015 From: marfig at gmx.com (Mario Figueiredo) Date: Wed, 09 Sep 2015 02:09:14 +0100 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> Message-ID: <55EF86BA.4050502@gmx.com> On 09-09-2015 01:25, Vladimir Ignatov wrote: >>> It's different from the rest 99.9% of languages for no particular reason. >>> >>> ( => perfect example of "design smell" => not a good example to follow) >>> >> >> Assuming that some programming language makes design choices "for no >> apparent reason" is your first hint you should probably reevaluate your >> position. People who design programming languages don't tend to throw coins >> to the air. > > Okay, I reevaluated my position and suddenly found that 1-based > indexes is such a honking great idea! Now I have another difficulty > though. How to justify absence of built-in unicode support in a > language carefully designed in 1993 ? > Sarcasm noted. Because: a) In 1993, ANSI C (C89) of which Lua had been developed had poor multibyte and wide character support. It was only with C95 that this stabilized. b) It didn't needed Unicode support for what it was initially designed for; a scripting language to provide programming capabilities to data-descriptive and configuration languages. c) As the years moved Lua eventually implemented support for the storage of unicode strings, but doesn't provide any higher level functions (including character traversing or searching). This is so because by that time, that task had already fallen to the unicode libraries that had been developed in the meantime. Note: You know, it is a pointless exercise to try and downplay programming languages (any programming language) that has proven its worth by being generally adopted by the programming community. Adoption is the sign of a respected and well designed language. You are just wasting your time. Even if you can find here and there some apparent flaw of arguable design choice, that will be true of any programming language. From ben+python at benfinney.id.au Tue Sep 8 21:26:55 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 09 Sep 2015 11:26:55 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55EF86BA.4050502@gmx.com> Message-ID: <85y4gg8js0.fsf@benfinney.id.au> Mario Figueiredo writes: > Note: > You know, it is a pointless exercise to try and downplay programming > languages (any programming language) that has proven its worth by > being generally adopted by the programming community. Adoption is the > sign of a respected and well designed language. I can think of numerous widely-adpoted languages that disprove that assertion, by nevertheless being poorly-designed languages that are loathed by the vast majority of programmers who use them. On the other hand, I think there is merit in an argument that runs the other way: the quality of languages that a community adopts are predictive of the quality of programs that community will produce. -- \ ?It's up to the masses to distribute [music] however they want | `\ ? The laws don't matter at that point. People sharing music in | _o__) their bedrooms is the new radio.? ?Neil Young, 2008-05-06 | Ben Finney From rosuav at gmail.com Tue Sep 8 21:41:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Sep 2015 11:41:10 +1000 Subject: Python handles globals badly. In-Reply-To: <85y4gg8js0.fsf@benfinney.id.au> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55EF86BA.4050502@gmx.com> <85y4gg8js0.fsf@benfinney.id.au> Message-ID: On Wed, Sep 9, 2015 at 11:26 AM, Ben Finney wrote: > On the other hand, I think there is merit in an argument that runs the > other way: the quality of languages that a community adopts are > predictive of the quality of programs that community will produce. Broadly, yes. But regardless of its flaws, a language can be used because of a unique position; for instance, JavaScript/ECMAScript is going to continue to be the primary language of client-side web browser scripting for a long time, unless the major browsers all start supporting a new language (and until they all do, the benefit to one of them is low). ECMAScript isn't an abysmal language by any means, but it certainly has detectable flaws that come up fairly consistently. (Easy example: Find any fill-out form that says "Maximum X characters" and has a little counter that ticks down as you type. Now key in some astral characters. The odds are fairly good that they'll decrement the counter by 2 each.) If Apple declares that the iPhone 9 will be programmed exclusively in Even Swiftier, then it won't matter how terrible a language it is, people who want to say "Our app works on the iPhone 9" will write it in Even Swiftier. That's how PHP got to its position of being the default web scripting language for so many people - if you got yourself some cheap hosting, you could confidently expect PHP support, but until relatively recently, you couldn't depend on Ruby or Python (and certainly couldn't install your own); which, in turn, means that anyone who's building something for other people to deploy (a wiki, a forum, a blogging system, etc) will write it in PHP. And in all of these cases, a competent programmer can turn out good quality code. But if you take the average of all PHP programs, it'll tend toward a level that much better follows your estimate. A poorer language will generally have an overall poorer codebase. ChrisA From marfig at gmx.com Tue Sep 8 22:43:07 2015 From: marfig at gmx.com (Mario Figueiredo) Date: Wed, 09 Sep 2015 03:43:07 +0100 Subject: Python handles globals badly. In-Reply-To: <85y4gg8js0.fsf@benfinney.id.au> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55EF86BA.4050502@gmx.com> <85y4gg8js0.fsf@benfinney.id.au> Message-ID: <55EF9CBB.4070809@gmx.com> On 09-09-2015 02:26, Ben Finney wrote: > Mario Figueiredo writes: > >> Note: >> You know, it is a pointless exercise to try and downplay programming >> languages (any programming language) that has proven its worth by >> being generally adopted by the programming community. Adoption is the >> sign of a respected and well designed language. > > I can think of numerous widely-adpoted languages that disprove that > assertion, by nevertheless being poorly-designed languages that are > loathed by the vast majority of programmers who use them. > > On the other hand, I think there is merit in an argument that runs the > other way: the quality of languages that a community adopts are > predictive of the quality of programs that community will produce. > I'll have to agree to an extent. And you did remind me of PHP. So there's that. But in a way PHP served an important purpose in its time. Despite its flaws, it was once an important language that helped solve programming problems. And for that it served the purpose. Many of us went through it for the lack of a better fast-and-dirty alternative to server-side scripting. I remember others, like Cold Fusion or ASP. (Can't recall exactly why Cold Fusion didn't experience a wider support. But, truth be told I barely touched it). In any case, it stands that, unless a programming language is so ruined by bad design choices it is unusable, there is some kind of merit to its ability to solve computational problems. And Lua, Java, Python, C++, C, let me stop naming some popular or mildly popular languages, aren't nowhere close to being in that game. They are superior choices, despite our personal dislikes. I can't stand Java. I just don't think calling it a mistake. It's worth has been proven by its level of adoption and by the usable software that has been made with it. Javascript/ECMAScript is criticized by so many and yet there's no denying of its importance. Even today we struggle to find a better alternative to client-side scripting. Python is criticized by so many. And yet I don't think calling on Python developers as an inferior breed of programmers. From rosuav at gmail.com Tue Sep 8 23:03:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Sep 2015 13:03:41 +1000 Subject: Python handles globals badly. In-Reply-To: <55EF9CBB.4070809@gmx.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55EF86BA.4050502@gmx.com> <85y4gg8js0.fsf@benfinney.id.au> <55EF9CBB.4070809@gmx.com> Message-ID: On Wed, Sep 9, 2015 at 12:43 PM, Mario Figueiredo wrote: > I can't stand Java. I just don't think calling it a mistake. It's worth has > been proven by its level of adoption and by the usable software that has > been made with it. Javascript/ECMAScript is criticized by so many and yet > there's no denying of its importance. Even today we struggle to find a > better alternative to client-side scripting. Yeah, the reason for that is simple: anything else adds (sometimes massive) overhead. Would you suggest creating a client/server architecture, a RESTful API, and a triple-redundant HTTPS+SSL+Blowfish security system, to enumerate files on your hard drive? No, you'd just use ls(1). In the same way, there's not a lot of point downloading megs and megs of PyPyJS engine before running a single line of code, when you could skip that and just write in JS. Before Python can be "a better alternative", it has to overcome this massive hump. If Python 3.x were as well supported by web browsers as ECMAScript 5.x is, I think we'd see a dramatic shift in usage. But it ain't, so we won't. ChrisA From steve at pearwood.info Tue Sep 8 23:23:25 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 09 Sep 2015 13:23:25 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55efa62d$0$1653$c3e8da3$5496439d@news.astraweb.com> On Wed, 9 Sep 2015 09:55 am, Michael Torrie wrote: > On 09/08/2015 09:56 AM, Steven D'Aprano wrote: >> http://exple.tive.org/blarg/2013/10/22/citation-needed/ >> >> It's a wonderful read. > > I read this article, but I'm still uncertain to what his point actually > is. It's a great review of the history of C, some batch computing, and > IBM's CEO's penchant for boat racing. He tries to say that 0-based > indexing made for faster compiling, but given the runtime nature of > BCPL's ! operator, I don't see how it wouldn't affect runtime also. He > also says that saying pointers are the reason for 0-based indexing then > you're wrong, except that BCPL's creator says in this same article that > array variables are essentially pointers. You know about the boat races, so you obviously read the article... so how did you miss the part where the author explicitly raises the exact objection you do? [quote] ?Now just a second, Hoye?, I can hear you muttering. ?I?ve looked at the BCPL manual and read Dr. Richards? explanation and you?re not fooling anyone. That looks a lot like the efficient-pointer-arithmetic argument you were frothing about, except with exclamation points.? And you?d be very close to right. That?s exactly what it is ? the distinction is where those efficiencies take place, and why. [end quote] > A few people tried to point > this out in the comments but the author simply lambasted them, saying > thinks like, "Thanks for leaving a comment. I'm sure it's made you feel > clever." If people raise an objection that is already raised and covered in the text, I'd be a tad snarky too. Like the guy who objects, tells the author he ought to read Dijkstra, and *utterly failed* to notice that the article links to the same paper. Or the guy who somehow decided that the length of a 1-based array wasn't end-start, but "there?s always a +1 or -1 to be strewn in there". O rly? 0-based indexes: [0|1|2|3|4], end-start = 4-0 = 4 1-based indexes: [1|2|3|4|5], end-start = 5-1 = 4 And yes, the fellow Joe who completely missed the point of the blog post, and made the comment "You don?t think you?re wrong and that?s part of a much larger problem, but you?re still wrong" completely deserved to be called out on his lack of reading comprehension and smugness. > Like I say I guess I must have missed his point in there > somewhere. I suppose his point is C is 0-based because BCPL was, and > I'm sure that's true, but I'm also sure K&R saw some benefits to keeping > this in C. The post has *nothing* to do with why languages today might use 0-based arrays. It's not a post about which is better, or an attack on 0-based languages. It's about the historical forces that lead to design decisions being made, and how computer science is almost completely blind to those forces. Lacking real insight into why decisions are made, the IT field is dominated by superstitious post-hoc rationales being given as "the reason" why things are the way they are, when the truth is far more interesting. > In any case, 0-based indexing in Python makes a lot of sense when you > bring in the slicing syntax. Especially if you think of slicing as > operating on the boundaries between cells as it were. > > I used a 1-based indexed language (BASIC) for many years, and I was > always having to subtract 1 from things. So 0-based is simply more > convenient for me. There are certainly advantages to 0-based indexing. But there are also advantages to 1-based. For example, many mathematical algorithms are best written in terms of 1-based indexes, or at least are described as such. For example, quartile calculations. I'm constantly having to adjust such algorithms to work with Python. -- Steven From steve at pearwood.info Tue Sep 8 23:27:02 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 09 Sep 2015 13:27:02 +1000 Subject: Python handles globals badly. References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> <55E8E09A.3080309@gmail.com> Message-ID: <55efa705$0$1653$c3e8da3$5496439d@news.astraweb.com> On Tue, 8 Sep 2015 06:59 pm, Antoon Pardon wrote: > Op 04-09-15 om 02:47 schreef Mark Lawrence: >> On 04/09/2015 01:06, Michael Torrie wrote: >>> On 09/03/2015 01:05 PM, tdev at freenet.de wrote: >>> >>>> [The same e.g. with switch statement: add it] >>> >>> Switch is a nice-to-have thing, but definitely not essential. A PEP here >>> (probably already has been several) would at least be read anyway. >>> However, there are several idiomatic ways of accomplishing the same >>> thing that are often good enough and familiar to any Python programmer >>> out there. Since functions are first-class objects, often a dispatch >>> table is the best way to go here. >>> >> >> https://www.python.org/dev/peps/pep-3103/ "A Switch/Case Statement" by >> Guido van Rossum, "Rejection Notice - A quick poll during my keynote >> presentation at PyCon 2007 shows this proposal has no popular support. >> I therefore reject it". >> >> https://www.python.org/dev/peps/pep-0275/ "Switching on Multiple >> Values" by Marc-Andr? Lemburg, "Rejection Notice - A similar PEP for >> Python 3000, PEP 3103 [2], was already rejected, so this proposal has >> no chance of being accepted either." >> > Were those polls, like the poll he once did for the condtional expression? > There the poll indicated no specific proposal had a majority, so for each > specific proposal one could say it didn't have popular support, but the > majority still prefered to have a conditional expression. But at that > time Guido used that poll as an indication there was not enough support. In the case of conditional expression, there is *no good alternative*. Using if...then statement is too heavyweight, and cannot be used in an expression. Using "flag and true_value or false_value" is buggy -- it fails if true_value is itself false. Refactoring it to a function uses eager rather than lazy evaluation. So there was no existing alternative to a ternary if expression that worked correctly. In the case of case/switch, there is no consensus on what the statement should do, how it should work, what purpose it has, or what syntax it should use. Rather than "there's no alternative to a case statement", the situation was more like "there are many good alternatives to the various different case statements people want". -- Steven From ian.g.kelly at gmail.com Wed Sep 9 01:08:24 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 8 Sep 2015 23:08:24 -0600 Subject: Python handles globals badly. In-Reply-To: <55efa705$0$1653$c3e8da3$5496439d@news.astraweb.com> References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> <55E8E09A.3080309@gmail.com> <55efa705$0$1653$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 8, 2015 at 9:27 PM, Steven D'Aprano wrote: > Using if...then statement is too heavyweight, and cannot be used in an > expression. Using "flag and true_value or false_value" is buggy -- it fails > if true_value is itself false. Refactoring it to a function uses eager > rather than lazy evaluation. So there was no existing alternative to a > ternary if expression that worked correctly. I used to see "(flag and [true_value] or [false_value])[0]" fairly often, which solves the bugginess problem by ensuring that the second term can't be false. Not that I would recommend it over an actual conditional expression. From ben+python at benfinney.id.au Wed Sep 9 01:53:09 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 09 Sep 2015 15:53:09 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55EF86BA.4050502@gmx.com> <85y4gg8js0.fsf@benfinney.id.au> <55EF9CBB.4070809@gmx.com> Message-ID: <85twr487ga.fsf@benfinney.id.au> Mario Figueiredo writes: > On 09-09-2015 02:26, Ben Finney wrote: > > Mario Figueiredo writes: > > > >> You know, it is a pointless exercise to try and downplay > >> programming languages (any programming language) that has proven > >> its worth by being generally adopted by the programming community. > >> Adoption is the sign of a respected and well designed language. > > > > I can think of numerous widely-adpoted languages that disprove that > > assertion, by nevertheless being poorly-designed languages that are > > loathed by the vast majority of programmers who use them. > > I'll have to agree to an extent. And you did remind me of PHP. So > there's that. > > But in a way PHP served an important purpose in its time. Important, yes. > In any case, it stands that, unless a programming language is so > ruined by bad design choices it is unusable, there is some kind of > merit to its ability to solve computational problems. That's a *very much* lower bar than your earlier claim I responded to: that ?[widespread] adoption is the sign of a respected and well designed language?. > I can't stand Java. I just don't think calling it a mistake. It's > worth has been proven by its level of adoption and by the usable > software that has been made with it. Javascript/ECMAScript is > criticized by so many and yet there's no denying of its importance. You're making the case for importance, and capability to implement programs that solve problems. Maybe it's true, but it's irrelevant to the earlier point. It is quite separate from the language being well designed, and it is quite separate from the language being respectable. Many languages ? some of which you've named ? are poorly-designed, are not deserving of respect, despite being widely-adopted. > Even today we struggle to find a better alternative to client-side > scripting. Python is criticized by so many. And yet I don't think > calling on Python developers as an inferior breed of programmers. Glad to know that :-) -- \ ?I have the simplest tastes. I am always satisfied with the | `\ best.? ?Oscar Wilde | _o__) | Ben Finney From tjreedy at udel.edu Wed Sep 9 01:53:11 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 9 Sep 2015 01:53:11 -0400 Subject: Need Help w. PIP! In-Reply-To: References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <2579215.WiH7nXzSoB@PointedEars.de> Message-ID: On 9/8/2015 6:19 PM, Cody Piersall wrote: > > On Sat, Sep 5, 2015 at 3:14 AM, Thomas 'PointedEars' Lahn > > wrote: > > > > Cody Piersall wrote: > > > > > Please respond to the list as well as the person you're actually > talking > > > to. It works out better for everyone that way. (You should just > have to > > > "reply all" instead of "reply"). [Reply] should send the reply to the list. > > ?Better? as in ?getting/reading/downloading the same message *twice*?? > > > > The rule of thumb is: write here, read here. > > Some people email the list, but aren't subscribed to it. So I guess a > better rule is to just reply-to-all for the OP? Please no, not as a routine. I intentionally read python-list as a newsgroup via gmane.news.org so I can pick messages as I feel like without my mailbox being flooded. Anyone who want to read responses to something they send can do so via gmane. Also, [Reply All] tends to collect multiple CC names, and most people don't have the curtesy to properly prune it. -- Terry Jan Reedy From ben+python at benfinney.id.au Wed Sep 9 02:09:34 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 09 Sep 2015 16:09:34 +1000 Subject: Reply to author, reply to list, reply to all (was: Need Help w. PIP!) References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <2579215.WiH7nXzSoB@PointedEars.de> Message-ID: <85pp1s86ox.fsf_-_@benfinney.id.au> Terry Reedy writes: > On 9/8/2015 6:19 PM, Cody Piersall wrote: > > On Sat, Sep 5, 2015 at 3:14 AM, Thomas 'PointedEars' Lahn > > > wrote: > > > > > > Cody Piersall wrote: > > > > > > > Please respond to the list as well as the person you're > > > > actually talking to. It works out better for everyone that way. > > > > (You should just have to "reply all" instead of "reply"). > > [Reply] should send the reply to the list. The function named ?reply? normally means ?reply individually to the author?, and that's how it needs to stay. The ?reply to the list? function is present in many mail clients, and works fine for this mailing list; Google Mail seems to be a notable exception that its users should ask to change. > > Some people email the list, but aren't subscribed to it. People who fit that description are not participants in the forum, so excluding them from forum replies is the right thing to do. > > So I guess a better rule is to just reply-to-all for the OP? > > Please no, not as a routine. Agreed. -- \ ?Anyone who puts a small gloss on [a] fundamental technology, | `\ calls it proprietary, and then tries to keep others from | _o__) building on it, is a thief.? ?Tim O'Reilly, 2000-01-25 | Ben Finney From nick.a.sarbicki at gmail.com Wed Sep 9 02:37:01 2015 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Wed, 9 Sep 2015 07:37:01 +0100 Subject: Reply to author, reply to list, reply to all (was: Need Help w. PIP!) In-Reply-To: <85pp1s86ox.fsf_-_@benfinney.id.au> References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <2579215.WiH7nXzSoB@PointedEars.de> <85pp1s86ox.fsf_-_@benfinney.id.au> Message-ID: On 9 Sep 2015 07:11, "Ben Finney" wrote: > > Terry Reedy writes: > > > On 9/8/2015 6:19 PM, Cody Piersall wrote: > > > On Sat, Sep 5, 2015 at 3:14 AM, Thomas 'PointedEars' Lahn > > > > wrote: > > > > > > > > Cody Piersall wrote: > > > > > > > > > Please respond to the list as well as the person you're > > > > > actually talking to. It works out better for everyone that way. > > > > > (You should just have to "reply all" instead of "reply"). > > > > [Reply] should send the reply to the list. > > The function named ?reply? normally means ?reply individually to the > author?, and that's how it needs to stay. > > The ?reply to the list? function is present in many mail clients, and > works fine for this mailing list; Google Mail seems to be a notable > exception that its users should ask to change. > > > > Some people email the list, but aren't subscribed to it. > > People who fit that description are not participants in the forum, so > excluding them from forum replies is the right thing to do. > > > > So I guess a better rule is to just reply-to-all for the OP? > > > > Please no, not as a routine. > > Agreed. > > -- > \ ?Anyone who puts a small gloss on [a] fundamental technology, | > `\ calls it proprietary, and then tries to keep others from | > _o__) building on it, is a thief.? ?Tim O'Reilly, 2000-01-25 | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list My question then is do you reply to all (with a clean cc list but including an OP from outside the list) in response to a persons question, even if the question is relatively simple. For me it's appreciated so that you know someone is dealing with it. But then it can also result in flooding your inbox. - Nick. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Wed Sep 9 03:20:56 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 09 Sep 2015 17:20:56 +1000 Subject: Reply to author, reply to list, reply to all References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <2579215.WiH7nXzSoB@PointedEars.de> <85pp1s86ox.fsf_-_@benfinney.id.au> Message-ID: <85lhcg83dz.fsf@benfinney.id.au> Nick Sarbicki writes: > My question then is do you reply to all (with a clean cc list but > including an OP from outside the list) in response to a persons > question If the question was addressed to this forum, then answering the question should also be addressed to this forum. So: reply to list. > even if the question is relatively simple. I don't think the simplicity of the question changes the above. > For me it's appreciated so that you know someone is dealing with it. If you're asking a question in a public discussion forum (such as this one), then to see the ensuing dicussion you need to subscribe. > But then it can also result in flooding your inbox. If you don't want that, then don't have them delivered to your inbox. You can, for example, filter messages that are part of this forum to a separate mailbox; or you can subscribe using a non-email method such as NNTP. -- \ ?Courage is not the absence of fear, but the decision that | `\ something else is more important than fear.? ?Ambrose Redmoon | _o__) | Ben Finney From rosuav at gmail.com Wed Sep 9 03:24:37 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Sep 2015 17:24:37 +1000 Subject: Reply to author, reply to list, reply to all (was: Need Help w. PIP!) In-Reply-To: References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <2579215.WiH7nXzSoB@PointedEars.de> <85pp1s86ox.fsf_-_@benfinney.id.au> Message-ID: On Wed, Sep 9, 2015 at 4:37 PM, Nick Sarbicki wrote: > My question then is do you reply to all (with a clean cc list but including > an OP from outside the list) in response to a persons question, even if the > question is relatively simple. > > For me it's appreciated so that you know someone is dealing with it. But > then it can also result in flooding your inbox. Personally, what I do (which I'm doing with this post) is to use Gmail's "reply-all" feature, and then manually delete the individual addresses. Sometimes, half way through writing up a post, I decide to send it privately rather than to the list, and then I delete the list rather than the author. (Not usually with this list, though; more often with Savoynet, where private replies are more common, and there's no newsgroup equivalence.) ChrisA From ben+python at benfinney.id.au Wed Sep 9 03:38:23 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 09 Sep 2015 17:38:23 +1000 Subject: Reply to author, reply to list, reply to all References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <2579215.WiH7nXzSoB@PointedEars.de> <85pp1s86ox.fsf_-_@benfinney.id.au> Message-ID: <85d1xs82kw.fsf@benfinney.id.au> Chris Angelico writes: > Personally, what I do (which I'm doing with this post) is to use > Gmail's "reply-all" feature, and then manually delete the individual > addresses. That is testimony in support of the position that Google Mail is a poorly-designed interface for discussion forums such as mailing lists. Google Mail, like any other mail client, has full access to all the technical information (specified in RFC 3696) needed to implement a correct ?reply to list? behaviour. Users shouldn't need to do anything tediously manual like you describe, they should be presented with an obvious ?reply to the same place? function, as implemented in many mail clients for over a decade. That Google Mail continues to fail in this regard is something its users need to apply pressure to fix, or choose better mail clients until it improves. -- \ ?Anyone who believes exponential growth can go on forever in a | `\ finite world is either a madman or an economist.? ?Kenneth | _o__) Boulding | Ben Finney From lazlo.lebrun at googlemail.com Wed Sep 9 03:59:29 2015 From: lazlo.lebrun at googlemail.com (Laszlo Lebrun) Date: Wed, 9 Sep 2015 07:59:29 +0000 (UTC) Subject: PIP does not appear to handle diacritics correctly. References: Message-ID: On Tue, 08 Sep 2015 23:35:33 +0100, Mark Lawrence wrote: > On 08/09/2015 20:14, Laszlo Lebrun via Python-list wrote: >> >> Dear group, >> I do use Windows 7 and have a user name with diacritics. >> >> Whenever I am querying an extension with pip, it will fail since it >> does not pass on the user folder correctly. >> I thought PIP deals well with unicode, doesn't it? >> >> Has anyone a clue how to fix it? >> Thank you >> >> > Can you please cut and paste exactly what you tried and the failure > messages, as there's a lot of smart people around here but we're not > mind readers :) Which Python and pip version are you using? Did you > install pip yourself or did it come with your Python installation? Yes, you are right, let me append the message. Just after a fresh install of Python with PIP on Windows. Whenever I start PIP, I get: "Fatal error in launcher: Unable to create process using '"C:\Users \B??rgerGegenFlugl??rm\AppData\Local\Programs\Python\Python35-32 \python.exe" "C:\Users\B?rgerGegenFlugl?rm\AppData\Local\Programs\Python \Python35-32\Scripts\pip.exe" '" Where the correct path is "C:\Users\B?rgerGegenFlugl?rm\AppData..." The funny thing is that the message mentions the path twice, with different wrong codings. :-( Thank you for your help. -- Stand up against TTIP and ISDS ! From mail at timgolden.me.uk Wed Sep 9 04:13:41 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 9 Sep 2015 09:13:41 +0100 Subject: PIP does not appear to handle diacritics correctly. In-Reply-To: References: Message-ID: <55EFEA35.9070103@timgolden.me.uk> On 09/09/2015 08:59, Laszlo Lebrun via Python-list wrote: > On Tue, 08 Sep 2015 23:35:33 +0100, Mark Lawrence wrote: > >> On 08/09/2015 20:14, Laszlo Lebrun via Python-list wrote: >>> >>> Dear group, >>> I do use Windows 7 and have a user name with diacritics. >>> >>> Whenever I am querying an extension with pip, it will fail since it >>> does not pass on the user folder correctly. >>> I thought PIP deals well with unicode, doesn't it? > Yes, you are right, let me append the message. > Just after a fresh install of Python with PIP on Windows. > Whenever I start PIP, I get: > "Fatal error in launcher: Unable to create process using '"C:\Users > \B??rgerGegenFlugl??rm\AppData\Local\Programs\Python\Python35-32 > \python.exe" "C:\Users\B?rgerGegenFlugl?rm\AppData\Local\Programs\Python > \Python35-32\Scripts\pip.exe" '" > > Where the correct path is "C:\Users\B?rgerGegenFlugl?rm\AppData..." > > The funny thing is that the message mentions the path twice, with > different wrong codings. > :-( > What version of pip are you using? Since (from the path) I guess you have a 32-bit version of Python 3.5, I assume it's the version which was installed with that but just check: pip --version Hopefully someone here can help, but in fact pip is not part of core Python: the ensurepip mechanism (which *is* part of core Python) bootstraps a recent version of pip but it's maintained elsewhere. So you may need to raise this as a bug on the Pip tracker: https://github.com/pypa/pip/issues TJG From tjreedy at udel.edu Wed Sep 9 04:16:44 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 9 Sep 2015 04:16:44 -0400 Subject: Reply to author, reply to list, reply to all In-Reply-To: <85pp1s86ox.fsf_-_@benfinney.id.au> References: <56f811b9-aa5c-45c2-9daf-888a4b239f2f@googlegroups.com> <2579215.WiH7nXzSoB@PointedEars.de> <85pp1s86ox.fsf_-_@benfinney.id.au> Message-ID: On 9/9/2015 2:09 AM, Ben Finney wrote: > Terry Reedy writes: >> [Reply] should send the reply to the list. > > The function named ?reply? normally means ?reply individually to the > author?, and that's how it needs to stay. Oh, right. I was thinking of 'Followup' and that should go to the list, and does for me. -- Terry Jan Reedy From dieter at handshake.de Wed Sep 9 04:20:48 2015 From: dieter at handshake.de (dieter) Date: Wed, 09 Sep 2015 10:20:48 +0200 Subject: XML Binding References: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> <9b916796-623d-45d9-abe0-8bc7934ec42b@googlegroups.com> Message-ID: <87r3m8q9zz.fsf@handshake.de> Palpandi writes: > Is it better to use pyxb than lxml? > > What are the advantages of lxml and pyxb? "pyxb" has a different aim than "lxml". "lxml" is a general purpose library to process XML documents. It gives you an interface to the document's resources (elements, attributes, comments, processing instructions) on a low level independ from the document type. "pyxb" is different: there, you start with an XML schema description. You use "pyxb" to generate Python bindings for this schema. With such a binding generated, "pyxb" can parse XML documents following a known XML schema into the corresponding binding. The binding objects expose child (XML) elements and (XML) attributes as attributes of the binding object. Thus, the Python interface (as defined by the binding) is highly dependent on the type (aka XML schema) of the document. I use "lxml" for either simple XML processing or when the XML documents are not described by an XML schema. I use "pyxb" when the XML documents has an associated complex schema and the processing is rather complex. From rosuav at gmail.com Wed Sep 9 04:23:45 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Sep 2015 18:23:45 +1000 Subject: PIP does not appear to handle diacritics correctly. In-Reply-To: References: Message-ID: On Wed, Sep 9, 2015 at 5:59 PM, Laszlo Lebrun via Python-list wrote: > Whenever I start PIP, I get: > "Fatal error in launcher: Unable to create process using '"C:\Users > \B??rgerGegenFlugl??rm\AppData\Local\Programs\Python\Python35-32 > \python.exe" "C:\Users\B?rgerGegenFlugl?rm\AppData\Local\Programs\Python > \Python35-32\Scripts\pip.exe" '" > > Where the correct path is "C:\Users\B?rgerGegenFlugl?rm\AppData..." > > The funny thing is that the message mentions the path twice, with > different wrong codings. > :-( Peculiar. I don't know if it helps, but the first one seems to have been encoded UTF-8 and then decoded CP437; and the second has been encoded Latin-1 and decoded CP850. >>> "B?rgerGegenFlugl?rm".encode("utf-8").decode("437") 'B??rgerGegenFlugl??rm' >>> "B?rgerGegenFlugl?rm".encode("iso-8859-1").decode("850") 'B?rgerGegenFlugl?rm' But why those particular encodings... weird. ChrisA From hv at tbz-pariv.de Wed Sep 9 04:33:56 2015 From: hv at tbz-pariv.de (=?ISO-8859-1?Q?Thomas_G=FCttler?=) Date: Wed, 9 Sep 2015 01:33:56 -0700 (PDT) Subject: From logging to files to a better solution: syslog, Sentry, Logstash, .... Message-ID: <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> Up to now we use simple logging to files. We don't use syslog or an other server based solution. I am unsure which architecture works for our environment. Our environment: - django based applications - a lot of batch/cron jobs (non web gui) processing - One linux server runs several systems. Each system has its own virtualenv. - servers are running in the intranet of our customers. - We have access via VPN, but it is slow. And sometimes down for some minutes. - 40MByte logs per day per server. Why we are unhappy with logging to files: - filtering: We don't want to get INFO messages over the VPN. Background: Sometimes a there is too much logging and we don't want to pull gigabytes over the VPN. - Rotating: Rotating files is possible, but somehow cumbersome. - Support structured logging of values (json) in the future. I have not locked at Sentry or Logstash in detail. Which solution could fit for our environment? Please ask if you have question! Regards, Thomas G?ttler From harirammanohar159 at gmail.com Wed Sep 9 04:58:30 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Wed, 9 Sep 2015 01:58:30 -0700 (PDT) Subject: issue while doing pexpect ssh In-Reply-To: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> References: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> Message-ID: <789c4865-9526-4592-bcaa-9b83955b41d8@googlegroups.com> On Tuesday, 8 September 2015 17:07:24 UTC+5:30, hariramm... at gmail.com wrote: > Some where i am missing simple logic.... :) > > ===== > child = pexpect.spawn('ssh hari at hostname') > child.logfile = sys.stdout > child.expect('hari\'s Password: ') > ===== > > getting error as follows: > ============ > child.expect('hari\'s Password: ') > TypeError: must be str, not bytes > =========== > > Thanks... Hey Laura, spawnu worked for handling the unicode, thank you for that, yes i have already tried paramiko, it didnt worked for the same purpose (tried both sftp client and ssh client of paramiko module; finally while doing su getting the error as expecting tty terminal...) fabric will work but it is up to only python 2.7 so just i am trying to work out with pexpect whether it will be of any use or not. (my goal is to login to remote server then do su then execute commands...) Thank you for spawnu, now i got stuck with freezing issue similar to it is not returing to the shell prompt...its on waiting...i had to press ctrl+c =========== child.sendline(password) child.expect('-bash-4.1$') child.sendline('ls') print(child.before) child.sendline('su - user1') child.expect('-bash-4.1$') child.sendline('pwd; hostname') print(child.before) child.close() ================= output: ============ hari's Password: ls WARNING. You have accessed a private computer system. Unauthorized access,use,connection,or entry is not permitted and constitutes a crime punishable by law. We reserve the right to fully pursue criminal and civil legal penalties. All individuals using this computer system with or without proper authority are subject to having all their activities monitored and recorded. Anyone using this system implicitly consents to this monitoring. Any evidence of suspected criminal activity revealed by such monitoring may be provided to law enforcement officials. su - user1 lsTotal users logged in under your name (via BoKS): 3 (2 on this host) Total users logged in (via BoKS): 8324 (2 on this host) ######################################################################### # For Authorized Use Only # # # # Activities on this system are subject to being monitored # # or recorded for all users, authorized or unauthorized. # # Use of the system is considered consent to such monitoring. # # Any evidence of possible criminal activity may be provided # # to law enforcement. # # # ######################################################################### -bash-4.1$ ls -bash-4.1$ su - user1 -bash-4.1$ ^CTraceback (most recent call last): File "./rmcomments.py", line 16, in child.expect('-bash-4.1$') File "/ceopt/utils/python/3.4.3/custommodules/lib/python3.4/site-packages/pexpect/__init__.py", line 1451, in expect timeout, searchwindowsize) File "/ceopt/utils/python/3.4.3/custommodules/lib/python3.4/site-packages/pexpect/__init__.py", line 1466, in expect_list timeout, searchwindowsize) File "/ceopt/utils/python/3.4.3/custommodules/lib/python3.4/site-packages/pexpect/__init__.py", line 1535, in expect_loop c = self.read_nonblocking(self.maxread, timeout) File "/ceopt/utils/python/3.4.3/custommodules/lib/python3.4/site-packages/pexpect/__init__.py", line 958, in read_nonblocking r, w, e = self.__select([self.child_fd], [], [], timeout) File "/ceopt/utils/python/3.4.3/custommodules/lib/python3.4/site-packages/pexpect/__init__.py", line 1717, in __select return select.select(iwtd, owtd, ewtd, timeout) KeyboardInterrupt From harirammanohar159 at gmail.com Wed Sep 9 05:00:40 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Wed, 9 Sep 2015 02:00:40 -0700 (PDT) Subject: XML Binding In-Reply-To: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> References: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> Message-ID: <0618b133-a063-4752-85b7-1ee7518e5262@googlegroups.com> On Thursday, 3 September 2015 22:25:06 UTC+5:30, Palpandi wrote: > Hi All, > > Is there any module available in python standard library for XML binding? If not, any other suggestions. > > Which is good for parsing large file? > 1. XML binding > 2. Creating our own classes > > > Thanks, > Palpandi Hey you can use internal package itself, argparse will work good...even xmltree also... From wxjmfauth at gmail.com Wed Sep 9 05:05:38 2015 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 9 Sep 2015 02:05:38 -0700 (PDT) Subject: Silly question about pip In-Reply-To: <39e93a61-c134-45e3-ac48-9c0af98c674f@googlegroups.com> References: <54d12451-0160-4acb-b850-b2f49838fe42@googlegroups.com> <55ef263e$0$23821$e4fe514c@news.xs4all.nl> <39e93a61-c134-45e3-ac48-9c0af98c674f@googlegroups.com> Message-ID: <0e72d8e1-c454-4087-a27b-6fe8f93b9a33@googlegroups.com> Le mardi 8 septembre 2015 21:02:31 UTC+2, wxjm... at gmail.com a ?crit?: > Le mardi 8 septembre 2015 20:18:20 UTC+2, Irmen de Jong a ?crit?: > > On 8-9-2015 17:54, wxjmfauth at gmail.com wrote: > > > win7 / py433 > > > > > > How to downgrade from the latest pip (7.1.2) to > > > the previous one? > > > I'm sorry, I do not remember the numerous msgs > > > I saw when updating. (Yesterday) > > > > > > (I'm serious) > > > > > > Now, what? > > > > > > > I think: > > > > $ pip install --upgrade pip==7.0.0 > > > > > > would do the trick, where you substitute the required version number for 7.0.0. > > > > > > Irmen > > Addendum (your question) > > > pip install --upgrade pip > > which probably selects the latest version --- > pip install --upgrade pip==6.0.8 is indeed a valid command except I'm seeing the same previous mess. From harirammanohar159 at gmail.com Wed Sep 9 05:19:50 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Wed, 9 Sep 2015 02:19:50 -0700 (PDT) Subject: issue while doing pexpect ssh In-Reply-To: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> References: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> Message-ID: <21277811-df80-49d8-9249-c58b7fdf01c2@googlegroups.com> On Tuesday, 8 September 2015 17:07:24 UTC+5:30, hariramm... at gmail.com wrote: > Some where i am missing simple logic.... :) > > ===== > child = pexpect.spawn('ssh hari at hostname') > child.logfile = sys.stdout > child.expect('hari\'s Password: ') > ===== > > getting error as follows: > ============ > child.expect('hari\'s Password: ') > TypeError: must be str, not bytes > =========== > > Thanks... Hey All, I am able to achieve this using pxssh.. thank you for help... From stefan_ml at behnel.de Wed Sep 9 05:44:07 2015 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 9 Sep 2015 11:44:07 +0200 Subject: XML Binding In-Reply-To: <87r3m8q9zz.fsf@handshake.de> References: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> <9b916796-623d-45d9-abe0-8bc7934ec42b@googlegroups.com> <87r3m8q9zz.fsf@handshake.de> Message-ID: dieter schrieb am 09.09.2015 um 10:20: > Palpandi writes: >> Is it better to use pyxb than lxml? >> >> What are the advantages of lxml and pyxb? > > "pyxb" has a different aim than "lxml". > > "lxml" is a general purpose library to process XML documents. > It gives you an interface to the document's resources (elements, > attributes, comments, processing instructions) on a low level > independ from the document type. lxml's toolbox is actually larger than that. There's also lxml.objectify which provides a Python object interface to the XML tree, similar to what data binding would give you. And you can stick your own Element object implementations into it if you feel a need to simplify the API itself and/or adapt it to a given document format. http://lxml.de/objectify.html Stefan From larry.martell at gmail.com Wed Sep 9 06:37:15 2015 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 9 Sep 2015 06:37:15 -0400 Subject: Getting response over logging socket Message-ID: I have an app that uses the logging package with a SocketHandler to send messages. Now I've been asked to change it so that it can receive a response for each log message sent. It appears there is no way to do this with logging package. Is that true? Can I not receive data over a socket used in a logging handler? From antoon.pardon at rece.vub.ac.be Wed Sep 9 06:42:33 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 09 Sep 2015 12:42:33 +0200 Subject: Python handles globals badly. In-Reply-To: <55EF7556.2090409@gmail.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> <55EF7556.2090409@gmail.com> Message-ID: <55F00D19.2000101@rece.vub.ac.be> Op 09-09-15 om 01:55 schreef Michael Torrie: > In any case, 0-based indexing in Python makes a lot of sense when you > bring in the slicing syntax. Especially if you think of slicing as > operating on the boundaries between cells as it were. Then you have never used slices with a negative step. If slicing would operate on the boundaries between cells then the reverse of lst[2:7] would be lst[7:2:-1] instead it is lst[6:1:-1] This gets you in trouble when you want to reverse through lst[0:8] which would be lst[7:-1:-1] but now the special meaning of negative indexes kicks in and you are screwed. -- Antoon Pardon From lac at openend.se Wed Sep 9 06:45:56 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 09 Sep 2015 12:45:56 +0200 Subject: issue while doing pexpect ssh In-Reply-To: <789c4865-9526-4592-bcaa-9b83955b41d8@googlegroups.com> References: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> <789c4865-9526-4592-bcaa-9b83955b41d8@googlegroups.com> Message-ID: <201509091045.t89AjuJC009931@fido.openend.se> In a message of Wed, 09 Sep 2015 01:58:30 -0700, harirammanohar159 at gmail.com wr ites: >Thank you for spawnu, now i got stuck with freezing issue similar to it is not returing to the shell prompt...its on waiting...i had to press ctrl+c > >=========== >child.sendline(password) >child.expect('-bash-4.1$') >child.sendline('ls') >print(child.before) >child.sendline('su - user1') >child.expect('-bash-4.1$') >child.sendline('pwd; hostname') >print(child.before) >child.close() >WARNING. You have accessed a private computer system. Any doubts we had about whether the computer policy authorities as this place are 'nuttier than 2 trees full of squirrels' are now put to rest. I just hope I am not helping you do things that is going to end up with them trying to put you in jail. Poor you. >su - user1 > >lsTotal users logged in under your name (via BoKS): 3 (2 on this host) >Total users logged in (via BoKS): 8324 (2 on this host) >-bash-4.1$ ls >-bash-4.1$ su - user1 >-bash-4.1$ Okay. Instead of waiting for that bash-4.1 prompt after you issue your su, issue whoami and wait to see if it returns user1. That way we can see if the problem is with expect waiting for the prompt which for some reason it is not seeing, or whether it is just lost, lost, lost. Also, for informational purposes try your su without the '-' just "su user1", and see if it is some part of the 'provide an environment similar to what the user would get if the user logged in directly' ability of su that is confusing things. Laura From lac at openend.se Wed Sep 9 06:47:57 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 09 Sep 2015 12:47:57 +0200 Subject: issue while doing pexpect ssh In-Reply-To: <21277811-df80-49d8-9249-c58b7fdf01c2@googlegroups.com> References: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> <21277811-df80-49d8-9249-c58b7fdf01c2@googlegroups.com> Message-ID: <201509091047.t89Alv9x010484@fido.openend.se> >Hey All, > >I am able to achieve this using pxssh.. thank you for help... Great to hear it. Good luck with the crazies. Laura From lazlo.lebrun at googlemail.com Wed Sep 9 07:03:31 2015 From: lazlo.lebrun at googlemail.com (Laszlo Lebrun) Date: Wed, 9 Sep 2015 11:03:31 +0000 (UTC) Subject: PIP does not appear to handle diacritics correctly. References: Message-ID: On Wed, 09 Sep 2015 09:13:41 +0100, Tim Golden wrote: > On 09/09/2015 08:59, Laszlo Lebrun via Python-list wrote: >> On Tue, 08 Sep 2015 23:35:33 +0100, Mark Lawrence wrote: >> >>> On 08/09/2015 20:14, Laszlo Lebrun via Python-list wrote: >>>> >>>> Dear group, >>>> I do use Windows 7 and have a user name with diacritics. >>>> >>>> Whenever I am querying an extension with pip, it will fail since it >>>> does not pass on the user folder correctly. >>>> I thought PIP deals well with unicode, doesn't it? > >> Yes, you are right, let me append the message. >> Just after a fresh install of Python with PIP on Windows. >> Whenever I start PIP, I get: >> "Fatal error in launcher: Unable to create process using '"C:\Users >> \B??rgerGegenFlugl??rm\AppData\Local\Programs\Python\Python35-32 >> \python.exe" >> "C:\Users\B?rgerGegenFlugl?rm\AppData\Local\Programs\Python >> \Python35-32\Scripts\pip.exe" '" >> >> Where the correct path is "C:\Users\B?rgerGegenFlugl?rm\AppData..." >> >> The funny thing is that the message mentions the path twice, with >> different wrong codings. >> :-( >> >> > What version of pip are you using? Since (from the path) I guess you > have a 32-bit version of Python 3.5, I assume it's the version which was > installed with that but just check: > > pip --version > Sorry I can't even execute that one. I keep getting the weird error message. But I just downloaded it 3 days ago, so it should be the current one. > Hopefully someone here can help, but in fact pip is not part of core > Python: the ensurepip mechanism (which *is* part of core Python) > bootstraps a recent version of pip but it's maintained elsewhere. > > So you may need to raise this as a bug on the Pip tracker: > > https://github.com/pypa/pip/issues > done. Thank you. -- Stand up against TTIP and ISDS ! From lazlo.lebrun at googlemail.com Wed Sep 9 07:07:20 2015 From: lazlo.lebrun at googlemail.com (Laszlo Lebrun) Date: Wed, 9 Sep 2015 11:07:20 +0000 (UTC) Subject: PIP does not appear to handle diacritics correctly. References: <17f087e9-59d4-4f23-8e3c-d054f03674f6@googlegroups.com> Message-ID: On Wed, 09 Sep 2015 00:22:31 -0700, wxjmfauth wrote: > Yes, I know how to fix all these problems. I know as well: have a user, which name is just plain ASCII. But it sucks to rebuild everything... -- Stand up against TTIP and ISDS ! From harirammanohar159 at gmail.com Wed Sep 9 07:22:52 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Wed, 9 Sep 2015 04:22:52 -0700 (PDT) Subject: issue while doing pexpect ssh In-Reply-To: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> References: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> Message-ID: On Tuesday, 8 September 2015 17:07:24 UTC+5:30, hariramm... at gmail.com wrote: > Some where i am missing simple logic.... :) > > ===== > child = pexpect.spawn('ssh hari at hostname') > child.logfile = sys.stdout > child.expect('hari\'s Password: ') > ===== > > getting error as follows: > ============ > child.expect('hari\'s Password: ') > TypeError: must be str, not bytes > =========== > > Thanks... Hi Laura, Basically its the same, no difference if i keep su user1... i am getting the desired output with a single host, but if i keep for loop for multiple hosts, remaining are skipped saying as below: pexpect.TIMEOUT: Timeout exceeded. During handling of the above exception, another exception occurred: pexpect.TIMEOUT: Timeout exceeded. only 1st host is getting executed. how to control child.logout() and make for loop continue... From alister.nospam.ware at ntlworld.com Wed Sep 9 07:41:33 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 9 Sep 2015 11:41:33 +0000 (UTC) Subject: Hi am new to python References: Message-ID: On Tue, 08 Sep 2015 17:44:26 -0500, Nassim Gannoun wrote: > Hi I'm also new to Python but would like to reply. > Like others have stated there is a built in function (sum) that can give > the sum of the elements of a list, but if what you are trying to do is > learn how to use the while command here is some code that will work. > Your question: > My question is in a while loop; how do l sum all the numbers in the > given list (list_a)? > > list_a = [8, 5, 2, 4] > sum_a = 0 # for storing the sum of list_a i = 0 # for looping through > the list_a# Use a while loop to sum all numbers in list_a# If you store > the sums into sum_a print(sum_a) # should print 19 My answer: > list_a = [8, 5, 2, 4] > > > > sum_a = 0 i = 0 while i < (len(list_a)): > sum_a += list_a[i] > i += 1 > > > print(sum_a) > This is OK a a learning excise but it is just about the worst way to achieve the result in python. It should be considered as an example of how NOT to perform the task. I do hope this is NOT a homework question set by a teacher as it would get the student into bad habits. -- It's spelled Linux, but it's pronounced `Not Windows' It's spelled Windows, but it's pronounced `Aieeeeeeee!' -- Shannon Hendrix From rosuav at gmail.com Wed Sep 9 09:10:07 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Sep 2015 23:10:07 +1000 Subject: PIP does not appear to handle diacritics correctly. In-Reply-To: References: <17f087e9-59d4-4f23-8e3c-d054f03674f6@googlegroups.com> Message-ID: On Wed, Sep 9, 2015 at 9:07 PM, Laszlo Lebrun via Python-list wrote: > On Wed, 09 Sep 2015 00:22:31 -0700, wxjmfauth wrote: > >> Yes, I know how to fix all these problems. > > I know as well: have a user, which name is just plain ASCII. > But it sucks to rebuild everything... Don't bother responding to jmf - he's our resident Unicode troll. His posts don't get through to me any more, except when someone responds :) Not sure where they're getting blocked; probably at the news<->list boundary. You shouldn't have to restrict your username to ASCII. It's 2015, and non-ASCII names should work everywhere. Anywhere they don't is a bug to be fixed, and I'm confident the pip folks will treat this with the respect it deserves. ChrisA From larry at hastings.org Wed Sep 9 09:42:02 2015 From: larry at hastings.org (Larry Hastings) Date: Wed, 9 Sep 2015 06:42:02 -0700 Subject: [RELEASED] Python 3.5.0rc4 is now available! Message-ID: <55F0372A.3050007@hastings.org> On behalf of the Python development community and the Python 3.5 release team, I'm surprised to announce the availability of Python 3.5.0rc4, also known as Python 3.5.0 Release Candidate 4. Python 3.5.0 Release Candidate 3 was only released about a day ago. However: during testing, a major regression was discovered, reported on the issue tracker as #25027: http://bugs.python.org/issue25027 Python 3.5 includes some big changes on how Python is built on Windows. One of those changes resulted in Python processes on Windows exceeding the maximum number of loadable shared libraries. As a result Windows builds of Python could no longer run major Python software stacks like Pandas and Jupyter. Fixing this required non-trivial last-minute changes to the Windows build--and those changes need testing. We therefore elected to insert an extra release candidate before the final release, to get these changes into your hands as soon as possible, so that Windows users could test these changes. As with all other Python 3.5 releases to date, this is a preview release, and its use is not recommended for production settings. However, users are encouraged to test with Python 3.5.0rc4, /especially/ Windows users who build or make use of numerous external packages. (Non-Windows users will find little difference between Python 3.5.0rc3 and Python 3.5.0rc4.) You can find Python 3.5.0rc4 here: https://www.python.org/downloads/release/python-350rc4/ Windows and Mac users: please read the important platform-specific "Notes on this release" section near the end of that page. Please kick the tires, //arry/ p.s. Special thanks from the Python 3.5 release team to Christoph Gohlke for the bug report! -------------- next part -------------- An HTML attachment was scrubbed... URL: From antoon.pardon at rece.vub.ac.be Wed Sep 9 11:04:00 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 09 Sep 2015 17:04:00 +0200 Subject: Python handles globals badly. In-Reply-To: <55efa705$0$1653$c3e8da3$5496439d@news.astraweb.com> References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> <55E8E09A.3080309@gmail.com> <55efa705$0$1653$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55F04A60.9050402@rece.vub.ac.be> Op 09-09-15 om 05:27 schreef Steven D'Aprano: > >> Were those polls, like the poll he once did for the condtional expression? >> There the poll indicated no specific proposal had a majority, so for each >> specific proposal one could say it didn't have popular support, but the >> majority still prefered to have a conditional expression. But at that >> time Guido used that poll as an indication there was not enough support. > In the case of conditional expression, there is *no good alternative*. Yet there were people who passionatly argued against introducing one. Even when list comprehensions were introduced where they really would be useful some people still fought it. Just to show that people fighting something is not a strong argument. > Using if...then statement is too heavyweight, and cannot be used in an > expression. Using "flag and true_value or false_value" is buggy -- it fails > if true_value is itself false. Refactoring it to a function uses eager > rather than lazy evaluation. So there was no existing alternative to a > ternary if expression that worked correctly. Yes there was. There were even two. One was packing your values into a one element list, the other was packing them in a lambda. It was ugly but it was what people came up with for lack of better. > In the case of case/switch, there is no consensus on what the statement > should do, how it should work, what purpose it has, or what syntax it > should use. Rather than "there's no alternative to a case statement", the > situation was more like "there are many good alternatives to the various > different case statements people want". Since when does Guido need a consensus? Look the developers have only limited time, and they get to choose what they consider a priority and what they don't. And if they think other things have higher priority, fine by me. But don't come with, no support/consensus with the users, because if the dev-team thinks something is a good idea, they'll implement it without much consideration for support/consensus among the users. -- Antoon Pardon From mail at timgolden.me.uk Wed Sep 9 11:55:01 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 9 Sep 2015 16:55:01 +0100 Subject: PIP does not appear to handle diacritics correctly. In-Reply-To: References: <17f087e9-59d4-4f23-8e3c-d054f03674f6@googlegroups.com> Message-ID: <55F05655.305@timgolden.me.uk> On 09/09/2015 14:10, Chris Angelico wrote: > Don't bother responding to jmf - he's our resident Unicode troll. His > posts don't get through to me any more, except when someone responds > :) Not sure where they're getting blocked; probably at the news<->list > boundary. They're held for mailing list moderation. If they're the usual rant I discard them. > You shouldn't have to restrict your username to ASCII. It's 2015, and > non-ASCII names should work everywhere. Anywhere they don't is a bug > to be fixed, and I'm confident the pip folks will treat this with the > respect it deserves. Definitely. I'll try to reproduce this at home (when I have access to a machine on which I can create a suitably unicode-y username). TJG From auriocus at gmx.de Wed Sep 9 12:09:14 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 09 Sep 2015 18:09:14 +0200 Subject: Python handles globals badly. In-Reply-To: <55efa62d$0$1653$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> <55efa62d$0$1653$c3e8da3$5496439d@news.astraweb.com> Message-ID: Am 09.09.15 um 05:23 schrieb Steven D'Aprano: > And yes, the fellow Joe who completely missed the point of the blog post, > and made the comment "You don?t think you?re wrong and that?s part of a > much larger problem, but you?re still wrong" completely deserved to be > called out on his lack of reading comprehension and smugness. This sentence is a very arrogant one, yes, but it is quoted from the article. Overall I have the feeling that the point he wants to make is a very subtle one. Christian From wolfgang.maier at biologie.uni-freiburg.de Wed Sep 9 12:16:02 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 9 Sep 2015 18:16:02 +0200 Subject: PIP does not appear to handle diacritics correctly. In-Reply-To: References: Message-ID: <55F05B42.8010803@biologie.uni-freiburg.de> On 09.09.2015 10:23, Chris Angelico wrote: > On Wed, Sep 9, 2015 at 5:59 PM, Laszlo Lebrun via Python-list > wrote: >> Whenever I start PIP, I get: >> "Fatal error in launcher: Unable to create process using '"C:\Users >> \B??rgerGegenFlugl??rm\AppData\Local\Programs\Python\Python35-32 >> \python.exe" "C:\Users\B?rgerGegenFlugl?rm\AppData\Local\Programs\Python >> \Python35-32\Scripts\pip.exe" '" >> >> Where the correct path is "C:\Users\B?rgerGegenFlugl?rm\AppData..." >> >> The funny thing is that the message mentions the path twice, with >> different wrong codings. >> :-( > I may be wrong, but isn't the error message suggesting that this is a bug in the py launcher instead of in pip? If I remember a post from a recent thread correctly, then pip.exe is just a script using the launcher. If that's true, shouldn't the recommended: python -m pip be a workaround? I might be wrong, but it's worth a try. Best, Wolfgang From mail at timgolden.me.uk Wed Sep 9 12:21:59 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 9 Sep 2015 17:21:59 +0100 Subject: PIP does not appear to handle diacritics correctly. In-Reply-To: <55F05B42.8010803@biologie.uni-freiburg.de> References: <55F05B42.8010803@biologie.uni-freiburg.de> Message-ID: <55F05CA7.50608@timgolden.me.uk> On 09/09/2015 17:16, Wolfgang Maier wrote: > On 09.09.2015 10:23, Chris Angelico wrote: >> On Wed, Sep 9, 2015 at 5:59 PM, Laszlo Lebrun via Python-list >> wrote: >>> Whenever I start PIP, I get: >>> "Fatal error in launcher: Unable to create process using '"C:\Users >>> \B??rgerGegenFlugl??rm\AppData\Local\Programs\Python\Python35-32 >>> \python.exe" >>> "C:\Users\B?rgerGegenFlugl?rm\AppData\Local\Programs\Python >>> \Python35-32\Scripts\pip.exe" '" >>> >>> Where the correct path is "C:\Users\B?rgerGegenFlugl?rm\AppData..." >>> >>> The funny thing is that the message mentions the path twice, with >>> different wrong codings. >>> :-( >> > > I may be wrong, but isn't the error message suggesting that this is a > bug in the py launcher instead of in pip? > If I remember a post from a recent thread correctly, then pip.exe is > just a script using the launcher. > If that's true, shouldn't the recommended: > > python -m pip > > be a workaround? > > I might be wrong, but it's worth a try. Actually, that's a good point. Especially given the start of the error message... TJG From breamoreboy at yahoo.co.uk Wed Sep 9 12:46:37 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 9 Sep 2015 17:46:37 +0100 Subject: Python handles globals badly. In-Reply-To: <55F04A60.9050402@rece.vub.ac.be> References: <4602a32c-5109-47dd-95bb-b9723738f07f@googlegroups.com> <55E8E09A.3080309@gmail.com> <55efa705$0$1653$c3e8da3$5496439d@news.astraweb.com> <55F04A60.9050402@rece.vub.ac.be> Message-ID: On 09/09/2015 16:04, Antoon Pardon wrote: > Op 09-09-15 om 05:27 schreef Steven D'Aprano: > >> In the case of case/switch, there is no consensus on what the statement >> should do, how it should work, what purpose it has, or what syntax it >> should use. Rather than "there's no alternative to a case statement", the >> situation was more like "there are many good alternatives to the various >> different case statements people want". > > Since when does Guido need a consensus? Look the developers have only limited > time, and they get to choose what they consider a priority and what they don't. > And if they think other things have higher priority, fine by me. But don't > come with, no support/consensus with the users, because if the dev-team thinks > something is a good idea, they'll implement it without much consideration for > support/consensus among the users. > A number of recent PEPs have been given delegated authority, so someone other than Guido makes the final decision as to whether to accept or reject it. I can only suggest you don't follow some of the intense wars of words that go on on python-dev, or even python-ideas, as the part about this dev-team simply overriding users is nonsense. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve at pearwood.info Wed Sep 9 13:22:41 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 10 Sep 2015 03:22:41 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> <55efa62d$0$1653$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f06ae1$0$1650$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Sep 2015 02:09 am, Christian Gollwitzer wrote: > Am 09.09.15 um 05:23 schrieb Steven D'Aprano: >> And yes, the fellow Joe who completely missed the point of the blog post, >> and made the comment "You don?t think you?re wrong and that?s part of a >> much larger problem, but you?re still wrong" completely deserved to be >> called out on his lack of reading comprehension and smugness. > > This sentence is a very arrogant one, yes, but it is quoted from the > article. Overall I have the feeling that the point he wants to make is a > very subtle one. Subtle enough that his quoting the author's words back at him escaped me, but I suspect not subtle enough to escape the author's notice. Hence the reply "Thanks for leaving your comment. I?m sure it?s made you feel very clever." I think my favourite is the guy who claims that the reason natural languages all count from 1 is because the Romans failed to invent zero. (What about languages that didn't derive from Latin, say, Chinese?) And that now that we have zero, counting from it should be more natural. So if you give somebody two apples, but no banana, and ask them to count their apples, they would count "Zero, one... therefore I have two apples". And if you then ask them to count their bananas, they would do what? +++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++ -- Steven From gary719_list1 at verizon.net Wed Sep 9 13:27:03 2015 From: gary719_list1 at verizon.net (Gary Roach) Date: Wed, 09 Sep 2015 10:27:03 -0700 Subject: Lesson 39 of Learning Python the Hard Way hangs Message-ID: <55F06BE7.1080709@verizon.net> Hi all I am new to python but not programming (Although rusty) and am using Learning Python The Hard Way. I really like it. System: --------------- Debian 8 (jessie) KDE Desktop Python 2.7 (It's going to be a while before 2,7 goes away. There is just too much code out there. Ninja-IDE IDE - I like this a lot. I can't seem to find out how to put breaks into the code though. The debugger plugin is installed. -------------- For some reason lesson 39 is hanging and I can't find the cause. A print statement inserted into the get_slot function just after bucket shows that get_bucket is returning an []. It' not surprising that enumerate() doesn't like this very much. I just can't find the cause. The error message is as follows: ------------------------------------------- Running: /root/mystuff/mystuff/ex39_test.py (Wed Sep 9 09:57:51 2015) Traceback (most recent call last): File "/root/mystuff/mystuff/ex39_test.py", line 6, in hashmap.set(states, 'Oregon', 'OR') File "/root/mystuff/mystuff/hashmap.py", line 50, in set i, k, v = get_slot(aMap, key) TypeError: 'NoneType' object is not iterable Execution Successful! NOTE: Line 50 is the - i, k, v = get_slot(aMap, key)- of def set. -------------------------------------------- The calling code is: -------------------------------------------- # -*- coding: utf-8 -*- import hashmap # creat a mapping of stat to abbreviation states = hashmap.new() hashmap.set(states, 'Oregon', 'OR') -------------------------------------------- The hashmap code is as follows: -------------------------------------------- def new(num_buckets=256): """Initializes a Map with the given number of buckets.""" aMap = [] for i in range(0, num_buckets): aMap.append([]) return aMap def hash_key(aMap, key): """Given a key this will create a number and then convert it to an index for the aMap's buckets.""" return hash(key) % len(aMap) def get_bucket(aMap, key): """Given a key, find the bucket where it would go.""" bucket_id = hash_key(aMap, key) return aMap[bucket_id] def get_slot(aMap, key, default=None): """ Returns the index, key, and value of a slot found in a bucket. Returns -1, key, and default (None if not set) when not found. """ bucket = get_bucket(aMap, key) for i, kv in enumerate(bucket): k, v = kv if key == k: return i, k, v return -1, key, default def get(aMap, key, default=None): """Gets the value in a bucket for the given key, or the default.""" i, k, v = get_slot(aMap, key, default=default) return v def set(aMap, key, value): """Sets the key to the value, replacing any existing value.""" bucket = get_bucket(aMap, key) i, k, v = get_slot(aMap, key) if i >= 0: # the key exists, replace it bucket[i] = (key, value) else: # the key does not, append to create it bucket.append((key, value)) def delete(aMap, key): """Deletes the given key from the Map.""" bucket = get_bucket(aMap, key) for i in xrange(len(bucket)): k, v = bucket[i] if key == k: del bucket[i] break def list(aMap): """Prints out what's in the Map.""" for bucket in aMap: if bucket: for k, v in bucket: print k, v Very frustrating and probably a stupid error. Any help will be sincerely appreciated. Gary R. From rosuav at gmail.com Wed Sep 9 13:27:28 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Sep 2015 03:27:28 +1000 Subject: Python handles globals badly. In-Reply-To: <55f06ae1$0$1650$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> <55efa62d$0$1653$c3e8da3$5496439d@news.astraweb.com> <55f06ae1$0$1650$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Sep 10, 2015 at 3:22 AM, Steven D'Aprano wrote: > I think my favourite is the guy who claims that the reason natural languages > all count from 1 is because the Romans failed to invent zero. (What about > languages that didn't derive from Latin, say, Chinese?) And that now that > we have zero, counting from it should be more natural. So if you give > somebody two apples, but no banana, and ask them to count their apples, > they would count "Zero, one... therefore I have two apples". And if you > then ask them to count their bananas, they would do what? They would respond that there is a subtle difference between "Please count your bananas" and "Please, Count... you're bananas". ChrisA From steve at pearwood.info Wed Sep 9 13:36:32 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 10 Sep 2015 03:36:32 +1000 Subject: Python 3.3 couldnt find its libraries. References: Message-ID: <55f06e20$0$1640$c3e8da3$5496439d@news.astraweb.com> On Wed, 9 Sep 2015 07:37 pm, ?????? ??????????????? wrote: [...] > [root at superhost ~]# /opt/rh/python33/root/usr/bin/python -V > /opt/rh/python33/root/usr/bin/python: error while loading shared > libraries: libpython3.3m.so.1.0: cannot open shared object file: No such > file or directory Again? Nikos, this looks like exactly the same error you got back in April, in the thread with subject line "Question Installing latest Python". The date was around 29 Apr 2015, possibly a couple of days either side. I suggest you go back and read the replies to that. If this is the same problem, then I think these were the steps you followed last time. Try running this as a regular user: python3 -c "import sys; print(sys.executable)" Does it work? If not, run this as the root user: ldconfig That will tell your system to cache any shared libraries it knows about. yum is supposed to do that for you, but perhaps it didn't. Now try running the python3 test above. Does it work? Then the problem is solved and you can stop reading. If you get the same error, then run this as root: find /opt -name libpython3.3m.so.1.0 If it returns a single result, that's good. If it returns no results, try this instead: find / -name libpython3.3m.so.1.0 2> /dev/null It may take a while: it's going to search your entire hard drive. Hopefully that will return a single result: let's say it returns /this/that/libpython3.3m.so.1.0 then you need to edit /etc/ld.so.conf and add this line to the end: /this/that Save your changes, run ldconfig again, and hopefully python3 will now work. -- Steven From steve at pearwood.info Wed Sep 9 13:55:54 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 10 Sep 2015 03:55:54 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> Message-ID: <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> On Wed, 9 Sep 2015 11:09 am, Mario Figueiredo wrote: > You know, it is a pointless exercise to try and downplay programming > languages (any programming language) that has proven its worth by being > generally adopted by the programming community. Adoption is the sign of > a respected and well designed language. Counter-examples: PHP and C. Adoption of programming languages is driven by many things, technical excellence and careful design are not even in the top 10. Most of them are social in nature, particularly "what is everyone else using?". Network effects dominate: you could design the perfect language, but if nobody else uses it, nobody will use it. Sometimes a language will actually gain a kind of technical excellence despite some really shitty design decisions -- but usually at great cost elsewhere. C is a good example of that. Due to lousy decisions made by the designers of C, it is a language really well suited for writing fast, incorrect code. Since programmers benefit from writing fast code, but rarely suffer from writing incorrect code (it's mostly users who suffer the consequences of security holes), we have ended up in the situation we live in now, where compilers compete to write faster and faster code that has less and less relation to what the programmer intended. (I wanted to link to the "Everything Is Broken" essay on The Medium, but the page appears to be gone. This makes me sad. BTW, what's the point of Google's cache when it just redirects to the original, missing, page?) In fairness to the C creators, I'm sure that nobody back in the early seventies imagined that malware and security vulnerabilities would be as widespread as they have become. But still, the fundamental decisions made by C are lousy. Assignment is an expression? Lack of first-class arrays? The C pre-processor? They're pretty awful, but *nothing* in the entire history of computing, not even Intercal and the COMEFROM command, comes even close to the evil that is C "undefined behaviour". I believe that the computing industry may never recover from the harm done to it by the widespread use of C. -- Steven From wxjmfauth at gmail.com Wed Sep 9 13:56:18 2015 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 9 Sep 2015 10:56:18 -0700 (PDT) Subject: PIP does not appear to handle diacritics correctly. In-Reply-To: References: <17f087e9-59d4-4f23-8e3c-d054f03674f6@googlegroups.com> Message-ID: Le mercredi 9 septembre 2015 17:55:28 UTC+2, Tim Golden a ?crit?: > On 09/09/2015 14:10, Chris Angelico wrote: > > Don't bother responding to jmf - he's our resident Unicode troll. His > > posts don't get through to me any more, except when someone responds > > :) Not sure where they're getting blocked; probably at the news<->list > > boundary. > > They're held for mailing list moderation. If they're the usual rant I > discard them. > > > You shouldn't have to restrict your username to ASCII. It's 2015, and > > non-ASCII names should work everywhere. Anywhere they don't is a bug > > to be fixed, and I'm confident the pip folks will treat this with the > > respect it deserves. > > Definitely. I'll try to reproduce this at home (when I have access to a > machine on which I can create a suitably unicode-y username). > > TJG And if possible. Try to be a user, not an administrator. I'm seeing strange things on that side. From wrw at mac.com Wed Sep 9 13:59:53 2015 From: wrw at mac.com (William Ray Wing) Date: Wed, 09 Sep 2015 13:59:53 -0400 Subject: Python handles globals badly. In-Reply-To: <55f06ae1$0$1650$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> <55efa62d$0$1653$c3e8da3$5496439d@news.astraweb.com> <55f06ae1$0$1650$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3435A80B-14B9-4A7C-99D5-06D898297839@mac.com> > On Sep 9, 2015, at 1:22 PM, Steven D'Aprano wrote: > > [byte] > > I think my favourite is the guy who claims that the reason natural languages > all count from 1 is because the Romans failed to invent zero. (What about > languages that didn't derive from Latin, say, Chinese?) Right. Note that the Arabs, who DID invent zero, still count from one. Bill From lac at openend.se Wed Sep 9 14:05:22 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 09 Sep 2015 20:05:22 +0200 Subject: Python handles globals badly. In-Reply-To: <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201509091805.t89I5Mrv021886@fido.openend.se> In a message of Thu, 10 Sep 2015 03:55:54 +1000, "Steven D'Aprano" writes: >(I wanted to link to the "Everything Is Broken" essay on The Medium, but the >page appears to be gone. This makes me sad. BTW, what's the point of >Google's cache when it just redirects to the original, missing, page?) Working for me: https://medium.com/message/everything-is-broken-81e5f33a24e1 Laura From emile at fenx.com Wed Sep 9 14:23:46 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 9 Sep 2015 11:23:46 -0700 Subject: Python handles globals badly. In-Reply-To: <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/9/2015 10:55 AM, Steven D'Aprano wrote: > (I wanted to link to the "Everything Is Broken" essay on The Medium, but the > page appears to be gone. Is this it? http://www.sott.net/article/280956-Everything-is-broken-on-the-Internet From srkunze at mail.de Wed Sep 9 14:26:05 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 9 Sep 2015 20:26:05 +0200 Subject: Python handles globals badly. In-Reply-To: <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55F079BD.7040408@mail.de> On 09.09.2015 19:55, Steven D'Aprano wrote: > On Wed, 9 Sep 2015 11:09 am, Mario Figueiredo wrote: > >> You know, it is a pointless exercise to try and downplay programming >> languages (any programming language) that has proven its worth by being >> generally adopted by the programming community. Adoption is the sign of >> a respected and well designed language. > Counter-examples: PHP and C. > > Adoption of programming languages is driven by many things, technical > excellence and careful design are not even in the top 10. Most of them are > social in nature, particularly "what is everyone else using?". Network > effects dominate: you could design the perfect language, but if nobody else > uses it, nobody will use it. Just to understand it the way you want it to be understood: what do you mean by "technical excellence"? > > Sometimes a language will actually gain a kind of technical excellence > despite some really shitty design decisions -- but usually at great cost > elsewhere. C is a good example of that. Due to lousy decisions made by the > designers of C, it is a language really well suited for writing fast, > incorrect code. Since programmers benefit from writing fast code, but > rarely suffer from writing incorrect code (it's mostly users who suffer the > consequences of security holes), we have ended up in the situation we live > in now, where compilers compete to write faster and faster code that has > less and less relation to what the programmer intended. > > (I wanted to link to the "Everything Is Broken" essay on The Medium, but the > page appears to be gone. This makes me sad. BTW, what's the point of > Google's cache when it just redirects to the original, missing, page?) Do you mean https://medium.com/message/everything-is-broken-81e5f33a24e1 ? > In fairness to the C creators, I'm sure that nobody back in the early > seventies imagined that malware and security vulnerabilities would be as > widespread as they have become. But still, the fundamental decisions made > by C are lousy. Assignment is an expression? Lack of first-class arrays? > The C pre-processor? They're pretty awful, but *nothing* in the entire > history of computing, not even Intercal and the COMEFROM command, comes > even close to the evil that is C "undefined behaviour". > > I believe that the computing industry may never recover from the harm done > to it by the widespread use of C. It'll take some time. From random832 at fastmail.us Wed Sep 9 14:59:20 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Wed, 09 Sep 2015 14:59:20 -0400 Subject: Python handles globals badly. In-Reply-To: <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1441825160.2868154.379145417.24FA9F1B@webmail.messagingengine.com> On Wed, Sep 9, 2015, at 13:55, Steven D'Aprano wrote: > In fairness to the C creators, I'm sure that nobody back in the early > seventies imagined that malware and security vulnerabilities would be as > widespread as they have become. But still, the fundamental decisions made > by C are lousy. Assignment is an expression? Whoa, hold on. The problem with C assignment isn't that it's an expression, it's that it's spelled "=" and can be used in contexts where one would normally do an equality comparison. In some languages (Lisp/Scheme/etc come to mind), *everything* is an expression. But assignment is spelled with, generally, some variant of "set" [setq, set!, etc]. From rosuav at gmail.com Wed Sep 9 15:00:22 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Sep 2015 05:00:22 +1000 Subject: Python handles globals badly. In-Reply-To: <55F079BD.7040408@mail.de> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F079BD.7040408@mail.de> Message-ID: On Thu, Sep 10, 2015 at 4:26 AM, Sven R. Kunze wrote: >> Adoption of programming languages is driven by many things, technical >> excellence and careful design are not even in the top 10. Most of them are >> social in nature, particularly "what is everyone else using?". Network >> effects dominate: you could design the perfect language, but if nobody >> else >> uses it, nobody will use it. > > Just to understand it the way you want it to be understood: what do you mean > by "technical excellence"? Suppose it's possible, somehow, to design the perfect language. (It isn't, because the best language for a job depends on the job, but suppose it for the nonce.) It is simultaneously more readable than Python, more ugly than Perl, more functional than Haskell, and compiles to lower level code than C does. The compiler's/interpreter's internals are a bug-free demonstration of utter code beauty, and you no longer have reason to use any other programming language, because this one is the ultimate. But nobody uses it except you. Technical excellence it has a'plenty, but is it going to be on the job postings? No. Is it going to be on people's resumes? No. When a programmer pitches a proposal at his manager, will he mention your language, which he's never heard of? No. When someone asks on Stack Overflow "How do I...", will the answers recommend the use of your language? No. It isn't going to be used, no matter how good it is, if nobody knows about it. And if it isn't used, nobody will get to know it. Until you start getting some usage, you won't get much usage. That's what drives programming language adoption: existing usage. It's self-perpetuating and proves little. To get started, you need some other sort of kick. Maybe a high-profile company uses your language. Maybe a hardware manufacturer mandates its use. Maybe your development team has so many famous names that the world has been watching with interest. But whatever it is, it has to be something big or you won't get over that initial usage hump. ChrisA From davros at bellaliant.net Wed Sep 9 15:03:04 2015 From: davros at bellaliant.net (John McKenzie) Date: Wed, 09 Sep 2015 19:03:04 GMT Subject: RPI.GPIO Help References: Message-ID: Hello. As per the suggestion of two of you I went to the Raspberry Pi newsgroup. Dennis is also there and has been posting in response to my problems. Between there and the Raspberry Foundation website I discovered that my wiring did not match my code and changed all PUD_DOWN to PUD_UP and all GPIO.RISING to GPIO.FALLING because I was wired to the ground pin. Someone suggested code very close to what hakugin suggested. Right now I have response buttons that work, but the colour of the LED strip is not correct. It adds colours instead of changing to a new one. I hit red, it pulses red, I hit blue, it pulses red and blue, making purple. It appears now my problem is more about Python usage than anything else, so I am asking for help here as well as having already asked elsewhere. Tried using a go to black command (led.set_color(name="black")) and a turn off command (led.turn_off()) before the pulse command to reset the colour and these did not work. To see what would happen I removed the "while colour == 1:" (or == 2: or ==3:) line and it acted as expected. The LED pulsed once. However, it would pulse the correct colour, it would not add colours together. So the while loop seems to be the cause of my problem, but it is needed to keep the pulse repeating as far I can know. Maybe Python has another way to repeat the function. Here is the code I was working from: import atexit import time from blinkstick import blinkstick import RPi.GPIO as GPIO led = blinkstick.find_first() colour = 0 time_red = 0 time_yellow = 0 time_blue = 0 timestamp = time.strftime("%H:%M:%S") GPIO.setmode(GPIO.BCM) GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) def red_button(channel): led.set_color(name="black") colour = 1 while colour == 1: led.pulse(red=255, green=0, blue=0, repeats=1, duration=3000, steps=50) def yellow_button(channel): led.set_color(name="black") colour = 2 while colour == 2: led.pulse(red=255, green=255, blue=0, repeats=1, duration=3000, steps=50) def blue_button(channel): led.set_color(name="black") colour = 3 while colour == 3: led.pulse(red=0, green=0, blue=255, repeats=1, duration=2000, steps=50) GPIO.add_event_detect(22, GPIO.FALLING, callback=red_button, bouncetime=200) GPIO.add_event_detect(23, GPIO.FALLING, callback=yellow_button, bouncetime=200) GPIO.add_event_detect(24, GPIO.FALLING, callback=blue_button, bouncetime=200) while True: if colour == 1: time_red += 1 elif colour == 2: time_yellow += 1 elif colour == 3: time_blue += 1 time.sleep(0.1) def exit_handler(): print "\033[0;41;37mRed Team:\033[0m ", time_red print "\033[0;43;30mYellow Time:\033[0m ", time_yellow print "\033[0;44;37mBlue Time:\033[0m ", time_blue flog = open("flag1.log", "a") flog.write(timestamp + "\n" + "Red Team: " + str(time_red) + "\n" + "Yellow Team: " + str(time_yellow) + "\n" + "Blue Team: " + str (time_blue) + "\n") flog.close() GPIO.cleanup() atexit.register(exit_handler) Any advice about the while loop for the colour pulsing is appreciated. From lac at openend.se Wed Sep 9 15:14:14 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 09 Sep 2015 21:14:14 +0200 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F079BD.7040408@mail.de> Message-ID: <201509091914.t89JEEcc006661@fido.openend.se> In a message of Thu, 10 Sep 2015 05:00:22 +1000, Chris Angelico writes: >To get started, you need some other sort of kick. Having Brian Kernighan write a really nice book about you, helps a lot. Laura From rosuav at gmail.com Wed Sep 9 15:18:08 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Sep 2015 05:18:08 +1000 Subject: Python handles globals badly. In-Reply-To: <201509091914.t89JEEcc006661@fido.openend.se> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F079BD.7040408@mail.de> <201509091914.t89JEEcc006661@fido.openend.se> Message-ID: On Thu, Sep 10, 2015 at 5:14 AM, Laura Creighton wrote: > In a message of Thu, 10 Sep 2015 05:00:22 +1000, Chris Angelico writes: >>To get started, you need some other sort of kick. > > Having Brian Kernighan write a really nice book about you, helps a lot. It kinda does. And of course, it also helps to have a time machine, so you can launch your language when there are less languages around. Today, you compete for attention with myriad languages that simply didn't exist when C was introduced to an unsuspecting world. ChrisA From breamoreboy at yahoo.co.uk Wed Sep 9 15:20:42 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 9 Sep 2015 20:20:42 +0100 Subject: Python handles globals badly. In-Reply-To: <3435A80B-14B9-4A7C-99D5-06D898297839@mac.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> <55efa62d$0$1653$c3e8da3$5496439d@news.astraweb.com> <55f06ae1$0$1650$c3e8da3$5496439d@news.astraweb.com> <3435A80B-14B9-4A7C-99D5-06D898297839@mac.com> Message-ID: On 09/09/2015 18:59, William Ray Wing wrote: > >> On Sep 9, 2015, at 1:22 PM, Steven D'Aprano wrote: >> >> > > [byte] > >> >> I think my favourite is the guy who claims that the reason natural languages >> all count from 1 is because the Romans failed to invent zero. (What about >> languages that didn't derive from Latin, say, Chinese?) > > Right. Note that the Arabs, who DID invent zero, still count from one. > > Bill > Would you please provide a citation to support your claim as this http://www.livescience.com/27853-who-invented-zero.html disagrees. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From srkunze at mail.de Wed Sep 9 15:21:51 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 9 Sep 2015 21:21:51 +0200 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F079BD.7040408@mail.de> Message-ID: <55F086CF.7040507@mail.de> On 09.09.2015 21:00, Chris Angelico wrote: > Suppose it's possible, somehow, to design the perfect language. (It > isn't, because the best language for a job depends on the job, but > suppose it for the nonce.) It is simultaneously more readable than > Python, more ugly than Perl, more functional than Haskell, and > compiles to lower level code than C does. The compiler's/interpreter's > internals are a bug-free demonstration of utter code beauty, and you > no longer have reason to use any other programming language, because > this one is the ultimate. That sounds boring, right? ;) Best, Sven From python at mrabarnett.plus.com Wed Sep 9 15:22:37 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 9 Sep 2015 20:22:37 +0100 Subject: Python handles globals badly. In-Reply-To: <3435A80B-14B9-4A7C-99D5-06D898297839@mac.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> <55efa62d$0$1653$c3e8da3$5496439d@news.astraweb.com> <55f06ae1$0$1650$c3e8da3$5496439d@news.astraweb.com> <3435A80B-14B9-4A7C-99D5-06D898297839@mac.com> Message-ID: <55F086FD.8000000@mrabarnett.plus.com> On 2015-09-09 18:59, William Ray Wing wrote: > >> On Sep 9, 2015, at 1:22 PM, Steven D'Aprano wrote: >> >> > > [byte] > >> >> I think my favourite is the guy who claims that the reason natural languages >> all count from 1 is because the Romans failed to invent zero. (What about >> languages that didn't derive from Latin, say, Chinese?) > > Right. Note that the Arabs, who DID invent zero, still count from one. > No, they didn't invent zero. > Bill > From breamoreboy at yahoo.co.uk Wed Sep 9 15:24:53 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 9 Sep 2015 20:24:53 +0100 Subject: Python handles globals badly. In-Reply-To: <201509091914.t89JEEcc006661@fido.openend.se> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F079BD.7040408@mail.de> <201509091914.t89JEEcc006661@fido.openend.se> Message-ID: On 09/09/2015 20:14, Laura Creighton wrote: > In a message of Thu, 10 Sep 2015 05:00:22 +1000, Chris Angelico writes: >> To get started, you need some other sort of kick. > > Having Brian Kernighan write a really nice book about you, helps a lot. > > Laura > Who? Did he play left wing or right wing for City? Or was it United? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Wed Sep 9 15:27:37 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Sep 2015 05:27:37 +1000 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> <55efa62d$0$1653$c3e8da3$5496439d@news.astraweb.com> <55f06ae1$0$1650$c3e8da3$5496439d@news.astraweb.com> <3435A80B-14B9-4A7C-99D5-06D898297839@mac.com> Message-ID: On Thu, Sep 10, 2015 at 5:20 AM, Mark Lawrence wrote: > On 09/09/2015 18:59, William Ray Wing wrote: >> Right. Note that the Arabs, who DID invent zero, still count from one. > > Would you please provide a citation to support your claim as this > http://www.livescience.com/27853-who-invented-zero.html disagrees. There will be no such citation, because it's well known that zero was invented by the jungle natives of Papua New French Guiana. http://www.jumbojoke.com/high_tech_natives.html ChrisA From python at mrabarnett.plus.com Wed Sep 9 15:29:26 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 9 Sep 2015 20:29:26 +0100 Subject: RPI.GPIO Help In-Reply-To: References: Message-ID: <55F08896.9070807@mrabarnett.plus.com> On 2015-09-09 20:03, John McKenzie wrote: > > Hello. > > As per the suggestion of two of you I went to the Raspberry Pi > newsgroup. Dennis is also there and has been posting in response to my > problems. Between there and the Raspberry Foundation website I discovered > that my wiring did not match my code and changed all PUD_DOWN to PUD_UP > and all GPIO.RISING to GPIO.FALLING because I was wired to the ground pin. > > Someone suggested code very close to what hakugin suggested. > > Right now I have response buttons that work, but the colour of the LED > strip is not correct. It adds colours instead of changing to a new one. I > hit red, it pulses red, I hit blue, it pulses red and blue, making purple. > > It appears now my problem is more about Python usage than anything else, > so I am asking for help here as well as having already asked elsewhere. > > Tried using a go to black command (led.set_color(name="black")) and a > turn off command (led.turn_off()) before the pulse command to reset the > colour and these did not work. To see what would happen I removed the > "while colour == 1:" (or == 2: or ==3:) line and it acted as expected. > The LED pulsed once. However, it would pulse the correct colour, it would > not add colours together. > > So the while loop seems to be the cause of my problem, but it is needed > to keep the pulse repeating as far I can know. Maybe Python has another > way to repeat the function. > > Here is the code I was working from: > > import atexit > import time > from blinkstick import blinkstick > import RPi.GPIO as GPIO > > led = blinkstick.find_first() > colour = 0 > time_red = 0 > time_yellow = 0 > time_blue = 0 > timestamp = time.strftime("%H:%M:%S") > > GPIO.setmode(GPIO.BCM) > GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) > GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) > GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) > > > def red_button(channel): > led.set_color(name="black") > colour = 1 > while colour == 1: > led.pulse(red=255, green=0, blue=0, repeats=1, duration=3000, > steps=50) > > def yellow_button(channel): > led.set_color(name="black") > colour = 2 > while colour == 2: > led.pulse(red=255, green=255, blue=0, repeats=1, duration=3000, > steps=50) > > def blue_button(channel): > led.set_color(name="black") > colour = 3 > while colour == 3: > led.pulse(red=0, green=0, blue=255, repeats=1, duration=2000, > steps=50) > > > GPIO.add_event_detect(22, GPIO.FALLING, callback=red_button, > bouncetime=200) > GPIO.add_event_detect(23, GPIO.FALLING, callback=yellow_button, > bouncetime=200) > GPIO.add_event_detect(24, GPIO.FALLING, callback=blue_button, > bouncetime=200) > > > while True: > if colour == 1: > time_red += 1 > elif colour == 2: > time_yellow += 1 > elif colour == 3: > time_blue += 1 > time.sleep(0.1) > > > def exit_handler(): > print "\033[0;41;37mRed Team:\033[0m ", time_red > print "\033[0;43;30mYellow Time:\033[0m ", time_yellow > print "\033[0;44;37mBlue Time:\033[0m ", time_blue > flog = open("flag1.log", "a") > flog.write(timestamp + "\n" + "Red Team: " + str(time_red) + "\n" + > "Yellow Team: " + str(time_yellow) + "\n" + "Blue Team: " + str > (time_blue) + "\n") > flog.close() > GPIO.cleanup() > atexit.register(exit_handler) > > > Any advice about the while loop for the colour pulsing is appreciated. > It's the same problem as before, and it has the same answer. In red_button, yellow_button and blue_button, 'colour' is a local variable. It's set to a value and that value is never changed in the loop, so it loops forever. You should declare 'colour' to be global in all 3 functions, e.g.: def red_button(channel): global colour From marfig at gmx.com Wed Sep 9 15:57:12 2015 From: marfig at gmx.com (Mario Figueiredo) Date: Wed, 09 Sep 2015 20:57:12 +0100 Subject: Python handles globals badly. In-Reply-To: <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55F08F18.70708@gmx.com> On 09-09-2015 18:55, Steven D'Aprano wrote: > On Wed, 9 Sep 2015 11:09 am, Mario Figueiredo wrote: > >> You know, it is a pointless exercise to try and downplay programming >> languages (any programming language) that has proven its worth by being >> generally adopted by the programming community. Adoption is the sign of >> a respected and well designed language. > > Counter-examples: PHP and C. > > Adoption of programming languages is driven by many things, technical > excellence and careful design are not even in the top 10. Most of them are > social in nature, particularly "what is everyone else using?". Network > effects dominate: you could design the perfect language, but if nobody else > uses it, nobody will use it. You paint a dim picture of the computer science ecosystem. You almost make it look like we are a bunch of fashionists. There is some truth to what you are saying, but not to the level you are implying. "Technical excellence not being on the top 10" is just a blanket statement that does not address the constant search for better programming languages. The fact is that you, I and a large representative number of software engineers are always on the constant lookout for better designed languages. And it's people like us that eventually ensure the success of a programming language based on its merits. It's the software engineering "society" that eventually promotes a programming language out of obscurity and into popular use. And this can only happen if that language holds enough merits. We may have been experiencing a rise in programming languages protected by commercial interests, but so far they still obey this simple truth. That speech that languages are popularity contests is just a superficial view of the whole of the industry and frankly very much untrue. > Sometimes a language will actually gain a kind of technical excellence > despite some really shitty design decisions -- but usually at great cost > elsewhere. C is a good example of that. Due to lousy decisions made by the > designers of C, it is a language really well suited for writing fast, > incorrect code. Right. There we go. Another, C is a badly designed language... If I had a penny for every time I heard this, I could then wish for a penny for every other program or computer language that was designed in C. I would be twice as rich. Almost all of the modern programming edifice sits on top of C on one way or another. Our operating systems, many of our most mission critical system, even many of our high level programming languages, including the one represented on these forums. But somehow, there is always someone trying to sell that C is a lousy designed programming language. At this point in history, I couldn't blame C anymore. If it is such a lousy job, then the real problem must be with the people that kept on truckin' it around. That includes the whole of the computer science industry. And that just doesn't make sense. Your programming language based on lousy decisions, proved instead that those those lousy decisions around lack of security are necessary when you need to create a systems programming language that can eventually carry on its shoulders the weight of an entire industry. Maybe Rust will finally be able to prove that you can do better. That it is actually possible to create a close-to-the-metal programming language with security in mind and as performant as C. But if it does succeed (and I'd like for it to succeed, make no mistake), it took us over 40 years to actually come up with something. > In fairness to the C creators, I'm sure that nobody back in the early > seventies imagined that malware and security vulnerabilities would be as > widespread as they have become. Of course they did. The Design of C states this on several occasions, while The C Programming Language is full of mentions to the security concerns in some of the programming language semantics. Meanwhile the patterns and best practices for secure C code are known for decades, well before the widespread use of computers and the internet itself. > I believe that the computing industry may never recover from the harm done > to it by the widespread use of C. Yes. It's been a terrible 4 decades of technological innovation. From mail at timgolden.me.uk Wed Sep 9 15:59:58 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 9 Sep 2015 20:59:58 +0100 Subject: PIP does not appear to handle diacritics correctly. In-Reply-To: References: Message-ID: <55F08FBE.3030200@timgolden.me.uk> On 09/09/2015 08:59, Laszlo Lebrun via Python-list wrote: > On Tue, 08 Sep 2015 23:35:33 +0100, Mark Lawrence wrote: > >> On 08/09/2015 20:14, Laszlo Lebrun via Python-list wrote: >>> >>> Dear group, >>> I do use Windows 7 and have a user name with diacritics. >>> >>> Whenever I am querying an extension with pip, it will fail since it >>> does not pass on the user folder correctly. >>> I thought PIP deals well with unicode, doesn't it? >>> >>> Has anyone a clue how to fix it? >>> Thank you >>> >>> > Yes, you are right, let me append the message. > Just after a fresh install of Python with PIP on Windows. > Whenever I start PIP, I get: > "Fatal error in launcher: Unable to create process using '"C:\Users > \B??rgerGegenFlugl??rm\AppData\Local\Programs\Python\Python35-32 > \python.exe" "C:\Users\B?rgerGegenFlugl?rm\AppData\Local\Programs\Python > \Python35-32\Scripts\pip.exe" '" > > Where the correct path is "C:\Users\B?rgerGegenFlugl?rm\AppData..." Well on my Win8.1 machine I created a local user with the name you give and did a fresh install of the very latest Python 3.5rc. I installed from the 32-bit web installer and the only variation from the defaults was to add Python to the PATH (the last checkbox on the first page of the wizard). It all installed without issue and I was able to do "pip --version" from a command prompt to see that it had installed pip 7.1.something. Now this is on my standard dev machine, ie not a virgin VM, and it's 8.1 rather than Win7, but it's not clear why either of those would make a difference. The standard codepage for console processes appears to be 850. Let's see if the pip guys respond to your bug request TJG From breamoreboy at yahoo.co.uk Wed Sep 9 16:15:49 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 9 Sep 2015 21:15:49 +0100 Subject: Python handles globals badly. In-Reply-To: <55F08F18.70708@gmx.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F08F18.70708@gmx.com> Message-ID: On 09/09/2015 20:57, Mario Figueiredo wrote: > On 09-09-2015 18:55, Steven D'Aprano wrote: >> On Wed, 9 Sep 2015 11:09 am, Mario Figueiredo wrote: >> >>> You know, it is a pointless exercise to try and downplay programming >>> languages (any programming language) that has proven its worth by being >>> generally adopted by the programming community. Adoption is the sign of >>> a respected and well designed language. >> >> Counter-examples: PHP and C. >> >> Adoption of programming languages is driven by many things, technical >> excellence and careful design are not even in the top 10. Most of them are >> social in nature, particularly "what is everyone else using?". Network >> effects dominate: you could design the perfect language, but if nobody else >> uses it, nobody will use it. > > You paint a dim picture of the computer science ecosystem. You almost > make it look like we are a bunch of fashionists. There is some truth to > what you are saying, but not to the level you are implying. "Technical > excellence not being on the top 10" is just a blanket statement that > does not address the constant search for better programming languages. > If the designers of languages spent more time considering business benefits rather than better languages, then I believe we'd end up with better languages. However that depends on your (plural) definition of "better". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From wolfgang.maier at biologie.uni-freiburg.de Wed Sep 9 16:20:16 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Wed, 9 Sep 2015 22:20:16 +0200 Subject: PIP does not appear to handle diacritics correctly. In-Reply-To: <55F08FBE.3030200@timgolden.me.uk> References: <55F08FBE.3030200@timgolden.me.uk> Message-ID: <55F09480.9000604@biologie.uni-freiburg.de> On 09.09.2015 21:59, Tim Golden wrote: > > Well on my Win8.1 machine I created a local user with the name you give > and did a fresh install of the very latest Python 3.5rc. I installed > from the 32-bit web installer and the only variation from the defaults > was to add Python to the PATH (the last checkbox on the first page of > the wizard). > > It all installed without issue and I was able to do "pip --version" from > a command prompt to see that it had installed pip 7.1.something. > > Now this is on my standard dev machine, ie not a virgin VM, and it's 8.1 > rather than Win7, but it's not clear why either of those would make a > difference. > > The standard codepage for console processes appears to be 850. > It's been resolved a minute ago. See https://github.com/pypa/pip/issues/3087#issuecomment-139034217 for an explanation of why the latest rc does not have the bug. From lazlo.lebrun at googlemail.com Wed Sep 9 16:23:47 2015 From: lazlo.lebrun at googlemail.com (Laszlo Lebrun) Date: Wed, 9 Sep 2015 20:23:47 +0000 (UTC) Subject: PIP does not appear to handle diacritics correctly. References: <55F05B42.8010803@biologie.uni-freiburg.de> Message-ID: On Wed, 09 Sep 2015 17:21:59 +0100, Tim Golden wrote: > On 09/09/2015 17:16, Wolfgang Maier wrote: >> On 09.09.2015 10:23, Chris Angelico wrote: >>> On Wed, Sep 9, 2015 at 5:59 PM, Laszlo Lebrun via Python-list >>> wrote: >>>> Whenever I start PIP, I get: >>>> "Fatal error in launcher: Unable to create process using '"C:\Users >>>> \B??rgerGegenFlugl??rm\AppData\Local\Programs\Python\Python35-32 >>>> \python.exe" >>>> "C:\Users\B?rgerGegenFlugl?rm\AppData\Local\Programs\Python >>>> \Python35-32\Scripts\pip.exe" '" >>>> >>>> Where the correct path is "C:\Users\B?rgerGegenFlugl?rm\AppData..." >>>> >>>> The funny thing is that the message mentions the path twice, with >>>> different wrong codings. >>>> :-( >>> >>> >> I may be wrong, but isn't the error message suggesting that this is a >> bug in the py launcher instead of in pip? >> If I remember a post from a recent thread correctly, then pip.exe is >> just a script using the launcher. >> If that's true, shouldn't the recommended: >> >> python -m pip >> >> be a workaround? >> >> I might be wrong, but it's worth a try. > > Actually, that's a good point. Especially given the start of the error > message... > > TJG python -m pip works well. That's a help, I will be able to get the libraries I need. Thank you. -- Stand up against TTIP and ISDS ! From random832 at fastmail.us Wed Sep 9 16:23:52 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Wed, 09 Sep 2015 16:23:52 -0400 Subject: PIP does not appear to handle diacritics correctly. In-Reply-To: <55F08FBE.3030200@timgolden.me.uk> References: <55F08FBE.3030200@timgolden.me.uk> Message-ID: <1441830232.2886190.379217793.52B0148C@webmail.messagingengine.com> On Wed, Sep 9, 2015, at 15:59, Tim Golden wrote: > On 09/09/2015 08:59, Laszlo Lebrun via Python-list wrote: > > Yes, you are right, let me append the message. > > Just after a fresh install of Python with PIP on Windows. > > Whenever I start PIP, I get: > > "Fatal error in launcher: Unable to create process using '"C:\Users > > \B??rgerGegenFlugl??rm\AppData\Local\Programs\Python\Python35-32 > > \python.exe" "C:\Users\B?rgerGegenFlugl?rm\AppData\Local\Programs\Python > > \Python35-32\Scripts\pip.exe" '" > > > > Where the correct path is "C:\Users\B?rgerGegenFlugl?rm\AppData..." > > > Well on my Win8.1 machine I created a local user with the name you give > and did a fresh install of the very latest Python 3.5rc. I installed > from the 32-bit web installer and the only variation from the defaults > was to add Python to the PATH (the last checkbox on the first page of > the wizard). Did you install Python _under_ the user directory? If the programs it's trying to launch are in C:\Python35 instead of C:\Users\B?rgerGegenFlugl?rm the bug won't show up. I've never actually seen an "AppData\Local\Programs\Python" directory. Is this an ActiveState thing? Is there an "Install just for me" option in the installer that will choose a different default install location? > It all installed without issue and I was able to do "pip --version" from > a command prompt to see that it had installed pip 7.1.something. > > Now this is on my standard dev machine, ie not a virgin VM, and it's 8.1 > rather than Win7, but it's not clear why either of those would make a > difference. > > The standard codepage for console processes appears to be 850. The strings shown above are, respectively, the name as UTF-8 reinterpreted as 850, and the name as 1252 reinterpreted as 850 (Incidentally, the latter will appear as "B?rgerGegenFlugl?rm" for US users if it is reinterpreted as 437 instead). It's possible that one or both may be caused partially by issues with how the error message was printed. From gordon at panix.com Wed Sep 9 16:45:57 2015 From: gordon at panix.com (John Gordon) Date: Wed, 9 Sep 2015 20:45:57 +0000 (UTC) Subject: Lesson 39 of Learning Python the Hard Way hangs References: Message-ID: In Gary Roach writes: > Traceback (most recent call last): > File "/root/mystuff/mystuff/ex39_test.py", line 6, in > hashmap.set(states, 'Oregon', 'OR') > File "/root/mystuff/mystuff/hashmap.py", line 50, in set > i, k, v = get_slot(aMap, key) > TypeError: 'NoneType' object is not iterable > Execution Successful! Where does the message "Execution Successful!" come from? It seems like you have other code that you haven't shown us. In any case, I saved your code and ran it, and did not get an error. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From ahlusar.ahluwalia at gmail.com Wed Sep 9 17:15:48 2015 From: ahlusar.ahluwalia at gmail.com (kbtyo) Date: Wed, 9 Sep 2015 14:15:48 -0700 (PDT) Subject: Potential Solution for AssertionError: invalid dtype determination in get_concat_dtype when concatenating operation on list of Dataframes? Message-ID: <3db12d5e-0697-4a06-b5ee-e3bd629f8f83@googlegroups.com> I have a list of Pandas Dataframes that I am attempting to combine using the concatenation function. dataframe_lists = [df1, df2, df3] result = pd.concat(dataframe_lists, keys = ['one', 'two','three'], ignore_index=True) The full traceback that I receive when I execute this function is: --------------------------------------------------------------------------- AssertionError Traceback (most recent call last) in () ----> 1 result = pd.concat(dataframe_lists, keys = ['one', 'two','three'], ignore_index=True) 2 check(dataframe_lists) C:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\pandas\tools\merge.py in concat(objs, axis, join, join_axes, ignore_index, keys, levels, names, verify_integrity, copy) 753 verify_integrity=verify_integrity, 754 copy=copy) --> 755 return op.get_result() 756 757 C:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\pandas\tools\merge.py in get_result(self) 924 925 new_data = concatenate_block_managers( --> 926 mgrs_indexers, self.new_axes, concat_axis=self.axis, copy=self.copy) 927 if not self.copy: 928 new_data._consolidate_inplace() C:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\pandas\core\internals.py in concatenate_block_managers(mgrs_indexers, axes, concat_axis, copy) 4061 copy=copy), 4062 placement=placement) -> 4063 for placement, join_units in concat_plan] 4064 4065 return BlockManager(blocks, axes) C:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\pandas\core\internals.py in (.0) 4061 copy=copy), 4062 placement=placement) -> 4063 for placement, join_units in concat_plan] 4064 4065 return BlockManager(blocks, axes) C:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\pandas\core\internals.py in concatenate_join_units(join_units, concat_axis, copy) 4150 raise AssertionError("Concatenating join units along axis0") 4151 -> 4152 empty_dtype, upcasted_na = get_empty_dtype_and_na(join_units) 4153 4154 to_concat = [ju.get_reindexed_values(empty_dtype=empty_dtype, C:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\pandas\core\internals.py in get_empty_dtype_and_na(join_units) 4139 return np.dtype('m8[ns]'), tslib.iNaT 4140 else: # pragma -> 4141 raise AssertionError("invalid dtype determination in get_concat_dtype") 4142 4143 AssertionError: invalid dtype determination in get_concat_dtype I believe that the error lies in the fact that one of the data frames is empty. As a temporary workaround this rather perplexing error. I used the simple function check to verify and return just the headers of the empty dataframe: def check(list_of_df): headers = [] for df in dataframe_lists: if df.empty is not True: continue else: headers.append(df.columns) return headers I am wondering if it is possible to use this function to, if in the case of an empty dataframe, return just that empty dataframe's headers and append it to the concatenated dataframe. The output would be a single row for the headers (and, in the case of a repeating column name, just a single instance of the header (as in the case of the concatenation function). I have two sample data sources, one and two non-empty data sets. df1: https://gist.github.com/ahlusar1989/42708e6a3ca0aed9b79b df2 :https://gist.github.com/ahlusar1989/26eb4ce1578e0844eb82 Here is an empty dataframe. df3 (empty dataframe): https://gist.github.com/ahlusar1989/0721bd8b71416b54eccd I would like to have the resulting concatenate have the column headers (with their values) that reflects df1 and df2... 'AT','AccountNum', 'AcctType', 'Amount', 'City', 'Comment', 'Country','DuplicateAddressFlag', 'FromAccount', 'FromAccountNum', 'FromAccountT','PN', 'PriorCity', 'PriorCountry', 'PriorState', 'PriorStreetAddress','PriorStreetAddress2', 'PriorZip', 'RTID', 'State', 'Street1','Street2', 'Timestamp', 'ToAccount', 'ToAccountNum', 'ToAccountT', 'TransferAmount', 'TransferMade', 'TransferTimestamp', 'Ttype', 'WA','WC', 'Zip' as follows: 'A', 'AT','AccountNum', 'AcctType', 'Amount', 'B', 'C', 'City', 'Comment', 'Country', 'D', 'DuplicateAddressFlag', 'E', 'F' 'FromAccount', 'FromAccountNum', 'FromAccountT', 'G', 'PN', 'PriorCity', 'PriorCountry', 'PriorState', 'PriorStreetAddress','PriorStreetAddress2', 'PriorZip', 'RTID', 'State', 'Street1','Street2', 'Timestamp', 'ToAccount', 'ToAccountNum', 'ToAccountT', 'TransferAmount', 'TransferMade', 'TransferTimestamp', 'Ttype', 'WA','WC', 'Zip' I welcome any feedback on how to best do this. Thank you. From denismfmcmahon at gmail.com Wed Sep 9 17:36:39 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 9 Sep 2015 21:36:39 +0000 (UTC) Subject: Lesson 39 of Learning Python the Hard Way hangs References: Message-ID: On Wed, 09 Sep 2015 20:45:57 +0000, John Gordon wrote: > In any case, I saved your code and ran it, and did not get an error. +1 I think "Execution Succesful!" might be coming from his IDE? -- Denis McMahon, denismfmcmahon at gmail.com From garyroach at verizon.net Wed Sep 9 17:53:10 2015 From: garyroach at verizon.net (Gary Roach) Date: Wed, 09 Sep 2015 14:53:10 -0700 Subject: Lesson 39 of Learning Python the Hard Way hangs In-Reply-To: References: Message-ID: <55F0AA46.6030305@verizon.net> On 09/09/2015 01:45 PM, John Gordon wrote: > In Gary Roach writes: > >> Traceback (most recent call last): >> File "/root/mystuff/mystuff/ex39_test.py", line 6, in >> hashmap.set(states, 'Oregon', 'OR') >> File "/root/mystuff/mystuff/hashmap.py", line 50, in set >> i, k, v = get_slot(aMap, key) >> TypeError: 'NoneType' object is not iterable >> Execution Successful! > Where does the message "Execution Successful!" come from? It seems like > you have other code that you haven't shown us. > > In any case, I saved your code and ran it, and did not get an error. > No other code. Ninja-IDE tacked the "Execution Successful" at the end if the error message. Dont know why. Interesting that you ran the code successfully. I have tried to run the code in both Ninja and at the command line and got the exact same error message. A note: If you could, please post your replies to the list. If you don't, it either breaks the thread or ends up sending a copy to my personal email address. I am assuming that your email client gives you that choice. If not, I'm not sure how you would assure that the proper way happens. I use the icedove (thunderbird) mail client and the choice is a drop down list at the top of the mail editor page. Thanks for your reply. Still confused Gary R. From jlmora_ at hotmail.com Wed Sep 9 17:58:47 2015 From: jlmora_ at hotmail.com (Julio Alonso) Date: Wed, 9 Sep 2015 21:58:47 +0000 Subject: =?utf-8?Q?ImportError:_No_module_named_multiprocessing?= Message-ID: Hi, I have a problem to import a multiprocessing module. I am using Python 2.7 and Windows 8. The program (.py) is executed since MS-DOS console. If I run the program the output is "ImportError: No module named multiprocessing". If I execute "import multiprocessing" on Python Command Line I don't have problems, but It isn't useful for my program, because I need to import since my own file .py What do you recommend me?. I need to get benefit from the process-based parallelism and to use several processors. Thank you so much ________________________ Julio Mora Olivares Estudiante Ingenier?a Civil Industrial Diploma en Transporte y Log?stica Pontificia Universidad Cat?lica de Chile -------------- next part -------------- An HTML attachment was scrubbed... URL: From denismfmcmahon at gmail.com Wed Sep 9 18:35:49 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 9 Sep 2015 22:35:49 +0000 (UTC) Subject: Hi am new to python References: Message-ID: On Tue, 08 Sep 2015 17:44:26 -0500, Nassim Gannoun wrote: > My question is in a while loop; how do l sum all the numbers in the > given list (list_a)? You don't normally use a while loop or a counter to iterate over a list. Such a question should only be used as a precursor to discussing better methods of achieving the required result. While loop: > sum_a = 0 > i = 0 > while i < (len(list_a)): > sum_a += list_a[i] > i += 1 > print(sum_a) Better, use a for loop: s = 0 for i in list_a: s += i print (s) Even better, use sum(): s = sum(list_a) print (s) And if you only want to display the answer: print (sum(list_a)) -- Denis McMahon, denismfmcmahon at gmail.com From emile at fenx.com Wed Sep 9 19:16:40 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 9 Sep 2015 16:16:40 -0700 Subject: Hi am new to python In-Reply-To: References: Message-ID: On 9/9/2015 3:35 PM, Denis McMahon wrote: > On Tue, 08 Sep 2015 17:44:26 -0500, Nassim Gannoun wrote: > >> My question is in a while loop; how do l sum all the numbers in the >> given list (list_a)? > > You don't normally use a while loop or a counter to iterate over a list. > Such a question should only be used as a precursor to discussing better > methods of achieving the required result. As I understand it, the OP was given the homework assignment to sum up a list of numbers using while. Too bad he didn't also specify using binary operators along with while. :) Emile From breamoreboy at yahoo.co.uk Wed Sep 9 19:52:14 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 10 Sep 2015 00:52:14 +0100 Subject: Can't use Python Launcher on Windows after update to 3.5 Message-ID: I've installed 3.5 for all users so it's in C:\Program Files From https://docs.python.org/3.5/using/windows.html#from-the-command-line it says "System-wide installations of Python 3.3 and later will put the launcher on your PATH. The launcher is compatible with all available versions of Python, so it does not matter which version is installed. To check that the launcher is available, execute the following command in Command Prompt:", but:- C:\Users\Mark\Documents\MyPython>py -3.4 'py' is not recognized as an internal or external command, operable program or batch file. Further running ftype shows nothing for Python, assoc just gives this .pyproj=VisualStudio.Launcher.pyproj.14.0. Surely this is wrong? Before I go to the bug tracker to raise an issue could somebody please confirm what I'm seeing, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From garyroach at verizon.net Wed Sep 9 19:58:02 2015 From: garyroach at verizon.net (Gary Roach) Date: Wed, 09 Sep 2015 16:58:02 -0700 Subject: Lesson 39 of Learning Python the Hard Way hangs (Fixed?) In-Reply-To: References: Message-ID: <55F0C78A.3080205@verizon.net> On 09/09/2015 01:45 PM, John Gordon wrote: > In Gary Roach writes: > >> Traceback (most recent call last): >> File "/root/mystuff/mystuff/ex39_test.py", line 6, in >> hashmap.set(states, 'Oregon', 'OR') >> File "/root/mystuff/mystuff/hashmap.py", line 50, in set >> i, k, v = get_slot(aMap, key) >> TypeError: 'NoneType' object is not iterable >> Execution Successful! > Where does the message "Execution Successful!" come from? It seems like > you have other code that you haven't shown us. > > In any case, I saved your code and ran it, and did not get an error. > No other code. Ninja-IDE tacked the "Execution Successful" at the end if the error message. Dont know why. Interesting that you ran the code successfully. I have tried to run the code in both Ninja and at the command line and got the exact same error message. A note: If you could, please post your replies to the list. If you don't, it either breaks the thread or ends up sending a copy to my personal email address. I am assuming that your email client gives you that choice. If not, I'm not sure how you would assure that the proper way happens. I use the icedove (thunderbird) mail client and the choice is a drop down list at the top of the mail editor page. Thanks for your reply. Still confused Gary R. PS I copied over my code with the one from the lesson and all of a sudden it works. I then used the code I copied to the email. It also worked. Now I can't duplicate the problem. The problems fixed but .... From gary719_list1 at verizon.net Wed Sep 9 19:58:30 2015 From: gary719_list1 at verizon.net (Gary Roach) Date: Wed, 09 Sep 2015 16:58:30 -0700 Subject: Lesson 39 of Learning Python the Hard Way hangs (Fixed?) In-Reply-To: References: Message-ID: <55F0C7A6.9010709@verizon.net> On 09/09/2015 01:45 PM, John Gordon wrote: > In Gary Roach writes: > >> Traceback (most recent call last): >> File "/root/mystuff/mystuff/ex39_test.py", line 6, in >> hashmap.set(states, 'Oregon', 'OR') >> File "/root/mystuff/mystuff/hashmap.py", line 50, in set >> i, k, v = get_slot(aMap, key) >> TypeError: 'NoneType' object is not iterable >> Execution Successful! > Where does the message "Execution Successful!" come from? It seems like > you have other code that you haven't shown us. > > In any case, I saved your code and ran it, and did not get an error. > No other code. Ninja-IDE tacked the "Execution Successful" at the end if the error message. Dont know why. Interesting that you ran the code successfully. I have tried to run the code in both Ninja and at the command line and got the exact same error message. A note: If you could, please post your replies to the list. If you don't, it either breaks the thread or ends up sending a copy to my personal email address. I am assuming that your email client gives you that choice. If not, I'm not sure how you would assure that the proper way happens. I use the icedove (thunderbird) mail client and the choice is a drop down list at the top of the mail editor page. Thanks for your reply. Still confused Gary R. PS I copied over my code with the one from the lesson and all of a sudden it works. I then used the code I copied to the email. It also worked. Now I can't duplicate the problem. The problems fixed but .... From chenchao at inhand.com.cn Wed Sep 9 23:58:26 2015 From: chenchao at inhand.com.cn (chenchao at inhand.com.cn) Date: Thu, 10 Sep 2015 11:58:26 +0800 Subject: setenv Message-ID: <55F0FFE2.6080908@inhand.com.cn> hi: This is not a question about python. It is a shell question. I'm sorry to bother you. But I really want to know it. As follow: I want to set a shell environment variable:PYTHONPATH. When i executeecho $PYTHONPATH, it is value:/usr/lib/python/Lib:/usr/lib/python/lib/python27.zip:/var/app/python/libs/pip-lib.zip. Now, I want to add value to it. The value is all files in a folder with the.zip end. For install, directory(/var/app/python/libs/) include gpio.zip, a.zip, b.zip and so on. So I want to add value:/var/app/python/libs/gpio.zip, /var/app/python/libs/a.zip, /var/app/python/libs/b.zip to environment variable:PYTHONPATH. I execute cmd: export PYTHONPATH='/var/app/python/libs/*zip':$PYTHONPATH, but its value is not correct. So, how can i do this? My program use setenv to set environment variable. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Sep 10 00:34:53 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Sep 2015 14:34:53 +1000 Subject: setenv In-Reply-To: <55F0FFE2.6080908@inhand.com.cn> References: <55F0FFE2.6080908@inhand.com.cn> Message-ID: On Thu, Sep 10, 2015 at 1:58 PM, chenchao at inhand.com.cn wrote: > hi: > This is not a question about python. It is a shell question. I'm sorry to > bother you. But I really want to know it. As follow: > I want to set a shell environment variable:PYTHONPATH. When i execute > echo $PYTHONPATH, it is > value:/usr/lib/python/Lib:/usr/lib/python/lib/python27.zip:/var/app/python/libs/pip-lib.zip. > Now, I want to add value to it. The value is all files in a folder with > the.zip end. For install, directory(/var/app/python/libs/) include gpio.zip, > a.zip, b.zip and so on. So I want to add > value:/var/app/python/libs/gpio.zip, /var/app/python/libs/a.zip, > /var/app/python/libs/b.zip to environment variable:PYTHONPATH. I execute > cmd: export PYTHONPATH='/var/app/python/libs/*zip':$PYTHONPATH, but its > value is not correct. So, how can i do this? My program use setenv to set > environment variable. Sounds to me like you want something like this: http://stackoverflow.com/questions/3430569/globbing-pathname-expansion-with-colon-as-separator If that's not the case, can you elaborate a bit on what you're trying to do, preferably in pure text rather than relying on HTML? ChrisA From rosuav at gmail.com Thu Sep 10 00:40:17 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Sep 2015 14:40:17 +1000 Subject: Lesson 39 of Learning Python the Hard Way hangs In-Reply-To: <55F06BE7.1080709@verizon.net> References: <55F06BE7.1080709@verizon.net> Message-ID: On Thu, Sep 10, 2015 at 3:27 AM, Gary Roach wrote: > > Python 2.7 (It's going to be a while before 2,7 goes away. There is just too > much code out there. 2.7 isn't going to go away, but that doesn't mean you should learn on it. Unless you have a particular reason for learning 2.7, I would recommend picking up 3.4 (or 3.5, which is about to be released). ChrisA From ben+python at benfinney.id.au Thu Sep 10 00:56:28 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 10 Sep 2015 14:56:28 +1000 Subject: Lesson 39 of Learning Python the Hard Way hangs References: <55F06BE7.1080709@verizon.net> Message-ID: <854mj298jn.fsf@benfinney.id.au> Gary Roach writes: > Python 2.7 (It's going to be a while before 2,7 goes away. There is > just too much code out there. The time since Python 2 got any improvements is long in the past, and it will never get any more. It is rapidly becoming the case that new libraries just don't support Python 2, for the same reason. Rather than learning the dead-end Python 2, you should be using the time better by learning Python 3 which is actively-developed and will serve you much longer. -- \ ?Remember: every member of your ?target audience? also owns a | `\ broadcasting station. These ?targets? can shoot back.? ?Michael | _o__) Rathbun to advertisers, news.admin.net-abuse.email | Ben Finney From harirammanohar159 at gmail.com Thu Sep 10 01:18:19 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Wed, 9 Sep 2015 22:18:19 -0700 (PDT) Subject: issue while doing pexpect ssh In-Reply-To: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> References: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> Message-ID: On Tuesday, 8 September 2015 17:07:24 UTC+5:30, hariramm... at gmail.com wrote: > Some where i am missing simple logic.... :) > > ===== > child = pexpect.spawn('ssh hari at hostname') > child.logfile = sys.stdout > child.expect('hari\'s Password: ') > ===== > > getting error as follows: > ============ > child.expect('hari\'s Password: ') > TypeError: must be str, not bytes > =========== > > Thanks... Hi, can you check it and let me know the way... Thanks... From rosuav at gmail.com Thu Sep 10 01:39:10 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 10 Sep 2015 15:39:10 +1000 Subject: ImportError: No module named multiprocessing In-Reply-To: References: Message-ID: On Thu, Sep 10, 2015 at 7:58 AM, Julio Alonso wrote: > have a problem to import a multiprocessing module. I am using Python 2.7 and > Windows 8. The program (.py) is executed since MS-DOS console. > > If I run the program the output is "ImportError: No module named > multiprocessing". > > If I execute "import multiprocessing" on Python Command Line I don't have > problems, but It isn't useful for my program, because I need to import since > my own file .py > > What do you recommend me?. I need to get benefit from the process-based > parallelism and to use several processors. Did you name your file multiprocessing.py? If so, simply rename it; it should be fine. Otherwise, try running "python -v your_script_name.py" and paste the full output here, as text. Or at very least, paste the full exception traceback that you're currently seeing. The exception gives a lot more information than just its final message, and it helps a lot with tracking down the problem. ChrisA From harirammanohar159 at gmail.com Thu Sep 10 02:08:11 2015 From: harirammanohar159 at gmail.com (harirammanohar159 at gmail.com) Date: Wed, 9 Sep 2015 23:08:11 -0700 (PDT) Subject: issue while doing pexpect ssh In-Reply-To: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> References: <3f4642c2-d548-4089-87c2-f3abb4ccb224@googlegroups.com> Message-ID: <19322052-a9bf-441a-bc8e-bb7ae1932037@googlegroups.com> Hey, its resolved by small tweak :) do child.sendline('logout') instead of child.logout() Thanks... From dieter at handshake.de Thu Sep 10 02:30:52 2015 From: dieter at handshake.de (dieter) Date: Thu, 10 Sep 2015 08:30:52 +0200 Subject: XML Binding References: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> <9b916796-623d-45d9-abe0-8bc7934ec42b@googlegroups.com> <87r3m8q9zz.fsf@handshake.de> Message-ID: <87h9n2ss4j.fsf@handshake.de> Stefan Behnel writes: > dieter schrieb am 09.09.2015 um 10:20: >> Palpandi writes: >>> Is it better to use pyxb than lxml? >>> >>> What are the advantages of lxml and pyxb? >> >> "pyxb" has a different aim than "lxml". >> >> "lxml" is a general purpose library to process XML documents. >> It gives you an interface to the document's resources (elements, >> attributes, comments, processing instructions) on a low level >> independ from the document type. > > lxml's toolbox is actually larger than that. There's also lxml.objectify > which provides a Python object interface to the XML tree, similar to what > data binding would give you. And you can stick your own Element object > implementations into it if you feel a need to simplify the API itself > and/or adapt it to a given document format. > > http://lxml.de/objectify.html This is nice - but still quite far from the schema support of "pyxb". The "pyxb" binding generation generates a Python class for each type defined in the schema. You just instantiate such a class, populate the resulting object (in the normal Python way) and either use it in the construction of larger objects or serialize it as XML -- no need to worry about special construction ("objectivity.DataElement", "objectivity.SubElement", ...), no need to worry about xml namespaces. From dieter at handshake.de Thu Sep 10 02:41:45 2015 From: dieter at handshake.de (dieter) Date: Thu, 10 Sep 2015 08:41:45 +0200 Subject: From logging to files to a better solution: syslog, Sentry, Logstash, .... References: <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> Message-ID: <87d1xqsrme.fsf@handshake.de> Thomas G?ttler writes: > ... > Why we are unhappy with logging to files: > > - filtering: We don't want to get INFO messages over the VPN. You can quite easily control at what level messages are logged with the standard Python logging framework. Each handler has a level and will ignore messages at a lower level. > - Rotating: Rotating files is possible, but somehow cumbersome. There are standard tools to rotate logfiles. > - Support structured logging of values (json) in the future. Again, the Python logging framework is quite flexible with respect to the format of logged messages. > ... > Which solution could fit for our environment? I work for a customer with a similar environment (he uses "Zope" instead of "Django") - and he uses logfiles. The logfiles are automatically rotated and there are in the order of half a dozen to a dozen logfiles per day. When I have to analyse a problem with the help of the logfiles, I do not copy them via VPN but do the filtering remotely and only copy the filtered portion, if necessary. From ybmess at nooos.fr.invalid Thu Sep 10 02:42:26 2015 From: ybmess at nooos.fr.invalid (YBM) Date: Thu, 10 Sep 2015 03:42:26 -0300 Subject: Lesson 39 of Learning Python the Hard Way hangs (Fixed?) In-Reply-To: References: Message-ID: <55f1256a$0$4570$426a74cc@news.free.fr> Le 09/09/2015 20:58, Gary Roach a ?crit : > On 09/09/2015 01:45 PM, John Gordon wrote: >> In Gary Roach >> writes: >> >>> Traceback (most recent call last): >>> File "/root/mystuff/mystuff/ex39_test.py", line 6, in >>> hashmap.set(states, 'Oregon', 'OR') >>> File "/root/mystuff/mystuff/hashmap.py", line 50, in set >>> i, k, v = get_slot(aMap, key) >>> TypeError: 'NoneType' object is not iterable >>> Execution Successful! >> Where does the message "Execution Successful!" come from? It seems like >> you have other code that you haven't shown us. >> >> In any case, I saved your code and ran it, and did not get an error. >> > No other code. Ninja-IDE tacked the "Execution Successful" at the end if > the error message. Dont know why. > > Interesting that you ran the code successfully. I have tried to run the > code in both Ninja and at the command line and got the exact same error > message. > > A note: If you could, please post your replies to the list. If you > don't, it either breaks the thread or ends up sending a copy to my > personal email address. I am assuming that your email client gives you > that choice. If not, I'm not sure how you would assure that the proper > way happens. I use the icedove (thunderbird) mail client and the choice > is a drop down list at the top of the mail editor page. > > Thanks for your reply. > Still confused > > Gary R. > > PS I copied over my code with the one from the lesson and all of a > sudden it works. I then used the code I copied to the email. It also > worked. Now I can't duplicate the problem. The problems fixed but .... So something was *necessarely* different between your test and what you've posted here (which works for me as well, without error). Your first tests were different from what you've posted, this is certain. Could be because you redefined "list" in your module, you shouldn't: >>> list('abcd') ['a', 'b', 'c', 'd'] >>> def list(aMap): ... """Prints out what's in the Map.""" ... for bucket in aMap: ... if bucket: ... for k, v in bucket: ... print k, v >>> list('abcd') Traceback (most recent call last): File "", line 1, in File "", line 5, in list ValueError: need more than 1 value to unpack So if you've been using "list" as a constructor *after* def list... *in your module* it wouldn't have behaved as expected. As a rule of thumb : do not use types names (list, str, tuple, ...) as identifiers in your code. Most of the times it is harmless first, (especially in modules, because of namespaces isolation) but sooner or later it leads to strange errors... >>> list(message) ['h', 'e', 'l', 'l', 'o'] >>> list = [1,2,3] >>> list(message) Traceback (most recent call last): File "", line 1, in TypeError: 'list' object is not callable From dieter at handshake.de Thu Sep 10 02:54:58 2015 From: dieter at handshake.de (dieter) Date: Thu, 10 Sep 2015 08:54:58 +0200 Subject: Getting response over logging socket References: Message-ID: <878u8esr0d.fsf@handshake.de> Larry Martell writes: > I have an app that uses the logging package with a SocketHandler to > send messages. Now I've been asked to change it so that it can receive > a response for each log message sent. It appears there is no way to do > this with logging package. Is that true? You are right. There are different connotations associated with the term "logging". One connatation is to inform related parties about events of potential interest in the current execution. The parties may or may not be interested. It is of no importance for the current execution whether some party has processed the event. This is the model, the Python standard handlers adhere to. Another connatation is used for transaction management. Those systems often use a sequentially written "log" and some operations must only proceed after this "log" has definitely been updated. For this type of "logging", you need a feedback that the logging operation has completed successfully. The Python logging targets the first connatation. For the second connotation, there are likely better approaches than the standard Python logging framework (look for "transaction", "transactional"). > Can I not receive data over a > socket used in a logging handler? Almost surely, you can develop your own logging handler which performs a handshake with the logging target. Note that the logging destination, too, will need to be modified for this. I assume, however, there will be better approaches that using the Python logging framework -- e.g. transactional safe message queues. From frank at chagford.com Thu Sep 10 03:12:29 2015 From: frank at chagford.com (Frank Millman) Date: Thu, 10 Sep 2015 09:12:29 +0200 Subject: Question about import Message-ID: Hi all My project comprises a number of modules, split into packages. Modules frequently need to access the contents of other modules, in the same or in a different package. I am getting better at it, but I still occasionally bump my head against circular imports, and have to fiddle around until it settles down again. Not ideal, I know. I have just noticed something odd, and I wondered if it might provide a solution, or if it is a dangerous sidetrack. Here is a simple example - /test | start.py /a | aa.py /b | bb.py start.py import a.aa import b.bb a.aa.aaa() b.bb.bbb() aa.py import b def aaa(): print('in aaa') b.bb.bbbb() def aaaa(): print('in aaaa') bb.py import a def bbb(): print('in bbb') a.aa.aaaa() def bbbb(): print('in bbbb') c:\test>start.py in aaa in bbbb in bbb in aaaa The surprising thing is that, within aa.py, I just have to say 'import b', and I can access 'b.bb.bbbb', and the same applies to 'bb.py'. That makes me wonder if, in my project, I can import all modules inside 'start.py', and then just use 'import package_name' inside each module? Another question - I thought that, because aa.py and bb.py are in different sub-directories, I would have to set them up as packages by adding '__init__.py' to each one, but it works fine without that. What am I missing? I am using python 3.4. Any comments appreciated. Frank Millman From antoon.pardon at rece.vub.ac.be Thu Sep 10 03:27:10 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 10 Sep 2015 09:27:10 +0200 Subject: Python handles globals badly. In-Reply-To: <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55F130CE.5060203@rece.vub.ac.be> Op 09-09-15 om 19:55 schreef Steven D'Aprano: > In fairness to the C creators, I'm sure that nobody back in the early > seventies imagined that malware and security vulnerabilities would be as > widespread as they have become. But still, the fundamental decisions made > by C are lousy. Assignment is an expression? What is wrong with that? -- Antoon Pardon From breamoreboy at gmail.com Thu Sep 10 03:39:12 2015 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 10 Sep 2015 00:39:12 -0700 (PDT) Subject: Silly question about pip In-Reply-To: <0e72d8e1-c454-4087-a27b-6fe8f93b9a33@googlegroups.com> References: <54d12451-0160-4acb-b850-b2f49838fe42@googlegroups.com> <55ef263e$0$23821$e4fe514c@news.xs4all.nl> <39e93a61-c134-45e3-ac48-9c0af98c674f@googlegroups.com> <0e72d8e1-c454-4087-a27b-6fe8f93b9a33@googlegroups.com> Message-ID: <6f57313a-ac8e-4d06-9ea2-d5cc98c4fd18@googlegroups.com> On Wednesday, September 9, 2015 at 10:06:31 AM UTC+1, wxjm... at gmail.com wrote: > Le mardi 8 septembre 2015 21:02:31 UTC+2, wxjm... at gmail.com a ?crit?: > > Le mardi 8 septembre 2015 20:18:20 UTC+2, Irmen de Jong a ?crit?: > > > On 8-9-2015 17:54, wxjmfauth at gmail.com wrote: > > > > win7 / py433 > > > > > > > > How to downgrade from the latest pip (7.1.2) to > > > > the previous one? > > > > I'm sorry, I do not remember the numerous msgs > > > > I saw when updating. (Yesterday) > > > > > > > > (I'm serious) > > > > > > > > Now, what? > > > > > > > > > > I think: > > > > > > $ pip install --upgrade pip==7.0.0 > > > > > > > > > would do the trick, where you substitute the required version number for 7.0.0. > > > > > > > > > Irmen > > > > Addendum (your question) > > > > > pip install --upgrade pip > > > > which probably selects the latest version > > > --- > > pip install --upgrade pip==6.0.8 > > is indeed a valid command > except I'm seeing the same previous mess. The minor snag is we're not seeing your mess. However as I'm getting really good vibes from my crystal ball today, I'd guess that you're getting a known problem on Windows with a permissions error, but the pip upgrade has actually worked fine. Am I close? From marko at pacujo.net Thu Sep 10 03:49:07 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 10 Sep 2015 10:49:07 +0300 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87zj0ur9xo.fsf@elektro.pacujo.net> Antoon Pardon : > Op 09-09-15 om 19:55 schreef Steven D'Aprano: >> In fairness to the C creators, I'm sure that nobody back in the early >> seventies imagined that malware and security vulnerabilities would be >> as widespread as they have become. But still, the fundamental >> decisions made by C are lousy. Assignment is an expression? > > What is wrong with that? C is an extremely strong language. However, I also think they made some slightly regrettable choices, some of which later standards have alleviated. One of my main issues with C has been the intentional confusion between arrays and pointers. Also, the type notation is clearly inferior to that of Pascal. The greatest blessing C has bestowed upon programmers is the void pointer. While C++ programmers (among others) have built a ridiculous cathedral (templates) to capture the same universal notion, C programmers just shrug their shoulders and store the reference in a void pointer variable. Marko From chenchao at inhand.com.cn Thu Sep 10 06:11:08 2015 From: chenchao at inhand.com.cn (chenchao at inhand.com.cn) Date: Thu, 10 Sep 2015 18:11:08 +0800 Subject: numpy Message-ID: <55F1573C.8060807@inhand.com.cn> hi: I have to use numpy package. My python runs on my embedded arm device. So, how do i cross compile numpy? From mail at timgolden.me.uk Thu Sep 10 06:20:49 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 10 Sep 2015 11:20:49 +0100 Subject: Can't use Python Launcher on Windows after update to 3.5 In-Reply-To: References: Message-ID: <55F15981.8030804@timgolden.me.uk> On 10/09/2015 00:52, Mark Lawrence wrote: > I've installed 3.5 for all users so it's in C:\Program Files > > From > https://docs.python.org/3.5/using/windows.html#from-the-command-line it > says "System-wide installations of Python 3.3 and later will put the > launcher on your PATH. The launcher is compatible with all available > versions of Python, so it does not matter which version is installed. To > check that the launcher is available, execute the following command in > Command Prompt:", but:- > > C:\Users\Mark\Documents\MyPython>py -3.4 > 'py' is not recognized as an internal or external command, > operable program or batch file. > > Further running ftype shows nothing for Python, assoc just gives this > .pyproj=VisualStudio.Launcher.pyproj.14.0. Surely this is wrong? > > Before I go to the bug tracker to raise an issue could somebody please > confirm what I'm seeing, thanks. > Well I've just installed 64-bit 3.5.0rc4 via the web installer (ie this: https://www.python.org/ftp/python/3.5.0/python-3.5.0rc4-amd64-webinstall.exe) onto a machine with 64-bit 3.4.2 already installed. I went for the default install. It all seems to be ok and py -3.4 --version gives me "Python 3.4.2" as expected. assoc/ftype both look ok. c:\windows\py.exe has the versions & dates I expect. TJG From schweiger.gerald at gmail.com Thu Sep 10 07:18:20 2015 From: schweiger.gerald at gmail.com (Gerald) Date: Thu, 10 Sep 2015 04:18:20 -0700 (PDT) Subject: textfile: copy between 2 keywords Message-ID: <13d875f0-ae8d-43de-85b4-c943a0e7f5e2@googlegroups.com> Hey, is there a easy way to copy the content between 2 unique keywords in a .txt file? example.txt 1, 2, 3, 4 #keyword1 3, 4, 5, 6 2, 3, 4, 5 #keyword2 4, 5, 6 ,7 Thank you very much From steve at pearwood.info Thu Sep 10 08:10:15 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 10 Sep 2015 22:10:15 +1000 Subject: textfile: copy between 2 keywords References: <13d875f0-ae8d-43de-85b4-c943a0e7f5e2@googlegroups.com> Message-ID: <55f17326$0$1655$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Sep 2015 09:18 pm, Gerald wrote: > Hey, > > is there a easy way to copy the content between 2 unique keywords in a > .txt file? > > example.txt > > 1, 2, 3, 4 > #keyword1 > 3, 4, 5, 6 > 2, 3, 4, 5 > #keyword2 > 4, 5, 6 ,7 > > > Thank you very much Copy in what sense? Write to another file, or just copy to memory? Either way, your solution will look something like this: * read each line from the input file, until you reach the first keyword; * as soon as you see the first keyword, change to "copy mode" and start copying lines in whatever way you feel is best; * until you see the second keyword, then stop. E.g. with open("input.txt") as f: # Skip lines as fast as possible. for line in f: if line == "START\n": break # Instead of copying, I'll just print the lines. That's sort of a copy. for line in f: # This will pick up where the previous for loop ended. if line == "STOP\n": break print(line) # If you like, you can just finish now. # Or, we can read the rest of the lines. for line in f: # continue from just after the STOP keyword. pass # This is a waste of time... print("Done!") -- Steven From steve at pearwood.info Thu Sep 10 08:18:23 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 10 Sep 2015 22:18:23 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F079BD.7040408@mail.de> <201509091914.t89JEEcc006661@fido.openend.se> Message-ID: <55f1750e$0$1642$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Sep 2015 05:18 am, Chris Angelico wrote: > On Thu, Sep 10, 2015 at 5:14 AM, Laura Creighton wrote: >> In a message of Thu, 10 Sep 2015 05:00:22 +1000, Chris Angelico writes: >>>To get started, you need some other sort of kick. >> >> Having Brian Kernighan write a really nice book about you, helps a lot. > > It kinda does. And of course, it also helps to have a time machine, so > you can launch your language when there are less languages around. > Today, you compete for attention with myriad languages that simply > didn't exist when C was introduced to an unsuspecting world. I don't think that's quite right. I think, if anything, there were more languages in the 1970s than now, it's just that they tended to be proprietary, maybe only running on a single vendor's machine. But even if I'm mistaken, I think that there is near-universal agreement that the single biggest factor in C's popularity and growth during the 1970s and 80s is that it was tied so intimately to Unix, and Unix was taking over from mainframes, VAX, etc. -- Steven From steve at pearwood.info Thu Sep 10 08:20:51 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 10 Sep 2015 22:20:51 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f175a1$0$1642$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Sep 2015 04:23 am, Emile van Sebille wrote: > On 9/9/2015 10:55 AM, Steven D'Aprano wrote: > >> (I wanted to link to the "Everything Is Broken" essay on The Medium, but >> the page appears to be gone. > > Is this it? > http://www.sott.net/article/280956-Everything-is-broken-on-the-Internet Looks like that's a mirror of the original, which is the one Laura found: https://medium.com/message/everything-is-broken-81e5f33a24e1 Thanks guys. I don't know why I couldn't get to it earlier. -- Steven From harvesting at makes.email.invalid Thu Sep 10 09:47:39 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Thu, 10 Sep 2015 16:47:39 +0300 Subject: textfile: copy between 2 keywords References: <13d875f0-ae8d-43de-85b4-c943a0e7f5e2@googlegroups.com> Message-ID: Gerald writes: > Hey, > > is there a easy way to copy the content between 2 unique keywords in a > .txt file? > > example.txt > > 1, 2, 3, 4 > #keyword1 > 3, 4, 5, 6 > 2, 3, 4, 5 > #keyword2 > 4, 5, 6 ,7 Depending on your notion of easy, you may or may not like itertools. The following code gets you the first keyword and the lines between but consumes the second keyword. If I needed more control, I'd probably write what Steven D'Aprano wrote but as a generator function, to get the flexibility of deciding separately what kind of copy I want in the end. And I'd be anxious about the possibility that the second keyword is not there in the input at all. Steven's code and mine simply take every line after the first keyword in that case. Worth a comment in the code, if not an exception. Depends. Code: from itertools import dropwhile, takewhile from sys import stdin def notbeg(line): return line != '#keyword1\n' def notend(line): return line != '#keyword2 \n' # sic! if __name__ == '__main__': print(list(takewhile(notend, dropwhile(notbeg, stdin)))) Output with your original mail as input in stdin: ['#keyword1\n', '3, 4, 5, 6\n', '2, 3, 4, 5\n'] From ian.g.kelly at gmail.com Thu Sep 10 10:17:19 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 10 Sep 2015 08:17:19 -0600 Subject: Question about import In-Reply-To: References: Message-ID: On Thu, Sep 10, 2015 at 1:12 AM, Frank Millman wrote: > That makes me wonder if, in my project, I can import all modules inside > 'start.py', and then just use 'import package_name' inside each module? You can, but for readability and reuse I think it's better to be explicit in each module and import the fully qualified module names that are needed, rather than relying on some other module to import them for you. > Another question - I thought that, because aa.py and bb.py are in different > sub-directories, I would have to set them up as packages by adding > '__init__.py' to each one, but it works fine without that. What am I > missing? That surprises me also, but I suspect it's because they're subdirectories of the current working directory rather than packages found on the sys.path. From torriem at gmail.com Thu Sep 10 10:21:01 2015 From: torriem at gmail.com (Michael Torrie) Date: Thu, 10 Sep 2015 08:21:01 -0600 Subject: Python handles globals badly. In-Reply-To: <55F130CE.5060203@rece.vub.ac.be> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F130CE.5060203@rece.vub.ac.be> Message-ID: <55F191CD.8040901@gmail.com> On 09/10/2015 01:27 AM, Antoon Pardon wrote: > Op 09-09-15 om 19:55 schreef Steven D'Aprano: >> In fairness to the C creators, I'm sure that nobody back in the early >> seventies imagined that malware and security vulnerabilities would be as >> widespread as they have become. But still, the fundamental decisions made >> by C are lousy. Assignment is an expression? > > What is wrong with that? Makes for a common error of putting an assignment in a conditional expression like: if (a=4) this_is_always_true(); GCC will give you a warning over that these days. But many C programmers still adopt a notation of if (4 == a) do_something(); to protect them if they accidentally leave out one =. If assignment was not an expression, then the compiler would properly error out every time you used a solitary = in the conditional of an if statement. Python strikes a good compromise. You can chain = in an assignment statement, but you can't use them in a conditional expression. From vlastimil.brom at gmail.com Thu Sep 10 10:33:37 2015 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 10 Sep 2015 16:33:37 +0200 Subject: textfile: copy between 2 keywords In-Reply-To: <13d875f0-ae8d-43de-85b4-c943a0e7f5e2@googlegroups.com> References: <13d875f0-ae8d-43de-85b4-c943a0e7f5e2@googlegroups.com> Message-ID: 2015-09-10 13:18 GMT+02:00 Gerald : > Hey, > > is there a easy way to copy the content between 2 unique keywords in a .txt file? > > example.txt > > 1, 2, 3, 4 > #keyword1 > 3, 4, 5, 6 > 2, 3, 4, 5 > #keyword2 > 4, 5, 6 ,7 > > > Thank you very much Hi, just to add another possible approach, you can use regular expression search for this task, e.g. (after you have read the text content to an input string): >>> import re >>> input_txt ="""1, 2, 3, 4 ... #keyword1 ... 3, 4, 5, 6 ... 2, 3, 4, 5 ... #keyword2 ... 4, 5, 6 ,7""" >>> re.findall(r"(?s)(#keyword1)(.*?)(#keyword2)", input_txt) [('#keyword1', '\n3, 4, 5, 6\n2, 3, 4, 5\n', '#keyword2')] >>> like in the other approaches, you might need to specify the details for specific cases (no keywords, only one of them, repeated keywords (possible in different order, overlapping or "crossed"), handling of newlines etc. hth, vbr From __peter__ at web.de Thu Sep 10 10:47:16 2015 From: __peter__ at web.de (Peter Otten) Date: Thu, 10 Sep 2015 16:47:16 +0200 Subject: Question about import References: Message-ID: Ian Kelly wrote: > On Thu, Sep 10, 2015 at 1:12 AM, Frank Millman wrote: >> That makes me wonder if, in my project, I can import all modules inside >> 'start.py', and then just use 'import package_name' inside each module? > > You can, but for readability and reuse I think it's better to be > explicit in each module and import the fully qualified module names > that are needed, rather than relying on some other module to import > them for you. > >> Another question - I thought that, because aa.py and bb.py are in >> different sub-directories, I would have to set them up as packages by >> adding '__init__.py' to each one, but it works fine without that. What am >> I missing? > > That surprises me also, but I suspect it's because they're > subdirectories of the current working directory rather than packages > found on the sys.path. So even the experts cannot keep up with all those nifty new features: https://www.python.org/dev/peps/pep-0420/ (Implicit Namespace Packages) I'm waiting to see the language collapse under all its nice and -- seen in isolation -- incredibly useful additions. C++ we're coming :( From jkn_gg at nicorp.f9.co.uk Thu Sep 10 11:09:00 2015 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Thu, 10 Sep 2015 08:09:00 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: <55f1750e$0$1642$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F079BD.7040408@mail.de> <201509091914.t89JEEcc006661@fido.openend.se> <55f1750e$0$1642$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, 10 September 2015 13:18:39 UTC+1, Steven D'Aprano wrote: > On Thu, 10 Sep 2015 05:18 am, Chris Angelico wrote: > > > On Thu, Sep 10, 2015 at 5:14 AM, Laura Creighton wrote: > >> In a message of Thu, 10 Sep 2015 05:00:22 +1000, Chris Angelico writes: > >>>To get started, you need some other sort of kick. > >> > >> Having Brian Kernighan write a really nice book about you, helps a lot. > > > > It kinda does. And of course, it also helps to have a time machine, so > > you can launch your language when there are less languages around. > > Today, you compete for attention with myriad languages that simply > > didn't exist when C was introduced to an unsuspecting world. > > I don't think that's quite right. I think, if anything, there were more > languages in the 1970s than now, it's just that they tended to be > proprietary, maybe only running on a single vendor's machine. But even if > I'm mistaken, I think that there is near-universal agreement that the > single biggest factor in C's popularity and growth during the 1970s and 80s > is that it was tied so intimately to Unix, and Unix was taking over from > mainframes, VAX, etc. > > > > -- > Steven In 'The Design and Evolution of C++', Bjarne Stroustrup writes about a principle that was applied to C with classes (an early embodiment of C++): "C with Classes has to be a weed like C or Fortran because we cannot afford to take care of a rose like Algol68 or Simula. If we deliver an implementation and go away for a year, we want to find several systems running when we come back. That will not happen if complicated maintenance is needed or if a simple port to a new machine takes longer than a week". (pp. 37) I think the 'C is a weed' observation one is a good one to explain the proliferation. I say this as a good thing, and as a programmer in C, C++ and Python. Jon N From ian.g.kelly at gmail.com Thu Sep 10 11:11:19 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 10 Sep 2015 09:11:19 -0600 Subject: Question about import In-Reply-To: References: Message-ID: On Thu, Sep 10, 2015 at 8:47 AM, Peter Otten <__peter__ at web.de> wrote: > Ian Kelly wrote: >> That surprises me also, but I suspect it's because they're >> subdirectories of the current working directory rather than packages >> found on the sys.path. > > So even the experts cannot keep up with all those nifty new features: > > https://www.python.org/dev/peps/pep-0420/ (Implicit Namespace Packages) I've seen that before, but forgot about it. I wouldn't call myself an expert, though; I haven't been using Python regularly for the past couple of years, so I am getting a bit rusty. From harvesting at makes.email.invalid Thu Sep 10 11:48:41 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Thu, 10 Sep 2015 18:48:41 +0300 Subject: textfile: copy between 2 keywords References: <13d875f0-ae8d-43de-85b4-c943a0e7f5e2@googlegroups.com> Message-ID: Vlastimil Brom writes: > just to add another possible approach, you can use regular expression Now you have three problems: whatever the two problems are that you are alleged to have whenever you decide to use regular expressions for anything at all, plus all the people piling on you to tell that a Jamie Zawinski once said that whenever you decide to use regular expressions to solve a problem, you end up with two problems. :) From steve at pearwood.info Thu Sep 10 11:50:36 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 11 Sep 2015 01:50:36 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f1a6cc$0$1669$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Sep 2015 04:26 am, Sven R. Kunze wrote: > Just to understand it the way you want it to be understood: what do you > mean by "technical excellence"? That's one of those things that are difficult to define precisely. All I can do is give some partial examples, and counter-examples. Lisp embodies a form of mathematical elegance and simplicity that one might call technical excellence. Forth does too, despite their completely different syntax and computational model. BASIC does not. ML's type-checker displays technical excellence: http://perl.plover.com/yak/typing/notes.html Haskell, which inherits the same sort of type-checker, does too. Inform 7's natural language syntax and inference engine displays technical excellence. APL's mathematics syntax does not, as it doesn't even follow the same rules that mathematicians expect. (APL, I'm lead to believe, is evaluated purely from left-to-right -- or was it right to left? -- so that 1+2*3 gives 9 rather than 7 like mathematicians expect.) Credit where credit is due: although I think that in the broader computing ecosystem it does more harm than good, the efforts put into optimization by C compilers show technical excellence. If there's a cycle that can be shaved, good C compilers like gcc and clang will find it. It's hard (impossible?) to think of a language that gets *everything* right, because so much of that depends on subjective factors, but I think that languages can display technical excellence in a particular subset of features. It's not "all or nothing" -- a language can be excellent in one area, and poor in another. [...] >> (I wanted to link to the "Everything Is Broken" essay on The Medium, but >> the page appears to be gone. This makes me sad. BTW, what's the point of >> Google's cache when it just redirects to the original, missing, page?) > > Do you mean https://medium.com/message/everything-is-broken-81e5f33a24e1 ? Yes, that's the one, thanks. -- Steven From davros at bellaliant.net Thu Sep 10 11:56:28 2015 From: davros at bellaliant.net (John McKenzie) Date: Thu, 10 Sep 2015 15:56:28 GMT Subject: RPI.GPIO Help References: Message-ID: MRAB: Thanks for replying. I got so hyper focused on solving my hardware problems, and excited that I did, that I forgot details from previous comments. Thanks for your post. Off to make things global... From breamoreboy at yahoo.co.uk Thu Sep 10 11:56:37 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 10 Sep 2015 16:56:37 +0100 Subject: Can't use Python Launcher on Windows after update to 3.5 In-Reply-To: <55F15981.8030804@timgolden.me.uk> References: <55F15981.8030804@timgolden.me.uk> Message-ID: On 10/09/2015 11:20, Tim Golden wrote: > On 10/09/2015 00:52, Mark Lawrence wrote: >> I've installed 3.5 for all users so it's in C:\Program Files >> >> From >> https://docs.python.org/3.5/using/windows.html#from-the-command-line it >> says "System-wide installations of Python 3.3 and later will put the >> launcher on your PATH. The launcher is compatible with all available >> versions of Python, so it does not matter which version is installed. To >> check that the launcher is available, execute the following command in >> Command Prompt:", but:- >> >> C:\Users\Mark\Documents\MyPython>py -3.4 >> 'py' is not recognized as an internal or external command, >> operable program or batch file. >> >> Further running ftype shows nothing for Python, assoc just gives this >> .pyproj=VisualStudio.Launcher.pyproj.14.0. Surely this is wrong? >> >> Before I go to the bug tracker to raise an issue could somebody please >> confirm what I'm seeing, thanks. >> > > Well I've just installed 64-bit 3.5.0rc4 via the web installer (ie this: > https://www.python.org/ftp/python/3.5.0/python-3.5.0rc4-amd64-webinstall.exe) > onto a machine with 64-bit 3.4.2 already installed. I went for the > default install. > > It all seems to be ok and py -3.4 --version gives me "Python 3.4.2" as > expected. assoc/ftype both look ok. c:\windows\py.exe has the versions & > dates I expect. > > TJG > So I ran the 64-bit 3.5.0rc4 via the web installer and still no joy. Ran repair with same and it's business as usual. I'm not that bothered, it's here for the record should anybody else come searching, so chalk it up to experience and move on. Thanks anyway :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve at pearwood.info Thu Sep 10 11:59:27 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 11 Sep 2015 01:59:27 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> On Thu, 10 Sep 2015 04:59 am, random832 at fastmail.us wrote: > On Wed, Sep 9, 2015, at 13:55, Steven D'Aprano wrote: >> In fairness to the C creators, I'm sure that nobody back in the early >> seventies imagined that malware and security vulnerabilities would be as >> widespread as they have become. But still, the fundamental decisions made >> by C are lousy. Assignment is an expression? > > Whoa, hold on. The problem with C assignment isn't that it's an > expression, it's that it's spelled "=" and can be used in contexts where > one would normally do an equality comparison. Yes, that's what I'm referring to. Although, I'm not sure that I agree with the idea that "everything is an expression". I think that's a category mistake, like asking for the speed of dark[1], or for a bucket of cold. Some things are functional by nature, and other things are imperative; some may be both, but I don't think that assignment is one. I think that assignment is imperative, not functional, and forcing it to return a value is artificial. > In some languages (Lisp/Scheme/etc come to mind), *everything* is an > expression. But assignment is spelled with, generally, some variant of > "set" [setq, set!, etc]. Yes, that at least avoids the possibility of mistaking = for == or similar. [1] Obviously it's faster than light, since wherever the light arrives, it finds the dark got there first. -- Steven From lac at openend.se Thu Sep 10 12:05:50 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 10 Sep 2015 18:05:50 +0200 Subject: numpy In-Reply-To: <55F1573C.8060807@inhand.com.cn> References: <55F1573C.8060807@inhand.com.cn> Message-ID: <201509101605.t8AG5orl024197@fido.openend.se> In a message of Thu, 10 Sep 2015 18:11:08 +0800, "chenchao at inhand.com.cn" write s: >hi: > I have to use numpy package. My python runs on my embedded arm >device. So, how do i cross compile numpy? >-- >https://mail.python.org/mailman/listinfo/python-list Ask that one here: http://mail.scipy.org/mailman/listinfo/numpy-discussion Do you even have a floating point processor? I'm not an expert but I don't think that it makes sense to try to run numpy anywhere that doesn't have one. Laura From random832 at fastmail.us Thu Sep 10 12:31:51 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 10 Sep 2015 12:31:51 -0400 Subject: Python handles globals badly. In-Reply-To: <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1441902711.3168172.380049449.32E41922@webmail.messagingengine.com> On Thu, Sep 10, 2015, at 11:59, Steven D'Aprano wrote: > Although, I'm not sure that I agree with the idea that "everything is an > expression". I think that's a category mistake, like asking for the speed > of dark[1], or for a bucket of cold. Some things are functional by > nature, > and other things are imperative; some may be both, but I don't think that > assignment is one. I think that assignment is imperative, not functional, > and forcing it to return a value is artificial. Why shouldn't imperative things be expressions? Why should all expressions return a value? From rosuav at gmail.com Thu Sep 10 12:48:12 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Sep 2015 02:48:12 +1000 Subject: Python handles globals badly. In-Reply-To: <1441902711.3168172.380049449.32E41922@webmail.messagingengine.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> <1441902711.3168172.380049449.32E41922@webmail.messagingengine.com> Message-ID: On Fri, Sep 11, 2015 at 2:31 AM, wrote: > On Thu, Sep 10, 2015, at 11:59, Steven D'Aprano wrote: >> Although, I'm not sure that I agree with the idea that "everything is an >> expression". I think that's a category mistake, like asking for the speed >> of dark[1], or for a bucket of cold. Some things are functional by >> nature, >> and other things are imperative; some may be both, but I don't think that >> assignment is one. I think that assignment is imperative, not functional, >> and forcing it to return a value is artificial. > > Why shouldn't imperative things be expressions? Why should all > expressions return a value? I'm not sure what the point would be of having an expression that doesn't return a value. The point of assignment-as-an-expression is that you can do other things with the result: while ((ch=getchar()) != EOF) In Python, we have a couple of cases where that's done with the 'as' keyword: with open(fn) as in_file: except KeyError as e: and there've been proposals now and then to have the same thing added to if and while, which actually isn't hard: while getchar() as ch: but the trouble is that you can check for falsiness, but nothing else. (In C, EOF is an integer outside the range 0..255, such that it's distinct from any byte value. It's usually -1.) If assignment is an expression, you can capture a value and keep going - something like this: stash = [None] while (stash.__setitem__(0, getchar()) or stash[0]) != -1: ch = stash[0] It's ugly, but it does work - because the setitem call is an expression. However, for this to succeed, the expression MUST yield a value. Otherwise it doesn't make sense, and the difference between expression and statement is a purely technical/theoretical one. (In this case, the value of the "assignment" expression is always None, which is less useful than C's policy of returning the value itself; but at least I know what it's going to be, so I can use the "or stash[0]" notation.) Having assignment be a statement (and therefore illegal in a loop condition) makes sense. Having it be an expression that yields a useful or predictable value makes sense. Having it be an expression, but not returning a value, doesn't. (I'm not going to get into the argument here about whether assignment SHOULD be a statement or an expression. There are plenty of languages to choose from, so you can have it both ways if you like.) ChrisA From auriocus at gmx.de Thu Sep 10 13:29:08 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 10 Sep 2015 19:29:08 +0200 Subject: textfile: copy between 2 keywords In-Reply-To: <13d875f0-ae8d-43de-85b4-c943a0e7f5e2@googlegroups.com> References: <13d875f0-ae8d-43de-85b4-c943a0e7f5e2@googlegroups.com> Message-ID: Am 10.09.15 um 13:18 schrieb Gerald: > Hey, > > is there a easy way to copy the content between 2 unique keywords in a .txt file? > > example.txt > > 1, 2, 3, 4 > #keyword1 > 3, 4, 5, 6 > 2, 3, 4, 5 > #keyword2 > 4, 5, 6 ,7 If "copying" does mean copy it to another file, and you are not obliged to use Python, this is unmatched in awk: Apfelkiste:Tests chris$ cat kw.txt 1, 2, 3, 4 #keyword1 3, 4, 5, 6 2, 3, 4, 5 #keyword2 4, 5, 6 ,7 Apfelkiste:Tests chris$ awk '/keyword1/,/keyword2/' kw.txt #keyword1 3, 4, 5, 6 2, 3, 4, 5 #keyword2 Consequently, awk '/keyword1/,/keyword2/' kw.txt > kw_copy.txt would write it out to kw_copy.txt Beware that between the two slashes there are regexps, so if you have metacharacters in your keywords, you need to quote them. Christian From steve at pearwood.info Thu Sep 10 13:54:14 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 11 Sep 2015 03:54:14 +1000 Subject: Context-aware return Message-ID: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> I have a function which is intended for use at the interactive interpreter, but may sometimes be used non-interactively. I wish to change it's output depending on the context of how it is being called. If the function is being called as if it were a procedure or command, that is the return result is just ignored, I want to return one thing. But if it is being called where the return result goes somewhere, I want to return something else. Most importantly, I don't want to pass a flag to the function myself, I want the function to know its own context. I don't mind if it is CPython only, or if it is a bit expensive. E.g. def func(): do_stuff() if procedure: # FIXME what goes here??? return "Awesome" else: return 999 Now I can do this: x = func() assert x == 999 L = [1, 2, func(), 4] assert L[2] == 999 func() # interactive interpreter prints "Awesome" Is such a thing possible, and if so, how would I do it? If I did this thing, would people follow me down the street booing and jeering and throwing things at me? -- Steven From srkunze at mail.de Thu Sep 10 14:03:02 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 10 Sep 2015 20:03:02 +0200 Subject: Context-aware return In-Reply-To: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55F1C5D6.7020202@mail.de> http://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode On 10.09.2015 19:54, Steven D'Aprano wrote: > I have a function which is intended for use at the interactive interpreter, > but may sometimes be used non-interactively. I wish to change it's output > depending on the context of how it is being called. > > If the function is being called as if it were a procedure or command, that > is the return result is just ignored, I want to return one thing. But if it > is being called where the return result goes somewhere, I want to return > something else. Most importantly, I don't want to pass a flag to the > function myself, I want the function to know its own context. > > I don't mind if it is CPython only, or if it is a bit expensive. > > > E.g. > > def func(): > do_stuff() > if procedure: # FIXME what goes here??? > return "Awesome" > else: > return 999 > > Now I can do this: > > > x = func() > assert x == 999 > > L = [1, 2, func(), 4] > assert L[2] == 999 > > func() > # interactive interpreter prints "Awesome" > > Is such a thing possible, and if so, how would I do it? > > If I did this thing, would people follow me down the street booing and > jeering and throwing things at me? Probably. ;) But it it solve a problem, why not. Best, Sven From ben+python at benfinney.id.au Thu Sep 10 14:12:53 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 11 Sep 2015 04:12:53 +1000 Subject: Context-aware return References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85vbbi6t3u.fsf@benfinney.id.au> Steven D'Aprano writes: > I have a function which is intended for use at the interactive > interpreter, but may sometimes be used non-interactively. I wish to > change it's output depending on the context of how it is being called. > [?] > > x = func() > assert x == 999 > > L = [1, 2, func(), 4] > assert L[2] == 999 > > func() > # interactive interpreter prints "Awesome" > > Is such a thing possible, and if so, how would I do it? That makes my skin creep. In the name of all the tea I've sacrificed to Python over the years, I pray this isn't possible. > If I did this thing, would people follow me down the street booing and > jeering and throwing things at me? First thing in the morning I will purchase a head of cabbage and store it in a warm place to make it rot, on the off chance you find some obscure way to achieve your benighted goal, just so I can be first in line to throw it as you pass. If ever I have to worry that some arbitrary Python function, unbenownst to me, might have a branch that will make it behave differently depending on *whether I bind a reference to its return value*, then I'll know you are sent to us as an evil spirit to make all software suck. -- \ ?Nothing exists except atoms and empty space; everything else | `\ is opinion.? ?Democritus | _o__) | Ben Finney From steve at pearwood.info Thu Sep 10 14:13:50 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 11 Sep 2015 04:13:50 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f1c85d$0$1638$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Sep 2015 02:31 am, random832 at fastmail.us wrote: > On Thu, Sep 10, 2015, at 11:59, Steven D'Aprano wrote: >> Although, I'm not sure that I agree with the idea that "everything is an >> expression". I think that's a category mistake, like asking for the speed >> of dark[1], or for a bucket of cold. Some things are functional by >> nature, >> and other things are imperative; some may be both, but I don't think that >> assignment is one. I think that assignment is imperative, not functional, >> and forcing it to return a value is artificial. > > Why shouldn't imperative things be expressions? Sometimes they might be. But in general, I think it is meaningless to expect a imperative command to have a return result. The whole point of an imperative command is that it operates by side-effect. For example, what would `del x` return if it were an expression instead of a statement? I can think of two reasonable alternatives, but both feel a bit wrong to me. (1) Return True if x was successfully unbound, False if it wasn't. Except that raising an exception seems more Pythonic, in which case returning True seems redundant. It will *always* return True, unless there's an exception. So why bother? We only bother because there's no way to *not* return a result if "everything is an expression". (2) Return None, like functions do by default. But again, it only returns None, not because None is a meaningful thing to return, but because we don't actually have a way to say "it doesn't return anything". Or os.abort. The docs for that say: Help on built-in function abort in module posix: abort(...) abort() -> does not return! Abort the interpreter immediately. This 'dumps core' or otherwise fails in the hardest way possible on the hosting operating system. So, what would os.abort() return, if everything is an expression? Obviously one can always find some arbitrary value for expressions to return, in order to keep the invariant "all expressions return something". But I dislike the arbitrariness of it. Some things aren't conceptually functional expressions, they're imperative commands that (like Pascal procedures, or Python statements) don't naturally have a return result. > Why should all expressions return a value? Because that's the definition of an expression in this context. An expression is evaluated to either return a result, or raise an exception. -- Steven From ben+python at benfinney.id.au Thu Sep 10 14:14:49 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 11 Sep 2015 04:14:49 +1000 Subject: Context-aware return References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> <55F1C5D6.7020202@mail.de> Message-ID: <85r3m66t0m.fsf@benfinney.id.au> "Sven R. Kunze" writes: > http://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode I'm pretty sure Steven knows full well the answer to that question, which is not anything like the one he asked. Would you care to read the question he did ask? -- \ ?The optimist thinks this is the best of all possible worlds. | `\ The pessimist fears it is true.? ?J. Robert Oppenheimer | _o__) | Ben Finney From srkunze at mail.de Thu Sep 10 14:21:36 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 10 Sep 2015 20:21:36 +0200 Subject: Context-aware return In-Reply-To: <55F1C5D6.7020202@mail.de> References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> <55F1C5D6.7020202@mail.de> Message-ID: <55F1CA30.1060703@mail.de> I need to add: you need to look up the stack to see if you have been called by __main__ and if __main__.__file__ is missing. Implementation: I would write decorator for your func. Best, Sven PS: did I say it would probably be a bad idea? If not, it would probably be a bad idea. PPS: what is the reason for this special behavior? On 10.09.2015 20:03, Sven R. Kunze wrote: > http://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode > > > > On 10.09.2015 19:54, Steven D'Aprano wrote: >> I have a function which is intended for use at the interactive >> interpreter, >> but may sometimes be used non-interactively. I wish to change it's >> output >> depending on the context of how it is being called. >> >> If the function is being called as if it were a procedure or command, >> that >> is the return result is just ignored, I want to return one thing. But >> if it >> is being called where the return result goes somewhere, I want to return >> something else. Most importantly, I don't want to pass a flag to the >> function myself, I want the function to know its own context. >> >> I don't mind if it is CPython only, or if it is a bit expensive. >> >> >> E.g. >> >> def func(): >> do_stuff() >> if procedure: # FIXME what goes here??? >> return "Awesome" >> else: >> return 999 >> >> Now I can do this: >> >> >> x = func() >> assert x == 999 >> >> L = [1, 2, func(), 4] >> assert L[2] == 999 >> >> func() >> # interactive interpreter prints "Awesome" >> >> Is such a thing possible, and if so, how would I do it? >> >> If I did this thing, would people follow me down the street booing and >> jeering and throwing things at me? > > Probably. ;) > > But it it solve a problem, why not. > > > Best, > Sven From srkunze at mail.de Thu Sep 10 14:24:15 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 10 Sep 2015 20:24:15 +0200 Subject: Context-aware return In-Reply-To: <85vbbi6t3u.fsf@benfinney.id.au> References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> <85vbbi6t3u.fsf@benfinney.id.au> Message-ID: <55F1CACF.7070004@mail.de> On 10.09.2015 20:12, Ben Finney wrote: > First thing in the morning I will purchase a head of cabbage and store > it in a warm place to make it rot, on the off chance you find some > obscure way to achieve your benighted goal, just so I can be first in > line to throw it as you pass. Well, go ahead. And make photos! From james.harris.1 at gmail.com Thu Sep 10 14:24:37 2015 From: james.harris.1 at gmail.com (James Harris) Date: Thu, 10 Sep 2015 19:24:37 +0100 Subject: Signal SIGINT ignored during socket.accept Message-ID: I have a listening socket, self.lsock, which is used in an accept() call as follows endpoint = self.lsock.accept() The problem is that if control-C is pressed it is not recognised until something connects to that socket. Only when the accept() call returns is the signal seen. The question, then, is how to get the signal to break out of the accept() call. This is currently on Windows but I would like it to run on Unix too. I see from the web that this type of thing is a common problem with the underlying C libraries but I cannot quite relate the posts I have found to Python. Any ideas? James From rosuav at gmail.com Thu Sep 10 14:33:42 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Sep 2015 04:33:42 +1000 Subject: Python handles globals badly. In-Reply-To: <55f1c85d$0$1638$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> <55f1c85d$0$1638$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 11, 2015 at 4:13 AM, Steven D'Aprano wrote: > Sometimes they might be. But in general, I think it is meaningless to expect > a imperative command to have a return result. The whole point of an > imperative command is that it operates by side-effect. > > For example, what would `del x` return if it were an expression instead of a > statement? I can think of two reasonable alternatives, but both feel a bit > wrong to me. > > (1) Return True if x was successfully unbound, False if it wasn't. Except > that raising an exception seems more Pythonic, in which case returning True > seems redundant. It will *always* return True, unless there's an exception. > So why bother? We only bother because there's no way to *not* return a > result if "everything is an expression". > > (2) Return None, like functions do by default. But again, it only returns > None, not because None is a meaningful thing to return, but because we > don't actually have a way to say "it doesn't return anything". Yes, or: (3) Return the old value that x contained, the way dict.pop() does. That makes it a "destructive retrieval" rather than simply a destruction operation. > Or os.abort. The docs for that say: > > Help on built-in function abort in module posix: > > abort(...) > abort() -> does not return! > > Abort the interpreter immediately. This 'dumps core' or otherwise fails > in the hardest way possible on the hosting operating system. > > > So, what would os.abort() return, if everything is an expression? Since this is in the os module, and is thus a thin wrapper around lower-level operations, I could imagine it returning an error code (the way the C-level exec functions do - if they succeed, they don't return, but if they fail, they return an error number); in Python, it'd be best to have it either abort the process (and thus not return), or raise an exception (and thus not return). But abort functions are a rarity. It's not a problem to have a rule "all functions must return something" (as Python does), and then have functions that never actually use the normal return path: def raise_(exc): raise exc raise_stopiteration = iter([]).__next__ raise_typeerror = lambda: ""() Calling one of these functions is *syntactically* an expression, but at run time, it'll never actually get as far as producing a value. If it's at all possible for the operation to, based on run-time information, NOT abort, then it absolutely has to be able to return. > Because that's the definition of an expression in this context. An > expression is evaluated to either return a result, or raise an exception. I'd define it more simply: An expression always produces a result. It's possible that, during the evaluation of an expression, an exception will be raised; if that happens, evaluation stops. Doesn't matter whether the expression itself caused that, or if an OS-level signal did (eg triggering KeyboardInterrupt), or if the expression was "yield 1" and an exception got thrown in. But yes, an expression is something that generates a result; a statement isn't. ChrisA From srkunze at mail.de Thu Sep 10 14:34:11 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 10 Sep 2015 20:34:11 +0200 Subject: Context-aware return In-Reply-To: <85r3m66t0m.fsf@benfinney.id.au> References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> <55F1C5D6.7020202@mail.de> <85r3m66t0m.fsf@benfinney.id.au> Message-ID: <55F1CD23.5060009@mail.de> On 10.09.2015 20:14, Ben Finney wrote: > "Sven R. Kunze" writes: > >> http://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode > I'm pretty sure Steven knows full well the answer to that question, > which is not anything like the one he asked. Would you care to read the > question he did ask? You are right. I turned out to me harder that I first thought. My initial guess was like: use AST. But now I see, it would be hard to get the source code. So, what actually could work, would be faking the interactive interpreter wrapping it up and thus have control over the source code typed in. Best, Sven From rosuav at gmail.com Thu Sep 10 14:36:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Sep 2015 04:36:43 +1000 Subject: Signal SIGINT ignored during socket.accept In-Reply-To: References: Message-ID: On Fri, Sep 11, 2015 at 4:24 AM, James Harris wrote: > I have a listening socket, self.lsock, which is used in an accept() call as > follows > > endpoint = self.lsock.accept() > > The problem is that if control-C is pressed it is not recognised until > something connects to that socket. Only when the accept() call returns is > the signal seen. > > The question, then, is how to get the signal to break out of the accept() > call. This is currently on Windows but I would like it to run on Unix too. I > see from the web that this type of thing is a common problem with the > underlying C libraries but I cannot quite relate the posts I have found to > Python. What version of Python are you using? Also (in case it matters), what version of Windows? Have you tested on any Unix system? I just tried on my Linux, and Ctrl-C interrupted the accept() straight away, so this is quite probably a Windows-only issue. Can you produce an absolute minimal demo program? I'd try something like this: import socket s = socket.socket() s.listen(1) s.accept() which is what worked for me (interactively, Python 2.7.9 and 3.6.0a0, Debian Linux). ChrisA From rosuav at gmail.com Thu Sep 10 14:39:15 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Sep 2015 04:39:15 +1000 Subject: Context-aware return In-Reply-To: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 11, 2015 at 3:54 AM, Steven D'Aprano wrote: > If the function is being called as if it were a procedure or command, that > is the return result is just ignored, I want to return one thing. But if it > is being called where the return result goes somewhere, I want to return > something else. Most importantly, I don't want to pass a flag to the > function myself, I want the function to know its own context. The first thing that comes to mind is a repr hack. If you make your function return an int-like object with a different repr, it could look like it's returning "Awesome" interactively. The usefulness of that depends on what the two forms are you're trying to return, though. Advantage: Doesn't get Ben's cabbage. I think. Disadvantage: Looks weird if you try to debug stuff and get the repr staring back at you. ChrisA From lac at openend.se Thu Sep 10 14:40:49 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 10 Sep 2015 20:40:49 +0200 Subject: Context-aware return In-Reply-To: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: <201509101840.t8AIennI030824@fido.openend.se> In a message of Fri, 11 Sep 2015 03:54:14 +1000, "Steven D'Aprano" writes: >def func(): > do_stuff() > if procedure: # FIXME what goes here??? > return "Awesome" > else: > return 999 > >Now I can do this: > > >x = func() >assert x == 999 > >L = [1, 2, func(), 4] >assert L[2] == 999 > >func() ># interactive interpreter prints "Awesome" > >Is such a thing possible, and if so, how would I do it? Why, why, why do you want such a horrid thing? I have an function that isn't always doing what I want. I make a reference to it, so I can print it from time to time, and do some other things to try to see why sometimes I am getting an unwanted result. I can no longer debug my problem. You are seriously proposing this? >If I did this thing, would people follow me down the street booing and >jeering and throwing things at me? I might start ahead of time, just for thinking of it ... There has got to be a better way to get what you want -- or perhaps for you to want something saner. Laura From srkunze at mail.de Thu Sep 10 14:45:20 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 10 Sep 2015 20:45:20 +0200 Subject: Context-aware return In-Reply-To: <55F1CD23.5060009@mail.de> References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> <55F1C5D6.7020202@mail.de> <85r3m66t0m.fsf@benfinney.id.au> <55F1CD23.5060009@mail.de> Message-ID: <55F1CFC0.6070505@mail.de> On 10.09.2015 20:34, Sven R. Kunze wrote: > You are right. I turned out to me harder that I first thought. > > My initial guess was like: use AST. But now I see, it would be hard to > get the source code. > > So, what actually could work, would be faking the interactive > interpreter wrapping it up and thus have control over the source code > typed in. Ha, got it: sys.settrace >>> def traceit(frame, event, arg): ... return traceit >>> sys.settrace(traceit) >>> a=1 (, 'call', None) (, 'line', None) (, 'return', (u'a=1\n', 4)) (, 'call', None) (, 'line', None) (, 'return', None) There you got the source. The use an AST to find out whether the line fits your definition of 'interactive'. That should only be necessary when the top frame is interactive. Best, Sven From srkunze at mail.de Thu Sep 10 14:56:08 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 10 Sep 2015 20:56:08 +0200 Subject: Context-aware return In-Reply-To: <55F1CFC0.6070505@mail.de> References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> <55F1C5D6.7020202@mail.de> <85r3m66t0m.fsf@benfinney.id.au> <55F1CD23.5060009@mail.de> <55F1CFC0.6070505@mail.de> Message-ID: <55F1D248.7090601@mail.de> Oops, missing print: On 10.09.2015 20:45, Sven R. Kunze wrote: > On 10.09.2015 20:34, Sven R. Kunze wrote: >> You are right. I turned out to me harder that I first thought. >> >> My initial guess was like: use AST. But now I see, it would be hard >> to get the source code. >> >> So, what actually could work, would be faking the interactive >> interpreter wrapping it up and thus have control over the source code >> typed in. > > Ha, got it: sys.settrace > > >>> def traceit(frame, event, arg): ... print(frame, event, arg) > ... return traceit > > >>> sys.settrace(traceit) > > >>> a=1 > (, 'call', None) > (, 'line', None) > (, 'return', (u'a=1\n', 4)) > (, 'call', None) > (, 'line', None) > (, 'return', None) > > > There you got the source. The use an AST to find out whether the line > fits your definition of 'interactive'. > > That should only be necessary when the top frame is interactive. > > > Best, > Sven From rurpy at yahoo.com Thu Sep 10 15:04:05 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Thu, 10 Sep 2015 12:04:05 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: <55f1750e$0$1642$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F079BD.7040408@mail.de> <201509091914.t89JEEcc006661@fido.openend.se> <55f1750e$0$1642$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1eee075d-7073-4875-9e42-2e053ee59b41@googlegroups.com> On Thursday, September 10, 2015 at 6:18:39 AM UTC-6, Steven D'Aprano wrote: > On Thu, 10 Sep 2015 05:18 am, Chris Angelico wrote: > > On Thu, Sep 10, 2015 at 5:14 AM, Laura Creighton wrote: > >> In a message of Thu, 10 Sep 2015 05:00:22 +1000, Chris Angelico writes: > >>>To get started, you need some other sort of kick. > >> > >> Having Brian Kernighan write a really nice book about you, helps a lot. > > > > It kinda does. And of course, it also helps to have a time machine, so > > you can launch your language when there are less languages around. > > Today, you compete for attention with myriad languages that simply > > didn't exist when C was introduced to an unsuspecting world. > > I don't think that's quite right. I think, if anything, there were more > languages in the 1970s than now, it's just that they tended to be > proprietary, maybe only running on a single vendor's machine. But even if > I'm mistaken, I think that there is near-universal agreement that the > single biggest factor in C's popularity and growth during the 1970s and 80s > is that it was tied so intimately to Unix, and Unix was taking over from > mainframes, VAX, etc. The growth of C and Unix were mutually interdependent, one was not the cause of the other. A big factor in the growth of Unix was that it was portable to new hardware relatively easily, a portability made possible by C. I note that even today, 3 or 4 decades later, the availability of Python on a wide variety of platforms is made possible by C. I also doubt there were more programming languages around in the 1970s than now, on the grounds that there were far fewer people capable of writing a compiler or interpreter in those days, and there were far fewer tools to help, or easily accessible knowledge about how to do do it. From james.harris.1 at gmail.com Thu Sep 10 15:11:12 2015 From: james.harris.1 at gmail.com (James Harris) Date: Thu, 10 Sep 2015 20:11:12 +0100 Subject: Signal SIGINT ignored during socket.accept References: Message-ID: "Chris Angelico" wrote in message news:mailman.332.1441910212.8327.python-list at python.org... > On Fri, Sep 11, 2015 at 4:24 AM, James Harris > wrote: >> I have a listening socket, self.lsock, which is used in an accept() >> call as >> follows >> >> endpoint = self.lsock.accept() >> >> The problem is that if control-C is pressed it is not recognised >> until >> something connects to that socket. Only when the accept() call >> returns is >> the signal seen. >> >> The question, then, is how to get the signal to break out of the >> accept() >> call. This is currently on Windows but I would like it to run on Unix >> too. I >> see from the web that this type of thing is a common problem with the >> underlying C libraries but I cannot quite relate the posts I have >> found to >> Python. > > What version of Python are you using? Also (in case it matters), what > version of Windows? Good point. It turns out that it does matter. I have one implementation which fails (Windows) and one which works (Linux). The Linux one breaks out on Control-C. The Windows one does not recognise Control-C until the accept() call returns. The implementations are: $ uname -srm Linux 3.18.7-v7+ armv7l $ python -V Python 2.7.3 And c:\>ver Microsoft Windows XP [Version 5.1.2600] c:\>python -V Python 2.7.9 > Have you tested on any Unix system? I just tried on my Linux, and > Ctrl-C interrupted the accept() straight away, Thanks. > so this is quite probably a Windows-only issue. That turns out to be exactly right. > Can you produce an absolute minimal demo program? I'd try something > like this: > > import socket > s = socket.socket() > s.listen(1) > s.accept() Yes: port = 8880 import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("", port)) s.listen(1) endpoint = s.accept() > which is what worked for me (interactively, Python 2.7.9 and 3.6.0a0, > Debian Linux). On Linux I get $ python socktest.py ^CTraceback (most recent call last): File "socktest.py", line 6, in endpoint = s.accept() File "/usr/lib/python2.7/socket.py", line 202, in accept sock, addr = self._sock.accept() KeyboardInterrupt $ On Windows I get S:\>python socktest.py Traceback (most recent call last): File "socktest.py", line 6, in endpoint = s.accept() File "C:\Python27\lib\socket.py", line 202, in accept sock, addr = self._sock.accept() KeyboardInterrupt S:\> However, on Windows the recognition of Control-C does not happen until after something connects to the socket. I will carry on researching it but maybe the above gives a clue to those in the know...! James From harvesting at makes.email.invalid Thu Sep 10 15:11:25 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Thu, 10 Sep 2015 22:11:25 +0300 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> <55f1c85d$0$1638$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > Or os.abort. The docs for that say: > > Help on built-in function abort in module posix: > > abort(...) > abort() -> does not return! > > Abort the interpreter immediately. This 'dumps core' or otherwise > fails in the hardest way possible on the hosting operating system. > > > So, what would os.abort() return, if everything is an expression? But os.abort() *is* an expression. It's allowed where only an expression is valid syntax. From no.email at nospam.invalid Thu Sep 10 15:19:59 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 10 Sep 2015 12:19:59 -0700 Subject: Context-aware return References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87twr2rsio.fsf@jester.gateway.pace.com> Steven D'Aprano writes: > I want the function to know its own context. > I don't mind if it is CPython only, or if it is a bit expensive. That sounds crazy but if it's really what you want, you can probably fake it by examining the control stack using the backtrace module. I remember doing some hack of raising and catching an exception in order to retrieve the backtrace, but there might be a cleaner way that I didn't bother researching since it was just for a quick debugging problem. From invalid at invalid.invalid Thu Sep 10 15:23:08 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 10 Sep 2015 19:23:08 +0000 (UTC) Subject: Context-aware return References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2015-09-10, Steven D'Aprano wrote: > I have a function which is intended for use at the interactive interpreter, > but may sometimes be used non-interactively. I wish to change it's output > depending on the context of how it is being called. [...] Sounds like an excellent way to waste somebody's afternoon when they start to troubleshoot code that's using your function. Over and over and over we tell newbies who have questions about what something returns or how it works "Start up an interactive session, and try it!". If word gets out about functions like yours, we sort of end up looking like twits. > If I did this thing, would people follow me down the street booing > and jeering and throwing things at me? Only the people who use your function. :) -- Grant Edwards grant.b.edwards Yow! FROZEN ENTREES may at be flung by members of gmail.com opposing SWANSON SECTS ... From rosuav at gmail.com Thu Sep 10 15:26:27 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Sep 2015 05:26:27 +1000 Subject: Signal SIGINT ignored during socket.accept In-Reply-To: References: Message-ID: On Fri, Sep 11, 2015 at 5:11 AM, James Harris wrote: > S:\>python socktest.py > Traceback (most recent call last): > File "socktest.py", line 6, in > endpoint = s.accept() > File "C:\Python27\lib\socket.py", line 202, in accept > sock, addr = self._sock.accept() > KeyboardInterrupt > > S:\> > > However, on Windows the recognition of Control-C does not happen until after > something connects to the socket. > > I will carry on researching it but maybe the above gives a clue to those in > the know...! This is a known problem on Windows. I can't remember what the best solution was, but there's a chance something got into 2.7.10, as it was fairly recent. There's a significantly better chance that something's different in Python 3.x. You may find it worth grabbing a few different versions of Python and trying the same code on all of them. You may run into issues with XP, though. For instance, Python 3.5 doesn't support it, and (IIRC) won't install at all; 3.4 does work, as will all releases of 2.7.x. Worst case, grab yourself a Windows 7 and try a few tests. But a quick test on one of my VMs, with 3.4 on Win 7, didn't show any change. It's entirely possible that a blocking socket-accept call will continue to block. There is one rather silly option, and that's to use select() to effectively poll for Ctrl-C... or, possibly better, have a separate program that shuts down your server (by connecting to it, which thus breaks the stranglehold). Of course, switching over to Unix is also a good option... ChrisA From alister.nospam.ware at ntlworld.com Thu Sep 10 15:41:09 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 10 Sep 2015 19:41:09 +0000 (UTC) Subject: textfile: copy between 2 keywords References: <13d875f0-ae8d-43de-85b4-c943a0e7f5e2@googlegroups.com> Message-ID: On Thu, 10 Sep 2015 12:11:55 -0700, wxjmfauth wrote: >>>> s = """1, 2, 3, 4 > ... #keyword1 ... 3, 4, 5, 6 ... 2, 3, 4, 5 ... #keyword2 ... 4, 5, 6 > ,7""" >>>> s[s.find('keyword1') + len('keyword1'):s.find('keyword2') - 1] > '\n3, 4, 5, 6\n2, 3, 4, 5\n' >>>> #or s[s.find('keyword1') + len('keyword1') + 1:s.find('keyword2') - >>>> 2] > '3, 4, 5, 6\n2, 3, 4, 5' >>>> split works well as a simple 1 liner (well 2 if you include the string setup) >>>a="crap word1 more crap word1 again word2 still more crap" >>>a.split('word1',1)[1].split('word2')[0] ' more crap word1 again ' -- All bad precedents began as justifiable measures. -- Gaius Julius Caesar, quoted in "The Conspiracy of Catiline", by Sallust From alister.nospam.ware at ntlworld.com Thu Sep 10 15:56:33 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 10 Sep 2015 19:56:33 +0000 (UTC) Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 11 Sep 2015 01:59:27 +1000, Steven D'Aprano wrote: > > Although, I'm not sure that I agree with the idea that "everything is an > expression". I think that's a category mistake, like asking for the > speed of dark[1], or for a bucket of cold. Some things are functional by > nature, and other things are imperative; some may be both, but I don't > think that assignment is one. I think that assignment is imperative, not > functional, and forcing it to return a value is artificial. > > > [1] Obviously it's faster than light, since wherever the light arrives, > it finds the dark got there first. Incorrect light is simply the absence of dark https://astro.uni-bonn.de/~dfischer/dark_sucker_2.html http://tristan.ethereal.net/humor/dark-suckers.html -- Neutrinos have bad breadth. From random832 at fastmail.us Thu Sep 10 16:07:44 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 10 Sep 2015 16:07:44 -0400 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> <1441902711.3168172.380049449.32E41922@webmail.messagingengine.com> Message-ID: <1441915664.3216384.380230649.5CF010BC@webmail.messagingengine.com> On Thu, Sep 10, 2015, at 12:48, Chris Angelico wrote: > Having assignment be a statement (and therefore illegal in a loop > condition) makes sense. Having it be an expression that yields a > useful or predictable value makes sense. Having it be an expression, > but not returning a value, doesn't. Why not? Having it not return a value (and thus be illegal in places that expect a value), but be legal in places like C's comma operator or Lisp's progn that do not use the value, would make logical sense. Your while loop could be written as something like "while (ch = getchar(); ch): ..." The main purpose of this would be to prevent you from using it where a boolean is expected, which wouldn't be necessary if Python hadn't repeated C's mistake of spelling it "=". From james.harris.1 at gmail.com Thu Sep 10 16:12:40 2015 From: james.harris.1 at gmail.com (James Harris) Date: Thu, 10 Sep 2015 21:12:40 +0100 Subject: Signal SIGINT ignored during socket.accept References: Message-ID: "Chris Angelico" wrote in message news:mailman.337.1441913195.8327.python-list at python.org... > On Fri, Sep 11, 2015 at 5:11 AM, James Harris > wrote: ... >> However, on Windows the recognition of Control-C does not happen >> until after >> something connects to the socket. ... > This is a known problem on Windows. ... > It's entirely possible that a blocking socket-accept call will > continue to block. There is one rather silly option, and that's to use > select() to effectively poll for Ctrl-C... or, possibly better, have a > separate program that shuts down your server (by connecting to it, > which thus breaks the stranglehold). Thanks for your help, Chris. Using select() is a very good option. I tried first without a timeout and even then this version of Windows does not recognise Control-C until after the select() call returns (which needs similar prompting as with the accept() call. However, select() with a timeout allows the code to work both on Windows and Linux. Hooray! For anyone else who is looking for this the earlier test code was changed to port = 8880 import select import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setblocking(0) s.bind(("", port)) s.listen(1) while 1: ready = select.select((s,), (), (), 0.5) #print '(ready %s)' % repr(ready) if (ready[0]): try: endpoint = s.accept() except socket.error, details: print 'Ignoring socket error:', repr(details) continue print '(endpoint %s)' % repr(endpoint) if endpoint: break James From 4kir4.1i at gmail.com Thu Sep 10 16:15:31 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Thu, 10 Sep 2015 23:15:31 +0300 Subject: Context-aware return References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87twr26nfg.fsf@gmail.com> Grant Edwards writes: > On 2015-09-10, Steven D'Aprano wrote: > >> I have a function which is intended for use at the interactive interpreter, >> but may sometimes be used non-interactively. I wish to change it's output >> depending on the context of how it is being called. > > [...] > > Sounds like an excellent way to waste somebody's afternoon when they > start to troubleshoot code that's using your function. Over and over > and over we tell newbies who have questions about what something > returns or how it works > > "Start up an interactive session, and try it!". > > If word gets out about functions like yours, we sort of end up looking > like twits. > >> If I did this thing, would people follow me down the street booing >> and jeering and throwing things at me? > > Only the people who use your function. :) There are cases when it might be justified to alter the behavior e.g., *colorama* allows to strip ANSI codes (e.g., disable colored output) if stdout is not a tty or *win-unicode-console* make sys.stdout to use WriteConsoleW() to write Unicode to Windows console (interactive case). From invalid at invalid.invalid Thu Sep 10 16:27:10 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 10 Sep 2015 20:27:10 +0000 (UTC) Subject: Context-aware return References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2015-09-10, Akira Li <4kir4.1i at gmail.com> wrote: > Grant Edwards writes: > >> On 2015-09-10, Steven D'Aprano wrote: >> >>> I have a function which is intended for use at the interactive interpreter, >>> but may sometimes be used non-interactively. I wish to change it's output >>> depending on the context of how it is being called. >> >> [...] >> >> Sounds like an excellent way to waste somebody's afternoon when they >> start to troubleshoot code that's using your function. Over and over >> and over we tell newbies who have questions about what something >> returns or how it works >> >> "Start up an interactive session, and try it!". >> >> If word gets out about functions like yours, we sort of end up looking >> like twits. >> >>> If I did this thing, would people follow me down the street booing >>> and jeering and throwing things at me? >> >> Only the people who use your function. :) > > There are cases when it might be justified to alter the behavior e.g., > *colorama* allows to strip ANSI codes (e.g., disable colored output) if > stdout is not a tty or *win-unicode-console* make sys.stdout to use > WriteConsoleW() to write Unicode to Windows console (interactive case). I hate that sort of behavior also, but there's a long historical precident on Unix of command line utilities changing output format based on the results of isatty(STDIN_FILENO). IMO, that was definitely a mistake, and to this day regularly wastes my time when troubleshooting bash programs. But, it's been that way for 45 years, and it's not going to get fixed now. That sort of auto-magical "trying to guess what the user wants" instead of doing what the user says is what makes PHP smell so bad. A bad idea copied by thousand of people over several decades is still a bad idea. Let's not duplicate that mistake in Python. But, just to clarify, we're talking about the function's return value, not what it writes to stdout, right? -- Grant Edwards grant.b.edwards Yow! I would like to at urinate in an OVULAR, gmail.com porcelain pool -- From random832 at fastmail.us Thu Sep 10 16:30:20 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 10 Sep 2015 16:30:20 -0400 Subject: Python handles globals badly. In-Reply-To: <55f1c85d$0$1638$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> <55f1c85d$0$1638$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1441917020.3220484.380248601.6AA39423@webmail.messagingengine.com> On Thu, Sep 10, 2015, at 14:13, Steven D'Aprano wrote: > Because that's the definition of an expression in this context. An > expression is evaluated to either return a result, or raise an exception. Nonsense. An expression is something allowed within a larger expression. It's easy to imagine an expression allowing a subexpression that does not return a result. For example, in non-tail positions of something like C-comma/Lisp-progn. Or, for example, if a C-style "for" loop was an expression, the initializer and increment bits. This is semantics, to some extent - you could just as well say an expression may "return" a "result" that is a special non-value which transforms into an error if it's allowed to escape into a context where the value is needed (e.g. the argument to a function, a place a boolean is expected, being assigned to a variable) - C (and other C-family languages) has such a thing, Lisp does not. From random832 at fastmail.us Thu Sep 10 16:42:26 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Thu, 10 Sep 2015 16:42:26 -0400 Subject: Context-aware return In-Reply-To: <87twr26nfg.fsf@gmail.com> References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> <87twr26nfg.fsf@gmail.com> Message-ID: <1441917746.3223134.380266417.3915C7C9@webmail.messagingengine.com> On Thu, Sep 10, 2015, at 16:15, Akira Li wrote: > There are cases when it might be justified to alter the behavior e.g., > *colorama* allows to strip ANSI codes (e.g., disable colored output) if > stdout is not a tty or *win-unicode-console* make sys.stdout to use > WriteConsoleW() to write Unicode to Windows console (interactive case). These conditions have nothing to do with whether it is running in the interactive interpreter, since you can still be on the console (or a tty) without being in the interactive interpreter. What you are talking about is detecting file redirection. From pkpearson at nowhere.invalid Thu Sep 10 16:49:28 2015 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 10 Sep 2015 20:49:28 GMT Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55ef0514$0$1655$c3e8da3$5496439d@news.astraweb.com> <55efa62d$0$1653$c3e8da3$5496439d@news.astraweb.com> <55f06ae1$0$1650$c3e8da3$5496439d@news.astraweb.com> <3435A80B-14B9-4A7C-99D5-06D898297839@mac.com> Message-ID: On Wed, 9 Sep 2015 20:20:42 +0100, Mark Lawrence wrote: > On 09/09/2015 18:59, William Ray Wing wrote: >>> On Sep 9, 2015, at 1:22 PM, Steven D'Aprano wrote: [snip] >> Right. Note that the Arabs, who DID invent zero, still count from one. [snip] > Would you please provide a citation to support your claim as this > http://www.livescience.com/27853-who-invented-zero.html disagrees. That's baffling. Livescience.com says this: Robert Kaplan, author of "The Nothing That Is: A Natural History of Zero," suggests that an ancestor to the placeholder zero may have been a pair of angled wedges used to represent an empty number column. However, Charles Seife, author of "Zero: The Biography of a Dangerous Idea," disagrees that the wedges represented a placeholder. In that exact book, Seife says the exact opposite of the above allegation: Zero was the solution to the problem. By around 300 BC the Babylonians had started using two slanted wedges, [graphics omitted], to represent an empty space, an empty column on the abacus. This _placeholder_ [italics in original] mark made it easy to tell which position a symbol was in. Either Seife completely changed his mind after my copy of his book was published (2000), or Livescience.com got it completely wrong. -- To email me, substitute nowhere->runbox, invalid->com. From tdev at freenet.de Thu Sep 10 18:25:58 2015 From: tdev at freenet.de (tdev at freenet.de) Date: Thu, 10 Sep 2015 15:25:58 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: References: Message-ID: Some notes to the "global"-keyword and the other proposals. It has been proposed to have these six enhancements 1. optional keyword "global" 2. switch statement 3. less restrictive indentation 4. universal scope 5. goto label 6- "include" script statement with following proofs uncommented: Each sample provided would work without global (or you get runtime failure while try to write a global). So the compiler knows the distiction between global and local already. Otherwise you would have to write in every function this keyword But this is not the case. You write it because you need write access. And this is an over-regulation. So, NO need for an explicit global. Optional ok. Another proof about identation: The parser can recognise identation with tabs and spaces. Otherwise semcicolons or brackets would be needed. It is correct that there have to be a decision for spaces or tabs. But sure not necessarily the exact same indentation to the right for each block. Jus more same inserter to the right and the context is clear. Another proof is Python itself (from Tutorial): "Python is an ... powerful programming language. It has ... and a simple but effective approach to object-oriented programming. Python's elegant syntax ... together with its interpreted nature, make it an ideal language for scripting ... . The proposals are all made for structual programming enhancements This is nothing else than having structural programming, functional programming and OO and many more features in parallel. Why that all? For the same reason: For an another type of programmers - or say: nothing more than even more flexibility. Read also here: https://en.wikipedia.org/wiki/History_of_Python Especially sections: "incfluences from other languages" But all proposals are more or less fully denied - for more or less no reasons. The last statement against the proposals: > "EVERYONE who suggests massive, sweeping changes says "hey, if you only > make these changes, Python will actually become popular". It's almost > mandatory." Additionally, that proofs: that this is not a single meaning. And also speaking from changes is wrong. Enhancements or extensions would be correct. There is the big question: Who is responding or has responded? Extreme Programmers, Python-Hardliner, Python-Evangelists, ... . Presumably no core Python Programmers (wrting compiler and standard library stuff) On Google groups you can currently read for this thread: 37 Authors. 152 posts. 443 views. That is not that much for views (probably mostly from the writer's itself) So, is this really the place where a PEP can be started? When has a proposal to be accepted? If ten-thousands say yes? Which ten-thousands? Who decides it? Thanks. From emile at fenx.com Thu Sep 10 18:40:18 2015 From: emile at fenx.com (Emile van Sebille) Date: Thu, 10 Sep 2015 15:40:18 -0700 Subject: Python handles globals badly. In-Reply-To: References: Message-ID: On 9/10/2015 3:25 PM, tdev at freenet.de wrote: > Who decides it? The BDFL or his delegate. It's simplest that way. Emile From ian.g.kelly at gmail.com Thu Sep 10 20:35:03 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 10 Sep 2015 18:35:03 -0600 Subject: Python handles globals badly. In-Reply-To: References: Message-ID: On Thu, Sep 10, 2015 at 4:25 PM, wrote: > with following proofs uncommented: None of these are "proofs". > Each sample provided would work without global > (or you get runtime failure while try to write a global). What samples? It would be easier to follow your messages if you would include quotes from previous messages as context. > So the compiler knows the distiction between global and local already. As we've said before, it doesn't. The compiler's current rules are fairly simple: 1) If it's in the function's argument list, it's an argument (and therefore local). 2) If it's explicitly declared global, then it's global. 3) If it's never assigned within the function, then it's global. 4) Otherwise, it's local. If you take out step 2, then the compiler has no way of distinguishing whether a variable that is assigned to is local or global. > Another proof about identation: > The parser can recognise identation with tabs and spaces. You can use tabs *or* spaces. If you want to mix the two, then there would need to be some official decision made about how many spaces compose a tab, and then everybody who wants to use tabs would have to configure their editors to conform to that decision, or risk breaking their code. Some people like to indent two spaces. Some people like to indent four spaces. On the other hand, the de facto standard for terminal tab width is eight spaces. However, virtually nobody prefers eight spaces of indentation. So the question is which standard are you going to adopt, and which groups are you going to upset? I really doubt that you're going to gain any traction with this one, because the decision that was made with Python 3 was to make the compiler *more* rigid about not mixing tabs and spaces, not less. > It is correct that there have to be a decision for spaces or tabs. > But sure not necessarily the exact same indentation to the right for each block. > Jus more same inserter to the right and the context is clear. I don't understand what you're trying to say here. > But all proposals are more or less fully denied - for more or less no reasons. You've been given reasons. You seem unwilling to accept them. > There is the big question: > > Who is responding or has responded? > Extreme Programmers, Python-Hardliner, Python-Evangelists, ... . > Presumably no core Python Programmers (wrting compiler and standard library stuff) Ad hominem. > On Google groups you can currently read for this thread: > 37 Authors. 152 posts. 443 views. > > That is not that much for views (probably mostly from the writer's itself) This is not a Google Group. This is the comp.lang.python newsgroup, which is mirrored bidirectionally to the python.org python-list mailing list. Google Groups provides another portal to the newsgroup. There is no way to measure how many users have been reading this thread in the newsgroup or the mailing list. > So, is this really the place where a PEP can be started? No, this list is for general Python discussion. The place to present a PEP is the python-dev mailing list. It is generally considered advisable to post the idea to the python-ideas mailing list first, to find support for the idea and to hone it before going to the trouble of writing a PEP. If you do get to the point of writing a PEP, you will also need to have a clear picture of how you plan to actually implement the idea. It's not enough to just propose that "the global keyword should be optional". Precisely how would scopes be determined? How would you ensure backward compatibility? These are questions that would need answers before anything could be implemented. > When has a proposal to be accepted? If ten-thousands say yes? > Which ten-thousands? Who decides it? That's up to the BDFL. From noah-list at enabled.com Thu Sep 10 20:41:50 2015 From: noah-list at enabled.com (Noah) Date: Thu, 10 Sep 2015 17:41:50 -0700 Subject: finding the diff Message-ID: <55F2234E.8020408@enabled.com> Hi there, I am researching a nice slick way to provide the difference between generated python multi-line configuration output and specific configuration lines gathered from an output file. I could put things in a list? I could put both forms output into IOString() and run a diff command to it? What are some options that work well? Cheers, Noah From denismfmcmahon at gmail.com Thu Sep 10 20:41:57 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 11 Sep 2015 00:41:57 +0000 (UTC) Subject: Context-aware return References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 11 Sep 2015 03:54:14 +1000, Steven D'Aprano wrote: > If I did this thing, would people follow me down the street booing and > jeering and throwing things at me? Yes >>> x = func() >>> x >>> func() >>> print x == func() >>> assert x == func() Would you expect the last two calls to func() to return 999 or "Awesome"? Why? What is the material difference if any between interpreter (a) displaying the return value and (b) comparing the return value with another value. Debugging nightmare! -- Denis McMahon, denismfmcmahon at gmail.com From python at mrabarnett.plus.com Thu Sep 10 21:17:50 2015 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 11 Sep 2015 02:17:50 +0100 Subject: Python handles globals badly. In-Reply-To: References: Message-ID: <55F22BBE.3090202@mrabarnett.plus.com> On 2015-09-11 01:35, Ian Kelly wrote: > On Thu, Sep 10, 2015 at 4:25 PM, wrote: [snip] >> It is correct that there have to be a decision for spaces or tabs. >> But sure not necessarily the exact same indentation to the right for each block. >> Jus more same inserter to the right and the context is clear. > > I don't understand what you're trying to say here. > [snip] I don't understand either, but perhaps he means that as long as the lines of a suite are indented more than their introductory line, the meaning should be clear (although "sibling" lines of the introductory line should still be indented the same as the introductory line, e.g. "elif" lines should still be indented the same amount as their "if" line). It would look untidy though! :-) From rosuav at gmail.com Thu Sep 10 21:35:40 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Sep 2015 11:35:40 +1000 Subject: Python handles globals badly. In-Reply-To: <1441915664.3216384.380230649.5CF010BC@webmail.messagingengine.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> <1441902711.3168172.380049449.32E41922@webmail.messagingengine.com> <1441915664.3216384.380230649.5CF010BC@webmail.messagingengine.com> Message-ID: On Fri, Sep 11, 2015 at 6:07 AM, wrote: > On Thu, Sep 10, 2015, at 12:48, Chris Angelico wrote: >> Having assignment be a statement (and therefore illegal in a loop >> condition) makes sense. Having it be an expression that yields a >> useful or predictable value makes sense. Having it be an expression, >> but not returning a value, doesn't. > > Why not? Having it not return a value (and thus be illegal in places > that expect a value), but be legal in places like C's comma operator or > Lisp's progn that do not use the value, would make logical sense. Your > while loop could be written as something like "while (ch = getchar(); > ch): ..." > > The main purpose of this would be to prevent you from using it where a > boolean is expected, which wouldn't be necessary if Python hadn't > repeated C's mistake of spelling it "=". I didn't say it doesn't make _technical_ sense to have an expression without value, but it doesn't make any _useful_ sense. In previous posts I consciously avoided this wording, but I'm going to say it, and clink my pun jar: There's no value in doing it that way. In order to make this valueless expression useful, you have to first have some sort of expression that consists of two subexpressions, where one of them is ignored. (Like C's comma operator.) Why do it? Why not simply have the expression yield a useful value - or else not be an expression, such that you have two _statements_? ChrisA From rosuav at gmail.com Thu Sep 10 22:01:24 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Sep 2015 12:01:24 +1000 Subject: Signal SIGINT ignored during socket.accept In-Reply-To: References: Message-ID: On Fri, Sep 11, 2015 at 6:12 AM, James Harris wrote: > Thanks for your help, Chris. Using select() is a very good option. I tried > first without a timeout and even then this version of Windows does not > recognise Control-C until after the select() call returns (which needs > similar prompting as with the accept() call. However, select() with a > timeout allows the code to work both on Windows and Linux. Hooray! > > For anyone else who is looking for this the earlier test code was changed to > > port = 8880 > import select > import socket > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.setblocking(0) > s.bind(("", port)) > s.listen(1) > while 1: > ready = select.select((s,), (), (), 0.5) > #print '(ready %s)' % repr(ready) > if (ready[0]): > try: > endpoint = s.accept() > except socket.error, details: > print 'Ignoring socket error:', repr(details) > continue > print '(endpoint %s)' % repr(endpoint) > if endpoint: > break (Your indentation is looking like a single space, here. I would suggest indenting a bit more, for readability; but it might just be an artefact of posting.) This is what I meant when I said you would be polling. Effectively, you wake up your program every half-second, check if Ctrl-C has been pressed, and if it hasn't, you go back to sleep again. This is pretty inefficient. Assuming you don't need stdin for any other purpose, one solution would be to spin off a thread that simply watches for a keyboard signal. I tested this on Windows 7 with 2.7.10 and 3.4.3, and it appears to work: import socket import threading # Python 2/3 compat try: input = raw_input except NameError: pass PORT = 8880 mainsock = socket.socket() mainsock.bind(("", PORT)) mainsock.listen(1) def console(): """Constantly read from stdin and discard""" try: while "moar console": input() except (KeyboardInterrupt, EOFError): socket.socket().connect(("127.0.0.1",PORT)) threading.Thread(target=console).start() while "moar sockets": s = mainsock.accept() print("New connection: %r" % s) # Do whatever you want with the connection s.close() As long as you have _some_ thread reading from the console, you can get woken up by Ctrl-C. When that happens, it simply fires off a quick socket connection to itself, thus waking up the main thread; and then the main thread sees the KeyboardInterrupt. (I'm not sure why, but instead of seeing KeyboardInterrupt in the console thread, I've been seeing EOFError. Since I don't particularly care to explore the problem, I just wrote the except clause to catch both.) This eliminates the polling, but you have to sacrifice stdin to do it. It may be worth bracketing all of that code with a platform check - don't bother doing all this unless you're on Windows. Up to you. Stupid Windows. ChrisA From gheskett at wdtv.com Thu Sep 10 22:19:14 2015 From: gheskett at wdtv.com (Gene Heskett) Date: Thu, 10 Sep 2015 22:19:14 -0400 Subject: Python handles globals badly. In-Reply-To: <0784va15gme91mqvoasfub3hvu59ehpepl@4ax.com> References: <1eee075d-7073-4875-9e42-2e053ee59b41@googlegroups.com> <0784va15gme91mqvoasfub3hvu59ehpepl@4ax.com> Message-ID: <201509102219.14138.gheskett@wdtv.com> On Thursday 10 September 2015 20:33:03 Dennis Lee Bieber wrote: > On Thu, 10 Sep 2015 12:04:05 -0700 (PDT), rurpy--- via Python-list > > declaimed the following: > >I also doubt there were more programming languages around in the > >1970s than now, on the grounds that there were far fewer people > >capable of writing a compiler or interpreter in those days, and > >there were far fewer tools to help, or easily accessible knowledge > >about how to do do it. > > Yet there were enough assorted semi-specialized languages in use on > military programs to induce the DoD to run the competition for a > singular language -- which became Ada. And which should be noted that it has been a rather spectacular failure in the commercial market. Does that mean that those who can code in Ada are working only for the military's suppliers, and because they are a scarce commodity, writing their own paycheck? I don't know, other than no one is publically bragging about it. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From chenchao at inhand.com.cn Thu Sep 10 22:35:41 2015 From: chenchao at inhand.com.cn (chenchao at inhand.com.cn) Date: Fri, 11 Sep 2015 10:35:41 +0800 Subject: numpy In-Reply-To: <201509101605.t8AG5orl024197@fido.openend.se> References: <55F1573C.8060807@inhand.com.cn> <201509101605.t8AG5orl024197@fido.openend.se> Message-ID: <55F23DFD.5020608@inhand.com.cn> hi, Laura: My embedded arm device supports floating point operation. I have to use numpy and pandas packages. But now, I do not known how to cross compile numpy and pandas packages? On 09/11/2015 12:05 AM, Laura Creighton wrote: > In a message of Thu, 10 Sep 2015 18:11:08 +0800, "chenchao at inhand.com.cn" write > s: >> hi: >> I have to use numpy package. My python runs on my embedded arm >> device. So, how do i cross compile numpy? >> -- >> https://mail.python.org/mailman/listinfo/python-list > Ask that one here: > http://mail.scipy.org/mailman/listinfo/numpy-discussion > > Do you even have a floating point processor? I'm not an > expert but I don't think that it makes sense to try to run > numpy anywhere that doesn't have one. > > Laura > From spluque at gmail.com Thu Sep 10 23:05:07 2015 From: spluque at gmail.com (Seb) Date: Thu, 10 Sep 2015 22:05:07 -0500 Subject: subdividing a rectangle using numpy Message-ID: <87k2rxy7to.fsf@gmail.com> Hello, The code below is what I came up with to solve the problem: 1. We're given geographic coordinates for two opposite vertices of a rectangle. 2. If any of the sides of the rectangle is larger than some number of degrees, then subdivide the rectangle into squares/rectangles such that all sub-units have sides smaller than the specified amount. 3. Define each sub-unit by providing a list of all vertices, where the first and last vertices are identical so as to close the polygon. I've ignored the "if" part of the problem to simplify. The key to my solution was to use numpy's meshgrid to generate the coordinates for defining the sub-units. However, it seems awfully complex and contrived, and am wondering if there's a simpler solution, or perhaps some package offers this functionality. I couldn't find any, so any tips appreciated. ---<--------------------cut here---------------start------------------->--- # Let's say we have these coordinates lons = [-96, -51.4] lats = [60, 72] # And we want to create 10x10 (max) degree polygons covering the rectangle # defined by these coordinates step = 10 # Calculate how many samples we need for linspace. The ceiling is required # to cover the last step, and then add two to accomodate for the inclusion # of the end points... what a pain. xn = np.ceil((lons[1] - lons[0]) / step) + 2 yn = np.ceil((lats[1] - lats[0]) / step) + 2 xgrd = np.linspace(lons[0], lons[1], xn) ygrd = np.linspace(lats[0], lats[1], yn) # Create grids of longitudes and latitudes with dimension (yn, xn). The # elements of the longitude grid are the longitude coordinates along the # rows, where rows are identical. The elements of the latitude grid are # the latitude coordinates along the columns, where columns are identical. longrd, latgrd = np.meshgrid(xgrd, ygrd, sparse=False) for i in range(int(xn) - 1): for j in range(int(yn) - 1): print [(longrd[j, i], latgrd[j, i]), # lower left (longrd[j, i + 1], latgrd[j, i]), # lower right (longrd[j, i + 1], latgrd[j + 1, i]), # upper right (longrd[j, i], latgrd[j + 1, i]), # upper left (longrd[j, i], latgrd[j, i])] # close at lower left ---<--------------------cut here---------------end--------------------->--- -- Seb From nobody at nowhere.invalid Thu Sep 10 23:47:23 2015 From: nobody at nowhere.invalid (Nobody) Date: Fri, 11 Sep 2015 04:47:23 +0100 Subject: subdividing a rectangle using numpy References: Message-ID: On Thu, 10 Sep 2015 22:05:07 -0500, Seb wrote: > The key to my solution was to use numpy's meshgrid to generate the > coordinates for defining the sub-units. However, it seems awfully > complex and contrived, Half a dozen lines of code is "complex and contrived"? Also, you should lose marks for having those for loops. Hint: corners = np.array([[0,0],[0,1],[1,1],[1,0],[0,0]]) > or perhaps some package offers this functionality. People don't write packages for such trivial tasks. From marko at pacujo.net Fri Sep 11 00:34:11 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 11 Sep 2015 07:34:11 +0300 Subject: Python handles globals badly. References: Message-ID: <87h9n1o9q4.fsf@elektro.pacujo.net> Ian Kelly : > You can use tabs *or* spaces. If you want to mix the two, then there > would need to be some official decision made about how many spaces > compose a tab, and then everybody who wants to use tabs would have to > configure their editors to conform to that decision, or risk breaking > their code. Some people like to indent two spaces. Some people like to > indent four spaces. On the other hand, the de facto standard for > terminal tab width is eight spaces. However, virtually nobody prefers > eight spaces of indentation. So the question is which standard are you > going to adopt, and which groups are you going to upset? Indentation preferences and the interpretation of TABs are two separate things. For example, in the default emacs configuration, the C indentation levels go like this: SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC SPC TAB TAB SPC SPC etc. The TAB *key* is a command that makes emacs indent with a mix of spaces and TABs. Marko From rosuav at gmail.com Fri Sep 11 00:59:36 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Sep 2015 14:59:36 +1000 Subject: Python handles globals badly. In-Reply-To: <87h9n1o9q4.fsf@elektro.pacujo.net> References: <87h9n1o9q4.fsf@elektro.pacujo.net> Message-ID: On Fri, Sep 11, 2015 at 2:34 PM, Marko Rauhamaa wrote: > etc. The TAB *key* is a command that makes emacs indent with a mix of > spaces and TABs. I don't care how you key them in. If your tab key moves you to the next position, that's good. If you convert a sequence of N spaces into a tab character, though, that's bad, because then your file ends up with a mix, and an inconsistent one. To make emacs safe for use with Python code, you'll need to reconfigure it so the tab key inserts either a tab character or spaces, but never switches between them. Personally, I like to use tab characters for indentation. You can choose how many pixels or ems or ens or spaces the actual visual shift is, and if I disagree with your choice, it won't affect anything. As long as tabs are used _exclusively_, Python won't be bothered by it either. ChrisA From ian.g.kelly at gmail.com Fri Sep 11 01:07:17 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 10 Sep 2015 23:07:17 -0600 Subject: Python handles globals badly. In-Reply-To: <87h9n1o9q4.fsf@elektro.pacujo.net> References: <87h9n1o9q4.fsf@elektro.pacujo.net> Message-ID: On Thu, Sep 10, 2015 at 10:34 PM, Marko Rauhamaa wrote: > Ian Kelly : > >> You can use tabs *or* spaces. If you want to mix the two, then there >> would need to be some official decision made about how many spaces >> compose a tab, and then everybody who wants to use tabs would have to >> configure their editors to conform to that decision, or risk breaking >> their code. Some people like to indent two spaces. Some people like to >> indent four spaces. On the other hand, the de facto standard for >> terminal tab width is eight spaces. However, virtually nobody prefers >> eight spaces of indentation. So the question is which standard are you >> going to adopt, and which groups are you going to upset? > > Indentation preferences and the interpretation of TABs are two separate > things. > > For example, in the default emacs configuration, the C indentation > levels go like this: > > SPC SPC > SPC SPC SPC SPC > SPC SPC SPC SPC SPC SPC > TAB > TAB SPC SPC > > etc. The TAB *key* is a command that makes emacs indent with a mix of > spaces and TABs. That's all true but is tangential to my point. Emacs users with that setup would probably want the Python compiler to interpret a tab as eight spaces. On the other hand, the major benefit that is often touted for indentation using tab characters is that the reader can set their tab width and read the code with their preferred indentation (this fails however when using mixed tabs and spaces as in that Emacs scheme). Such users typically use one tab character as one level of indentation and would presumably prefer to have those tab characters interpreted as two or four spaces, not eight. If we're forced to choose a canonical tab width, both groups can't win. (Of course that Emacs indentation scheme already doesn't work for Python, but then the only possible benefit I can see to using it is a mild compression of the source code, an economy of disk space that really isn't necessary in this day and age.) From marko at pacujo.net Fri Sep 11 01:15:01 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 11 Sep 2015 08:15:01 +0300 Subject: Python handles globals badly. References: <87h9n1o9q4.fsf@elektro.pacujo.net> Message-ID: <878u8do7u2.fsf@elektro.pacujo.net> Chris Angelico : > Personally, I like to use tab characters for indentation. You can > choose how many pixels or ems or ens or spaces the actual visual shift > is, and if I disagree with your choice, it won't affect anything. As > long as tabs are used _exclusively_, Python won't be bothered by it > either. Your preferred, novel usage of TABs, which runs counter to the age-old programming convention, has won enough supporters to make TABs unusable. No harm done. TABs have been banished. They were a bad idea in the first place. Marko From rosuav at gmail.com Fri Sep 11 01:25:41 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Sep 2015 15:25:41 +1000 Subject: Python handles globals badly. In-Reply-To: <878u8do7u2.fsf@elektro.pacujo.net> References: <87h9n1o9q4.fsf@elektro.pacujo.net> <878u8do7u2.fsf@elektro.pacujo.net> Message-ID: On Fri, Sep 11, 2015 at 3:15 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> Personally, I like to use tab characters for indentation. You can >> choose how many pixels or ems or ens or spaces the actual visual shift >> is, and if I disagree with your choice, it won't affect anything. As >> long as tabs are used _exclusively_, Python won't be bothered by it >> either. > > Your preferred, novel usage of TABs, which runs counter to the age-old > programming convention, has won enough supporters to make TABs unusable. > > No harm done. TABs have been banished. They were a bad idea in the first > place. I don't understand. How does that usage run counter to the old conventions? A tab character, a press of the tab key, was a signal to move to the next logical column - regardless of the exact width of a column. It's also completely compatible with the stricter rule "a tab is equivalent to eight spaces". ChrisA From marko at pacujo.net Fri Sep 11 01:27:47 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 11 Sep 2015 08:27:47 +0300 Subject: Python handles globals badly. References: <87h9n1o9q4.fsf@elektro.pacujo.net> Message-ID: <874mj1o78s.fsf@elektro.pacujo.net> Ian Kelly : > Emacs users with that setup would probably want the Python compiler to > interpret a tab as eight spaces. Which it does: Tabs are replaced (from left to right) by one to eight spaces such that the total number of characters up to and including the replacement is a multiple of eight (this is intended to be the same rule as used by Unix). although that definition has been rendered insignificant in Python 3 by the footnote: Indentation is rejected as inconsistent if a source file mixes tabs and spaces in a way that makes the meaning dependent on the worth of a tab in spaces; a TabError is raised in that case. > On the other hand, the major benefit that is often touted for > indentation using tab characters is that the reader can set their tab > width and read the code with their preferred indentation (this fails > however when using mixed tabs and spaces as in that Emacs scheme). > Such users typically use one tab character as one level of indentation > and would presumably prefer to have those tab characters interpreted > as two or four spaces, not eight. That "innovation" has destroyed the TAB character. It won't be missed, though. > If we're forced to choose a canonical tab width, both groups can't > win. (Of course that Emacs indentation scheme already doesn't work for > Python, but then the only possible benefit I can see to using it is a > mild compression of the source code, an economy of disk space that > really isn't necessary in this day and age.) Emacs didn't invent that scheme. That's how TABs worked in my childhood across operating systems. However, TABs were always problematic for other reasons. If you added a space to the beginning of every line to shift everything to the right, TABs caused a misalignment. Marko From dieter at handshake.de Fri Sep 11 02:29:12 2015 From: dieter at handshake.de (dieter) Date: Fri, 11 Sep 2015 08:29:12 +0200 Subject: Question about import References: Message-ID: <87d1xpii4n.fsf@handshake.de> "Frank Millman" writes: >... > My project comprises a number of modules, split into packages. Modules > frequently need to access the contents of other modules, in the same > or in a different package. I am getting better at it, but I still > occasionally bump my head against circular imports, and have to fiddle > around until it settles down again. Not ideal, I know. Ideally, you have only oneway dependencies between modules. In most cases, cyclic dependencies can be removed by refactoring - yielding a better architecture. > ... > The surprising thing is that, within aa.py, I just have to say 'import > b', and I can access 'b.bb.bbbb', and the same applies to 'bb.py'. As a side effect of importing "." "" is bound in "". Thus, after the first import of ".", "" can be accessed via "" after only importing "". > That makes me wonder if, in my project, I can import all modules > inside 'start.py', and then just use 'import package_name' inside each > module? You could - but you should not as this make you vulnerable with respect to the import order. In a small project, this is likely no problem. However, when your projects grow and reuse components intially developped for other projects, this may become unfeasable. From frank at chagford.com Fri Sep 11 02:40:24 2015 From: frank at chagford.com (Frank Millman) Date: Fri, 11 Sep 2015 08:40:24 +0200 Subject: Question about import In-Reply-To: References: Message-ID: "Ian Kelly" wrote in message news:CALwzidm3khNaGTt0OhVEo5bhqk1tFEjBUUUinW9TNUxrpnr8cw at mail.gmail.com... On Thu, Sep 10, 2015 at 1:12 AM, Frank Millman wrote: > > That makes me wonder if, in my project, I can import all modules inside > > 'start.py', and then just use 'import package_name' inside each module? > > You can, but for readability and reuse I think it's better to be > explicit in each module and import the fully qualified module names > that are needed, rather than relying on some other module to import > them for you. I don't disagree. However, I started this exercise because I found a situation in one of my modules where I was referring to another module without ever importing it, and it worked! It took me quite a while to track down what was happening. So there could be a case for being explicit in the other direction - import all modules up front, and explicitly state that all modules are now free to reference anything in any other module. I will give it more thought. > > Another question - I thought that, because aa.py and bb.py are in > > different > > sub-directories, I would have to set them up as packages by adding > > '__init__.py' to each one, but it works fine without that. What am I > > missing? > That surprises me also, but I suspect it's because they're > subdirectories of the current working directory rather than packages > found on the sys.path. I had a look at PEP 420, as mentioned by Peter. I did not understand much of it, but it did say that omitting __init__.py incurs an additional overhead, so I will stick with including it. Many thanks for the useful input. Frank From michele.simionato at gmail.com Fri Sep 11 02:47:47 2015 From: michele.simionato at gmail.com (Michele Simionato) Date: Thu, 10 Sep 2015 23:47:47 -0700 (PDT) Subject: XML Binding In-Reply-To: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> References: <8e17ef7d-a08d-42bf-a56c-0a886d620130@googlegroups.com> Message-ID: <98854a42-cbf3-44de-baea-47a4d89a5381@googlegroups.com> On Thursday, September 3, 2015 at 6:55:06 PM UTC+2, Palpandi wrote: > Hi All, > > Is there any module available in python standard library for XML binding? If not, any other suggestions. > > Which is good for parsing large file? > 1. XML binding > 2. Creating our own classes > > > Thanks, > Palpandi I am one who has just abandoned lxml for xml.etree in the standard library. The reasons for that change were: 1. we had issues compiling/installing lxml on different platforms 2. we had instabilities from one version to the other for what we wanted to do (XML validation with an XSD schema) At the end we solved everything by replacing the XSD validation with a custom validation (which we had to do anyway); at that point the need for lxml disappeared and ElementTree did everything we wanted, except providing the line error in case of invalid files, which was easy to add. It was also smaller, easier to understand and to customize. Its speed was more than enough. However I hear that everybody else is happy with lxml, so YMMV. Michele From __peter__ at web.de Fri Sep 11 03:03:06 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 11 Sep 2015 09:03:06 +0200 Subject: finding the diff References: <55F2234E.8020408@enabled.com> Message-ID: Noah wrote: > I am researching a nice slick way to provide the difference between > generated python multi-line configuration output and specific > configuration lines gathered from an output file. I could put things in > a list? I could put both forms output into IOString() and run a diff > command to it? There's difflib in Python's standard library: >>> import difflib >>> print("".join(difflib.unified_diff( ... ["foo\n", "bar\n", "baz\n"], ... ["foo\n", "baz\n", "bang\n"]))) --- +++ @@ -1,3 +1,3 @@ foo -bar baz +bang From hv at tbz-pariv.de Fri Sep 11 03:22:22 2015 From: hv at tbz-pariv.de (=?ISO-8859-1?Q?Thomas_G=FCttler?=) Date: Fri, 11 Sep 2015 00:22:22 -0700 (PDT) Subject: From logging to files to a better solution: syslog, Sentry, Logstash, .... In-Reply-To: References: <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> Message-ID: Am Donnerstag, 10. September 2015 08:42:47 UTC+2 schrieb dieter: > Thomas G?ttler writes: > > ... > > Why we are unhappy with logging to files: > > > > - filtering: We don't want to get INFO messages over the VPN. > > You can quite easily control at what level messages are logged with > the standard Python logging framework. Each handler has a level > and will ignore messages at a lower level. I want INFO to be logged and stored on the remote host. Therefore I must not filter INFO messages. I don't want to pull INFO messages over the VPN. Ergo, the filtering at Python level does not help in my use case. Or I am missing something. And now I have an ugly soup. The ugly soup is a text file with not well defined syntax. It looks line based. But sometimes there are log messages which span multiple lines .... Remember: "Life is too short to (re)write parsers" Yes, there are tools to parse that soup. But why create this soup in the first place? That's why I want to move from file based logging to a different solution. Unfortunately there too many choices (graylog, logstash, sentry, ...) :-( > > - Rotating: Rotating files is possible, but somehow cumbersome. > > There are standard tools to rotate logfiles. > > > - Support structured logging of values (json) in the future. > > Again, the Python logging framework is quite flexible with > respect to the format of logged messages. > > > ... > > Which solution could fit for our environment? > > I work for a customer with a similar environment (he uses "Zope" instead > of "Django") - and he uses logfiles. The logfiles are automatically > rotated and there are in the order of half a dozen to a dozen logfiles > per day. > > When I have to analyse a problem with the help of the logfiles, > I do not copy them via VPN but do the filtering remotely and only > copy the filtered portion, if necessary. Good to know that I am not the only one running servers in remote intranets. Regards, Thomas G?ttler From antoon.pardon at rece.vub.ac.be Fri Sep 11 03:28:23 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 11 Sep 2015 09:28:23 +0200 Subject: Python handles globals badly. In-Reply-To: <55F191CD.8040901@gmail.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F130CE.5060203@rece.vub.ac.be> <55F191CD.8040901@gmail.com> Message-ID: <55F28297.8080104@rece.vub.ac.be> Op 10-09-15 om 16:21 schreef Michael Torrie: > On 09/10/2015 01:27 AM, Antoon Pardon wrote: >> Op 09-09-15 om 19:55 schreef Steven D'Aprano: >>> In fairness to the C creators, I'm sure that nobody back in the early >>> seventies imagined that malware and security vulnerabilities would be as >>> widespread as they have become. But still, the fundamental decisions made >>> by C are lousy. Assignment is an expression? >> What is wrong with that? > Makes for a common error of putting an assignment in a conditional > expression like: > > if (a=4) this_is_always_true(); No it doesn't. You confuse a semantic characteristic with the specifix syntax that was chosen to express it in C. Should C have chosen '<-' as token for assignment, that error would have been far less common. The error is also facilitated because C doesn't have booleans and so everything can be used as one. If C would have had proper booleans and only allowed those as conditions in if and while statements, most of those errors would have been caught too, because the expression a=4 wouldn't produce a boolean. > GCC will give you a warning over that these days. But many C > programmers still adopt a notation of > > if (4 == a) do_something(); > > to protect them if they accidentally leave out one =. If assignment was > not an expression, then the compiler would properly error out every time > you used a solitary = in the conditional of an if statement. A language can provide this kind of protection and still allow assignment as an expression. A lousy syntactical choice, doesn't invalidate a particular choice in semantics. > Python strikes a good compromise. You can chain = in an assignment > statement, but you can't use them in a conditional expression. Python could have chosen other options, like a different assignment token, like providing a proper boolean type and expection such a type in a condition context. It could reverse the assignment so that you would have to write: expression = var, so that if someone accidently writes if var = expression instead of if var == expression, that would have been caught. It could combine some of these options. Now you possibly don't like these possibilities, but they show there are multiple syntactical possibilities that all allow for assignment as expressions, and that are less vulnerable than C for a specific kind of error. -- Antoon Pardon From rustompmody at gmail.com Fri Sep 11 03:39:09 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 11 Sep 2015 00:39:09 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: <87h9n1o9q4.fsf@elektro.pacujo.net> References: <87h9n1o9q4.fsf@elektro.pacujo.net> Message-ID: <452038d3-cdcb-4786-b4e0-45df34c56ab8@googlegroups.com> On Friday, September 11, 2015 at 10:04:25 AM UTC+5:30, Marko Rauhamaa wrote: > Ian Kelly : > > > You can use tabs *or* spaces. If you want to mix the two, then there > > would need to be some official decision made about how many spaces > > compose a tab, and then everybody who wants to use tabs would have to > > configure their editors to conform to that decision, or risk breaking > > their code. Some people like to indent two spaces. Some people like to > > indent four spaces. On the other hand, the de facto standard for > > terminal tab width is eight spaces. However, virtually nobody prefers > > eight spaces of indentation. So the question is which standard are you > > going to adopt, and which groups are you going to upset? > > Indentation preferences and the interpretation of TABs are two separate > things. Required reading http://www.jwz.org/doc/tabs-vs-spaces.html From marco.nawijn at colosso.nl Fri Sep 11 04:17:38 2015 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Fri, 11 Sep 2015 01:17:38 -0700 (PDT) Subject: From logging to files to a better solution: syslog, Sentry, Logstash, .... In-Reply-To: References: <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> Message-ID: <681f390f-9f1d-4968-8226-41db62ae0f9e@googlegroups.com> On Friday, September 11, 2015 at 9:22:42 AM UTC+2, Thomas G?ttler wrote: > Am Donnerstag, 10. September 2015 08:42:47 UTC+2 schrieb dieter: > > Thomas G?ttler writes: > > > ... > > > Why we are unhappy with logging to files: > > > > > > - filtering: We don't want to get INFO messages over the VPN. > > > > You can quite easily control at what level messages are logged with > > the standard Python logging framework. Each handler has a level > > and will ignore messages at a lower level. > > > I want INFO to be logged and stored on the remote host. > Therefore I must not filter INFO messages. > > I don't want to pull INFO messages over the VPN. > > Ergo, the filtering at Python level does not help in my use case. > Or I am missing something. > > And now I have an ugly soup. > > The ugly soup is a text file with not well defined syntax. It looks line > based. But sometimes there are log messages which span multiple lines .... > > Remember: "Life is too short to (re)write parsers" > > Yes, there are tools to parse that soup. But why create this soup in > the first place? > > That's why I want to move from file based logging to a different solution. > > Unfortunately there too many choices (graylog, logstash, sentry, ...) :-( > > > > > > - Rotating: Rotating files is possible, but somehow cumbersome. > > > > There are standard tools to rotate logfiles. > > > > > - Support structured logging of values (json) in the future. > > > > Again, the Python logging framework is quite flexible with > > respect to the format of logged messages. > > > > > ... > > > Which solution could fit for our environment? > > > > I work for a customer with a similar environment (he uses "Zope" instead > > of "Django") - and he uses logfiles. The logfiles are automatically > > rotated and there are in the order of half a dozen to a dozen logfiles > > per day. > > > > When I have to analyse a problem with the help of the logfiles, > > I do not copy them via VPN but do the filtering remotely and only > > copy the filtered portion, if necessary. > > Good to know that I am not the only one running servers in remote intranets. > > Regards, > Thomas G?ttler So, if logging to json is on the horizon anyway, why don't you create something like a MongoDb handler in the standard Python logging framework and run a MongoDb server in the client intranet? You could then connect over VPN to MongoDb, filter the warning/error messages there on the server side and fetch them to your local systems for analysis. Marco From skybuck2000 at hotmail.com Fri Sep 11 04:23:26 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Fri, 11 Sep 2015 10:23:26 +0200 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EF1DD9.8080705@mrabarnett.plus.com> <55EF6D3B.6030106@mrabarnett.plus.com> Message-ID: <6ddeb$55f28f7d$d47876e2$13291@news.ziggo.nl> "Random832" wrote in message news:mailman.242.1441758354.8327.python-list at python.org... MRAB writes: > If you're allowed to specify both bounds, why would you be forbidden > from negative ones? " It makes it non-obvious what value should be returned from e.g. search methods that return a negative number on failure. .NET's IndexOf function returns -1, but MaxValue if the array has a negative bound. BinarySearch returns the complement of the nearest index to the value you were searching for, which requires some gymnastics if you want to make use of it for an array that has negative and positive bounds. " Yes pascal/Delphi allows negative bounds if I recall correctly, example: var vIntegerArray : array[-10..10] of integer; You have just given a very good reason why to not use negative values for return values/indications of success or failure. In pascal I pretty much always try and use booleans to return success. This is a smart thing to do... especially in pascal/Delphi, since one never knows when one is dealing with negative numbers having processing needs. -1 could then cause problems/troubles/errors. There is a drawback of using booleans which I suspect is the real reason why C programmers for example like to use -1 to indicate failure. It's "speed/performance". Using a seperate boolean doubles memory requirement and might or might not require extra processing time from the CPU. Delphi usually optimizes these booleans to be returned in EAX register... so it's a register based thing... if enough registers or so are available otherwise perhaps some pushes/pops needed... not sure about that last thing. Whatever the case may be... I will assume for now... that nowadays the performance impact of using booleans as return values is not that great ? Also I am not sure... but perhaps booleans allow safer/better procesing of boolean operations. Not sure how -1 or if -1 could lead to problems with or/and statements... mixing C function results will also become problematic... sometimes C functions return 0 to indicate failure. Sometimes 0 can even mean success. So C is pretty inconsistent when it comes to return values. Hence I believe Pascal/Delphi to be better/safer at this. Bye, Skybuck. From steve at pearwood.info Fri Sep 11 04:42:02 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 11 Sep 2015 18:42:02 +1000 Subject: Python handles globals badly. References: Message-ID: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Sep 2015 10:35 am, Ian Kelly wrote: > On Thu, Sep 10, 2015 at 4:25 PM, wrote: [...] >> So the compiler knows the distiction between global and local already. > > As we've said before, it doesn't. The compiler's current rules are > fairly simple: > > 1) If it's in the function's argument list, it's an argument (and > therefore local). > 2) If it's explicitly declared global, then it's global. > 3) If it's never assigned within the function, then it's global. Almost. If it's never assigned within the function, then it is looked up according to the non-local scoping rules: - closures and enclosing functions (if any); - globals; - builtins; in that order. > 4) Otherwise, it's local. "Otherwise" meaning "if it is assigned to", except that "del" counts as an assignment. That is: def spam(): del x makes x a local variable inside the function spam. There's also a bunch of specialised and complicated rules for what happens if you make a star import ("from module import *") inside a function, or call eval or exec without specifying a namespace. Both of these things are now illegal in Python 3. And lastly, in Python 3 only, there is also a nonlocal declaration which works like global except it applies only to closures and enclosing functions. >> Another proof about identation: >> The parser can recognise identation with tabs and spaces. > > You can use tabs *or* spaces. In Python 3. In Python 2, you can mix tabs *and* spaces, and Python will try to guess what you mean. This causes more trouble than it is worth, and is removed in Python 3. [...] > I really doubt that you're going to gain any traction with this one, > because the decision that was made with Python 3 was to make the > compiler *more* rigid about not mixing tabs and spaces, not less. Correct. [...] >> Who is responding or has responded? >> Extreme Programmers, Python-Hardliner, Python-Evangelists, ... . >> Presumably no core Python Programmers (wrting compiler and standard >> library stuff) > > Ad hominem. For the record, I am the author of the statistics module in Python 3.4, and Terry Reedy is the very active maintainer of IDLE. If I have missed anyone, my apologies. So, yes, there are core developers here. (Although not any of the senior core devs, as far as I know.) -- Steven From jeanmichel at sequans.com Fri Sep 11 05:02:54 2015 From: jeanmichel at sequans.com (jmp) Date: Fri, 11 Sep 2015 11:02:54 +0200 Subject: From logging to files to a better solution: syslog, Sentry, Logstash, .... In-Reply-To: References: <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> Message-ID: On 09/11/2015 09:22 AM, Thomas G?ttler wrote: > > I want INFO to be logged and stored on the remote host. > Therefore I must not filter INFO messages. > > I don't want to pull INFO messages over the VPN. > > Ergo, the filtering at Python level does not help in my use case. > Or I am missing something. Probably, Your logger should have * a remote host handler * and a VPN handler. You can set filters and log levels separately for each handler. More info here https://docs.python.org/2/library/logging.html#handler-objects https://docs.python.org/2/howto/logging-cookbook.html#logging-to-multiple-destinations Something like (python 2.7) import logging logCfg = { 'remote':( logging.StreamHandler(), logging.Formatter('Remote - %(levelname)s - %(message)s'), logging.INFO, ), 'vpn':( logging.StreamHandler(), logging.Formatter('VPN - %(levelname)s - %(message)s'), logging.ERROR, ), } log = logging.getLogger() log.setLevel(logging.DEBUG) for handler, formatter, level in logCfg.itervalues(): handler.setFormatter(formatter) handler.setLevel(level) log.addHandler(handler) log.info('This is an info') log.error('This is error') and the result: Remote - INFO - This is an info VPN - ERROR - This is error Remote - ERROR - This is error JM From rosuav at gmail.com Fri Sep 11 05:16:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 11 Sep 2015 19:16:06 +1000 Subject: Python handles globals badly. In-Reply-To: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 11, 2015 at 6:42 PM, Steven D'Aprano wrote: >>> Who is responding or has responded? >>> Extreme Programmers, Python-Hardliner, Python-Evangelists, ... . >>> Presumably no core Python Programmers (wrting compiler and standard >>> library stuff) >> >> Ad hominem. > > For the record, I am the author of the statistics module in Python 3.4, and > Terry Reedy is the very active maintainer of IDLE. If I have missed anyone, > my apologies. So, yes, there are core developers here. > > (Although not any of the senior core devs, as far as I know.) I don't know what the definition of "senior core dev" would be. Checking the Experts List [1] shows you and Terry both, as does the list of committers [2] (and it has me as well, although that's because I wear a PEP Editor hat, so I don't count as even a non-senior core dev). Is there an "inner circle" of people Guido trusts more than "just ordinary core devs"? I rather suspect not, but maybe I'm wrong. Hacking on CPython without core dev status is actually pretty easy. I've done it. (Added a "while ... as name:" syntax, just to see how hard it would be. Conclusion: It's not hard at all.) If anything, that's a _lower_ bar to clear than "idiomatic Python programmer", because anyone can hack on C code without understanding the goals and beauties of the Python language. So I'm really not sure what the original complaint was about, nor how to answer it. ChrisA [1] https://docs.python.org/devguide/experts.html#experts [2] https://hg.python.org/committers.txt From antoon.pardon at rece.vub.ac.be Fri Sep 11 06:19:45 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 11 Sep 2015 12:19:45 +0200 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> <1441902711.3168172.380049449.32E41922@webmail.messagingengine.com> Message-ID: <55F2AAC1.5030902@rece.vub.ac.be> Op 10-09-15 om 18:48 schreef Chris Angelico: > I'm not sure what the point would be of having an expression that > doesn't return a value. The point of assignment-as-an-expression is > that you can do other things with the result: > > while ((ch=getchar()) != EOF) > > In Python, we have a couple of cases where that's done with the 'as' keyword: > > with open(fn) as in_file: > > except KeyError as e: > > and there've been proposals now and then to have the same thing added > to if and while, which actually isn't hard: > > while getchar() as ch: I just don't get why people want to introduce special cases in python. Why allow such a construct only in while and if? Why not just allow it generally as an assignment expression? Why not allow: while (f(x) as fx) > 5: proces(fx) or if check(nextvalue() as new): treat(new) One of the things I don't like about python is the limitation of the slice syntax. I have been in situations where the natural thing to do was write a method that takes a slice as a parameter and have it called like: for key, value in Tree.items(lowkey:highkey). But that doesn't work because slice notation is only allowed in a subscription context. It is kind of frustrating when you see something in the language you think useful, to then notice the language doesn't allow you to use in the context you need/want it. At this moment I feel that introducing the "as v" possibily only in while and if statements would mainly enlargen my frustration. -- Antoon Pardon From marko at pacujo.net Fri Sep 11 07:59:20 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 11 Sep 2015 14:59:20 +0300 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> <1441902711.3168172.380049449.32E41922@webmail.messagingengine.com> Message-ID: <87pp1pqi93.fsf@elektro.pacujo.net> Antoon Pardon : > I just don't get why people want to introduce special cases in python. > Why allow such a construct only in while and if? Why not just allow > it generally as an assignment expression? > > Why not allow: > > while (f(x) as fx) > 5: > proces(fx) > > or > > if check(nextvalue() as new): > treat(new) Hey, I know, I know!... Let's allow: while (fx = f(x)) > 5: process(fx) if check(new = nextvalue()): treat(new) Seriously, though, I share your distaste of special cases, Antoon. Only I don't like too much syntax (just look at Perl). There's nothing wrong in: while True: fx = f(x) if fx <= 5: break process(fx) new = nextvalue() if check(new): treat(new) Marko From random832 at fastmail.us Fri Sep 11 08:50:50 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 11 Sep 2015 08:50:50 -0400 Subject: Python handles globals badly. In-Reply-To: <55F28297.8080104@rece.vub.ac.be> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F130CE.5060203@rece.vub.ac.be> <55F191CD.8040901@gmail.com> <55F28297.8080104@rece.vub.ac.be> Message-ID: <1441975850.3461843.380835001.166C9086@webmail.messagingengine.com> On Fri, Sep 11, 2015, at 03:28, Antoon Pardon wrote: > The error is also facilitated because C doesn't have booleans > and so everything can be used as one. Python does have booleans and everything can be used as one - the logical conclusion is that being able to use everything as a boolean is a positive feature that has nothing to do with lacking a "proper" boolean type. From lac at openend.se Fri Sep 11 09:41:50 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 11 Sep 2015 15:41:50 +0200 Subject: numpy In-Reply-To: <55F23DFD.5020608@inhand.com.cn> References: <55F1573C.8060807@inhand.com.cn> <201509101605.t8AG5orl024197@fido.openend.se> <55F23DFD.5020608@inhand.com.cn> Message-ID: <201509111341.t8BDfoT5020599@fido.openend.se> In a message of Fri, 11 Sep 2015 10:35:41 +0800, "chenchao at inhand.com.cn" write s: >hi, Laura: > My embedded arm device supports floating point operation. I >have to use numpy and pandas packages. But now, I do not known how to >cross compile numpy and pandas packages? You are going to have to ask this one here: http://mail.scipy.org/mailman/listinfo/numpy-discussion I do not know anybody who has got this to work yet, but if somebody has, the people there will know. Laura From lac at openend.se Fri Sep 11 09:49:49 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 11 Sep 2015 15:49:49 +0200 Subject: subdividing a rectangle using numpy In-Reply-To: <87k2rxy7to.fsf@gmail.com> References: <87k2rxy7to.fsf@gmail.com> Message-ID: <201509111349.t8BDnnbO022689@fido.openend.se> I think pyeuclid will do what you want. https://pypi.python.org/pypi/euclid Laura From invalid at invalid.invalid Fri Sep 11 09:50:04 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 11 Sep 2015 13:50:04 +0000 (UTC) Subject: Signal SIGINT ignored during socket.accept References: Message-ID: On 2015-09-11, Chris Angelico wrote: > This is what I meant when I said you would be polling. Effectively, > you wake up your program every half-second, check if Ctrl-C has been > pressed, and if it hasn't, you go back to sleep again. This is pretty > inefficient. Though it offends one's engineering sensibilities[1], it's just not that inefficient. I'd bet money you won't even be able to measure the difference in CPU usage. Waking up twice per second and immediately calling select() again on any hardware/OS built in the past 50 years is going completely negligible (as long as you can ignore the smell). Even waking up ten times per second won't be noticeable. Waking up every millisecond or two might be noticeable. > Stupid Windows. Agreed. [1] If offenses to engineering sensibility were of concern, then he wouldn't be using Windows in the first place. ;) -- Grant Edwards grant.b.edwards Yow! PIZZA!! at gmail.com From marko at pacujo.net Fri Sep 11 10:00:30 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 11 Sep 2015 17:00:30 +0300 Subject: Signal SIGINT ignored during socket.accept References: Message-ID: <87k2rxqcn5.fsf@elektro.pacujo.net> Grant Edwards : > On 2015-09-11, Chris Angelico wrote: >> This is what I meant when I said you would be polling. Effectively, >> you wake up your program every half-second, check if Ctrl-C has been >> pressed, and if it hasn't, you go back to sleep again. This is pretty >> inefficient. > > Though it offends one's engineering sensibilities[1], it's just not > that inefficient. I'd bet money you won't even be able to measure the > difference in CPU usage. Waking up twice per second and immediately > calling select() again on any hardware/OS built in the past 50 years > is going completely negligible (as long as you can ignore the smell). > > Even waking up ten times per second won't be noticeable. > > Waking up every millisecond or two might be noticeable. It can add up. In particular, it can prevent the CPU from staying in the low-power mode, especially on battery-powered devices. Another environment where such polling circuses can actually overwhelm a CPU is virtual machines. When dozens or hundreds of VMs are each polling left and right, the host may not get much actual work done. Marko From rosuav at gmail.com Fri Sep 11 10:27:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Sep 2015 00:27:43 +1000 Subject: Signal SIGINT ignored during socket.accept In-Reply-To: References: Message-ID: On Fri, Sep 11, 2015 at 11:50 PM, Grant Edwards wrote: > On 2015-09-11, Chris Angelico wrote: > >> This is what I meant when I said you would be polling. Effectively, >> you wake up your program every half-second, check if Ctrl-C has been >> pressed, and if it hasn't, you go back to sleep again. This is pretty >> inefficient. > > Though it offends one's engineering sensibilities[1], it's just not > that inefficient. I'd bet money you won't even be able to measure the > difference in CPU usage. Waking up twice per second and immediately > calling select() again on any hardware/OS built in the past 50 years > is going completely negligible (as long as you can ignore the smell). > > Even waking up ten times per second won't be noticeable. > True (although, as Marko says, it can add up). The other difference, though, is that I like to keep "cope-with-stupidity" code to itself - ideally, the clean path shouldn't be infected with it. Waking up periodically with select(), when you otherwise just want a blocking accept(), affects all your code. Spinning off a thread that monitors stdin and signals the main thread when it's time to shut down can be kept to a single block of code, guarded by some sort of platform check: import socket PORT = 8880 mainsock = socket.socket() mainsock.bind(("", PORT)) mainsock.listen(1) if Windows: # however you want to go about checking this import threading # Python 2/3 compat try: input = raw_input except NameError: pass def console(): """Constantly read from stdin and discard""" try: while "moar console": input() except (KeyboardInterrupt, EOFError): socket.socket().connect(("127.0.0.1",PORT)) threading.Thread(target=console).start() while "moar sockets": s = mainsock.accept() print("New connection: %r" % s) # Do whatever you want with the connection s.close() As well as keeping the Unix variant stupidity-free, this allows you to vary your platform check in the event that a future version of Windows allows blocking calls to be interrupted. Or if a future version of Python implements this kind of check globally. Or if a Python built with Cygwin doesn't exhibit this behaviour. Or if PyPy... you get the idea. The clean path is clearly delineated, and hopefully, the complexity of your code will increase linearly with the number of problems you're coping with, rather than having each patch affect each other. ChrisA From ian.g.kelly at gmail.com Fri Sep 11 11:03:41 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 11 Sep 2015 09:03:41 -0600 Subject: Python handles globals badly. In-Reply-To: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 11, 2015 at 2:42 AM, Steven D'Aprano wrote: > On Fri, 11 Sep 2015 10:35 am, Ian Kelly wrote: > >> On Thu, Sep 10, 2015 at 4:25 PM, wrote: > [...] >>> So the compiler knows the distiction between global and local already. >> >> As we've said before, it doesn't. The compiler's current rules are >> fairly simple: >> >> 1) If it's in the function's argument list, it's an argument (and >> therefore local). >> 2) If it's explicitly declared global, then it's global. >> 3) If it's never assigned within the function, then it's global. > > Almost. If it's never assigned within the function, then it is looked up > according to the non-local scoping rules: > > - closures and enclosing functions (if any); > - globals; > - builtins; > > in that order. I excluded non-locals intentionally, but if you want to be pedantic about it, then that's still not quite right. Non-locals are indeed identified by the compiler and compiled with the LOAD_DEREF/STORE_DEREF opcodes (rather than the _GLOBAL and _FAST variants used by globals and locals, respectively). The compiler doesn't make any such distinction between globals and builtins however, as that can only be determined at run-time. > There's also a bunch of specialised and complicated rules for what happens > if you make a star import ("from module import *") inside a function, or > call eval or exec without specifying a namespace. Both of these things are > now illegal in Python 3. Huh? >>> exec("x = 42") >>> x 42 >>> exec("x = 43", None, None) >>> x 43 That's in Python 3.4.0. Maybe I don't understand what you mean by "without specifying a namespace". From rosuav at gmail.com Fri Sep 11 11:15:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Sep 2015 01:15:14 +1000 Subject: Python handles globals badly. In-Reply-To: References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 12, 2015 at 1:03 AM, Ian Kelly wrote: >> There's also a bunch of specialised and complicated rules for what happens >> if you make a star import ("from module import *") inside a function, or >> call eval or exec without specifying a namespace. Both of these things are >> now illegal in Python 3. > > Huh? > >>>> exec("x = 42") >>>> x > 42 >>>> exec("x = 43", None, None) >>>> x > 43 > > That's in Python 3.4.0. Maybe I don't understand what you mean by > "without specifying a namespace". *inside a function* >>> def f(): ... exec("x = 42") ... print(x) ... >>> x = 231 >>> f() 231 ChrisA From ian.g.kelly at gmail.com Fri Sep 11 11:27:10 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 11 Sep 2015 09:27:10 -0600 Subject: Python handles globals badly. In-Reply-To: References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 11, 2015 at 9:15 AM, Chris Angelico wrote: > On Sat, Sep 12, 2015 at 1:03 AM, Ian Kelly wrote: >>> There's also a bunch of specialised and complicated rules for what happens >>> if you make a star import ("from module import *") inside a function, or >>> call eval or exec without specifying a namespace. Both of these things are >>> now illegal in Python 3. >> >> Huh? >> >>>>> exec("x = 42") >>>>> x >> 42 >>>>> exec("x = 43", None, None) >>>>> x >> 43 >> >> That's in Python 3.4.0. Maybe I don't understand what you mean by >> "without specifying a namespace". > > *inside a function* > >>>> def f(): > ... exec("x = 42") > ... print(x) > ... >>>> x = 231 >>>> f() > 231 Ah, I didn't parse the "inside a function" as applying to that clause, but even so, I don't see in what way that is "now illegal". For example: >>> x = 231 >>> def f(): ... exec("print(x); x = 42; print(x)") ... print(x) ... >>> f() 231 42 231 The exec still happily runs; it's just using its own private locals namespace. Tangent: does the help for exec need to be updated? It currently reads: The globals and locals are dictionaries, defaulting to the current globals and locals. If only globals is given, locals defaults to it. Which would seem to indicate that if called from within a function with no globals or locals, the locals from the function would be used. From rosuav at gmail.com Fri Sep 11 11:44:17 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Sep 2015 01:44:17 +1000 Subject: Python handles globals badly. In-Reply-To: References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 12, 2015 at 1:27 AM, Ian Kelly wrote: > The exec still happily runs; it's just using its own private locals namespace. > > Tangent: does the help for exec need to be updated? It currently reads: > > The globals and locals are dictionaries, defaulting to the current > globals and locals. If only globals is given, locals defaults to it. > > Which would seem to indicate that if called from within a function > with no globals or locals, the locals from the function would be used. And that's the thing... I think. It's using locals(), which starts out as a copy of the function's locals (in this example, empty), but without assignment affecting anything. Which is more than a little weird: >>> def f(): ... x = [1] ... exec("print(x); x[0] = 2; print(x); x = [3]; print(x)") ... print(x) ... >>> f() [1] [2] [3] [2] It's kinda like how globals can shadow builtins, I think. Maybe. Except that you can't del the name inside exec to unshadow and go back to the outer version of it. ChrisA From ian.g.kelly at gmail.com Fri Sep 11 11:49:47 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 11 Sep 2015 09:49:47 -0600 Subject: Python handles globals badly. In-Reply-To: References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 11, 2015 at 9:44 AM, Chris Angelico wrote: > On Sat, Sep 12, 2015 at 1:27 AM, Ian Kelly wrote: >> The exec still happily runs; it's just using its own private locals namespace. >> >> Tangent: does the help for exec need to be updated? It currently reads: >> >> The globals and locals are dictionaries, defaulting to the current >> globals and locals. If only globals is given, locals defaults to it. >> >> Which would seem to indicate that if called from within a function >> with no globals or locals, the locals from the function would be used. > > And that's the thing... I think. It's using locals(), which starts out > as a copy of the function's locals (in this example, empty), but > without assignment affecting anything. Which is more than a little > weird: > >>>> def f(): > ... x = [1] > ... exec("print(x); x[0] = 2; print(x); x = [3]; print(x)") > ... print(x) > ... >>>> f() > [1] > [2] > [3] > [2] Ah, that makes sense. It's writing into the dict that is created and returned by locals(), but not actually updating the frame locals which are the source of truth. From rosuav at gmail.com Fri Sep 11 11:55:28 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Sep 2015 01:55:28 +1000 Subject: Python handles globals badly. In-Reply-To: References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 12, 2015 at 1:49 AM, Ian Kelly wrote: >> And that's the thing... I think. It's using locals(), which starts out >> as a copy of the function's locals (in this example, empty), but >> without assignment affecting anything. Which is more than a little >> weird: >> >>>>> def f(): >> ... x = [1] >> ... exec("print(x); x[0] = 2; print(x); x = [3]; print(x)") >> ... print(x) >> ... >>>>> f() >> [1] >> [2] >> [3] >> [2] > > Ah, that makes sense. It's writing into the dict that is created and > returned by locals(), but not actually updating the frame locals which > are the source of truth. Yeah... but it only makes sense to people who understand the implementation. It's certainly not a logical and sane behaviour that would be worth documenting and using. ChrisA From rustompmody at gmail.com Fri Sep 11 11:55:44 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 11 Sep 2015 08:55:44 -0700 (PDT) Subject: Context-aware return In-Reply-To: References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, September 11, 2015 at 12:53:28 AM UTC+5:30, Grant Edwards wrote: > On 2015-09-10, Steven D'Aprano wrote: > > > I have a function which is intended for use at the interactive interpreter, > > but may sometimes be used non-interactively. I wish to change it's output > > depending on the context of how it is being called. > > [...] > > Sounds like an excellent way to waste somebody's afternoon when they > start to troubleshoot code that's using your function. Over and over > and over we tell newbies who have questions about what something > returns or how it works > > "Start up an interactive session, and try it!". > > If word gets out about functions like yours, we sort of end up looking > like twits. > > > If I did this thing, would people follow me down the street booing > > and jeering and throwing things at me? > > Only the people who use your function. :) In emacs: You can make a function a 'command' by putting an (interactive) into it. And then in the function if you check interactive-p (nowadays more fashionably 'called-interactively-p' ) then it can figure out whether it was called from elisp or from emacs (top level)... and then change behavior accordingly. IOW this behavior is quite routine in emacs-land The norm being - Some functions are meant to be called only from Lisp - Some functions (commands) only from emacs - And then there are the 'Steven-functions' I find it curious that the people getting upset about this are all the emacs users [as far as I know] ;-) From rustompmody at gmail.com Fri Sep 11 11:55:50 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 11 Sep 2015 08:55:50 -0700 (PDT) Subject: Context-aware return In-Reply-To: References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: <79f7cf3b-b656-4a3b-9dba-d86e2b797700@googlegroups.com> On Friday, September 11, 2015 at 12:53:28 AM UTC+5:30, Grant Edwards wrote: > On 2015-09-10, Steven D'Aprano wrote: > > > I have a function which is intended for use at the interactive interpreter, > > but may sometimes be used non-interactively. I wish to change it's output > > depending on the context of how it is being called. > > [...] > > Sounds like an excellent way to waste somebody's afternoon when they > start to troubleshoot code that's using your function. Over and over > and over we tell newbies who have questions about what something > returns or how it works > > "Start up an interactive session, and try it!". > > If word gets out about functions like yours, we sort of end up looking > like twits. > > > If I did this thing, would people follow me down the street booing > > and jeering and throwing things at me? > > Only the people who use your function. :) In emacs: You can make a function a 'command' by putting an (interactive) into it. And then in the function if you check interactive-p (nowadays more fashionably 'called-interactively-p' ) then it can figure out whether it was called from elisp or from emacs (top level)... and then change behavior accordingly. IOW this behavior is quite routine in emacs-land The norm being - Some functions are meant to be called only from Lisp - Some functions (commands) only from emacs - And then there are the 'Steven-functions' I find it curious that the people getting upset about this are all the emacs users [as far as I know] ;-) From random832 at fastmail.us Fri Sep 11 11:57:32 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 11 Sep 2015 11:57:32 -0400 Subject: Python handles globals badly. In-Reply-To: References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1441987052.3506145.381042489.570191F2@webmail.messagingengine.com> On Fri, Sep 11, 2015, at 11:55, Chris Angelico wrote: > On Sat, Sep 12, 2015 at 1:49 AM, Ian Kelly wrote: > > Ah, that makes sense. It's writing into the dict that is created and > > returned by locals(), but not actually updating the frame locals which > > are the source of truth. > > Yeah... but it only makes sense to people who understand the > implementation. It's certainly not a logical and sane behaviour that > would be worth documenting and using. What else would you document? Reading from them is a reasonable thing to do, and works. Writing to them is a reasonable thing to want to do, but won't work, so you need to document that it doesn't work. From rosuav at gmail.com Fri Sep 11 12:04:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Sep 2015 02:04:21 +1000 Subject: Python handles globals badly. In-Reply-To: <1441987052.3506145.381042489.570191F2@webmail.messagingengine.com> References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> <1441987052.3506145.381042489.570191F2@webmail.messagingengine.com> Message-ID: On Sat, Sep 12, 2015 at 1:57 AM, wrote: > On Fri, Sep 11, 2015, at 11:55, Chris Angelico wrote: >> On Sat, Sep 12, 2015 at 1:49 AM, Ian Kelly wrote: >> > Ah, that makes sense. It's writing into the dict that is created and >> > returned by locals(), but not actually updating the frame locals which >> > are the source of truth. >> >> Yeah... but it only makes sense to people who understand the >> implementation. It's certainly not a logical and sane behaviour that >> would be worth documenting and using. > > What else would you document? Reading from them is a reasonable thing to > do, and works. Writing to them is a reasonable thing to want to do, but > won't work, so you need to document that it doesn't work. Documenting that "it doesn't work" seems fine. Documenting the specific behaviour (that it gives you a sort of "shadow" locals, into which you can write, but which won't persist past the execution of that block of code) seems pointless. Especially since this behaviour is implementation-dependent anyway. ChrisA From rustompmody at gmail.com Fri Sep 11 12:08:24 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 11 Sep 2015 09:08:24 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: <81f15401-eefd-487b-a695-60fbf2a98a29@googlegroups.com> On Friday, September 11, 2015 at 9:27:46 PM UTC+5:30, rand... at fastmail.us wrote: > On Fri, Sep 11, 2015, at 11:55, Chris Angelico wrote: > > On Sat, Sep 12, 2015 at 1:49 AM, Ian Kelly wrote: > > > Ah, that makes sense. It's writing into the dict that is created and > > > returned by locals(), but not actually updating the frame locals which > > > are the source of truth. > > > > Yeah... but it only makes sense to people who understand the > > implementation. It's certainly not a logical and sane behaviour that > > would be worth documenting and using. > > What else would you document? Reading from them is a reasonable thing to > do, and works. Writing to them is a reasonable thing to want to do, but > won't work, so you need to document that it doesn't work. This is actually an old elusive holy grail -- first class environments. In denotational semantics the two tools used to model variables and control-flow respectively are environments and continuations. The Scheme inventors were brave enough to mandate first-class continuations but could not make the courage for first-class environments. So every Scheme dialect introduces 1? class envs in a ?-assed inconsistent way Likewise python's locals-dicts and (I am guessing) most languages with some commitment to first-classness From ian.g.kelly at gmail.com Fri Sep 11 12:27:57 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 11 Sep 2015 10:27:57 -0600 Subject: Python handles globals badly. In-Reply-To: References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> <1441987052.3506145.381042489.570191F2@webmail.messagingengine.com> Message-ID: On Fri, Sep 11, 2015 at 10:04 AM, Chris Angelico wrote: > On Sat, Sep 12, 2015 at 1:57 AM, wrote: >> On Fri, Sep 11, 2015, at 11:55, Chris Angelico wrote: >>> On Sat, Sep 12, 2015 at 1:49 AM, Ian Kelly wrote: >>> > Ah, that makes sense. It's writing into the dict that is created and >>> > returned by locals(), but not actually updating the frame locals which >>> > are the source of truth. >>> >>> Yeah... but it only makes sense to people who understand the >>> implementation. It's certainly not a logical and sane behaviour that >>> would be worth documenting and using. >> >> What else would you document? Reading from them is a reasonable thing to >> do, and works. Writing to them is a reasonable thing to want to do, but >> won't work, so you need to document that it doesn't work. > > Documenting that "it doesn't work" seems fine. Documenting the > specific behaviour (that it gives you a sort of "shadow" locals, into > which you can write, but which won't persist past the execution of > that block of code) seems pointless. Especially since this behaviour > is implementation-dependent anyway. It's documented in the standard library docs: https://docs.python.org/3.4/library/functions.html#exec I think that's probably sufficient. From cl at isbd.net Fri Sep 11 12:33:32 2015 From: cl at isbd.net (cl at isbd.net) Date: Fri, 11 Sep 2015 17:33:32 +0100 Subject: Problem with handling errors in POP3 message retrieval/deletion Message-ID: I have a (fairly) simple script that does 'catchall' processing on my POP3 mailbox. It looks for messages To: strings that *might* be for me and then throws everything else away. I was getting the occasional error as follows:- Traceback (most recent call last): File "/home/chris/.mutt/bin/getCatchall.py", line 59, in popmsg = pop3.retr(i+1) File "/usr/lib/python2.7/poplib.py", line 232, in retr return self._longcmd('RETR %s' % which) File "/usr/lib/python2.7/poplib.py", line 167, in _longcmd return self._getlongresp() File "/usr/lib/python2.7/poplib.py", line 152, in _getlongresp line, o = self._getline() File "/usr/lib/python2.7/poplib.py", line 377, in _getline raise error_proto('line too long') poplib.error_proto: line too long So I added a try/except round the pop3.retr() and now I get this error:- Traceback (most recent call last): File "/home/chris/.mutt/bin/getCatchall.py", line 63, in x = pop3.dele(i+1) File "/usr/lib/python2.7/poplib.py", line 240, in dele return self._shortcmd('DELE %s' % which) File "/usr/lib/python2.7/poplib.py", line 160, in _shortcmd return self._getresp() File "/usr/lib/python2.7/poplib.py", line 136, in _getresp raise error_proto(resp) poplib.error_proto: Data Base /Diamond /Arm /Freeway /Pocket /Barbecue /Bathroom /Eyes /Train /Hat /Planet /Web /Girl /Surveyor /Rocket /Slave /Software /Vampire /Vacuum /Sun /Egg /Leg /Ice /Guitar /Post-office /Pepper /Hat /Eartupletters:10,50: AAMGQLMUHSMCCVXEOPQRDWUSFEJFSHPEAQWHh /Spiral /Garden /Tennis racquet /Banana /Spectrum /Bed /Fruit /Earth /Wheelchair /Spoon /Bee /Highway /God /Guitar /Sandpaper /Typewriter /Finger /Feather /Salt /Electricity /Pants /Sphere /Table /Comet / /Bee /Button /Map /Data Base /Hieroglyph /Carpet /Hose /Bank /Fire /Solid /Staircase /Eyes /Rope /School /Onion /Barbecue /Gemstone /Ice-cream /Nail /Alphabet /Feather /Compass /Bottle /Shop /Fruit /Map /Sphere /Coffee /Radar /Tongue /Tapestry /Radar /Sandwich /Circus /Spectrum /Aeroplane /Clock /Room /Stomach /Snail / Satellite /Worm /Money $$$$ /Bed /Pyramid /Boy /Pepper /Fruit /Junk /Bank /Bird /Pebble /Chair /Microscope /Satellite /Woman /Kaleidoscope /Perfume /Triangle /Sunglasses /Needle /Thermometer /Freeway /Man /Mist upletters:10,50: TQDPDUGSMYEPJGBPYCTEIKMNFXKCSNDY/Vulture /Thermometer /Treadmill /Pillow /Hose /Necklace /Coffee-shop /Space Shuttle /Pyramid /Rope /Surveyor /Spot Light /Nail /Bed /Mist /Sandwich /Family /Salt /Fan /Air /Maze /Mouth /Vacuum /Tongue /Bible /Gate /Wheelchair /Jet fighter /Bible /Tunnel /Navy /Festival /Shop /Tapestry /Shower /Cappuccino /Sandpaper /PaintBrush /Prison /Sex /Church /Man /Meat /Ring /Snail /Floodlight /Toilet /Shower /Computer /Tiger /Diamond /Bathroom /Boss /Leather jacket /Dress /Ship /Finger /Torpedo /Car /Compass /Water /Mist /Butterfly /Staircase /Child /Backpack /Umbrella /Tiger /School /Explosive /Restaurant /Bird /Cycle /Television /Cappuccino /Bible /Kaleidoscope /Drill /Church /Television /Hieroglyph /Game /Fungus /Sword /Gloves /Highway /Box functon /2022 /browser /cowritten /livinglogic /ione /800 /susceptibles /psz Can anyone make any suggestions as to how to overcome this issue, all I want to do is throw away the offending message. The code for the whole thing is as follows:- #!/usr/bin/python # # # Collect E-Mail from my catchall POP3 mailbox on tsohost, deliver anything # that looks remotely useful and bin the rest # # import getpass, poplib import email import mailbox import string import smtplib import time import mailLib home = "/home/chris" log = mailLib.initLog("getCatchall") # # # Read the filter file # fltr = {} f = open(home + "/.mutt/getCatchall.filter", 'r') for ln in f: # for each line in filter if ln[0] == '#': # ignore comments continue # # # split the line into fields and store in a dictionary # fld = ln.split() fltr[fld[0]] = fld[1] # # # Process the messages, do a maximum of 100 at a time # while (1): # # # Connect to the POP3 server, get message count, exit if no messages # pop3 = poplib.POP3_SSL('pop.isbd.net') pop3.user('catchall at isbd.net') pop3.pass_('XXXXXXXX') numMessages = len(pop3.list()[1]) if (numMessages == 0): break # # # Process a maximum of 100 messages # log.info(str(numMessages) + " messages") for i in range(min(numMessages, 100)): # # # Read each message into a string and then parse with the email module, if # there's an error retrieving the message then just throw it away # try: popmsg = pop3.retr(i+1) except: pop3.dele(i+1) continue log.info("Retrieved message number " + str(i+1)) msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list containing the lines of the message msg = mailbox.mboxMessage(msgstr) # # # Look for names from the filter file in To: and Cc:, deliver message if possibly relevant # for nm, dest in fltr.items(): if (msg.get("To","unknown").find(nm) >= 0) or (msg.get("Cc", "unknown").find(nm) >= 0): log.info( "Sending message, Subject: " + msg.get("Subject", "No subject") + ", To: " + dest) if '@' in dest: try: # # # Connect to the SMTP server and send the message # smtp = smtplib.SMTP('smtp.isbd.net') smtp.login("catchall at isbd.net", "XXXXXXXX") smtp.sendmail("catchall at isbd.net", dest, msgstr) smtp.quit() except: # # # If the message can't be sent then give it to me locally # mailLib.deliverMboxMsg(dest, msg, log) else: # # # Put message in local mbox # mailLib.deliverMboxMsg(dest, msg, log) break # # # delete the message from the POP3 mailbox # log.info("Deleting message " + msg.get("To","unknown")) pop3.dele(i+1) # # # disconnect, only when this is done do the POP3 messages actually disappear # pop3.quit() # # # Exit if no more messages (the normal case) otherwise wait a minute before # processing any more, otherwise we get zombie messages which # cause "poplib.error_proto: -ERR Can't open the message file - it's gone!" # if (numMessages > 100): time.sleep(60) else: break -- Chris Green ? From zxcvbm4 at gmail.com Fri Sep 11 12:52:55 2015 From: zxcvbm4 at gmail.com (Wannaphong) Date: Fri, 11 Sep 2015 09:52:55 -0700 (PDT) Subject: Windows mingw64 compile pthon module error Message-ID: <104d8243-9f43-4162-9a30-12f3b505c6bf@googlegroups.com> I using Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AM D64)] on win32. I install tdm64-gcc-5-1-0.exe. I setting from https://stackoverflow.com/a/27506457 , but I using "pip install scandir". ------------------------ C:\TDM-GCC-64\bin\x86_64-w64-mingw32-gcc.exe -shared -s build\temp.win-amd64 -3.4\Release\_scandir.o build\temp.win-amd64-3.4\Release\_scandir.def -LC:\py34\ libs -LC:\py34\PCbuild\amd64 -lpython34 -o build\lib.win-amd64-3.4\_scandir.pyd C:\py34\libs/python34.lib: error adding symbols: File in wrong format collect2.exe: error: ld returned 1 exit status error: command 'C:\\TDM-GCC-64\\bin\\x86_64-w64-mingw32-gcc.exe' failed with exit status 1 ---------------------------------------- Command "C:\py34\python.exe -c "import setuptools, tokenize;__file__='C:\\Us ers\\B15D~1\\AppData\\Local\\Temp\\pip-build-vnnkz86l\\scandir\\setup.py';exec(c ompile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), _ _file__, 'exec'))" install --record C:\Users\B15D~1\AppData\Local\Temp\pip-hhbfw 636-record\install-record.txt --single-version-externally-managed --compile" fai led with error code 1 in C:\Users\B15D~1\AppData\Local\Temp\pip-build-vnnkz86l\s candir ------------------------ I apologize here. I am not good in English. Thank you. From cl at isbd.net Fri Sep 11 13:13:06 2015 From: cl at isbd.net (cl at isbd.net) Date: Fri, 11 Sep 2015 18:13:06 +0100 Subject: Problem with handling errors in POP3 message retrieval/deletion References: Message-ID: <2mebcc-406.ln1@esprimo.zbmc.eu> cl at isbd.net wrote: > I have a (fairly) simple script that does 'catchall' processing on my > POP3 mailbox. It looks for messages To: strings that *might* be for > me and then throws everything else away. > [snip] Sorry folks, I found the problem, it's a known 'bug' due to someone trying to protect poplib from excessively long lines. See:- https://bugs.python.org/issue16041 It's easy to work around by something like:- import poplib poplib._MAXLINE=20480 -- Chris Green ? From james.harris.1 at gmail.com Fri Sep 11 13:14:20 2015 From: james.harris.1 at gmail.com (James Harris) Date: Fri, 11 Sep 2015 18:14:20 +0100 Subject: Signal SIGINT ignored during socket.accept References: Message-ID: "Grant Edwards" wrote in message news:msum6c$hv$1 at reader1.panix.com... > On 2015-09-11, Chris Angelico wrote: > >> This is what I meant when I said you would be polling. Effectively, >> you wake up your program every half-second, check if Ctrl-C has been >> pressed, and if it hasn't, you go back to sleep again. This is pretty >> inefficient. > > Though it offends one's engineering sensibilities[1], it's just not > that inefficient. Indeed. > I'd bet money you won't even be able to measure the > difference in CPU usage. You would win your bet. > Waking up twice per second and immediately > calling select() again on any hardware/OS built in the past 50 years > is going completely negligible (as long as you can ignore the smell). CPU usage is not the only issue but it is a consideration. I tested it before posting the code and couldn't see any significant increase in CPU use. To give it a better test I have just left running for a couple of hours or so. I am pleased to say it currently reports a cumulative total of 0:00:00, i.e. it has not clocked up even a second of CPU time yet! ... > [1] If offenses to engineering sensibility were of concern, then > he wouldn't be using Windows in the first place. ;) LOL. I know that's tongue in cheek but I tend to favour portability over most other things. So running on Windows as well as Unix is, in my book, a Good Thing. James From davros at bellaliant.net Fri Sep 11 14:24:53 2015 From: davros at bellaliant.net (John McKenzie) Date: Fri, 11 Sep 2015 18:24:53 GMT Subject: RPI.GPIO Help References: Message-ID: Hello. Thanks to the help of people here and in other newsgroups I seem to have something working doing the basics. (Buttons work, colours light up appropriately.) When I followed MRAB's instructions and read about scopes of variables that solved my most recent problem, but it introduced a bug. I think I fixed the bug but after all my stupid mistakes and forgetfulness that seems too good to be true. I expect there is a better, more elegant, or more Pythonic way to do what I did so please feel free to share on the subject. I had a problem where if I pressed a button while the LEDs were already flashing the colour of that button it would block a new colour from starting when I pressed a new button. So if the LED strip was red and I pressed the red button again nothing would happen when I pressed the blue or yellow button. Similar problem for the other two buttons. So inside my callbacks I added this code: if colour == 1: pass elif colour == 2 or 3: colour = 1 Now it seems OK from my limited testing. Here is the code that has buttons and colours working and includes my bug fix: import atexit import time from blinkstick import blinkstick import RPi.GPIO as GPIO led = blinkstick.find_first() colour = 0 time_red = 0 time_yellow = 0 time_blue = 0 timestamp = time.strftime("%H:%M:%S") GPIO.setmode(GPIO.BCM) GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) def red_button(channel): global colour if colour == 1: pass elif colour == 2 or 3: colour = 1 while colour == 1: led.pulse(red=255, green=0, blue=0, repeats=1, duration=2000, steps=50) def yellow_button(channel): global colour if colour == 2: pass elif colour == 1 or 3: colour = 2 while colour == 2: led.pulse(red=255, green=96, blue=0, repeats=1, duration=2000, steps=50) def blue_button(channel): global colour if colour == 3: pass elif colour == 1 or 2: colour = 3 while colour == 3: led.pulse(red=0, green=0, blue=255, repeats=1, duration=2000, steps=50) GPIO.add_event_detect(22, GPIO.FALLING, callback=red_button, bouncetime=200) GPIO.add_event_detect(23, GPIO.FALLING, callback=yellow_button, bouncetime=200) GPIO.add_event_detect(24, GPIO.FALLING, callback=blue_button, bouncetime=200) while True: if colour == 1: time_red += 1 elif colour == 2: time_yellow += 1 elif colour == 3: time_blue += 1 time.sleep(0.1) def exit_handler(): print "\033[0;41;37mRed Team:\033[0m ", time_red print "\033[0;43;30mYellow Time:\033[0m ", time_yellow print "\033[0;44;37mBlue Time:\033[0m ", time_blue flog = open("flag1.log", "a") flog.write(timestamp + "\n" + "Red Team: " + str(time_red) + "\n" + "Yellow Team: " + str(time_yellow) + "\n" + "Blue Team: " + str (time_blue) + "\n") flog.close() led.set_color(name="black") atexit.register(exit_handler) GPIO.cleanup() I think I am OK GPIO wise now, although always happy to improve the code and in the long term I want to do so. Will start new threads for more straight forward Python questions like help with saving a log of the results, timing, etc. Thanks for your help, everyone. From python at mrabarnett.plus.com Fri Sep 11 14:49:15 2015 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 11 Sep 2015 19:49:15 +0100 Subject: RPI.GPIO Help In-Reply-To: References: Message-ID: <55F3222B.2060509@mrabarnett.plus.com> On 2015-09-11 19:24, John McKenzie wrote: > > Hello. > > Thanks to the help of people here and in other newsgroups I seem to have > something working doing the basics. (Buttons work, colours light up > appropriately.) > > When I followed MRAB's instructions and read about scopes of variables > that solved my most recent problem, but it introduced a bug. I think I > fixed the bug but after all my stupid mistakes and forgetfulness that > seems too good to be true. I expect there is a better, more elegant, or > more Pythonic way to do what I did so please feel free to share on the > subject. > > I had a problem where if I pressed a button while the LEDs were already > flashing the colour of that button it would block a new colour from > starting when I pressed a new button. So if the LED strip was red and I > pressed the red button again nothing would happen when I pressed the blue > or yellow button. Similar problem for the other two buttons. > > So inside my callbacks I added this code: > > if colour == 1: > pass > elif colour == 2 or 3: > colour = 1 > > > Now it seems OK from my limited testing. > [snip] "colour == 2 or 3" means the same as "(colour == 2) or 3", where 3 is a true value (zero is a false value; any non-zero number is a true value). What you mean is "colour == 2 or colour == 3". A shorter alternative is "colour in (2, 3)". From hakugin.gin at gmail.com Fri Sep 11 15:00:55 2015 From: hakugin.gin at gmail.com (hakugin.gin at gmail.com) Date: Fri, 11 Sep 2015 12:00:55 -0700 (PDT) Subject: RPI.GPIO Help In-Reply-To: References: Message-ID: <2984b094-5458-4d5d-beda-adca10687dcd@googlegroups.com> On Friday, September 11, 2015 at 2:25:15 PM UTC-4, John McKenzie wrote: > Hello. > > Thanks to the help of people here and in other newsgroups I seem to have > something working doing the basics. (Buttons work, colours light up > appropriately.) > def red_button(channel): > global colour > if colour == 1: > pass > elif colour == 2 or 3: > colour = 1 > while colour == 1: > led.pulse(red=255, green=0, blue=0, repeats=1, duration=2000, > steps=50) Another option for this would be: def red_button(channel): global colour if colour != 1: colour = 1 # Rest of your original code goes below here I am currently checking some other options, unfortunately I am not at home or have access to a RPi right now so I am unable to fully test. From ottonebolone at gmx.com Fri Sep 11 15:14:02 2015 From: ottonebolone at gmx.com (Redacted) Date: Fri, 11 Sep 2015 12:14:02 -0700 (PDT) Subject: Redacted Message-ID: <72683ca2-11fb-4200-8ffd-d98f14fdcaa9@googlegroups.com> Redacted From lac at openend.se Fri Sep 11 15:17:48 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 11 Sep 2015 21:17:48 +0200 Subject: Problem with handling errors in POP3 message retrieval/deletion In-Reply-To: References: Message-ID: <201509111917.t8BJHmjS007174@fido.openend.se> In a message of Fri, 11 Sep 2015 17:33:32 +0100, cl at isbd.net writes: >I have a (fairly) simple script that does 'catchall' processing on my >POP3 mailbox. It looks for messages To: strings that *might* be for >me and then throws everything else away. Somebody tried to protect you from yourself. see https://bugs.python.org/issue1604 after your imput do poplib._MAXLINE= 20480 has been big enough for me ... Laura From hakugin.gin at gmail.com Fri Sep 11 15:24:13 2015 From: hakugin.gin at gmail.com (hakugin.gin at gmail.com) Date: Fri, 11 Sep 2015 12:24:13 -0700 (PDT) Subject: RPI.GPIO Help In-Reply-To: References: Message-ID: On Friday, September 11, 2015 at 2:25:15 PM UTC-4, John McKenzie wrote: > Hello. > > Thanks to the help of people here and in other newsgroups I seem to have > something working doing the basics. (Buttons work, colours light up > appropriately.) > > When I followed MRAB's instructions and read about scopes of variables > that solved my most recent problem, but it introduced a bug. I think I > fixed the bug but after all my stupid mistakes and forgetfulness that > seems too good to be true. I expect there is a better, more elegant, or > more Pythonic way to do what I did so please feel free to share on the > subject. > > I had a problem where if I pressed a button while the LEDs were already > flashing the colour of that button it would block a new colour from > starting when I pressed a new button. So if the LED strip was red and I > pressed the red button again nothing would happen when I pressed the blue > or yellow button. Similar problem for the other two buttons. > > So inside my callbacks I added this code: > > if colour == 1: > pass > elif colour == 2 or 3: > colour = 1 > > > Now it seems OK from my limited testing. > > > Here is the code that has buttons and colours working and includes my > bug fix: > > > import atexit > import time > from blinkstick import blinkstick > import RPi.GPIO as GPIO > > led = blinkstick.find_first() > colour = 0 > time_red = 0 > time_yellow = 0 > time_blue = 0 > timestamp = time.strftime("%H:%M:%S") > > GPIO.setmode(GPIO.BCM) > GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) > GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) > GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) > > > def red_button(channel): > global colour > if colour == 1: > pass > elif colour == 2 or 3: > colour = 1 > while colour == 1: > led.pulse(red=255, green=0, blue=0, repeats=1, duration=2000, > steps=50) > def yellow_button(channel): > global colour > if colour == 2: > pass > elif colour == 1 or 3: > colour = 2 > while colour == 2: > led.pulse(red=255, green=96, blue=0, repeats=1, > duration=2000, steps=50) > def blue_button(channel): > global colour > if colour == 3: > pass > elif colour == 1 or 2: > colour = 3 > while colour == 3: > led.pulse(red=0, green=0, blue=255, repeats=1, duration=2000, > steps=50) > > > GPIO.add_event_detect(22, GPIO.FALLING, callback=red_button, > bouncetime=200) > GPIO.add_event_detect(23, GPIO.FALLING, callback=yellow_button, > bouncetime=200) > GPIO.add_event_detect(24, GPIO.FALLING, callback=blue_button, > bouncetime=200) > > > while True: > if colour == 1: > time_red += 1 > elif colour == 2: > time_yellow += 1 > elif colour == 3: > time_blue += 1 > > time.sleep(0.1) > > > def exit_handler(): > print "\033[0;41;37mRed Team:\033[0m ", time_red > print "\033[0;43;30mYellow Time:\033[0m ", time_yellow > print "\033[0;44;37mBlue Time:\033[0m ", time_blue > flog = open("flag1.log", "a") > flog.write(timestamp + "\n" + "Red Team: " + str(time_red) + "\n" + > "Yellow Team: " + str(time_yellow) + "\n" + "Blue Team: " + str > (time_blue) + "\n") > flog.close() > led.set_color(name="black") > atexit.register(exit_handler) > GPIO.cleanup() > > > > I think I am OK GPIO wise now, although always happy to improve the code > and in the long term I want to do so. > > Will start new threads for more straight forward Python questions like > help with saving a log of the results, timing, etc. > > Thanks for your help, everyone. I just noticed another potential issue with your code. You added "while" loops to your button functions, you should adjust the code so that the "led.pulse" call is in the main loop. For example, at the beginning add something like: pulse_settings = [] Change your button functions to change this new variable when the button is pressed: def red_button(channel): global colour, pulse_settings if colour != 1: colour = 1 pulse_settings = (red=255, green=0, blue=0, repeats=1, duration=2000, steps=50) Then change your main "while" loop: while True: if colour == 1: time_red += 1 elif colour == 2: time_yellow += 1 elif colour == 3: time_blue += 1 led.pulse(pulse_settings) time.sleep(pulse_settings[4]) # sets the delay to the duration of the pulse effect These are merely suggestions, again I do not have access to my RPi to test, your mileage may vary. From anthon at mnt.org Fri Sep 11 16:51:22 2015 From: anthon at mnt.org (Anthon van der Neut) Date: Fri, 11 Sep 2015 22:51:22 +0200 Subject: string_formatter 1.0.1 released In-Reply-To: References: Message-ID: <55F33ECA.3010206@mnt.org> string_formatter is a backport of the 3.4.1+ string.Formatter class, to 2.7, 3.3 and 3.4.0. This allows the use of empty keys {} in its format strings. At the same time it solves an existing (at least until 3.5.0.rc3) bug in string.Formatter, breaking with the use of nested empty keys. Python 3.4.3: >>> import string >>> string.Formatter().format("|{:<{}} {}|", 'a', 3, 5) '|a 3|' In addition (that is how it all started) it provides TrailingFormatter which allows a type specification "t" with a single character parameter. That character will be added to the (stringified) value before applying (left-aligned) formatting: import string_formatter as string fmt = string.TrailingFormatter() d = dict(a=1, bc=2, xyz=18) for key in sorted(d): print(fmt.format("{:t{}<{}} {:>3}", key, ':', 15, d[key])) giving: a: 1 bc: 2 xyz: 18 From tdev at freenet.de Fri Sep 11 17:26:58 2015 From: tdev at freenet.de (tdev at freenet.de) Date: Fri, 11 Sep 2015 14:26:58 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: References: Message-ID: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> Reflecting latest answers to global and "proposals" Ad hominem. There is a slogan: "There are always two persons involved" This I dont want talk about. I dont go into such a discussion. It seems more a problem of misinterpretations. Proofs. Not really proofs. I meant more or less proofs. Proofs in "Proofs". Proofs from my point of view or you can say from my understanding (or say also high level position view) and from the answers given so far Samples (+main discussion "global"). Samples are often as text only in this thread. I think it is clear when you have followed the thread. But the thread has now taken some new directions. Yes, it is litte awkward searching back now. But you can say, the "general" sample is: You have to specify global that the compiler can distinguish between local and global Other words: global is needed to distinct global from local. But this is "not" true. You specify global cause you want write access. Even the rules specified proves it: > 1) If it's in the function's argument list, it's an argument (and > therefore local). > 2) If it's explicitly declared global, then it's global. > 3) If it's never assigned within the function, then it's global. > 4) Otherwise, it's local. Take step 2 out than it is again recognized as global. So the global keyword is not needed to distinguish global from local. Rule 3 proves it. Identation. It is stated > It is correct that there have to be a decision for spaces or tabs. With that I meant clearly no mixing of tabs and spaces. So forget tabs (tabs changed to spaces) and take spaces. The meaning is clearly: def x(): pass 2 spaces to the right def y(): pass 3 spaces to the right Surprisingly this runs now. Sometimes I run into indentations errors similiar to sample above for no reasons (maybe cause of existing spaces on the end of a line - next occurences I will try to note it down) But I have to remove this proposal for now. Sorry. PEP. As previously stated I am not in the position (and/or knowledge) to write a PEP. I wanted only to start a general (high-level point of view) discussion about it, in the hope there is somehow an agreement which starts somehow a PEP. But from answers in this list I would say: No chance. Practically no agreements. This I have to accept, although I cannot understand it (reasons given in previous post: it was/is nothing more than to enhance and give even more flexibility to the language as with all the other features already available in parallel for the same reasons). Conclusion. I will use Python, but never become a Pythonier, although quite conform with its philosophy "One best way". But even a traditional switch is denied, although much clearer in reading and writing than any if-else construct. I can and will not understand it. Thanks for your answers. From skybuck2000 at hotmail.com Fri Sep 11 17:50:38 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Fri, 11 Sep 2015 23:50:38 +0200 Subject: Python handles globals badly. In-Reply-To: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> Message-ID: Hello, I'll add some arguments to the global discussion for you. First a look back at the origin of this "global" keyword, basically it's idea behind it, which is probably a flawed assumption. The origin/purpose of global as I now understand it is to give "write" access to globally declared variables. This is first of all something unusual. Which other programmer language has this weird/whacky inconsistency ? In general I believe inconsistent behaviour should be prevented in programming languages. Anyway... having written/said that... there is a flawed assumption with this idea. The assumption is that: "writing to globals is bad and can lead to bugs". The further assumption is that: "denieing write access to globals prevents bugs". Especially the last assumption is just plain wrong. Not giving write access to globals can also lead to even much harder to find bugs. The unaware programmer may assume that a global was changed, while in reality it was not. How will such a bug be found ? Very hard to do in general, especially in an interpreter like python... where these bugs will need to be catched at run time. Catching these bugs at runtime is far more difficult than bugs/errors which show up during compile time. Thus forgetting "global" is going to be a far worse mistake... then actually overwritten or re-using some global accidently. This kind of mistake can be checked by the programmer without requiring runtime inspection. As soon as the programmer notices that some global is being re-used abusively the programmer can correct the situation. With forgetting the global keyword not so... much harder to find. Only possibility is to add "global" everywhere out of paranoya... which prevents the programmer from having to inspect every possibly line of code. The global/write access requirement right now basically forces the programmer to check EVERY line of python code to see if a global is being written to which actually does not have the required write permission ?!? How can anybody in their right mind think that is is somehow an improvement ? It simply is not... unless the interpreter at runtime would start to BEEP or show ERROR messages in some log... that a global is being written too which actually does not have WRITE permissions ? So far I have only used Sikuli to develop in Python... so let me ask a question here: Is there ANY Python IDE that actually produces such a warning or error message at runtime ???? Is there any IDE which outputs: "Error: GLOBAL variable being written too without WRITE permission ?!?". How would the interpreter know that it is a global variable ? Well it's declared somewhere outside the scope of the function... so that's not the issue... issue is missing GLOBAL declaration inside the function... so it's more of a "WRITE" permission than "global permission". So the name itself: "GLOBAL" is somewhat misleading... it's more a "WRITE" permission lol. Just that reason alone is enough to remove "GLOBAL" from python language and replace it with: "WRITE". or if it has to be: "GLOBAL-WRITE". But any programmer would probably find that ridicilous. So that basically proves that this GLOBAL requirement in itself is pretty ridicilous... though it does give a nice hint that this variable is a global variable ?! But is that really necessary ?!? Perhaps, perhaps not... in PASCAL one would simply look at the top section of the function... where all variable must be declared, python lacks this feature which is kinda nice... but it does make it a bit problematic to spot if something is local or global. While the next best thing the python programmer can do is: inspect the entire function to see if the variable is being written to or read from somewhere... but in reality this is no garantuee that it is local or global... so hence a little bit of a problem... adding global to the language is not really going to solve that... since programmer will have to add that manually to a variable... might forget it... and then the variable will actually still be a global variable.. and any bug fixer will still need to inspect code. So basically this global requirement doesn't really help that much... as some say... it's a bit of a hint... a shitty one for that... it's almost like fuzzy logic... 50% chance that it's gonna help... 50% it's not gonna help ;) or might even lead to problems if read-only behaviour was actually required. So when it comes to assumptions which bug is worse: 1. Willfully writing to a read-only global variable. (assignment failed-bug) 2. Mistakenly writing to a writeable global variable. (overwrite-bug) As I already wrote before I think bug1 is much harder to spot then bug 2 by pure code inspection. Ask yourself one question: How many times does a programmer actually want a "read-only" global variable ? This seems very weird to me. Pascal solves this very nicely for "constants" with constant declaration. If a global variable is to remain "read-only" then a better approach would be pascal's way: Simply declaring the global variable as "constant" constant MyGlobal = 5 Writing to MyGlobal would then produce an error. This can probably be checked at compile time too. Something which python does not seem to do currently ?! So that's weird. I will leave it at that for now. Bye, Skybuck. From ian.g.kelly at gmail.com Fri Sep 11 18:10:14 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 11 Sep 2015 16:10:14 -0600 Subject: Python handles globals badly. In-Reply-To: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> Message-ID: On Fri, Sep 11, 2015 at 3:26 PM, wrote: > Ad hominem. > There is a slogan: "There are always two persons involved" > This I dont want talk about. I dont go into such a discussion. > It seems more a problem of misinterpretations. I think you misunderstand my comment. The paragraph that I was responding to commits the ad hominem logical fallacy by supposing that the credentials of the person making an argument have any bearing on the validity of the argument. It therefore is dismissed as being poorly reasoned. I point this out not to criticize, but to point out that your argument is fallacious. > But you can say, the "general" sample is: > You have to specify global that the compiler can distinguish > between local and global > Other words: global is needed to distinct global from local. This is not what I would consider a sample. I thought you were referring to actual code examples demonstrating something. > But this is "not" true. > You specify global cause you want write access. > Even the rules specified proves it: > >> 1) If it's in the function's argument list, it's an argument (and >> therefore local). >> 2) If it's explicitly declared global, then it's global. >> 3) If it's never assigned within the function, then it's global. >> 4) Otherwise, it's local. > > Take step 2 out than it is again recognized as global. > So the global keyword is not needed to distinguish global from local. > Rule 3 proves it. Rule 3 works because it's generally safe to assume that a variable that is never assigned locally can't be local; any attempt to access it would result in an UnboundLocalError. (I say "generally" because this assumption only holds as long as it's not possible to set locals via eval or by updating locals(). That's true in the C implementation of Python but not necessarily true in other implementations.) Rule 3 doesn't imply that the compiler is capable of distinguishing globals from locals. It's a guess based on a rule of thumb. So it's less accurate to say that "you specify global cause you want write access" and more accurate to say that "you specify global in cases where the compiler can't guess it without assistance". It just so happens that the two line up with one another. > Surprisingly this runs now. > Sometimes I run into indentations errors similiar to sample above for no reasons > (maybe cause of existing spaces on the end of a line - next occurences I will try to note it down) > But I have to remove this proposal for now. > Sorry. Yes, you can already choose between tabs or spaces for indentation. You just can't mix them within the same code block. From nospam at nospam.com Fri Sep 11 18:16:36 2015 From: nospam at nospam.com (Javier) Date: Fri, 11 Sep 2015 22:16:36 +0000 (UTC) Subject: monospaced font in MS Windows with wxpython Message-ID: I am trying to use a monospaced font (preferably small) in MS Windows with wxpython. I have tried txtctrl.SetFont(wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Consolas')) but no success, I still get a proportional font. From emile at fenx.com Fri Sep 11 18:28:35 2015 From: emile at fenx.com (Emile van Sebille) Date: Fri, 11 Sep 2015 15:28:35 -0700 Subject: monospaced font in MS Windows with wxpython In-Reply-To: References: Message-ID: On 9/11/2015 3:16 PM, Javier wrote: > I am trying to use a monospaced font (preferably small) in MS Windows > with wxpython. I have tried > > txtctrl.SetFont(wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Consolas')) > > but no success, I still get a proportional font. > You may also want to try posting to http://www.wxpython.org/maillist.php as they're more wxpython focused. Emile From python at mrabarnett.plus.com Fri Sep 11 19:03:54 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 12 Sep 2015 00:03:54 +0100 Subject: Python handles globals badly. In-Reply-To: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> Message-ID: <55F35DDA.7020508@mrabarnett.plus.com> On 2015-09-11 22:26, tdev at freenet.de wrote: > Reflecting latest answers to global and "proposals" > [snip] > But you can say, the "general" sample is: > You have to specify global that the compiler can distinguish > between local and global > Other words: global is needed to distinct global from local. > > But this is "not" true. > You specify global cause you want write access. > Even the rules specified proves it: > >> 1) If it's in the function's argument list, it's an argument (and >> therefore local). >> 2) If it's explicitly declared global, then it's global. >> 3) If it's never assigned within the function, then it's global. >> 4) Otherwise, it's local. > > Take step 2 out than it is again recognized as global. > So the global keyword is not needed to distinguish global from local. > Rule 3 proves it. > I'd would rephrase 3 and 4: 1) If it's in the function's argument list, it's local. 2) If it's declared global, it's global. 3) If it's assigned within the function, it's local. 4) Otherwise, it's global. > > Conclusion. > I will use Python, but never become a Pythonier, > although quite conform with its philosophy "One best way". > But even a traditional switch is denied, although much clearer > in reading and writing than any if-else construct. > I can and will not understand it. > No-one can decide on how it should be written without it looking syntactically inconsistent in some way compared to the other control structures. > > Thanks for your answers. > > From james.harris.1 at gmail.com Fri Sep 11 19:15:54 2015 From: james.harris.1 at gmail.com (James Harris) Date: Sat, 12 Sep 2015 00:15:54 +0100 Subject: Signal SIGINT ignored during socket.accept References: Message-ID: "James Harris" wrote in message news:msv21t$n1m$1 at dont-email.me... > > "Grant Edwards" wrote in message > news:msum6c$hv$1 at reader1.panix.com... ... >> Waking up twice per second and immediately >> calling select() again on any hardware/OS built in the past 50 years >> is going completely negligible (as long as you can ignore the smell). > > CPU usage is not the only issue but it is a consideration. I tested it > before posting the code and couldn't see any significant increase in > CPU use. To give it a better test I have just left running for a > couple of hours or so. I am pleased to say it currently reports a > cumulative total of 0:00:00, i.e. it has not clocked up even a second > of CPU time yet! I am beginning to wonder if time is being accounted properly. It has now been running 8 hours and still shows CPU time as zero. James From torriem at gmail.com Fri Sep 11 20:01:16 2015 From: torriem at gmail.com (Michael Torrie) Date: Fri, 11 Sep 2015 18:01:16 -0600 Subject: Python handles globals badly. In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> Message-ID: <55F36B4C.9020007@gmail.com> On 09/11/2015 03:50 PM, Skybuck Flying wrote: > Something which python does not seem to do currently ?! > > So that's weird. > > I will leave it at that for now. Seems to me you have a completely mistaken understanding of how variables work in Python. This is one of the reasons why I have said in the past, erroneously, that Python does not have variables. It does of course but not in the same way as C or Pascal. In those languages names are source-code abstractions only, and irrelevant to the compiler and machine code. C and Pascal define variables as boxes that can be written to. Not so in Python. In Python most common objects are immutable. Meaning they can never change or be overwritten. They are bound to names. This binding is what makes names look like and act like traditional variables. The secret to understanding the global keyword is to understand how Python namespaces work. The statement "a=5" does not assign a 5 to the box called "a." Rather it binds the name "a" to the "5" object, which is immutable and called into existence by the interpreter implementation. Subsequently "a=6" disconnects a from the 5 object, casting the 5 object loose to be reclaimed in some fashion that doesn't matter at this point. "a" is then rebound to a new object, 6. When doing a look-up on a name, the interpreter first checks the local scope's dictionary and if it does not find the name there there, goes to the outer scope and so forth until you get to the module global namespace. So we don't need any special keywords to do Pascal-style constants. We just define them in the module and they work. Usually we name them in all caps so we have a bit of a convention as to where they come from. And yes we're talking about looking up strings in a dictionary here. When binding a name to an object, the interpreter always binds a name in the local namespace, unless the global keyword has been used previously and then it goes right to the global namespace. As has been said numerous times on this thread, how else would the interpreter do this? There simply isn't any other way that makes sense. Certainly you haven't made the case for it, seeing as you have some fundamental misunderstandings about variables in Python. You keep saying things like "writing to a variable" or "declared variables" which just don't apply to Python because that's not how Python variables work. It may appear this way on the surface, but the differences are subtle yet important. Namespaces are written to, not variables, some objects can be mutated. Names are bound to objects, but variables are not declared, as a name can be bound to an object of any type. Namespaces are powerful constructs that give Python much of its dynamic nature and expressivity. Learn to use them! From random832 at fastmail.us Fri Sep 11 20:11:38 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Fri, 11 Sep 2015 20:11:38 -0400 Subject: Python handles globals badly. In-Reply-To: <55F36B4C.9020007@gmail.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> Message-ID: <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> On Fri, Sep 11, 2015, at 20:01, Michael Torrie wrote: > The secret to understanding the global keyword is to understand how > Python namespaces work. The statement "a=5" does not assign a 5 to the > box called "a." Rather it binds the name "a" to the "5" object, which > is immutable and called into existence by the interpreter > implementation. In other words, it assigns a pointer to the "5" object [otherwise known as "a 5"] to the box called "a". (And increments its reference count, if you care about how the CPython garbage collector works) From torriem at gmail.com Fri Sep 11 20:34:07 2015 From: torriem at gmail.com (Michael Torrie) Date: Fri, 11 Sep 2015 18:34:07 -0600 Subject: Python handles globals badly. In-Reply-To: <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: <55F372FF.4070504@gmail.com> On 09/11/2015 06:11 PM, random832 at fastmail.us wrote: > On Fri, Sep 11, 2015, at 20:01, Michael Torrie wrote: >> The secret to understanding the global keyword is to understand how >> Python namespaces work. The statement "a=5" does not assign a 5 to the >> box called "a." Rather it binds the name "a" to the "5" object, which >> is immutable and called into existence by the interpreter >> implementation. > > In other words, it assigns a pointer to the "5" object [otherwise known > as "a 5"] to the box called "a". (And increments its reference count, if > you care about how the CPython garbage collector works) Yes I suppose that works. It shows the difference between Pascal's "a := 5" and Python's "a = 5". So long as it's not just a pointer we're talking about here; it's a counted reference. I think I prefer the word "reference" to "pointer" in this case. The word, pointer has certain connotations that come from C. Certainly in the implementation you would probably use pointers. But we don't really need a full physical memory abstraction to understand names and how they are bound (made to refer) to objects. In fact it might be more useful to forget about the underlying mechanisms in the interpreter. And it's useful to think about namespaces because then we can understand what happens when python sees a variable in an expression. In any case, we're not overwriting any values in Python assignments. From nospam at nospam.com Fri Sep 11 20:35:06 2015 From: nospam at nospam.com (Javier) Date: Sat, 12 Sep 2015 00:35:06 +0000 (UTC) Subject: monospaced font in MS Windows with wxpython References: Message-ID: The font I posted before was actually monospaced. I was just putting the definition in the wrong place All solved now. Sorry for the noise. > txtctrl.SetFont(wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Consolas')) From breamoreboy at yahoo.co.uk Fri Sep 11 22:11:50 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 03:11:50 +0100 Subject: Context-aware return In-Reply-To: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 10/09/2015 18:54, Steven D'Aprano wrote: > I have a function which is intended for use at the interactive interpreter, > but may sometimes be used non-interactively. I wish to change it's output > depending on the context of how it is being called. > > If the function is being called as if it were a procedure or command, that > is the return result is just ignored, I want to return one thing. But if it > is being called where the return result goes somewhere, I want to return > something else. Most importantly, I don't want to pass a flag to the > function myself, I want the function to know its own context. > > I don't mind if it is CPython only, or if it is a bit expensive. > > E.g. > > def func(): > do_stuff() > if procedure: # FIXME what goes here??? > return "Awesome" > else: > return 999 > > Now I can do this: > > x = func() > assert x == 999 > > L = [1, 2, func(), 4] > assert L[2] == 999 > > func() > # interactive interpreter prints "Awesome" > > Is such a thing possible, and if so, how would I do it? > > If I did this thing, would people follow me down the street booing and > jeering and throwing things at me? > Not unless you were thrown in the Australian equivalent of Broadmoor first. For those who don't know, Broadmoor is a famous place in the UK for the criminally insane. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Fri Sep 11 22:27:48 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 03:27:48 +0100 Subject: Python handles globals badly. In-Reply-To: References: Message-ID: On 10/09/2015 23:25, tdev at freenet.de wrote: > Some notes to the "global"-keyword and the other proposals. > > It has been proposed to have these six enhancements > > 1. optional keyword "global" Won't happen. > 2. switch statement Won't happen. > 3. less restrictive indentation Won't happen. > 4. universal scope No idea what you mean by this. > 5. goto label Won't happen. > 6- "include" script statement No idea what you mean by this. > > with following proofs uncommented: > Your "proofs" hold about as much water as a bottomless bucket. > There is the big question: > > Who is responding or has responded? > Extreme Programmers, Python-Hardliner, Python-Evangelists, ... . > Presumably no core Python Programmers (wrting compiler and standard library stuff) Core Python Programmers have better things to do than waste their time on rubbish like this. Examples include writing code and fixing bugs. I understand that some of them are actually really weird and do other things like paid jobs, see their families, take holidays and worst of all, have other hobbies. > > On Google groups you can currently read for this thread: > 37 Authors. 152 posts. 443 views. > > That is not that much for views (probably mostly from the writer's itself) > > So, is this really the place where a PEP can be started? > When has a proposal to be accepted? If ten-thousands say yes? > Which ten-thousands? Who decides it? > The BDFL or his delegate decides, not that a PEP like this should be written. If you want to waste your time please feel free to go ahead, I won't stop you. However I do feel you should put this on python-ideas where it will be shot to pieces and then with any luck we'll get some peace and quiet. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Fri Sep 11 22:35:00 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 03:35:00 +0100 Subject: Python handles globals badly. In-Reply-To: <201509102219.14138.gheskett@wdtv.com> References: <1eee075d-7073-4875-9e42-2e053ee59b41@googlegroups.com> <0784va15gme91mqvoasfub3hvu59ehpepl@4ax.com> <201509102219.14138.gheskett@wdtv.com> Message-ID: On 11/09/2015 03:19, Gene Heskett wrote: > On Thursday 10 September 2015 20:33:03 Dennis Lee Bieber wrote: > >> On Thu, 10 Sep 2015 12:04:05 -0700 (PDT), rurpy--- via Python-list >> >> declaimed the following: >>> I also doubt there were more programming languages around in the >>> 1970s than now, on the grounds that there were far fewer people >>> capable of writing a compiler or interpreter in those days, and >>> there were far fewer tools to help, or easily accessible knowledge >>> about how to do do it. >> >> Yet there were enough assorted semi-specialized languages in use on >> military programs to induce the DoD to run the competition for a >> singular language -- which became Ada. > > And which should be noted that it has been a rather spectacular failure > in the commercial market. Does that mean that those who can code in Ada > are working only for the military's suppliers, and because they are a > scarce commodity, writing their own paycheck? I don't know, other than > no one is publically bragging about it. > >> -- >> Wulfraed Dennis Lee Bieber AF6VN >> wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > > Cheers, Gene Heskett > Ada took over from CORAL in the UK, at least in military projects. It was also used in the aircraft industry. My old work mates tell me that its completely died a death, to be replaced by C++. Someone please remind me never to fly again. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Fri Sep 11 22:43:37 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 03:43:37 +0100 Subject: Python handles globals badly. In-Reply-To: <878u8do7u2.fsf@elektro.pacujo.net> References: <87h9n1o9q4.fsf@elektro.pacujo.net> <878u8do7u2.fsf@elektro.pacujo.net> Message-ID: On 11/09/2015 06:15, Marko Rauhamaa wrote: > Chris Angelico : > >> Personally, I like to use tab characters for indentation. You can >> choose how many pixels or ems or ens or spaces the actual visual shift >> is, and if I disagree with your choice, it won't affect anything. As >> long as tabs are used _exclusively_, Python won't be bothered by it >> either. > > Your preferred, novel usage of TABs, which runs counter to the age-old > programming convention, has won enough supporters to make TABs unusable. > > No harm done. TABs have been banished. They were a bad idea in the first > place. > > Marko > TABs might have been banished from some places, but certainly not Python. Of course you have to be careful or you run into problems with this:- TabError - Raised when indentation contains an inconsistent use of tabs and spaces. https://docs.python.org/3/library/exceptions.html#TabError -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From gheskett at wdtv.com Fri Sep 11 22:47:45 2015 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 11 Sep 2015 22:47:45 -0400 Subject: Python handles globals badly. In-Reply-To: References: <201509102219.14138.gheskett@wdtv.com> Message-ID: <201509112247.45986.gheskett@wdtv.com> On Friday 11 September 2015 22:35:00 Mark Lawrence wrote: > On 11/09/2015 03:19, Gene Heskett wrote: > > On Thursday 10 September 2015 20:33:03 Dennis Lee Bieber wrote: > >> On Thu, 10 Sep 2015 12:04:05 -0700 (PDT), rurpy--- via Python-list > >> > >> declaimed the following: > >>> I also doubt there were more programming languages around in the > >>> 1970s than now, on the grounds that there were far fewer people > >>> capable of writing a compiler or interpreter in those days, and > >>> there were far fewer tools to help, or easily accessible knowledge > >>> about how to do do it. > >> > >> Yet there were enough assorted semi-specialized languages in use > >> on military programs to induce the DoD to run the competition for a > >> singular language -- which became Ada. > > > > And which should be noted that it has been a rather spectacular > > failure in the commercial market. Does that mean that those who can > > code in Ada are working only for the military's suppliers, and > > because they are a scarce commodity, writing their own paycheck? I > > don't know, other than no one is publically bragging about it. > > > >> -- > >> Wulfraed Dennis Lee Bieber AF6VN > >> wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > > > Cheers, Gene Heskett > > Ada took over from CORAL in the UK, at least in military projects. It > was also used in the aircraft industry. My old work mates tell me that > its completely died a death, to be replaced by C++. Someone please > remind me never to fly again. > Oh my gawd. C++ in a airplane autopilot? Now that's scarey. And I was just in one, three each way actually, round trip halfway across the country, last December. > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From breamoreboy at yahoo.co.uk Fri Sep 11 22:51:17 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 03:51:17 +0100 Subject: Python handles globals badly. In-Reply-To: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 11/09/2015 09:42, Steven D'Aprano wrote: > On Fri, 11 Sep 2015 10:35 am, Ian Kelly wrote: > >> On Thu, Sep 10, 2015 at 4:25 PM, wrote: > [...] >>> So the compiler knows the distiction between global and local already. >> >> As we've said before, it doesn't. The compiler's current rules are >> fairly simple: >> >> 1) If it's in the function's argument list, it's an argument (and >> therefore local). >> 2) If it's explicitly declared global, then it's global. >> 3) If it's never assigned within the function, then it's global. > > Almost. If it's never assigned within the function, then it is looked up > according to the non-local scoping rules: > > - closures and enclosing functions (if any); > - globals; > - builtins; > > in that order. > > >> 4) Otherwise, it's local. > > "Otherwise" meaning "if it is assigned to", except that "del" counts as an > assignment. That is: > > def spam(): > del x > > makes x a local variable inside the function spam. > > > There's also a bunch of specialised and complicated rules for what happens > if you make a star import ("from module import *") inside a function, or > call eval or exec without specifying a namespace. Both of these things are > now illegal in Python 3. > > And lastly, in Python 3 only, there is also a nonlocal declaration which > works like global except it applies only to closures and enclosing > functions. > > >>> Another proof about identation: >>> The parser can recognise identation with tabs and spaces. >> >> You can use tabs *or* spaces. > > In Python 3. > > In Python 2, you can mix tabs *and* spaces, and Python will try to guess > what you mean. This causes more trouble than it is worth, and is removed in > Python 3. > > > [...] >> I really doubt that you're going to gain any traction with this one, >> because the decision that was made with Python 3 was to make the >> compiler *more* rigid about not mixing tabs and spaces, not less. > > Correct. > > [...] >>> Who is responding or has responded? >>> Extreme Programmers, Python-Hardliner, Python-Evangelists, ... . >>> Presumably no core Python Programmers (wrting compiler and standard >>> library stuff) >> >> Ad hominem. > > For the record, I am the author of the statistics module in Python 3.4, and > Terry Reedy is the very active maintainer of IDLE. If I have missed anyone, > my apologies. So, yes, there are core developers here. > > (Although not any of the senior core devs, as far as I know.) > IIRC Serhiy Storchaka pops in occasionally, as on the one genuine report from the RUE about the FSR. Slight aside, I swear blind that Serhiy never sleeps as he always seems to be doing something on the bug tracker. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Fri Sep 11 22:57:22 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 03:57:22 +0100 Subject: Python handles globals badly. In-Reply-To: <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: On 12/09/2015 01:11, random832 at fastmail.us wrote: > On Fri, Sep 11, 2015, at 20:01, Michael Torrie wrote: >> The secret to understanding the global keyword is to understand how >> Python namespaces work. The statement "a=5" does not assign a 5 to the >> box called "a." Rather it binds the name "a" to the "5" object, which >> is immutable and called into existence by the interpreter >> implementation. > > In other words, it assigns a pointer to the "5" object [otherwise known > as "a 5"] to the box called "a". (And increments its reference count, if > you care about how the CPython garbage collector works) > If everything in Python is an object, how can it assign a pointer? Especially how do Jython and IronPython assign pointers? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Fri Sep 11 23:01:24 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 04:01:24 +0100 Subject: Python handles globals badly. In-Reply-To: <55F36B4C.9020007@gmail.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> Message-ID: On 12/09/2015 01:01, Michael Torrie wrote: > On 09/11/2015 03:50 PM, Skybuck Flying wrote: >> Something which python does not seem to do currently ?! >> >> So that's weird. >> >> I will leave it at that for now. > > Seems to me you have a completely mistaken understanding of how > variables work in Python. This is one of the reasons why I have said in > the past, erroneously, that Python does not have variables. It does of > course but not in the same way as C or Pascal. In those languages names > are source-code abstractions only, and irrelevant to the compiler and > machine code. C and Pascal define variables as boxes that can be > written to. Not so in Python. > > In Python most common objects are immutable. Meaning they can never > change or be overwritten. They are bound to names. This binding is > what makes names look like and act like traditional variables. > > The secret to understanding the global keyword is to understand how > Python namespaces work. The statement "a=5" does not assign a 5 to the > box called "a." Rather it binds the name "a" to the "5" object, which > is immutable and called into existence by the interpreter > implementation. Subsequently "a=6" disconnects a from the 5 object, > casting the 5 object loose to be reclaimed in some fashion that doesn't > matter at this point. "a" is then rebound to a new object, 6. > > When doing a look-up on a name, the interpreter first checks the local > scope's dictionary and if it does not find the name there there, goes to > the outer scope and so forth until you get to the module global > namespace. So we don't need any special keywords to do Pascal-style > constants. We just define them in the module and they work. Usually we > name them in all caps so we have a bit of a convention as to where they > come from. And yes we're talking about looking up strings in a > dictionary here. > > When binding a name to an object, the interpreter always binds a name in > the local namespace, unless the global keyword has been used previously > and then it goes right to the global namespace. As has been said > numerous times on this thread, how else would the interpreter do this? > There simply isn't any other way that makes sense. Certainly you haven't > made the case for it, seeing as you have some fundamental > misunderstandings about variables in Python. > > You keep saying things like "writing to a variable" or "declared > variables" which just don't apply to Python because that's not how > Python variables work. It may appear this way on the surface, but the > differences are subtle yet important. Namespaces are written to, not > variables, some objects can be mutated. Names are bound to objects, but > variables are not declared, as a name can be bound to an object of any type. > > Namespaces are powerful constructs that give Python much of its dynamic > nature and expressivity. Learn to use them! > My favourite analogy for Python names, the sticky note, here https://mail.python.org/pipermail/tutor/2006-October/049767.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve at pearwood.info Fri Sep 11 23:48:29 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 12 Sep 2015 13:48:29 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F130CE.5060203@rece.vub.ac.be> <55F191CD.8040901@gmail.com> Message-ID: <55f3a08d$0$1674$c3e8da3$5496439d@news.astraweb.com> On Fri, 11 Sep 2015 05:28 pm, Antoon Pardon wrote: > Should C have chosen '<-' as token for assignment, that error > would have been far less common. > > The error is also facilitated because C doesn't have booleans > and so everything can be used as one. If C would have had > proper booleans [...] In other words, "If C were some other language, then assignment as an expression would be fine." I believe I already acknowledged that assignment-as-expression was fine if it avoided the = versus == error, from the perspective of avoiding errors. But from the perspective of a clean and logical programming model, perhaps not so much. Assignment is imperative, not functional, and requiring it to return a result is somewhat unclean. Look at it this way: suppose you had a robot servant that always, without fail or misunderstanding, did what you instructed. There are broadly two sorts of things that you can give as instructions: questions, and commands. Questions always require an answer: "What's the length of this list?" is functional. Commands are imperative, not functional, and don't necessarily require an answer: "Move the small red pyramid onto the large green cube." Some commands arguable might require an answer, but arguable they are better served by an out-of-band error condition (an exception). *Requiring* all commands to give an answer is silly, given that the robot servant is infallible. There's an argument to be made that, clean or not, assignment as an expression is useful. So be it -- other languages do that. I personally find it more confusing and annoying than useful when I come across it, but YMMV. -- Steven From random832 at fastmail.com Sat Sep 12 00:06:18 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 00:06:18 -0400 Subject: Python handles globals badly. References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: Mark Lawrence writes: > On 12/09/2015 01:11, random832 at fastmail.us wrote: > If everything in Python is an object, how can it assign a pointer? > Especially how do Jython and IronPython assign pointers? The Java and .NET runtimes also have pointers, they just don't [usually] call them pointers, just like Python doesn't call them pointers (a match made in... well, somewhere starting with an H, for sure). Honestly, whether you want to call the thing a pointer or a reference, you have to call it *something*, and I think "reference" is a worse fit based on its connotations from C++. Whatever you call it, it's an arrow on a diagram. From marfig at gmx.com Sat Sep 12 00:11:46 2015 From: marfig at gmx.com (Mario Figueiredo) Date: Sat, 12 Sep 2015 05:11:46 +0100 Subject: Python handles globals badly. In-Reply-To: References: <1eee075d-7073-4875-9e42-2e053ee59b41@googlegroups.com> <0784va15gme91mqvoasfub3hvu59ehpepl@4ax.com> <201509102219.14138.gheskett@wdtv.com> Message-ID: <55F3A602.50906@gmx.com> On 12-09-2015 03:35, Mark Lawrence wrote: > > Ada took over from CORAL in the UK, at least in military projects. It > was also used in the aircraft industry. My old work mates tell me that > its completely died a death, to be replaced by C++. Someone please > remind me never to fly again. Alright. But then someone should probably have reminded you that a long time ago. Maybe you missed it when an Ada integer overflow bug produced one of the most expensive software bugs in history by crashing the Ariane 501 rocket and its 4 cluster sattelites payload. But sure. Don't let that get in your way of thinking there are safe languages. From random832 at fastmail.com Sat Sep 12 00:16:40 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 00:16:40 -0400 Subject: Python handles globals badly. References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> Message-ID: Mark Lawrence writes: > My favourite analogy for Python names, the sticky note, here > https://mail.python.org/pipermail/tutor/2006-October/049767.html Is player3[3] also a sticky note? Wouldn't the note have to have the id of player3 written on it somehow? Should the player3 sticky note have the id of the global namespace that "player3" is valid in written on it? I like my analogy better because it means both player3 and (the list we call player3)[3] are both the *same* kind of thing: boxes that have pointers in them (i.e. variables). From breamoreboy at yahoo.co.uk Sat Sep 12 00:17:36 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 05:17:36 +0100 Subject: Python handles globals badly. In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: On 12/09/2015 05:06, Random832 wrote: > Mark Lawrence writes: > >> On 12/09/2015 01:11, random832 at fastmail.us wrote: >> If everything in Python is an object, how can it assign a pointer? >> Especially how do Jython and IronPython assign pointers? > > The Java and .NET runtimes also have pointers, they just don't [usually] > call them pointers, just like Python doesn't call them pointers (a match > made in... well, somewhere starting with an H, for sure). > > Honestly, whether you want to call the thing a pointer or a reference, > you have to call it *something*, and I think "reference" is a worse fit > based on its connotations from C++. Whatever you call it, it's an arrow > on a diagram. > I think pointer is even worse because of its connection with C and hence cPython. What is wrong with object if that is the only thing Python knows about? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ben+python at benfinney.id.au Sat Sep 12 00:27:38 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 12 Sep 2015 14:27:38 +1000 Subject: Terminology: =?utf-8?B?4oCccmVmZXJlbmNl4oCd?= versus =?utf-8?B?4oCccG9pbnRlcuKAnQ==?= (was: Python handles globals badly.) References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: <85mvws6z45.fsf_-_@benfinney.id.au> Random832 writes: > Honestly, whether you want to call the thing a pointer or a reference, > you have to call it *something*, and I think "reference" is a worse > fit based on its connotations from C++. Whatever you call it, it's an > arrow on a diagram. With the significant difference that ?pointer? implies that it has its own value accessible directly by the running program, such as a pointer in C. That's different from a ?reference?, which to my understanding implies the running program does *not* normally have direct access to it as a distinct value. The only way you can use a reference is to get at the object to which it refers. That's the distinction I've been reying on for years, anyway: Python's names are references, collections are collections of references, etc. They aren't pointers because you can't get them as a distinct value; you can only use them to refer to the object at the other end. -- \ ?If we don't believe in freedom of expression for people we | `\ despise, we don't believe in it at all.? ?Noam Chomsky, | _o__) 1992-11-25 | Ben Finney From breamoreboy at yahoo.co.uk Sat Sep 12 00:34:40 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 05:34:40 +0100 Subject: Python handles globals badly. In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> Message-ID: On 12/09/2015 05:16, Random832 wrote: > Mark Lawrence writes: >> My favourite analogy for Python names, the sticky note, here >> https://mail.python.org/pipermail/tutor/2006-October/049767.html > > Is player3[3] also a sticky note? Wouldn't the note have to have the id > of player3 written on it somehow? Should the player3 sticky note have > the id of the global namespace that "player3" is valid in written on it? > > I like my analogy better because it means both player3 and (the list we > call player3)[3] are both the *same* kind of thing: boxes that have > pointers in them (i.e. variables). > For the final time I hope, "pointer" is not appropriate for Python, so I'll stick with the sticky note analogy, thanks all the same. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From random832 at fastmail.com Sat Sep 12 00:34:52 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 00:34:52 -0400 Subject: Python handles globals badly. References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: Mark Lawrence writes: > I think pointer is even worse because of its connection with C and > hence cPython. What is wrong with object if that is the only thing > Python knows about? Because the object is the *thing the arrow points at*. You don't have two objects when store the same object in two variables (names, list slots, whatever), but you do have two pointers. And they *are* pointers in cPython - so that "connection" is a feature, not a bug. From breamoreboy at yahoo.co.uk Sat Sep 12 00:38:46 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 05:38:46 +0100 Subject: Python handles globals badly. In-Reply-To: <55F3A602.50906@gmx.com> References: <1eee075d-7073-4875-9e42-2e053ee59b41@googlegroups.com> <0784va15gme91mqvoasfub3hvu59ehpepl@4ax.com> <201509102219.14138.gheskett@wdtv.com> <55F3A602.50906@gmx.com> Message-ID: On 12/09/2015 05:11, Mario Figueiredo wrote: > On 12-09-2015 03:35, Mark Lawrence wrote: >> >> Ada took over from CORAL in the UK, at least in military projects. It >> was also used in the aircraft industry. My old work mates tell me that >> its completely died a death, to be replaced by C++. Someone please >> remind me never to fly again. > > Alright. But then someone should probably have reminded you that a long > time ago. > > Maybe you missed it when an Ada integer overflow bug produced one of the > most expensive software bugs in history by crashing the Ariane 501 > rocket and its 4 cluster sattelites payload. > > But sure. Don't let that get in your way of thinking there are safe > languages. > Nothing to do with this being untested software then? Actually it was so I'd put that down to a programmer error. "The code always worked before so it's bound to work this time". Such a pity that this particular launch wasn't the same as anything done previously. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From random832 at fastmail.com Sat Sep 12 00:42:04 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 00:42:04 -0400 Subject: Terminology: =?utf-8?B?4oCccmVmZXJlbmNl4oCd?= versus =?utf-8?B?4oCccG9pbnRlcuKAnQ==?= References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> Message-ID: Ben Finney writes: > With the significant difference that ?pointer? implies that it has its > own value accessible directly by the running program, such as a pointer > in C. Its own value *is* what you're accessing when you assign or return it. You just can't do math on it, but there are lots of things you can't do math on. > That's different from a ?reference?, which to my understanding implies > the running program does *not* normally have direct access to it as a > distinct value. The only way you can use a reference is to get at the > object to which it refers. In C++, references cannot be reassigned. I consider *that* the fundamental difference - a pointer is a variable that you can reassign and return; a reference always refers to the same object once created. > That's the distinction I've been reying on for years, anyway: Python's > names are references, collections are collections of references, etc. > They aren't pointers because you can't get them as a distinct value; you > can only use them to refer to the object at the other end. Anyway, maybe we do need a term to distinguish Python/C#/Java pointers from C/C++ pointers - maybe call it a "non-arithmetic" pointer, since the key thing about it is you can't do pointer arithmetic on them to get the object "next to" the one it points at. From breamoreboy at yahoo.co.uk Sat Sep 12 00:45:24 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 05:45:24 +0100 Subject: Python handles globals badly. In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: On 12/09/2015 05:34, Random832 wrote: > Mark Lawrence writes: >> I think pointer is even worse because of its connection with C and >> hence cPython. What is wrong with object if that is the only thing >> Python knows about? > > Because the object is the *thing the arrow points at*. You don't have > two objects when store the same object in two variables (names, list > slots, whatever), but you do have two pointers. > > And they *are* pointers in cPython - so that "connection" is a feature, > not a bug. > How do I access these pointers? Is there a builtin called pointer() that's analogous to id()? I'll ask again, where do pointers come into the Jython and IronPython models? How do I access their pointers, the same builtin? The fact that the underlying implementation language has some terminology that it uses, has no bearing on the actual language being implemented. This seems to me rather important, or have I missed something here? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ben+python at benfinney.id.au Sat Sep 12 00:52:51 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 12 Sep 2015 14:52:51 +1000 Subject: Terminology: =?utf-8?B?4oCccmVmZXJlbmNl4oCd?= versus =?utf-8?B?4oCccG9pbnRlcuKAnQ==?= References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> Message-ID: <85io7g6xy4.fsf@benfinney.id.au> Random832 writes: > Ben Finney writes: > > With the significant difference that ?pointer? implies that it has its > > own value accessible directly by the running program, such as a pointer > > in C. > > Its own value *is* what you're accessing when you assign or return it. You're not describing Python references. But I don't know what you are describing with all those ?it?s ? what language, what behaviour, what concept? Can you clarify what you mean, and what in my description you are disagreeing with? > > That's different from a ?reference?, which to my understanding > > implies the running program does *not* normally have direct access > > to it as a distinct value. The only way you can use a reference is > > to get at the object to which it refers. > > In C++, references cannot be reassigned. I consider *that* the > fundamental difference - a pointer is a variable that you can reassign > and return; a reference always refers to the same object once created. Sure, that will work fine. So in Python, we don't have pointers because we don't have access to change or reassign them. A Python reference isn't accessible and can't be changed; you can just make another reference and switch to that. You can't, for example, keep the old reference (there are no references to references in Python), because they're not accessible as values in themselves. Once you assign a different reference, the old one is gone and can't be found again. -- \ ?[T]he great menace to progress is not ignorance but the | `\ illusion of knowledge.? ?Daniel J. Boorstin, historian, | _o__) 1914?2004 | Ben Finney From random832 at fastmail.com Sat Sep 12 01:03:26 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 01:03:26 -0400 Subject: Terminology: =?utf-8?B?4oCccmVmZXJlbmNl4oCd?= versus =?utf-8?B?4oCccG9pbnRlcuKAnQ==?= References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> Message-ID: Ben Finney writes: > Random832 writes: > >> Ben Finney writes: >> > With the significant difference that ?pointer? implies that it has its >> > own value accessible directly by the running program, such as a pointer >> > in C. >> >> Its own value *is* what you're accessing when you assign or return it. > > You're not describing Python references. Yes I am. You're just making the implicit assumption that a "value" has to be a number, and I was ignoring that assumption. The value is the address of an object. Like I said, an arrow on a diagram. > Can you clarify what you mean, and what in my description you are > disagreeing with? > >> > That's different from a ?reference?, which to my understanding >> > implies the running program does *not* normally have direct access >> > to it as a distinct value. The only way you can use a reference is >> > to get at the object to which it refers. >> >> In C++, references cannot be reassigned. I consider *that* the >> fundamental difference - a pointer is a variable that you can reassign >> and return; a reference always refers to the same object once created. > > Sure, that will work fine. > > So in Python, we don't have pointers because we don't have access to > change or reassign them. Yes you do. That's _exactly what happens_ in an assignment statement - you are reassigning it to the address of another object. And that's something you *can't do* with references in C++. Neither term is perfect, but "reference" is a *terrible* fit because of that. > A Python reference isn't accessible and can't be changed; you can just > make another reference and switch to that. Huh? > You can't, for example, keep the old reference (there are no references > to references in Python), because they're not accessible as values in > themselves. Once you assign a different reference, the old one is gone > and can't be found again. You can keep it by copying it to somewhere. The pointer is the value, not the variable, you don't _need_ a reference to it. From random832 at fastmail.com Sat Sep 12 01:07:52 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 01:07:52 -0400 Subject: Python handles globals badly. References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: Mark Lawrence writes: > How do I access these pointers? Is there a builtin called pointer() > that's analogous to id()? You access them *all the time*. They are the *only* thing you access. But if you want... pointer = lambda x: return x > I'll ask again, where do pointers come into > the Jython and IronPython models? How do I access their pointers, the > same builtin? The fact that the underlying implementation language > has some terminology that it uses, has no bearing on the actual > language being implemented. I am not using "pointer" as language-specific terminology, I am using it as *the* name of the concept we are talking about. The Java and .NET runtimes *don't* use that terminology, but they still *actually* have pointers, in the same way that Python does. From ben+python at benfinney.id.au Sat Sep 12 01:20:51 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 12 Sep 2015 15:20:51 +1000 Subject: Terminology: =?utf-8?B?4oCccmVmZXJlbmNl4oCd?= versus =?utf-8?B?4oCccG9pbnRlcuKAnQ==?= References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> Message-ID: <85egi46wng.fsf@benfinney.id.au> Random832 writes: > Ben Finney writes: > > > Random832 writes: > > > >> Ben Finney writes: > >> > With the significant difference that ?pointer? implies that it has its > >> > own value accessible directly by the running program, such as a pointer > >> > in C. > >> > >> Its own value *is* what you're accessing when you assign or return it. > > > > You're not describing Python references. > > Yes I am. You're just making the implicit assumption that a "value" has > to be a number, and I was ignoring that assumption. The value is the > address of an object. Like I said, an arrow on a diagram. I made no assumption about the type; I don't care how the reference is implemented in the Python interpreter. That's not accessible to the running Python program without some API. My assertion still stands: the address of the object is *not* what the reference is, in Python. Calling ?id(foo)? does not return a reference to ?foo?, so I don't know how you think the value is accessible in the Python program. The reference value is inaccessible to the program, it can only be used to get at the referenced object. > > So in Python, we don't have pointers because we don't have access to > > change or reassign them. > > Yes you do. That's _exactly what happens_ in an assignment statement - > you are reassigning it to the address of another object. And that's > something you *can't do* with references in C++. The operation you describe doesn't change the reference; it doesn't mutate an existing value which can be compared with whatever value it had before. Instead, it throws away one reference and replaces it with a different one. That's significant, because unlike a mutable value you can never again get at the old reference in the Python program. > > You can't, for example, keep the old reference (there are no references > > to references in Python), because they're not accessible as values in > > themselves. Once you assign a different reference, the old one is gone > > and can't be found again. > > You can keep it by copying it to somewhere. How do you propose to ?copy? a reference in Python? Making a new reference to the referenced object is not making a copy of the reference. -- \ ?Demagogue: One who preaches doctrines he knows to be untrue to | `\ men he knows to be idiots.? ?Henry L. Mencken | _o__) | Ben Finney From skybuck2000 at hotmail.com Sat Sep 12 01:22:41 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Sat, 12 Sep 2015 07:22:41 +0200 Subject: Python handles globals badly. In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> Message-ID: <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> "Michael Torrie" wrote in message news:mailman.384.1442016089.8327.python-list at python.org... On 09/11/2015 03:50 PM, Skybuck Flying wrote: > Something which python does not seem to do currently ?! > > So that's weird. > > I will leave it at that for now. " Seems to me you have a completely mistaken understanding of how variables work in Python. This is one of the reasons why I have said in the past, erroneously, that Python does not have variables. It does of course but not in the same way as C or Pascal. In those languages names are source-code abstractions only, and irrelevant to the compiler and machine code. C and Pascal define variables as boxes that can be written to. Not so in Python. " Well you basically said it yourself: " irrelevant to the compiler and machine code". That's kinda nice about a high level language. Programmer does not need to understand anything below the language. A python programmer shouldn't need to understand a damn thing to write: A = 10 A = A + 1 print A However for sake of your discussion I will continue your arguments below, since I get the impression you guys are clueless how to change python implementation ;) " In Python most common objects are immutable. Meaning they can never change or be overwritten. They are bound to names. This binding is what makes names look like and act like traditional variables. The secret to understanding the global keyword is to understand how Python namespaces work. The statement "a=5" does not assign a 5 to the box called "a." Rather it binds the name "a" to the "5" object, which is immutable and called into existence by the interpreter implementation. Subsequently "a=6" disconnects a from the 5 object, casting the 5 object loose to be reclaimed in some fashion that doesn't matter at this point. "a" is then rebound to a new object, 6. " What happens for following code: A=1234567890111111 Are you going to claim it's going to bind to all these numbers and then also multiple times ? Sounds a bit shady ?! ;) Perhaps python considers it a string ? Python applies math to strings ? Sounds a bit slow... therefore perhaps you're wrong... " When doing a look-up on a name, the interpreter first checks the local scope's dictionary and if it does not find the name there there, goes to the outer scope and so forth until you get to the module global namespace. So we don't need any special keywords to do Pascal-style constants. We just define them in the module and they work. Usually we name them in all caps so we have a bit of a convention as to where they come from. And yes we're talking about looking up strings in a dictionary here. " So big deal, solution is easy to see, invert interpreter logic: Everything declared is "not constant". Everything declared as "constant" suddenly becomes constant. And thus everything declared as not constant behaves the same way as "global", problem solved. " When binding a name to an object, the interpreter always binds a name in the local namespace, unless the global keyword has been used previously and then it goes right to the global namespace. As has been said numerous times on this thread, how else would the interpreter do this? There simply isn't any other way that makes sense. Certainly you haven't made the case for it, seeing as you have some fundamental misunderstandings about variables in Python. " You didn't completely explain how the global namespace becomes writeable ? or re-bindeable ? (It seems not necessary to explain it you implement the constant idea, as explained above already). Do I have to assume that global namespace is "re-bindeable" = writeable ? " You keep saying things like "writing to a variable" or "declared variables" which just don't apply to Python because that's not how Python variables work. It may appear this way on the surface, but the differences are subtle yet important. Namespaces are written to, not variables, some objects can be mutated. Names are bound to objects, but variables are not declared, as a name can be bound to an object of any type. " Well again you didn't explain how using namespaces suddenly lead to "rewritable" and/or "rebinding" if A is declared as global as follows: global A and then code is written as follows: A = 10 A = 20 def Test() global A = 30 return How does this make A "rewriteable" ? Or "rebindable" to 30 ? " Namespaces are powerful constructs that give Python much of its dynamic nature and expressivity. Learn to use them! " I didn't learn anything from this posting, sorry ! ;) Bye, Skybuck. From breamoreboy at yahoo.co.uk Sat Sep 12 01:25:37 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 06:25:37 +0100 Subject: Python handles globals badly. In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: On 12/09/2015 06:07, Random832 wrote: > Mark Lawrence writes: >> How do I access these pointers? Is there a builtin called pointer() >> that's analogous to id()? > > You access them *all the time*. They are the *only* thing you access. > > But if you want... pointer = lambda x: return x > >> I'll ask again, where do pointers come into >> the Jython and IronPython models? How do I access their pointers, the >> same builtin? The fact that the underlying implementation language >> has some terminology that it uses, has no bearing on the actual >> language being implemented. > > I am not using "pointer" as language-specific terminology, I am using it > as *the* name of the concept we are talking about. The Java and .NET > runtimes *don't* use that terminology, but they still *actually* have > pointers, in the same way that Python does. > Let's put it another way, in the 15 years I've been using Python I do not recall any experienced Python programmer using "pointer", so what makes you think, in 2015, that you are correct and everybody else is wrong? I still say that everything in Python is an object, and should add that it has one or more things, "names", that are associated with it. Hence my preferred analogy about the sticky note. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From random832 at fastmail.com Sat Sep 12 01:35:12 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 01:35:12 -0400 Subject: Python handles globals badly. References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: Mark Lawrence writes: > Let's put it another way, in the 15 years I've been using Python I do > not recall any experienced Python programmer using "pointer", so what > makes you think, in 2015, that you are correct and everybody else is > wrong? I still say that everything in Python is an object, and should > add that it has one or more things, "names", that are associated with > it. Hence my preferred analogy about the sticky note. So is player3[3] also a name, a sticky note? What if we copy player3 to another name; does it get two sticky notes, player3[3] and foo[3]? Your "sticky note" analogy doesn't unify variables/names/whatever you want to call them with other places that you can assign stuff to, and it implies that the objects themselves have knowledge of their "names", and that names are global (if I have two functions each with a result variable, does that mean there are two different result sticky notes?) It doesn't matter that a pointer isn't what it's *called*, it's what it *is*. And it's not an object, because you can copy it to more than one place with only one object. From miki.tebeka at gmail.com Sat Sep 12 01:41:39 2015 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Fri, 11 Sep 2015 22:41:39 -0700 (PDT) Subject: numpy In-Reply-To: References: Message-ID: On Thursday, September 10, 2015 at 1:11:59 PM UTC+3, chen... at inhand.com.cn wrote: > hi: > I have to use numpy package. My python runs on my embedded arm > device. So, how do i cross compile numpy? conda has support for ARM - http://continuum.io/blog/new-arch BTW: I suggest you write a better subject next time, almost missed this one :) http://www.catb.org/esr/faqs/smart-questions.html From random832 at fastmail.com Sat Sep 12 01:42:43 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 01:42:43 -0400 Subject: Terminology: =?utf-8?B?4oCccmVmZXJlbmNl4oCd?= versus =?utf-8?B?4oCccG9pbnRlcuKAnQ==?= References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> Message-ID: Ben Finney writes: > The reference value is inaccessible to the program, it can only be used > to get at the referenced object. That's like saying an integer is inaccessible since it can only be used to add/subtract/etc (list of all operations you can do with an integer). What does it mean to access something, if not to do some operation on it? Getting the referenced object is the operation you can do with it. >> > So in Python, we don't have pointers because we don't have access to >> > change or reassign them. >> >> Yes you do. That's _exactly what happens_ in an assignment statement - >> you are reassigning it to the address of another object. And that's >> something you *can't do* with references in C++. > > The operation you describe doesn't change the reference; it doesn't > mutate an existing value which can be compared with whatever value it > had before. Instead, it throws away one reference and replaces it with a > different one. So, if you have a list x, and assign a new value to x[0], it doesn't change the list, because you can't compare the list to the value the list had before? You're not making any sense. It's a value. Changing it and "throwing away and replacing with a different one" are the same thing. > That's significant, because unlike a mutable value you can never again > get at the old reference in the Python program. I don't understand what you mean by "can never again get at" it if you think you _can_ do it for mutable values. >> > You can't, for example, keep the old reference (there are no references >> > to references in Python), because they're not accessible as values in >> > themselves. Once you assign a different reference, the old one is gone >> > and can't be found again. >> >> You can keep it by copying it to somewhere. > > How do you propose to ?copy? a reference in Python? Making a new > reference to the referenced object is not making a copy of the > reference. Yes it is. I don't know why you think it's not, so I can't even figure out how to respond to this. From breamoreboy at yahoo.co.uk Sat Sep 12 01:54:06 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 06:54:06 +0100 Subject: Python handles globals badly. In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: On 12/09/2015 06:35, Random832 wrote: > Mark Lawrence writes: >> Let's put it another way, in the 15 years I've been using Python I do >> not recall any experienced Python programmer using "pointer", so what >> makes you think, in 2015, that you are correct and everybody else is >> wrong? I still say that everything in Python is an object, and should >> add that it has one or more things, "names", that are associated with >> it. Hence my preferred analogy about the sticky note. > > So is player3[3] also a name, a sticky note? What if we copy player3 to > another name; does it get two sticky notes, player3[3] and foo[3]? Your > "sticky note" analogy doesn't unify variables/names/whatever you want to > call them with other places that you can assign stuff to, and it implies > that the objects themselves have knowledge of their "names", and that > names are global (if I have two functions each with a result variable, > does that mean there are two different result sticky notes?) > > It doesn't matter that a pointer isn't what it's *called*, it's what it > *is*. And it's not an object, because you can copy it to more than one > place with only one object. > There is NO CONCEPT in Python of a "pointer". player3[3] is the fourth item of a list or similar, or a reference to something in a dictionary, but regardless of the type it is an object that has a name player3. player3 then gets copied to foo. Both names are referring to the same object. It certainly DOES NOT imply anything about objects having knowledge of their names and it DOES NOT say anything about the scope of names. As for "two functions each with a result variable" I haven't the faintest notion what you could be talking about, would you please explain for the benefit of everybody reading this thread. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Sat Sep 12 02:02:35 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Sep 2015 16:02:35 +1000 Subject: =?UTF-8?B?UmU6IFRlcm1pbm9sb2d5OiDigJxyZWZlcmVuY2XigJ0gdmVyc3VzIOKAnHBvaW50ZXI=?= =?UTF-8?B?4oCd?= In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> Message-ID: On Sat, Sep 12, 2015 at 3:03 PM, Random832 wrote: >> You can't, for example, keep the old reference (there are no references >> to references in Python), because they're not accessible as values in >> themselves. Once you assign a different reference, the old one is gone >> and can't be found again. > > You can keep it by copying it to somewhere. The pointer is the value, > not the variable, you don't _need_ a reference to it. CPython happens to implement references using pointers, which leads a lot of people to think that Python's references are pointers in disguise. But Python (the language) does not have any concept of pointers or memory. An integer is not a GNU Multiprecision Bignum object, it is simply an integer. A string is not a series of bytes in Latin-1/UCS-2/UCS-4, it is a series of codepoints. Aside from fiddling around with ctypes (which isn't a supported action), there is nothing you can do within Python to find out what a reference "is"; there is literally ONE operation you can do with a reference, and that's to get at the object it refers to. (For example, you might think that the 'is' operator is comparing two references to see if they point to the same object. In CPython, it probably is implemented as a pointer comparison; but actually, it's comparing two objects to see if they're the same object.) Python does not have pointers, not because you can't do arithmetic on those pointers, but because they do not exist in the language spec. The Python interpreter in my brain, which I use frequently when diagnosing bugs (whether in my own or someone else's code), does not have pointers; I'm not prepared to guarantee that it's 100% compliant with the spec, but I know for sure that it _could be_, without adding any notion of pointers. C has pointers, and still would even pointer arithmetic were disallowed. The languages are architected differently. (Oh, and an object's identity is a special attribute of that object. It's not like its location in memory, which is an attribute of the reference to the object; it's a number that can be retrieved from the object itself.) ChrisA From breamoreboy at yahoo.co.uk Sat Sep 12 02:05:06 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 07:05:06 +0100 Subject: =?UTF-8?B?UmU6IFRlcm1pbm9sb2d5OiDigJxyZWZlcmVuY2XigJ0gdmVyc3VzIA==?= =?UTF-8?B?4oCccG9pbnRlcuKAnQ==?= In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> Message-ID: On 12/09/2015 06:42, Random832 wrote: > Ben Finney writes: >> The reference value is inaccessible to the program, it can only be used >> to get at the referenced object. > > That's like saying an integer is inaccessible since it can only be used > to add/subtract/etc (list of all operations you can do with an > integer). What does it mean to access something, if not to do some > operation on it? Getting the referenced object is the operation you can > do with it. > >>>> So in Python, we don't have pointers because we don't have access to >>>> change or reassign them. >>> >>> Yes you do. That's _exactly what happens_ in an assignment statement - >>> you are reassigning it to the address of another object. And that's >>> something you *can't do* with references in C++. >> >> The operation you describe doesn't change the reference; it doesn't >> mutate an existing value which can be compared with whatever value it >> had before. Instead, it throws away one reference and replaces it with a >> different one. > > So, if you have a list x, and assign a new value to x[0], it doesn't > change the list, because you can't compare the list to the value the > list had before? x still refers to a object which in this case happens to be a list. You've merely changed the value of the first element of the object that is referred to by the name x. > > You're not making any sense. It's a value. Changing it and "throwing > away and replacing with a different one" are the same thing. > >> That's significant, because unlike a mutable value you can never again >> get at the old reference in the Python program. > > I don't understand what you mean by "can never again get at" it if you > think you _can_ do it for mutable values. > >>>> You can't, for example, keep the old reference (there are no references >>>> to references in Python), because they're not accessible as values in >>>> themselves. Once you assign a different reference, the old one is gone >>>> and can't be found again. >>> >>> You can keep it by copying it to somewhere. >> >> How do you propose to ?copy? a reference in Python? Making a new >> reference to the referenced object is not making a copy of the >> reference. > > Yes it is. I don't know why you think it's not, so I can't even figure > out how to respond to this. > No it isn't. When you make a copy of an object you will end up with two names that refer to the same object. >>> x = [1,2,3] >>> y = x >>> x;y [1, 2, 3] [1, 2, 3] >>> del x >>> y [1, 2, 3] If y was a copy of x, then when x is blown away how can y still know about the list that x originally referred to? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Sat Sep 12 02:13:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Sep 2015 16:13:06 +1000 Subject: Python handles globals badly. In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: On Sat, Sep 12, 2015 at 3:35 PM, Random832 wrote: > Mark Lawrence writes: >> Let's put it another way, in the 15 years I've been using Python I do >> not recall any experienced Python programmer using "pointer", so what >> makes you think, in 2015, that you are correct and everybody else is >> wrong? I still say that everything in Python is an object, and should >> add that it has one or more things, "names", that are associated with >> it. Hence my preferred analogy about the sticky note. > > So is player3[3] also a name, a sticky note? What if we copy player3 to > another name; does it get two sticky notes, player3[3] and foo[3]? Your > "sticky note" analogy doesn't unify variables/names/whatever you want to > call them with other places that you can assign stuff to, and it implies > that the objects themselves have knowledge of their "names", and that > names are global (if I have two functions each with a result variable, > does that mean there are two different result sticky notes?) Whatever you want to use to describe a name-binding reference, the exact same thing applies to a list element or anything else. If your analogy is strings tied to sheets of paper, with sticky notes on the ends of strings to represent actual names, then you have similar strings connecting list elements to their referents. (The sticky notes aren't actually part of the objects, and you just have to understand that you can't trace a string "backwards", only "forwards"; there's no way to start with an object and ask "what refers to this?".) Here. Ned Batchelder explains it better than I can. http://nedbatchelder.com/text/names1.html https://www.youtube.com/watch?v=_AEJHKGk9ns ChrisA From random832 at fastmail.com Sat Sep 12 02:15:40 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 02:15:40 -0400 Subject: Terminology: =?utf-8?B?4oCccmVmZXJlbmNl4oCd?= versus =?utf-8?B?4oCccG9pbnRlcuKAnQ==?= References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> Message-ID: Mark Lawrence writes: > No it isn't. When you make a copy of an object you will end up with > two names that refer to the same object. No, when you *make a copy of* an object, you get two objects. >>> x = [1, 2, 3] >>> y = copy.copy(x) >>> x is y False What you make a copy of when you do y = x is not the object. > If y was a copy of x, then when x is blown away how can y still know > about the list that x originally referred to? Because what is in x, and therefore what is copied when you assign y = x, *is* the knowledge of how to find the list. Not the list itself. The object is also not what is deleted when you delete it. And deleting the original does not delete a copy and I don't even understand how you can possibly think it could. From random832 at fastmail.com Sat Sep 12 02:25:01 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 02:25:01 -0400 Subject: Python handles globals badly. References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: Chris Angelico writes: > Here. Ned Batchelder explains it better than I can. See, those diagrams are perfect (well, almost, I think the names should have square boxes too). They're arrows. They *point* at things. *Pointers*. The boxes are variables. The circles represent special boxes (implemented in C or Java or whatever) that hold things other than pointers and therefore can't be used as Python variables. From ben+python at benfinney.id.au Sat Sep 12 02:26:37 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 12 Sep 2015 16:26:37 +1000 Subject: Terminology: =?utf-8?B?4oCccmVmZXJlbmNl4oCd?= versus =?utf-8?B?4oCccG9pbnRlcuKAnQ==?= References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> Message-ID: <858u8c6tlu.fsf@benfinney.id.au> Random832 writes: > Ben Finney writes: > > The reference value is inaccessible to the program, it can only be > > used to get at the referenced object. > > What does it mean to access something, if not to do some operation on > it? Getting the referenced object is the operation you can do with it. You've clearly committed to some ontology that just doesn't match the Python data model. The following are some of the axioms in Python's data model: * All values are objects that persist over time. * All objects have an immutable identity, that is guaranteed different from all other coexisting objects. * The identity of an object has no particular relationship to the object's implementation or location [0], it is an abstract value that has no meaning other than uniquely identifying the object. * The ?id? function returns the identity of the object passed as the parameter to the call. * A name used to access an object is a reference to that object, equivalent to an item in a dictionary. * A collection instance ? a list, a dict, a set, etc. ? contains references to objects, and provide access to those references via the container type's API. If you don't agree with those, that's too bad, and it means there's not much point continuing the discussion. I hope, therefore, that you do agree with those axioms. If you do agree with those, some corollaries follow: * Container types do not contain objects. It is a useful analogy to say the objects are ?in? the container; but that would imply they are not simultaneously in any other container. That's not true, so it's a flawed (though very useful) analogy. * Names do not contain anything. They aren't what some other languages call ?variables?. They are oblivious to the type of the value and can never exist except while referencing some object. * References are not values. The reference obviously must have an implementation that deals with values, but those values are not available in Python. Each reference is inaccessible, hidden away; it is not a value, it is not an object. > So, if you have a list x, and assign a new value to x[0], it doesn't > change the list, because you can't compare the list to the value the > list had before? Yes, it changes the list. It doesn't change any of the references themselves. The list's value is the sequence of references it contains. Removing one reference changes the list's value; putting a different reference in the collection changes the list's value. None of that changes any reference, it just changes *which* references are in the list. The references themselves don't have any value accessible to Python. > You're not making any sense. It's a value. Changing it and "throwing > away and replacing with a different one" are the same thing. Not true. To throw away one and replace it with another is to switch to a different value with a different identity:: >>> foo = 17 # One reference to the integer object. >>> bar = foo # A different reference to the object. >>> id(foo) == id(bar) # Are these references to the same object? True >>> bar = 9 # Try to ?change? the object. >>> id(foo) == id(bar) # Is ?bar? still the same object? False To change a value is to keep the same identity:: >>> foo = [17, 23, 42] # One reference to the list object. >>> bar = foo # A different reference to the object. >>> id(foo) == id(bar) # Are these references to the same object? True >>> id(foo[2]) == id(bar[2]) # How about the references contained in the list? True >>> bar[2] = 9 # Try to ?change? the object. >>> id(foo) == id(bar) # Is ?bar? still the same object? True References aren't values, so their identity doesn't even feature in Python's data model. >From the point of view of a Python program, a reference *has no value* (and no identity). It is just a metaphorical label, tag, or ?sticky note? one can invoke to make a specific object available. > > That's significant, because unlike a mutable value you can never > > again get at the old reference in the Python program. > > I don't understand what you mean by "can never again get at" it if you > think you _can_ do it for mutable values. In the above example, the different references originally created for ?foo? and ?bar? are inaccessible. ?foo? and ?bar? are not the same, they are different references that happen to lead to the same object. When ?bar? switches to a different reference, whatever reference it had at prior points in time are gone for good. Any other references to the same object continue on unaffected, because they are not the same reference. [0]: This axiom is unfortunately confused in the documentation's statement ?you may think of it as the object?s address in memory? . That's not a guarantee of the data model, it is merely meant to help the reader understand the concept. Note that the documentation deliberately does *not* say the identity is the object's address in memory except as a note about the *implementation* in CPython. That is not part of the data model. -- \ ?It is well to remember that the entire universe, with one | `\ trifling exception, is composed of others.? ?John Andrew Holmes | _o__) | Ben Finney From rosuav at gmail.com Sat Sep 12 02:27:46 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Sep 2015 16:27:46 +1000 Subject: Python handles globals badly. In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Message-ID: On Sat, Sep 12, 2015 at 4:25 PM, Random832 wrote: > Chris Angelico writes: >> Here. Ned Batchelder explains it better than I can. > > See, those diagrams are perfect (well, almost, I think the names should > have square boxes too). They're arrows. They *point* at > things. *Pointers*. > > The boxes are variables. The circles represent special boxes > (implemented in C or Java or whatever) that hold things other than > pointers and therefore can't be used as Python variables. Okay, okay, you've won. They're pointers. Now, try to do anything with them. They *instantly* devolve to their referent objects, which means you cannot do anything with the pointer at all. Congratulations, pointers do not exist. ChrisA From rosuav at gmail.com Sat Sep 12 02:31:16 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 12 Sep 2015 16:31:16 +1000 Subject: =?UTF-8?B?UmU6IFRlcm1pbm9sb2d5OiDigJxyZWZlcmVuY2XigJ0gdmVyc3VzIOKAnHBvaW50ZXI=?= =?UTF-8?B?4oCd?= In-Reply-To: <858u8c6tlu.fsf@benfinney.id.au> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <858u8c6tlu.fsf@benfinney.id.au> Message-ID: On Sat, Sep 12, 2015 at 4:26 PM, Ben Finney wrote: > If you do agree with those, some corollaries follow: > > * Container types do not contain objects. > > It is a useful analogy to say the objects are ?in? the container; but > that would imply they are not simultaneously in any other container. > That's not true, so it's a flawed (though very useful) analogy. It's so useful that we have an operator called "in", implemented using a magic method "__contains__", to test exactly that concept. As long as you understand that containment here really means something more like "is accessible from", it's correct. Flawed in a minor way, but so extremely convenient that it's not worth going for complete technical correctness. ChrisA From dieter at handshake.de Sat Sep 12 02:36:37 2015 From: dieter at handshake.de (dieter) Date: Sat, 12 Sep 2015 08:36:37 +0200 Subject: From logging to files to a better solution: syslog, Sentry, Logstash, .... References: <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> Message-ID: <87egi42lfu.fsf@handshake.de> Thomas G?ttler writes: > Am Donnerstag, 10. September 2015 08:42:47 UTC+2 schrieb dieter: >> Thomas G?ttler writes: >> > ... >> > Why we are unhappy with logging to files: >> > >> > - filtering: We don't want to get INFO messages over the VPN. >> >> You can quite easily control at what level messages are logged with >> the standard Python logging framework. Each handler has a level >> and will ignore messages at a lower level. > > > I want INFO to be logged and stored on the remote host. > Therefore I must not filter INFO messages. > > I don't want to pull INFO messages over the VPN. Thus, you could define one handler which logs at INFO level and another one which logs at WARNING level. The latter handler would log only WARNING and more serious events. > ... > Yes, there are tools to parse that soup. But why create this soup in > the first place? > > That's why I want to move from file based logging to a different solution. As you have explained above, you need this "soup" (both INFO messages as well as messages above WARNING level - but handled differently). Define an additional handler which handles "WARNING" (and above). This is easy with Zope (I do not know for Django). > Unfortunately there too many choices (graylog, logstash, sentry, ...) :-( I do not know any of them - but I doubt that they will help you much to untangle your "soup". From steve at pearwood.info Sat Sep 12 03:00:39 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 12 Sep 2015 17:00:39 +1000 Subject: Python handles globals badly. References: <55f293da$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f3cd96$0$1655$c3e8da3$5496439d@news.astraweb.com> On Sat, 12 Sep 2015 01:03 am, Ian Kelly wrote: > On Fri, Sep 11, 2015 at 2:42 AM, Steven D'Aprano > wrote: [...] >> Almost. If it's never assigned within the function, then it is looked up >> according to the non-local scoping rules: >> >> - closures and enclosing functions (if any); >> - globals; >> - builtins; >> >> in that order. > > I excluded non-locals intentionally, but if you want to be pedantic > about it, then that's still not quite right. Non-locals are indeed > identified by the compiler and compiled with the > LOAD_DEREF/STORE_DEREF opcodes (rather than the _GLOBAL and _FAST > variants used by globals and locals, respectively). Ah, nice, yes I forgot about that, thanks for the correction. > The compiler > doesn't make any such distinction between globals and builtins > however, as that can only be determined at run-time. > >> There's also a bunch of specialised and complicated rules for what >> happens if you make a star import ("from module import *") inside a >> function, or call eval or exec without specifying a namespace. Both of >> these things are now illegal in Python 3. > > Huh? > >>>> exec("x = 42") >>>> x > 42 >>>> exec("x = 43", None, None) >>>> x > 43 > > That's in Python 3.4.0. Maybe I don't understand what you mean by > "without specifying a namespace". Inside a function star imports are illegal in Python 3: py> def f(): ... from math import * ... File "", line 1 SyntaxError: import * only allowed at module level My recollection was incorrect about exec. You can still exec inside a function, but it may have no effect: py> def f(): ... x = 1 ... exec("x = 2") ... return x ... py> f() 1 You can specify locals, but it doesn't help: py> def f(): ... x = 1 ... exec("x = 2", globals(), locals()) ... return x ... py> f() 1 However, in Python 2, Python tried hard to make exec work: py> def f(): ... x = 1 ... exec("x = 2") ... return x ... py> f() 2 I don't recall all the details, but in Python 2 functions could use two different schemes for local variables: the regular, optimized one using memory slots, and a dict-based one that came into play with exec. So we have this: py> def g(): ... a = 1 ... exec("b = 2") ... return (a, b) ... py> dis.dis(g) 2 0 LOAD_CONST 1 (1) 3 STORE_FAST 0 (a) 3 6 LOAD_CONST 2 ('b = 2') 9 LOAD_CONST 0 (None) 12 DUP_TOP 13 EXEC_STMT 4 14 LOAD_FAST 0 (a) 17 LOAD_NAME 0 (b) 20 BUILD_TUPLE 2 23 RETURN_VALUE `a` is a regular, optimized local looked up with LOAD_FAST; but `b` gets the same old LOAD_NAME used for globals and built-ins. In Python 3.3, that same function uses LOAD_GLOBAL for `b`, even though the variable does actually exist: py> dis.dis(g) 2 0 LOAD_CONST 1 (1) 3 STORE_FAST 0 (a) 3 6 LOAD_GLOBAL 0 (exec) 9 LOAD_CONST 2 ('b = 2') 12 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 15 POP_TOP 4 16 LOAD_FAST 0 (a) 19 LOAD_GLOBAL 1 (b) 22 BUILD_TUPLE 2 25 RETURN_VALUE py> g() Traceback (most recent call last): File "", line 1, in File "", line 4, in g NameError: global name 'b' is not defined The conclusion I draw from all this is that the rules governing local variables in Python are a mess :-) -- Steven From jonas at wielicki.name Sat Sep 12 04:51:30 2015 From: jonas at wielicki.name (Jonas Wielicki) Date: Sat, 12 Sep 2015 10:51:30 +0200 Subject: Python handles globals badly. In-Reply-To: References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> Message-ID: <55F3E792.6010404@wielicki.name> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 On 08.09.2015 16:31, Ian Kelly wrote: > On Tue, Sep 8, 2015 at 5:55 AM, Vladimir Ignatov > wrote: >>> I had some experience programming in Lua and I'd say - that >>> language is bad example to follow. Indexes start with 1 (I am >>> not kidding) >> >> What is so bad about that? > > It's different from the rest 99.9% of languages for no particular > reason. It's not "different from the rest 99.9% of languages". > There are many languages that use 1-based indexing, e.g. Matlab, > Pascal, Fortran. To be fair, that is not entirely true. In Pascal, there are three cases (you can argue that this doesn?t improve anything): (a) statically allocated arrays where the programmer chooses the bounds, e.g. const InBitData: array [1..4] of Integer = (128, 32, 16, 64); (b) strings, which start at 1, as historically, the length of the string was stored at position 0; pascal uses length-delimiting instead of NUL-delimiting. (c) dynamically allocated arrays which always start at 0. So let aside the historical cruft from Strings, Pascal uses zero-based indexing unless told otherwise. regards, jwi -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCgAGBQJV8+eJAAoJEMBiAyWXYliKe4gP/ipqzEWQvp3jDwINm8Ofdlpc 4ngOlwUQxAo25DNPG1qnT06iRj+CN5wpJDr5CgYW0Hb6nkoLzlJG6XDqK7S3BAQy msTvDlZFwnWEJ7AQcLP1RCYNy1Z0O9j+/XAEWD7wDk02wlZnEtrIWXGvxpR98fjx HOKLxHHEQsi4+qhgpQJzqXHEi5UozN52f6AC1B7JGAwueCx8+gjAeIGHwcYQXFRZ L78pBRZQpwoLBumylShUOO8HvouHSyRwfMF+we907oDAgWREnmwu82Q2jOHqAPXt UDMlyi2hueQXNvJFTqCfdkOAEcDk/Jn2Agx7w5A5k2oHptK8uwS+2/SghmPwPZuh G+Gqi5+FxSEkQDJBvsU9dUwCy/OIBm2kxGlaVB+MRN8LxvLVYsx5DdZbIlce9VVn SrehJPo6TnFBsgpRsjr9Ahpnmh769ej/jcyfKDgYb6tXW0XANlPUQ/nGxtNES4hJ l7ds3VE/n91WU/cQlTKB9EviteMDit0iqYRlPOwV1QPNWx0z2a+/nMGyRH/Baaqj r1rdmzWkks+vMmkYd8Yl+IlHmnWUBM/gI4qh9I1mA+iyH/n/Se9SdSISLqmccdoB 0ph1UmM3Tz/vGvguVdaF8WJzpL2sdtaR4ibjeN5IhYyhzREOFnJkKvofxfYNm3TF kCSAK5/Q6qPg4s9X2nCt =KixQ -----END PGP SIGNATURE----- From oudou78 at gmail.com Sat Sep 12 05:36:34 2015 From: oudou78 at gmail.com (oudou78 at gmail.com) Date: Sat, 12 Sep 2015 02:36:34 -0700 (PDT) Subject: Wholesale Sports Shoes Clear Air Force One AAA++quality(www.cnnshoe.com) In-Reply-To: <74294e2e-5b43-4731-8a40-8b33b87d6980@w15g2000pro.googlegroups.com> References: <74294e2e-5b43-4731-8a40-8b33b87d6980@w15g2000pro.googlegroups.com> Message-ID: <4ff98f9e-0af2-41c7-b837-7922e8f2600c@googlegroups.com> What is the new adrss From lac at openend.se Sat Sep 12 05:56:00 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 12 Sep 2015 11:56:00 +0200 Subject: monospaced font in MS Windows with wxpython In-Reply-To: References: Message-ID: <201509120956.t8C9u0P6029136@fido.openend.se> In a message of Fri, 11 Sep 2015 22:16:36 -0000, Javier writes: >I am trying to use a monospaced font (preferably small) in MS Windows >with wxpython. I have tried > >txtctrl.SetFont(wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Consolas')) > >but no success, I still get a proportional font. > >-- >https://mail.python.org/mailman/listinfo/python-list wxpython has its own mailing lists where the response might be better: http://www.wxpython.org/maillist.php Laura From rustompmody at gmail.com Sat Sep 12 08:46:35 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 12 Sep 2015 05:46:35 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> Message-ID: On Saturday, September 12, 2015 at 11:57:01 AM UTC+5:30, Ben Finney wrote: > Random832 writes: > > > Ben Finney writes: > > > The reference value is inaccessible to the program, it can only be > > > used to get at the referenced object. > > > > What does it mean to access something, if not to do some operation on > > it? Getting the referenced object is the operation you can do with it. > > You've clearly committed to some ontology that just doesn't match the > Python data model. How about lay-English ontology in which "point to" and "refer to" are fairly synonymous? From lac at openend.se Sat Sep 12 10:41:06 2015 From: lac at openend.se (Laura Creighton) Date: Sat, 12 Sep 2015 16:41:06 +0200 Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> Message-ID: <201509121441.t8CEf664002104@fido.openend.se> In a message of Sat, 12 Sep 2015 05:46:35 -0700, Rustom Mody writes: >How about lay-English ontology in which "point to" and "refer to" are fairly >synonymous? This I have found is important in teaching, which is why I favour 'bind' and 'binding' -- rather than pointer, pointer, refer to, referring. However, the problem that even people who have never used C, and probably have never read about it, either (children) really want a word that means 'when I use this name I get this physical chunk of memory, over there' cannot be completely defeated with this simple language change. I know kids who think that python variable names bind to actual physical chunks of their memory sticks, because they haven't got around to understanding what RAM is, yet. On the other hand, being able to say 'Right. You are a garbage collector. Because only garbage collectors need to care about such things.' makes for a pretty memorable lesson. Laura From rustompmody at gmail.com Sat Sep 12 11:13:40 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 12 Sep 2015 08:13:40 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> Message-ID: <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> On Saturday, September 12, 2015 at 8:11:49 PM UTC+5:30, Laura Creighton wrote: > In a message of Sat, 12 Sep 2015 05:46:35 -0700, Rustom Mody writes: > >How about lay-English ontology in which "point to" and "refer to" are fairly > >synonymous? > > This I have found is important in teaching, which is why I favour 'bind' > and 'binding' -- rather than pointer, pointer, refer to, referring. Well we can play humpty dumpty and make any word mean whatever we like. However if you are a teacher you will recognize a need for pictures. And (as far as I can tell) "Random832" finds a need for the box-n-arrow diagrams of classic data-structure books From marfig at gmx.com Sat Sep 12 11:52:50 2015 From: marfig at gmx.com (Mario Figueiredo) Date: Sat, 12 Sep 2015 16:52:50 +0100 Subject: Python handles globals badly. In-Reply-To: References: <1eee075d-7073-4875-9e42-2e053ee59b41@googlegroups.com> <0784va15gme91mqvoasfub3hvu59ehpepl@4ax.com> <201509102219.14138.gheskett@wdtv.com> <55F3A602.50906@gmx.com> Message-ID: <55F44A52.5010002@gmx.com> On 12-09-2015 05:38, Mark Lawrence wrote: > > Nothing to do with this being untested software then? Actually it was > so I'd put that down to a programmer error. "The code always worked > before so it's bound to work this time". Such a pity that this > particular launch wasn't the same as anything done previously. I am not even sure what you are saying. Can't be that C++ bugs are not not caused by programmer errors. Because C++ is actually used in numerous mission critical systems. But anyways. If you are that scared of C++ it is indeed best you don't fly. From rurpy at yahoo.com Sat Sep 12 12:17:07 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 12 Sep 2015 09:17:07 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> Message-ID: <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> Picking a post to respond to, more or less at random... On Saturday, September 12, 2015 at 9:14:00 AM UTC-6, Rustom Mody wrote: > On Saturday, September 12, 2015 at 8:11:49 PM UTC+5:30, Laura Creighton wrote: > > In a message of Sat, 12 Sep 2015 05:46:35 -0700, Rustom Mody writes: > > >How about lay-English ontology in which "point to" and "refer to" are fairly > > >synonymous? > > > > This I have found is important in teaching, which is why I favour 'bind' > > and 'binding' -- rather than pointer, pointer, refer to, referring. > > Well we can play humpty dumpty and make any word mean whatever we like. > However if you are a teacher you will recognize a need for pictures. > And (as far as I can tell) "Random832" finds a need for the box-n-arrow > diagrams of classic data-structure books *The* python data model is a concept that, like all concepts, exist in human brains. It (and its related terminology) are descriptions agreed upon by a majority of Python developers, documentors and others. Its purpose is to explain in a simpler way the behavior of a running Python program. [*] It is only one of many possible descriptions. Its value is measured in how well and efficiently it allows Python programmers to predict the behavior of a Python program. I never found its presentation in the Python documentation very understandable or helpful. Having programmed in C in the past, the model of Python I eventually developed is very much (I think, haven't read the whole thread) like Random832's. I think of boxes (objects) with slots containing "pointers" that "point" to other boxes. Even today when dealing with complex Python data structures, I draw boxes and arrows to help me understand them and think of the arrows as "pointers". Frankly, I feel a little insulted by people who presume that having learned what a pointer is in C, that my brain is so rigid that I must necessarily think that pointer means exactly what pointer means in C forever after. FYI (the general you), I am capable of extracting the general principle and applying it to Python. Not just capable, but using the concept from C made understanding Python faster than pretending that somehow Python has some magical and unique way of structuring data that's brand new. Maybe pedagogical research will show that one particular model is more easily understood by python learners that some other model. But please keep in mind that learners come in many varieties and that one size will not fit all. Knowing what a pointer is in C and applying the concept to model python worked well for me and I would have no hesitation offering it as an explanation to others as an option to help someone else's understanding if they, like me, find the official model less then helpful. ---- [*] There is also possibly a "data model" used in specifying the Python language for implementors but this thread seems to be about how to describe Python's behavior to users. From steve at pearwood.info Sat Sep 12 12:32:22 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 13 Sep 2015 02:32:22 +1000 Subject: Terminology: =?UTF-8?B?4oCccmVmZXJlbmNl4oCdIHZlcnN1cyDigJxwb2ludGVy4oCd?= References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> Message-ID: <55f45396$0$1660$c3e8da3$5496439d@news.astraweb.com> On Sat, 12 Sep 2015 02:42 pm, Random832 wrote: > Anyway, maybe we do need a term to distinguish Python/C#/Java pointers > from C/C++ pointers - maybe call it a "non-arithmetic" pointer, since > the key thing about it is you can't do pointer arithmetic on them to get > the object "next to" the one it points at. How about *just don't call them pointers*? You know, since they aren't pointers in the computer science sense. The Free On-line Dictionary of Computing defines "pointer": 1. An address, from the point of view of a programming language. A pointer may be typed, with its type indicating the type of data to which it points. Arithmetic is irrelevant to the definition of "pointer". That's a foible of C, not fundamental to the concept of pointer. Pascal, for example, has pointers too, implemented pretty much in the same way as C/C++, but the type system doesn't allow you to perform arithmetic on them because they aren't treated as integers. Computer science and IT is *dominated* by a single usage for "pointer" -- it's an abstract memory address. The fundamental characteristics of pointers are: - they are first-class values; you can assign a pointer to a variable; - you can dereference a pointer: get the value pointed to; - (in some languages) you can get a pointer to a specific variable (possibly an unnamed, dynamic variable allocated in the heap rather than a named, statically allocated variable). The last two imply that the language must be one where values have fixed addresses, not just as a matter of implementation, but as a matter of language semantics. If they are free to move, they cannot have a fixed address. Python, Java, Ruby, Lua, Javascript etc. have *no such concept* as pointer. There are no values in these languages which correspond to the standard definition of pointer: - you cannot get a pointer to an object or a variable (a name); - since there are no pointers, you cannot dereference them; - or assign them to a variable. Since pointers can be considered an indirect reference to a value, what sort of indirect references does Python have? The simplest thing in Python that is somewhat analogous to a pointer is a *name*, since names allow you to indirectly refer to some value: x = 23 print(x) # prints the value referred to by x, not "x" itself. ptr = "x" # equivalent to "the address of x" y = globals()[ptr] # equivalent to dereferencing Note that names are not first-class values in Python: there is no Name type, and you cannot bind a name to a variable, you have to use a string. It's not a very close analogy, but it's the closest Python has. Implementations of Python, Javascript, Lua, Java, Ruby etc. *may or may not* use pointers in the implementation, but they are not part of the language interface. These languages have no "addressof" operator, no dereference operator, and no "pointer" type; values do not necessarily have fixed addresses (indeed, in Jython and IronPython, values can move in memory). Insisting that Python has pointers is like insisting that you use a text editor by flipping bits. "What happens if I press Ctrl-X?" "Well, these bits on the screen flip from black to white, these bits flip from white to black, and these stay the same." -- Steven From steve at pearwood.info Sat Sep 12 12:50:53 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 13 Sep 2015 02:50:53 +1000 Subject: Terminology: =?UTF-8?B?4oCccmVmZXJlbmNl4oCdIHZlcnN1cyDigJxwb2ludGVy4oCd?= References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> Message-ID: <55f457ec$0$1675$c3e8da3$5496439d@news.astraweb.com> On Sat, 12 Sep 2015 03:03 pm, Random832 wrote: > Yes I am. You're just making the implicit assumption that a "value" has > to be a number, and I was ignoring that assumption. The value is the > address of an object. The unknown, unknowable, and in fact possibly non-existent address of an object. There is nothing about the Python language which demands that objects have addresses. We could build a Python interpreter using a giant clockwork mechanical computing machine, like the Difference Engine only much more complex, and it would not have addressable objects. If you would prefer a more practical counter-example, we can simulate a Python interpreter in our head (at least for short programs). Again, there is no addressable memory in the human brain, and hence the objects have no address. But for the sake of the argument, let's suppose you are right, and that Python values are "the address of the object". Given: x = "blue cats eat green mice" I would say that the value of x is the string "blue cats eat green mice". You, apparently, believe that the value of x is 0xb7aea480. Or possibly 0xb43384aa. Or whatever address the interpreter happens to give you on this specific run of your program. This abuse of the word "value" is sheer balderdash. To quote Fredrik Lundh: well, I guess you can, in theory, value an artificial number assigned to an object as much as the object itself. "Joe, I think our son might be lost in the woods" "Don't worry, I have his social security number" http://effbot.org/zone/call-by-object.htm. Python values are not addresses. Python values are objects. Addresses, even when they exist, are not accessible in the Python language. -- Steven From rustompmody at gmail.com Sat Sep 12 12:54:24 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 12 Sep 2015 09:54:24 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <55f45396$0$1660$c3e8da3$5496439d@news.astraweb.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <55f45396$0$1660$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1dabdb08-2aee-4a53-bb57-1410edd372f6@googlegroups.com> On Saturday, September 12, 2015 at 10:02:40 PM UTC+5:30, Steven D'Aprano wrote: > On Sat, 12 Sep 2015 02:42 pm, Random832 wrote: > > > Anyway, maybe we do need a term to distinguish Python/C#/Java pointers > > from C/C++ pointers - maybe call it a "non-arithmetic" pointer, since > > the key thing about it is you can't do pointer arithmetic on them to get > > the object "next to" the one it points at. > > How about *just don't call them pointers*? You know, since they aren't > pointers in the computer science sense. > > The Free On-line Dictionary of Computing defines "pointer": > > 1. An address, from the point of view of a > programming language. A pointer may be typed, with its type > indicating the type of data to which it points. > Insisting that Python has pointers is like insisting that you use a text > editor by flipping bits. "What happens if I press Ctrl-X?" "Well, these > bits on the screen flip from black to white, these bits flip from white to > black, and these stay the same." > This is from the docs https://docs.python.org/3/library/functions.html#id id(object) Return the "identity" of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. CPython implementation detail: This is the address of the object in memory. From rustompmody at gmail.com Sat Sep 12 13:04:07 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 12 Sep 2015 10:04:07 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <55f457ec$0$1675$c3e8da3$5496439d@news.astraweb.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <55f457ec$0$1675$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Saturday, September 12, 2015 at 10:21:08 PM UTC+5:30, Steven D'Aprano wrote: > Python values are not addresses. Python values are objects. Which means for example...??? Atoms? Stars? People? Countries? > Addresses, even when they exist, are not accessible in the Python language. And you claim that these addresses are less accessible to python than the objects above? From python at mrabarnett.plus.com Sat Sep 12 13:05:27 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 12 Sep 2015 18:05:27 +0100 Subject: Python handles globals badly. In-Reply-To: <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> Message-ID: <55F45B57.6090400@mrabarnett.plus.com> On 2015-09-12 06:22, Skybuck Flying wrote: > > > "Michael Torrie" wrote in message > news:mailman.384.1442016089.8327.python-list at python.org... > > On 09/11/2015 03:50 PM, Skybuck Flying wrote: >> Something which python does not seem to do currently ?! >> >> So that's weird. >> >> I will leave it at that for now. > > " > Seems to me you have a completely mistaken understanding of how > variables work in Python. This is one of the reasons why I have said in > the past, erroneously, that Python does not have variables. It does of > course but not in the same way as C or Pascal. In those languages names > are source-code abstractions only, and irrelevant to the compiler and > machine code. C and Pascal define variables as boxes that can be > written to. Not so in Python. > " > > Well you basically said it yourself: > > " irrelevant to the compiler and machine code". > > That's kinda nice about a high level language. > > Programmer does not need to understand anything below the language. > > A python programmer shouldn't need to understand a damn thing to write: > > A = 10 > A = A + 1 > print A > > However for sake of your discussion I will continue your arguments below, > since I get the impression you guys are clueless how to change python > implementation ;) > > " > In Python most common objects are immutable. Meaning they can never > change or be overwritten. They are bound to names. This binding is > what makes names look like and act like traditional variables. > > The secret to understanding the global keyword is to understand how > Python namespaces work. The statement "a=5" does not assign a 5 to the > box called "a." Rather it binds the name "a" to the "5" object, which > is immutable and called into existence by the interpreter > implementation. Subsequently "a=6" disconnects a from the 5 object, > casting the 5 object loose to be reclaimed in some fashion that doesn't > matter at this point. "a" is then rebound to a new object, 6. > " > > What happens for following code: > > A=1234567890111111 > > Are you going to claim it's going to bind to all these numbers and then also > multiple times ? > "all these numbers"? I see only one number there. At runtime, it'll bind the name to the number, putting the pair into a dict. (Actually, in a function, it can determine the names of all of the local variables, so it uses 'slots' instead, as an optimisation.) > Sounds a bit shady ?! ;) > > Perhaps python considers it a string ? > > Python applies math to strings ? > > Sounds a bit slow... therefore perhaps you're wrong... > Why would _he_ be wrong? _He_ never claimed any such thing! > " > When doing a look-up on a name, the interpreter first checks the local > scope's dictionary and if it does not find the name there there, goes to > the outer scope and so forth until you get to the module global > namespace. So we don't need any special keywords to do Pascal-style > constants. We just define them in the module and they work. Usually we > name them in all caps so we have a bit of a convention as to where they > come from. And yes we're talking about looking up strings in a > dictionary here. > " > > So big deal, solution is easy to see, invert interpreter logic: > > Everything declared is "not constant". > > Everything declared as "constant" suddenly becomes constant. > > And thus everything declared as not constant behaves the same way as > "global", problem solved. > > " > When binding a name to an object, the interpreter always binds a name in > the local namespace, unless the global keyword has been used previously > and then it goes right to the global namespace. As has been said > numerous times on this thread, how else would the interpreter do this? > There simply isn't any other way that makes sense. Certainly you haven't > made the case for it, seeing as you have some fundamental > misunderstandings about variables in Python. > " > > You didn't completely explain how the global namespace becomes writeable ? > or re-bindeable ? > > (It seems not necessary to explain it you implement the constant idea, as > explained above already). > > Do I have to assume that global namespace is "re-bindeable" = writeable ? > > " > You keep saying things like "writing to a variable" or "declared > variables" which just don't apply to Python because that's not how > Python variables work. It may appear this way on the surface, but the > differences are subtle yet important. Namespaces are written to, not > variables, some objects can be mutated. Names are bound to objects, but > variables are not declared, as a name can be bound to an object of any type. > " > > Well again you didn't explain how using namespaces suddenly lead to > "rewritable" and/or "rebinding" > Namespaces don't "become writeable". The purpose of "global" is to tell the compiler that this name should be bound in the global namespace, not the local namespace. > if A is declared as global as follows: > > global A > > and then code is written as follows: > > A = 10 > A = 20 > > def Test() > global A = 30 > return > > How does this make A "rewriteable" ? Or "rebindable" to 30 ? > > " > Namespaces are powerful constructs that give Python much of its dynamic > nature and expressivity. Learn to use them! > " > > I didn't learn anything from this posting, sorry ! ;) > From rosuav at gmail.com Sat Sep 12 13:06:28 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 13 Sep 2015 03:06:28 +1000 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <1dabdb08-2aee-4a53-bb57-1410edd372f6@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <55f45396$0$1660$c3e8da3$5496439d@news.astraweb.com> <1dabdb08-2aee-4a53-bb57-1410edd372f6@googlegroups.com> Message-ID: On Sun, Sep 13, 2015 at 2:54 AM, Rustom Mody wrote: >> Insisting that Python has pointers is like insisting that you use a text >> editor by flipping bits. "What happens if I press Ctrl-X?" "Well, these >> bits on the screen flip from black to white, these bits flip from white to >> black, and these stay the same." >> > > This is from the docs > https://docs.python.org/3/library/functions.html#id > > id(object) > > Return the "identity" of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. > > CPython implementation detail: This is the address of the object in memory. *Python* does not have addresses. *CPython* is an implementation of the Python language which uses memory. Jython uses Java objects, and thus doesn't have memory addresses. PyPy doesn't keep things at fixed locations in memory, and maintains a separate concept of object identities, even though it is implemented using some form of system memory. Python does not have pointers or addresses. ChrisA From steve at pearwood.info Sat Sep 12 13:08:31 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 13 Sep 2015 03:08:31 +1000 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> Message-ID: <55f45c0f$0$1671$c3e8da3$5496439d@news.astraweb.com> On Sat, 12 Sep 2015 10:46 pm, Rustom Mody wrote: > On Saturday, September 12, 2015 at 11:57:01 AM UTC+5:30, Ben Finney wrote: >> You've clearly committed to some ontology that just doesn't match the >> Python data model. > > How about lay-English ontology in which "point to" and "refer to" are > fairly synonymous? "Pointer" in English is also a synonym for - a type of dog; - an instrument which pierces (as used by engravers, lace workers, etc); - an item of private information; - a hint or tip; - a caution or warning; - a recommendation; - the index finger; - a cricketer fielding at a specific position; - the hour/minute/second hand on a timepiece; - a compass needle; - two specific stars in the constellation of the Great Bear (Ursa Major); - diagonal braces fastened across the hold of a ship; - the small icon whose movement across the screen follows that of the mouse, trackball or other pointing device; - a signpost or milepost; and more. I don't think that arguing on the basis of lay-English or plain English terms is going to be terribly useful. -- Steven From python at mrabarnett.plus.com Sat Sep 12 13:09:32 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 12 Sep 2015 18:09:32 +0100 Subject: Python handles globals badly. In-Reply-To: <8hk8va5uljr0oqv0nrj6u3q9j72vffl7b9@4ax.com> References: <1eee075d-7073-4875-9e42-2e053ee59b41@googlegroups.com> <0784va15gme91mqvoasfub3hvu59ehpepl@4ax.com> <201509102219.14138.gheskett@wdtv.com> <55F3A602.50906@gmx.com> <8hk8va5uljr0oqv0nrj6u3q9j72vffl7b9@4ax.com> Message-ID: <55F45C4C.7070902@mrabarnett.plus.com> On 2015-09-12 17:29, Dennis Lee Bieber wrote: > On Sat, 12 Sep 2015 05:11:46 +0100, Mario Figueiredo > declaimed the following: > >>On 12-09-2015 03:35, Mark Lawrence wrote: >>> >>> Ada took over from CORAL in the UK, at least in military projects. It >>> was also used in the aircraft industry. My old work mates tell me that >>> its completely died a death, to be replaced by C++. Someone please >>> remind me never to fly again. >> >>Alright. But then someone should probably have reminded you that a long >>time ago. >> >>Maybe you missed it when an Ada integer overflow bug produced one of the >>most expensive software bugs in history by crashing the Ariane 501 >>rocket and its 4 cluster sattelites payload. >> > > As I recall, the software did exactly what it was supposed to do in > that situation... > > But no one had tested the algorithm with the rate of change the Ariane > 5 could produce -- so an algorithm that was developed for, and safe with, > the smaller Ariane suddenly went "something's wrong -- abandon ship" > > Nothing inherent in the language... > What would C++ have done in the same situation? Would Ariane still have failed? Probably... From rustompmody at gmail.com Sat Sep 12 13:12:41 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 12 Sep 2015 10:12:41 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> Message-ID: <22e8ac31-c1db-4a8c-9817-33c37c03b295@googlegroups.com> On Saturday, September 12, 2015 at 9:47:33 PM UTC+5:30, rurpy wrote: > Frankly, I feel a little insulted by people who presume that having > learned what a pointer is in C, that my brain is so rigid that I must > necessarily think that pointer means exactly what pointer means in C > forever after. Its more amusing than insulting Just open CPython sources and there's a pointer on every other line Best I can see, the people frothing at the mouth that python has no pointers are basically saying that "non-first-class" == "non-existent" By that same logic C has neither types nor functions Speaking as a teacher, sometimes one needs to be clean and dishonest Sometimes one needs to be honest and mop up after leaky abstractions From emile at fenx.com Sat Sep 12 13:14:05 2015 From: emile at fenx.com (Emile van Sebille) Date: Sat, 12 Sep 2015 10:14:05 -0700 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <1dabdb08-2aee-4a53-bb57-1410edd372f6@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <55f45396$0$1660$c3e8da3$5496439d@news.astraweb.com> <1dabdb08-2aee-4a53-bb57-1410edd372f6@googlegroups.com> Message-ID: On 9/12/2015 9:54 AM, Rustom Mody wrote: > On Saturday, September 12, 2015 at 10:02:40 PM UTC+5:30, Steven D'Aprano wrote: >> On Sat, 12 Sep 2015 02:42 pm, Random832 wrote: >> >>> Anyway, maybe we do need a term to distinguish Python/C#/Java pointers >>> from C/C++ pointers - maybe call it a "non-arithmetic" pointer, since >>> the key thing about it is you can't do pointer arithmetic on them to get >>> the object "next to" the one it points at. >> >> How about *just don't call them pointers*? You know, since they aren't >> pointers in the computer science sense. >> >> The Free On-line Dictionary of Computing defines "pointer": >> >> 1. An address, from the point of view of a >> programming language. A pointer may be typed, with its type >> indicating the type of data to which it points. > > > >> Insisting that Python has pointers is like insisting that you use a text >> editor by flipping bits. "What happens if I press Ctrl-X?" "Well, these >> bits on the screen flip from black to white, these bits flip from white to >> black, and these stay the same." >> > > This is from the docs > https://docs.python.org/3/library/functions.html#id > > id(object) > > Return the "identity" of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. > > CPython implementation detail: This is the address of the object in memory. Quoting from above: >> The Free On-line Dictionary of Computing defines "pointer": >> >> 1. An address, from the point of view of a >> programming language. So, how does the CPython program access the contents given its 'address in memory'? From the definition it would seem it's not a pointer, as from the perspective of the programming language, you can't get there from the id. Look-ma,-no-pointers-ly y'rs, Emile From emile at fenx.com Sat Sep 12 13:18:50 2015 From: emile at fenx.com (Emile van Sebille) Date: Sat, 12 Sep 2015 10:18:50 -0700 Subject: Python handles globals badly. In-Reply-To: <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> Message-ID: On 9/11/2015 10:22 PM, Skybuck Flying wrote: > I didn't learn anything from this posting, sorry ! ;) I'm seeing a pattern here... Emile From steve at pearwood.info Sat Sep 12 13:24:25 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 13 Sep 2015 03:24:25 +1000 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <55f45396$0$1660$c3e8da3$5496439d@news.astraweb.com> <1dabdb08-2aee-4a53-bb57-1410edd372f6@googlegroups.com> Message-ID: <55f45fc8$0$1653$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Sep 2015 02:54 am, Rustom Mody wrote: > This is from the docs > https://docs.python.org/3/library/functions.html#id Yes, what of it? What point do you think you are making? > id(object) > > Return the "identity" of an object. This is an integer which is > guaranteed to be unique and constant for this object during its > lifetime. Two objects with non-overlapping lifetimes may have the same > id() value. > > CPython implementation detail: This is the address of the object in > memory. What part of "CPython implementation detail" was too difficult for you to understand? id() is not an addressof function. It returns, and I quote: "an integer which is guaranteed to be unique and constant for this object during its lifetime" which is *not the case for memory addresses*. Here are the IDs of a few objects in Python: steve at orac:~$ jython -c "print id(None); import sys; print id(sys)" 1 2 steve at orac:~$ ipy -c "print id(None); import sys; print id(sys)" 0 43 Are you going to argue that these are memory addresses? If not, what relevance do you think the id() function has here? Note: when I write my own Python implementation, all IDs will be negative odd numbers. -- Steven From rustompmody at gmail.com Sat Sep 12 13:26:38 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 12 Sep 2015 10:26:38 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <55f45c0f$0$1671$c3e8da3$5496439d@news.astraweb.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <55f45c0f$0$1671$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1b27d8c8-f23e-4497-9b24-52066be0f66f@googlegroups.com> On Saturday, September 12, 2015 at 10:38:46 PM UTC+5:30, Steven D'Aprano wrote: > On Sat, 12 Sep 2015 10:46 pm, Rustom Mody wrote: > > > On Saturday, September 12, 2015 at 11:57:01 AM UTC+5:30, Ben Finney wrote: > > >> You've clearly committed to some ontology that just doesn't match the > >> Python data model. > > > > How about lay-English ontology in which "point to" and "refer to" are > > fairly synonymous? > > "Pointer" in English is also a synonym for > > - a type of dog; > - an instrument which pierces (as used by engravers, lace workers, etc); > - an item of private information; > - a hint or tip; > - a caution or warning; > - a recommendation; > - the index finger; > - a cricketer fielding at a specific position; > - the hour/minute/second hand on a timepiece; > - a compass needle; > - two specific stars in the constellation of the Great Bear (Ursa Major); > - diagonal braces fastened across the hold of a ship; > - the small icon whose movement across the screen follows that of the > mouse, trackball or other pointing device; > - a signpost or milepost; > > and more. I don't think that arguing on the basis of lay-English or plain > English terms is going to be terribly useful. So if someone's ontology disagrees with yours its not very useful. You're welcome to that view of course Its called "Humpty-Dumpty" (in Alice ontology). We could have had a more 'useful' discussion if alongside the meanings of "pointer" you had provided meanings of "reference" as well From rosuav at gmail.com Sat Sep 12 13:34:15 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 13 Sep 2015 03:34:15 +1000 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <55f45fc8$0$1653$c3e8da3$5496439d@news.astraweb.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <55f45396$0$1660$c3e8da3$5496439d@news.astraweb.com> <1dabdb08-2aee-4a53-bb57-1410edd372f6@googlegroups.com> <55f45fc8$0$1653$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 13, 2015 at 3:24 AM, Steven D'Aprano wrote: > Note: when I write my own Python implementation, all IDs will be negative > odd numbers. When I build my own CPU architecture, all memory addresses will be negative odd numbers, so people think your Python uses addresses again. ChrisA From steve at pearwood.info Sat Sep 12 13:48:47 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 13 Sep 2015 03:48:47 +1000 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> Message-ID: <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Sep 2015 02:17 am, rurpy at yahoo.com wrote: > Having programmed in C in the past, Well, there's your problem. Like BASIC before it, anyone who has learned C is mentally crippled for life as a programmer *wink* > the model of Python I eventually > developed is very much (I think, haven't read the whole thread) like > Random832's. I think of boxes (objects) with slots containing "pointers" > that "point" to other boxes. Even today when dealing with complex > Python data structures, I draw boxes and arrows to help me understand > them and think of the arrows as "pointers". If you're going to abuse terminology, why don't you call the boxes "floats" since they "float around in memory", or some other story? After all, the JVM and .NET runtimes can and will move the boxes around as needed, which is sort of floating around. Then you can say that all Python objects are floats. Of course, what *you* mean by float is not what everyone else means by floats. But you've already made it clear that you're happy to use your own special meaning of "pointer" that disagrees with the computer science standard meaning, so what's the difference? > Frankly, I feel a little insulted by people who presume that having > learned what a pointer is in C, that my brain is so rigid that I must > necessarily think that pointer means exactly what pointer means in C > forever after. You C programmers, you always think it's about C *wink* C is not the only, or even the first, language to have standardised on a meaning for pointer in computer science. Pascal had pointers long before C, and I'm sure Pascal wasn't the first either. "Pointer" is a standard primitive data type across dozens of languages: it's an abstract data type holding the memory address of a variable (either a named, statically allocated variable, or more often, an anonymous, dynamically allocated variable). As such, it requires that variables have a fixed address. If the variable can move, the pointer will no longer point to the variable. If you want to use "pointer" to refer to something else, the onus is on you to make it clear that you're using it in a non-standard way. Some day, most programmers will be using nothing by dynamic languages which lack pointers-the-data-type, and the term will lose its baggage and can be safely used as a generic English term for "a thing which points". The tiny minority of systems programmers writing device drivers and kernel code in Rust (C having been long-since delegated to the wastebin of history -- well that's my fantasy and I'm sticking to it) will learn that, outside of their own niche, "pointer" does not have the technical meaning that they are used to, and everyone else will be as blissfully unaware of said technical meaning as the average programmer today is of continuations and futures. But this is not that day. > FYI (the general you), I am capable of extracting the > general principle and applying it to Python. Not just capable, but > using the concept from C made understanding Python faster than pretending > that somehow Python has some magical and unique way of structuring data > that's brand new. It's not magical or unique. It is shared by many other languages, such as Ruby, Lua, Java, Javascript. -- Steven From 4kir4.1i at gmail.com Sat Sep 12 13:54:33 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Sat, 12 Sep 2015 20:54:33 +0300 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> Message-ID: <87pp1n7cbq.fsf@gmail.com> Rustom Mody writes: > On Saturday, September 12, 2015 at 8:11:49 PM UTC+5:30, Laura Creighton wrote: >> In a message of Sat, 12 Sep 2015 05:46:35 -0700, Rustom Mody writes: >> >How about lay-English ontology in which "point to" and "refer to" are fairly >> >synonymous? >> >> This I have found is important in teaching, which is why I favour 'bind' >> and 'binding' -- rather than pointer, pointer, refer to, referring. > > Well we can play humpty dumpty and make any word mean whatever we like. > However if you are a teacher you will recognize a need for pictures. > And (as far as I can tell) "Random832" finds a need for the box-n-arrow > diagrams of classic data-structure books Speaking of pictures and names in Python http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables From steve at pearwood.info Sat Sep 12 14:14:30 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 13 Sep 2015 04:14:30 +1000 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <22e8ac31-c1db-4a8c-9817-33c37c03b295@googlegroups.com> Message-ID: <55f46b85$0$1655$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Sep 2015 03:12 am, Rustom Mody wrote: > Best I can see, the people frothing at the mouth that python has no > pointers are basically saying that "non-first-class" == "non-existent" Not at all. In Python, at least, all values are first-class, but that's not the case with all languages which lack pointers. Java has classes but they aren't first-class values. They aren't values at all, but they do exist as entities in Java code. You don't have to drop out of Java into some underlying implementation language in order to write Java classes. I trust that you agree that Fortran lacks pointers -- or at least, old versions of Fortran, like FORTRAN 5 and (by memory) Fortran 77 lack them. (Modern Fortran almost certain has pointers.) Old versions of Fortran lacks dynamic memory management, it has no pointers, no equivalent of Pascal's "new" and "dispose". It also has a variable model like C's (named variables with fixed memory locations). Suppose I write a Fortran 77 compiler in C. I daresay I would use C's ability to dynamically allocate and free memory (i.e. pointers) in my implementation of Fortran 77. But because this is a faithful implementation of the Fortran 77 standard, warts and all, the Fortran compiler itself won't have the ability to create, dereference or free pointers. Would you insist that Fortran 77 has pointers just because my implementation uses pointers under the hood? > By that same logic C has neither types nor functions No. C has both types and functions. You can define your own types, and you can define your own functions. They might not be first-class values, but they are entities you manipulate in your C code. You don't have to drop out of the C language into (say) machine code to write a function. In Python, the language *lacks pointers altogether*. It's not just that you can't treat them as first-class values, or that they aren't values, but that they aren't even entities in the Python programming model. In order to interact with pointers, you have to drop out of Python altogether, and start programming in the implementation language C, or use an interface to C such as ctypes. -- Steven From rustompmody at gmail.com Sat Sep 12 14:21:18 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 12 Sep 2015 11:21:18 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> Message-ID: <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> On Saturday, September 12, 2015 at 11:26:18 PM UTC+5:30, Akira Li wrote: > Rustom Mody writes: > > > On Saturday, September 12, 2015 at 8:11:49 PM UTC+5:30, Laura Creighton wrote: > >> In a message of Sat, 12 Sep 2015 05:46:35 -0700, Rustom Mody writes: > >> >How about lay-English ontology in which "point to" and "refer to" are fairly > >> >synonymous? > >> > >> This I have found is important in teaching, which is why I favour 'bind' > >> and 'binding' -- rather than pointer, pointer, refer to, referring. > > > > Well we can play humpty dumpty and make any word mean whatever we like. > > However if you are a teacher you will recognize a need for pictures. > > And (as far as I can tell) "Random832" finds a need for the box-n-arrow > > diagrams of classic data-structure books > > Speaking of pictures and names in Python > http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables Yeah cute [I think I will even use these in my classes] However they dont address the issue that I think random832 is referring to. viz. I have two variables (or names!) say a and b which look the same >>> a [[1,2],[1,2]] >>> b [[1,2],[1,2]] And yet doing >>> a[0][0] = "Oops!" gives a data structure one "Oops!" whereas doing it to b mysteriously gives 2 Best I can see you can only explain this seemingly-similar-but-structurally-different with box-n-arrow diagrams. Or some moral equivalent. And some people see no advantage to playing semantics and proclaiming "The arrows in C look similar to the arrows in python but they are not the same" From random832 at fastmail.com Sat Sep 12 14:23:12 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 14:23:12 -0400 Subject: Are there any "correct" implementations of tzinfo? Message-ID: I was trying to find out how arithmetic on aware datetimes is "supposed to" work, and tested with pytz. When I posted asking why it behaves this way I was told that pytz doesn't behave correctly according to the way the API was designed. The tzlocal module, on the other hand, appears to simply defer to pytz on Unix systems. My question is, _are_ there any correct reference implementations that demonstrate the proper behavior in the presence of a timezone that has daylight saving time transitions? From carl at oddbird.net Sat Sep 12 14:36:08 2015 From: carl at oddbird.net (Carl Meyer) Date: Sat, 12 Sep 2015 12:36:08 -0600 Subject: Are there any "correct" implementations of tzinfo? In-Reply-To: References: Message-ID: <55F47098.80706@oddbird.net> On 09/12/2015 12:23 PM, Random832 wrote: > I was trying to find out how arithmetic on aware datetimes is "supposed > to" work, and tested with pytz. When I posted asking why it behaves this > way I was told that pytz doesn't behave correctly according to the way > the API was designed. The tzlocal module, on the other hand, appears to > simply defer to pytz on Unix systems. > > My question is, _are_ there any correct reference implementations that > demonstrate the proper behavior in the presence of a timezone that has > daylight saving time transitions? Well, the problem is that because datetime doesn't include any way to disambiguate ambiguous times, it's not really possible to implement complex timezones in a way that is both correct (if your definition of correct includes "timezone conversions are lossless") and also matches the intended model of datetime. I believe that dateutil.tz has a tzinfo implementation (though I haven't used it myself) which is zoneinfo-based and matches the intended model of datetime (in that "Eastern" is always the same tzinfo object, and all operations within "Eastern" are always done on a local-clock-time basis). But in order to do this it has to sacrifice round-trippable conversions during a DST fold (because it has no way to disambiguate between the first and second 1:30am in local time during a DST fold). Pytz makes the other choice, making all operations consistent and loss-less by using only fixed-offset tzinfo instances. The cost of this choice is the need to "normalize" after arithmetic, because you may end up with e.g. an EDT datetime during a timeframe when DST is not in effect and it should be EST instead. PEP 495 is intended to solve the "no way to disambiguate ambiguous local times other than using fixed-offset tzinfos" problem, which would make it possible to implement tzinfo classes following the dateutil model while still having loss-less conversions. Carl -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From rurpy at yahoo.com Sat Sep 12 14:45:16 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 12 Sep 2015 11:45:16 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 09/12/2015 10:32 AM, Steven D'Aprano wrote: > On Sat, 12 Sep 2015 02:42 pm, Random832 wrote: >[...] > Computer science and IT is *dominated* by a single usage for "pointer" -- > it's an abstract memory address. The fundamental characteristics of > pointers are: Just upthread, you claimed something was "universally agreed" that was not so at all; so please forgive me for not taking your *dominated*/single assertion on simply your claim that it is so. > - they are first-class values; you can assign a pointer to a variable; Not true for Python "pointers" > - you can dereference a pointer: get the value pointed to; True for Python "pointers" > - (in some languages) you can get a pointer to a specific variable (possibly > an unnamed, dynamic variable allocated in the heap rather than a named, > statically allocated variable). True for Python "pointers". > The last two imply that the language must be one where values have fixed > addresses, not just as a matter of implementation, but as a matter of > language semantics. If they are free to move, they cannot have a fixed > address. The *address* must be fixed, that is, when you dereference the address you must always get the same thing back. But that implies nothing about how or where the thing is stored, or whether it can move or not. Indeed C and other languages with what even you call pointers get the same thing back even though the thing actually *has* moved in physical memory, because the address is denoted as a virtual memory address. I take the generalized meaning of "address" to be simply a token that allows you to get back the same thing each time you use it. > Python, Java, Ruby, Lua, Javascript etc. have *no such concept* as pointer. > There are no values in these languages which correspond to the standard > definition of pointer: They have not such concept because the developers and documentors choose not to describe that language that way. That does not mean one could not come up with a perfectly valid description that did include the concept of pointers. > - you cannot get a pointer to an object or a variable (a name); > > - since there are no pointers, you cannot dereference them; > > - or assign them to a variable. > > > Since pointers can be considered an indirect reference to a value, what sort > of indirect references does Python have? The simplest thing in Python that > is somewhat analogous to a pointer is a *name*, since names allow you to > indirectly refer to some value: > > x = 23 > print(x) # prints the value referred to by x, not "x" itself. > ptr = "x" # equivalent to "the address of x" > y = globals()[ptr] # equivalent to dereferencing Here is another kind of indirect reference a[0] = 23 The "pointer" in the first item of the list "a" does not have a name. But we can still dereference it. The dereferencing happens automatically when "a[0]" is executed. > Note that names are not first-class values in Python: there is no Name type, > and you cannot bind a name to a variable, you have to use a string. > > It's not a very close analogy, but it's the closest Python has. I think it is a close analogy. Things refer to other things and can be used to access those other things act like pointers. You are correct that they are not first class items: one cannot do with them everything one can do with other items, all one can actually do with them is create them and dereference them. That of course is a good thing. But that they are not first class objects does not mean that one can't or shouldn't use the term "pointer" to describe them. That is, I don't see first- classness as being a requirement for pointerness. The defining characteristic of a pointer is that it, well, points to something. It may not be appropriate way to describe Python for everybody but it is perfectly reasonable (and even preferable) for people with an understanding of "pointers" from some other language. And for those people who don't then one could argue they are a clean slate and using the word "pointer" won't hurt. (JFTR, I am not against describing python in terms of "reference", "binding" etc, I just object to the vehement frothing at the mouth and insistence of one Single Truth that occurs here whenever anyone attempts to present some alternative. As I said in another post one size does not fit all.) From tim.peters at gmail.com Sat Sep 12 14:53:06 2015 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 12 Sep 2015 13:53:06 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: Message-ID: > I was trying to find out how arithmetic on aware datetimes is "supposed > to" work, and tested with pytz. When I posted asking why it behaves this > way I was told that pytz doesn't behave correctly according to the way > the API was designed. You were told (by me) that its implementation of tzinfos was not the _intended_ way. Which is another way of saying it was an unanticipated way. "Correctly" is a whole different kind of judgment. pytz users who faithfully follow the docs seem happy with it. > The tzlocal module, on the other hand, appears to > simply defer to pytz on Unix systems. > > My question is, _are_ there any correct reference implementations that > demonstrate the proper behavior in the presence of a timezone that has > daylight saving time transitions? Which specific "proper behaviors"? :"Hybrid" tzinfos following the recommendations in the Python docs, including the sample implementations in the docs, correctly mimic local clock behavior (skipping the clock ahead when DST starts, and moving the clock back when DST ends) when converting from UTC. It's impossible now to do local -> UTC conversions correctly in all cases, because it's impossible now to know which UTC time was intended for a local time in a fold. For the same reason, it's impossible now to know whether a local time in a fold is intended to be viewed as being in daylight time or standard time. But do note limitations of the default .fromutc() implementation: it only guarantees correct mimic-the-local-clock behavior when total-offset transitions are solely due to a notion of "daylight time" that strictly alternates between .dst() returning zero and non-zero values. Transitions due to any other reason may or may not be reflected in .fromutc()'s treatment of the local clock. Most importantly, a transition due to a zone changing its base ("standard") UTC offset is a possibility the default .fromutc() knows nothing about. The wrapping of the IANA ("Olson") zoneinfo database in dateutil uses hybrid tzinfos (the intended way of wrapping zones with multiple UTC offsets), and inherits the default .fromutc(), so all the above applies to it. Including all behaviors stemming from the impossibility of disambiguating local times in a fold. That's not a bug in dateutil. It's a gap in datetime's design, It was an intentional gap at the time, but that pytz went to such heroic lengths to fill it suggests PEP 495 may well be overdue ;-) From random832 at fastmail.com Sat Sep 12 15:14:30 2015 From: random832 at fastmail.com (random832 at fastmail.com) Date: Sat, 12 Sep 2015 15:14:30 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: Message-ID: <1442085270.324423.381918721.2DA4A977@webmail.messagingengine.com> On Sat, Sep 12, 2015, at 14:53, Tim Peters wrote: > > I was trying to find out how arithmetic on aware datetimes is > > "supposed to" work, and tested with pytz. When I posted asking why > > it behaves this way I was told that pytz doesn't behave correctly > > according to the way the API was designed. > > You were told (by me) that its implementation of tzinfos was not the > _intended_ way. Which is another way of saying it was an > unanticipated way. "Correctly" is a whole different kind of judgment. > pytz users who faithfully follow the docs seem happy with it. My context is that I am working on an idea to include utc offsets in datetime objects (or on a similar object in a new module), as an alternative to something like a "fold" attribute. and since "classic arithmetic" is apparently so important, I'm trying to figure out how "classic arithmetic" _is actually supposed to work_ when adding a timedelta to a time lands it on the opposite side of a transition (or in the middle of a "spring forward" gap). If there is a "fall back" transition tonight, then adding a day to a time of 12 noon today could end up as: 12 noon tomorrow, offset still DST. 12 noon tomorrow, offset in standard time, 25 hours from now in real time. 11 AM tomorrow, offset in standard time, 24 hours from now in real time Which one of these is "classic arithmetic"? Pytz (if you don't explicitly call a "normalize" function) results in something that looks like the first. In one of the models I've thought of, you can get the second by replacing the tzinfo again, or the third by doing astimezone, but the first preserves "exactly 24 hours in the future" in both the UTC moment and the naive interpretation by leaving the offset alone even if it is an "unnatural" offset. The second one above is what you get when you call normalize. My question was whether there are any real implementations that work the intended way. If there are not, maybe the intended semantics should go by the wayside and be replaced by what pytz does. From random832 at fastmail.com Sat Sep 12 15:16:02 2015 From: random832 at fastmail.com (random832 at fastmail.com) Date: Sat, 12 Sep 2015 15:16:02 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: Message-ID: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Oops, pressed the wrong reply button and it didn't include the datetime list. On Sat, Sep 12, 2015, at 14:53, Tim Peters wrote: > > I was trying to find out how arithmetic on aware datetimes is > > "supposed to" work, and tested with pytz. When I posted asking why > > it behaves this way I was told that pytz doesn't behave correctly > > according to the way the API was designed. > > You were told (by me) that its implementation of tzinfos was not the > _intended_ way. Which is another way of saying it was an > unanticipated way. "Correctly" is a whole different kind of judgment. > pytz users who faithfully follow the docs seem happy with it. My context is that I am working on an idea to include utc offsets in datetime objects (or on a similar object in a new module), as an alternative to something like a "fold" attribute. and since "classic arithmetic" is apparently so important, I'm trying to figure out how "classic arithmetic" _is actually supposed to work_ when adding a timedelta to a time lands it on the opposite side of a transition (or in the middle of a "spring forward" gap). If there is a "fall back" transition tonight, then adding a day to a time of 12 noon today could end up as: 12 noon tomorrow, offset still DST. 12 noon tomorrow, offset in standard time, 25 hours from now in real time. 11 AM tomorrow, offset in standard time, 24 hours from now in real time Which one of these is "classic arithmetic"? Pytz (if you don't explicitly call a "normalize" function) results in something that looks like the first. In one of the models I've thought of, you can get the second by replacing the tzinfo again, or the third by doing astimezone, but the first preserves "exactly 24 hours in the future" in both the UTC moment and the naive interpretation by leaving the offset alone even if it is an "unnatural" offset. The second one above is what you get when you call normalize. My question was whether there are any real implementations that work the intended way. If there are not, maybe the intended semantics should go by the wayside and be replaced by what pytz does. From random832 at fastmail.us Sat Sep 12 15:18:59 2015 From: random832 at fastmail.us (random832 at fastmail.us) Date: Sat, 12 Sep 2015 15:18:59 -0400 Subject: Are there any "correct" implementations of tzinfo? In-Reply-To: <55F47098.80706@oddbird.net> References: <55F47098.80706@oddbird.net> Message-ID: <1442085539.325242.381921225.17E1166E@webmail.messagingengine.com> On Sat, Sep 12, 2015, at 14:36, Carl Meyer wrote: > Well, the problem is that because datetime doesn't include any way to > disambiguate ambiguous times, it's not really possible to implement > complex timezones in a way that is both correct (if your definition of > correct includes "timezone conversions are lossless") and also matches > the intended model of datetime. I'm not even talking about ambiguous times. I'm mostly talking about unambiguous times on opposite sides of the transition. It's not even clear to me how the model of datetime envisions _those_ working with "classic arithmetic". From cloverobert at gmail.com Sat Sep 12 15:20:24 2015 From: cloverobert at gmail.com (Robert Clove) Date: Sun, 13 Sep 2015 00:50:24 +0530 Subject: Random MAC generator error Message-ID: import random # global mac1 def randomMAC(): mac = [ 0x00, 0x16, 0x3e, random.randint(0x00, 0x7f), random.randint(0x00, 0xff), random.randint(0x00, 0xff) ] return ':'.join(map(lambda x: "%02x" % x, mac)) # print randomMAC() for x in range(1,11): mac1 = randomMAC() print mac1 I got the following random mac generator script from the net (simple google search) i want to use random mac in one of mine script.What i need is mac1=randomMAC() should give mac value to mac1 that i use in a function and this runs in a loop. -------------- next part -------------- An HTML attachment was scrubbed... URL: From 4kir4.1i at gmail.com Sat Sep 12 15:32:45 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Sat, 12 Sep 2015 22:32:45 +0300 Subject: Are there any "correct" implementations of tzinfo? References: Message-ID: <87io7f77s2.fsf@gmail.com> Random832 writes: > I was trying to find out how arithmetic on aware datetimes is "supposed > to" work, and tested with pytz. When I posted asking why it behaves this > way I was told that pytz doesn't behave correctly according to the way > the API was designed. The tzlocal module, on the other hand, appears to > simply defer to pytz on Unix systems. > > My question is, _are_ there any correct reference implementations that > demonstrate the proper behavior in the presence of a timezone that has > daylight saving time transitions? The only way to get correct[*] results now is to use *pytz*. PEP 495 might allow to fix some of non-avoidable (at the moment) bugs[1] in *dateutil* (another library that provides access to the tz database). Some core Python developers feel that pytz model does not implement the initial datetime design intent: both naive and timezone-aware datetime objects use the same model for arihtmetic (though the actual implementation contains a mix: aware datetime objects are treated as naive datetime objects in some cases but in others they behave as though they are utc-based). pytz model: aware datetime objects behave *as if* they are converted to UTC during arithmetic operations, comparisons, etc: # d = datetime.now(tz) (d2 - d1) == (d2.astimezone(utc) - d1.astimezone(utc)) tz.normalize(d + delta) == (d.astimezone(utc) + delta).astimezone(tz) tz.normalize() is necessary to get the correct local time (utc time is correct even without tz.normalize()) in presence of DST transitions (or other changes in UTC offset for any reason). Here's how the stdlib implementation behaves at the moment for a timezone-aware datetime object that represents local time (the only timezone with a non-fixed utc offset that is available in stdlib): # d = datetime.now(utc).astimezone() (d2 - d1) == (d2.astimezone(utc) - d1.astimezone(utc)) (d + delta).astimezone() == (d.astimezone(utc) + delta).astimezone() If utc offset is fixed then both naive and aware models are the same. [*] according to the tz database [1] https://github.com/dateutil/dateutil/issues/112 From tim.peters at gmail.com Sat Sep 12 15:41:15 2015 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 12 Sep 2015 14:41:15 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: [] > My context is that I am working on an idea to include utc offsets in > datetime objects (or on a similar object in a new module), as an > alternative to something like a "fold" attribute. and since "classic > arithmetic" is apparently so important, Love it or hate it, it's flatly impossible to change anything about it now, for backward compatibility. > I'm trying to figure out how > "classic arithmetic" _is actually supposed to work_ when adding a > timedelta to a time lands it on the opposite side of a transition (or in > the middle of a "spring forward" gap). datetime arithmetic is defined in the Python docs. > If there is a "fall back" transition tonight, then adding a day to a > time of 12 noon today could end up as: > > 12 noon tomorrow, offset still DST. > 12 noon tomorrow, offset in standard time, 25 hours from now in real > time. > 11 AM tomorrow, offset in standard time, 24 hours from now in real time > > Which one of these is "classic arithmetic"? 12 noon tomorrow in every case, regardless of tzinfo and regardless of whether any kind of transition may or may not have occurred. Whether it is or isn't in DST in this specific case isn't defined by Python - that's entirely up to what the tzinfo implementation says. The _intended_ way of implementing tzinfos would say it was in standard time. > Pytz (if you don't > explicitly call a "normalize" function) results in something that looks > like the first. Yes, because pytz always uses a fixed-offset tzinfo. There is no difference between timeline arithmetic and classic arithmetic in any fixed-offset zone. > In one of the models I've thought of, you can get the > second by replacing the tzinfo again, or the third by doing astimezone, > but the first preserves "exactly 24 hours in the future" in both the UTC > moment and the naive interpretation by leaving the offset alone even if > it is an "unnatural" offset. > > The second one above is what you get when you call normalize. Yes. .normalize() effectively converts to UTC and back again In fact, this is all it does: def normalize(self, dt, is_dst=False): if dt.tzinfo is self: return dt if dt.tzinfo is None: raise ValueError('Naive time - no tzinfo set') return dt.astimezone(self) .fromutc() is called as the last step of .astimezone(), and .pytz overrides the default .fromutc() to plug "the appropriate" fixed-offset pytz tzinfo into the result. > My question was whether there are any real implementations that work the > intended way. dateutil, plus all implementations anyone may have written for themselves based on the Python doc examples. When datetime was originally released, there were no concrete tzinfo implementations in the world, so lots of people wrote their own for the zones they needed by copy/paste/edit of the doc examples. > If there are not, maybe the intended semantics should go > by the wayside and be replaced by what pytz does. Changing anything about default arithmetic behavior is not a possibility. This has been beaten to death multiple times on this mailing list already, and I'm not volunteering for another round of it ;-) From alexander.belopolsky at gmail.com Sat Sep 12 15:53:38 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Sat, 12 Sep 2015 15:53:38 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: On Sat, Sep 12, 2015 at 3:41 PM, Tim Peters wrote: > > If there are not, maybe the intended semantics should go > > by the wayside and be replaced by what pytz does. > > Changing anything about default arithmetic behavior is not a > possibility. This has been beaten to death multiple times on this > mailing list already, and I'm not volunteering for another round of it > ;-) Tim and Guido only grudgingly accept it, but datetime already gives you "the pytz way" and PEP 495 makes a small improvement to it. The localize/normalize functionality is provided by the .astimezone() method which when called without arguments will attach an appropriate fixed offset timezone to a datetime object. You can then add timedeltas to the result and stay within a "fictitious" fixed offset timezone that extends indefinitely in both directions. To get back to the actual civil time - you call .astimezone() again. This gives you what we call here a "timeline" arithmetic and occasionally it is preferable to doing arithmetic in UTC. (Effectively you do arithmetic in local standard time instead of UTC.) Using a fixed offset timezone other than UTC for timeline arithmetic is preferable in timezones that are far enough from UTC that business hours straddle UTC midnight. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rurpy at yahoo.com Sat Sep 12 15:58:26 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 12 Sep 2015 12:58:26 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> On 09/12/2015 11:48 AM, Steven D'Aprano wrote: > On Sun, 13 Sep 2015 02:17 am, rurpy at yahoo.com wrote: > [...] >> the model of Python I eventually >> developed is very much (I think, haven't read the whole thread) like >> Random832's. I think of boxes (objects) with slots containing "pointers" >> that "point" to other boxes. Even today when dealing with complex >> Python data structures, I draw boxes and arrows to help me understand >> them and think of the arrows as "pointers". > > If you're going to abuse terminology, why don't you call the boxes "floats" > since they "float around in memory", > [...] I was not proposing that, I was talking about the use of the term "pointer". > C is not the only, or even the first, language to have standardised on a > meaning for pointer in computer science. Pascal had pointers long before C, > and I'm sure Pascal wasn't the first either. [I'm not sure about the "long before" part given they were nearly contemporaneous.] Right, and each of them uses the word (and others like "function", "call" "arguments", etc) in their own specific way, which they define as part of the description of the language. "function" in C is different than "function" in Pascal which is different than "function" in Python. That C (or Pascal) used the term first does not mean that it was "standardized" by that use to have that precise definition forever after. > "Pointer" is a standard primitive data type across dozens of languages: it's > an abstract data type holding the memory address of a variable (either a > named, statically allocated variable, or more often, an anonymous, > dynamically allocated variable). As such, it requires that variables have a > fixed address. If the variable can move, the pointer will no longer point > to the variable. See my comments on "fixed address" in another post. Your definition of "address" is too narrow. > If you want to use "pointer" to refer to something else, the onus is on you > to make it clear that you're using it in a non-standard way. Of course. Nobody should ever say (a least formally) just "pointer" and expect the entire (assumed diverse) audience to have a common single understanding of what is meant. But that applies to most terminology like "reference" as well. It is why language documentation has things like definitions and glossaries. > Some day, most programmers will be using nothing by dynamic languages which > lack pointers-the-data-type, I don't think there is any direct relationship between pointers and dynamic languages. Go is not a dynamic language yet it does not not allow unrestrained pointer use a'la C. My impression is that unmanaged pointers (in the C sense) are recognized these days as dangerous and that nearly all new languages including static ones manage "pointers" (perhaps under a different name) to prevent the problems that occur with C. > and the term will lose its baggage and can be > safely used as a generic English term for "a thing which points". The tiny > minority of systems programmers writing device drivers and kernel code in > Rust (C having been long-since delegated to the wastebin of history -- well > that's my fantasy and I'm sticking to it) That's fine, so we are talking about the far distant future, maybe year 3000 or so. :-) > will learn that, outside of their > own niche, "pointer" does not have the technical meaning that they are used > to, and everyone else will be as blissfully unaware of said technical > meaning as the average programmer today is of continuations and futures. > > But this is not that day. I think you underestimate the ability of human beings (even programmers) to interpret words in a context dependent way. The question is whether what "pointer" means in languages that use the word is *so* different than its meaning in the Python sense, that using it for Python is more misleading than helpful. You think so, perhaps because you focus on the unmanaged and memory-address aspects of its use. I consider those as non-determining characteristics of a thing that points to something and instead consider its pointingness to be its defining characteristic, in those languages and in Python, and thus find it perfectly descriptive for Python. From harvesting at makes.email.invalid Sat Sep 12 16:02:51 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Sat, 12 Sep 2015 23:02:51 +0300 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> Message-ID: Rustom Mody writes: >>>> a > [[1,2],[1,2]] >>>> b > [[1,2],[1,2]] > And yet doing >>>> a[0][0] = "Oops!" > gives a data structure one "Oops!" > whereas doing it to b mysteriously gives 2 > > Best I can see you can only explain this > seemingly-similar-but-structurally-different > with box-n-arrow diagrams. > Or some moral equivalent. I think the best way is to say that a[0] and a[1] are the same object, while b[0] and b[1] are different objects. Possibly b[0] is also the same object as a[0] and a[1]. Then b[0][0] = "Oops!" was redundant. And the way to work out whether two objects are the same is to trace where they come from. Certain pieces of code result in new objects. Other pieces of code pass old objects around. Possibly store them in places, or change them in some way. Never make copies. Works for me. Some sort of pointer-talk is useful to discuss the implementation of all this (how can an object be in different places? how does an arbitrary object fit in a 64-bit register?) but for ordinary reasoning about a program, pointer-talk with those diagrams mostly gets in the way. From tim.peters at gmail.com Sat Sep 12 16:10:29 2015 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 12 Sep 2015 15:10:29 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: >>> If there are not, maybe the intended semantics should go >> > by the wayside and be replaced by what pytz does. >> Changing anything about default arithmetic behavior is not a >> possibility. This has been beaten to death multiple times on this >> mailing list already, and I'm not volunteering for another round of it >> ;-) [Alex] > Tim and Guido only grudgingly accept it, but datetime already gives you "the > pytz way" and PEP 495 makes a small improvement to it. To be clear, "Tim and Guido" have nothing at all against timeline arithmetic. Sometimes it's exactly what you need. But the _intended_ way to get it was always to convert to UTC first, or to just use plain old timestamps. Classic arithmetic was very intentionally the default. The only "grudgingly accepted" part is that .astimezone() grew a special case later, to make the absence of an argument "mean something": > The localize/normalize functionality is provided by the .astimezone() > method which when called without arguments will attach an appropriate > fixed offset timezone to a datetime object. You can then add timedeltas > to the result and stay within a "fictitious" fixed offset timezone that extends > indefinitely in both directions. To get back to the actual civil time - you > call .astimezone() again. This gives you what we call here a "timeline" > arithmetic and occasionally it is preferable to doing arithmetic in UTC. > (Effectively you do arithmetic in local standard time instead of UTC.) > Using a fixed offset timezone other than UTC for timeline arithmetic is > preferable in timezones that are far enough from UTC that business hours > straddle UTC midnight. The distance from UTC can't make any difference to the end result, although if you're working in an interactive shell "it's nice" to see intermediate results near current wall-clock time. "A potential problem" with .astimezone()'s default is that it _does_ create a fixed-offset zone. It's not at all obvious that it should do so. First time I saw it, my initial _expectation_ was that it "obviously" created a hybrid tzinfo reflecting the system zone's actual daylight rules, as various "tzlocal" implementations outside of Python do. From 4kir4.1i at gmail.com Sat Sep 12 16:13:24 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Sat, 12 Sep 2015 23:13:24 +0300 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> Message-ID: <87egi375wb.fsf@gmail.com> Rustom Mody writes: > On Saturday, September 12, 2015 at 11:26:18 PM UTC+5:30, Akira Li wrote: >> Rustom Mody writes: >> >> > On Saturday, September 12, 2015 at 8:11:49 PM UTC+5:30, Laura Creighton wrote: >> >> In a message of Sat, 12 Sep 2015 05:46:35 -0700, Rustom Mody writes: >> >> >How about lay-English ontology in which "point to" and "refer to" are fairly >> >> >synonymous? >> >> >> >> This I have found is important in teaching, which is why I favour 'bind' >> >> and 'binding' -- rather than pointer, pointer, refer to, referring. >> > >> > Well we can play humpty dumpty and make any word mean whatever we like. >> > However if you are a teacher you will recognize a need for pictures. >> > And (as far as I can tell) "Random832" finds a need for the box-n-arrow >> > diagrams of classic data-structure books >> >> Speaking of pictures and names in Python >> http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables > > Yeah cute > [I think I will even use these in my classes] > However they dont address the issue that I think random832 is > referring to. The pictures despite their simplicity reflect the actual model that Python language uses i.e., any deviations are an implementation artifact and may be ignored. > viz. I have two variables (or names!) say a and b which look the same >>>> a > [[1,2],[1,2]] >>>> b > [[1,2],[1,2]] > And yet doing >>>> a[0][0] = "Oops!" > gives a data structure one "Oops!" > whereas doing it to b mysteriously gives 2 Sorry, I haven't followed the whole thread. Could your provide a complete code example? Mention what you expect to happen and what happens instead in your case. From denismfmcmahon at gmail.com Sat Sep 12 16:31:12 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 12 Sep 2015 20:31:12 +0000 (UTC) Subject: Random MAC generator error References: Message-ID: On Sun, 13 Sep 2015 00:50:24 +0530, Robert Clove wrote: > import random # > > global mac1 > def randomMAC(): > mac = [ 0x00, 0x16, 0x3e, > random.randint(0x00, 0x7f), random.randint(0x00, 0xff), > random.randint(0x00, 0xff) ] > return ':'.join(map(lambda x: "%02x" % x, mac)) > # > print randomMAC() > > for x in range(1,11): > > mac1 = randomMAC() > > print mac1 > > I got the following random mac generator script from the net (simple > google search) > > i want to use random mac in one of mine script.What i need is > mac1=randomMAC() should give mac value to mac1 that i use in a function > and this runs in a loop. And you haven't told us what the "error" you're posting about is? When I ran the code I got the following result: 00:16:3e:21:da:a4 00:16:3e:57:be:d2 00:16:3e:6b:e5:ae 00:16:3e:54:0e:f0 00:16:3e:57:5e:50 00:16:3e:21:99:6b 00:16:3e:12:e6:05 00:16:3e:53:02:6d 00:16:3e:79:17:1b 00:16:3e:02:ff:b8 00:16:3e:4e:ff:0d Observation: No point in declaring mac1 as global in the global scope. Is it possible that you've tried to run python 2.x code on python 3.x and hit an error due to 'print x' -> 'print(x)'? -- Denis McMahon, denismfmcmahon at gmail.com From random832 at fastmail.com Sat Sep 12 17:10:04 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 17:10:04 -0400 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> Message-ID: Jussi Piitulainen writes: > I think the best way is to say that a[0] and a[1] are the same object, > while b[0] and b[1] are different objects. Sure, you can *say* that. But how do you draw it on a diagram with sticky notes or parcel tags or whatever? From alexander.belopolsky at gmail.com Sat Sep 12 17:24:37 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Sat, 12 Sep 2015 17:24:37 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: On Sat, Sep 12, 2015 at 4:10 PM, Tim Peters wrote: > "A potential problem" with .astimezone()'s default is that it _does_ > create a fixed-offset zone. It's not at all obvious that it should do > so. First time I saw it, my initial _expectation_ was that it > "obviously" created a hybrid tzinfo reflecting the system zone's > actual daylight rules, as various "tzlocal" implementations outside of > Python do. > The clue should have been that .astimezone() is an instance method and you don't need to know time to create a hybrid tzinfo. If a Local tzinfo was available, it could just be passed to the .astimezone() method as an argument. You would not need .astimezone() to both create a tzinfo and convert the datetime instance to it. Still, I agree that this was a hack and a very similar hack to the one implemented by pytz. Hopefully once PEP 495 is implemented we will shortly see "as intended" tzinfos to become more popular. -------------- next part -------------- An HTML attachment was scrubbed... URL: From random832 at fastmail.com Sat Sep 12 17:27:51 2015 From: random832 at fastmail.com (Random832) Date: Sat, 12 Sep 2015 17:27:51 -0400 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> Message-ID: Akira Li <4kir4.1i at gmail.com> writes: >Rustom Mody writes: >> viz. I have two variables (or names!) say a and b which look the same >>>>> a >> [[1,2],[1,2]] >>>>> b >> [[1,2],[1,2]] >> And yet doing >>>>> a[0][0] = "Oops!" >> gives a data structure one "Oops!" >> whereas doing it to b mysteriously gives 2 > > Sorry, I haven't followed the whole thread. Could your provide a > complete code example? Mention what you expect to happen and what > happens instead in your case. a0 = a1 = [1, 2] b0 = [1, 2] b1 = [1, 2] a = [a0, a1] b = [b0, b1] del a0, a1, b0, b1 There's nothing about *him* expecting anything wrong to happen. The question is how to draw a diagram that unambiguously shows the resulting structure using the "parcel tags" model shown in the diagrams (and without having a0/a1/etc as actual names) It's easy to draw such a diagram for the "boxes and arrows" model: (@ shows the box named by a[0][0]. Or a[1][0].) a[*]-->[*]----v [*]-->[@]--------->(1) [*]-. ^^ `--------++--. b[*]-->[*]-->[*]----------'| | [*]-. [*]-----------+-.| v | || [*]--------------' vv [*]--------------->(2) If the "parcel tags" model can't show it, then the "parcel tag" model clearly is not a correct and complete depiction of how Python actually works. (If I were drawing a picture rather than ASCII I'd add something to make it clear that the pairs shown are list objects Like, it's a circle with the word "list" and two pointer-boxes inside it.) From marfig at gmx.com Sat Sep 12 17:57:59 2015 From: marfig at gmx.com (Mario Figueiredo) Date: Sat, 12 Sep 2015 22:57:59 +0100 Subject: Python handles globals badly. In-Reply-To: <55F45C4C.7070902@mrabarnett.plus.com> References: <1eee075d-7073-4875-9e42-2e053ee59b41@googlegroups.com> <0784va15gme91mqvoasfub3hvu59ehpepl@4ax.com> <201509102219.14138.gheskett@wdtv.com> <55F3A602.50906@gmx.com> <8hk8va5uljr0oqv0nrj6u3q9j72vffl7b9@4ax.com> <55F45C4C.7070902@mrabarnett.plus.com> Message-ID: <55F49FE7.5090002@gmx.com> On 12-09-2015 18:09, MRAB wrote: > On 2015-09-12 17:29, Dennis Lee Bieber wrote: >> But no one had tested the algorithm with the rate of change the >> Ariane >> 5 could produce -- so an algorithm that was developed for, and safe with, >> the smaller Ariane suddenly went "something's wrong -- abandon ship" >> >> Nothing inherent in the language... >> > What would C++ have done in the same situation? Would Ariane still have > failed? Probably... > And that's exactly the point. C++, or Ada, for that matter have decades old documented best practices and code patterns to deal with those aspects of the language that can induce in error. Integer overflow is a well documented problem. And relying on it, is documented as a bad idea for several reasons, including the changes in the underlying system that eventually led to Ariane incident. For all that is worth, C++ issues with all sorts of overflows and unchecked memory are documented from the very first beginning of the language. Same with C and same with Ada own particular issues. A safe(r) language just presents different ways of shooting one's foot. We can discuss how much of a bad boy C++ is, but at the end of the day programers will just keep on make mistakes and eventually on those very areas the safer language doesn't provide a safety net. One can argue that by offering more ways to shoot one's foot, C and C++ are more dangerous to use than other considered safer languages. But that doesn't gel with the operative history of C or C++ that are running mission critical systems, from stock markets to nuclear power plants. These languages just demand a different breed of programmers and different methods of testing. From breamoreboy at yahoo.co.uk Sat Sep 12 18:05:10 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 23:05:10 +0100 Subject: Python handles globals badly. In-Reply-To: <8hk8va5uljr0oqv0nrj6u3q9j72vffl7b9@4ax.com> References: <1eee075d-7073-4875-9e42-2e053ee59b41@googlegroups.com> <0784va15gme91mqvoasfub3hvu59ehpepl@4ax.com> <201509102219.14138.gheskett@wdtv.com> <55F3A602.50906@gmx.com> <8hk8va5uljr0oqv0nrj6u3q9j72vffl7b9@4ax.com> Message-ID: On 12/09/2015 17:29, Dennis Lee Bieber wrote: > On Sat, 12 Sep 2015 05:11:46 +0100, Mario Figueiredo > declaimed the following: > >> On 12-09-2015 03:35, Mark Lawrence wrote: >>> >>> Ada took over from CORAL in the UK, at least in military projects. It >>> was also used in the aircraft industry. My old work mates tell me that >>> its completely died a death, to be replaced by C++. Someone please >>> remind me never to fly again. >> >> Alright. But then someone should probably have reminded you that a long >> time ago. >> >> Maybe you missed it when an Ada integer overflow bug produced one of the >> most expensive software bugs in history by crashing the Ariane 501 >> rocket and its 4 cluster sattelites payload. >> > > As I recall, the software did exactly what it was supposed to do in > that situation... > > But no one had tested the algorithm with the rate of change the Ariane > 5 could produce -- so an algorithm that was developed for, and safe with, > the smaller Ariane suddenly went "something's wrong -- abandon ship" > > Nothing inherent in the language... > Well if the backup system that took over when the primary system gave up the ghost had used a different algorithm, and had been tested for an appropriate range of inputs, we wouldn't be having this discussion. It didn't. The rest is history, and very expensive history at that. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sat Sep 12 18:07:45 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 12 Sep 2015 23:07:45 +0100 Subject: Python handles globals badly. In-Reply-To: References: <1eee075d-7073-4875-9e42-2e053ee59b41@googlegroups.com> <0784va15gme91mqvoasfub3hvu59ehpepl@4ax.com> <201509102219.14138.gheskett@wdtv.com> Message-ID: On 12/09/2015 17:24, Dennis Lee Bieber wrote: > On Sat, 12 Sep 2015 03:35:00 +0100, Mark Lawrence > declaimed the following: > >> >> Ada took over from CORAL in the UK, at least in military projects. It >> was also used in the aircraft industry. My old work mates tell me that >> its completely died a death, to be replaced by C++. Someone please >> remind me never to fly again. > > Still used on some of the boxes being made... (I've just spent a month > investigating problem reports for a software release). > > Granted, that's an Ada 83 cross compiler running on VAX/VMS itself > running on a Windows server box with an emulator. It would cost way too > much money to try to recompile with, say, GNAT Pro -- as the entire suite > (including the compiler) would have to be recertified for airworthiness. > Having seen the comments on this thread I think some of the participants need to be recertified for programmerworthiness. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From emile at fenx.com Sat Sep 12 18:14:18 2015 From: emile at fenx.com (Emile van Sebille) Date: Sat, 12 Sep 2015 15:14:18 -0700 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> Message-ID: On 9/12/2015 12:58 PM, rurpy--- via Python-list wrote: > The question is whether what "pointer" means in languages that use the > word is*so* different than its meaning in the Python sense I can't find a single reference to pointer in the python docs outside of ctypes. What is its python sense? Is-there-no-hammer-in-this-toolbox-ly y'rs Emile From guido at python.org Sat Sep 12 18:24:58 2015 From: guido at python.org (Guido van Rossum) Date: Sat, 12 Sep 2015 15:24:58 -0700 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: On Sat, Sep 12, 2015 at 2:24 PM, Alexander Belopolsky < alexander.belopolsky at gmail.com> wrote: > > On Sat, Sep 12, 2015 at 4:10 PM, Tim Peters wrote: > >> "A potential problem" with .astimezone()'s default is that it _does_ >> create a fixed-offset zone. It's not at all obvious that it should do >> so. First time I saw it, my initial _expectation_ was that it >> "obviously" created a hybrid tzinfo reflecting the system zone's >> actual daylight rules, as various "tzlocal" implementations outside of >> Python do. >> > > The clue should have been that .astimezone() is an instance method and > you don't need to know time to create a hybrid tzinfo. If a Local tzinfo > was available, it could just be passed to the .astimezone() method as an > argument. You would not need .astimezone() to both create a tzinfo and > convert the datetime instance to it. > > Still, I agree that this was a hack and a very similar hack to the one > implemented by pytz. Hopefully once PEP 495 is implemented we will > shortly see "as intended" tzinfos to become more popular. > The repeated claims (by Alexander?) that astimezone() has the power of pytz's localize() need to stop. Those pytz methods work for any (pytz) timezone -- astimezone() with a default argument only works for the local time zone. (And indeed what it does is surprising, except perhaps to pytz users.) -- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rurpy at yahoo.com Sat Sep 12 18:34:58 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 12 Sep 2015 15:34:58 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> Message-ID: <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> On 09/12/2015 04:14 PM, Emile van Sebille wrote: > On 9/12/2015 12:58 PM, rurpy--- via Python-list wrote: > >> The question is whether what "pointer" means in languages that use the >> word is*so* different than its meaning in the Python sense > > I can't find a single reference to pointer in the python docs outside > of ctypes. What is its python sense? I should have said "proposed sense" (except I don't really mean proposed as in "let's change all the docs" but as "let's stop the hissy-fits when someone uses the term"), i.e. the way I, I think random832, and others use it re python. Sorry, I see in retrospect my phrasing could be confusing. From breamoreboy at yahoo.co.uk Sat Sep 12 19:14:33 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 13 Sep 2015 00:14:33 +0100 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> Message-ID: On 12/09/2015 23:34, rurpy--- via Python-list wrote: > On 09/12/2015 04:14 PM, Emile van Sebille wrote: >> On 9/12/2015 12:58 PM, rurpy--- via Python-list wrote: >> >>> The question is whether what "pointer" means in languages that use the >>> word is*so* different than its meaning in the Python sense >> >> I can't find a single reference to pointer in the python docs outside >> of ctypes. What is its python sense? > > I should have said "proposed sense" (except I don't really mean > proposed as in "let's change all the docs" but as "let's stop the > hissy-fits when someone uses the term"), i.e. the way I, I think > random832, and others use it re python. Sorry, I see in retrospect > my phrasing could be confusing. > The "hissy-fits" are caused because Python the language does not have pointers, so by definition there is no need to mention them in any way, shape or form in any Python thread. What is so difficult to understand about that? I would say it's not rocket science, but the insurers that paid out over Ariane 5 maybe wouldn't be too happy with that. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ned at nedbatchelder.com Sat Sep 12 19:27:32 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 12 Sep 2015 16:27:32 -0700 (PDT) Subject: Context-aware return In-Reply-To: References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, September 10, 2015 at 8:44:01 PM UTC-4, Denis McMahon wrote: > On Fri, 11 Sep 2015 03:54:14 +1000, Steven D'Aprano wrote: > > > If I did this thing, would people follow me down the street booing and > > jeering and throwing things at me? > > Yes > > >>> x = func() > >>> x > >>> func() > >>> print x == func() > >>> assert x == func() > > Would you expect the last two calls to func() to return 999 or "Awesome"? > Why? What is the material difference if any between interpreter (a) > displaying the return value and (b) comparing the return value with > another value. > > Debugging nightmare! I'll add my voice to the rising chorus condemning the very notion of a function that behaves this way! Then, I'll give you an implementation (Python 2): import inspect import opcode def magic_return(): frame = inspect.stack()[1][0] code = frame.f_code next_opcode = opcode.opname[ord(code.co_code[frame.f_lasti+3])] if next_opcode == "PRINT_EXPR": ret = "Used at the prompt" elif next_opcode == "POP_TOP": ret = "Value ignored" else: ret = "Normal call" print ret return ret def try_it(): magic_return() x = magic_return() print magic_return() magic_return() + "" This examines the byte code of the caller to determine the next byte code after the CALL_FUNCTION that called us. The byte code used next shows what will happen to the return value. Try it out: $ python -i detect_caller.py >>> magic_return() Used at the prompt 'Used at the prompt' >>> try_it() Value ignored Normal call Normal call Normal call Normal call >>> I'm sure there are plenty of cases this gets wrong. If you try to pin this on me, I will swear up and down that someone hacked into my account to send this message... --Ned. From rustompmody at gmail.com Sat Sep 12 19:39:48 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 12 Sep 2015 16:39:48 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> Message-ID: <239d70be-e78b-41d9-ad7b-c50461971784@googlegroups.com> On Sunday, September 13, 2015 at 4:05:21 AM UTC+5:30, ru... at yahoo.com wrote: > On 09/12/2015 04:14 PM, Emile van Sebille wrote: > > On 9/12/2015 12:58 PM, rurpy--- via Python-list wrote: > > > >> The question is whether what "pointer" means in languages that use the > >> word is*so* different than its meaning in the Python sense > > > > I can't find a single reference to pointer in the python docs outside > > of ctypes. What is its python sense? > > I should have said "proposed sense" (except I don't really mean > proposed as in "let's change all the docs" but as "let's stop the > hissy-fits when someone uses the term"), i.e. the way I, I think > random832, and others use it re python. Sorry, I see in retrospect > my phrasing could be confusing. Here is my post a little way up: ----------------------------------- On Saturday, September 12, 2015 at 10:02:40 PM UTC+5:30, Steven D'Aprano wrote: > On Sat, 12 Sep 2015 02:42 pm, Random832 wrote: > > > Anyway, maybe we do need a term to distinguish Python/C#/Java pointers > > from C/C++ pointers - maybe call it a "non-arithmetic" pointer, since > > the key thing about it is you can't do pointer arithmetic on them to get > > the object "next to" the one it points at. > > How about *just don't call them pointers*? You know, since they aren't > pointers in the computer science sense. > > The Free On-line Dictionary of Computing defines "pointer": > > 1. An address, from the point of view of a > programming language. A pointer may be typed, with its type > indicating the type of data to which it points. > Insisting that Python has pointers is like insisting that you use a text > editor by flipping bits. "What happens if I press Ctrl-X?" "Well, these > bits on the screen flip from black to white, these bits flip from white to > black, and these stay the same." > This is from the docs https://docs.python.org/3/library/functions.html#id id(object) Return the "identity" of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. CPython implementation detail: This is the address of the object in memory. ----------------------------------- which may be summarized as: 1. Steven (quoting Online dictionary): Pointer = Address 2. Steven: "Python has pointers" is ridiculous 3. Python docs: id returns an address in (C)Python To which we have Chris saying CPython ? Python Which reminds me of another definition Fig-Leaf: A device for converting poor porn into high art Even in languages like C with an ISO standard adhering to the standard is academic (gcc's switch is --pedantic) and it is in practice major implementations like gcc and MSC that define and push the standard. In python, CPython is the standard and other implementations can lay claim to being 'python' to the extent that they adhere to the standard. Or have I missed some ISO-ization? From ned at nedbatchelder.com Sat Sep 12 20:02:26 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 12 Sep 2015 17:02:26 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> Message-ID: <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> On Saturday, September 12, 2015 at 7:15:18 PM UTC-4, Mark Lawrence wrote: > On 12/09/2015 23:34, rurpy--- via Python-list wrote: > > On 09/12/2015 04:14 PM, Emile van Sebille wrote: > >> On 9/12/2015 12:58 PM, rurpy--- via Python-list wrote: > >> > >>> The question is whether what "pointer" means in languages that use the > >>> word is*so* different than its meaning in the Python sense > >> > >> I can't find a single reference to pointer in the python docs outside > >> of ctypes. What is its python sense? > > > > I should have said "proposed sense" (except I don't really mean > > proposed as in "let's change all the docs" but as "let's stop the > > hissy-fits when someone uses the term"), i.e. the way I, I think > > random832, and others use it re python. Sorry, I see in retrospect > > my phrasing could be confusing. > > > > The "hissy-fits" are caused because Python the language does not have > pointers, so by definition there is no need to mention them in any way, > shape or form in any Python thread. What is so difficult to understand > about that? I would say it's not rocket science, but the insurers that > paid out over Ariane 5 maybe wouldn't be too happy with that. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence After all the discussion here, it seems a bit disingenuous to flatly say that Python has no pointers, and to dismiss people's debate about it. Pointers are not a simple concept. In a language like C, they have a number of aspects, some of which are apparent in the Python world, and some of which are not. Python names refer to values, and this behavior is clearly related to pointers under the hood. Whatever Python implementation you are talking about, a Python name must have some way to indicate what value it refers to. In CPython, this is implemented with a pointer. This is what people mean when they say that of course Python has pointers. But in C, pointers mean more than that. You can perform arithmetic on them, to access memory as a linearly addressed abstraction. Python has nothing like this. In C, a pointer can refer to another variable. Again, Python has nothing like this. Python names refer to values, but they cannot refer to other names. These last two reasons are why people say that Python does not have pointers. As a language concept, Python has no pointers, because you cannot have names referring to names, and because you cannot perform arithmetic on references. The references from names to values are not things that can be manipulated themselves. In its implementation, CPython uses pointers. But if you say that Python has pointers because CPython uses pointers, then you might as well say that Python is statically typed because the CPython source has type declarations. It's a confusion of implementation and language to conflate these two. --Ned. From rosuav at gmail.com Sat Sep 12 20:19:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 13 Sep 2015 10:19:14 +1000 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <239d70be-e78b-41d9-ad7b-c50461971784@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <239d70be-e78b-41d9-ad7b-c50461971784@googlegroups.com> Message-ID: On Sun, Sep 13, 2015 at 9:39 AM, Rustom Mody wrote: > To which we have Chris saying CPython ? Python > Which reminds me of another definition > Fig-Leaf: A device for converting poor porn into high art > > Even in languages like C with an ISO standard adhering to the standard is > academic (gcc's switch is --pedantic) and it is in practice major > implementations like gcc and MSC that define and push the standard. > > In python, CPython is the standard and other implementations can lay claim to > being 'python' to the extent that they adhere to the standard. > > Or have I missed some ISO-ization? ISO hasn't standardized Python, but the Python developers do distinguish between the language and the various implementations. Yes, CPython does push forward ahead of the others, and thus sometimes another Python will replicate CPython behaviour rather than seeking an official language pronouncement; but other times, the PyPy or Jython or Brython folks come to python-dev with a question. As a general rule, most PEPs are about the language, not the implementation, so you can eyeball those to see what you'd need to implement to write a Python from scratch. CPython does not intrinsically define the standard. Some languages are done this way (Pike, for instance), but Python is not. ChrisA From rurpy at yahoo.com Sat Sep 12 20:23:28 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 12 Sep 2015 17:23:28 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> Message-ID: <8948afad-4cb5-415a-92a7-2954b2723885@googlegroups.com> On 09/12/2015 05:14 PM, Mark Lawrence wrote: > On 12/09/2015 23:34, rurpy--- via Python-list wrote: >> On 09/12/2015 04:14 PM, Emile van Sebille wrote: >>> On 9/12/2015 12:58 PM, rurpy--- via Python-list wrote: >>> >>>> The question is whether what "pointer" means in languages that >>>> use the word is*so* different than its meaning in the Python >>>> sense >>> >>> I can't find a single reference to pointer in the python docs >>> outside of ctypes. What is its python sense? >> >> I should have said "proposed sense" (except I don't really mean >> proposed as in "let's change all the docs" but as "let's stop the >> hissy-fits when someone uses the term"), i.e. the way I, I think >> random832, and others use it re python. Sorry, I see in retrospect >> my phrasing could be confusing. > > The "hissy-fits" are caused because Python the language does not have > pointers, so by definition there is no need to mention them in any > way, shape or form in any Python thread. Right. "And our country has no social unrest so there is no need for any mention of social unrest on our internet." (a common justification for censorship in some countries.) You can't define away reality, Bucky. But the issue is not one that can be expressed as a binary "has" or "has not". It is about how to best describe how Python works and what descriptions work best for what groups of people (at least in my view). > What is so difficult to understand about that? You'll find my questions about that in my previous posts. You can find them here: https://mail.python.org/pipermail/python-list/2015-September/thread.html If you have any specific serious questions I'll be happy to try to answer them for you. > I would say it's not rocket science, but the > insurers that paid out over Ariane 5 maybe wouldn't be too happy with > that. No clue what the Ariane 5 has to do with Python or how Python works is described. From rurpy at yahoo.com Sat Sep 12 20:25:15 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 12 Sep 2015 17:25:15 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <239d70be-e78b-41d9-ad7b-c50461971784@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <239d70be-e78b-41d9-ad7b-c50461971784@googlegroups.com> Message-ID: <8032121e-a62f-4610-be3a-51b471cad6d7@googlegroups.com> On 09/12/2015 05:39 PM, Rustom Mody wrote: > On Sunday, September 13, 2015 at 4:05:21 AM UTC+5:30, ru... at yahoo.com wrote: >> On 09/12/2015 04:14 PM, Emile van Sebille wrote: >>> On 9/12/2015 12:58 PM, rurpy--- via Python-list wrote: >>> >>>> The question is whether what "pointer" means in languages that use the >>>> word is*so* different than its meaning in the Python sense >>> >>> I can't find a single reference to pointer in the python docs outside >>> of ctypes. What is its python sense? >> >> I should have said "proposed sense" (except I don't really mean >> proposed as in "let's change all the docs" but as "let's stop the >> hissy-fits when someone uses the term"), i.e. the way I, I think >> random832, and others use it re python. Sorry, I see in retrospect >> my phrasing could be confusing. > > Here is my post a little way up: > > ----------------------------------- > On Saturday, September 12, 2015 at 10:02:40 PM UTC+5:30, Steven D'Aprano wrote: > [...] >> Insisting that Python has pointers is like insisting that you use a text >> editor by flipping bits. "What happens if I press Ctrl-X?" "Well, these >> bits on the screen flip from black to white, these bits flip from white to >> black, and these stay the same." > > This is from the docs > https://docs.python.org/3/library/functions.html#id > > id(object) > > Return the "identity" of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. > > CPython implementation detail: This is the address of the object in memory. > > ----------------------------------- > > which may be summarized as: > 1. Steven (quoting Online dictionary): Pointer = Address > 2. Steven: "Python has pointers" is ridiculous > 3. Python docs: id returns an address in (C)Python > > To which we have Chris saying CPython ? Python > Which reminds me of another definition > Fig-Leaf: A device for converting poor porn into high art > > Even in languages like C with an ISO standard adhering to the standard is > academic (gcc's switch is --pedantic) and it is in practice major > implementations like gcc and MSC that define and push the standard. > > In python, CPython is the standard and other implementations can lay claim to > being 'python' to the extent that they adhere to the standard. > > Or have I missed some ISO-ization? I have to agree with Steven and Chris here. Among other reasons because although id() allows you to determine if two objects are the same object, you can't dereference it to get any access to the object. So id() certainly doesn't give you something I would call a pointer. And though you are right about cpython's preeminent position, I don't think one can use that to make an argument about python-the-language unless it can be shown that implementing it in some other way would be very difficult. From rustompmody at gmail.com Sat Sep 12 20:28:06 2015 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 12 Sep 2015 17:28:06 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> Message-ID: <10052ca2-adac-45a9-b30e-7664eefc5a99@googlegroups.com> On Sunday, September 13, 2015 at 5:32:44 AM UTC+5:30, Ned Batchelder wrote: > In its implementation, CPython uses pointers. But if you say that Python > has pointers because CPython uses pointers, then you might as well say > that Python is statically typed because the CPython source has type > declarations. It's a confusion of implementation and language to conflate > these two. Yes that "because" can be ridiculous/disingenuous. Good deal of it in this thread itself. Consider int. Say there are 10,000 int something_or_other; in the CPython sources Out of these say 50 are the direct implementation python's int The remaining 9950 C-ints have no direct correlate with python's int. The disingenuous reasoning is some kind of statistical argument of 10,000 vs 50. The reasonable reasoning is that only those 50 are relevant to the discussion. Likewise pointers If one were to trace the semantics of looking up a variable in CPython, one would find some C code doing pointer dereferencing. One would also find zillions of other uses of pointers that have no direct correlate to python's variables. What of it? If I were to be more technically correct than saying "Python's variables are C-pointers" I could say something like: "Python variables are C pointers with much stronger data-structure invariants related to ownership. And implemented with ref-counting, gc etc as scaffolding to ensure them. These stronger invariants make impossible in python common C errors like null-pointer referencing. The corresponding cost of these stronger invariants is that C's pointer type is rendered un-first-class in python" From rurpy at yahoo.com Sat Sep 12 20:44:33 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 12 Sep 2015 17:44:33 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> Message-ID: On 09/12/2015 06:02 PM, Ned Batchelder wrote: > On Saturday, September 12, 2015 at 7:15:18 PM UTC-4, Mark Lawrence wrote: > [...] > But in C, pointers mean more than that. You can perform arithmetic on > them, to access memory as a linearly addressed abstraction. Python has > nothing like this. > > In C, a pointer can refer to another variable. Again, Python has > nothing like this. Python names refer to values, but they cannot > refer to other names. > > These last two reasons are why people say that Python does not have > pointers. > > As a language concept, Python has no pointers, because you cannot have > names referring to names, and because you cannot perform arithmetic on > references. The references from names to values are not things that can > be manipulated themselves. The reason python doesn't have pointers is that the majority of developers and documenters chose not to use the term. I don't see that pointer arithmetic is necessary to call something a pointer (and i think someone else said the same earlier). And references to a name I think that is an artifact of C because in C names and values are inextricably welded together at compile time -- a pointer to a name is also necessarily a pointer to a value. Since there are no C pointers to don't point to values they can provide a way to describe Python "things" that also point to values. If one acknowledges that those two properties are not intrinsic requirements for pointerness then describing the things "in" a python object that are used to identify and dereference other objects, as pointers is not at all unreasonable. From alexander.belopolsky at gmail.com Sat Sep 12 20:46:45 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Sat, 12 Sep 2015 20:46:45 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: On Sat, Sep 12, 2015 at 6:24 PM, Guido van Rossum wrote: > The repeated claims (by Alexander?) that astimezone() has the power of > pytz's localize() need to stop. Prove me wrong! :-) > Those pytz methods work for any (pytz) timezone -- astimezone() with a > default argument only works for the local time zone. That's what os.environ['TZ'] = zonename is for. The astimezone() method works for every timezone installed on your system. Try it - you won't even need to call time.tzset()! > (And indeed what it does is surprising, except perhaps to pytz users.) That I agree with. Which makes it even more surprising that I often find myself and pytz advocates on the opposite sides of the fence. Granted, setting TZ is a silly trick, but one simple way to bring a full TZ database to Python is to allow .astimezone() take a zonename string like 'Europe/Amsterdam' or 'America/Montevideo' as an argument and act as os.environ['TZ'] = zonename; t.astimezone() does now, but without messing with global state. I made this suggestion before, but I find it inferior to "as intended" tzinfos. The only real claim that I am making is that fictitious fixed offset timezones are useful and we already have some support for them in stdlib. The datetime.timezone instances that .astimezone() attaches as tzinfo are not that different from the instances that are attached by pytz's localize and normalize methods. In fact, the only major differences between datetime.timezone instances and those used by pytz is that pytz's EST and EDT instances know that they come from America/New_York, while datetime.timezone instances don't. That's why once you specify America/New_York in localize, your tzinfo.normalize knows it implicitely, while in the extended .astimezone() solution you will have to specify it again. This is not a problem when you only support one local timezone, but comes with a different set of tradeoffs when you have multiple timezones. One advantage of not carrying the memory of the parent zoneinfo in the fixed offset tzinfo instance is that pickling of datetime objects and their interchange between different systems becomes simpler. A pickle of a datetime.timezone instance is trivial - same as that of a tuple of timedelta and a short string, but if your fixed offset tzinfo carries a reference to a potentially large zoneinfo structure, you get all kinds of interesting problems when you share them between systems that have different TZ databases. In any case, there are three approaches to designing a TZ database interface in the datetime module: the "as intended" approach, the pytz approach and the astimezone(zonename:str) approach. The last two don't require a fold attribute to disambiguate end-of-dst times and the first one does. With respect to arithmetic, the last two approaches are equivalent: both timeline and classic arithmetics are possible, but neither is painless. The "as intended" approach comes with classic arithmetic that "just works" and encourages the best practice for timeline arithmetic: do it in UTC. That's why I believe PEP 495 followed by the implementation of fold-aware "as intended" tzinfos (either within stdlib or by third parties) is the right approach. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rurpy at yahoo.com Sat Sep 12 21:07:55 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 12 Sep 2015 18:07:55 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <8032121e-a62f-4610-be3a-51b471cad6d7@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <239d70be-e78b-41d9-ad7b-c50461971784@googlegroups.com> <8032121e-a62f-4610-be3a-51b471cad6d7@googlegroups.com> Message-ID: <46a62859-d142-4cce-bb14-161d6ff4718e@googlegroups.com> On Saturday, September 12, 2015 at 6:25:39 PM UTC-6, ru... at yahoo.com wrote: > On 09/12/2015 05:39 PM, Rustom Mody wrote: > [...] > > which may be summarized as: > > 1. Steven (quoting Online dictionary): Pointer = Address > > 2. Steven: "Python has pointers" is ridiculous > > 3. Python docs: id returns an address in (C)Python > > > > To which we have Chris saying CPython ? Python > > [...] > I have to agree with Steven and Chris here. > [...] I'm writing too fast. Just to clarify, I don't of course agree that python doesn't have pointers (or something that can be labeled as such), just that the existence of id() and cpython's internal use of pointers are not good arguments that it doesn't. From ben+python at benfinney.id.au Sat Sep 12 21:13:06 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 13 Sep 2015 11:13:06 +1000 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> Message-ID: <854miz6s0t.fsf@benfinney.id.au> Rustom Mody writes: > On Saturday, September 12, 2015 at 11:57:01 AM UTC+5:30, Ben Finney wrote: > > You've clearly committed to some ontology that just doesn't match > > the Python data model. > > How about lay-English ontology in which "point to" and "refer to" are fairly > synonymous? That's important. It's unrelated, though, to the very specific technical programming concepts to which I was responding. -- \ ?One bad programmer can easily create two new jobs a year. | `\ Hiring more bad programmers will just increase our perceived | _o__) need for them.? ?David Lorge Parnas, 1999-03 | Ben Finney From tim.peters at gmail.com Sat Sep 12 21:58:48 2015 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 12 Sep 2015 20:58:48 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: [Guido] >> Those pytz methods work for any (pytz) timezone -- astimezone() with a >> default argument only works for the local time zone. {Alex] > That's what os.environ['TZ'] = zonename is for. The astimezone() method > works for every timezone installed on your system. Try it - you won't even > need to call time.tzset()! I tried it. It makes no difference to anything for me. I stay on Windows to remind people that millions of Python users don't see any of the horrid nonsense Linuxish systems force on poor users ;-) > ... > In any case, there are three approaches to designing a TZ database interface > in the datetime module: the "as intended" approach, the pytz approach and > the astimezone(zonename:str) approach. Portability rules out #3, unless Python bundles its own zoneinfo wrapping. pytk's approach has many attractions, like no need for `fold` and no breakage of anything, and blazing fast .utcoffset(). Except at least arithmetic would have to be patched to do a `normalize` variant by magic (to attach the now-appropriate fixed-offset tzinfo, but without changing the clock in the process). Alas, that would be a huge speed hit for classic arithmetic. So, as always, the original intent is the only one that makes sense in the end ;-) > ... > That's why I believe PEP 495 followed by the implementation > of fold-aware "as intended" tzinfos (either within stdlib or by third > parties) is the right approach. Me too - except I think acceptance of 495 should be contingent upon someone first completing a fully functional (if not releasable) fold-aware zoneinfo wrapping. Details have a way of surprising, and we should learn from the last time we released a tzinfo spec in the absence of any industrial-strength wrappings using it. From guido at python.org Sat Sep 12 22:13:04 2015 From: guido at python.org (Guido van Rossum) Date: Sat, 12 Sep 2015 19:13:04 -0700 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: On Sat, Sep 12, 2015 at 5:46 PM, Alexander Belopolsky < alexander.belopolsky at gmail.com> wrote: > > On Sat, Sep 12, 2015 at 6:24 PM, Guido van Rossum > wrote: > >> The repeated claims (by Alexander?) that astimezone() has the power of >> pytz's localize() need to stop. > > > Prove me wrong! :-) > > >> Those pytz methods work for any (pytz) timezone -- astimezone() with a >> default argument only works for the local time zone. > > > That's what os.environ['TZ'] = zonename is for. The astimezone() method > works for every timezone installed on your system. Try it - you won't even > need to call time.tzset()! > That's global state. Doesn't count. > (And indeed what it does is surprising, except perhaps to pytz users.) > > > That I agree with. Which makes it even more surprising that I often find > myself and pytz advocates on the opposite sides of the fence. > > Granted, setting TZ is a silly trick, but one simple way to bring a full > TZ database to Python is to allow .astimezone() take a zonename string like > 'Europe/Amsterdam' or 'America/Montevideo' as an argument and act as > os.environ['TZ'] = zonename; t.astimezone() does now, but without messing > with global state. > It might as well be a different method then though. > I made this suggestion before, but I find it inferior to "as intended" > tzinfos. > > The only real claim that I am making is that fictitious fixed offset > timezones are useful and we already have some support for them in stdlib. > The datetime.timezone instances that .astimezone() attaches as tzinfo are > not that different from the instances that are attached by pytz's localize > and normalize methods. > And it has the same defect. > In fact, the only major differences between datetime.timezone instances > and those used by pytz is that pytz's EST and EDT instances know that they > come from America/New_York, while datetime.timezone instances don't. > That's why once you specify America/New_York in localize, your > tzinfo.normalize knows it implicitely, while in the extended .astimezone() > solution you will have to specify it again. This is not a problem when you > only support one local timezone, but comes with a different set of > tradeoffs when you have multiple timezones. > > One advantage of not carrying the memory of the parent zoneinfo in the > fixed offset tzinfo instance is that pickling of datetime objects and their > interchange between different systems becomes simpler. A pickle of a > datetime.timezone instance is trivial - same as that of a tuple of > timedelta and a short string, but if your fixed offset tzinfo carries a > reference to a potentially large zoneinfo structure, you get all kinds of > interesting problems when you share them between systems that have > different TZ databases. > The pickling should be careful to pickle by reference (on the timezone name). That its meaning depends on the tz database is a feature. > In any case, there are three approaches to designing a TZ database > interface in the datetime module: the "as intended" approach, the pytz > approach and the astimezone(zonename:str) approach. The last two don't > require a fold attribute to disambiguate end-of-dst times and the first one > does. With respect to arithmetic, the last two approaches are equivalent: > both timeline and classic arithmetics are possible, but neither is > painless. The "as intended" approach comes with classic arithmetic that > "just works" and encourages the best practice for timeline arithmetic: do > it in UTC. That's why I believe PEP 495 followed by the implementation of > fold-aware "as intended" tzinfos (either within stdlib or by third parties) > is the right approach. > Right. So please focus on this path and don't try to pretend to pytz users that hacks around astimezone() make pytz redundant, because they don't. There are other ways to fix the damage that pytz has done. -- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexander.belopolsky at gmail.com Sat Sep 12 22:15:02 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Sat, 12 Sep 2015 22:15:02 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: On Sat, Sep 12, 2015 at 9:58 PM, Tim Peters wrote: > > That's why I believe PEP 495 followed by the implementation > > of fold-aware "as intended" tzinfos (either within stdlib or by third > > parties) is the right approach. > > Me too - except I think acceptance of 495 should be contingent upon > someone first completing a fully functional (if not releasable) > fold-aware zoneinfo wrapping. Good idea. How far are you from completing that? > Details have a way of surprising, and > we should learn from the last time we released a tzinfo spec in the > absence of any industrial-strength wrappings using it. I completely agree. That's why I am adding test cases like Lord Hope Island and Vilnius to datetimetester. I will try to create a zoneinfo wrapping prototype as well, but I will probably "cheat" and build it on top of pytz. -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sat Sep 12 22:22:58 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 13 Sep 2015 03:22:58 +0100 Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> Message-ID: On 13/09/2015 01:44, rurpy--- via Python-list wrote: > On 09/12/2015 06:02 PM, Ned Batchelder wrote: >> On Saturday, September 12, 2015 at 7:15:18 PM UTC-4, Mark Lawrence wrote: >> [...] >> But in C, pointers mean more than that. You can perform arithmetic on >> them, to access memory as a linearly addressed abstraction. Python has >> nothing like this. >> >> In C, a pointer can refer to another variable. Again, Python has >> nothing like this. Python names refer to values, but they cannot >> refer to other names. >> >> These last two reasons are why people say that Python does not have >> pointers. >> >> As a language concept, Python has no pointers, because you cannot have >> names referring to names, and because you cannot perform arithmetic on >> references. The references from names to values are not things that can >> be manipulated themselves. > > The reason python doesn't have pointers is that the majority of developers > and documenters chose not to use the term. Nonsense. > > I don't see that pointer arithmetic is necessary to call something a pointer > (and i think someone else said the same earlier). And references to a name > I think that is an artifact of C because in C names and values are inextricably > welded together at compile time -- a pointer to a name is also necessarily a > pointer to a value. Since there are no C pointers to don't point to values > they can provide a way to describe Python "things" that also point to values. There are certainly no C pointers in Jython or IronPython but please don't let that stop you. > > If one acknowledges that those two properties are not intrinsic requirements > for pointerness then describing the things "in" a python object that are used > to identify and dereference other objects, as pointers is not at all unreasonable. > You appear to have the same level of knowledge of Python internals as the RUE has of the Python 3.3+ FSR unicode implementation. Let's have some fun, is Python pass by value or pass by reference? It has to be more interesting debating that than the drivel that's gone before in this thread. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tim.peters at gmail.com Sat Sep 12 22:25:19 2015 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 12 Sep 2015 21:25:19 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: [Tim] >> Me too - except I think acceptance of 495 should be contingent upon >> someone first completing a fully functional (if not releasable) >> fold-aware zoneinfo wrapping. [Alex] > Good idea. How far are you from completing that? In my head, it was done last week ;-) In real life, I'm running out of spare time for much of anything anymore. I don't expect to be able to resume zoneinfo fiddling for at least 2 weeks. >> Details have a way of surprising, and >> we should learn from the last time we released a tzinfo spec in the >> absence of any industrial-strength wrappings using it. > I completely agree. That's why I am adding test cases like Lord Hope Island > and Vilnius to datetimetester. That helps a lot, but "industrial-strength" implies "by algorithm". There are far too many zones to deal with by crafting a hand-written class for each. > I will try to create a zoneinfo wrapping prototype as well, but I will > probably "cheat" and build it on top of pytz. It would be crazy not to ;-) Note that Stuart got to punt on "the hard part": .utcoffset(), since pytz only uses fixed-offset classes. For a prototype - and possibly forever after - I'd be inclined to create an exhaustive list of transition times in local time, parallel to the list of such times already there in UTC. An index into either list then gives an index into the other, and into the list of information about the transition (total offset, is_dst, etc). From ned at nedbatchelder.com Sat Sep 12 22:25:30 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 12 Sep 2015 19:25:30 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> Message-ID: <1790a372-ac4f-4569-9afb-2fda0b846e96@googlegroups.com> On Saturday, September 12, 2015 at 10:23:24 PM UTC-4, Mark Lawrence wrote: > On 13/09/2015 01:44, rurpy--- via Python-list wrote: > > On 09/12/2015 06:02 PM, Ned Batchelder wrote: > >> On Saturday, September 12, 2015 at 7:15:18 PM UTC-4, Mark Lawrence wrote: > >> [...] > >> But in C, pointers mean more than that. You can perform arithmetic on > >> them, to access memory as a linearly addressed abstraction. Python has > >> nothing like this. > >> > >> In C, a pointer can refer to another variable. Again, Python has > >> nothing like this. Python names refer to values, but they cannot > >> refer to other names. > >> > >> These last two reasons are why people say that Python does not have > >> pointers. > >> > >> As a language concept, Python has no pointers, because you cannot have > >> names referring to names, and because you cannot perform arithmetic on > >> references. The references from names to values are not things that can > >> be manipulated themselves. > > > > The reason python doesn't have pointers is that the majority of developers > > and documenters chose not to use the term. > > Nonsense. > > > You appear to have the same level of knowledge of Python internals as > the RUE has of the Python 3.3+ FSR unicode implementation. Let's have > some fun, is Python pass by value or pass by reference? It has to be > more interesting debating that than the drivel that's gone before in > this thread. Mark, I'm sure you can be more respectful than this. And let's please not start down the "PBV or PBR" road... :( --Ned. From steve at pearwood.info Sat Sep 12 22:30:40 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 13 Sep 2015 12:30:40 +1000 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> Message-ID: <55f4dfd0$0$1669$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Sep 2015 07:10 am, Random832 wrote: > Jussi Piitulainen writes: >> I think the best way is to say that a[0] and a[1] are the same object, >> while b[0] and b[1] are different objects. > > Sure, you can *say* that. But how do you draw it on a diagram with > sticky notes or parcel tags or whatever? However you like. Invent your own notation. A few suggestions: Colour coding: Have a convention that objects drawn in black imply that object identity is not important. That is, if you have two boxes drawn in black with the same value, you are making no claim one way or the other whether they are the same object or not. If, and only if, identity is important, then you give each object a unique colour. So if the user sees five boxes containing the value "foo", two in red, two in green, and one in black, they know that there are at least two, and possibly three, but no more than three, individual objects. Shapes: Likewise, except instead of colour, use the shape of the box to indicate identity. A rectangular box means you say nothing about identity. Other shapes (circle, oval, rhombus, trapezium, parallelogram, cloud-shape, etc.) uniquely represents the individual objects. IDs: Write the object ID on each box, or at least the boxes where identity is important. A good convention is that IDs start at 1. Or, rather than show a numeric ID, use a symbolic ID: a, b, c, d, e would reference five distinct objects. Or, use non-alphabetical symbolic IDs: *?? would let you identify three distinct objects. Add extra symbols as needed. Astral travel: According to those who believe in the astral plane, when you travel through the astral plane, a silver thread connects your physical body to your astral body. Or your earthly soul to your astral soul. Or whatever it is that they believe. Use the same symbolism: if you have two or more boxes representing the same object in different places, join them with a silver thread. Or other colour of your choice. Perhaps a dotted or dashed line. Hatch marks: There is a convention in geometry to indicate lines of equal length with a hatch mark (a small line perpendicular to the line itself). You can mark the boxes which refer to identical objects using a similar convention. Here is a crappy ASCII-art representation of various hatch marks on a horizontal line: ----|----||----|||----/----//----\----\\----X----XX---->----<---- That is, reading from left to right: - 1 to 3 vertical lines; - 1 or 2 lines slanted up to the right; - 1 or 2 lines slanted down from the left; - 1 or 2 crossed lines; - single right-pointing arrow; - single left-pointing arrow. If you limit yourself to no more than four hatch marks, taken from the set of "|/\X<>", that gives you 1554 distinct markers. If you need to identify more than 1554 distinct objects on one diagram, I suggest your diagram is a tad too complex. -- Steven From torriem at gmail.com Sat Sep 12 22:32:36 2015 From: torriem at gmail.com (Michael Torrie) Date: Sat, 12 Sep 2015 20:32:36 -0600 Subject: Python handles globals badly. In-Reply-To: <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> Message-ID: <55F4E044.2050309@gmail.com> On 09/11/2015 11:22 PM, Skybuck Flying wrote: > I didn't learn anything from this posting, sorry ! ;) I too am not surprised. You're not here to learn, either about programming language theory, or about Python apparently. I would refer you to a good programming language theory class, but I suspect you're not interested in learning formal definitions and theory. The terms I used here are all from formal programming language theory, particularly the term "binding." If you're interested in it, this topic makes for a fascinating class. I loved my programming language theory class at uni. We used scheme to explore language construction and to build our own programming language. Cool stuff. I'm truly sorry you aren't interested in learning the underlying theories of things, or the reasons for certain aspects of the language. To me Python's ability to enable so many different programming paradigms, and to bring some of the coolest parts of LISP and Scheme to a language for the masses is really cool. From torriem at gmail.com Sat Sep 12 22:35:12 2015 From: torriem at gmail.com (Michael Torrie) Date: Sat, 12 Sep 2015 20:35:12 -0600 Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> Message-ID: <55F4E0E0.6020009@gmail.com> On 09/12/2015 08:22 PM, Mark Lawrence wrote: > You appear to have the same level of knowledge of Python internals as > the RUE has of the Python 3.3+ FSR unicode implementation. Let's have > some fun, is Python pass by value or pass by reference? It has to be > more interesting debating that than the drivel that's gone before in > this thread. Oh you are a devious one there! This should get good. From alexander.belopolsky at gmail.com Sat Sep 12 22:40:33 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Sat, 12 Sep 2015 22:40:33 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: On Sat, Sep 12, 2015 at 10:25 PM, Tim Peters wrote: > > I will try to create a zoneinfo wrapping prototype as well, but I will > > probably "cheat" and build it on top of pytz. > > It would be crazy not to ;-) Note that Stuart got to punt on "the > hard part": .utcoffset(), since pytz only uses fixed-offset classes. > For a prototype - and possibly forever after - I'd be inclined to > create an exhaustive list of transition times in local time, parallel > to the list of such times already there in UTC. Yes. The only complication is that you need four transition points instead of two per year in a regular DST case: (1) start of gap; (2) end of gap; (3) start of fold; and (4) end of fold. Once you know where you are with respect to those points, figuring out utcoffset(), dst() and tzname() for either value of fold is trivial. > An index into either > list then gives an index into the other, and into the list of > information about the transition (total offset, is_dst, etc). Right. It's a shame though to work from a transitions in UTC list because most of DST rules are expressed in local times and then laboriously converted into UTC. I think I should also implement the POSIX TZ spec tzinfo. This is where the advantage of the "as intended" approach will be obvious. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Sat Sep 12 22:42:48 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 13 Sep 2015 12:42:48 +1000 Subject: Terminology: "reference" versus "pointer" References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> <55F4E0E0.6020009@gmail.com> Message-ID: <85zj0r59av.fsf@benfinney.id.au> Michael Torrie writes: > On 09/12/2015 08:22 PM, Mark Lawrence wrote: > > You appear to have the same level of knowledge of Python internals as > > the RUE has of the Python 3.3+ FSR unicode implementation. Let's have > > some fun, is Python pass by value or pass by reference? It has to be > > more interesting debating that than the drivel that's gone before in > > this thread. > > Oh you are a devious one there! This should get good. No, it should stop there. Taunting trolls is no more welcome here than trolling. -- \ ?I have always wished for my computer to be as easy to use as | `\ my telephone; my wish has come true because I can no longer | _o__) figure out how to use my telephone.? ?Bjarne Stroustrup | Ben Finney From random832 at fastmail.com Sat Sep 12 22:54:09 2015 From: random832 at fastmail.com (random832 at fastmail.com) Date: Sat, 12 Sep 2015 22:54:09 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: <1442112849.1530082.382090617.0F961872@webmail.messagingengine.com> On Sat, Sep 12, 2015, at 22:25, Tim Peters wrote: > That helps a lot, but "industrial-strength" implies "by algorithm". > There are far too many zones to deal with by crafting a hand-written > class for each. It occurs to me that though it's written in C, the zdump utility included in the tz code is implementation-agnostic w.r.t. what algorithm is used by the localtime function being tested. It's algorithm could probably be adapted to python. From tim.peters at gmail.com Sat Sep 12 23:54:47 2015 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 12 Sep 2015 22:54:47 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: [Alex] >>> I will try to create a zoneinfo wrapping prototype as well, but I will >>> probably "cheat" and build it on top of pytz. [Tim] >> It would be crazy not to ;-) Note that Stuart got to punt on "the >> hard part": .utcoffset(), since pytz only uses fixed-offset classes. >> For a prototype - and possibly forever after - I'd be inclined to >> create an exhaustive list of transition times in local time, parallel >> to the list of such times already there in UTC. [Alex] > Yes. The only complication is that you need four transition points instead > of two per year in a regular DST case: (1) start of gap; (2) end of gap; (3) > start of fold; and (4) end of fold. Once you know where you are with > respect to those points, figuring out utcoffset(), dst() and tzname() for > either value of fold is trivial. I wouldn't call those extras transitions - they're just warts hanging off of actual transitions. Earlier I showed Stuart how to determine everything about a possible fold from a UTC time using pytz's internal info, in PEP-431/495 Fri, 28 Aug 2015 01:01:06 -0500 He didn't reply that I saw, so it was either obvious or incomprehensible to him ;-) In any case, it just takes some very simple code once the transition record the UTC time belongs in is found. I'd be surprised if it weren't similarly easy to determine everything about a possible gap. At least in a zoneinfo wrapping, a hybrid tzinfo's .utcoffset() has to (at least internally) find "the transition record the UTC time belongs in" regardless. > ... > It's a shame though to work from a transitions in UTC list But that's what tzfiles store. It would be insane for a zoneinfo wrapping not to take advantage of that. For which reason, I do consider dateutil's zoneinfo wrapping to be insane ;-) (It inherits the default .fromutc()) Ah, BTW, I think dateutil's zoneinfo's wrapping also misunderstood some of what's actually in a tzfile. Specifically, a tzfile's " UTC/local indicators" and " standard/wall indicators" are 100% useless for anything we need, and shouldn't even be read from the file(*) (seek over 'em). > because most of DST rules are expressed in local times and then > laboriously converted into UTC. It's just a few lines of code in zoneinfo's zic.c. Nobody is doing it "by hand" there. > I think I should also implement the POSIX TZ spec tzinfo. For that you really should grab dateutil. It has a full implementation of POSIX TZ rules, as hybrid tzinfos; here from its docs: >>> tz1 = tzstr('EST+05EDT,M4.1.0,M10.5.0') >>> tz2 = tzstr('AEST-10AEDT-11,M10.5.0,M3.5.0') >>> dt = datetime(2003, 5, 8, 2, 7, 36, tzinfo=tz1) >>> dt.strftime('%X %x %Z') '02:07:36 05/08/03 EDT' >>> dt.astimezone(tz2).strftime('%X %x %Z') '16:07:36 05/08/03 AEST' Of course this implementation is tied into dateutil's rich supply of "calendar operations" too. > This is where the advantage of the "as intended" approach will be obvious. ? "As intended" is all about (to me) using hybrid tzinfos. And those are far richer in tzfiles than from POSIX rules. The latter only present us with simplest-possible DST transitions; tzfiles present us with every absurd political manipulation yet inflicted on humankind ;-) ------- (*) Long boring story. Short course: those indicators are only needed, on some systems, if a POSIZ TZ rule specifies a zone offset but gives no rules at all for daylight transitions, _and_ the system has a "posixrules" tzfile. Then an insane scheme is used to make up daylight rules "as if" the source file from which the posixrules tzfile was created had been for a zone with the TZ-specified standard offset instead, and these absurd indicators are used to figure out whether the posixrules source file specified _its_ daylight rules using UTC or local times, and if the later case then whether using standard time or wall-clock time instead. It's completely nuts. From davros at bellaliant.net Sun Sep 13 02:08:54 2015 From: davros at bellaliant.net (John McKenzie) Date: Sun, 13 Sep 2015 06:08:54 GMT Subject: RPI.GPIO Help References: Message-ID: Hello, there. MRAB, thank you for teaching me proper Python syntax for how I tried to use the or operator. Dennis, I must have learned allot recently as I believe I understood 99% of that code. I see how it is not just more advanced, but actually better than what I had. However, line 47 (cumTime[colour] += now - changeTime) had an error I could not figure out what to do about. Considering my time line I decided not to leave it to latter. Will be using these electronic flags at next year's game and for then I intend to just be better about everything. Will use your code to learn to get there. Hakugin, thank you you as well. I took the basic ideas you showed me for improvement and used them. The pulse settings variable was not liked by the interpreter, so I simplified it. I turned it into a hex value for each button press, then in the main loop I inserted the whole line for the LED pulse command, but put "pulse_settings" after "hex=" in the arguments. This worked. I added a few green blinks of the LED to indicate the starting and stopping of the script. Also, I got the log files score print outs upon exit working. Very important, and also importantly, I have it so it stops after a certain amount of time. For testing, I have it at 60 seconds, but games will be 3600 seconds on average when really being used. The stopping after a certain amount of time was done in a way that apparently technically works, but seems very weird and probably wrong to me. You may freak out when you see it. I used an else statement inside a while loop and it just feels so strange. At least it works. Hoping I might be able to make it so I boot the Pi, it loads the script, script waits for the user to tell it how long to make a game, game starts, scripts ends game at appropriate time, saves dated log file with scores, then waits for user to enter new game length to start new game. This is probably way to much to hope to accomplish in time. For next year for sure though. It would be better for the referees to operate that way. Next I will try and integrate wireless communications. If anyone here knows Synapse RF modules well, or at all, PLEASE contact me. Here is the code I did up most recently. Again, thanks for all the suggestions, code examples, and general help. import atexit import sys import time from blinkstick import blinkstick import RPi.GPIO as GPIO gamestart = time.time() gamelength = 60 led = blinkstick.find_first() colour = 0 time_red = 0 time_yellow = 0 time_blue = 0 timestamp = time.strftime("%H:%M:%S") pulse_settings = [] led.blink(name="green", repeats=2) GPIO.setmode(GPIO.BCM) GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) def red_button(channel): global colour global pulse_settings if colour != 1: colour = 1 pulse_settings = "#FF0000" def yellow_button(channel): global colour global pulse_settings if colour != 2: colour = 2 pulse_settings = "#FF8900" # Corrected yellow for cheap LED strip. def blue_button(channel): global colour global pulse_settings if colour != 3: colour = 3 pulse_settings = "#0000FF" GPIO.add_event_detect(22, GPIO.FALLING, callback=red_button, bouncetime=200) GPIO.add_event_detect(23, GPIO.FALLING, callback=yellow_button, bouncetime=200) GPIO.add_event_detect(24, GPIO.FALLING, callback=blue_button, bouncetime=200) def exit_handler(): print "\033[0;41;37mRed Team:\033[0m ", time_red print "\033[0;103;30mYellow Team:\033[0m ", time_yellow print "\033[0;44;37mBlue Team:\033[0m ", time_blue flog = open("flag1.log", "a") flog.write("\n" + timestamp + "\n" + "Red Team: " + str(time_red) + "\n" + "Yellow Team: " + str(time_yellow) + "\n" + "Blue Team: " + str (time_blue) + "\n") flog.close() led.blink(name="green", repeats=4) led.set_color(name="black") atexit.register(exit_handler) while time.time() < gamestart + gamelength: if colour == 1: time_red += 1 elif colour == 2: time_yellow += 1 elif colour == 3: time_blue += 1 led.pulse(hex=pulse_settings, repeats=1, duration=2000, steps=50) time.sleep(0.1) else: sys.exit() GPIO.cleanup() From harvesting at makes.email.invalid Sun Sep 13 02:40:54 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Sun, 13 Sep 2015 09:40:54 +0300 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> Message-ID: Random832 writes: > Jussi Piitulainen writes: >> I think the best way is to say that a[0] and a[1] are the same >> object, while b[0] and b[1] are different objects. > > Sure, you can *say* that. But how do you draw it on a diagram with > sticky notes or parcel tags or whatever? I prefer to outline my code as code, with comments where needed, without irrelevant details. Those pointers and tags are usually irrelevant, best omitted altogether. From manjunatha.mahalingappa at gmail.com Sun Sep 13 03:38:03 2015 From: manjunatha.mahalingappa at gmail.com (manjunatha.mahalingappa at gmail.com) Date: Sun, 13 Sep 2015 00:38:03 -0700 (PDT) Subject: How to use the returned telnet object after creating the telnet session. Message-ID: Hello all, First I would like thank you for creating such good platform for discussing python..!!! Assume that I will pass IP and port information from a function to open the telnet session. have opened the telnet session and after opening the telnet session I returned telnet object to calling function. Now in the calling function If I use that object to read or write to terminal I'm getting ERROR "AttributeError: 'NoneType' object has no attribute 'read_very_eager'". #Open telnet connection to devices def open_telnet_conn(dname,ip,port): try: TELNET_PORT = port TELNET_TIMEOUT = 5 READ_TIMEOUT = 5 cmd = "show config" #Logging into device connection=telnetlib.Telnet(ip, TELNET_PORT, TELNET_TIMEOUT) time.sleep(1) connection.write(cmd + "\n") #Here I'm able to write to connection object.. connection.write("\n") time.sleep(2) router_output = connection.read_very_eager() print router_output return(connection) except IOError: print "Input parameter error! Please check username, password and file name." #Function to read device IP and port . and this info for opening the telnet session. def IP_port(file): T = [] F = open(file,'r') F.seek(0) line=F.read() tuples = re.findall(r'(.+?)\s+(.+?)\s+(\d+)',line) #(dname,IP,port)= tuples for (dname,ip,port) in tuples: T1=open_telnet_conn(dname,ip,port) #HERE I will get the telnet object point to the same location as the connection object. But I'm unable to write or read anything here. I think need to convert the object T1 to TELNET CLASS object type.. print T1 T1.write("show config") <<<<<<<< Message-ID: On Sun, 13 Sep 2015 00:38:03 -0700, manjunatha.mahalingappa wrote: > Assume that I will pass IP and port information from a function to open > the telnet session. have opened the telnet session and after opening the > telnet session I returned telnet object to calling function. > > Now in the calling function If I use that object to read or write to > terminal I'm getting ERROR "AttributeError: 'NoneType' object has no > attribute 'read_very_eager'". My best guess would be that something failed and has returned None instead of the object / class you're expecting. -- Denis McMahon, denismfmcmahon at gmail.com From skybuck2000 at hotmail.com Sun Sep 13 08:04:22 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Sun, 13 Sep 2015 14:04:22 +0200 Subject: Python handles globals badly. In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> Message-ID: <8d648$55f56643$d47876e2$38352@news.ziggo.nl> " Namespaces don't "become writeable". The purpose of "global" is to tell the compiler that this name should be bound in the global namespace, not the local namespace. " How does it become writeable then ? Bye, Skybuck. From skybuck2000 at hotmail.com Sun Sep 13 08:05:10 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Sun, 13 Sep 2015 14:05:10 +0200 Subject: Python handles globals badly. In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> Message-ID: >From what he wrote I can see he's not making much sense... Neither are you. Just lot's of nag and little python related stuff. Bye, Skybuck. From steve at pearwood.info Sun Sep 13 08:06:33 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 13 Sep 2015 22:06:33 +1000 Subject: Python handles globals badly. References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> <8d648$55f56643$d47876e2$38352@news.ziggo.nl> Message-ID: <55f566c8$0$1644$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Sep 2015 10:04 pm, Skybuck Flying wrote: > " > Namespaces don't "become writeable". > > The purpose of "global" is to tell the compiler that this name should > be bound in the global namespace, not the local namespace. > " > > How does it become writeable then ? It's always writeable. -- Steven From skybuck2000 at hotmail.com Sun Sep 13 08:06:42 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Sun, 13 Sep 2015 14:06:42 +0200 Subject: Python handles globals badly. In-Reply-To: References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> Message-ID: <23bf4$55f566d0$d47876e2$39971@news.ziggo.nl> "Emile van Sebille" wrote in message news:mailman.433.1442078406.8327.python-list at python.org... On 9/11/2015 10:22 PM, Skybuck Flying wrote: > I didn't learn anything from this posting, sorry ! ;) " I'm seeing a pattern here... " Only thing I might have learned from him was global namespace make thing writeable. But now somebody else says nope. So I can truely say nothing was learned. Explaining concepts to people takes something different. As far as I am concerned python works with objects like Delphi. And everything else is a reference to it. And the globals are somehow protected. But he's as clueless as everybody else seems to be. For me it doesn't matter since I will write python code just fine without understanding any of it. Bye, Skybuck. From skybuck2000 at hotmail.com Sun Sep 13 08:10:04 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Sun, 13 Sep 2015 14:10:04 +0200 Subject: Python handles globals badly. In-Reply-To: <23bf4$55f566d0$d47876e2$39971@news.ziggo.nl> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> <23bf4$55f566d0$d47876e2$39971@news.ziggo.nl> Message-ID: <18251$55f5679a$d47876e2$42283@news.ziggo.nl> I may add to that: Just like most programmers don't truely understand what a compiler does ! HAHAHAHAHA. C programmers, Delphi programmers, Java programmers. What python's interpreter is doing same thing, probably completely irrelevant. Except when it comes to making changes to how python works ;) I don't need to know how the Python interpreter works, cause I will never change Python's implementation. However as indicated I did try to help out. Reversing the logic for python's global functioning should be possible. Bye, Skybuck. From skybuck2000 at hotmail.com Sun Sep 13 08:11:05 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Sun, 13 Sep 2015 14:11:05 +0200 Subject: Python handles globals badly. In-Reply-To: <55f566c8$0$1644$c3e8da3$5496439d@news.astraweb.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> <8d648$55f56643$d47876e2$38352@news.ziggo.nl> <55f566c8$0$1644$c3e8da3$5496439d@news.astraweb.com> Message-ID: <60a52$55f567d6$d47876e2$43011@news.ziggo.nl> "Steven D'Aprano" wrote in message news:55f566c8$0$1644$c3e8da3$5496439d at news.astraweb.com... On Sun, 13 Sep 2015 10:04 pm, Skybuck Flying wrote: > " > Namespaces don't "become writeable". > > The purpose of "global" is to tell the compiler that this name should > be bound in the global namespace, not the local namespace. > " > > How does it become writeable then ? " It's always writeable. " Thus my logic is correct. By making something global, it ends up in the global namespace, and it becomes writeable. I don't even understand how python interpreter works but I can understand it better than you guys do apperently hahaha. Bye, Skybuck. From ned at nedbatchelder.com Sun Sep 13 08:17:28 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 13 Sep 2015 05:17:28 -0700 (PDT) Subject: Python handles globals badly. In-Reply-To: <60a52$55f567d6$d47876e2$43011@news.ziggo.nl> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> <8d648$55f56643$d47876e2$38352@news.ziggo.nl> <55f566c8$0$1644$c3e8da3$5496439d@news.astraweb.com> <60a52$55f567d6$d47876e2$43011@news.ziggo.nl> Message-ID: <180fe671-7bf9-4544-a3ad-d98a4a497d06@googlegroups.com> On Sunday, September 13, 2015 at 8:11:13 AM UTC-4, Skybuck Flying wrote: > I don't even understand how python interpreter works but I can understand it > better than you guys do apperently hahaha. As tempting as it is to respond to Skybuck, with a brief pause to consider, and a deep breath, I'm sure we can all agree that there is no point in it. Skybuck: go in peace, and thanks for being part of the Python community. --Ned. From lac at openend.se Sun Sep 13 08:24:33 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 13 Sep 2015 14:24:33 +0200 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> Message-ID: <201509131224.t8DCOXHO004891@fido.openend.se> In a message of Sat, 12 Sep 2015 22:15:02 -0400, Alexander Belopolsky writes: >I completely agree. That's why I am adding test cases like Lord Hope >Island and Vilnius to datetimetester. > >I will try to create a zoneinfo wrapping prototype as well, but I will >probably "cheat" and build it on top of pytz. My question, is whether it will handle Creighton, Saskatchewan, Canada? Creighton is an odd little place. Like all of Saskatchewan, it is in the Central time zone, even though you would expect it to be in the Mountain time zone based on its location on the globe. The people of Saskatchewan have decided not to adopt Daylight Savings time. Except for the people of Creighton (and nearby Denare Beach) -- who _do_ observe Daylight savings time. makes for an interesting corner case, one that I remember for personal (and not economic, or professional) reasons. Laura From steve at pearwood.info Sun Sep 13 08:50:43 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 13 Sep 2015 22:50:43 +1000 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f57122$0$1654$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Sep 2015 04:45 am, rurpy at yahoo.com wrote: > On 09/12/2015 10:32 AM, Steven D'Aprano wrote: >> On Sat, 12 Sep 2015 02:42 pm, Random832 wrote: >>[...] >> Computer science and IT is *dominated* by a single usage for "pointer" -- >> it's an abstract memory address. The fundamental characteristics of >> pointers are: > > Just upthread, you claimed something was "universally agreed" I did? "Universially agreed" doesn't sound like something I would say. Do you have a link to where I said that? I think you're confusing me with somebody else. Somebody who is not me. [...] >> Python, Java, Ruby, Lua, Javascript etc. have *no such concept* as >> pointer. There are no values in these languages which correspond to the >> standard definition of pointer: > > They have not such concept because the developers and documentors choose > not to describe that language that way. That does not mean one could not > come up with a perfectly valid description that did include the concept > of pointers. I have little problem with you using "pointer" as a metaphor: "Python variables are like pointers in these ways...". I do have a problem with you insisting that they are pointers. You can, if you choose, decide to change the meaning of the word "pointer". After all, as a general English term, it just means a type of dog. No, wait, that's the wrong meaning. It means anything which points in some fashion, like a dog. But as I said to Rurpy, if you're going to insist on using your own meanings for words, the onus is on you to ensure that people aren't going to misunderstand you. Sure, you could insist that `x = math.sin(1)` makes x a string, and justify that piece of obnoxious linguistic trickery by saying that x is a string of bits, but I think that we'd be justified in objecting to that misuse of terminology. Sure, you can insist that `x = math.sin(1)` makes x a pointer, but that too is a misuse of terminology. You can continue to call Python variables "pointers". After all, language is a construct, and words have no meaning but that we give them, and there is no law that says you are forbidden from using your own private meaning of words. And when you do, I shall continue to object vehemently to your wilful malapropism. [...] > It may not be appropriate way to describe Python for everybody but > it is perfectly reasonable (and even preferable) for people with > an understanding of "pointers" from some other language. And for > those people who don't then one could argue they are a clean slate > and using the word "pointer" won't hurt. No, it is not reasonable. You want to insist that `x = 23` in Python code makes x a pointer. But that Python snippet is analogous to to the following C and Pascal snippets: # C int x = 23; {Pascal} var x: integer; begin x := 23; end; Do you insist that they are pointers to? Then everything is a pointer, and the word has no meaning. Regardless of which of the three languages we are talking about, the assignment `x = 23` does not mean "bind some value to x which, when dereferenced, gives the value 23". The value bound to x is 23, not some indirect pointer to 23. The *implementation* of how names and variables are bound may (or may not) involve pointers, but that is outside of the language abstraction, whether we are talking about Python, C or Pascal. To call x a pointer to 23 breaks the language abstraction and confuses the (optional) implementation for the language interface: * CPython's implementation of namespaces may include a hash table, where the table's values are pointers to objects in the heap; * C's and Pascal's implementation of variables may include a compile-time table of variable names mapped to memory addresses; All three implementations may include a "thing-which-points" (Python name bindings may involve C pointers to objects implemented as C structs; Pascal and C variables may involve a compile-time table that points to the memory address of the variable being accessed), but NONE of them justifies calling x a pointer in ANY of those languages. If it helps you understand Python's programming model to discuss the implementation, by all means do so. But be clear that you are talking about *implementation* and not Python code. -- Steven From steve at pearwood.info Sun Sep 13 09:29:17 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 13 Sep 2015 23:29:17 +1000 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <55f57122$0$1654$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f57a2d$0$1666$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Sep 2015 10:50 pm, Steven D'Aprano wrote: > On Sun, 13 Sep 2015 04:45 am, rurpy at yahoo.com wrote: ............................... ^^^^^ > But as I said to Rurpy, Er, that would be you. Editing fail. Sorry about that. -- Steven From larry at hastings.org Sun Sep 13 10:28:34 2015 From: larry at hastings.org (Larry Hastings) Date: Sun, 13 Sep 2015 15:28:34 +0100 Subject: [RELEASED] Python 3.5.0 is now available Message-ID: <55F58812.1030001@hastings.org> On behalf of the Python development community and the Python 3.5 release team, I'm proud to announce the availability of Python 3.5.0. Python 3.5.0 is the newest version of the Python language, and it contains many exciting new features and optimizations. You can read all about what's new in Python 3.5.0 here: https://docs.python.org/3.5/whatsnew/3.5.html And you can download Python 3.5.0 here: https://www.python.org/downloads/release/python-350/ Windows and Mac users: please read the important platform-specific "Notes on this release" section near the end of that page. We hope you enjoy Python 3.5.0! //arry/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From ltoshea at gmail.com Sun Sep 13 10:39:23 2015 From: ltoshea at gmail.com (Azureaus) Date: Sun, 13 Sep 2015 07:39:23 -0700 (PDT) Subject: Phone Tree Message-ID: <6ae5c632-b061-4b86-87ae-24c50435445b@googlegroups.com> Hi, I'm helping out some teenagers (14yo ish) who have just started programming and are working on a 'call tree' program as part of some after school coding classes and I wanted to talk about potential solutions. The first task is to implement a 'troubleshooting program' similar to what a phone operator would have when you phone up with a problem. We all know the type when you phone up your ISP, 'have you turned it off and on again?', "have you changed your telephone filter' etc.. It states there should be at least 10 questions and that the user should reach a solution, e.g. 'replace your power cable'. There and my initial reaction was that this could be achieved by lots of if/else statements with each question running onto another one, ugly but it would certainly work. One of them pointed out how inefficient this was and asked if there was another way, they hated writing out tons of if/elif/else statements. Does anyone have any ideas for a more elegant solution? My thoughts are that I could use a tree data structure and hence make traversing the tree recursive based on yes or no answers. I'm happy to put the time in to explain these more complex ideas, I'm just hoping those with more expertise than myself could either help verify the idea or suggest alternatives. Thanks in advance! From sagark9299 at gmail.com Sun Sep 13 10:49:37 2015 From: sagark9299 at gmail.com (sagar k) Date: Sun, 13 Sep 2015 07:49:37 -0700 (PDT) Subject: Integration using scipy odeint Message-ID: Dear all I'm using Python 3.4.3. I am facing a problem in integrating using odeint solver. In the following code, tran is a function and in those are the variables which are arrays. These variables change their values with respect to time (the time which I pass to the function). I tried defining a loop inside the function, but Python throws an error saying float object not iterable. Please guide me how to solve this problem. #initial is an array containing initial values for the integration, dt is the time array with unequal time steps, which I have captured from other part of the code def tran(initial,dt): for i in dt: k1 [i] = 2.8e8 * math.exp(-21100/ta[i]) # k1,k2,k3 & k4 are constants which change according to temperature (ta), which in turn changes with respect to time. k2 [i] = 1.4e2 * math.exp(-12100/ta[i]) # ta changes its values according to dt, which is array. It runs from 0-6 with unequal time steps. k3 [i] = 1.4e5 * ta[i] * math.exp(-19680/ta[i]) # I've captured dt and all other arrays here from another loop, which is not of importtance. k4 [i] = 1.484e3 * ta[i] y = initial[0] z = initial[1] dn = (6*rho*initial[1]) dd = (math.pi*2000*initial[0]) ds = (dn/dd)**1/3 dydt = (166.2072*ta[i]*cca[i] - (1.447e13 * ta[i]**0.5 * rho**1/6 * y**1/6 * rho**1/6 * z**1/6 * 0.0832)) # cca,ta are arrays. y & z are 2 dependent variables dzdt = (k1[i]*ta[i]*cca[i]*12.011 + (21.2834*k2[i]*ta[i]*cca[i] * y**1/2 *ds) - (k3[i]*ta[i]*12.011*y*math.pi*ds**2 * cco[i]) - (phi*k4[i]*ta[i]*xo[i]*12.011*y*math.pi*ds**2)) return [dydt,dzdt] # dydt & dzdt are my final time integrated values initial = [0.01,1e-5] sol = odeint(tran, initial, dt) #this is my function call If I pass array in my function call, it says only length-1 can be converted to Python scalars. So I request all the experts in the group to tell me where I'm going wrong. Regards From rosuav at gmail.com Sun Sep 13 10:59:55 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Sep 2015 00:59:55 +1000 Subject: Phone Tree In-Reply-To: <6ae5c632-b061-4b86-87ae-24c50435445b@googlegroups.com> References: <6ae5c632-b061-4b86-87ae-24c50435445b@googlegroups.com> Message-ID: On Mon, Sep 14, 2015 at 12:39 AM, Azureaus wrote: > The first task is to implement a 'troubleshooting program' similar to what a phone operator would have when you phone up with a problem. We all know the type when you phone up your ISP, 'have you turned it off and on again?', "have you changed your telephone filter' etc.. > > It states there should be at least 10 questions and that the user should reach a solution, e.g. 'replace your power cable'. There and my initial reaction was that this could be achieved by lots of if/else statements with each question running onto another one, ugly but it would certainly work. One of them pointed out how inefficient this was and asked if there was another way, they hated writing out tons of if/elif/else statements. > > Does anyone have any ideas for a more elegant solution? My thoughts are that I could use a tree data structure and hence make traversing the tree recursive based on yes or no answers. I'm happy to put the time in to explain these more complex ideas, I'm just hoping those with more expertise than myself could either help verify the idea or suggest alternatives. > This sounds broadly similar to a Twenty Questions game. You may be able to find some neat implementations of that, which could be reworked into what you want. A more cynical algorithm could be implemented as follows: import random questions = [ # The IT Crowd "Hello, IT, have you tried turning it off and on again?", # The Bastard Operator From Hell "How long has this been happening?", "Has anyone else had this problem?", "Is it your floor that has the Gas Leak?", # Standard ISP questions "Have you tried disabling your antivirus?", "Are we talking to the authorized account holder?", # Add additional questions as required ] random.shuffle(questions) questions = questions[::2] # Ask about half of them for q in questions: response = input(q) # raw_input in Py2 # Utterly ignore the response print("I'm sorry, nobody else has reported this problem, so it cannot be a real problem.") I may or may not be basing this on real life experience. For something a bit more useful, though, what you might have is a nested pile of tuples. For instance: questions = ( # First the question "Have you rebooted your computer?", # Then the if-no response "Please reboot your computer, then call back.", # Finally the if-yes response ("Are you running Windows?", ("Are you using a Macintosh?", "I'm sorry, we only support Windows and Mac OS.", "Let me transfer you to our Macintosh support people.", ), ("Have you disabled your antivirus?", "Please disable your AV and try again.", ("Is it your floor that has the gas leak?", "I'm sorry, I can't help you.", "Strike a match. All your problems will disappear.", ), ), ), ) while isinstance(questions, tuple): q, no, yes = questions response = input(q) if response == "yes": questions = yes elif response == "no": questions = no else: print("I'm sorry, I didn't understand that response.") print(questions) # is now the solution This is a data-driven algorithm. The code is extremely short, and is fundamentally about the UI; you could change it completely (a GUI app, text-to-speech and DTMF for IVR, etc, etc) without changing the question structure at all. Is this the kind of tree structure you had in mind? ChrisA From tim.peters at gmail.com Sun Sep 13 11:27:30 2015 From: tim.peters at gmail.com (Tim Peters) Date: Sun, 13 Sep 2015 10:27:30 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <201509131224.t8DCOXHO004891@fido.openend.se> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> Message-ID: [Alex] >>I will try to create a zoneinfo wrapping prototype as well, but I will >>probably "cheat" and build it on top of pytz. [Laura Creighton] > My question, is whether it will handle Creighton, Saskatchewan, Canada? > Creighton is an odd little place. Like all of Saskatchewan, it is > in the Central time zone, even though you would expect it to be > in the Mountain time zone based on its location on the globe. > The people of Saskatchewan have decided not to adopt Daylight > Savings time. Except for the people of Creighton (and > nearby Denare Beach) -- who _do_ observe Daylight savings time. > > makes for an interesting corner case, one that I remember for > personal (and not economic, or professional) reasons. Hi, Laura! By "zoneinfo" here, we mean the IANA (aka "Olson") time zone database, which is ubiquitous on (at least) Linux: https://www.iana.org/time-zones So "will a wrapping of zoneinfo handle XYZ?" isn't so much a question about the wrapping as about what's in the IANA database. Best guess is that Creighton's rules are covered by that database's America/Winnipeg entries. It's generally true that the database makes no attempt to name every location on the planet. Instead it uses names of the form "general/specific" where "general" limits the scope to some large area of the Earth (here "America" really means "North America"), and "specific" names a well-known city within that area. For example, I live in Ashland, Wisconsin (extreme far north in that state, on Lake Superior), but so far as IANA is concerned my time zone rules are called "America/Chicago" (some 460 air miles SSE, in a different state). Just for fun, I'll paste in the comments from the Saskatchewan section of IANA's "northamerica" data file (a plain text source file from which binary tzfiles like America/Chicago and America/Winnipeg are generated). You'll see Creighton mentioned if you stay alert ;-) # Saskatchewan # From Mark Brader (2003-07-26): # The first actual adoption of DST in Canada was at the municipal # level. As the [Toronto] Star put it (1912-06-07), "While people # elsewhere have long been talking of legislation to save daylight, # the city of Moose Jaw [Saskatchewan] has acted on its own hook." # DST in Moose Jaw began on Saturday, 1912-06-01 (no time mentioned: # presumably late evening, as below), and would run until "the end of # the summer". The discrepancy between municipal time and railroad # time was noted. # From Paul Eggert (2003-07-27): # Willett (1914-03) notes that DST "has been in operation ... in the # City of Moose Jaw, Saskatchewan, for one year." # From Paul Eggert (2006-03-22): # Shanks & Pottenger say that since 1970 this region has mostly been as Regina. # Some western towns (e.g. Swift Current) switched from MST/MDT to CST in 1972. # Other western towns (e.g. Lloydminster) are like Edmonton. # Matthews and Vincent (1998) write that Denare Beach and Creighton # are like Winnipeg, in violation of Saskatchewan law. # From W. Jones (1992-11-06): # The. . .below is based on information I got from our law library, the # provincial archives, and the provincial Community Services department. # A precise history would require digging through newspaper archives, and # since you didn't say what you wanted, I didn't bother. # # Saskatchewan is split by a time zone meridian (105W) and over the years # the boundary became pretty ragged as communities near it reevaluated # their affiliations in one direction or the other. In 1965 a provincial # referendum favoured legislating common time practices. # # On 15 April 1966 the Time Act (c. T-14, Revised Statutes of # Saskatchewan 1978) was proclaimed, and established that the eastern # part of Saskatchewan would use CST year round, that districts in # northwest Saskatchewan would by default follow CST but could opt to # follow Mountain Time rules (thus 1 hour difference in the winter and # zero in the summer), and that districts in southwest Saskatchewan would # by default follow MT but could opt to follow CST. # # It took a few years for the dust to settle (I know one story of a town # on one time zone having its school in another, such that a mom had to # serve her family lunch in two shifts), but presently it seems that only # a few towns on the border with Alberta (e.g. Lloydminster) follow MT # rules any more; all other districts appear to have used CST year round # since sometime in the 1960s. # From Chris Walton (2006-06-26): # The Saskatchewan time act which was last updated in 1996 is about 30 pages # long and rather painful to read. # http://www.qp.gov.sk.ca/documents/English/Statutes/Statutes/T14.pdf From rurpy at yahoo.com Sun Sep 13 11:31:51 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 13 Sep 2015 08:31:51 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> <55F4E0E0.6020009@gmail.com> Message-ID: <557c7158-6a8f-42e3-8cec-411f29363436@googlegroups.com> On 09/12/2015 08:42 PM, Ben Finney wrote: > Michael Torrie writes: >> On 09/12/2015 08:22 PM, Mark Lawrence wrote: >>> You appear to have the same level of knowledge of Python internals as >>> the RUE has of the Python 3.3+ FSR unicode implementation. Let's have >>> some fun, is Python pass by value or pass by reference? It has to be >>> more interesting debating that than the drivel that's gone before in >>> this thread. >> >> Oh you are a devious one there! This should get good. > > No, it should stop there. Taunting trolls is no more welcome here than > trolling. Ben, If the troll being taunted here is referring to me, I suggest you review my posts in this thread, You've said in the past that you don't read posts from Google Groups (that's fine, your choice) so perhaps you do not have a clear idea what I have written. One of the most effective ways for a community to discredit itself is to make accusations of trolling in response to unpopular but legitimate and reasonable opinion. From rosuav at gmail.com Sun Sep 13 11:39:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Sep 2015 01:39:43 +1000 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <557c7158-6a8f-42e3-8cec-411f29363436@googlegroups.com> References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> <55F4E0E0.6020009@gmail.com> <557c7158-6a8f-42e3-8cec-411f29363436@googlegroups.com> Message-ID: On Mon, Sep 14, 2015 at 1:31 AM, rurpy--- via Python-list wrote: > Ben, > > If the troll being taunted here is referring to me, I suggest > you review my posts in this thread, You've said in the past > that you don't read posts from Google Groups (that's fine, > your choice) so perhaps you do not have a clear idea what I > have written. I think Ben's referring to taunting jmf, whom Mark called the "RUE" or "Resident Unicode Expert". There has been a long-standing antagonism between those two (which is completely understandable), and one which often spills over into vitriolic posts (which is less acceptable). ChrisA From lac at openend.se Sun Sep 13 12:00:07 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 13 Sep 2015 18:00:07 +0200 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> Message-ID: <201509131600.t8DG07e0025688@fido.openend.se> In a message of Sun, 13 Sep 2015 10:27:30 -0500, Tim Peters writes: >Hi, Laura! By "zoneinfo" here, we mean the IANA (aka "Olson") time >zone database, which is ubiquitous on (at least) Linux: > > https://www.iana.org/time-zones > >So "will a wrapping of zoneinfo handle XYZ?" isn't so much a question >about the wrapping as about what's in the IANA database. Then we had better be able to override it when it is wrong. >Best guess is that Creighton's rules are covered by that database's >America/Winnipeg entries. ># Saskatchewan ># Other western towns (e.g. Lloydminster) are like Edmonton. ># Matthews and Vincent (1998) write that Denare Beach and Creighton ># are like Winnipeg, in violation of Saskatchewan law. I think that this will work. Creighton is just across the border from Flin Flan, Manitoba. Indeed I think the problem of 'drunken people from Manitoba trying to get one hours more drinking done and being a menace on the highway' may have fueled the 'we are going to have DST in violation of the law' movement in Creighton. But I am not sure how it is that a poor soul who just wants to print a railway schedule 'in local time' is supposed to know that Creighton is using Winnipeg time. Laura From gtglus at gmail.com Sun Sep 13 13:15:19 2015 From: gtglus at gmail.com (Glus Xof) Date: Sun, 13 Sep 2015 19:15:19 +0200 Subject: How to set the history commands visible ? Message-ID: Hi guys, Today, a new python stable version was released (thanks for your job)... and I write to ask you for the recommended method to compile the sources (in Debian GNU/Linux platfom) in order to the arrow keys emit the history commands instead of... it seems that escape sequences... Python 3.5.0 (default, Sep 13 2015, 17:58:38) [GCC 4.9.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ^[[A^[[A^[[B^[[B (I run the configure, make, make test & make install scripts) Furthermore, I'd like also to ask a simple additional questions: Is yet an automatic indentation system implemented ? How to activate them ? Glus -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Sun Sep 13 14:03:11 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 13 Sep 2015 20:03:11 +0200 Subject: Phone Tree In-Reply-To: <6ae5c632-b061-4b86-87ae-24c50435445b@googlegroups.com> References: <6ae5c632-b061-4b86-87ae-24c50435445b@googlegroups.com> Message-ID: <201509131803.t8DI3BsG023829@fido.openend.se> Somewhere in there you may find that dictionary dispatching is something worth doing. I don't know. This whole sort of problem is sort of grating, in that it is trying to replicate one of the most irritating user experiences on the planet ... From python3: Patterns, Recipes and Idioms http://www.google.se/url?sa=t&rct=j&q=&esrc=s&source=web&cd=5&ved=0CEUQFjAEahUKEwiJv4CtxPTHAhVqvnIKHY68Bec&url=http%3A%2F%2Fpython-3-patterns-idioms-test.readthedocs.org%2Fen%2Flatest%2FMultipleDispatching.html&usg=AFQjCNG0UFOKpxJNVDSCt9dtAJ55SC_zEA The guts of the thing is a simple dictionary: outcome = { (Paper, Rock): Outcome.WIN, (Paper, Scissors): Outcome.LOSE, (Paper, Paper): Outcome.DRAW, (Scissors, Paper): Outcome.WIN, (Scissors, Rock): Outcome.LOSE, (Scissors, Scissors): Outcome.DRAW, (Rock, Scissors): Outcome.WIN, (Rock, Paper): Outcome.LOSE, (Rock, Rock): Outcome.DRAW, } Which, in this case, plays the child's game rock, paper, scissors with 2 players. But you could use a tuple with 10 values. If a lot of your outcomes are going to arrive at the same answer 'Stick the device in a box, print off this shipping label, and send it via UPS to our repair service centre.' then this approach will have more appeal. Sometimes what you want is to dispatch on a set of functions with arguments, and you can stick that in your dictionary as well. outcomes = { (a,c,d) : (function1_name, (arg1, arg2, arg3)) (a, b, d) : (function2_name, (arg1,))} But whether this is going to help or not really depends on your data. If you find yourself itching for a case statement, then it probably will. But I am not sure that this was your intent in the first place. Laura From 4kir4.1i at gmail.com Sun Sep 13 14:04:20 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Sun, 13 Sep 2015 21:04:20 +0300 Subject: Terminology: "reference" versus "pointer" References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> Message-ID: <87wpvu5h7f.fsf@gmail.com> Random832 writes: > Akira Li <4kir4.1i at gmail.com> writes: >>Rustom Mody writes: >>> viz. I have two variables (or names!) say a and b which look the same >>>>>> a >>> [[1,2],[1,2]] >>>>>> b >>> [[1,2],[1,2]] >>> And yet doing >>>>>> a[0][0] = "Oops!" >>> gives a data structure one "Oops!" >>> whereas doing it to b mysteriously gives 2 >> >> Sorry, I haven't followed the whole thread. Could your provide a >> complete code example? Mention what you expect to happen and what >> happens instead in your case. > > a0 = a1 = [1, 2] > b0 = [1, 2] > b1 = [1, 2] > a = [a0, a1] > b = [b0, b1] > del a0, a1, b0, b1 > > There's nothing about *him* expecting anything wrong to happen. The > question is how to draw a diagram that unambiguously shows the resulting > structure using the "parcel tags" model shown in the diagrams (and > without having a0/a1/etc as actual names) I'm not sure what "parcel tags" model is but if you mean these pictures[1] than it works in this case as well as any other (take *a*, *b* nametags, put them on the corresponding balloons that represents list objects). The only names left are *a* and *b* that refer to the corresponding lists. There is no ambiguity there to put *a*, *b* nametags. Lists as any other containers contain references to other objects and therefore "box and arrows" model provides _more details_ here[2,3] > If the "parcel tags" model can't show it, then the "parcel tag" model > clearly is not a correct and complete depiction of how Python actually > works. > (If I were drawing a picture rather than ASCII I'd add something to make > it clear that the pairs shown are list objects Like, it's a circle with > the word "list" and two pointer-boxes inside it.) "correct and complete" is impossible in the general case for any model. Imagine what happens if numpy arrays are used instead of Python lists: lst = [numpy.array([1, 2]) for _ in range(3)] a = [lst[0], lst[0]] b = [lst[1], lst[2]] Note: there could be no a[0][0], a[0][1], etc corresponding Python objects until you explicitly reference them in the code. If there are no Python objects then you can't draw any arrows and therefore "box and arrows" model is incomplete. Or consider this collections of all Unicode characters: class U: def __len__(self): return sys.maxunicode + 1 def __getitem__(self, index): if index < 0: index += len(self) if 0 <= index < len(self): return chr(index) raise IndexError(index) u = U() print(u[0x61]) # -> a In this example, it is even more clear that the corresponding items might not exist until they are explicitly referenced in a program. *u* is a sequence as any other in Python (it is easy to make it *collections.abc.Sequence* compatible). Or this: lst = [range(1, 3) for _ in range(3)] a = [lst[0], lst[0]] b = [lst[1], lst[2]] In Python 2, it is the exact replica of the original example. In Python 3, it is the same if you don't need to mutate the ranges. Again, the leaf objects might not exist until you reference them in the code in Python 3. Finally, consider a Python sequence that uses os.urandom() internally. No model will predict the result (and therefore no model is complete) in this case. [1] http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#python-has-names [2] http://www.pythontutor.com/visualize.html#code=a0+%3D+a1+%3D+%5B1,+2%5D%0Ab0+%3D+%5B1,+2%5D%0Ab1+%3D+%5B1,+2%5D%0Aa+%3D+%5Ba0,+a1%5D%0Ab+%3D+%5Bb0,+b1%5D%0Adel+a0,+a1,+b0,+b1%0A&mode=display&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&textReferences=false&py=3&rawInputLstJSON=%5B%5D&curInstr=6 [3] http://www.pythontutor.com/visualize.html#code=a0+%3D+a1+%3D+%5B1,+2%5D%0Ab0+%3D+%5B1,+2%5D%0Ab1+%3D+%5B1,+2%5D%0Aa+%3D+%5Ba0,+a1%5D%0Ab+%3D+%5Bb0,+b1%5D%0Adel+a0,+a1,+b0,+b1%0Aa%5B0%5D%5B0%5D+%3D+%22Oops!%22&mode=display&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&textReferences=false&py=3&rawInputLstJSON=%5B%5D&curInstr=7 From random832 at fastmail.com Sun Sep 13 14:15:58 2015 From: random832 at fastmail.com (Random832) Date: Sun, 13 Sep 2015 14:15:58 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> Message-ID: Laura Creighton writes: > But I am not sure how it is that a poor soul who just wants to print a > railway schedule 'in local time' is supposed to know that Creighton is > using Winnipeg time. The same way they know that any other location is using whatever time it uses. By the user having specified it (if the user's local time is wrong they'll "obviously" know it as soon as the daylight saving transition is supposed to happen but doesn't) or by checking the location against the data at http://efele.net/maps/tz/canada/ From lac at openend.se Sun Sep 13 14:24:03 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 13 Sep 2015 20:24:03 +0200 Subject: Integration using scipy odeint In-Reply-To: References: Message-ID: <201509131824.t8DIO3lK028765@fido.openend.se> In a message of Sun, 13 Sep 2015 07:49:37 -0700, sagar k writes: >Dear all > >I'm using Python 3.4.3. I am facing a problem in integrating using odeint solver. In the following code, tran is a function and in those are the variables which are arrays. These variables change their values with respect to time (the time which I pass to the function). I tried defining a loop inside the function, but Python throws an error saying float object not iterable. Please guide me how to solve this problem. > >#initial is an array containing initial values for the integration, dt is the time array with unequal time steps, which I have captured from other part of the code > >def tran(initial,dt): > for i in dt: > k1 [i] = 2.8e8 * math.exp(-21100/ta[i]) # k1,k2,k3 & k4 are constants which change according to temperature (ta), which in turn changes with respect to time. > k2 [i] = 1.4e2 * math.exp(-12100/ta[i]) # ta changes its values according to dt, which is array. It runs from 0-6 with unequal time steps. > k3 [i] = 1.4e5 * ta[i] * math.exp(-19680/ta[i]) # I've captured dt and all other arrays here from another loop, which is not of importtance. > k4 [i] = 1.484e3 * ta[i] > y = initial[0] > z = initial[1] > dn = (6*rho*initial[1]) > dd = (math.pi*2000*initial[0]) > ds = (dn/dd)**1/3 > dydt = (166.2072*ta[i]*cca[i] - (1.447e13 * ta[i]**0.5 * rho**1/6 * y**1/6 * rho**1/6 * z**1/6 * 0.0832)) # cca,ta are arrays. y & z are 2 dependent variables > dzdt = (k1[i]*ta[i]*cca[i]*12.011 + (21.2834*k2[i]*ta[i]*cca[i] * y**1/2 *ds) - (k3[i]*ta[i]*12.011*y*math.pi*ds**2 * cco[i]) - > (phi*k4[i]*ta[i]*xo[i]*12.011*y*math.pi*ds**2)) >return [dydt,dzdt] # dydt & dzdt are my final time integrated values > >initial = [0.01,1e-5] >sol = odeint(tran, initial, dt) #this is my function call > >If I pass array in my function call, it says only length-1 can be converted to Python scalars. > >So I request all the experts in the group to tell me where I'm going wrong. > >Regards You are getting this error, correct? TypeError: only length-1 arrays can be converted to Python scalars I don't know anything about odeint. But when I get these errors it is because I passed a numpy array into something that wanted a python list. This may be what you are doing. numpy arrays have a tolist method. see if passing array.tolist() instead of array works for you. Laura From tim.peters at gmail.com Sun Sep 13 15:00:33 2015 From: tim.peters at gmail.com (Tim Peters) Date: Sun, 13 Sep 2015 14:00:33 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <201509131600.t8DG07e0025688@fido.openend.se> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> Message-ID: [Tim] >> Hi, Laura! By "zoneinfo" here, we mean the IANA (aka "Olson") time >> zone database, which is ubiquitous on (at least) Linux: >> >> https://www.iana.org/time-zones >> >>So "will a wrapping of zoneinfo handle XYZ?" isn't so much a question >>about the wrapping as about what's in the IANA database. [Laura] > Then we had better be able to override it when it is wrong. Anyone can write their own tzinfo implementing any rules they like, and nobody is required to use anyone else's tzinfos. That said, zoneinfo is the most extensive collection of time zone info there is, so most people will probably use only that. And that said, zoneinfo is inordinately concerned with recording highly dubious guesses about what "the rules" were even over a century ago. Most people would probably be happy with a tzinfo that _only_ knew what "today's rules" are. POSIX TZ rules give a simple way to spell exactly that. Simple, but annoyingly cryptic. Gustavo's `dateutil` already supplies a way to magically build a tzinfo implementing a zone specified by a POSIX TZ rule string. More obvious ways to spell that are surely possible (like, for example, the obvious ways). Patches welcome ;-) >> Best guess is that Creighton's rules are covered by that database's >> America/Winnipeg entries. >> >> # Saskatchewan >> # Other western towns (e.g. Lloydminster) are like Edmonton. >> # Matthews and Vincent (1998) write that Denare Beach and Creighton >> # are like Winnipeg, in violation of Saskatchewan law. > I think that this will work. > Creighton is just across the border from Flin Flan, Manitoba. Indeed I think > the problem of 'drunken people from Manitoba trying to get one hours more > drinking done and being a menace on the highway' may have fueled the > 'we are going to have DST in violation of the law' movement in Creighton. :-) > But I am not sure how it is that a poor soul who just wants to print a > railway schedule 'in local time' is supposed to know that Creighton is > using Winnipeg time. I'm not sure how that poor soul would get a railway schedule manipulable in Python to begin with ;-) If it's "a problem" for "enough" users of a computer system, a Linux admin could simply make "America/Creighton" a link to the "America/Winnipeg" tzfile. But doing that for every nameable place on Earth might be considered annoying. To cover everyone, you may even need to specify a street address within "a city": http://www.quora.com/Are-there-any-major-cities-divided-by-two-time-zones Blame politicians for this. I can assure you Guido is not responsible for creating this mess ;-) From rosuav at gmail.com Sun Sep 13 15:03:59 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Sep 2015 05:03:59 +1000 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <87wpvu5h7f.fsf@gmail.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> Message-ID: On Mon, Sep 14, 2015 at 4:04 AM, Akira Li <4kir4.1i at gmail.com> wrote: >> (If I were drawing a picture rather than ASCII I'd add something to make >> it clear that the pairs shown are list objects Like, it's a circle with >> the word "list" and two pointer-boxes inside it.) > > "correct and complete" is impossible in the general case for any model. > > Imagine what happens if numpy arrays are used instead of Python lists: > > lst = [numpy.array([1, 2]) for _ in range(3)] > a = [lst[0], lst[0]] > b = [lst[1], lst[2]] > > Note: there could be no a[0][0], a[0][1], etc corresponding Python > objects until you explicitly reference them in the code. If there are no > Python objects then you can't draw any arrows and therefore "box and > arrows" model is incomplete. > > Or consider this collections of all Unicode characters: > > class U: > def __len__(self): > return sys.maxunicode + 1 > def __getitem__(self, index): > if index < 0: > index += len(self) > if 0 <= index < len(self): > return chr(index) > raise IndexError(index) > > u = U() > print(u[0x61]) # -> a > > In this example, it is even more clear that the corresponding items > might not exist until they are explicitly referenced in a program. What you've shown there is that it's perfectly possible to have an abstract collection which generates objects as they're needed. In the same way, you could define an infinite range object, which effectively has all positive odd numbers in it: class Odd: def __getitem__(self, index): if index >= 0: return index * 2 + 1 raise IndexError(index) Obviously it can't have objects representing every positive odd number, because that's an infinite set. If you want to think of this as containing all of those integers, sure, but now we're getting into functional programming styles and ways of representing infinity in finite RAM, and some things will look a bit different. However, none of this has anything to do with Python's object model. The expression "index * 2 + 1" results in the creation of new integer objects as required, rather than simply retrieving them from some containment list. The boxes-and-arrows stuff is all about pre-existing objects; if I construct one list from another, I expect all the references to be the same, but if I construct two Odd() objects, they don't have to be: >>> o1 = Odd(); x1 = o1[12345] >>> o2 = Odd(); x2 = o2[12345] >>> x1 is x2 False Even though every Odd() must, by definition, contain the exact same integers, it doesn't contain the same objects - it doesn't contain any objects. ChrisA From random832 at fastmail.com Sun Sep 13 15:04:16 2015 From: random832 at fastmail.com (Random832) Date: Sun, 13 Sep 2015 15:04:16 -0400 Subject: Terminology: "reference" versus "pointer" References: <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> Message-ID: Akira Li <4kir4.1i at gmail.com> writes: > I'm not sure what "parcel tags" model is but if you mean these > pictures[1] than it works in this case as well as any other (take *a*, > *b* nametags, put them on the corresponding balloons that represents > list objects). > > The only names left are *a* and *b* that refer to the corresponding > lists. There is no ambiguity there to put *a*, *b* nametags. But how do you make an a[0][0]/a[1][0] nametag to put on the "1" object? > Lists as any other containers contain references to other objects and > therefore "box and arrows" model provides _more details_ here[2,3] Right, but why not use the *same* model to represent *namespaces*? It seems like the "tags" model only exists to make the incorrect claim that python doesn't have variables (the boxes are variables). >> If the "parcel tags" model can't show it, then the "parcel tag" model >> clearly is not a correct and complete depiction of how Python actually >> works. >> (If I were drawing a picture rather than ASCII I'd add something to make >> it clear that the pairs shown are list objects Like, it's a circle with >> the word "list" and two pointer-boxes inside it.) > > "correct and complete" is impossible in the general case for any > model. Everything you wrote here has the same issue: The "objects" you are talking about do not physically exist, but are simply the result of calling a method on the object. Therefore they do not *belong* on the diagram, and the diagram not showing them does not mean the diagram is not complete. From lac at openend.se Sun Sep 13 15:40:03 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 13 Sep 2015 21:40:03 +0200 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> Message-ID: <201509131940.t8DJe36w015280@fido.openend.se> In a message of Sun, 13 Sep 2015 14:00:33 -0500, Tim Peters writes: >> But I am not sure how it is that a poor soul who just wants to print a >> railway schedule 'in local time' is supposed to know that Creighton is >> using Winnipeg time. > >I'm not sure how that poor soul would get a railway schedule >manipulable in Python to begin with ;-) Via Rail will give you a schedule when you book your tickets. But I am wrong, it gives it to you in local time, which you can scrape or even use the via rail api. So it is the person getting off in Creighton who wants to tell his relatives back in Halifax what time he is arriving (in their time) (so they can call him and avoid the hellish hotel surtax on long distance calls) who will have the problem. And this is the sort of use case I think we will see a lot of. >Blame politicians for this. I can assure you Guido is not responsible >for creating this mess ;-) :) Laura From paul.hermeneutic at gmail.com Sun Sep 13 15:51:46 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Sun, 13 Sep 2015 13:51:46 -0600 Subject: Cannot create a virtualenv Message-ID: Installing Py 3.5 and `pip install virtualenv` worked fine. However, I cannot create a virtualenv. "OSError: Command C:\ve\ve33\Scripts\python.exe -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 1" Any suggestions? From forums_mp at hotmail.com Sun Sep 13 15:55:13 2015 From: forums_mp at hotmail.com (forums_mp at hotmail.com) Date: Sun, 13 Sep 2015 12:55:13 -0700 (PDT) Subject: convert element in a list to float Message-ID: <417abfa4-e7c7-4573-83ed-50b8a5aca2b2@googlegroups.com> For starters, I googled and saw a plethora of writings on how to convert an entire list from string to float. My interest is on select elements in the list. The output from the print statement: print scenarioList is as follows [ '3000000', '"N"', '11400000', '"E"' ] I need to convert the first and third element to float. lat = ( float ) scenarioList [ 0 ] lon = ( float ) scenarioList [ 2 ] fails (invalid syntax). How can I achieve my objective. Thanks in advance From breamoreboy at yahoo.co.uk Sun Sep 13 16:07:38 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 13 Sep 2015 21:07:38 +0100 Subject: convert element in a list to float In-Reply-To: <417abfa4-e7c7-4573-83ed-50b8a5aca2b2@googlegroups.com> References: <417abfa4-e7c7-4573-83ed-50b8a5aca2b2@googlegroups.com> Message-ID: On 13/09/2015 20:55, forums_mp at hotmail.com wrote: > > For starters, I googled and saw a plethora of writings on how to convert an entire list from string to float. My interest is on select elements in the list. The output from the print statement: print scenarioList > > is as follows > > [ '3000000', '"N"', '11400000', '"E"' ] > > I need to convert the first and third element to float. > lat = ( float ) scenarioList [ 0 ] > lon = ( float ) scenarioList [ 2 ] > > fails (invalid syntax). How can I achieve my objective. > > Thanks in advance > Strong hint, you do not cast the strings to floats, you call the builtin float() function to do the conversion. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tim.peters at gmail.com Sun Sep 13 16:13:53 2015 From: tim.peters at gmail.com (Tim Peters) Date: Sun, 13 Sep 2015 15:13:53 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <201509131940.t8DJe36w015280@fido.openend.se> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509131940.t8DJe36w015280@fido.openend.se> Message-ID: [Laura] >>> But I am not sure how it is that a poor soul who just wants to print a >>> railway schedule 'in local time' is supposed to know that Creighton is >>> using Winnipeg time. [Tim] >> I'm not sure how that poor soul would get a railway schedule >> manipulable in Python to begin with ;-) [Laura] > Via Rail will give you a schedule when you book your tickets. But I > am wrong, it gives it to you in local time, which you can scrape or > even use the via rail api. So it is the person getting off in > Creighton who wants to tell his relatives back in Halifax what > time he is arriving (in their time) (so they can call him and > avoid the hellish hotel surtax on long distance calls) who will > have the problem. Whatever time zone the traveler's railroad schedule uses, so long as it sticks to just one the traveler subtracts the departure time from the arrival time to determine how long the trip takes. They add that to the Halifax time at which they depart, and tell their Halifax relatives the result. They don't need to know anything about the destination's time zone to do this, unless a daylight transition occurs between departure and arrival, and the schedule itself remembered to account for it. In which case, pragmatically, they can just add an hour "to be safe" ;-) > And this is the sort of use case I think we will see a lot of. But there's nothing new here: datetime has been around for a dozen years already, and nobody is proposing to add any new basic functionality to tzinfos. PEP 495 is only about adding a flag to allow correct conversion of ambiguous local times (typically at the end of DST, when the local clock repeats a span of times) to UTC. So if this were a popular use case, I expect we would already have heard of it. Note that Python zoneinfo wrappings are already available via, at least, the pytz and dateutil packages. From lac at openend.se Sun Sep 13 16:15:52 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 13 Sep 2015 22:15:52 +0200 Subject: How to set the history commands visible ? In-Reply-To: References: Message-ID: <201509132015.t8DKFqLG024138@fido.openend.se> In a message of Sun, 13 Sep 2015 19:15:19 +0200, Glus Xof writes: >Hi guys, > >Today, a new python stable version was released (thanks for your job)... >and I write to ask you for the recommended method to compile the sources >(in Debian GNU/Linux platfom) in order to the arrow keys emit the history >commands instead of... it seems that escape sequences... > >Python 3.5.0 (default, Sep 13 2015, 17:58:38) >[GCC 4.9.2] on linux >Type "help", "copyright", "credits" or "license" for more information. >>>> ^[[A^[[A^[[B^[[B > >(I run the configure, make, make test & make install scripts) It seems your python is not installed with readline support, if the arrow keys are not working. You don't need to recompile python for this. Instead you need to install this. https://pypi.python.org/pypi/readline But I am surprised that you need this, as my debian linux unstable system has this out of the box, more or less always. I think this is because I have this package installed https://packages.debian.org/stretch/readline-common (there are versions for testing and stable as well). If I were you I would install this first and see if your arrow problems go away. If not, get out pip. >Furthermore, I'd like also to ask a simple additional questions: > >Is yet an automatic indentation system implemented ? >How to activate them ? I am not sure what you mean by this. If you, as I, was unhappy as anything about tab in the interactive console (at the far margin) meaning 'tab complete every builtin on the planet' rather than 'I'd like another level of indent please' -- then, 3.5, you are good to go. :) tabs typed flush to the margin just indent. tabs complete if you type them in the middle of an identifier. If you mean something else, then, well, explain it a little more, ok? >Glus Laura From lac at openend.se Sun Sep 13 16:31:29 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 13 Sep 2015 22:31:29 +0200 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509131940.t8DJe36w015280@! fido.openend.se> Message-ID: <201509132031.t8DKVTwJ028027@fido.openend.se> In a message of Sun, 13 Sep 2015 15:13:53 -0500, Tim Peters writes: >[Laura] >> Via Rail will give you a schedule when you book your tickets. But I >> am wrong, it gives it to you in local time, which you can scrape or >> even use the via rail api. So it is the person getting off in >> Creighton who wants to tell his relatives back in Halifax what >> time he is arriving (in their time) (so they can call him and >> avoid the hellish hotel surtax on long distance calls) who will >> have the problem. > >Whatever time zone the traveler's railroad schedule uses, so long as >it sticks to just one This is what does not happen. Which is why I have written a python app to perform conversions for my parents, in the past. >But there's nothing new here: datetime has been around for a dozen >years already, and nobody is proposing to add any new basic >functionality to tzinfos. PEP 495 is only about adding a flag to >allow correct conversion of ambiguous local times (typically at the >end of DST, when the local clock repeats a span of times) to UTC. So >if this were a popular use case, I expect we would already have heard >of it. Note that Python zoneinfo wrappings are already available via, >at least, the pytz and dateutil packages. I am a happy user of pytz. On the other hand, I think this means that my brain has gone through some sort of non-reversible transformation which makes me accurate, but not exactly sane on the issue. I think I have misunderstood Alexander Belopolsky as saying that datetime had functionality which I don't think it has. Thus I thought we must be planning to add some functionality here. Sorry about this. However, people do need to be aware, if they are not already, that people with 3 times in 3 different tz will want to sort them. Telling them that they must convert them to UTC before they do so is, in my opinion, a very fine idea. Expecting them to work this out by themselves via a assertion that the comparison operator is not transitive, is, I think, asking a lot of them. Laura From ben+python at benfinney.id.au Sun Sep 13 16:48:18 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 14 Sep 2015 06:48:18 +1000 Subject: Terminology: "reference" versus "pointer" References: <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> <55F4E0E0.6020009@gmail.com> <557c7158-6a8f-42e3-8cec-411f29363436@googlegroups.com> Message-ID: <85vbbe59m5.fsf@benfinney.id.au> Chris Angelico writes: > I think Ben's referring to taunting jmf, whom Mark called the "RUE" or > "Resident Unicode Expert". There has been a long-standing antagonism > between those two (which is completely understandable), and one which > often spills over into vitriolic posts (which is less acceptable). Chris has it right. What's especially unacceptable is invoking that person for amusement, irrelevant to the conversation. It's one thing to respond when a person comes into a thread to troll unbidden; it is quite another to taunt them unprompted. -- \ ?I call him Governor Bush because that's the only political | `\ office he's ever held legally.? ?George Carlin, 2008 | _o__) | Ben Finney From lac at openend.se Sun Sep 13 17:02:55 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 13 Sep 2015 23:02:55 +0200 Subject: convert element in a list to float In-Reply-To: <417abfa4-e7c7-4573-83ed-50b8a5aca2b2@googlegroups.com> References: <417abfa4-e7c7-4573-83ed-50b8a5aca2b2@googlegroups.com> Message-ID: <201509132102.t8DL2tRL003625@fido.openend.se> In a message of Sun, 13 Sep 2015 12:55:13 -0700, forums_mp at hotmail.com writes: > > >For starters, I googled and saw a plethora of writings on how to convert an entire list from string to float. My interest is on select elements in the list. The output from the print statement: print scenarioList > >is as follows > >[ '3000000', '"N"', '11400000', '"E"' ] > >I need to convert the first and third element to float. > lat = ( float ) scenarioList [ 0 ] > lon = ( float ) scenarioList [ 2 ] > >fails (invalid syntax). How can I achieve my objective. > >Thanks in advance Does this help? >>> l = [ '3000000', '"N"', '11400000', '"E"' ] >>> [float(l[0]), l[1], float(l[2]), l[3]] [3000000.0, '"N"', 11400000.0, '"E"'] Laura From gtglus at gmail.com Sun Sep 13 17:35:01 2015 From: gtglus at gmail.com (Glus Xof) Date: Sun, 13 Sep 2015 23:35:01 +0200 Subject: How to set the history commands visible ? In-Reply-To: <201509132015.t8DKFqLG024138@fido.openend.se> References: <201509132015.t8DKFqLG024138@fido.openend.se> Message-ID: Laura, 2015-09-13 22:15 GMT+02:00 Laura Creighton : > In a message of Sun, 13 Sep 2015 19:15:19 +0200, Glus Xof writes: > >Hi guys, > > > >Today, a new python stable version was released (thanks for your job)... > >and I write to ask you for the recommended method to compile the sources > >(in Debian GNU/Linux platfom) in order to the arrow keys emit the history > >commands instead of... it seems that escape sequences... > > > >Python 3.5.0 (default, Sep 13 2015, 17:58:38) > >[GCC 4.9.2] on linux > >Type "help", "copyright", "credits" or "license" for more information. > >>>> ^[[A^[[A^[[B^[[B > > > >(I run the configure, make, make test & make install scripts) > > It seems your python is not installed with readline support, if > the arrow keys are not working. > > You don't need to recompile python for this. > Instead you need to install this. > https://pypi.python.org/pypi/readline > > But I am surprised that you need this, as my debian linux unstable > system has this out of the box, more or less always. > > I think this is because I have this package installed > https://packages.debian.org/stretch/readline-common > (there are versions for testing and stable as well). > > If I were you I would install this first and see if your > arrow problems go away. If not, get out pip. > Thanks, that's it !! > > >Furthermore, I'd like also to ask a simple additional questions: > > > >Is yet an automatic indentation system implemented ? > >How to activate them ? > > I am not sure what you mean by this. > If you, as I, was unhappy as anything about tab in the > interactive console (at the far margin) meaning 'tab complete > every builtin on the planet' rather than 'I'd like another level > of indent please' -- then, 3.5, you are good to go. :) tabs typed > flush to the margin just indent. tabs complete if you type them > in the middle of an identifier. > > If you mean something else, then, well, explain it a little more, ok? > If I'm not wrong, in a later interpreter versions, when an enter key was pressed after writing something requiring some indentated statement(s)... like in: >>> for i in range (0,3): the system used to suggest "one tab" placing the cursor automatically after. I don't know why this feature doesn't remain yet... or maybe I don't know how activate this... Glus > >Glus > > Laura > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.peters at gmail.com Sun Sep 13 17:58:09 2015 From: tim.peters at gmail.com (Tim Peters) Date: Sun, 13 Sep 2015 16:58:09 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <201509132031.t8DKVTwJ028027@fido.openend.se> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> Message-ID: [Tim] >> Whatever time zone the traveler's railroad schedule uses, so long as >> it sticks to just one [Laura] > This is what does not happen. Which is why I have written a python > app to perform conversions for my parents, in the past. So how did they get the right time zone rules for Creighton? >>But there's nothing new here: datetime has been around for a dozen >>years already, and nobody is proposing to add any new basic >>functionality to tzinfos. PEP 495 is only about adding a flag to >>allow correct conversion of ambiguous local times (typically at the >>end of DST, when the local clock repeats a span of times) to UTC. So >>if this were a popular use case, I expect we would already have heard >>of it. Note that Python zoneinfo wrappings are already available via, >>at least, the pytz and dateutil packages. > I am a happy user of pytz. On the other hand, I think this means that > my brain has gone through some sort of non-reversible transformation > which makes me accurate, but not exactly sane on the issue. pytz made some strange decisions, from the POV of datetime's intended tzinfo design. But it also solved a problem datetime left hanging: how to disambiguate ambiguous local times. The _intended_ way to model zones with UTC offset transitions was via what the docs call a "hybrid" tzinfo: a single object smart enough on its own to figure out, e.g., whether a datetime's date and time are in "daylight" or "standard" time. However, there's currently no way for such a tzinfo to know whether an ambiguous local time is intended to be the earlier or the later of repeated times. PEP 495 aims to plug that hole. pytz solves it by _never_ creating a hybrid tzinfo. It only uses eternally-fixed-offset tzinfos. For example, for a conceptual zone with two possible total UTC offsets (one for "daylight", one for "standard"), there two distinct eternally-fixed-offset tzinfo objects in pytz. Then an ambiguous time is resolved by _which_ specific tzinfo object is attached. Typically the "daylight" tzinfo for the first time a repeated local time appears, and the "standard" tzinfo for its second appearance. In return, you have to use .localize() and .normalize() at various times, because pytz's tzinfo objects themselves are completely blind to the possibility of the total UTC offset changing. .localize() and .normalize() are needed to possibly _replace_ the tzinfo object in use, depending on the then-current date and time. OTOH, `dateutil` does create hybrid tzinfo objects. No dances are ever needed to possibly replace them. But it's impossible for dateutil's tzinfos to disambiguate times in a fold. Incidentally, dateutil also makes no attempt to account for transitions other than DST (e.g., sometimes a zone may change its _base_ ("standard") offset from UTC). So, yup, if you're thoroughly indoctrinated in pytz behavior, you will be accurate but appear insane to Guido ;-) At a semantic level, a pytz tzinfo doesn't capture the notion of a zone with offset changes - it doesn't even try to. All knowledge about offset changes is inside the .localize() and .normalize() dances. > I think I have misunderstood Alexander Belopolsky as saying that > datetime had functionality which I don't think it has. Thus I thought > we must be planning to add some functionality here. Sorry about this. Guido told Alex to stop saying that ;-) You can already get eternally-fixed-offset classes, like pytz does, on (at least) Linux systems by setting os.environ['TZ'] and then exploiting that .astimezone() without an argument magically synthesizes an eternally-fixed-offset tzinfo for "the system zone" (which the TZ envar specifies) current total UTC offset. That's not really comparable to what pytz does, except at a level that makes a lot of sense in theory but not much at all in practice ;-) > However, people do need to be aware, if they are not already, that > people with 3 times in 3 different tz will want to sort them. Telling > them that they must convert them to UTC before they do so is, in my > opinion, a very fine idea. Expecting them to work this out by themselves > via a assertion that the comparison operator is not transitive, is, > I think, asking a lot of them. Of course. Note that it's _not_ a problem in pytz, though: there are no sorting (or transitivity) problems if the only tzinfos you ever use have eternally fixed UTC offsets. There are no gaps or folds then, and everything works in an utterly obvious way - except that you have to keep _replacing_ tzinfos when they become inappropriate for the current dates and times in the datetimes they're attached to. From guido at python.org Sun Sep 13 18:21:45 2015 From: guido at python.org (Guido van Rossum) Date: Sun, 13 Sep 2015 15:21:45 -0700 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <201509131224.t8DCOXHO004891@fido.openend.se> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> Message-ID: On Sun, Sep 13, 2015 at 5:24 AM, Laura Creighton wrote: > My question, is whether it will handle Creighton, Saskatchewan, Canada? > Creighton is an odd little place. Like all of Saskatchewan, it is > in the Central time zone, even though you would expect it to be > in the Mountain time zone based on its location on the globe. > The people of Saskatchewan have decided not to adopt Daylight > Savings time. Except for the people of Creighton (and > nearby Denare Beach) -- who _do_ observe Daylight savings time. > > makes for an interesting corner case, one that I remember for > personal (and not economic, or professional) reasons. > Hi Laura! Wouldn't it be sufficient for people in Creighton to set their timezone to US/Central? IIUC the Canadian DST rules are the same as the US ones. Now, the question may remain how do people know what to set their timezone to. But neither pytz nor datetime can help with that -- it is up to the sysadmin. -- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sun Sep 13 18:46:37 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 13 Sep 2015 23:46:37 +0100 Subject: Can't use Python Launcher on Windows after update to 3.5 In-Reply-To: References: <55F15981.8030804@timgolden.me.uk> Message-ID: On 10/09/2015 16:56, Mark Lawrence wrote: > On 10/09/2015 11:20, Tim Golden wrote: >> On 10/09/2015 00:52, Mark Lawrence wrote: >>> I've installed 3.5 for all users so it's in C:\Program Files >>> >>> From >>> https://docs.python.org/3.5/using/windows.html#from-the-command-line it >>> says "System-wide installations of Python 3.3 and later will put the >>> launcher on your PATH. The launcher is compatible with all available >>> versions of Python, so it does not matter which version is installed. To >>> check that the launcher is available, execute the following command in >>> Command Prompt:", but:- >>> >>> C:\Users\Mark\Documents\MyPython>py -3.4 >>> 'py' is not recognized as an internal or external command, >>> operable program or batch file. >>> >>> Further running ftype shows nothing for Python, assoc just gives this >>> .pyproj=VisualStudio.Launcher.pyproj.14.0. Surely this is wrong? >>> >>> Before I go to the bug tracker to raise an issue could somebody please >>> confirm what I'm seeing, thanks. >>> >> >> Well I've just installed 64-bit 3.5.0rc4 via the web installer (ie this: >> https://www.python.org/ftp/python/3.5.0/python-3.5.0rc4-amd64-webinstall.exe) >> >> onto a machine with 64-bit 3.4.2 already installed. I went for the >> default install. >> >> It all seems to be ok and py -3.4 --version gives me "Python 3.4.2" as >> expected. assoc/ftype both look ok. c:\windows\py.exe has the versions & >> dates I expect. >> >> TJG >> > > So I ran the 64-bit 3.5.0rc4 via the web installer and still no joy. Ran > repair with same and it's business as usual. I'm not that bothered, > it's here for the record should anybody else come searching, so chalk it > up to experience and move on. Thanks anyway :) > Exactly the same thing happened when I upgraded to 3.5.0. so raised http://bugs.python.org/issue25089 just in case it hurts other people more than it hurts me. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Sun Sep 13 18:56:23 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 13 Sep 2015 18:56:23 -0400 Subject: Auto indents (was Re: How to set the history commands visible ?) In-Reply-To: References: Message-ID: On 9/13/2015 1:15 PM, Glus Xof wrote: > Is yet an automatic indentation system implemented ? The Idle editor does pep8-aware 'smart indenting'. In the following, '|' indicates the cursor position after is pressed. A ':' at the end of the line adds 1 indent -- unless there is an opener that has not been closed. So what looks like a buggy indent usually indicates a syntax error in the user code. a = 3 | if a == 3: |pass a = int(len({}) |) # pep 8 positioning a = int( |) # pep 8 positioning if a = 3: if b = 5: |pass if a == int(len({}): | # unclosed int( -- Terry Jan Reedy From paul.hermeneutic at gmail.com Sun Sep 13 19:05:40 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Sun, 13 Sep 2015 17:05:40 -0600 Subject: Cannot create a virtualenv Message-ID: - I downloaded and installed Python 3.5 64-bit onto a Windows 7 64-bit machine. - Using `pip install virtualenv` worked fine. - Now, it is time to create a virtualenv, but it is not working fine. - I had to add Python 3.5 to the PATH. - Any suggestions? C:\ve>virtualenv -p "\Program Files\Python 3.5\python.exe" ve33 Running virtualenv with interpreter C:\Program Files\Python 3.5\python.exe Using base prefix 'C:\\Program Files\\Python 3.5' New python executable in ve33\Scripts\python.exe Installing setuptools, pip, wheel... Complete output from command C:\ve\ve33\Scripts\python.exe -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel: Ignoring indexes: https://pypi.python.org/simple Collecting setuptools The repository located at None is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwis e you may silence this warning and allow it anyways with '--trusted-host None'. The repository located at None is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwis e you may silence this warning and allow it anyways with '--trusted-host None'. The repository located at None is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwis e you may silence this warning and allow it anyways with '--trusted-host None'. The repository located at None is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwis e you may silence this warning and allow it anyways with '--trusted-host None'. The repository located at None is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwis e you may silence this warning and allow it anyways with '--trusted-host None'. The repository located at None is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwis e you may silence this warning and allow it anyways with '--trusted-host None'. The repository located at None is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwis e you may silence this warning and allow it anyways with '--trusted-host None'. The repository located at None is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwis e you may silence this warning and allow it anyways with '--trusted-host None'. The repository located at None is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwis e you may silence this warning and allow it anyways with '--trusted-host None'. Could not find a version that satisfies the requirement setuptools (from versions: ) No matching distribution found for setuptools ---------------------------------------- ...Installing setuptools, pip, wheel...done. Traceback (most recent call last): File "c:\program files\python 3.5\lib\site-packages\virtualenv.py", line 2363, in main() File "c:\program files\python 3.5\lib\site-packages\virtualenv.py", line 832, in main symlink=options.symlink) File "c:\program files\python 3.5\lib\site-packages\virtualenv.py", line 1004, in create_environment install_wheel(to_install, py_executable, search_dirs) File "c:\program files\python 3.5\lib\site-packages\virtualenv.py", line 969, in install_wheel 'PIP_NO_INDEX': '1' File "c:\program files\python 3.5\lib\site-packages\virtualenv.py", line 910, in call_subprocess % (cmd_desc, proc.returncode)) OSError: Command C:\ve\ve33\Scripts\python.exe -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 1 From 4kir4.1i at gmail.com Sun Sep 13 19:17:53 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 14 Sep 2015 02:17:53 +0300 Subject: Terminology: "reference" versus "pointer" References: <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> Message-ID: <87pp1l6h9a.fsf@gmail.com> Random832 writes: > Akira Li <4kir4.1i at gmail.com> writes: >> I'm not sure what "parcel tags" model is but if you mean these >> pictures[1] than it works in this case as well as any other (take *a*, >> *b* nametags, put them on the corresponding balloons that represents >> list objects). >> >> The only names left are *a* and *b* that refer to the corresponding >> lists. There is no ambiguity there to put *a*, *b* nametags. > > But how do you make an a[0][0]/a[1][0] nametag to put on the "1" object? a[0][0]/a[1][0] are not names. Though if we want to talk about the corresponding objects then a[0][0]/a[1][0] could be used instead of names (as a way to identify them). >> Lists as any other containers contain references to other objects and >> therefore "box and arrows" model provides _more details_ here[2,3] > > Right, but why not use the *same* model to represent *namespaces*? If it works for your case; use it. The links [2,3] show that It does work in this case (if it is correct to call what they show "box and arrows" model). > It seems like the "tags" model only exists to make the incorrect claim > that python doesn't have variables (the boxes are variables). If you mean this quote from [1]: Although we commonly refer to "variables" even in Python (because it's common terminology), we really mean "names" or "identifiers". In Python, "variables" are nametags for values, not labelled boxes. then *name* is the term that is defined in the Python language reference. The word "variable" we can use in day-to-day programming _unless_ we are discussing issues that are specific to _naming and binding_. In that case, we should use the _exact_ terminology. Otherwise there is nothing wrong with using "variables" casually in Python. Notice: that [2,3] model is different from "labelled boxes" model. There are arrows from *a*/*b* _to_ list objects i.e., *a*/*b* are not boxes that _contain_ list objects within -- _otherwise you have to put the *same* list into two *different* boxes_ -- let's not investigate quantum paradoxes here. The only difference from "parcel tags" model is that list items do not have explicit names. >>> If the "parcel tags" model can't show it, then the "parcel tag" model >>> clearly is not a correct and complete depiction of how Python actually >>> works. >>> (If I were drawing a picture rather than ASCII I'd add something to make >>> it clear that the pairs shown are list objects Like, it's a circle with >>> the word "list" and two pointer-boxes inside it.) >> >> "correct and complete" is impossible in the general case for any >> model. > > Everything you wrote here has the same issue: The "objects" you are > talking about do not physically exist, but are simply the result of > calling a method on the object. Therefore they do not *belong* on the > diagram, and the diagram not showing them does not mean the diagram is > not complete. "do not physically exist" does not make sense. Objects are *never* destroyed explicitly in Python (you can only make them *unreachable*). You can disable garbage collection completely and it is still will be Python. Immutable objects can be considered immortal e.g.: (1+1) -- question: does the object that represents int(2) exist before the expression is evaluated? The correct answer: it does not matter: int(2) can be created on the fly, a cached int(2) can be reused by a specific implementation -- Python doesn't care. I don't see why the model that can't describe range(1) in Python 3 pretends to be complete. [1] http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#python-has-names [2] http://www.pythontutor.com/visualize.html#code=a0+%3D+a1+%3D+%5B1,+2%5D%0Ab0+%3D+%5B1,+2%5D%0Ab1+%3D+%5B1,+2%5D%0Aa+%3D+%5Ba0,+a1%5D%0Ab+%3D+%5Bb0,+b1%5D%0Adel+a0,+a1,+b0,+b1%0A&mode=display&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&textReferences=false&py=3&rawInputLstJSON=%5B%5D&curInstr=6 [3] http://www.pythontutor.com/visualize.html#code=a0+%3D+a1+%3D+%5B1,+2%5D%0Ab0+%3D+%5B1,+2%5D%0Ab1+%3D+%5B1,+2%5D%0Aa+%3D+%5Ba0,+a1%5D%0Ab+%3D+%5Bb0,+b1%5D%0Adel+a0,+a1,+b0,+b1%0Aa%5B0%5D%5B0%5D+%3D+%22Oops!%22&mode=display&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&textReferences=false&py=3&rawInputLstJSON=%5B%5D&curInstr=7 From random832 at fastmail.com Sun Sep 13 19:38:37 2015 From: random832 at fastmail.com (Random832) Date: Sun, 13 Sep 2015 19:38:37 -0400 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <87pp1l6h9a.fsf@gmail.com> References: <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> Message-ID: <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> On Sun, Sep 13, 2015, at 19:17, Akira Li wrote: > "do not physically exist" does not make sense. Objects are *never* > destroyed explicitly in Python (you can only make them > *unreachable*). But the objects we've talking about have never been created, because the __getitem__ method has not been called, because we're talking about the structure of what _is there_, not the idea of what will happen after you call some method. The (range, or whatever) object holds no reference/pointer/whatever (maybe we should just call them arrows?) to the objects that it will create when you call __getitem__, or even to the ones that it has created when you've called it, so it doesn't make sense to put a box in it that will have an arrow pointing to those objects. > You can disable garbage collection completely and it is > still will be Python. Immutable objects can be considered immortal e.g.: > > (1+1) -- question: does the object that represents int(2) exist before > the expression is evaluated? > > The correct answer: it does not matter: int(2) can be created on the > fly, a cached int(2) can be reused by a specific implementation -- > Python doesn't care. > > I don't see why the model that can't describe range(1) in Python 3 > pretends to be complete. Why can't it describe range(1)? A range object in my model would include the start, stop, and step; _not_ the contents of what you would get by iterating over it; since that's not part of the physical structure of the object, but the consequences of calling methods on it. From denismfmcmahon at gmail.com Sun Sep 13 19:43:11 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 13 Sep 2015 23:43:11 +0000 (UTC) Subject: convert element in a list to float References: <417abfa4-e7c7-4573-83ed-50b8a5aca2b2@googlegroups.com> Message-ID: On Sun, 13 Sep 2015 23:02:55 +0200, Laura Creighton wrote: > In a message of Sun, 13 Sep 2015 12:55:13 -0700, forums_mp at hotmail.com > writes: >> >>For starters, I googled and saw a plethora of writings on how to convert >>an entire list from string to float. My interest is on select elements >>in the list. The output from the print statement: print scenarioList >> >>is as follows >> >>[ '3000000', '"N"', '11400000', '"E"' ] >> >>I need to convert the first and third element to float. >> lat = ( float ) scenarioList [ 0 ] >> lon = ( float ) scenarioList [ 2 ] >> >>fails (invalid syntax). How can I achieve my objective. >> >>Thanks in advance > > Does this help? > >>>> l = [ '3000000', '"N"', '11400000', '"E"' ] >>>> [float(l[0]), l[1], float(l[2]), l[3]] > [3000000.0, '"N"', 11400000.0, '"E"'] Here's a method that will convert any value in a list that can be made a float into a float, and (I think) should leave all others as they are. It users a helper function and a list comprehension. >>> def tofloat(x): ... try: ... return float(x) ... except ValueError: ... return None ... >>> l = [ '3000000', '"N"', '11400000', '"E"' ] >>> l = [ tofloat(x) or x for x in l ] >>> l [3000000.0, '"N"', 11400000.0, '"E"'] -- Denis McMahon, denismfmcmahon at gmail.com From rosuav at gmail.com Sun Sep 13 19:52:32 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Sep 2015 09:52:32 +1000 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <87pp1l6h9a.fsf@gmail.com> References: <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> Message-ID: On Mon, Sep 14, 2015 at 9:17 AM, Akira Li <4kir4.1i at gmail.com> wrote: > If you mean this quote from [1]: > > Although we commonly refer to "variables" even in Python (because it's > common terminology), we really mean "names" or "identifiers". In > Python, "variables" are nametags for values, not labelled boxes. > > then *name* is the term that is defined in the Python language > reference. The word "variable" we can use in day-to-day programming > _unless_ we are discussing issues that are specific to _naming and > binding_. In that case, we should use the _exact_ > terminology. Otherwise there is nothing wrong with using "variables" > casually in Python. Since you're talking about precise terminology, I think it would be better to say "name binding", rather than "naming and binding". When you talk of naming something (or someone!), you generally mean that it's possible to go from the thing to the (canonical) name. With people, for instance, you can walk up to someone and say "Hi! What's your name?", but with Python objects, you fundamentally can't. >> Everything you wrote here has the same issue: The "objects" you are >> talking about do not physically exist, but are simply the result of >> calling a method on the object. Therefore they do not *belong* on the >> diagram, and the diagram not showing them does not mean the diagram is >> not complete. > > "do not physically exist" does not make sense. Objects are *never* > destroyed explicitly in Python (you can only make them > *unreachable*). You can disable garbage collection completely and it is > still will be Python. Immutable objects can be considered immortal e.g.: > > (1+1) -- question: does the object that represents int(2) exist before > the expression is evaluated? > > The correct answer: it does not matter: int(2) can be created on the > fly, a cached int(2) can be reused by a specific implementation -- > Python doesn't care. > > I don't see why the model that can't describe range(1) in Python 3 > pretends to be complete. "Physically" isn't really the right word for it, given that objects in Python code aren't physical and therefore don't *ever* "physically exist". My bad there. But the objects completely do not exist. Yes, with integers you can't tell... but what about here? dependencies = collections.defaultdict(list) for fn in files: for dep in gather_deps(fn): dependencies[dep].append(fn) Until the moment when dependencies[dep] is requested for some new value of dep, the list *does not exist*. It is constructed anew. Obviously the end result of this is a dict of lists, and since those lists aren't accessible from anywhere else, it makes fine sense to talk about those lists as being "contained within" the (default)dict; but they clearly didn't exist until they were poked at. They're Heisenburg's Lists, I guess... ChrisA From denismfmcmahon at gmail.com Sun Sep 13 19:57:50 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 13 Sep 2015 23:57:50 +0000 (UTC) Subject: Phone Tree References: <6ae5c632-b061-4b86-87ae-24c50435445b@googlegroups.com> Message-ID: On Sun, 13 Sep 2015 07:39:23 -0700, Azureaus wrote: > Does anyone have any ideas for a more elegant solution? My thoughts are > that I could use a tree data structure and hence make traversing the > tree recursive based on yes or no answers. I'm happy to put the time in > to explain these more complex ideas, I'm just hoping those with more > expertise than myself could either help verify the idea or suggest > alternatives. The trick is to separate the data and the processing. Each question has a yes, no answer, so start with a dictionary of data tuples (you could use a list, but using a dictionary makes the relationship slightly easier to walk through): questions = { 1: (q1, response if yes, response if no), 2: (q2, response if yes, response if no) .... } The responses can be either a number of another question, or a result text. Then your algorithm is broadly: x = 1: while x is numeric: ask questions[x][0] if answer is "yes": x = questions[x][1] if answer is "no": x = questions[x][2] answer is x You can use a list instead of a dictionary, just remember 0 indexing when you're working out which question leads to which next question. This way also makes for an interesting talking point about separating data and code, especially given the multiple if statements issue. -- Denis McMahon, denismfmcmahon at gmail.com From tim.peters at gmail.com Sun Sep 13 20:13:19 2015 From: tim.peters at gmail.com (Tim Peters) Date: Sun, 13 Sep 2015 19:13:19 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> Message-ID: [Guido] > Wouldn't it be sufficient for people in Creighton to set their timezone to > US/Central? IIUC the Canadian DST rules are the same as the US ones. Now, > the question may remain how do people know what to set their timezone to. > But neither pytz nor datetime can help with that -- it is up to the > sysadmin. As Laura's use case evolved, it seems it was more that a train traveler from Halifax to Creighton wants to tell their Halifax relatives when they'll arrive in Creighton, but (of course) expressed in Halifax time. Nobody in this case knows anything about Creighton's rules, except the traveler may be staring at a train schedule giving arrival in Creighton time anyway. While this may be beyond pytz's wizardy, nothing is too hard for datetime ;-) datetime.timezone.setcontext("datetime-sig messages from mid-Sep 2015") arrivaltime = datetime.strptime(scraped_arrival_time, "") arrivaltime = datetime.replace(arrivaltime, tzinfo=gettz("Context/Creighton")) print(arrivaltime.astimezone(gettz("Context/Halifax")) From 4kir4.1i at gmail.com Sun Sep 13 20:30:37 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 14 Sep 2015 03:30:37 +0300 Subject: Terminology: "reference" versus "pointer" References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> Message-ID: <87lhc96dw2.fsf@gmail.com> Chris Angelico writes: > On Mon, Sep 14, 2015 at 9:17 AM, Akira Li <4kir4.1i at gmail.com> wrote: >> If you mean this quote from [1]: >> >> Although we commonly refer to "variables" even in Python (because it's >> common terminology), we really mean "names" or "identifiers". In >> Python, "variables" are nametags for values, not labelled boxes. >> >> then *name* is the term that is defined in the Python language >> reference. The word "variable" we can use in day-to-day programming >> _unless_ we are discussing issues that are specific to _naming and >> binding_. In that case, we should use the _exact_ >> terminology. Otherwise there is nothing wrong with using "variables" >> casually in Python. > > Since you're talking about precise terminology, I think it would be > better to say "name binding", rather than "naming and binding". When > you talk of naming something (or someone!), you generally mean that > it's possible to go from the thing to the (canonical) name. With > people, for instance, you can walk up to someone and say "Hi! What's > your name?", but with Python objects, you fundamentally can't. "Naming and binding" is the title from the Python language reference https://docs.python.org/3/reference/executionmodel.html#naming-and-binding Otherwise, I agree with you ("name" is better here). >>> Everything you wrote here has the same issue: The "objects" you are >>> talking about do not physically exist, but are simply the result of >>> calling a method on the object. Therefore they do not *belong* on the >>> diagram, and the diagram not showing them does not mean the diagram is >>> not complete. >> >> "do not physically exist" does not make sense. Objects are *never* >> destroyed explicitly in Python (you can only make them >> *unreachable*). You can disable garbage collection completely and it is >> still will be Python. Immutable objects can be considered immortal e.g.: >> >> (1+1) -- question: does the object that represents int(2) exist before >> the expression is evaluated? >> >> The correct answer: it does not matter: int(2) can be created on the >> fly, a cached int(2) can be reused by a specific implementation -- >> Python doesn't care. >> >> I don't see why the model that can't describe range(1) in Python 3 >> pretends to be complete. > > "Physically" isn't really the right word for it, given that objects in > Python code aren't physical and therefore don't *ever* "physically > exist". My bad there. > > But the objects completely do not exist. Yes, with integers you can't > tell... but what about here? > > dependencies = collections.defaultdict(list) > for fn in files: > for dep in gather_deps(fn): > dependencies[dep].append(fn) > > Until the moment when dependencies[dep] is requested for some new > value of dep, the list *does not exist*. It is constructed anew. > Obviously the end result of this is a dict of lists, and since those > lists aren't accessible from anywhere else, it makes fine sense to > talk about those lists as being "contained within" the (default)dict; > but they clearly didn't exist until they were poked at. They're > Heisenburg's Lists, I guess... lists are _mutable_ in Python. From rosuav at gmail.com Sun Sep 13 20:58:39 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Sep 2015 10:58:39 +1000 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <87lhc96dw2.fsf@gmail.com> References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <87lhc96dw2.fsf@gmail.com> Message-ID: On Mon, Sep 14, 2015 at 10:30 AM, Akira Li <4kir4.1i at gmail.com> wrote: > "Naming and binding" is the title from the Python language reference > https://docs.python.org/3/reference/executionmodel.html#naming-and-binding > > Otherwise, I agree with you ("name" is better here). Ah, gotcha. That's talking in much broader scope, so "naming" makes a bit more sense there. In any case, I can't think of a better term for it in the full context. >> Until the moment when dependencies[dep] is requested for some new >> value of dep, the list *does not exist*. It is constructed anew. >> Obviously the end result of this is a dict of lists, and since those >> lists aren't accessible from anywhere else, it makes fine sense to >> talk about those lists as being "contained within" the (default)dict; >> but they clearly didn't exist until they were poked at. They're >> Heisenburg's Lists, I guess... > > lists are _mutable_ in Python. So? Objects are objects. Some of them have no means of changing their values, while others do. But the Python object model is absolutely the same for all of them; it's not "pass by value for immutables, pass by reference for mutables" as some have tried to claim. Immutable objects have values and identities; the only difference is that the compiler is allowed to constant-fold, using the same string "hello" in each of the three places where such a string comes up, or sharing the tuple (1,2,None) across usages. ChrisA From steve at pearwood.info Sun Sep 13 21:09:12 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 14 Sep 2015 11:09:12 +1000 Subject: convert element in a list to float References: <417abfa4-e7c7-4573-83ed-50b8a5aca2b2@googlegroups.com> Message-ID: <55f61e38$0$1668$c3e8da3$5496439d@news.astraweb.com> Hi Forums_MP and welcome, On Mon, 14 Sep 2015 05:55 am, forums_mp at hotmail.com wrote: > For starters, I googled and saw a plethora of writings on how to convert > an entire list from string to float. My interest is on select elements > in the list. The output from the print statement: print scenarioList > > is as follows > > [ '3000000', '"N"', '11400000', '"E"' ] > > I need to convert the first and third element to float. > lat = ( float ) scenarioList [ 0 ] > lon = ( float ) scenarioList [ 2 ] > > fails (invalid syntax). How can I achieve my objective. By now you have hopefully discovered that the answer is to call float as a function: lat = float(scenarioList[0]) but I wonder what in the documentation or examples you saw suggested to you that Python used the C type-cast syntax `(float)value`? Whatever it was that gave you this wrong impression needs to be fixed. -- Steven From steve at pearwood.info Sun Sep 13 21:10:35 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 14 Sep 2015 11:10:35 +1000 Subject: Terminology: "reference" versus "pointer" References: <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> Message-ID: <55f61e8c$0$1660$c3e8da3$5496439d@news.astraweb.com> On Mon, 14 Sep 2015 09:17 am, Akira Li wrote: > I don't see why the model that can't describe range(1) in Python 3 > pretends to be complete. Please explain. range(1) returns a range instance. What is hard about that? -- Steven From rurpy at yahoo.com Sun Sep 13 21:13:22 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 13 Sep 2015 18:13:22 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <0034a8bd-cd81-4c5e-9759-1ce1aa97e2e2@googlegroups.com> <0f742e14-1983-42ae-a774-f8a9f3485e34@googlegroups.com> <5d871fb7-03f5-4b58-b03b-d411fc693658@googlegroups.com> <55F4E0E0.6020009@gmail.com> <557c7158-6a8f-42e3-8cec-411f29363436@googlegroups.com> Message-ID: <9036e3c8-24ce-43c6-bb54-ccb31098e13a@googlegroups.com> On Sunday, September 13, 2015 at 2:49:13 PM UTC-6, Ben Finney wrote: > Chris Angelico writes: > > > I think Ben's referring to taunting jmf, whom Mark called the "RUE" or > > "Resident Unicode Expert". There has been a long-standing antagonism > > between those two (which is completely understandable), and one which > > often spills over into vitriolic posts (which is less acceptable). > > Chris has it right. > > What's especially unacceptable is invoking that person for amusement, > irrelevant to the conversation. It's one thing to respond when a person > comes into a thread to troll unbidden; it is quite another to taunt them > unprompted. Thank you for making that clear. From 4kir4.1i at gmail.com Sun Sep 13 21:22:31 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 14 Sep 2015 04:22:31 +0300 Subject: Terminology: "reference" versus "pointer" References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <55f61e8c$0$1660$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87h9mx6bhk.fsf@gmail.com> Steven D'Aprano writes: > On Mon, 14 Sep 2015 09:17 am, Akira Li wrote: > >> I don't see why the model that can't describe range(1) in Python 3 >> pretends to be complete. > > > Please explain. > > range(1) returns a range instance. What is hard about that? Look at the last example: http://thread.gmane.org/gmane.comp.python.general/782626/focus=782704 From rosuav at gmail.com Sun Sep 13 21:30:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Sep 2015 11:30:43 +1000 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <87h9mx6bhk.fsf@gmail.com> References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <55f61e8c$0$1660$c3e8da3$5496439d@news.astraweb.com> <87h9mx6bhk.fsf@gmail.com> Message-ID: On Mon, Sep 14, 2015 at 11:22 AM, Akira Li <4kir4.1i at gmail.com> wrote: > Steven D'Aprano writes: > >> On Mon, 14 Sep 2015 09:17 am, Akira Li wrote: >> >>> I don't see why the model that can't describe range(1) in Python 3 >>> pretends to be complete. >> >> >> Please explain. >> >> range(1) returns a range instance. What is hard about that? > > Look at the last example: > http://thread.gmane.org/gmane.comp.python.general/782626/focus=782704 Still not sure what the problem is. As per Python's object model, the lists contain references to range objects. a contains two references to the same range object, b contains references to each of two distinct range objects. What of it? ChrisA From rurpy at yahoo.com Sun Sep 13 21:34:42 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sun, 13 Sep 2015 18:34:42 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: <55f57122$0$1654$c3e8da3$5496439d@news.astraweb.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <55f57122$0$1654$c3e8da3$5496439d@news.astraweb.com> Message-ID: <12d728b4-da61-483c-b49f-94b46ca86f21@googlegroups.com> On 09/13/2015 06:50 AM, Steven D'Aprano wrote: > On Sun, 13 Sep 2015 04:45 am, rurpy at yahoo.com wrote: >> On 09/12/2015 10:32 AM, Steven D'Aprano wrote: >>> On Sat, 12 Sep 2015 02:42 pm, Random832 wrote: >>> [...] >>> Computer science and IT is *dominated* by a single usage for "pointer" -- >>> it's an abstract memory address. The fundamental characteristics of >>> pointers are: >> >> Just upthread, you claimed something was "universally agreed" > > I did? "Universially agreed" doesn't sound like something I would say. Do > you have a link to where I said that? > I think you're confusing me with somebody else. Somebody who is not me. I should have copy/pasted rather than paraphrasing from memory. You said "near-universal agreement" ("Re: Python handles globals badly", 2015-09-10). The difference does not change my response at all. > [...] > I have little problem with you using "pointer" as a metaphor: "Python > variables are like pointers in these ways...". I do have a problem with you > insisting that they are pointers. First, I am very cautious about about using absolute and dogmatic words like *are* [pointers] (although I probably have occasionally for brevity or in response to someones else's dogmatism.) If you go back over what I've written, I think you'll see that my main point is that describing what is in python "variables" and objects as pointers can be useful in some circumstances as an alternative to the current official description (with people who have had some experience with pointers in other languages, for example). The "standard definition" you keep referring to (and basing your arguments on was): An address, from the point of view of a programming language.[...] Wikipedia also seems to define pointer in terms of memory address. As I said, I think when describing the behavior of a language in abstract terms it is perfectly valid to take "address" equally abstractly (eg a token that lets you retrieve the same data every time you use it) but unfortunately for me Wikipedia defines "address" as the conventional linear numbers used in real-world computers. And I am not going to waste my time trying to convince anyone that Wikipedia is wrong or the context in inappropriate. Wikipedia also makes a distinction between "pointer" as something that refers to some data by "memory address" and "reference" which refers to some data by any means (including but not limited to a memory address, eg offset from current address or url). That was not distinction I knew of; I considered both terms as being more or less synonymous (in the general sense, obviously they are different in specific domains like C++). So I will retract any claim I made about "pointer" being a technically correct term (because Python-the-language imposes no restrictions on on how references are implemented.) Nevertheless I'll continue to maintain that it is useful to explain how python works in terms of pointers in that: 1) The distinction between abstract pointers(*) and references is non-existant or irrelevant in Python for any existing implementation. 2) You can accurately specify python-the-language in term of abstract pointers (ie, "as if") regardless of how it is currently specified. 3) People who've used pointers in other languages are more easily able to grasp Python semantics when presented in term of pointers, a concept they already understand. (*) by "abstract pointers" I mean pointers in the sense given in your definition, not C datatype pointers. If you insist on "references" that's ok too, the description can be accompanied with a wink and a whispered, "hey, references are really like pointers".) Those are my opinions, if you have any clear counter examples I would certainly like to know of them but I've not seen or read anything yet that indicates they are wrong. Below I snipped out all your responses that were essentially "that's not the standard definition of pointers", having addressed those above. > [...] >> It may not be appropriate way to describe Python for everybody but >> it is perfectly reasonable (and even preferable) for people with >> an understanding of "pointers" from some other language. And for >> those people who don't then one could argue they are a clean slate >> and using the word "pointer" won't hurt. > > No, it is not reasonable. > > You want to insist that `x = 23` in Python code makes x a pointer. But that > Python snippet is analogous to to the following C and Pascal snippets: > > # C > int x = 23; > > [...pascal example snipped...] > > Do you insist that they are pointers to? > > Then everything is a pointer, and the word has no meaning. > > Regardless of which of the three languages we are talking about, the > assignment `x = 23` does not mean "bind some value to x which, when > dereferenced, gives the value 23". > > The value bound to x is 23, not some > indirect pointer to 23. Your problem is that the C snippet is not, as you claim, analogous to the Python snippet, despite their superficial syntactical similarity. C has allows one to mention values both directly and via pointers (or references if you prefer) and Python only the latter. You chose your C example to be an example of the kind of access Python doesn't do, so of course I would not call x in the C example a pointer or reference. /char *s = "foo";/ and /s = "foo"/ would have been a more analogous comparison. But continuing with your example... In C, x is immutably bound to the "object" containing 23. The object is an unboxed int at some fixed memory location and by immutably bound I mean that x will always refer to that memory location. You cannot change that binding, all you can do is change the contents of the object to some other int value. In Python of course all that is not true. As you well know, you can reassign x and when you do you don't change the contents of the object x was pointing to (or referencing if you insist) -- you change x itself. The object known as 23 is still sitting there, pretty as you please, waiting to be accessed though some other name, or some other unnamed pointer (or reference if you insist) or garbage collected or for the program to end. Meanwhile, x is there, now (dare I say it?) pointing to some other object, maybe an int(24), which it sitting in memory somewhere. We know it has an existence independent of x by many ways which you already know and I need not repeat. So what then is x in Python? Well of course it's a name in the source code. But how does it exist in the running program? Where is it and what does it contain? Python does not tell us but we know that whatever and wherever it is, when we mentioned it before we got back (the object) 23 and now when we mention it we get back (the object) 24. It *behaves* as though it were a pointer (or reference if you prefer). a = [23] What is a[0]? This time the Python docs tell us explicitly: "Some objects contain *references* to other objects; these are called containers" [Language Ref 3.1: Objects, values and types] The thing in a[0] is a *reference* (or sloppily, a pointer). b = 24 a[0] = 24 You say assignment in the first case assigns 24 directly to b and the Python docs tell us that assignment in the second case assigns a reference (to 24) when the assignment is done to a container. That's an utterly needless distinction. A simpler, more consistent description is to say Python assigns a reference (in this case to the object representing 24) to the thing on the left side of the "=". Always. There is nothing implementation dependent about this. It is more than possible to do this, it is advantageous because now it is obvious that named things work the same way unnamed things do (ie in python everything is an object and all objects are accessed through references -- emphasizing the consistency and simplicity of python's object model.) Of course it is also necessary to also have a concomitant rule that when a name is mentioned it is automatically dereferenced. That is not unique to Python; in Go the only thing you can do with pointers is dereference them. > The *implementation* of how names and variables are bound may (or may not) > involve pointers, but that is outside of the language abstraction, whether > we are talking about Python, C or Pascal. It is not outside the language abstraction if the description is "as-if" equivalent to every possible implementation choice, that is, it is isomorphic. (Probably not the right word but you get the idea). This discussion has bifurcated into two related but distinct issues: 1) Whether pointer is acceptable terminology for reference. 2) What in Python should or should not be described in terms of reference/pointer. There were some places above where I wasn't sure if your objection was on the grounds of 1 or 2. From 4kir4.1i at gmail.com Sun Sep 13 22:26:11 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 14 Sep 2015 05:26:11 +0300 Subject: Terminology: "reference" versus "pointer" References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <55f61e8c$0$1660$c3e8da3$5496439d@news.astraweb.com> <87h9mx6bhk.fsf@gmail.com> Message-ID: <87d1xl68jg.fsf@gmail.com> Chris Angelico writes: > On Mon, Sep 14, 2015 at 11:22 AM, Akira Li <4kir4.1i at gmail.com> wrote: >> Steven D'Aprano writes: >> >>> On Mon, 14 Sep 2015 09:17 am, Akira Li wrote: >>> >>>> I don't see why the model that can't describe range(1) in Python 3 >>>> pretends to be complete. >>> >>> >>> Please explain. >>> >>> range(1) returns a range instance. What is hard about that? >> >> Look at the last example: >> http://thread.gmane.org/gmane.comp.python.general/782626/focus=782704 > > Still not sure what the problem is. As per Python's object model, the > lists contain references to range objects. a contains two references > to the same range object, b contains references to each of two > distinct range objects. What of it? For me, there is no problem. "parcel tags" [1], "box and arrows"[2] are all the same (note: "labelled box"[3] that may contain an object is a different model). The talk about being "complete" is caused by the following quote from Random832 message [4]: If the "parcel tags" model can't show it, then the "parcel tag" model clearly is not a correct and complete depiction of how Python actually works. The purpose of the examples in [5] is to demonstate that neither models are "complete" i.e., there is (obviously) behavior of a Python program that they can't describe. [1] http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#python-has-names [2] http://www.pythontutor.com/visualize.html#code=a0+%3D+a1+%3D+%5B1,+2%5D%0Ab0+%3D+%5B1,+2%5D%0Ab1+%3D+%5B1,+2%5D%0Aa+%3D+%5Ba0,+a1%5D%0Ab+%3D+%5Bb0,+b1%5D%0Adel+a0,+a1,+b0,+b1%0A&mode=display&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&textReferences=false&py=3&rawInputLstJSON=%5B%5D&curInstr=6 [3] http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables [4] http://thread.gmane.org/gmane.comp.python.general/782626/focus=782645 [5] http://thread.gmane.org/gmane.comp.python.general/782626/focus=782704 From steve at pearwood.info Sun Sep 13 22:38:51 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 14 Sep 2015 12:38:51 +1000 Subject: Terminology: "reference" versus "pointer" References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <55f61e8c$0$1660$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f6333c$0$1636$c3e8da3$5496439d@news.astraweb.com> On Mon, 14 Sep 2015 11:22 am, Akira Li wrote: > Steven D'Aprano writes: > >> On Mon, 14 Sep 2015 09:17 am, Akira Li wrote: >> >>> I don't see why the model that can't describe range(1) in Python 3 >>> pretends to be complete. >> >> >> Please explain. >> >> range(1) returns a range instance. What is hard about that? > > Look at the last example: > http://thread.gmane.org/gmane.comp.python.general/782626/focus=782704 I'm afraid that page is broken in my browser. Can you not summarise, or link to the specific message? I may be able to use another browser in a day or two, but hopefully the discussion will have moved on by then. -- Steven From 4kir4.1i at gmail.com Sun Sep 13 23:23:47 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 14 Sep 2015 06:23:47 +0300 Subject: Terminology: "reference" versus "pointer" References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <55f61e8c$0$1660$c3e8da3$5496439d@news.astraweb.com> <55f6333c$0$1636$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878u8965vg.fsf@gmail.com> Steven D'Aprano writes: > On Mon, 14 Sep 2015 11:22 am, Akira Li wrote: >> Look at the last example: >> http://thread.gmane.org/gmane.comp.python.general/782626/focus=782704 > > > I'm afraid that page is broken in my browser. Can you not summarise, or link > to the specific message? I may be able to use another browser in a day or > two, but hopefully the discussion will have moved on by then. https://mail.python.org/pipermail/python-list/2015-September/696631.html From breamoreboy at yahoo.co.uk Sun Sep 13 23:34:52 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 14 Sep 2015 04:34:52 +0100 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <12d728b4-da61-483c-b49f-94b46ca86f21@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <8e16c020-e734-401d-92cb-10a2cdddd497@googlegroups.com> <55f4657f$0$1675$c3e8da3$5496439d@news.astraweb.com> <55f57122$0$1654$c3e8da3$5496439d@news.astraweb.com> <12d728b4-da61-483c-b49f-94b46ca86f21@googlegroups.com> Message-ID: On 14/09/2015 02:34, rurpy--- via Python-list wrote: Goodbye, *plonk* -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From victorhooi at gmail.com Sun Sep 13 23:44:16 2015 From: victorhooi at gmail.com (Victor Hooi) Date: Sun, 13 Sep 2015 20:44:16 -0700 (PDT) Subject: Using enumerate to get line-numbers with itertools grouper? In-Reply-To: References: Message-ID: <6050d61f-9e76-48b4-b870-16be601047bc@googlegroups.com> On Thursday, 3 September 2015 03:49:05 UTC+10, Terry Reedy wrote: > On 9/2/2015 6:04 AM, Victor Hooi wrote: > > I'm using grouper() to iterate over a textfile in groups of lines: > > > > def grouper(iterable, n, fillvalue=None): > > "Collect data into fixed-length chunks or blocks" > > # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx > > args = [iter(iterable)] * n > > return zip_longest(fillvalue=fillvalue, *args) > > > > However, I'd also like to know the line-number that I'm up to, for printing out in informational or error messages. > > > > Is there a way to use enumerate with grouper to achieve this? > > Without a runnable test example, it is hard to be sure what you want. > However, I believe replacing 'iter(iterable)' with 'enumerate(iterable, > 1)', and taking into account that you will get (line_number, line) > tuples instead of lines, will do what you want. > > -- > Terry Jan Reedy Hi, Hmm, I've tried that suggestion, but for some reason, it doesn't seem to be unpacking the values correctly - in this case, line_number and chunk below just give me two successive items from the iterable: Below is the complete code I'm running: #!/usr/bin/env python3 from datetime import datetime from itertools import zip_longest def grouper(iterable, n, fillvalue=None): "Collect data into fixed-length chunks or blocks" # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx args = [enumerate(iterable, 1)] * n return zip_longest(fillvalue=fillvalue, *args) def parse_iostat(lines): """Parse lines of iostat information, yielding iostat blocks. lines should be an iterable yielding separate lines of output """ block = None for line in lines: line = line.strip() try: if ' AM' in line or ' PM' in line: # What happens if their device names have AM or PM? tm = datetime.strptime(line, "%m/%d/%Y %I:%M:%S %p") else: tm = datetime.strptime(line, "%m/%d/%y %H:%M:%S") if block: yield block block = [tm] except ValueError: # It's not a new timestamp, so add it to the existing block # We ignore the iostat startup lines (which deals with random restarts of iostat), as well as empty lines if '_x86_64_' not in line: block.append(line) if block: yield block with open('iostat_sample_12hr_time', 'r') as f: f.__next__() # Skip the "Linux..." line f.__next__() # Skip the blank line for line_number, chunk in grouper(parse_iostat(f), 2): print("Line Number: {}".format(line_number)) print("Chunk: {}".format(chunk)) Here is the input file: Linux 3.19.0-20-generic (ip-172-31-12-169) 06/25/2015 _x86_64_ (2 CPU) 06/25/2015 07:37:04 AM avg-cpu: %user %nice %system %iowait %steal %idle 0.02 0.00 0.02 0.00 0.00 99.95 Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await r_await w_await svctm %util xvdap1 0.00 0.04 0.03 0.07 0.00 0.00 84.96 0.00 30.36 2.74 42.83 0.53 0.01 xvdb 0.00 0.00 0.00 0.00 0.00 0.00 11.62 0.00 0.23 0.19 2.13 0.16 0.00 xvdf 0.00 0.00 0.00 0.00 0.00 0.00 10.29 0.00 0.41 0.41 0.73 0.38 0.00 xvdg 0.00 0.00 0.00 0.00 0.00 0.00 9.12 0.00 0.36 0.35 1.20 0.34 0.00 xvdh 0.00 0.00 0.00 0.00 0.00 0.00 33.35 0.00 1.39 0.41 8.91 0.39 0.00 dm-0 0.00 0.00 0.00 0.00 0.00 0.00 11.66 0.00 0.46 0.46 0.00 0.37 0.00 06/25/2015 07:37:05 AM avg-cpu: %user %nice %system %iowait %steal %idle 0.50 0.00 0.50 0.00 0.00 99.01 Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await r_await w_await svctm %util xvdap1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 xvdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 xvdf 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 xvdg 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 xvdh 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 dm-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 Essentially, in the full code, what I'd like to be able to do is process a "iostat" file, which contains "blocks" of iostat output, and know at any point in time what line number I was up to in the original file. Cheers, Victor From alexander.belopolsky at gmail.com Sun Sep 13 23:54:42 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Sun, 13 Sep 2015 23:54:42 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> Message-ID: On Sun, Sep 13, 2015 at 6:21 PM, Guido van Rossum wrote: > > Now, the question may remain how do people know what to set their timezone to. But neither pytz nor datetime can help with that -- it is up to the sysadmin. Note that this question is also out of the scope of "tzdist", IETF Time Zone Data Distribution Service Working Group: """ The following are Out of scope for the working group: ... - Lookup protocols or APIs to map a location to a time zone. """ I am not aware of any effort to develop such service. On the other hand, stationary ISPs have means to distribute TZ information to the hosts. See for example, RFC 4833 ("Timezone Options for DHCP"). -------------- next part -------------- An HTML attachment was scrubbed... URL: From kawazu428 at gmail.com Mon Sep 14 02:58:29 2015 From: kawazu428 at gmail.com (Kristian Rink) Date: Sun, 13 Sep 2015 23:58:29 -0700 (PDT) Subject: Packaging and deployment of standalone Python applications? Message-ID: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> Folks; coming from a server-sided Java background, I'm recently exploring frameworks such as cherrypy or webpy for building RESTful services, which is quite a breeze and a pretty pleasant experience; however one thing so far bugs me: Using Java tooling and libraries such as DropWizard, it is pretty straightforward to build an "all-inclusive" application containing (a) all code of my own, (b) all required dependencies, (c) all other resources and, if required, even (d) a Java virtual machine in one large .zip file which can easily be copied to a clean Linux VM, unzipped and started there. Are there ways of doing so using Python, too? I'd like to set up a project structure / working environment that includes all Python 3rd party libraries, my own code and maybe even a "standard" Python runtime for 64bit Linux systems (to not depend too much on what version a certain Linux distribution actually ships) and focus on doing deployment to various machines at best by simply copying these packages around. Any pointers, ideas, inspirations on that greatly appreciated - even in total different ways if what I am about to do is completely off anyone would do it in a Python environment. ;) TIA and all the best, Kristian From antoon.pardon at rece.vub.ac.be Mon Sep 14 03:13:45 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 14 Sep 2015 09:13:45 +0200 Subject: Python handles globals badly. In-Reply-To: <87pp1pqi93.fsf@elektro.pacujo.net> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55f1a8df$0$1660$c3e8da3$5496439d@news.astraweb.com> <1441902711.3168172.380049449.32E41922@webmail.messagingengine.com> <87pp1pqi93.fsf@elektro.pacujo.net> Message-ID: <55F673A9.4070107@rece.vub.ac.be> Op 11-09-15 om 13:59 schreef Marko Rauhamaa: > Antoon Pardon : > >> I just don't get why people want to introduce special cases in python. >> Why allow such a construct only in while and if? Why not just allow >> it generally as an assignment expression? >> >> Why not allow: >> >> while (f(x) as fx) > 5: >> proces(fx) >> >> or >> >> if check(nextvalue() as new): >> treat(new) > Hey, I know, I know!... Let's allow: > > while (fx = f(x)) > 5: > process(fx) > > if check(new = nextvalue()): > treat(new) > > Seriously, though, I share your distaste of special cases, Antoon. Only > I don't like too much syntax (just look at Perl). This proposal would have as an effect less syntax. The 'as ...' syntax already exists, but as special cases. Making 'as ...' a general assignment operator would eliminated the special cases and collect them all in the expression syntax. So less syntax. > There's nothing wrong > in: > > while True: > fx = f(x) > if fx <= 5: > break > process(fx) There was also nothing wrong with: if b > c: a = 5 else: a = 2 > new = nextvalue() > if check(new): > treat(new) Except that it would need an extra indentation level if it was an elif. -- Antoon Pardon From nomail at invalid.com Mon Sep 14 03:13:47 2015 From: nomail at invalid.com (ast) Date: Mon, 14 Sep 2015 09:13:47 +0200 Subject: Putting the main program in a main function Message-ID: <55f673b3$0$3342$426a74cc@news.free.fr> Hi I saw here http://inventwithpython.com/pygame/chapter3.html a program where the main program is put in a function. So the structure is: def main(): main code here def f1(): function 1 code def f2(): function 2 code ...... if __name__ == '__main__': main() The author says that with this structure there are no global variables (except when using "global' keyword) and that the program can be loaded as a module without be ran to test the function in the python shell. is it advised to always write programs like that ? thx From nobody at nowhere.invalid Mon Sep 14 03:25:05 2015 From: nobody at nowhere.invalid (Nobody) Date: Mon, 14 Sep 2015 08:25:05 +0100 Subject: Putting the main program in a main function References: <55f673b3$0$3342$426a74cc@news.free.fr> Message-ID: On Mon, 14 Sep 2015 09:13:47 +0200, ast wrote: > is it advised to always write programs like that ? If global (module-scope) variables are initialised by main, then those variables won't exist unless main() is run, which means that you can't use it as a module, only as a script. IMHO, global variables whose initial values can be evaluated without depending upon or modifying external state should be initialised at the top level. If a module has variables which cannot be so initialised, the module needs to provide an initialisation function which must be called explicitly by any program or module which imports it. From ben+python at benfinney.id.au Mon Sep 14 03:32:01 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 14 Sep 2015 17:32:01 +1000 Subject: Putting the main program in a main function References: <55f673b3$0$3342$426a74cc@news.free.fr> Message-ID: <85r3m15udq.fsf@benfinney.id.au> "ast" writes: > The author says that with this structure there are no global variables > (except when using "global' keyword) and that the program can be > loaded as a module without be ran to test the function in the python > shell. > > is it advised to always write programs like that ? Writing all the code in functions makes your code more reliably tested: you can write a unit test that exercises the code and know whether it is behaving correctly. Writing all the code in functions makes your code more understandable: the possible interactions between different parts of the program are more explicitly and strictly defined. So yes, it's advisable to write a ?main? function for the application and keep to absolute minimum the ?if __name__ == "__main__"? block. That said, your ?main? function can be slightly more self-contained. The paradigm for invoking a command-line program is that its input parameters are the process's command-line arguments, and its return value is the process's exit status. So you can write a ?main? function that explicitly allows those input and output to be handled as for a normal function:: import sys def main(argv=None): """ Mainline code for this module. :param argv: The sequence of command-line arguments used to invoke this program. Defaults to `sys.argv`. :return: ``None``. """ if argv is None: argv = sys.argv try: handle_the_command_line(argv) do_various_things() except SystemExit as exc: exit_status = exc.code else: # No exit requested; return ?success? status. exit_status = 0 return exit_status if __name__ == "__main__": exit_status = main(sys.argv) sys.exit(exit_status) That way, the ?if __name__ == "__main__"? block will use the conventional input (command-line arguments) and output (process exit status); the rest of the application code may call ?sys.exit? or raise ?SystemExit? as normal; but your code will wrap it all up as the inputs and outputs of the ?main? function, making it much easier to control for testing. Python's BDFL wrote an article many years ago describing this pattern , mine is a small refinement of that. -- \ ?It is the fundamental duty of the citizen to resist and to | `\ restrain the violence of the state.? ?Noam Chomsky, 1971 | _o__) | Ben Finney From lac at openend.se Mon Sep 14 04:01:22 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 14 Sep 2015 10:01:22 +0200 Subject: How to set the history commands visible ? In-Reply-To: References: <201509132015.t8DKFqLG024138@fido.openend.se> Message-ID: <201509140801.t8E81MDc027041@fido.openend.se> In a message of Sun, 13 Sep 2015 23:35:01 +0200, Glus Xof writes: >If I'm not wrong, in a later interpreter versions, when an enter key was >pressed after writing something requiring some indentated statement(s)... >like in: > >>>> for i in range (0,3): > >the system used to suggest "one tab" placing the cursor automatically after. > >I don't know why this feature doesn't remain yet... or maybe I don't know >how activate this... > >Glus I think you must have had some sort of custom startup script here. Maybe even this one: https://github.com/brandoninvergo/python-startup/blob/master/python-startup.py though I found it annoying as anything as it only does the tab indent after you have started typing. If you decide to hack on custom startup scripts you may be interested in https://bitbucket.org/pypy/pyrepl PyPy needed to make a pure python replacement for readline, and did so. It has some nice support for multi-line editing and a lot of emacs style keybindings. I like it. Also, if you paste output from the interpreter into mail to other people, you should edit your python startup file to reset sys.PS1 to not be '>>>' right at the margin. (mine is ' >>>'). The arrogant idiots at Google have decided that people who ask for plain text mail (which you currently cannot do using gmail on android) in no way should be trusted to know what they are doing. Thus any text that begins with some number of '>' can be reflowed, at will, by gmail. Since you are a gmail user, you should be able to see this: >>> import sys >>> import os >>> import tkinter >>> from __future__ import print_function >>> for i in range(3): ... print (i) ... 0 1 2 Now try to reply to me, quoting this in gmail. Gmail will happily reflow the lines above. But it will respect these ones. >>> import sys >>> import os >>> import tkinter >>> from __future__ import print_function >>> for i in range(3): ... print (i) ... 0 1 2 sys.PS1 is what is giving me ' >>>' and sys.PS2 is ... If you want sys.PS2 to be a tab, then you can do this as well, but note that it does not stick a tab into your input buffer for you, so you will still need to type one -- or whatever number of spaces you use as an indent. If I have misunderstood, and your problem is that your editor no longer suggests tabs, then you have lost your python-mode settings for that editor. But we need to know what editor that is, before we can tell you how to fix it. Laura From info at egenix.com Mon Sep 14 04:24:28 2015 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Mon, 14 Sep 2015 10:24:28 +0200 Subject: ANN: eGenix mxODBC Plone/Zope Database Adapter 2.2.3 Message-ID: <55F6843C.2020301@egenix.com> ________________________________________________________________________ ANNOUNCING mxODBC Plone/Zope Database Adapter Version 2.2.3 for the Plone CMS and Zope server platform Available for Plone 4.0-4.3 and Plone 5.0, Zope 2.12 and 2.13, on Windows, Linux, Mac OS X, FreeBSD and other platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Zope-DA-2.2.3-GA.html ________________________________________________________________________ INTRODUCTION The eGenix mxODBC Zope DA allows you to easily connect your Zope or Plone CMS installation to just about any database backend on the market today, giving you the reliability of the commercially supported eGenix product mxODBC and the flexibility of the ODBC standard as middle-tier architecture. The mxODBC Zope Database Adapter is highly portable, just like Zope itself, and provides a high performance interface to all your ODBC data sources, using a single well-supported interface on Windows, Linux, Mac OS X, FreeBSD and other platforms. This makes it ideal for deployment in ZEO Clusters and Zope hosting environments where stability and high performance are a top priority, establishing an excellent basis and scalable solution for your Plone CMS. Product page: http://www.egenix.com/products/zope/mxODBCZopeDA/ ________________________________________________________________________ NEWS The 2.2.3 release of our mxODBC Zope/Plone Database Adapter product is a patch level release of the popular ODBC database interface for Plone and Zope. It includes these enhancements and fixes: Feature Updates --------------- * We have integrated a new option to force serialized connects on a per Zope connection object basis. This can be used to work around bugs in ODBC drivers which are not fully thread-safe in the connect phase. The option is disabled per default. Driver Compatibility Enhancements --------------------------------- * ODBC driver compatibility updated. Upgraded to the latest mxODBC 3.3.5 release, adding compatibility enhancements for MS SQL Server. See the mxODBC 3.3.5 release announcements for full details. Installation Enhancements ------------------------- * Added pip install compatibility to mxODBC Zope DA by creating prebuilt archives and uploading a web installer to PyPI. This can be useful if you are installing Zope or Plone using a requirements.txt type approach, e.g. using pip install ThreadLock Products.ZSQLMethods egenix-mxodbc-zopeda * Enabled creating wheels from the prebuilt archives, which helps when running pip with the wheels package installed. pip then tries to build wheels during installation and caches them for future reuse. The complete list of changes is available on the mxODBC Zope DA changelog page. http://www.egenix.com/products/zope/mxODBCZopeDA/changelog.html mxODBC Zope DA 2.2.0 was released on 2014-12-11. Please see the mxODBC Zope DA 2.2.0 release announcement for all the new features we have added. http://www.egenix.com/company/news/eGenix-mxODBC-Zope-DA-2.2.0-GA.html For the full list of features, please see the mxODBC Zope DA feature list: http://www.egenix.com/products/zope/mxODBCZopeDA/#Features The complete list of changes is available on the mxODBC Zope DA changelog page. ________________________________________________________________________ UPGRADING Users are encouraged to upgrade to this latest mxODBC Plone/Zope Database Adapter release to benefit from the new features and updated ODBC driver support. We have taken special care not to introduce backwards incompatible changes, making the upgrade experience as smooth as possible. For major and minor upgrade purchases, we will give out 20% discount coupons going from mxODBC Zope DA 1.x to 2.2 and 50% coupons for upgrades from mxODBC 2.x to 2.2. After upgrade, use of the original license from which you upgraded is no longer permitted. Patch level upgrades (e.g. 2.2.0 to 2.2.3) are always free of charge. Please contact the eGenix.com Sales Team with your existing license serials for details for an upgrade discount coupon. If you want to try the new release before purchase, you can request 30-day evaluation licenses by visiting our web-site or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. http://www.egenix.com/products/python/mxODBCZopeDA/#Evaluation ________________________________________________________________________ DOWNLOADS Please visit the eGenix mxODBC Zope DA product page for downloads, instructions on installation and documentation of the packages: http://www.egenix.com/company/products/zope/mxODBCZopeDA/ If you want to try the package, please jump straight to the download instructions: http://www.egenix.com/products/zope/mxODBCZopeDA/#Download Fully functional evaluation licenses for the mxODBC Zope DA are available free of charge: http://www.egenix.com/products/zope/mxODBCZopeDA/#Evaluation ________________________________________________________________________ SUPPORT Commercial support for this product is available directly from eGenix.com. Please see the support section of our website for details: http://www.egenix.com/services/support/ ________________________________________________________________________ MORE INFORMATION For more information on eGenix mxODBC Zope DA, licensing and download instructions, please write to sales at egenix.com. About eGenix (http://www.egenix.com/): eGenix is a software project, consulting and product company focusing on expert project services and professional quality products for companies, Python users and developers. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 14 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2015-09-18: PyCon UK 2015 ... 4 days to go 2015-10-21: Python Meeting Duesseldorf ... 37 days to go ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From rosuav at gmail.com Mon Sep 14 04:24:42 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 14 Sep 2015 18:24:42 +1000 Subject: How to set the history commands visible ? In-Reply-To: <201509140801.t8E81MDc027041@fido.openend.se> References: <201509132015.t8DKFqLG024138@fido.openend.se> <201509140801.t8E81MDc027041@fido.openend.se> Message-ID: On Mon, Sep 14, 2015 at 6:01 PM, Laura Creighton wrote: > Since you are a gmail user, you should be able to see this: > >>>> import sys >>>> import os >>>> import tkinter >>>> from __future__ import print_function >>>> for i in range(3): > ... print (i) > ... > 0 > 1 > 2 > > Now try to reply to me, quoting this in gmail. Gmail will happily reflow > the lines above. > I, too, am using Gmail, and I simply selected those lines and clicked into the Reply box. No wrapping in evidence. Is it a problem specific to the mobile app? I'm using the regular in-browser form. Or does the wrapping occur at the next stage? ChrisA From lac at openend.se Mon Sep 14 04:27:25 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 14 Sep 2015 10:27:25 +0200 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> Message-ID: <201509140827.t8E8RPqb001076@fido.openend.se> In a message of Sun, 13 Sep 2015 16:58:09 -0500, Tim Peters writes: >[Tim] >>> Whatever time zone the traveler's railroad schedule uses, so long as >>> it sticks to just one > >[Laura] >> This is what does not happen. Which is why I have written a python >> app to perform conversions for my parents, in the past. > >So how did they get the right time zone rules for Creighton? I was fortunate enough that they were never going there. But in investigating the problem I had it filed away under 'really ugly hacks I might have to write in the future'. Pre-parsing the file with special mappings for special lookups seemed the only way to fix this, at the time, but we have newer databases now than I had then ... some of which might already know about Creighton. >pytz solves it by _never_ creating a hybrid tzinfo. It only uses >eternally-fixed-offset tzinfos. For example, for a conceptual zone >with two possible total UTC offsets (one for "daylight", one for >"standard"), there two distinct eternally-fixed-offset tzinfo objects >in pytz. Then an ambiguous time is resolved by _which_ specific >tzinfo object is attached. Typically the "daylight" tzinfo for the >first time a repeated local time appears, and the "standard" tzinfo >for its second appearance. Yes. I think this is a really great idea. I have no idea why other people disagree. >In return, you have to use .localize() and .normalize() at various >times, because pytz's tzinfo objects themselves are completely blind >to the possibility of the total UTC offset changing. .localize() and >.normalize() are needed to possibly _replace_ the tzinfo object in >use, depending on the then-current date and time. Yes. >OTOH, `dateutil` does create hybrid tzinfo objects. No dances are >ever needed to possibly replace them. But it's impossible for >dateutil's tzinfos to disambiguate times in a fold. Incidentally, >dateutil also makes no attempt to account for transitions other than >DST (e.g., sometimes a zone may change its _base_ ("standard") offset >from UTC). I find this totally unacceptable. My conclusion was that hybrid tzinfo objects were a _really stupid idea_ proposed by somebody who misunderstood the problem, or rather only understood the most common case. Smack them with a dead fish, https://www.youtube.com/watch?v=i9SSOWORzw4 and get back to work. >So, yup, if you're thoroughly indoctrinated in pytz behavior, you will >be accurate but appear insane to Guido ;-) At a semantic level, a >pytz tzinfo doesn't capture the notion of a zone with offset changes - >it doesn't even try to. All knowledge about offset changes is inside >the .localize() and .normalize() dances. I can see why people would like to modify it to spit out this information when asked. I don't understand why they would like to have a hybrid tzinfo. The notion of replacing tzinfos when they become inappropriate fills their souls with revulsion, or something? But, as I said, once you know the pytz way you may be ruined for appreciating other solutions. From antoon.pardon at rece.vub.ac.be Mon Sep 14 04:30:18 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 14 Sep 2015 10:30:18 +0200 Subject: Python handles globals badly. In-Reply-To: <55f3a08d$0$1674$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F130CE.5060203@rece.vub.ac.be> <55F191CD.8040901@gmail.com> <55f3a08d$0$1674$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55F6859A.3090007@rece.vub.ac.be> Op 12-09-15 om 05:48 schreef Steven D'Aprano: > I believe I already acknowledged that assignment-as-expression was fine if > it avoided the = versus == error, from the perspective of avoiding errors. > But from the perspective of a clean and logical programming model, perhaps > not so much. Assignment is imperative, not functional, and requiring it to > return a result is somewhat unclean. I thought practicallity beats purity? AFAICS python doesn't use such a clean and logical programming model and it isn't given much critique over it. So I don't think it is fair to critique assignment as an expression because of this aspect. > Look at it this way: suppose you had a robot servant that always, without > fail or misunderstanding, did what you instructed. There are broadly two > sorts of things that you can give as instructions: questions, and commands. > Questions always require an answer: "What's the length of this list?" is > functional. Commands are imperative, not functional, and don't necessarily > require an answer: "Move the small red pyramid onto the large green cube." > Some commands arguable might require an answer, but arguable they are > better served by an out-of-band error condition (an exception). *Requiring* > all commands to give an answer is silly, given that the robot servant is > infallible. But we are not talking about all commands, we are just talking about assignments. Sure an assignment has a side effect. But so has ls.pop(). So something having a side-effect and a value is not unheard of even within a python context. -- Antoon Pardon From katewinslet626 at gmail.com Mon Sep 14 04:44:09 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Mon, 14 Sep 2015 01:44:09 -0700 (PDT) Subject: Selenium Message-ID: <25ec8a9e-e5e1-49df-adf7-e6789e500d77@googlegroups.com> I wrote this code in python for submitting a login form: from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get('some url') elem = driver.find_element_by_name("username") elem.send_keys('13103666') elem = driver.find_element_by_name("password") elem.send_keys('as') driver.find_element_by_name("btnSubmit").click() #nothing happens from here print driver.page_source print "test" After clicking on submit button, a message is displayed on the same page whether login was successful or not. However after clicking on submit button, I lose control over the web page. I can't use any selenium functions now like 'driver.find_element_by_name()'. Initially everything works fine. I can enter username and password using selenium as written in my code, but once I click on submit button or press return key(tried both using selenium), any script written after that(involving web driver) doesnt seem to work. Even driver.close() doesnt work. This is the form I am trying to submit:
The submission is successful, however after submission I cant verify if login was successful or not because of the issue I posted above. Do I need to switch web handle? If, then how. Any help will be highly appreciated. From lac at openend.se Mon Sep 14 04:53:09 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 14 Sep 2015 10:53:09 +0200 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> Message-ID: <201509140853.t8E8r99u007805@fido.openend.se> In a message of Sun, 13 Sep 2015 15:21:45 -0700, Guido van Rossum writes: >Hi Laura! > >Wouldn't it be sufficient for people in Creighton to set their timezone to >US/Central? IIUC the Canadian DST rules are the same as the US ones. Now, >the question may remain how do people know what to set their timezone to. >But neither pytz nor datetime can help with that -- it is up to the >sysadmin. The Canadian DST rules are not the same as the US ones, wherein lies the rub. The province of Saskatchewan has a few areas which prefer to be on Mountain time, which we will ignore in this mail. The bulk of them prefer to be on Central time, which is the same as Winnipeg and Chicago. But what happens on DST start day (early March) in Saskachewan? Provincial law mandates that you do not change your clock, and do not adopt daylight savings time. The people in Saskachewan thus stick to CST all year round. And this is how sites like http://www.timeanddate.com/worldclock/canada/saskatoon record things, with them at CST. However, the people of Creighton have decided to keep DST, in violation of the law, so they set their clocks forward. http://www.timeanddate.com/worldclock/canada/creighton does this properly as well, showing them with CDT. But this is not quite the complete story. In many (most?) places in Saskatchewan, the rule is understood differently. Instead of 'we keep to CST all year long' is is understood that 'we keep central time in the winter and mountain time in the summer'. This makes parsing log files from all over Saskachewan, where sometime in March things often stop saying CST and say MDT instead rather more interesting than the adverage person might suspect. Laura From lac at openend.se Mon Sep 14 05:22:35 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 14 Sep 2015 11:22:35 +0200 Subject: Can't use Python Launcher on Windows after update to 3.5 In-Reply-To: References: <55F15981.8030804@timgolden.me.uk> Message-ID: <201509140922.t8E9MZQY015225@fido.openend.se> In a message of Sun, 13 Sep 2015 23:46:37 +0100, Mark Lawrence writes: >Exactly the same thing happened when I upgraded to 3.5.0. so raised >http://bugs.python.org/issue25089 just in case it hurts other people >more than it hurts me. > >-- >My fellow Pythonistas, ask not what our language can do for you, ask >what you can do for our language. > >Mark Lawrence Thank you. Laura From lac at openend.se Mon Sep 14 05:55:52 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 14 Sep 2015 11:55:52 +0200 Subject: How to set the history commands visible ? In-Reply-To: References: <201509132015.t8DKFqLG024138@fido.openend.se> <201509140801.t8E81MDc027041@fido.openend.se> Message-ID: <201509140955.t8E9tqP7024336@fido.openend.se> In a message of Mon, 14 Sep 2015 18:24:42 +1000, Chris Angelico writes: >On Mon, Sep 14, 2015 at 6:01 PM, Laura Creighton wrote: >> Since you are a gmail user, you should be able to see this: >> >>>>> import sys >>>>> import os >>>>> import tkinter >>>>> from __future__ import print_function >>>>> for i in range(3): >> ... print (i) >> ... >> 0 >> 1 >> 2 >> >> Now try to reply to me, quoting this in gmail. Gmail will happily reflow >> the lines above. >> > >I, too, am using Gmail, and I simply selected those lines and clicked >into the Reply box. No wrapping in evidence. Is it a problem specific >to the mobile app? I'm using the regular in-browser form. > >Or does the wrapping occur at the next stage? > >ChrisA It definitely was with replying to me with the regular, not browser app. I will be overjoyed to hear that gmail respects text-only Thread stats here: https://mail.python.org/pipermail/python-list/2015-July/694572.html On the other hand, it may be related to one particular gmail user's emacs settings: https://mail.python.org/pipermail/python-list/2015-July/694657.html except that I got the same behaviour from a different user, I forget whom I asked to check this. Clearly wasn't you ... This may be a case of 'how pleasant to be wrong' ... Laura From oscar.j.benjamin at gmail.com Mon Sep 14 06:47:02 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 14 Sep 2015 11:47:02 +0100 Subject: How to set the history commands visible ? In-Reply-To: References: <201509132015.t8DKFqLG024138@fido.openend.se> <201509140801.t8E81MDc027041@fido.openend.se> Message-ID: On 14 September 2015 at 09:24, Chris Angelico wrote: > On Mon, Sep 14, 2015 at 6:01 PM, Laura Creighton wrote: >> Since you are a gmail user, you should be able to see this: >> >>>>> import sys >>>>> import os >>>>> import tkinter >>>>> from __future__ import print_function >>>>> for i in range(3): >> ... print (i) >> ... >> 0 >> 1 >> 2 >> >> Now try to reply to me, quoting this in gmail. Gmail will happily reflow >> the lines above. >> > > I, too, am using Gmail, and I simply selected those lines and clicked > into the Reply box. I've also just done the same but this is only possible if you've enabled the "quote selected text" extension from the labs part of your gmail settings. Perhaps it works differently if you just reply to the whole thing... > No wrapping in evidence. There's no wrapping but now that Laura's repl session has two extra > characters it looks like a mix of text at 5 and 2 level quoting depth. This is why I would put spaces at the start of those lines. Not just gmail but other mail clients will confuse this with different levels of quoted text and it gets harder to read than it would if it were indented. > Is it a problem specific > to the mobile app? I'm using the regular in-browser form. A further confounding point is google's new "inbox" which is a different interface to a gmail account. It has a number of features that actually make it useful for _reading_ mailing lists but it's not very good for replying: no plain text mode, top-post by default (without even showing the ... to represent the quoted text - pop-out reply to see that) and it quotes using a vertical line rather than > characters and so on. From the mailing list end I'm not sure if it's possible to tell whether someone has sent their reply from regular gmail (like this one) or from inbox. -- Oscar From hakugin.gin at gmail.com Mon Sep 14 08:53:32 2015 From: hakugin.gin at gmail.com (hakugin.gin at gmail.com) Date: Mon, 14 Sep 2015 05:53:32 -0700 (PDT) Subject: RPI.GPIO Help In-Reply-To: References: Message-ID: On Sunday, September 13, 2015 at 2:09:11 AM UTC-4, John McKenzie wrote: > Hello, there. > > Hakugin, thank you you as well. I took the basic ideas you showed me for > improvement and used them. The pulse settings variable was not liked by > the interpreter, so I simplified it. I turned it into a hex value for > each button press, then in the main loop I inserted the whole line for > the LED pulse command, but put "pulse_settings" after "hex=" in the > arguments. This worked. > I realized the error with my example after I got home and forgot to update it. The issue was with: (red=255, green=0, blue=0, repeats=1, duration=2000, steps=50) I had copied and pasted that and should have removed the "red=", "green=", etc. I'm glad you were able to work it out. > I added a few green blinks of the LED to indicate the starting and > stopping of the script. Also, I got the log files score print outs upon > exit working. Very important, and also importantly, I have it so it stops > after a certain amount of time. For testing, I have it at 60 seconds, but > games will be 3600 seconds on average when really being used. > > The stopping after a certain amount of time was done in a way that > apparently technically works, but seems very weird and probably wrong to > me. You may freak out when you see it. I used an else statement inside a > while loop and it just feels so strange. At least it works. > > Hoping I might be able to make it so I boot the Pi, it loads the script, > script waits for the user to tell it how long to make a game, game > starts, scripts ends game at appropriate time, saves dated log file with > scores, then waits for user to enter new game length to start new game. > This is probably way to much to hope to accomplish in time. For next year > for sure though. It would be better for the referees to operate that way. > Having the game load when the Pi starts is fairly easy, but I'd recommend searching the official Raspberry Pi forums. Last time I was there I saw quite a few posts on various ways to accomplish this. As for allowing someone to enter a game time limit you can change your "gamelength" variable assignment to something along the lines of: gamelength = None while not isinstance(gamelength, int): gamelength = raw_input("Please enter a game time limit:\n") try: gamelength = int(gamelength) # Converts to integer except: print("Invalid entry. Time limit must be a number.\n") pass # ignore error and allow the loop to start over I was able to test this code, and you will want to add it before your main game loop. > Next I will try and integrate wireless communications. If anyone here > knows Synapse RF modules well, or at all, PLEASE contact me. > > > Here is the code I did up most recently. Again, thanks for all the > suggestions, code examples, and general help. > > > while time.time() < gamestart + gamelength: > This is actually how I personally would have accomplished the task of having it end at a specific time. There may be other ways though. From random832 at fastmail.com Mon Sep 14 09:30:43 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 09:30:43 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <201509140827.t8E8RPqb001076@fido.openend.se> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> Message-ID: <1442237443.176050.383098065.12F20DB7@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 04:27, Laura Creighton wrote: > I find this totally unacceptable. My conclusion was that hybrid tzinfo > objects were a _really stupid idea_ proposed by somebody who > misunderstood > the problem, or rather only understood the most common case. "Hybrid tzinfo objects" _in isolation_ are not bad. The problem isn't the objects themselves, it's the whole design: 1. Hybrid tzinfo objects 2. Attached tzinfo object as the _only_ way to identify the timezone of a datetime (no offset member) 3. Datetime itself stored in local time. There's a reason that other languages store the offset explicitly - because it causes the datetime+offset object to uniquely identify a specific moment in time, and _without_ having to call in to any complex logic [i.e. the tzinfo object's utcoffset method]. Normalizing the results of "classic arithmetic" could (and should) be solved by providing a hook that calls a method on the tzinfo object to find the new offset for the result of the operation. A "hybrid tzinfo object" is itself, in principle, exactly the same kind of thing that, in C, is returned by tzalloc and used by localtime_rz, on systems that have those functions. The difference is, this object is explicitly managed rather than being "attached" to struct tm objects. From 4kir4.1i at gmail.com Mon Sep 14 10:48:36 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 14 Sep 2015 17:48:36 +0300 Subject: Terminology: "reference" versus "pointer" References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> Message-ID: <874mix5a63.fsf@gmail.com> Random832 writes: ... > Why can't it describe range(1)? A range object in my model would include > the start, stop, and step; _not_ the contents of what you would get by > iterating over it; since that's not part of the physical structure of > the object, but the consequences of calling methods on it. start, stop, step attributes (corresponding Python ints) may not exist ("the objects we've talking about have never been created") until you request them explicitly. I've mentioned it in another message but to be clear, I consider "parcel tags" [1] and "box and arrows" [2] (boxes are always empty, they only point to objects) models to be the same and different from "labelled box" [3] model (boxes contain objects). [1] http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#python-has-names [2] http://www.pythontutor.com/visualize.html#code=a0+%3D+a1+%3D+%5B1,+2%5D%0Ab0+%3D+%5B1,+2%5D%0Ab1+%3D+%5B1,+2%5D%0Aa+%3D+%5Ba0,+a1%5D%0Ab+%3D+%5Bb0,+b1%5D%0Adel+a0,+a1,+b0,+b1%0A&mode=display&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&textReferences=false&py=3&rawInputLstJSON=%5B%5D&curInstr=6 [3] http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables From random832 at fastmail.com Mon Sep 14 11:10:11 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 11:10:11 -0400 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <874mix5a63.fsf@gmail.com> References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> Message-ID: <1442243411.198925.383193481.6164EF4E@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 10:48, Akira Li wrote: > start, stop, step attributes (corresponding Python ints) may not exist > ("the objects we've talking about have never been created") until you > request them explicitly. That's not true in CPython. In fact, the range object in python contains *four* reference boxes - one more for length. > I've mentioned it in another message but to be clear, I consider "parcel > tags" [1] and "box and arrows" [2] (boxes are always empty, they only > point to objects) models to be the same and different from "labelled > box" [3] model (boxes contain objects). See, I consider the box and arrow to be the same as the labeled box model - only the object the boxes contain is an arrow. Except for special kinds of boxes implemented in some other language, such as the elements of an array from the array module The problem with "parcel tags" is that it represents namespaces - or one particular namespace, I've never seen any version of it that even clearly talks about locals, let alone different modules - differently from other kinds of objects. From robin at reportlab.com Mon Sep 14 11:52:51 2015 From: robin at reportlab.com (Robin Becker) Date: Mon, 14 Sep 2015 16:52:51 +0100 Subject: how to build windows extensions for python 3.5 Message-ID: <55F6ED53.9080103@chamonix.reportlab.co.uk> I understand there have been changes to the way that extensions are supposed to be built for windows. Is there any user documentation regarding these changes? Last time I looked the appropriate Visual Studio hadn't been release so I guess I will need to use my MSDN skills (or incantations) to first get that installed. -- Robin Becker From zachary.ware+pylist at gmail.com Mon Sep 14 11:58:57 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 14 Sep 2015 10:58:57 -0500 Subject: how to build windows extensions for python 3.5 In-Reply-To: <55F6ED53.9080103@chamonix.reportlab.co.uk> References: <55F6ED53.9080103@chamonix.reportlab.co.uk> Message-ID: On Mon, Sep 14, 2015 at 10:52 AM, Robin Becker wrote: > I understand there have been changes to the way that extensions are supposed > to be built for windows. Is there any user documentation regarding these > changes? Last time I looked the appropriate Visual Studio hadn't been > release so I guess I will need to use my MSDN skills (or incantations) to > first get that installed. Visual Studio 2015 has been released for about 7 weeks now. Community Edition (the free one) should be plenty to compile Python extensions in either 32 or 64 bit. In general, if you build your extensions using distutils, it should still 'just work', but some truly exotic situations may be different (or broken, in which case please file bugs!). Unfortunately I don't have any kind of documentation quick to hand for this. -- Zach From breamoreboy at yahoo.co.uk Mon Sep 14 12:26:06 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 14 Sep 2015 17:26:06 +0100 Subject: how to build windows extensions for python 3.5 In-Reply-To: <55F6ED53.9080103@chamonix.reportlab.co.uk> References: <55F6ED53.9080103@chamonix.reportlab.co.uk> Message-ID: On 14/09/2015 16:52, Robin Becker wrote: > I understand there have been changes to the way that extensions are > supposed to be built for windows. Is there any user documentation > regarding these changes? Last time I looked the appropriate Visual > Studio hadn't been release so I guess I will need to use my MSDN skills > (or incantations) to first get that installed. http://stevedower.id.au/blog/building-for-python-3-5-part-two/ The most important thing is to have something to do while the Visual Studio installation takes up 8G of your disk space and several hours of elapsed time. At least the installation went smoothly. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From lac at openend.se Mon Sep 14 12:59:27 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 14 Sep 2015 18:59:27 +0200 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442237443.176050.383098065.12F20DB7@webmail.messagingengine.com> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@! fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442237443.176050.383098065.12F20DB7@webmail.messagingengine.com> Message-ID: <201509141659.t8EGxRZA002402@fido.openend.se> In a message of Mon, 14 Sep 2015 09:30:43 -0400, Random832 writes: >On Mon, Sep 14, 2015, at 04:27, Laura Creighton wrote: >> I find this totally unacceptable. My conclusion was that hybrid tzinfo >> objects were a _really stupid idea_ proposed by somebody who >> misunderstood >> the problem, or rather only understood the most common case. > >"Hybrid tzinfo objects" _in isolation_ are not bad. The problem isn't >the objects themselves, it's the whole design: > >1. Hybrid tzinfo objects >2. Attached tzinfo object as the _only_ way to identify the timezone of >a datetime (no offset member) >3. Datetime itself stored in local time. Ah, thank you for explaining. I thought the only reason you would want a hybrid tzinfo number is that you absolutely did not want an offset number. Which is the part I found, ah, nutty. I see now that it doesn't have to be this way. Laura From steve at pearwood.info Mon Sep 14 12:59:36 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 15 Sep 2015 02:59:36 +1000 Subject: Terminology: "reference" versus "pointer" References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <55f61e8c$0$1660$c3e8da3$5496439d@news.astraweb.com> <55f6333c$0$1636$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f6fcf7$0$1640$c3e8da3$5496439d@news.astraweb.com> On Mon, 14 Sep 2015 01:23 pm, Akira Li wrote: > Steven D'Aprano writes: > >> On Mon, 14 Sep 2015 11:22 am, Akira Li wrote: >>> Look at the last example: >>> http://thread.gmane.org/gmane.comp.python.general/782626/focus=782704 >> >> >> I'm afraid that page is broken in my browser. Can you not summarise, or >> link to the specific message? I may be able to use another browser in a >> day or two, but hopefully the discussion will have moved on by then. > > https://mail.python.org/pipermail/python-list/2015-September/696631.html Thanks. You mean this example? lst = [range(1, 3) for _ in range(3)] a = [lst[0], lst[0]] b = [lst[1], lst[2]] I don't see what's difficult about this example. Here's a simple ASCII drawing: lst --------> [ range-object-1 , range-object-2 , range-object-3 ] a ----------> [ range-object-1 , range-object-1 ] b ----------> [ range-object-2 , range-object-3 ] Trying to draw an arrow diagram using text is not my idea of a good time, but I'll give it a go. Requires a monospaced font and an email client that won't reflow the text: +-----+------+ | | | <--------------------------- a +--|--+---|--+ | | | | V | +-----+ <-+ +----+ |range| <---------------|- |<------------ lst +-----+ +----+ +-----------|- | +-----+ | +----+ +-> |range| <---+ +------|- | | +-----+ | +----+ | | | +-----+ | | |range| <--------+ | +-----+ | ^ +-|-+ | | | | +---+ | | -|----+ +---+ ^ | +------------------------------------------- b Out of the two, I know which one I prefer. -- Steven From steve at pearwood.info Mon Sep 14 13:03:22 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 15 Sep 2015 03:03:22 +1000 Subject: Terminology: "reference" versus "pointer" References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> Message-ID: <55f6fdd9$0$1640$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Sep 2015 01:10 am, Random832 wrote: > On Mon, Sep 14, 2015, at 10:48, Akira Li wrote: >> start, stop, step attributes (corresponding Python ints) may not exist >> ("the objects we've talking about have never been created") until you >> request them explicitly. > > That's not true in CPython. In fact, the range object in python contains > *four* reference boxes - one more for length. I really don't see why any of this is relevant to the business being discussed. A range object is an object. It has an interface, e.g. it is sized (has a length), it has start, stop and step attributes. But the *implementation* of that interface is (1) irrelevant and (2) subject to change. Maybe the __len__ method calculates the length on the fly. Maybe start, stop and step are virtual attributes that extract the appropriate values from a C-level datastructure inaccessible to pure Python code. Unless you are the author of the range class, you don't really have any business worrying about whether range.start is a "reference" to the start value, or something computed on the fly as needed. It could be either. -- Steven From 4kir4.1i at gmail.com Mon Sep 14 13:24:32 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 14 Sep 2015 20:24:32 +0300 Subject: Terminology: "reference" versus "pointer" References: <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <55f61e8c$0$1660$c3e8da3$5496439d@news.astraweb.com> <55f6333c$0$1636$c3e8da3$5496439d@news.astraweb.com> <55f6fcf7$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wpvs52y7.fsf@gmail.com> Steven D'Aprano writes: > On Mon, 14 Sep 2015 01:23 pm, Akira Li wrote: > >> Steven D'Aprano writes: >> >>> On Mon, 14 Sep 2015 11:22 am, Akira Li wrote: >>>> Look at the last example: >>>> http://thread.gmane.org/gmane.comp.python.general/782626/focus=782704 >>> >>> >>> I'm afraid that page is broken in my browser. Can you not summarise, or >>> link to the specific message? I may be able to use another browser in a >>> day or two, but hopefully the discussion will have moved on by then. >> >> https://mail.python.org/pipermail/python-list/2015-September/696631.html > > Thanks. You mean this example? > > lst = [range(1, 3) for _ in range(3)] > a = [lst[0], lst[0]] > b = [lst[1], lst[2]] > > > I don't see what's difficult about this example. Here's a simple ASCII > drawing: > > > lst --------> [ range-object-1 , range-object-2 , range-object-3 ] > > a ----------> [ range-object-1 , range-object-1 ] > > b ----------> [ range-object-2 , range-object-3 ] > I should have mentioned that lst plays the role of range-object-X in your diagram i.e., only *a*, *b* names actualy exits (I should add `del lst` to the example) -- as the original example requires. > Trying to draw an arrow diagram using text is not my idea of a good time, > but I'll give it a go. Requires a monospaced font and an email client that > won't reflow the text: > > +-----+------+ > | | | <--------------------------- a > +--|--+---|--+ > | | > | | > V | > +-----+ <-+ +----+ > |range| <---------------|- |<------------ lst > +-----+ +----+ > +-----------|- | > +-----+ | +----+ > +-> |range| <---+ +------|- | > | +-----+ | +----+ > | | > | +-----+ | > | |range| <--------+ > | +-----+ > | ^ > +-|-+ | > | | | > +---+ | > | -|----+ > +---+ > ^ > | > +------------------------------------------- b > > > Out of the two, I know which one I prefer. I don't know what it means. If you mean "box and arrows" is superior somehow then I don't see any difference from the "parcel tags" model here. My point is that neither models are detailed enough to describe meaningfully the behavior of Python code in the general case. From random832 at fastmail.com Mon Sep 14 13:34:53 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 13:34:53 -0400 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <55f6fdd9$0$1640$c3e8da3$5496439d@news.astraweb.com> References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <55f6fdd9$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1442252093.231783.383350001.6CF3FF6F@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 13:03, Steven D'Aprano wrote: > On Tue, 15 Sep 2015 01:10 am, Random832 wrote: > > That's not true in CPython. In fact, the range object in python contains > > *four* reference boxes - one more for length. > > I really don't see why any of this is relevant to the business being > discussed. When you're drawing this sort of diagram then what references are held by an object are more important than what interfaces it implements. Personally I think it's a bit silly to insist on a diagram model where a box with an arrow in it pointing at an int object can't be represented by a box with an integer in it (where 'int' is any immutable type - string, tuple, even range), but people don't like boxes with integers in them for some reason. From 4kir4.1i at gmail.com Mon Sep 14 13:45:22 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 14 Sep 2015 20:45:22 +0300 Subject: Terminology: "reference" versus "pointer" References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <1442243411.198925.383193481.6164EF4E@webmail.messagingengine.com> Message-ID: <87vbbc51zh.fsf@gmail.com> Random832 writes: > On Mon, Sep 14, 2015, at 10:48, Akira Li wrote: >> start, stop, step attributes (corresponding Python ints) may not exist >> ("the objects we've talking about have never been created") until you >> request them explicitly. > > That's not true in CPython. In fact, the range object in python contains > *four* reference boxes - one more for length. Even if it true in CPython. Specific implementations are irrelevant for the discussions. Python -- the language -- does not mandate any reference boxes (and given how you interpret the term "box" -- boxes are not used anywhere). >> I've mentioned it in another message but to be clear, I consider "parcel >> tags" [1] and "box and arrows" [2] (boxes are always empty, they only >> point to objects) models to be the same and different from "labelled >> box" [3] model (boxes contain objects). > > See, I consider the box and arrow to be the same as the labeled box > model - only the object the boxes contain is an arrow. Except for > special kinds of boxes implemented in some other language, such as the > elements of an array from the array module [box + arrow pointing to] + object == parcel tag + object I could draw a picture but it won't be pretty. "labelled box" model that assumes that objects are inside boxes is clearly wrong -- it fails if you have two names that refer to the same object in Python (you can't put the same object into different boxes). If a box contains nothing then there is no need for the box. If you think the box contains "something" then find me the corresponding term in Python language reference. I don't understand what is "arrow" that the box might contain exactly. For example I can find what "name", "object" mean in Python. > The problem with "parcel tags" is that it represents namespaces - or one > particular namespace, I've never seen any version of it that even > clearly talks about locals, let alone different modules - differently > from other kinds of objects. I don't understand what are you trying to say here. If you have a specific example when the "parcel tags" [1] model predicts a _wrong_ behavior; please do provide it. If your point is that "parcel tag" does not describe in full detail all aspect of the behavior of an arbitrary Python code then I agree with you (though none of the discussed models can or should do it). From emile at fenx.com Mon Sep 14 13:51:50 2015 From: emile at fenx.com (Emile van Sebille) Date: Mon, 14 Sep 2015 10:51:50 -0700 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <1442252093.231783.383350001.6CF3FF6F@webmail.messagingengine.com> References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <55f6fdd9$0$1640$c3e8da3$5496439d@news.astraweb.com> <1442252093.231783.383350001.6CF3FF6F@webmail.messagingengine.com> Message-ID: On 9/14/2015 10:34 AM, Random832 wrote: > Personally I think it's a bit silly to insist on a diagram model where a > box with an arrow in it pointing at an int object can't be represented > by a box with an integer in it (where 'int' is any immutable type - > string, tuple, even range), but people don't like boxes with integers in > them for some reason. Actually, boxes with integers in them isn't the appropriate analogy. Consider the naming of cats. My cat is known to me as Paddy. My next door neighbor sometimes feeds her and is known to her as Stripes. The cat also is known as kitty to my youngest daughter. The cat has no idea what its name is, it just is and eats. So three labels, one object. Putting the object in three boxes isn't right -- how could you know (other than checking the id()) that they're the same? Shroedingers-cat-was-just-a-cat-in-a-box-too-ly y'rs, Emile From kevin.p.dwyer at gmail.com Mon Sep 14 13:55:59 2015 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Mon, 14 Sep 2015 18:55:59 +0100 Subject: Cannot create a virtualenv References: Message-ID: paul.hermeneutic at gmail.com wrote: > - I downloaded and installed Python 3.5 64-bit onto a Windows 7 64-bit > machine. - Using `pip install virtualenv` worked fine. > - Now, it is time to create a virtualenv, but it is not working fine. > - I had to add Python 3.5 to the PATH. > - Any suggestions? > > C:\ve>virtualenv -p "\Program Files\Python 3.5\python.exe" ve33 > Running virtualenv with interpreter C:\Program Files\Python 3.5\python.exe > Using base prefix 'C:\\Program Files\\Python 3.5' > New python executable in ve33\Scripts\python.exe > Installing setuptools, pip, wheel... > Complete output from command C:\ve\ve33\Scripts\python.exe -c > "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel: > Ignoring indexes: https://pypi.python.org/simple > Collecting setuptools > The repository located at None is not a trusted or secure host and > is being ignored. If this repository is available via HTTPS it is > recommended to use HTTPS instead, otherwis > e you may silence this warning and allow it anyways with '--trusted-host > None'. > The repository located at None is not a trusted or secure host and > is being ignored. If this repository is available via HTTPS it is > recommended to use HTTPS instead, otherwis > e you may silence this warning and allow it anyways with '--trusted-host > None'. > The repository located at None is not a trusted or secure host and > is being ignored. If this repository is available via HTTPS it is > recommended to use HTTPS instead, otherwis > e you may silence this warning and allow it anyways with '--trusted-host > None'. > The repository located at None is not a trusted or secure host and > is being ignored. If this repository is available via HTTPS it is > recommended to use HTTPS instead, otherwis > e you may silence this warning and allow it anyways with '--trusted-host > None'. > The repository located at None is not a trusted or secure host and > is being ignored. If this repository is available via HTTPS it is > recommended to use HTTPS instead, otherwis > e you may silence this warning and allow it anyways with '--trusted-host > None'. > The repository located at None is not a trusted or secure host and > is being ignored. If this repository is available via HTTPS it is > recommended to use HTTPS instead, otherwis > e you may silence this warning and allow it anyways with '--trusted-host > None'. > The repository located at None is not a trusted or secure host and > is being ignored. If this repository is available via HTTPS it is > recommended to use HTTPS instead, otherwis > e you may silence this warning and allow it anyways with '--trusted-host > None'. > The repository located at None is not a trusted or secure host and > is being ignored. If this repository is available via HTTPS it is > recommended to use HTTPS instead, otherwis > e you may silence this warning and allow it anyways with '--trusted-host > None'. > The repository located at None is not a trusted or secure host and > is being ignored. If this repository is available via HTTPS it is > recommended to use HTTPS instead, otherwis > e you may silence this warning and allow it anyways with '--trusted-host > None'. > Could not find a version that satisfies the requirement setuptools > (from versions: ) > No matching distribution found for setuptools > ---------------------------------------- > ...Installing setuptools, pip, wheel...done. > Traceback (most recent call last): > File "c:\program files\python 3.5\lib\site-packages\virtualenv.py", > line 2363, in > main() > File "c:\program files\python 3.5\lib\site-packages\virtualenv.py", > line 832, in main > symlink=options.symlink) > File "c:\program files\python 3.5\lib\site-packages\virtualenv.py", > line 1004, in create_environment > install_wheel(to_install, py_executable, search_dirs) > File "c:\program files\python 3.5\lib\site-packages\virtualenv.py", > line 969, in install_wheel > 'PIP_NO_INDEX': '1' > File "c:\program files\python 3.5\lib\site-packages\virtualenv.py", > line 910, in call_subprocess > % (cmd_desc, proc.returncode)) > OSError: Command C:\ve\ve33\Scripts\python.exe -c "import sys, pip; > sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error > code 1 Have you tried using the venv module? https://docs.python.org/3/library/venv.html From rosuav at gmail.com Mon Sep 14 13:59:08 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Sep 2015 03:59:08 +1000 Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <55f6fdd9$0$1640$c3e8da3$5496439d@news.astraweb.com> <1442252093.231783.383350001.6CF3FF6F@webmail.messagingengine.com> Message-ID: On Tue, Sep 15, 2015 at 3:51 AM, Emile van Sebille wrote: > Actually, boxes with integers in them isn't the appropriate analogy. > Consider the naming of cats. My cat is known to me as Paddy. My next door > neighbor sometimes feeds her and is known to her as Stripes. The cat also > is known as kitty to my youngest daughter. The cat has no idea what its > name is, it just is and eats. Thanks for that. As someone who shares a house with a cat (not my own), I find this apt and amusing. :) ChrisA From random832 at fastmail.com Mon Sep 14 14:00:30 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 14:00:30 -0400 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <87vbbc51zh.fsf@gmail.com> References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <1442243411.198925.383193481.6164EF4E@webmail.messagingengine.com> <87vbbc51zh.fsf@gmail.com> Message-ID: <1442253630.238013.383375545.5EF03093@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 13:45, Akira Li wrote: > [box + arrow pointing to] + object == parcel tag + object The problem is that if there are multiple namespaces, or if you've also got to include references from within other objects such as list, then you've got to write all that somehow on the parcel tag, instead of just having different places the arrows can start from. The box and arrow model easily extends to this, and the fact that no-one can make up their mind on what to *call* the thing the arrows represent doesn't mean they don't exist. From random832 at fastmail.com Mon Sep 14 14:02:00 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 14:02:00 -0400 Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <55f6fdd9$0$1640$c3e8da3$5496439d@news.astraweb.com> <1442252093.231783.383350001.6CF3FF6F@webmail.messagingengine.com> Message-ID: <1442253720.238284.383377753.74AED02F@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 13:51, Emile van Sebille wrote: > Actually, boxes with integers in them isn't the appropriate analogy. > Consider the naming of cats. My cat is known to me as Paddy. My next > door neighbor sometimes feeds her and is known to her as Stripes. The > cat also is known as kitty to my youngest daughter. The cat has no idea > what its name is, it just is and eats. So three labels, one object. > Putting the object in three boxes isn't right The point is that with immutable objects no-one cares if they are three objects with the same value, or three references to the same object. Your cat is not an integer. From ian.g.kelly at gmail.com Mon Sep 14 14:16:02 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 14 Sep 2015 12:16:02 -0600 Subject: How to set the history commands visible ? In-Reply-To: <201509140955.t8E9tqP7024336@fido.openend.se> References: <201509132015.t8DKFqLG024138@fido.openend.se> <201509140801.t8E81MDc027041@fido.openend.se> <201509140955.t8E9tqP7024336@fido.openend.se> Message-ID: On Mon, Sep 14, 2015 at 3:55 AM, Laura Creighton wrote: > It definitely was with replying to me with the regular, not browser > app. I will be overjoyed to hear that gmail respects text-only > > Thread stats here: > https://mail.python.org/pipermail/python-list/2015-July/694572.html > > On the other hand, it may be related to one particular gmail user's > emacs settings: > https://mail.python.org/pipermail/python-list/2015-July/694657.html > > except that I got the same behaviour from a different user, I forget > whom I asked to check this. Clearly wasn't you ... > > This may be a case of 'how pleasant to be wrong' ... I remember that thread, and as I recall the user was apparently using Emacs Gnus to post to Gmane. Gmail was not involved at all. From 4kir4.1i at gmail.com Mon Sep 14 14:17:56 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 14 Sep 2015 21:17:56 +0300 Subject: Terminology: "reference" versus "pointer" References: <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <1442243411.198925.383193481.6164EF4E@webmail.messagingengine.com> <87vbbc51zh.fsf@gmail.com> <1442253630.238013.383375545.5EF03093@webmail.messagingengine.com> Message-ID: <87r3m050h7.fsf@gmail.com> Random832 writes: > On Mon, Sep 14, 2015, at 13:45, Akira Li wrote: >> [box + arrow pointing to] + object == parcel tag + object > > The problem is that if there are multiple namespaces, or if you've also > got to include references from within other objects such as list, then > you've got to write all that somehow on the parcel tag, instead of just > having different places the arrows can start from. > > The box and arrow model easily extends to this, and the fact that no-one > can make up their mind on what to *call* the thing the arrows represent > doesn't mean they don't exist. box has arrow, parcel tag has string/thread. We could attach an arrow instead of a string to the parcel tag. The box does not contain anything inside (we can attach the arrow outside the box -- nothing changes). If the box does not contain anything then we could use a parcel tag instead. From ned at nedbatchelder.com Mon Sep 14 14:29:02 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 14 Sep 2015 11:29:02 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <55f61e8c$0$1660$c3e8da3$5496439d@news.astraweb.com> <55f6333c$0$1636$c3e8da3$5496439d@news.astraweb.com> <55f6fcf7$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4e340057-3a72-405f-82ef-51f865a97a18@googlegroups.com> On Monday, September 14, 2015 at 1:26:39 PM UTC-4, Akira Li wrote: > My point is that neither models are detailed enough to describe > meaningfully the behavior of Python code in the general case. This is of course true, because a model is never detailed enough to fully describe the real thing. I'm curious what aspect of the example here isn't meaningfully described by the boxes and arrows notation? It seems to me that usually the problem is that the diagram is simplified at a certain level of detail. For example, the range objects here are presented as atomic, without revealing that they hold references to other objects. What do you feel is missing from Steven's diagram? --Ned. From tim.peters at gmail.com Mon Sep 14 14:53:33 2015 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 14 Sep 2015 13:53:33 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <201509140827.t8E8RPqb001076@fido.openend.se> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> Message-ID: [Tim] >> pytz solves it by _never_ creating a hybrid tzinfo. It only uses >> eternally-fixed-offset tzinfos. For example, for a conceptual zone >> with two possible total UTC offsets (one for "daylight", one for >> "standard"), there two distinct eternally-fixed-offset tzinfo objects >> in pytz. Then an ambiguous time is resolved by _which_ specific >> tzinfo object is attached. Typically the "daylight" tzinfo for the >> first time a repeated local time appears, and the "standard" tzinfo >> for its second appearance [Laura Creighton ] > Yes. I think this is a really great idea. I have no idea why other > people disagree. Really? >> In return, you have to use .localize() and .normalize() at various >> times, because pytz's tzinfo objects themselves are completely blind >> to the possibility of the total UTC offset changing. .localize() and >> .normalize() are needed to possibly _replace_ the tzinfo object in >> use, depending on the then-current date and time. > Yes. >>OTOH, `dateutil` does create hybrid tzinfo objects. No dances are >>ever needed to possibly replace them. But it's impossible for >>dateutil's tzinfos to disambiguate times in a fold. Incidentally, >>dateutil also makes no attempt to account for transitions other than >>DST (e.g., sometimes a zone may change its _base_ ("standard") offset >>from UTC). > I find this totally unacceptable. The precise referent for "this" isn't clear to me. The lack of knowledge of base-offset transitions is a property of dateutil's implementation, due to inheriting the default .fromutc() instead of implementing its own to take advantage of all the transition info a tzfile records. It's not _inherent_ to hybrid tzinfos. Just an omission in this specific zoneinfo wrapping. > My conclusion was that hybrid tzinfo > objects were a _really stupid idea_ proposed by somebody who misunderstood > the problem, or rather only understood the most common case. Smack them > with a dead fish, https://www.youtube.com/watch?v=i9SSOWORzw4 > and get back to work. So, on your own machine, whenever daylight time starts or ends, you manually change your TZ environment variable to specify the newly appropriate eternally-fixed-offset zone? Of course not. Your OS doesn't change it for you by magic either. Your OS implements a hybrid tzinfo: it knows all by itself what the appropriate current total UTC offset is, by consulting the tzfile (or hybrid POSIX TZ rule) you attached to your account the last time you set it, however many years ago that may have been. Indeed, I don't know of any software package _other_ than pytz doing it the "switch eternally-fixed-offset zones" way. Not that it's impossible Stuart is the first person in history not to implement it in a "really stupid" way ;-) But it was more that Stuart made heroic efforts to leap the datetime design gap explained next: In all POSIX-ish OSes, hybrid tzinfos are just business as usual: a struct tm's tm_isdst flag distinguishes ambiguous times. localtime() (UTC->local) sets tm_isdst by magic for you, and mktime() (local->UTC) consults tm_isdst to disambiguate local times in a fold. A datetime object is the Python spelling of a C struct tm, but never included the tm_isdst flag. PEP 495 aims to supply a similar bit. When it does, hybrid tzinfos will do cross-zone conversions correctly in all cases. Before then, pytz uses eternally-fixed-offset zones primarily to overcome the current lack of that bit. C's localtime() and mktime() are both spelled .astimezone(...) in Python, but under the covers localtime() is essentially Python's fromutc() (which will set the new bit appropriately after 495) and mktime() is essentially .utcoffset() (which will consult the new bit after 495). That's all there is to it. "In theory" ;-) datetime will become more-or-less exactly as stupid as POSIX has been for some decades. >> So, yup, if you're thoroughly indoctrinated in pytz behavior, you will >> be accurate but appear insane to Guido ;-) At a semantic level, a >> pytz tzinfo doesn't capture the notion of a zone with offset changes - >> it doesn't even try to. All knowledge about offset changes is inside >> the .localize() and .normalize() dances. > I can see why people would like to modify it to spit out this information > when asked. I don't understand why they would like to have a hybrid > tzinfo. The notion of replacing tzinfos when they become inappropriate > fills their souls with revulsion, or something? Because, e.g., a hybrid tzinfo (after 495) _can_ do it correctly all the time, with no need for user interventions ever. Same as your OS does. That's about usability and lack of surprise. It didn't take much web cruising, e.g., to find baffled new pytz users wondering why the zone displayed "was wrong" sometimes in utterly unexceptional cases (nowhere near a fold or a gap). "Read the docs! normalize()!" Why should they _have_ to? The only other things in their life that demand they manually fiddle to adjust for UTC-offset transitions are "dumb clocks", where _needing_ to fiddle is universally viewed as a twice-a-year annoyance. > But, as I said, once you know the pytz way you may be ruined for > appreciating other solutions. Well, take just a moment to appreciate that your OS does use hybrid tzinfos, and that it works so smoothly you never really noticed it ;-) From random832 at fastmail.com Mon Sep 14 15:13:16 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 15:13:16 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> Message-ID: <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 14:53, Tim Peters wrote: > So, on your own machine, whenever daylight time starts or ends, you > manually change your TZ environment variable to specify the newly > appropriate eternally-fixed-offset zone? Of course not. No, but the hybrid zone isn't what gets attached to the individual struct tm value when you convert a time from utc (or from a POSIX timestamp) to a timezone local value. A single fixed utc offset is (along with the name and, yes, isdst flag). And pytz doesn't involve manually changing anything, it involves (as best it can) automatically applying the value to attach to each individual datetime value. > A datetime object is the Python spelling of a C struct tm, but never > included the tm_isdst flag. And no-one behind this proposal seems to be contemplating adding an equivalent to tm_gmtoff, despite that it would serve the same disambiguation purpose and make it much cheaper to maintain global invariants like a sort order according to the UTC value (No, I don't *care* how that's not how it's defined, it is *in fact* true for the UTC value that you will ever actually get from converting the values to UTC *today*, and it's the only total ordering that actually makes any sense) From tim.peters at gmail.com Mon Sep 14 15:15:12 2015 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 14 Sep 2015 14:15:12 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <201509140853.t8E8r99u007805@fido.openend.se> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509140853.t8E8r99u007805@fido.openend.se> Message-ID: [Guido] >> Wouldn't it be sufficient for people in Creighton to set their timezone to >> US/Central? IIUC the Canadian DST rules are the same as the US ones. Now, >> the question may remain how do people know what to set their timezone to. >> But neither pytz nor datetime can help with that -- it is up to the >> sysadmin. [Laura Creighton] > The Canadian DST rules are not the same as the US ones, wherein lies > the rub. ? All US locations observing DST switch at 2AM on the local clock on the 2nd Sunday of March and the 1st Sunday of November (since 2007). Best I can tell, exactly the same is true of all zones observing DST in Canada and in Mexico. The province of Saskatchewan has a few areas which prefer to > be on Mountain time, which we will ignore in this mail. The bulk of > them prefer to be on Central time, which is the same as Winnipeg and > Chicago. But what happens on DST start day (early March) in > Saskachewan? Provincial law mandates that you do not change your > clock, and do not adopt daylight savings time. The people in > Saskachewan thus stick to CST all year round. And this is how > sites like http://www.timeanddate.com/worldclock/canada/saskatoon > record things, with them at CST. I'm sure Guido is only talking about places in Canada that _do_ observe DST. There are also places in the US that don't observe DST. Of course "the DST rules" only apply to locations that do observe DST, and that's what Guido is asking about. > However, the people of Creighton have decided to keep DST, in > violation of the law, so they set their clocks forward. > http://www.timeanddate.com/worldclock/canada/creighton does this > properly as well, showing them with CDT. > > But this is not quite the complete story. In many (most?) places in > Saskatchewan, the rule is understood differently. Instead of 'we keep > to CST all year long' is is understood that 'we keep central time in > the winter and mountain time in the summer'. > > This makes parsing log files from all over Saskachewan, where sometime > in March things often stop saying CST and say MDT instead rather more > interesting than the adverage person might suspect. Read question as "in general" ;-) There are plenty of exceptions to the general rules all over the world. From alexander.belopolsky at gmail.com Mon Sep 14 15:25:55 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Mon, 14 Sep 2015 15:25:55 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> Message-ID: On Mon, Sep 14, 2015 at 3:13 PM, Random832 wrote: > (No, I don't > *care* how that's not how it's defined, it is *in fact* true for the UTC > value that you will ever actually get from converting the values to UTC > *today*, and it's the only total ordering that actually makes any sense) > This is a fine attitude when you implement your own brand new datetime library. As an author of a new library you have freedoms that developers of a 12 years old widely deployed code don't have. -------------- next part -------------- An HTML attachment was scrubbed... URL: From 4kir4.1i at gmail.com Mon Sep 14 15:30:56 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 14 Sep 2015 22:30:56 +0300 Subject: Terminology: "reference" versus "pointer" References: <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <55f61e8c$0$1660$c3e8da3$5496439d@news.astraweb.com> <55f6333c$0$1636$c3e8da3$5496439d@news.astraweb.com> <55f6fcf7$0$1640$c3e8da3$5496439d@news.astraweb.com> <4e340057-3a72-405f-82ef-51f865a97a18@googlegroups.com> Message-ID: <87mvwo4x3j.fsf@gmail.com> Ned Batchelder writes: ... > What do you feel is missing from Steven's diagram? I don't feel anything missing because I don't expect the model to be more detailed. From tim.peters at gmail.com Mon Sep 14 15:30:58 2015 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 14 Sep 2015 14:30:58 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> Message-ID: [Tim] >> So, on your own machine, whenever daylight time starts or ends, you >> manually change your TZ environment variable to specify the newly >> appropriate eternally-fixed-offset zone? Of course not. [Random832 ] > No, but the hybrid zone isn't what gets attached to the individual > struct tm value when you convert a time from utc (or from a POSIX > timestamp) to a timezone local value. A single fixed utc offset is > (along with the name and, yes, isdst flag). You're assuming much more than POSIX - and the ISO C standard - requirs. My description was quite explicitly about how POSIX has done it all along. tm_gmtoff and tm_zone are extensions to the standards, introduced (IIRC) by BSD. Portable code (including Python's implementation) can't assume they're available. > And pytz doesn't involve manually changing anything, it involves (as > best it can) automatically applying the value to attach to each > individual datetime value. .normalize() is a manual step. It doesn't invoke itself by magic (although I believe Stuart would like Python to add internal hooks so pytz _could_ get it invoked by magic). >> A datetime object is the Python spelling of a C struct tm, but never >> included the tm_isdst flag. > And no-one behind this proposal seems to be contemplating adding an > equivalent to tm_gmtoff, It was off the table because, for backward compatibility, we need to mess with the pickle format as little as possible. It's vital that datetimes obtained from old pickles continue to work fine, and that pickles obtained from new datetime objects work fine when loaded by older Pythons unless they actually require the new fold=1 possibility. > despite that it would serve the same disambiguation purpose and > make it much cheaper to maintain global invariants like a sort order > according to the UTC value It would be nice to have! .utcoffset() is an expensive operation as-is, and being able to rely on tm_gmtoff would make that dirt-cheap instead. > (No, I don't *care* how that's not how it's defined, ? How what is defined?: > it is *in fact* true for the UTC value that you will ever actually get > from converting the values to UTC *today*, and it's the only total > ordering that actually makes any sense) Well, you lost me there. In a post-495 world, conversion to UTC will work correctly in all cases. It cannot today.; From random832 at fastmail.com Mon Sep 14 15:35:28 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 15:35:28 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <201509140853.t8E8r99u007805@fido.openend.se> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509140853.t8E8r99u007805@fido.openend.se> Message-ID: <1442259328.257554.383459153.4191C75E@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 04:53, Laura Creighton wrote: > But this is not quite the complete story. In many (most?) places in > Saskatchewan, the rule is understood differently. Instead of 'we keep > to CST all year long' is is understood that 'we keep central time in > the winter and mountain time in the summer'. As far as I know, the position of the tzdata people is that while this belief is held almost everywhere that does not observe DST but is surrounded by places that do (I should know; I live in Indiana, which was such a place until 2006), almost nowhere does it have any formal legitimacy, and systems that use the data therefore, by design, will not actually generate "CST/MDT" timestamps. When exactly is this transition supposed to take place? At 2AM, Manitoba springs forward, but Alberta remains on MST for another hour - nowhere else in North America *but* Saskatchewan uses an offset of -06:00 for this hour-long period. From katewinslet626 at gmail.com Mon Sep 14 15:40:28 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Mon, 14 Sep 2015 12:40:28 -0700 (PDT) Subject: need help with selenium Message-ID: I wrote this code in python for submitting a login form: from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get('some url') elem = driver.find_element_by_name("username") elem.send_keys('13103666') elem = driver.find_element_by_name("password") elem.send_keys('as') driver.find_element_by_name("btnSubmit").click() #nothing happens from here print driver.page_source print "test" After clicking on submit button, a message is displayed on the same page whether login was successful or not. However after clicking on submit button, I lose control over the web page. I can't use any selenium functions now like 'driver.find_element_by_name()'. Initially everything works fine. I can enter username and password using selenium as written in my code, but once I click on submit button or press return key(tried both using selenium), any script written after that(involving web driver) doesnt seem to work. Even driver.close() doesnt work. This is the form I am trying to submit: The submission is successful, however after submission I cant verify if login was successful or not because of the issue I posted above. Do I need to switch web handle? If, then how. Any help will be highly appreciated. From random832 at fastmail.com Mon Sep 14 15:44:12 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 15:44:12 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> Message-ID: <1442259852.259192.383467881.5156BE88@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 15:25, Alexander Belopolsky wrote: > This is a fine attitude when you implement your own brand new datetime > library. As an author of a new library you have freedoms that developers > of a 12 years old widely deployed code don't have. I'm talking about the real behavior of datetime as it exists *today*, and has existed for the past 12 years, before any of this "add fold flag but sort 2:15 fold1 before 2:45 fold0" nonsense gets in. It is an invariant that is true today, and therefore which you can't rely on any of the consumers of this 12 years old widely deployed code not to assume will remain true. Enforcing an invariant that all ordering is done according to UTC timestamps would not break any backward compatibility, because there is not a *single* pair of timestamps that can be represented today with any *remotely* plausible tzinfo whose order is different from that. For that matter, a tzinfo where two possible values for fold aren't sufficient to disambiguate timestamps is *more* plausible than one where the naive ordering of any two non-fold timestamps is reversed from the UTC order, yet that case apparently isn't being considered. From alexander.belopolsky at gmail.com Mon Sep 14 15:44:25 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Mon, 14 Sep 2015 15:44:25 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> Message-ID: On Mon, Sep 14, 2015 at 3:30 PM, Tim Peters wrote: > > make it much cheaper to maintain global invariants like a sort order > > according to the UTC value > > It would be nice to have! .utcoffset() is an expensive operation > as-is, and being able to rely on tm_gmtoff would make that dirt-cheap > instead. If it is just a question of optimization, datetime objects can be extended to cache utcoffset. Note that PyPy have recently added caching of the hash values in datetime objects. I merged their changes in our datetime.py, but it did not look like C implementation would benefit from it as much as pure python did. I expect something similar from caching utcoffset: a measurable improvement for tzinfos implemented in Python and a wash for those implemented in C. (A more promising optimization approach is to define a C API for tzinfo interface.) -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexander.belopolsky at gmail.com Mon Sep 14 15:48:08 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Mon, 14 Sep 2015 15:48:08 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442259852.259192.383467881.5156BE88@webmail.messagingengine.com> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442259852.259192.383467881.5156BE88@webmail.messagingengine.com> Message-ID: On Mon, Sep 14, 2015 at 3:44 PM, Random832 wrote: > It is an > invariant that is true today, and therefore which you can't rely on any > of the consumers of this 12 years old widely deployed code not to assume > will remain true. > Sorry, this sentence does not parse. You are missing a "not" somewhere. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.peters at gmail.com Mon Sep 14 15:49:53 2015 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 14 Sep 2015 14:49:53 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> Message-ID: [Tim] >> It would be nice to have! .utcoffset() is an expensive operation >> as-is, and being able to rely on tm_gmtoff would make that dirt-cheap >> instead. [Alex] > If it is just a question of optimization, Yes. If it's more than just that, then 495 doesn't actually solve the problem of getting the correct UTC offset in all cases. > datetime objects can be extended to cache utcoffset. Note that PyPy > have recently added caching of the hash values in datetime objects. I > merged their changes in our datetime.py, but it did not look like C > implementation would benefit from it as much as pure python did. I > expect something similar from caching utcoffset: a measurable > improvement for tzinfos implemented in Python and a wash for those > implemented in C. (A more promising optimization approach is to define a C > API for tzinfo interface.) There's no answer to this. It depends on how expensive .utcoffset() is, which in turn depends on how the tzinfo author implements it. I don't care now fast it is. But, even if I did, "premature optimization" applies at this time ;-) From random832 at fastmail.com Mon Sep 14 15:58:34 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 15:58:34 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> Message-ID: <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 15:30, Tim Peters wrote: > You're assuming much more than POSIX - and the ISO C standard - > requirs. My description was quite explicitly about how POSIX has done > it all along. tm_gmtoff and tm_zone are extensions to the standards, > introduced (IIRC) by BSD. Portable code (including Python's > implementation) can't assume they're available. No, but that doesn't mean it's not in fact true (what was under discussion was "your own machine", not "a minimal POSIX implementation"). And it doesn't mean it's not a best practice that python can and should copy. I'm not talking about *using* it, I'm talking about working the same way independently, so this has nothing to do with assuming it's available. > It was off the table because, for backward compatibility, we need to > mess with the pickle format as little as possible. It's vital that > datetimes obtained from old pickles continue to work fine, and that > pickles obtained from new datetime objects work fine when loaded by > older Pythons unless they actually require the new fold=1 possibility. I don't see how this would prevent that. Aware datetimes have a tzinfo *right there* that can be asked for a value to populate utcoffset with if there isn't a pickled one. > > (No, I don't *care* how that's not how it's defined, > > ? How what is defined?: Just trying, unsuccessfully apparently, to head off the "no, it's defined as working the same as a naive datetime if the tzinfo values are the same" argument that got brought up the *last* time I made this claim. > > it is *in fact* true for the UTC value that you will ever actually get > > from converting the values to UTC *today*, and it's the only total > > ordering that actually makes any sense) > > Well, you lost me there. In a post-495 world, conversion to UTC will > work correctly in all cases. It cannot today.; It'll provide *a* value in all cases. The sort order today is equivalent to using that value in all cases unless you've got a pathological tzinfo specifically crafted to break it. I think that's an important enough invariant to be worth keeping, since it is the only possible way to provide a total order in the presence of interzone comparisons. From alexander.belopolsky at gmail.com Mon Sep 14 16:01:03 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Mon, 14 Sep 2015 16:01:03 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> Message-ID: On Mon, Sep 14, 2015 at 3:49 PM, Tim Peters wrote: > It depends on how expensive .utcoffset() > is, which in turn depends on how the tzinfo author implements it. > No, it does not. In most time zones, UTC offset in seconds can be computed by C code as a 4-byte integer faster than CPython can look up the .utcoffset method. (At least for times within a few years around now.) A programmer who makes it slower should be fired. Yet I agree, "'premature optimization' applies at this time." -------------- next part -------------- An HTML attachment was scrubbed... URL: From carl at oddbird.net Mon Sep 14 16:01:23 2015 From: carl at oddbird.net (Carl Meyer) Date: Mon, 14 Sep 2015 14:01:23 -0600 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> References: <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> Message-ID: <55F72793.1030702@oddbird.net> Can we please stop cross-posting this thread to python-list and move it to datetime-sig only? I think anyone here on python-list who is sufficiently interested in it can subscribe to datetime-sig. Or the other way around, whatever. I'd just like to stop getting all the messages twice. Carl -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From random832 at fastmail.com Mon Sep 14 16:08:50 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 16:08:50 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442259852.259192.383467881.5156BE88@webmail.messagingengine.com> Message-ID: <1442261330.265134.383487745.4E9C3005@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 15:48, Alexander Belopolsky wrote: > On Mon, Sep 14, 2015 at 3:44 PM, Random832 > wrote: > > > It is an > > invariant that is true today, and therefore which you can't rely on any > > of the consumers of this 12 years old widely deployed code not to assume > > will remain true. > > > > Sorry, this sentence does not parse. You are missing a "not" somewhere. Nope. I am asserting that: This invariant is true today. Therefore, it is likely that at least some consumers of datetime will assume it is true. Therefore, you cannot rely on there not being any consumers which assume it will remain true. It's awkward, since when I go back to analyze it it turns out that the "not" after 'code' actually technically modifies "any" earlier in the sentence, but the number of negatives is correct. (Though, it actually works out even without that change, since the question of *which* consumers rely on the invariant is unknown.) From random832 at fastmail.com Mon Sep 14 16:10:38 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 16:10:38 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <55F72793.1030702@oddbird.net> References: <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> <55F72793.1030702@oddbird.net> Message-ID: <1442261438.265623.383499657.4EA31AFA@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 16:01, Carl Meyer wrote: > Can we please stop cross-posting this thread to python-list and move it > to datetime-sig only? I think anyone here on python-list who is > sufficiently interested in it can subscribe to datetime-sig. > > Or the other way around, whatever. I'd just like to stop getting all the > messages twice. Er, sorry. To compound the issue, i've also had problems with some of my replies accidentally only going to python-list due to my email client having a "reply list" button that identifies python-list as the primary. From tim.peters at gmail.com Mon Sep 14 16:15:35 2015 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 14 Sep 2015 15:15:35 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> Message-ID: [Random832 ] Whether or not datetimes stored tm_gmtoff and tm_zone workalikes has no effect on semantics I can see. If, in your view, they're purely an optimization, they're just a distraction for now. If you're proposing to add them _instead_ of adding `fold`, no, that can't work, for the pickle compatibility reasons already explained. Whether something is in a fold needs to preserved across pickling, but "almost all" pickles need to be readable by older Pythons too. This is doable adding one bit, but not doable at all if we need to add arbitrary timedelta and string objects _instead_ of that bit. ... >>> (No, I don't *care* how that's not how it's defined, >> ? How what is defined?: > Just trying, unsuccessfully apparently, to head off the "no, it's > defined as working the same as a naive datetime if the tzinfo values are > the same" argument that got brought up the *last* time I made this > claim. Sorry, I still don't know what this is about. >>> it is *in fact* true for the UTC value that you will ever actually get >>> from converting the values to UTC *today*, and it's the only total >>> ordering that actually makes any sense) >> Well, you lost me there. In a post-495 world, conversion to UTC will >> work correctly in all cases. It cannot today.; > It'll provide *a* value in all cases. It will provide the correct UTC offset in all cases. > The sort order today is equivalent to using that value in all > cases unless you've got a pathological tzinfo > specifically crafted to break it. I think that's an important enough > invariant to be worth keeping, since it is the only possible way to > provide a total order in the presence of interzone comparisons. Show some code? I don't know what you're talking about. It is true that the earlier and later of an ambiguous time in a fold will compare equal in their own zone, but compare not equal after conversion to UTC (or to any other zone in which they're not in one of the latter zone's folds). Is that what you're talking about? From ned at nedbatchelder.com Mon Sep 14 16:16:05 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 14 Sep 2015 13:16:05 -0700 (PDT) Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <55f61e8c$0$1660$c3e8da3$5496439d@news.astraweb.com> <55f6333c$0$1636$c3e8da3$5496439d@news.astraweb.com> <55f6fcf7$0$1640$c3e8da3$5496439d@news.astraweb.com> <4e340057-3a72-405f-82ef-51f865a97a18@googlegroups.com> Message-ID: On Monday, September 14, 2015 at 3:32:46 PM UTC-4, Akira Li wrote: > Ned Batchelder writes: > ... > > What do you feel is missing from Steven's diagram? > > I don't feel anything missing because I don't expect the model to be > more detailed. Akira, you said, "neither models are detailed enough to describe meaningfully the behavior of Python code in the general case." I'm wondering what aspect of the code's behavior isn't captured in this model? I know you didn't expect it to be complete, but I'm not sure what you think is missing. --Ned. From tim.peters at gmail.com Mon Sep 14 16:22:50 2015 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 14 Sep 2015 15:22:50 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> Message-ID: [Tim] >> It depends on how expensive .utcoffset() >> is, which in turn depends on how the tzinfo author implements it. [Alex] > No, it does not. In most time zones, UTC offset in seconds can be computed > by C code as a 4-byte integer Which is a specific implementation of .utcoffset(). Which likely has nothing to do with how most tzinfo authors will implement _their_ .utcoffset(). For example, look at any tzinfo.utcoffset() implementation that currently exists ;-) > faster > than CPython can look up the .utcoffset method. (At least for times > within a few years around now.) A programmer who makes it slower should > be fired. So any programmer who implements .utcoffset() in Python should be fired? That's the only way I can read that. > Yet I agree, "'premature optimization' applies at this time." I'm more worried now about premature firing ;-) From random832 at fastmail.com Mon Sep 14 16:27:05 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 16:27:05 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> Message-ID: <1442262425.268793.383506657.0443601E@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 16:15, Tim Peters wrote: > [Random832 ] > > Whether or not datetimes stored tm_gmtoff and tm_zone workalikes has > no effect on semantics I can see. If, in your view, they're purely an > optimization, they're just a distraction for now. If you're proposing > to add them _instead_ of adding `fold`, no, that can't work, for the > pickle compatibility reasons already explained. Whether something is > in a fold needs to preserved across pickling, but "almost all" pickles > need to be readable by older Pythons too. This is doable adding one > bit, but not doable at all if we need to add arbitrary timedelta and > string objects _instead_ of that bit. A) I'm still not sure why, but I was talking about adding an int, not a timedelta and a string. B) Older python versions can't make use of either utcoffset or fold, but can ignore either of them. I don't even see why they couldn't ignore a timedelta and a string if we felt like adding those. C) What value fold "should" have can be inferred from the time, the utcoffset, and the tzinfo. > >> Well, you lost me there. In a post-495 world, conversion to UTC will > >> work correctly in all cases. It cannot today.; > > > It'll provide *a* value in all cases. > > It will provide the correct UTC offset in all cases. I'm saying that *today*, even with no 495, it does provide *a* value in all cases (even if that's sometimes the "wrong" value for an ambiguous time). And that value is, for any plausible tzinfo, ordered the same for any given pair of datetimes with the same tzinfo as the datetimes considered as naive datetimes. There is, or appears to be, a faction that is proposing to change that by sorting fold=1 2:15 before fold=0 2:45 even though the former is *actually* 30 minutes later than the latter, and I am *utterly baffled* at why they think this is a good idea. > It is true that the earlier and later of an ambiguous time in a fold > will compare equal in their own zone, but compare not equal after > conversion to UTC (or to any other zone in which they're not in one of > the latter zone's folds). Is that what you're talking about? Yes. Or two different ambiguous times, where the properly earlier one compares greater and vice versa. I have no idea why anyone thinks this is reasonable or desirable behavior. From alexander.belopolsky at gmail.com Mon Sep 14 16:27:26 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Mon, 14 Sep 2015 16:27:26 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442261330.265134.383487745.4E9C3005@webmail.messagingengine.com> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442259852.259192.383467881.5156BE88@webmail.messagingengine.com> <1442261330.265134.383487745.4E9C3005@webmail.messagingengine.com> Message-ID: On Mon, Sep 14, 2015 at 4:08 PM, Random832 wrote: > On Mon, Sep 14, 2015, at 15:48, Alexander Belopolsky wrote: > > On Mon, Sep 14, 2015 at 3:44 PM, Random832 > > wrote: > > > > > It is an > > > invariant that is true today, and therefore which you can't rely on any > > > of the consumers of this 12 years old widely deployed code not to > assume > > > will remain true. > > > > > > > Sorry, this sentence does not parse. You are missing a "not" somewhere. > > Nope. I am asserting that: > > This invariant is true today. > You've never specified "this invariant", but I'll assume you are talking about "a < b implies a.astimezone(UTC) < b.astimezone(UTC)." This is *not* true today: >>> from datetime import * >>> from datetimetester import Eastern >>> UTC = timezone.utc >>> a = datetime(2002, 4, 7, 1, 40, tzinfo=Eastern) >>> b = datetime(2002, 4, 7, 2, 20, tzinfo=Eastern) >>> a < b True >>> a.astimezone(UTC) < b.astimezone(UTC) False > Therefore, it is likely that at least some consumers of datetime will > assume it is true. > Obviously, if Random832 is a real person, the last statement is true. This does not make the assumption true, just proves that at least one user is confused about the current behavior. :-) > Therefore, you cannot rely on there not being any consumers which assume > it will remain true. > That's where we are now. Some users make baseless assumptions. This will probably remain true. :-( > It's awkward, since when I go back to analyze it it turns out that the > "not" after 'code' actually technically modifies "any" earlier in the > sentence, but the number of negatives is correct. Writing in shorter sentences may help. > (Though, it actually > works out even without that change, since the question of *which* > consumers rely on the invariant is unknown.) > True. We will never know how many users rely on false assumptions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From 4kir4.1i at gmail.com Mon Sep 14 16:32:06 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 14 Sep 2015 23:32:06 +0300 Subject: Terminology: "reference" versus "pointer" References: <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <55f61e8c$0$1660$c3e8da3$5496439d@news.astraweb.com> <55f6333c$0$1636$c3e8da3$5496439d@news.astraweb.com> <55f6fcf7$0$1640$c3e8da3$5496439d@news.astraweb.com> <4e340057-3a72-405f-82ef-51f865a97a18@googlegroups.com> Message-ID: <87io7c4u9l.fsf@gmail.com> Ned Batchelder writes: > On Monday, September 14, 2015 at 3:32:46 PM UTC-4, Akira Li wrote: >> Ned Batchelder writes: >> ... >> > What do you feel is missing from Steven's diagram? >> >> I don't feel anything missing because I don't expect the model to be >> more detailed. > > Akira, you said, "neither models are detailed enough to describe > meaningfully the behavior of Python code in the general case." > > I'm wondering what aspect of the code's behavior isn't captured > in this model? I know you didn't expect it to be complete, but I'm > not sure what you think is missing. > I don't understand what you are talking about. From alexander.belopolsky at gmail.com Mon Sep 14 16:39:14 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Mon, 14 Sep 2015 16:39:14 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> Message-ID: On Mon, Sep 14, 2015 at 4:22 PM, Tim Peters wrote: > > faster > > than CPython can look up the .utcoffset method. (At least for times > > within a few years around now.) A programmer who makes it slower should > > be fired. > > So any programmer who implements .utcoffset() in Python should be > fired? That's the only way I can read that. No, no! I've already conceded that caching UTC offset will probably help pure Python implementations. PyPy folks have established this fact for hash and I am willing to extrapolate their results to UTC offset. I am only trying to say that if we decide to bring a fast TZ database to CPython, pure python tzinfo interface will likely become our main bottleneck, not the speed with which C code can compute the offset value. -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.peters at gmail.com Mon Sep 14 16:45:17 2015 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 14 Sep 2015 15:45:17 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442262425.268793.383506657.0443601E@webmail.messagingengine.com> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> <1442262425.268793.383506657.0443601E@webmail.messagingengine.com> Message-ID: [Random832 ] > A) I'm still not sure why, but I was talking about adding an int, not a > timedelta and a string. > > B) Older python versions can't make use of either utcoffset or fold, but > can ignore either of them. I don't even see why they couldn't ignore a > timedelta and a string if we felt like adding those. Because all versions of Python expect a very specific pickle layout for _every_ kind of pickled object (including datetimes).. Make any change to the pickle format of any object, and older Pythons will simply blow up (raise an exception) when trying to load the new pickle - or do something insane with the pickle bits. It's impossible for older Pythons to know anything about what "the new bits" are supposed to mean, and there is no way to spell, in the pickle engine, "but if you're an older version, skip over the next N bytes". > C) What value fold "should" have can be inferred from the time, the > utcoffset, and the tzinfo. So you are proposing to add ... something ... _instead_ of adding `fold`. Already addressed that. See above. > I'm saying that *today*, even with no 495, it [utcoffset] does provide > *a* value in all cases (even if that's sometimes the "wrong" value > for an ambiguous time). Sure. > And that value is, for any plausible tzinfo, ordered the same for > any given pair of datetimes with the same tzinfo as the datetimes > considered as naive datetimes. Yes. > There is, or appears to be, a faction that is proposing to change that > by sorting fold=1 2:15 before fold=0 2:45 even though the former is > *actually* 30 minutes later than the latter, and I am *utterly baffled* > at why they think this is a good idea. It's not so much a "good idea" as that it's the only idea consistent with Python's "naive time" model. Folds and gaps don't exist in naive time. Indeed, the _concept_ of "time zone" doesn't really exist in naive time. There's _inherent_ tension between the naive time model and the way multi-offset time zones actually behave. So it goes. >> It is true that the earlier and later of an ambiguous time in a fold >> will compare equal in their own zone, but compare not equal after >> conversion to UTC (or to any other zone in which they're not in one of >> the latter zone's folds). Is that what you're talking about? > Yes. Or two different ambiguous times, where the properly earlier one > compares greater and vice versa. I have no idea why anyone thinks this > is reasonable or desirable behavior. >From which I can guess, without asking, that you think "naive time" itself is unreasonable and undesirable ;-) From random832 at fastmail.com Mon Sep 14 17:23:20 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 17:23:20 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> <1442262425.268793.383506657.0443601E@webmail.messagingengine.com> Message-ID: <1442265800.280460.383547057.16B65298@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 16:45, Tim Peters wrote: > Because all versions of Python expect a very specific pickle layout > for _every_ kind of pickled object (including datetimes).. Make any > change to the pickle format of any object, and older Pythons will > simply blow up (raise an exception) when trying to load the new pickle > - or do something insane with the pickle bits. It's impossible for > older Pythons to know anything about what "the new bits" are supposed > to mean, and there is no way to spell, in the pickle engine, "but if > you're an older version, skip over the next N bytes". Well, you could have put some reserved bits in the original pickle format for datetime back when it was first defined, or even just allowed passing in a longer string for future extension purposes. That you didn't makes me wonder just where you're finding the space to put the fold bit. > It's not so much a "good idea" as that it's the only idea consistent > with Python's "naive time" model. Folds and gaps don't exist in naive > time. Indeed, the _concept_ of "time zone" doesn't really exist in > naive time. There's _inherent_ tension between the naive time model > and the way multi-offset time zones actually behave. So it goes. But why does it need to be consistent? You can't compare naive datetimes with aware ones. If you want to sort/bisect a list of datetimes, they have to either all be naive or all be aware. So when we're talking about how ordering works, we're fundamentally talking about how it works for aware datetimes. From tim.peters at gmail.com Mon Sep 14 17:34:07 2015 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 14 Sep 2015 16:34:07 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442265800.280460.383547057.16B65298@webmail.messagingengine.com> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> <1442262425.268793.383506657.0443601E@webmail.messagingengine.com> <1442265800.280460.383547057.16B65298@webmail.messagingengine.com> Message-ID: [Tim] >> Because all versions of Python expect a very specific pickle layout >> for _every_ kind of pickled object (including datetimes).. Make any >> change to the pickle format of any object, and older Pythons will >> simply blow up (raise an exception) when trying to load the new pickle >> - or do something insane with the pickle bits. It's impossible for >> older Pythons to know anything about what "the new bits" are supposed >> to mean, and there is no way to spell, in the pickle engine, "but if >> you're an older version, skip over the next N bytes". [Random832 ] > Well, you could have put some reserved bits in the original pickle > format for datetime back when it was first defined, or even just allowed > passing in a longer string for future extension purposes. Yes, we "could have" done that for all pickle formats for all types. But why on Earth would we? Pickle size is important to many apps (e.g., Zope applications can store billions of pickles in databases. and it may not be purely coincidence ;-) that Zope Corp paid for datetime development), and there would have been loud screaming about any "wasted" bytes. > That you didn't makes me wonder just where you're finding the space to put the > fold bit. PEP 495 gives all the details. Short course: there are bits that are _always_ 0 now within some datetime pickle bytes. `fold` will abuse one of those always-0-now pickle bits. >> It's not so much a "good idea" as that it's the only idea consistent >> with Python's "naive time" model. Folds and gaps don't exist in naive >> time. Indeed, the _concept_ of "time zone" doesn't really exist in >> naive time. There's _inherent_ tension between the naive time model >> and the way multi-offset time zones actually behave. So it goes. > But why does it need to be consistent? You can't compare naive datetimes > with aware ones. If you want to sort/bisect a list of datetimes, they > have to either all be naive or all be aware. So when we're talking about > how ordering works, we're fundamentally talking about how it works for > aware datetimes. Aware datetimes _within_ a zone also follow the naive time model. It's unfortunate that they're nevertheless called "aware" datetimes. So, sorry, even when sorting a list of aware datetimes, if they share a common zone it is wholly intended that they all work in naive time. Apps that can't tolerate naive time should convert to UTC first. End of problems. From random832 at fastmail.com Mon Sep 14 17:53:55 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 17:53:55 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> <1442262425.268793.383506657.0443601E@webmail.messagingengine.com> <1442265800.280460.383547057.16B65298@webmail.messagingengine.com> Message-ID: <1442267635.287083.383576201.0990DAA7@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 17:34, Tim Peters wrote: > Yes, we "could have" done that for all pickle formats for all types. > But why on Earth would we? Pickle size is important to many apps > (e.g., Zope applications can store billions of pickles in databases. > and it may not be purely coincidence ;-) that Zope Corp paid for > datetime development), and there would have been loud screaming about > any "wasted" bytes. Would allowing a 16-byte string in the future have increased the storage occupied by a 10-byte string today? Would allowing a third argument in the future have increased the storage occupied by two arguments today? As far as I can tell the pickle format for non-primitive types isn't _that_ fixed-width. > > That you didn't makes me wonder just where you're finding the space to put the > > fold bit. > > PEP 495 gives all the details. Short course: there are bits that are > _always_ 0 now within some datetime pickle bytes. `fold` will abuse > one of those always-0-now pickle bits. And what happens to older implementations if that bit is 1? > Aware datetimes _within_ a zone also follow the naive time model. > It's unfortunate that they're nevertheless called "aware" datetimes. > > So, sorry, even when sorting a list of aware datetimes, if they share > a common zone it is wholly intended that they all work in naive time. And if some of them share a common zone, then some of them will work in naive time, and some of them will work in aware time, and some pairs (well, triples) of them will cause problems for sort/bisect algorithms. Maybe it'd be best to simply ban interzone comparisons. Or have some sort of context manager to determine how arithmetic and comparisons work. From tim.peters at gmail.com Mon Sep 14 18:09:47 2015 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 14 Sep 2015 17:09:47 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442267635.287083.383576201.0990DAA7@webmail.messagingengine.com> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> <1442262425.268793.383506657.0443601E@webmail.messagingengine.com> <1442265800.280460.383547057.16B65298@webmail.messagingengine.com> <1442267635.287083.383576201.0990DAA7@webmail.messagingengine.com> Message-ID: [Random832 ] > Would allowing a 16-byte string in the future have increased the storage > occupied by a 10-byte string today? Would allowing a third argument in > the future have increased the storage occupied by two arguments today? > As far as I can tell the pickle format for non-primitive types isn't > _that_ fixed-width. Sorry, I'm not arguing about this any more. Pickle doesn't work at all at the level of "count of bytes followed by a string". If you want to make a pickle argument that makes sense, I'm afraid you'll need to become familiar with how pickle works first. This is not the place for a pickle tutorial. Start by learning what a datetime pickle actually is. pickletools.dis() will be very helpful. >>> That you didn't makes me wonder just where you're finding the space to put the >>> fold bit. >> PEP 495 gives all the details. Short course: there are bits that are >> _always_ 0 now within some datetime pickle bytes. `fold` will abuse >> one of those always-0-now pickle bits. > And what happens to older implementations if that bit is 1? Unpickling will raise an exception, complaining that the minute value is out of range. >> Aware datetimes _within_ a zone also follow the naive time model. >> It's unfortunate that they're nevertheless called "aware" datetimes. >> >> So, sorry, even when sorting a list of aware datetimes, if they share >> a common zone it is wholly intended that they all work in naive time. > And if some of them share a common zone, then some of them will work in > naive time, and some of them will work in aware time, and some pairs > (well, triples) of them will cause problems for sort/bisect algorithms. All sorts of things may happen, yes. As I said, if you need to care, convert to UTC first. Most apps do nothing like this. > Maybe it'd be best to simply ban interzone comparisons. We cannot. Backward compatibility. If would have been better had interzone comparisons and subtraction not been supported from the start. Too late to change that. > Or have some sort of context manager to determine how arithmetic and comparisons > work. Write a PEP ;-) From lac at openend.se Mon Sep 14 19:00:37 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 15 Sep 2015 01:00:37 +0200 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442259328.257554.383459153.4191C75E@webmail.messagingengine.com> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509140853.t8E8r99u007805@fido.openend.se> <1442259328.257554.383459153.4191C75E@webmail.messagingengine.com> Message-ID: <201509142300.t8EN0bLa027634@fido.openend.se> In a message of Mon, 14 Sep 2015 15:35:28 -0400, Random832 writes: >As far as I know, the position of the tzdata people is that while this >belief is held almost everywhere that does not observe DST but is >surrounded by places that do (I should know; I live in Indiana, which >was such a place until 2006), almost nowhere does it have any formal >legitimacy, and systems that use the data therefore, by design, will not >actually generate "CST/MDT" timestamps. It been many, many years since I cared about this, but I used to see a lot of timestamp fiddling among people who ran online services. Because otherwise the natives would wake up in the morning and fire off bug reports 'you are supposed to change the time to Mountain' ... >When exactly is this transition supposed to take place? At 2AM, Manitoba >springs forward, but Alberta remains on MST for another hour - nowhere >else in North America *but* Saskatchewan uses an offset of -06:00 for >this hour-long period. Which is why I ended up putting my faith in offsets. As you might guess, when this transition takes place was locally determined by whoever had to make the switch. Every year we got to hear why it was best (and maybe even legally required) to make the switch at 02:00. Others insisted that the nameswap should happen at 03:00. And, in a time when a lot of this absolutely had to be done by hand (think Fidonet systems running on user pcs that had no automatic clock at all) the real answer was 'The time will always be right, I will change the timezone to mountain when I get up in the morning'. Things may be different now. Laura >-- >https://mail.python.org/mailman/listinfo/python-list From lac at openend.se Mon Sep 14 19:23:13 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 15 Sep 2015 01:23:13 +0200 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442261438.265623.383499657.4EA31AFA@webmail.messagingengine.com> References: <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> <55F7279! 3.1030702@oddbird.net> <1442261438.265623.383499657.4EA31AFA@webmail.messagingengine.com> Message-ID: <201509142323.t8ENNDUc001332@fido.openend.se> On Mon, Sep 14, 2015, at 16:01, Carl Meyer wrote: >> Can we please stop cross-posting this thread to python-list and move it >> to datetime-sig only? I think anyone here on python-list who is >> sufficiently interested in it can subscribe to datetime-sig. >> >> Or the other way around, whatever. I'd just like to stop getting all the >> messages twice. I don't know about the others, but I am finding this rather more entertaining than another round of 'python -- does it have pointers' in python-list. Laura From rurpy at yahoo.com Mon Sep 14 19:38:12 2015 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Mon, 14 Sep 2015 16:38:12 -0700 (PDT) Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> <55F7279!> <3.1030702@oddbird.net> <1442261438.265623.383499657.4EA31AFA@webmail.messagingengine.com> Message-ID: <619ac8ff-1961-49de-9bf3-3bd515bcbb4e@googlegroups.com> On Monday, September 14, 2015 at 5:23:32 PM UTC-6, Laura Creighton wrote: >[...] > I don't know about the others, but I am finding this rather more > entertaining than another round of 'python -- does it have pointers' > in python-list. Could we please dispense with the gratuitous "what I'm interested in is more important that what you are interested in" posts please? Almost all mail readers have a filter ability that will address the problem more effectively. Thank you. From random832 at fastmail.com Mon Sep 14 21:19:56 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 21:19:56 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> <1442262425.268793.383506657.0443601E@webmail.messagingengine.com> <1442265800.280460.383547057.16B65298@webmail.messagingengine.com> <1442267635.287083.383576201.0990DAA7@webmail.messagingengine.com> Message-ID: <1442279996.198469.383712497.36F9DE26@webmail.messagingengine.com> On Mon, Sep 14, 2015, at 18:09, Tim Peters wrote: > Sorry, I'm not arguing about this any more. Pickle doesn't work at > all at the level of "count of bytes followed by a string". The SHORT_BINBYTES opcode consists of the byte b'C', followed by *yes indeed* "count of bytes followed by a string". > If you > want to make a pickle argument that makes sense, I'm afraid you'll > need to become familiar with how pickle works first. This is not the > place for a pickle tutorial. > > Start by learning what a datetime pickle actually is. > pickletools.dis() will be very helpful. 0: \x80 PROTO 3 2: c GLOBAL 'datetime datetime' 21: q BINPUT 0 23: C SHORT_BINBYTES b'\x07\xdf\t\x0e\x15\x06*\x00\x00\x00' 35: q BINPUT 1 37: \x85 TUPLE1 38: q BINPUT 2 40: R REDUCE 41: q BINPUT 3 43: . STOP The payload is ten bytes, and the byte immediately before it is in fact 0x0a. If I pickle any byte string under 256 bytes long by itself, the byte immediately before the data is the length. This is how I initially came to the conclusion that "count of bytes followed by a string" was valid. I did, before writing my earlier post, look into the high-level aspects of how datetime pickle works - it uses __reduce__ to create up to two arguments, one of which is a 10-byte string, and the other is the tzinfo. Those arguments are passed into the date constructor and detected by that constructor - for example, I can call it directly with datetime(b'\x07\xdf\t\x0e\x15\x06*\x00\x00\x00') and get the same result as unpickling. At the low level, the part that represents that first argument does indeed appear to be "count of bytes followed by a string". I can add to the count, add more bytes, and it will call the constructor with the longer string. If I use pickletools.dis on my modified value the output looks the same except for, as expected, the offsets and the value of the argument to the SHORT_BINBYTES opcode. So, it appears that, as I was saying, "wasted space" would not have been an obstacle to having the "payload" accepted by the constructor (and produced by __reduce__ ultimately _getstate) consist of "a byte string of >= 10 bytes, the first 10 of which are used and the rest of which are ignored by python <= 3.5" instead of "a byte string of exactly 10 bytes", since it would have accepted and produced exactly the same pickle values, but been prepared to accept larger arguments pickled from future versions. For completeness: Protocol version 2 and 1 use BINUNICODE on a latin1-to-utf8 version of the byte string, with a similar "count of bytes followed by a string" (though the count of bytes is of UTF-8 bytes). Protocol version 0 uses UNICODE, terminated by \n, and a literal \n is represented by \\u000a. In all cases some extra data around the value sets it up to call "codecs.encode(..., 'latin1')" upon unpickling. So have I shown you that I know enough about the pickle format to know that permitting a longer string (and ignoring the extra bytes) would have had zero impact on the pickle representation of values that did not contain a longer string? I'd already figured out half of this before writing my earlier post; I just assumed *you* knew enough that I wouldn't have to show my work. Extra credit: 0: \x80 PROTO 3 2: c GLOBAL 'datetime datetime' 21: q BINPUT 0 23: ( MARK 24: M BININT2 2014 27: K BININT1 9 29: K BININT1 14 31: K BININT1 21 33: K BININT1 6 35: K BININT1 42 37: t TUPLE (MARK at 23) 38: q BINPUT 1 40: R REDUCE 41: q BINPUT 2 43: . STOP From tim.peters at gmail.com Mon Sep 14 21:56:47 2015 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 14 Sep 2015 20:56:47 -0500 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: <1442279996.198469.383712497.36F9DE26@webmail.messagingengine.com> References: <1442085362.324875.381920729.5E7A6DCE@webmail.messagingengine.com> <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> <1442262425.268793.383506657.0443601E@webmail.messagingengine.com> <1442265800.280460.383547057.16B65298@webmail.messagingengine.com> <1442267635.287083.383576201.0990DAA7@webmail.messagingengine.com> <1442279996.198469.383712497.36F9DE26@webmail.messagingengine.com> Message-ID: [Tim] >> Sorry, I'm not arguing about this any more. Pickle doesn't work at >> all at the level of "count of bytes followed by a string". [Random832 ] > The SHORT_BINBYTES opcode consists of the byte b'C', followed by *yes > indeed* "count of bytes followed by a string". Yes, some individual opcodes do work that way. >> If you >> want to make a pickle argument that makes sense, I'm afraid you'll >> need to become familiar with how pickle works first. This is not the >> place for a pickle tutorial. >> >> Start by learning what a datetime pickle actually is. >> pickletools.dis() will be very helpful. > 0: \x80 PROTO 3 > 2: c GLOBAL 'datetime datetime' > 21: q BINPUT 0 > 23: C SHORT_BINBYTES b'\x07\xdf\t\x0e\x15\x06*\x00\x00\x00' > 35: q BINPUT 1 > 37: \x85 TUPLE1 > 38: q BINPUT 2 > 40: R REDUCE > 41: q BINPUT 3 > 43: . STOP > > The payload is ten bytes, and the byte immediately before it is in fact > 0x0a. If I pickle any byte string under 256 bytes long by itself, the > byte immediately before the data is the length. This is how I initially > came to the conclusion that "count of bytes followed by a string" was > valid. Ditto. > I did, before writing my earlier post, look into the high-level aspects > of how datetime pickle works - it uses __reduce__ to create up to two > arguments, one of which is a 10-byte string, and the other is the > tzinfo. Those arguments are passed into the date constructor and > detected by that constructor - for example, I can call it directly with > datetime(b'\x07\xdf\t\x0e\x15\x06*\x00\x00\x00') and get the same result > as unpickling. Good job! That abuse of the constructor was supposed to remain a secret ;-) > At the low level, the part that represents that first argument does > indeed appear to be "count of bytes followed by a string". I can add to > the count, add more bytes, and it will call the constructor with the > longer string. If I use pickletools.dis on my modified value the output > looks the same except for, as expected, the offsets and the value of the > argument to the SHORT_BINBYTES opcode. > > So, it appears that, as I was saying, "wasted space" would not have been > an obstacle to having the "payload" accepted by the constructor (and > produced by __reduce__ ultimately _getstate) consist of "a byte string > of >= 10 bytes, the first 10 of which are used and the rest of which are > ignored by python <= 3.5" instead of "a byte string of exactly 10 > bytes", since it would have accepted and produced exactly the same > pickle values, but been prepared to accept larger arguments pickled from > future versions. Yes, if we had done things differently from the start, things would work differently today. But what's the point? We have to live now with what _was_ done. A datetime pickle carrying a string payload with anything other than exactly 10 bytes will almost always blow up under older Pythons. and would be considered "a bug" if it didn't. Pickles are not at all intended to be forgiving (they're enough of a potential security hole without going out of their way to ignore random mysteries). It may be nicer if Python had a serialization format more deliberately designed for evolution of class structure - but it doesn't. Classes that need such a thing now typically store their own idea of a "version" number as part of their pickled state datetime never did. > ... > So have I shown you that I know enough about the pickle format to know > that permitting a longer string (and ignoring the extra bytes) would > have had zero impact on the pickle representation of values that did not > contain a longer string? Yes. If we had a time machine, it might even have proved useful ;-) > I'd already figured out half of this before > writing my earlier post; I just assumed *you* knew enough that I > wouldn't have to show my work. It's always best to show your work on a public list. Thanks for finally ;-) doing so! From random832 at fastmail.com Mon Sep 14 22:08:58 2015 From: random832 at fastmail.com (Random832) Date: Mon, 14 Sep 2015 22:08:58 -0400 Subject: [Datetime-SIG] Are there any "correct" implementations of tzinfo? In-Reply-To: (Alexander Belopolsky's message of "Mon, 14 Sep 2015 21:42:00 -0400") References: <201509131224.t8DCOXHO004891@fido.openend.se> <201509131600.t8DG07e0025688@fido.openend.se> <201509132031.t8DKVTwJ028027@fido.openend.se> <201509140827.t8E8RPqb001076@fido.openend.se> <1442257996.253100.383441705.7A0986C7@webmail.messagingengine.com> <1442260714.263025.383475777.4728D768@webmail.messagingengine.com> <1442262425.268793.383506657.0443601E@webmail.messagingengine.com> <1442265800.280460.383547057.16B65298@webmail.messagingengine.com> <1442267635.287083.383576201.0990DAA7@webmail.messagingengine.com> <1442279996.198469.383712497.36F9DE26@webmail.messagingengine.com> Message-ID: Alexander Belopolsky writes: > No credit for anything other than the "extra credit" section. Partial > credit for that. Study that printout and you should understand what > Tim was saying. My original claim was that the pickler can't know and doesn't care if a byte string value merely happens to be 10 bytes long for this object, or is 10 bytes long every time, it will encode it with SHORT_BINBYTES ["C", count of bytes, string of bytes] regardless. The datetime constructor itself does care what value is passed to it, but what I was saying was the class could have been written originally to accept optionally longer strings and ignore the extra values, so that future versions could pickle as longer strings and be compatible. In such a case, the actual pickle format would _still_ have consisted of __reduce__() == (datetime, (b"..........", [optional tzinfo])), just with the option of accepting (and ignoring) longer byte strings encoded by later versions of the datetime class. The pickle format is versatile enough to pass any (pickleable) value at all to a constructor (or to __setstate__). Designing the datetime constructor/setstate in the past to be able to accept a byte string of a length other than exactly 10 would have allowed the representation to be extended in the present, rather than smuggling a single extra bit into one of the existing bytes. But it would not have changed the actual representation that would have been produced by pickle back then, not one bit. And, now, to answer my own question from a previous message... >>> class C(): ... def __reduce__(self): ... return (datetime, (b"\x07\xdf\t\x0e\x155'\rA\xb2",)) ... >>> pickle.loads(pickle.dumps(C())) datetime.datetime(2015, 9, 14, 21, 53, 39, 868786) >>> class C(): ... def __reduce__(self): ... return (datetime, (b"\x07\xdf\t\x0e\x955'\rA\xb2",)) ... >>> pickle.loads(pickle.dumps(C())) datetime.datetime(2015, 9, 14, 149, 53, 39, 868786) >>> datetime.strftime(pickle.loads(pickle.dumps(C())), '%Y%m%d%H%M%S') Traceback (most recent call last): File "", line 1, in ValueError: hour out of range That was the bit we were talking about, right? From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Mon Sep 14 22:31:49 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Tue, 15 Sep 2015 03:31:49 +0100 Subject: kivy editable multicolumn list Message-ID: Hi all. Not sure if this is the place to ask about kivy ... I apologize if not. I am playing with the example here https://gist.github.com/geojeff/4442405 Now I would like to change the background color the editable field. So I added def __init__(self,**kwargs): super(EditableLabel,self).__init__(**kwargs) with self.canvas.before: Color(0,1,0) Rectangle(pos=self.pos,size=self.size) print(self.pos,self.size) to class EditableLabel. But when entering __init__ self.pos and self.size do not have the correct pos/size for the EditableLabel. How can I fix this? Please no kv solutions. I need dynamic change it in a real example. Thanks for any help. From skybuck2000 at hotmail.com Mon Sep 14 23:36:23 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Tue, 15 Sep 2015 05:36:23 +0200 Subject: Python handles globals badly. In-Reply-To: <180fe671-7bf9-4544-a3ad-d98a4a497d06@googlegroups.com> References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <52271$55f3b6a0$d47876e2$40653@news.ziggo.nl> <8d648$55f56643$d47876e2$38352@news.ziggo.nl> <55f566c8$0$1644$c3e8da3$5496439d@news.astraweb.com> <60a52$55f567d6$d47876e2$43011@news.ziggo.nl> <180fe671-7bf9-4544-a3ad-d98a4a497d06@googlegroups.com> Message-ID: "Ned Batchelder" wrote in message news:180fe671-7bf9-4544-a3ad-d98a4a497d06 at googlegroups.com... On Sunday, September 13, 2015 at 8:11:13 AM UTC-4, Skybuck Flying wrote: > I don't even understand how python interpreter works but I can understand > it > better than you guys do apperently hahaha. " As tempting as it is to respond to Skybuck, with a brief pause to consider, and a deep breath, I'm sure we can all agree that there is no point in it. Skybuck: go in peace, and thanks for being part of the Python community. " Go in Peace yourself From dieter at handshake.de Tue Sep 15 01:46:06 2015 From: dieter at handshake.de (dieter) Date: Tue, 15 Sep 2015 07:46:06 +0200 Subject: Packaging and deployment of standalone Python applications? References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> Message-ID: <87a8sos09t.fsf@handshake.de> Kristian Rink writes: > Folks; > > coming from a server-sided Java background, I'm recently exploring frameworks such as cherrypy or webpy for building RESTful services, which is quite a breeze and a pretty pleasant experience; however one thing so far bugs me: Using Java tooling and libraries such as DropWizard, it is pretty straightforward to build an "all-inclusive" application containing (a) all code of my own, (b) all required dependencies, (c) all other resources and, if required, even (d) a Java virtual machine in one large .zip file which can easily be copied to a clean Linux VM, unzipped and started there. > > Are there ways of doing so using Python, too? I do not think that the Python support in this regard is as sophisticated as in the Java world. Have a look at "distribute/setuptools". It supports (a) and (b) (event though you must write a "setup.py" without the help of an UI) and allows to state the dependencies (part of (c)). It can generate a so called "egg" (a distribution unit) representing one distributable component. On installation, you still need a local Python (with its runtime environment) and the installation process will try to resolve the stated dependencies - potentially requiring internet access. In order to get one executable containing the Python interpreter and all required packages, there is "freeze" (and when I remember right a solution provided by "eGenix"). However, you must manually prepare the application such that "freeze" learns about the "required packages". "freeze" is likely too old that it already would interprete the dependency declarations. You might also have a look at "zc.buildout". Its primary task is to ensure the setup of a consistent development/deployment environment across different environments (hosts). It relies on a local Python installation - but can handle almost everything else. Again - without UI support. From auriocus at gmx.de Tue Sep 15 02:17:55 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 15 Sep 2015 08:17:55 +0200 Subject: Packaging and deployment of standalone Python applications? In-Reply-To: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> Message-ID: Am 14.09.15 um 08:58 schrieb Kristian Rink: > Folks; > > coming from a server-sided Java background, I'm recently exploring > frameworks such as cherrypy or webpy for building RESTful services, > which is quite a breeze and a pretty pleasant experience; however one > thing so far bugs me: Using Java tooling and libraries such as > DropWizard, it is pretty straightforward to build an "all-inclusive" > application containing (a) all code of my own, (b) all required > dependencies, (c) all other resources and, if required, even (d) a > Java virtual machine in one large .zip file which can easily be > copied to a clean Linux VM, unzipped and started there. > > Are there ways of doing so using Python, too? I'd like to set up a > project structure / working environment that includes all Python 3rd > party libraries, my own code and maybe even a "standard" Python > runtime for 64bit Linux systems (to not depend too much on what > version a certain Linux distribution actually ships) and focus on > doing deployment to various machines at best by simply copying these > packages around. > > Any pointers, ideas, inspirations on that greatly appreciated - even > in total different ways if what I am about to do is completely off > anyone would do it in a Python environment. ;) Look at pyinstaller. It creates monsters (i.e. really huge single file or single directory builds), but it works for my projects. Christian From paul.hermeneutic at gmail.com Tue Sep 15 02:59:15 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Tue, 15 Sep 2015 00:59:15 -0600 Subject: Packaging and deployment of standalone Python applications? In-Reply-To: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> Message-ID: This might be helpful. https://docs.python.org/3/distributing/index.html See also https://docs.python.org/3/library/venv.html?highlight=venv#module-venv Folks; coming from a server-sided Java background, I'm recently exploring frameworks such as cherrypy or webpy for building RESTful services, which is quite a breeze and a pretty pleasant experience; however one thing so far bugs me: Using Java tooling and libraries such as DropWizard, it is pretty straightforward to build an "all-inclusive" application containing (a) all code of my own, (b) all required dependencies, (c) all other resources and, if required, even (d) a Java virtual machine in one large .zip file which can easily be copied to a clean Linux VM, unzipped and started there. Are there ways of doing so using Python, too? I'd like to set up a project structure / working environment that includes all Python 3rd party libraries, my own code and maybe even a "standard" Python runtime for 64bit Linux systems (to not depend too much on what version a certain Linux distribution actually ships) and focus on doing deployment to various machines at best by simply copying these packages around. Any pointers, ideas, inspirations on that greatly appreciated - even in total different ways if what I am about to do is completely off anyone would do it in a Python environment. ;) TIA and all the best, Kristian -- https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From David.Aldrich at EMEA.NEC.COM Tue Sep 15 03:44:21 2015 From: David.Aldrich at EMEA.NEC.COM (David Aldrich) Date: Tue, 15 Sep 2015 07:44:21 +0000 Subject: kivy editable multicolumn list In-Reply-To: References: Message-ID: <41302A7145AC054FA7A96CFD03835A0A0B9D5EFA@EX10MBX02.EU.NEC.COM> > Not sure if this is the place to ask about kivy ... Try the kivy users list here: https://groups.google.com/forum/#!forum/kivy-users Best regards David From jondy.zhao at gmail.com Tue Sep 15 05:21:55 2015 From: jondy.zhao at gmail.com (Jondy Zhao) Date: Tue, 15 Sep 2015 02:21:55 -0700 (PDT) Subject: Pyarmor, guard your python scripts Message-ID: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Pyarmor is a simple to use tool which is capable of importing or running encrypted Python script files. Moreover, it can apply encoding algorithms to your Python scripts, in order to help you protect them before you can distribute them. You may also generate license files with custom validity conditions. Python protector application Pyarmor is dedicated to users who create their applications, components, scripts or any file with the help of the Python programming language. You may use this application to encrypt the files, in order to protect their content and your intellectual property, by encoding the scripts. Pyarmor uses two alternative methods of applying protection: converting the Python script file to an encrypted type of item, with the .PYX extension. Otherwise, you may add specific files to the script and distribute it as a package: the program can create and attach license files, with various validity terms. Change the shape, not the content While Pyarmor can modify the package in which the Python script is distributed, it hardly applies any modifications to the script itself. In fact, the program is not a script editor and does not allow you to make changes within the files. The program allows you to encrypt files, but to also open and run them as if no protection was applied. Moreover, it can run or import encrypted Python scripts in any target machine, only in specified machines or before a specified date. This aspect can be controlled by the creation of the license files: bound to a hard disk serial number or by an expiration date. Simple to use application Pyarmor comes as a wizard, which can guide you through all the steps of the process, for your convenience. The steps are not restricted by certain requirements, so you may easily skip either of them and customize the process. Moreover, the program allows you to save the files at any location on your computer. For more information, search pyarmor in pypi. From hv at tbz-pariv.de Tue Sep 15 05:35:39 2015 From: hv at tbz-pariv.de (=?ISO-8859-1?Q?Thomas_G=FCttler?=) Date: Tue, 15 Sep 2015 02:35:39 -0700 (PDT) Subject: From logging to files to a better solution: syslog, Sentry, Logstash, .... In-Reply-To: References: <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> Message-ID: Am Freitag, 11. September 2015 11:03:52 UTC+2 schrieb jmp: > On 09/11/2015 09:22 AM, Thomas G?ttler wrote: > > > > I want INFO to be logged and stored on the remote host. > > Therefore I must not filter INFO messages. > > > > I don't want to pull INFO messages over the VPN. > > > > Ergo, the filtering at Python level does not help in my use case. > > Or I am missing something. > > Probably, > > Your logger should have > > * a remote host handler > * and a VPN handler. > > You can set filters and log levels separately for each handler. > More info here > https://docs.python.org/2/library/logging.html#handler-objects > https://docs.python.org/2/howto/logging-cookbook.html#logging-to-multiple-destinations > > Something like (python 2.7) > > import logging > > logCfg = { > 'remote':( > logging.StreamHandler(), > logging.Formatter('Remote - %(levelname)s - %(message)s'), > logging.INFO, > ), > 'vpn':( > logging.StreamHandler(), > logging.Formatter('VPN - %(levelname)s - %(message)s'), > logging.ERROR, > ), > } .... Yes, I could do it this way. But somehow I am not happy with this solution. I think the filtering should be outside of python. I like DevOp, but sometimes clear responsibilities help to cut big problems into smaller ones. I would like to handle the log message filtering outside of python. Can you understand my concerns? Thomas G?ttler From ben+python at benfinney.id.au Tue Sep 15 05:36:21 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 15 Sep 2015 19:36:21 +1000 Subject: Pyarmor, guard your python scripts References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: <857fns58iy.fsf@benfinney.id.au> Jondy Zhao writes: > Pyarmor is a simple to use tool which is capable of importing or > running encrypted Python script files. Moreover, it can apply encoding > algorithms to your Python scripts, in order to help you protect them > before you can distribute them. You may also generate license files > with custom validity conditions. Protect them from whom? What is the threat model against which Pyarmor is claimed to protect? Who is the attacker, who is being protected? > The program allows you to encrypt files, but to also open and run them > as if no protection was applied. Moreover, it can run or import > encrypted Python scripts in any target machine, only in specified > machines or before a specified date. This aspect can be controlled by > the creation of the license files: bound to a hard disk serial number > or by an expiration date. So a Python file encrypted this way will be arbitrarily restricted in how it can be inspected for debugging, performance monitoring, and testing? This seems to explicitly treat the user of the Python software as a hostile attacker. That is not a friendly or respectful position, and I hope I misunderstand Pyarmor's operation. -- \ ?Any fool can write code that a computer can understand. Good | `\ programmers write code that humans can understand.? ?Martin | _o__) Fowler, _Refactoring_, 2000 | Ben Finney From hv at tbz-pariv.de Tue Sep 15 05:37:13 2015 From: hv at tbz-pariv.de (=?ISO-8859-1?Q?Thomas_G=FCttler?=) Date: Tue, 15 Sep 2015 02:37:13 -0700 (PDT) Subject: From logging to files to a better solution: syslog, Sentry, Logstash, .... In-Reply-To: <681f390f-9f1d-4968-8226-41db62ae0f9e@googlegroups.com> References: <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> <681f390f-9f1d-4968-8226-41db62ae0f9e@googlegroups.com> Message-ID: <6e71dffa-ab27-4399-8aeb-7889e76214d6@googlegroups.com> Am Freitag, 11. September 2015 10:18:11 UTC+2 schrieb marco.... at colosso.nl: > On Friday, September 11, 2015 at 9:22:42 AM UTC+2, Thomas G?ttler wrote: > > Am Donnerstag, 10. September 2015 08:42:47 UTC+2 schrieb dieter: > > > Thomas G?ttler writes: > > > > ... > > > > Why we are unhappy with logging to files: > > > > > > > > - filtering: We don't want to get INFO messages over the VPN. > > > > > > You can quite easily control at what level messages are logged with > > > the standard Python logging framework. Each handler has a level > > > and will ignore messages at a lower level. > > > > > > I want INFO to be logged and stored on the remote host. > > Therefore I must not filter INFO messages. > > > > I don't want to pull INFO messages over the VPN. > > > > Ergo, the filtering at Python level does not help in my use case. > > Or I am missing something. > > > > And now I have an ugly soup. > > > > The ugly soup is a text file with not well defined syntax. It looks line > > based. But sometimes there are log messages which span multiple lines .... > > > > Remember: "Life is too short to (re)write parsers" > > > > Yes, there are tools to parse that soup. But why create this soup in > > the first place? > > > > That's why I want to move from file based logging to a different solution. > > > > Unfortunately there too many choices (graylog, logstash, sentry, ...) :-( > > > > > > > > > > - Rotating: Rotating files is possible, but somehow cumbersome. > > > > > > There are standard tools to rotate logfiles. > > > > > > > - Support structured logging of values (json) in the future. > > > > > > Again, the Python logging framework is quite flexible with > > > respect to the format of logged messages. > > > > > > > ... > > > > Which solution could fit for our environment? > > > > > > I work for a customer with a similar environment (he uses "Zope" instead > > > of "Django") - and he uses logfiles. The logfiles are automatically > > > rotated and there are in the order of half a dozen to a dozen logfiles > > > per day. > > > > > > When I have to analyse a problem with the help of the logfiles, > > > I do not copy them via VPN but do the filtering remotely and only > > > copy the filtered portion, if necessary. > > > > Good to know that I am not the only one running servers in remote intranets. > > > > Regards, > > Thomas G?ttler > > So, if logging to json is on the horizon anyway, why don't you create > something like a MongoDb handler in the standard Python logging framework > and run a MongoDb server in the client intranet? You could then connect > over VPN to MongoDb, filter the warning/error messages there on the server > side and fetch them to your local systems for analysis. Yes I could set up a MongoDB server. But I would like to reuse and not to reinvent. I would like to go a proven solid road. From rosuav at gmail.com Tue Sep 15 05:48:57 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Sep 2015 19:48:57 +1000 Subject: Pyarmor, guard your python scripts In-Reply-To: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: On Tue, Sep 15, 2015 at 7:21 PM, Jondy Zhao wrote: > Pyarmor is dedicated to users who create their applications, components, scripts or any file with the help of the Python programming language. You may use this application to encrypt the files, in order to protect their content and your intellectual property, by encoding the scripts. > > > The program allows you to encrypt files, but to also open and run them as if no protection was applied. If they can be run as if no protection had been applied, that presumably means the loader is capable of decrypting them, right? So what's to stop anyone from reading the loader, using it to decrypt the actual code, and running it? ChrisA From lac at openend.se Tue Sep 15 06:42:47 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 15 Sep 2015 12:42:47 +0200 Subject: kivy editable multicolumn list In-Reply-To: References: Message-ID: <201509151042.t8FAglgs009144@fido.openend.se> In a message of Tue, 15 Sep 2015 03:31:49 +0100, Paulo da Silva writes: >Hi all. >Not sure if this is the place to ask about kivy ... >I apologize if not. > >I am playing with the example here >https://gist.github.com/geojeff/4442405 > >Now I would like to change the background color the editable field. > >So I added > def __init__(self,**kwargs): > super(EditableLabel,self).__init__(**kwargs) > with self.canvas.before: > Color(0,1,0) > Rectangle(pos=self.pos,size=self.size) > print(self.pos,self.size) > >to class EditableLabel. > >But when entering __init__ self.pos and self.size do not have the >correct pos/size for the EditableLabel. > >How can I fix this? Please no kv solutions. I need dynamic change it in >a real example. I am not sure what you want for your integers_dict. It isn't the something that Rob Collins fixtures package provides. :) https://pypi.python.org/pypi/fixtures I just hardcoded it like this: integers_dict = {str(i): {'text': str(i), 'is_selected': False} for i in range(100)} which I pasted out of http://kivy.org/docs/api-kivy.uix.listview.html 'Using an Item View Template'. This may have no relation to what you really want. you also need a line from kivy.graphics import Color, Rectangle Then you change your class definition to be: class EditableLabel(ListItemLabel): def __init__(self,**kwargs): super(EditableLabel, self).__init__(**kwargs) self.bind(pos=self.redraw) self.bind(size=self.redraw) def redraw(self, *args): self.canvas.clear() with self.canvas: Color(.5,.5,.5) Rectangle(pos=self.pos,size=self.size) I don't know why changing self.canvas.before: to self.canvas: in the redraw method was needed here. I expected self.canvas.before to be what was needed, but doesn't seem that way. If you don't clear the canvas first, in the redraw the results look very silly to me. However, since you are just playing around to learn things, then that behaviour may be what you are looking for, so comment it out and see if you like that better. HTH, Laura From sp4soft at gmail.com Tue Sep 15 06:43:00 2015 From: sp4soft at gmail.com (Serj) Date: Tue, 15 Sep 2015 13:43:00 +0300 Subject: broken install? Message-ID: <55F7F634.9040008@gmail.com> Hi there! I just downloaded 3.5.0 install package for Win32 (python-3.5.0-webinstall.exe) and I see some strange behaviour under Win XP: there is no "Next" or "Run" button in wizard ))) Clicked into space near "Cancel" I opened "options" screen, while clicked in another place (closer to center of window) setup started without any options at all ))) Screen is attached below -- Best Regards Serj -------------- next part -------------- A non-text attachment was scrubbed... Name: Clipboard01.png Type: image/png Size: 37112 bytes Desc: not available URL: From marco.nawijn at colosso.nl Tue Sep 15 07:25:43 2015 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Tue, 15 Sep 2015 04:25:43 -0700 (PDT) Subject: Packaging and deployment of standalone Python applications? In-Reply-To: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> Message-ID: On Monday, September 14, 2015 at 8:58:51 AM UTC+2, Kristian Rink wrote: > Folks; > > coming from a server-sided Java background, I'm recently exploring frameworks such as cherrypy or webpy for building RESTful services, which is quite a breeze and a pretty pleasant experience; however one thing so far bugs me: Using Java tooling and libraries such as DropWizard, it is pretty straightforward to build an "all-inclusive" application containing (a) all code of my own, (b) all required dependencies, (c) all other resources and, if required, even (d) a Java virtual machine in one large .zip file which can easily be copied to a clean Linux VM, unzipped and started there. > > Are there ways of doing so using Python, too? I'd like to set up a project structure / working environment that includes all Python 3rd party libraries, my own code and maybe even a "standard" Python runtime for 64bit Linux systems (to not depend too much on what version a certain Linux distribution actually ships) and focus on doing deployment to various machines at best by simply copying these packages around. > > Any pointers, ideas, inspirations on that greatly appreciated - even in total different ways if what I am about to do is completely off anyone would do it in a Python environment. ;) > > TIA and all the best, > Kristian If your business-cases allows it, I would seriously consider using Docker. I makes it pretty straightforward to move your deployments around from your development machine, to a test setup, to a cloud provider (e.g. AWS) etc. Lack or incomplete support on Windows systems is a little bit a deal breaker, but this situation is improving quickly. Marco From robin at reportlab.com Tue Sep 15 07:38:59 2015 From: robin at reportlab.com (Robin Becker) Date: Tue, 15 Sep 2015 12:38:59 +0100 Subject: how to build windows extensions for python 3.5 In-Reply-To: References: <55F6ED53.9080103@chamonix.reportlab.co.uk> Message-ID: <55F80353.9080609@chamonix.reportlab.co.uk> On 14/09/2015 17:26, Mark Lawrence wrote: > On 14/09/2015 16:52, Robin Becker wrote: ....... > > http://stevedower.id.au/blog/building-for-python-3-5-part-two/ > > The most important thing is to have something to do while the Visual > Studio installation takes up 8G of your disk space and several hours of elapsed > time. At least the installation went smoothly. > thanks -- Robin Becker From arfprogrammer at gmail.com Tue Sep 15 07:54:59 2015 From: arfprogrammer at gmail.com (AliReza Firuzabadi) Date: Tue, 15 Sep 2015 04:54:59 -0700 (PDT) Subject: Horizontal Scalability in python Message-ID: <437764bd-7a2c-44d0-905e-8a7c8e99397e@googlegroups.com> I am new in tornado and I want to make web application with tornado and want to scale one instance of tornado application to many in separated servers. I should have load balancer and it send client requests to servers. please tell me how can I do it in the best way. thank you for helping me. From iurisilvio at gmail.com Tue Sep 15 08:02:43 2015 From: iurisilvio at gmail.com (Iuri) Date: Tue, 15 Sep 2015 09:02:43 -0300 Subject: Horizontal Scalability in python In-Reply-To: <437764bd-7a2c-44d0-905e-8a7c8e99397e@googlegroups.com> References: <437764bd-7a2c-44d0-905e-8a7c8e99397e@googlegroups.com> Message-ID: You can do it with nginx. Tornado has some docs about it: http://tornado.readthedocs.org/en/latest/guide/running.html#running-behind-a-load-balancer Also, nginx has extensive documentation about the topic; https://www.nginx.com/resources/admin-guide/load-balancer/ Cheers! On Tue, Sep 15, 2015 at 8:54 AM, AliReza Firuzabadi wrote: > I am new in tornado and I want to make web application with tornado and > want to scale one instance of tornado application to many in separated > servers. I should have load balancer and it send client requests to > servers. please tell me how can I do it in the best way. > thank you for helping me. > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Tue Sep 15 08:04:19 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 15 Sep 2015 14:04:19 +0200 Subject: Packaging and deployment of standalone Python applications? In-Reply-To: References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> Message-ID: <201509151204.t8FC4Jal029387@fido.openend.se> >On Monday, September 14, 2015 at 8:58:51 AM UTC+2, Kristian Rink wrote: >> Folks; coming from a server-sided Java background, I'm recently >> exploring frameworks such as cherrypy or webpy for building RESTful >> services, which is quite a breeze and a pretty pleasant experience; >> however one thing so far bugs me: Using Java tooling and libraries >> such as DropWizard, it is pretty straightforward to build an >> "all-inclusive" application containing (a) all code of my own, (b) >> all required dependencies, (c) all other resources and, if >> required, even (d) a Java virtual machine in one large .zip file >> which can easily be copied to a clean Linux VM, unzipped and >> started there. Are there ways of doing so using Python, too? I'd >> like to set up a project structure / working environment that >> includes all Python 3rd party libraries, my own code and maybe even >> a "standard" Python runtime for 64bit Linux systems (to not depend >> too much on what version a certain Linux distribution actually >> ships) and focus on doing deployment to various machines at best by >> simply copying these packages around. Your main problem may not be technical, but political. PyInstaller will do what you want, and docker is really really interesting, but many linux users really detest the idea of getting a huge package which duplicates stuff they already have installed on their system. And it isn't something they are used to -- it is rarely done. Instead, they will want you to send them a .deb or a .rpm (whatever their OS package manager wants) or they will want a PyPI package. If you are distributing them python source, then rather than have you build them an app, they are more likely to want instructions for what are the dependencies so they can build your app itself, and also control whether or not to install the dependencies you require system-wide or in a virtualenv. You know your own situation best, but if you are aiming for widespread adoption by linux users everywhere, well, I am just warning you that they aren't going to like it. (Unless docker, which is very new, turns into The Next Big Thing, which I suppose always could happen.) Laura From gandalf at shopzeus.com Tue Sep 15 08:18:46 2015 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Tue, 15 Sep 2015 14:18:46 +0200 Subject: {Spam?} Re: need help with selenium In-Reply-To: References: Message-ID: <55F80CA6.2000003@shopzeus.com> > After clicking on submit button, a message is displayed on the same page whether login was successful or not. > However after clicking on submit button, I lose control over the web page. I can't use any selenium functions now like 'driver.find_element_by_name()'. You need to wait until the submit completes. Firefox works in paralel in the background, so don't expect the new page to be loaded right after you called .submit(). One way to do it is this: after calling submit, call this: self.browser.find_element_by_tag_name("body") This call will return ONLY if the page has completed loading. Then you can get page_source or do whatever you want. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From invalid at invalid.invalid Tue Sep 15 09:16:11 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 15 Sep 2015 13:16:11 +0000 (UTC) Subject: Pyarmor, guard your python scripts References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: On 2015-09-15, Chris Angelico wrote: > On Tue, Sep 15, 2015 at 7:21 PM, Jondy Zhao wrote: >> Pyarmor is dedicated to users who create their applications, components, scripts or any file with the help of the Python programming language. You may use this application to encrypt the files, in order to protect their content and your intellectual property, by encoding the scripts. >> >> The program allows you to encrypt files, but to also open and run >> them as if no protection was applied. > > If they can be run as if no protection had been applied, that > presumably means the loader is capable of decrypting them, right? So > what's to stop anyone from reading the loader, using it to decrypt > the actual code, and running it? I rather expect the answer to that questions is "laziness". It's like the lock on my front door. It's not going to stop anybody who really wants to get in, but it will prevent the idle curious from wandering in and messing about with my stuff. -- Grant Edwards grant.b.edwards Yow! Are we on STRIKE yet? at gmail.com From rosuav at gmail.com Tue Sep 15 09:29:25 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Sep 2015 23:29:25 +1000 Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: On Tue, Sep 15, 2015 at 11:16 PM, Grant Edwards wrote: > On 2015-09-15, Chris Angelico wrote: >> On Tue, Sep 15, 2015 at 7:21 PM, Jondy Zhao wrote: >>> Pyarmor is dedicated to users who create their applications, components, scripts or any file with the help of the Python programming language. You may use this application to encrypt the files, in order to protect their content and your intellectual property, by encoding the scripts. >>> >>> The program allows you to encrypt files, but to also open and run >>> them as if no protection was applied. >> >> If they can be run as if no protection had been applied, that >> presumably means the loader is capable of decrypting them, right? So >> what's to stop anyone from reading the loader, using it to decrypt >> the actual code, and running it? > > I rather expect the answer to that questions is "laziness". > > It's like the lock on my front door. It's not going to stop anybody > who really wants to get in, but it will prevent the idle curious from > wandering in and messing about with my stuff. Maybe. It seems more like having a lock on your front door, with the key permanently inside it. But maybe that's just me. In any case, this needs to be clear about how much security it's actually offering. ChrisA From robin at reportlab.com Tue Sep 15 09:32:16 2015 From: robin at reportlab.com (Robin Becker) Date: Tue, 15 Sep 2015 14:32:16 +0100 Subject: how to build windows extensions for python 3.5 In-Reply-To: <55F80353.9080609@chamonix.reportlab.co.uk> References: <55F6ED53.9080103@chamonix.reportlab.co.uk> <55F80353.9080609@chamonix.reportlab.co.uk> Message-ID: <55F81DE0.5050100@chamonix.reportlab.co.uk> On 15/09/2015 12:38, Robin Becker wrote: > On 14/09/2015 17:26, Mark Lawrence wrote: >> On 14/09/2015 16:52, Robin Becker wrote: > ....... >> >> http://stevedower.id.au/blog/building-for-python-3-5-part-two/ >> >> The most important thing is to have something to do while the Visual >> Studio installation takes up 8G of your disk space and several hours of elapsed >> time. At least the installation went smoothly. >> > > thanks Mark's reference seems more directed at designers of the compilation steps for the extension. From Zachary's comment it seems I should be able to build with distutils without too much trouble. However, I try to link bits of various libraries statically into the reportlab extensions eg freetype.lib. Does anyone know if I will need separate versions of those for VS2015? Currently I build with distutils for Python 27, 33 & 34. Currently the .libs seem OK with both 2.7 & >=3.3 builds, but I notice from the reference that all the code for VS2015 needs to be built with specific options set, so will I need separate versions of the relocatable libs? -- Robin Becker From chris at simplistix.co.uk Tue Sep 15 09:54:55 2015 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 15 Sep 2015 14:54:55 +0100 Subject: testfixtures 4.3.0 Released! Message-ID: <55F8232F.4090308@simplistix.co.uk> Hi All, I'm pleased to announce the release of testfixtures 4.3.0. This is a feature release that adds the following: - Add TempDirectory.compare with a cleaner, more explicit API that allows comparison of only the files in a temporary directory. - Deprecate TempDirectory.check, TempDirectory.check_dir and TempDirectory.check_all - Relax absolute-path rules so that if it's inside the TempDirectory, it's allowed. - Allow OutputCapture to separately check output to stdout and stderr. The package is on PyPI and a full list of all the links to docs, issue trackers and the like can be found here: https://github.com/Simplistix/testfixtures Any questions, please do ask on the Testing in Python list or on the Simplistix open source mailing list... cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk From steve at pearwood.info Tue Sep 15 10:14:18 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 16 Sep 2015 00:14:18 +1000 Subject: Terminology: "reference" versus "pointer" References: <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <55f6fdd9$0$1640$c3e8da3$5496439d@news.astraweb.com> <1442252093.231783.383350001.6CF3FF6F@webmail.messagingengine.com> Message-ID: <55f827bb$0$1671$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Sep 2015 04:02 am, Random832 wrote: > The point is that with immutable objects no-one cares if they are three > objects with the same value, or three references to the same object. Well, you might care... a = (1,)*(10**12) b = (1,)*(10**12) c = (1,)*(10**12) Each of those tuples would require a rather lot of memory. The difference between "a lot" and "three times a lot" could be significant. But other than memory efficiency, yes, you are correct, there's no real reason to care about the difference between the two cases. -- Steven From steve at pearwood.info Tue Sep 15 10:26:32 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 16 Sep 2015 00:26:32 +1000 Subject: Terminology: "reference" versus "pointer" References: <85mvws6z45.fsf_-_@benfinney.id.au> <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <55f6fdd9$0$1640$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f82a98$0$1672$c3e8da3$5496439d@news.astraweb.com> On Tue, 15 Sep 2015 03:34 am, Random832 wrote: > On Mon, Sep 14, 2015, at 13:03, Steven D'Aprano wrote: >> On Tue, 15 Sep 2015 01:10 am, Random832 wrote: >> > That's not true in CPython. In fact, the range object in python >> > contains *four* reference boxes - one more for length. >> >> I really don't see why any of this is relevant to the business being >> discussed. > > When you're drawing this sort of diagram then what references are held > by an object are more important than what interfaces it implements. Hmmm. Well, that's going to be tricky then, at least for some objects. Take a function object, for example: +-----------------+ func --------> | function object | +-----------------+ Nice and simple if you draw it like that. Or: +-------------------+ func --------> | function object | | -|-------> ... +-|----------|--|---+ | | | | | +---> ... V | +---------+ | | __doc__ | +------> ... +---------+ Due to laziness, the diagram is incomplete. But here is a partial list of references held by each function object. For brevity, I have not included the leading and trailing underscores: doc (string, or None); annotations (dict mapping strings to arbitrary objects); class (type object); closure (None, or closure object); code (code object) dict (dict mapping strings to arbitrary objects); module (string) name (string) and various more. Some of them, such as __code__, themselves include references to many other objects. Even relatively small diagrams with only a few objects could easily expand in complexity. > > Personally I think it's a bit silly to insist on a diagram model where a > box with an arrow in it pointing at an int object can't be represented > by a box with an integer in it (where 'int' is any immutable type - > string, tuple, even range), but people don't like boxes with integers in > them for some reason. What's wrong with this? +------+ myint ---------------> | 23 | +------+ -- Steven From jeanmichel at sequans.com Tue Sep 15 10:36:46 2015 From: jeanmichel at sequans.com (jmp) Date: Tue, 15 Sep 2015 16:36:46 +0200 Subject: From logging to files to a better solution: syslog, Sentry, Logstash, .... In-Reply-To: References: <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> Message-ID: On 09/15/2015 11:35 AM, Thomas G?ttler wrote: > > .... Yes, I could do it this way. > > But somehow I am not happy with this solution. > > I think the filtering should be outside of python. [snip] > Can you understand my concerns? > > Thomas G?ttler > No, not really. I showed you how it can be done in python using standard logging technics. Others have also provided suggestions and you've also dismissed those with a "I don't feel like it". Remember this is a python mailing list hence if you're looking for help about a non python log infrastructure, you probably find better answers in those said log infrastructures mailing lists. JM From zachary.ware+pylist at gmail.com Tue Sep 15 11:54:13 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Tue, 15 Sep 2015 10:54:13 -0500 Subject: how to build windows extensions for python 3.5 In-Reply-To: <55F81DE0.5050100@chamonix.reportlab.co.uk> References: <55F6ED53.9080103@chamonix.reportlab.co.uk> <55F80353.9080609@chamonix.reportlab.co.uk> <55F81DE0.5050100@chamonix.reportlab.co.uk> Message-ID: On Tue, Sep 15, 2015 at 8:32 AM, Robin Becker wrote: > However, I try to link bits of various libraries statically into the > reportlab extensions eg freetype.lib. Does anyone know if I will need > separate versions of those for VS2015? Currently I build with distutils for > Python 27, 33 & 34. Currently the .libs seem OK with both 2.7 & >=3.3 > builds, but I notice from the reference that all the code for VS2015 needs > to be built with specific options set, so will I need separate versions of > the relocatable libs? I'm a bit surprised that you can successfully use the same .libs for 2.7 and 3.3/3.4. But since that seems to work, I'd say go ahead and try it with 3.5, and if the build succeeds test the crap out of it :) -- Zach From robin at reportlab.com Tue Sep 15 12:03:58 2015 From: robin at reportlab.com (Robin Becker) Date: Tue, 15 Sep 2015 17:03:58 +0100 Subject: how to build windows extensions for python 3.5 In-Reply-To: References: <55F6ED53.9080103@chamonix.reportlab.co.uk> <55F80353.9080609@chamonix.reportlab.co.uk> <55F81DE0.5050100@chamonix.reportlab.co.uk> Message-ID: <55F8416E.6010901@chamonix.reportlab.co.uk> On 15/09/2015 16:54, Zachary Ware wrote: > On Tue, Sep 15, 2015 at 8:32 AM, Robin Becker wrote: ........ > > I'm a bit surprised that you can successfully use the same .libs for > 2.7 and 3.3/3.4. But since that seems to work, I'd say go ahead and > try it with 3.5, and if the build succeeds test the crap out of it :) > I've downloaded the vs2015 iso from msdn and I'll give the install a try tomorrow. It can't be that hard to build our extensions since Christoph Golhke has done a reportlab wheel for 3.5 at http://www.lfd.uci.edu/~gohlke/pythonlibs/ -- Robin Becker From invalid at invalid.invalid Tue Sep 15 12:20:31 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 15 Sep 2015 16:20:31 +0000 (UTC) Subject: Pyarmor, guard your python scripts References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: On 2015-09-15, Chris Angelico wrote: > On Tue, Sep 15, 2015 at 11:16 PM, Grant Edwards wrote: >> On 2015-09-15, Chris Angelico wrote: >>> On Tue, Sep 15, 2015 at 7:21 PM, Jondy Zhao wrote: >>>> Pyarmor is dedicated to users who create their applications, components, scripts or any file with the help of the Python programming language. You may use this application to encrypt the files, in order to protect their content and your intellectual property, by encoding the scripts. >>>> >>>> The program allows you to encrypt files, but to also open and run >>>> them as if no protection was applied. >>> >>> If they can be run as if no protection had been applied, that >>> presumably means the loader is capable of decrypting them, right? So >>> what's to stop anyone from reading the loader, using it to decrypt >>> the actual code, and running it? >> >> I rather expect the answer to that questions is "laziness". >> >> It's like the lock on my front door. It's not going to stop anybody >> who really wants to get in, but it will prevent the idle curious from >> wandering in and messing about with my stuff. > > Maybe. It seems more like having a lock on your front door, with the > key permanently inside it. But maybe that's just me. I you may be underestimating the laziness and overestimating the cleverness of most people. ;) -- Grant Edwards grant.b.edwards Yow! Is this sexual at intercourse yet?? Is it, gmail.com huh, is it?? From chris at simplistix.co.uk Tue Sep 15 12:28:05 2015 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 15 Sep 2015 17:28:05 +0100 Subject: testfixtures 4.3.3 Released! In-Reply-To: <55F8232F.4090308@simplistix.co.uk> References: <55F8232F.4090308@simplistix.co.uk> Message-ID: <55F84715.7090003@simplistix.co.uk> Sorry, the move to using Travis CI was not without bumps, and we're now on 4.3.3, which should be correctly built, including docs up on http://testfixtures.readthedocs.org/. Apologies for the noise... Chris On 15/09/2015 14:54, Chris Withers wrote: > Hi All, > > I'm pleased to announce the release of testfixtures 4.3.0. This is a > feature release that adds the following: > > - Add TempDirectory.compare with a cleaner, more explicit API that > allows comparison of only the files in a temporary directory. > > - Deprecate TempDirectory.check, TempDirectory.check_dir > and TempDirectory.check_all > > - Relax absolute-path rules so that if it's inside the TempDirectory, > it's allowed. > > - Allow OutputCapture to separately check output to stdout and > stderr. > > The package is on PyPI and a full list of all the links to docs, issue > trackers and the like can be found here: > > https://github.com/Simplistix/testfixtures > > Any questions, please do ask on the Testing in Python list or on the > Simplistix open source mailing list... > > cheers, > > Chris > From rosuav at gmail.com Tue Sep 15 12:29:21 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Sep 2015 02:29:21 +1000 Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: On Wed, Sep 16, 2015 at 2:20 AM, Grant Edwards wrote: > On 2015-09-15, Chris Angelico wrote: >> On Tue, Sep 15, 2015 at 11:16 PM, Grant Edwards wrote: >>> On 2015-09-15, Chris Angelico wrote: >>>> If they can be run as if no protection had been applied, that >>>> presumably means the loader is capable of decrypting them, right? So >>>> what's to stop anyone from reading the loader, using it to decrypt >>>> the actual code, and running it? >>> >>> I rather expect the answer to that questions is "laziness". >>> >>> It's like the lock on my front door. It's not going to stop anybody >>> who really wants to get in, but it will prevent the idle curious from >>> wandering in and messing about with my stuff. >> >> Maybe. It seems more like having a lock on your front door, with the >> key permanently inside it. But maybe that's just me. > > I you may be underestimating the laziness and overestimating the > cleverness of most people. ;) Heh :) But in that case, you can probably get away with just zipimport. Deflation sure isn't encryption, but the code is pretty thoroughly concealed anyway. ChrisA From invalid at invalid.invalid Tue Sep 15 12:40:37 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 15 Sep 2015 16:40:37 +0000 (UTC) Subject: Pyarmor, guard your python scripts References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: On 2015-09-15, Chris Angelico wrote: > >> I you may be underestimating the laziness and overestimating the >> cleverness of most people. ;) > > Heh :) But in that case, you can probably get away with just > zipimport. Deflation sure isn't encryption, but the code is pretty > thoroughly concealed anyway. I agree completely. There are three categories of protection: 1) The program never leaves your computer. 2) Obfuscation to deter the idle curious from mucking about. 3) Put the source code on the interwebs. In category 2 you find the single-file/directory-app bundlers[1] (which IIRC mostly use something like zipimport) and various other "encryption" wrappers. They all provide pretty much the same minimal "protection". [1] Most of which are intended to provide ease of distribution and installation -- the obfuscation is mostly a side-effect. -- Grant Edwards grant.b.edwards Yow! I love ROCK 'N ROLL! at I memorized the all WORDS gmail.com to "WIPE-OUT" in 1965!! From rosuav at gmail.com Tue Sep 15 12:59:36 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Sep 2015 02:59:36 +1000 Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: On Wed, Sep 16, 2015 at 2:40 AM, Grant Edwards wrote: > On 2015-09-15, Chris Angelico wrote: >> >>> I you may be underestimating the laziness and overestimating the >>> cleverness of most people. ;) >> >> Heh :) But in that case, you can probably get away with just >> zipimport. Deflation sure isn't encryption, but the code is pretty >> thoroughly concealed anyway. > > I agree completely. There are three categories of protection: > > 1) The program never leaves your computer. > > 2) Obfuscation to deter the idle curious from mucking about. > > 3) Put the source code on the interwebs. Agreed. #3 is the protection that I use for most of my code, and it's protected me several times from a threat that's far more serious (in my mind) than someone ripping off my code: it's kept my code safe from hard drive failures. Yeah, nothing like seeing errors spewing off a drive that's suddenly died to make you appreciate distributed source control! (Oh look, my private key is no longer accessible. How terrible... I have to go to GitHub and register a new public key before I can continue development. That's gonna set me back... five whole minutes!) #1 wasn't really viable until the always-on internet connection became a normal thing, but today, it's actually pretty easy. Shove your application up onto cheap hosting somewhere, and make it accessible via the web... anyone can do it, and your code needs no obfuscation to be truly secure. > In category 2 you find the single-file/directory-app bundlers[1] > (which IIRC mostly use something like zipimport) and various other > "encryption" wrappers. They all provide pretty much the same minimal > "protection". > > [1] Most of which are intended to provide ease of distribution and > installation -- the obfuscation is mostly a side-effect. Right. Anyone who thinks zipapp is good for security is wrong, but it sure can be handy for packaging up a one-click "here, download and run this" Windows .exe file. Any obfuscation should be seen as a freebie, on par with the toy you get in a fast-food meal. ChrisA From appthought1 at gmail.com Tue Sep 15 17:19:51 2015 From: appthought1 at gmail.com (appthought1 at gmail.com) Date: Tue, 15 Sep 2015 14:19:51 -0700 (PDT) Subject: Python Developer- Houston, TX Message-ID: <3d7dc2d7-cd2e-4043-9c43-1e40adaf62d9@googlegroups.com> Hi, Hope you are doing good!! Please revert back to me if the below job description matches your profile Position: Python Developer Location: Houston, TX Duration: Long Term Job Description * 6+ years of experience with Linux/UNIX Systems Administration * 2+ years of Openstack Experience * Hypervisor KVM, BIOS, Firmware update * Storage Technologies (NAS, SAN & Cloud Storage) * Experience with configuration management tools (Chef expert!!) * Analytical problem-solving and conceptual skills * Strong scripting and/or development chops (Ruby, Python, Bash, Perl) * Experience with database technologies (MySQL, Percona, MongoDB) * Experience with automation (Chef etc.) and monitoring (Nagios, etc.) technologies in production setting * Experience with networking technologies including TCP/IP VPN DNS routing firewalls VLAN. * Excellent communication skills * Excellent team player Thanks & Regards Vignesh Talent Acquisition Specialist Email: vick at theappliedthought.com IM: vicky_298 Phone: 407-574-2696 Fax: 407-641-8184 From rdavid.br at gmail.com Tue Sep 15 19:45:40 2015 From: rdavid.br at gmail.com (Rafael David) Date: Tue, 15 Sep 2015 16:45:40 -0700 (PDT) Subject: Problem with lists Message-ID: <008a92e2-9e56-4ac8-aa5f-2b121380778a@googlegroups.com> Hi guys, I'm newbie in Python (but not a newbie developer). I'm facing a problem with a bidimensional list (list of lists) containing dictionaries. I don't know if I didn't understand how lists and dictionaries work in Python or if there is a mistake in my code that I can't see. In the code I'm printing the list values just after the assignment and they are ok, but when I try to print the list at the end of the function the values are different (repeated). Below is the code and the result in Python 3.4.0. Could you guys please help me with that? Thanks a lot! Rafael >>> def preencherTabuleiroInicial(): tabuleiro = [[None for x in range(8)] for y in range(8)] peca = {} for lin in range(8): for col in range(8): if lin == 0 or lin == 1 or lin == 6 or lin == 7: if lin == 0 or lin == 1: peca['cor'] = 'b' elif lin == 6 or lin == 7: peca['cor'] = 'p' if lin == 1 or lin == 6: peca['nome'] = 'p' elif col == 0 or col == 7: peca['nome'] = 't' elif col == 1 or col == 6: peca['nome'] = 'c' elif col == 2 or col == 5: peca['nome'] = 'b' elif col == 3: peca['nome'] = 'd' else: peca['nome'] = 'r' tabuleiro[lin][col] = peca print(str(lin) + ' ' + str(col) + ' ' + str(tabuleiro[lin][col])) print() print(tabuleiro) >>> >>> preencherTabuleiroInicial() 0 0 {'nome': 't', 'cor': 'b'} 0 1 {'nome': 'c', 'cor': 'b'} 0 2 {'nome': 'b', 'cor': 'b'} 0 3 {'nome': 'd', 'cor': 'b'} 0 4 {'nome': 'r', 'cor': 'b'} 0 5 {'nome': 'b', 'cor': 'b'} 0 6 {'nome': 'c', 'cor': 'b'} 0 7 {'nome': 't', 'cor': 'b'} 1 0 {'nome': 'p', 'cor': 'b'} 1 1 {'nome': 'p', 'cor': 'b'} 1 2 {'nome': 'p', 'cor': 'b'} 1 3 {'nome': 'p', 'cor': 'b'} 1 4 {'nome': 'p', 'cor': 'b'} 1 5 {'nome': 'p', 'cor': 'b'} 1 6 {'nome': 'p', 'cor': 'b'} 1 7 {'nome': 'p', 'cor': 'b'} 2 0 None 2 1 None 2 2 None 2 3 None 2 4 None 2 5 None 2 6 None 2 7 None 3 0 None 3 1 None 3 2 None 3 3 None 3 4 None 3 5 None 3 6 None 3 7 None 4 0 None 4 1 None 4 2 None 4 3 None 4 4 None 4 5 None 4 6 None 4 7 None 5 0 None 5 1 None 5 2 None 5 3 None 5 4 None 5 5 None 5 6 None 5 7 None 6 0 {'nome': 'p', 'cor': 'p'} 6 1 {'nome': 'p', 'cor': 'p'} 6 2 {'nome': 'p', 'cor': 'p'} 6 3 {'nome': 'p', 'cor': 'p'} 6 4 {'nome': 'p', 'cor': 'p'} 6 5 {'nome': 'p', 'cor': 'p'} 6 6 {'nome': 'p', 'cor': 'p'} 6 7 {'nome': 'p', 'cor': 'p'} 7 0 {'nome': 't', 'cor': 'p'} 7 1 {'nome': 'c', 'cor': 'p'} 7 2 {'nome': 'b', 'cor': 'p'} 7 3 {'nome': 'd', 'cor': 'p'} 7 4 {'nome': 'r', 'cor': 'p'} 7 5 {'nome': 'b', 'cor': 'p'} 7 6 {'nome': 'c', 'cor': 'p'} 7 7 {'nome': 't', 'cor': 'p'} [[{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}], [{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}], [{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}]] >>> From illusiontechniques at gmail.com Tue Sep 15 19:59:35 2015 From: illusiontechniques at gmail.com (C Smith) Date: Tue, 15 Sep 2015 16:59:35 -0700 Subject: Problem with lists In-Reply-To: <008a92e2-9e56-4ac8-aa5f-2b121380778a@googlegroups.com> References: <008a92e2-9e56-4ac8-aa5f-2b121380778a@googlegroups.com> Message-ID: >>tabuleiro[lin][col] = peca use peca.copy() here or else a deep copy is made. On Tue, Sep 15, 2015 at 4:45 PM, Rafael David wrote: > Hi guys, > > I'm newbie in Python (but not a newbie developer). I'm facing a problem with a bidimensional list (list of lists) containing dictionaries. I don't know if I didn't understand how lists and dictionaries work in Python or if there is a mistake in my code that I can't see. In the code I'm printing the list values just after the assignment and they are ok, but when I try to print the list at the end of the function the values are different (repeated). Below is the code and the result in Python 3.4.0. Could you guys please help me with that? > > Thanks a lot! > > Rafael > >>>> def preencherTabuleiroInicial(): > tabuleiro = [[None for x in range(8)] for y in range(8)] > peca = {} > for lin in range(8): > for col in range(8): > if lin == 0 or lin == 1 or lin == 6 or lin == 7: > if lin == 0 or lin == 1: > peca['cor'] = 'b' > elif lin == 6 or lin == 7: > peca['cor'] = 'p' > if lin == 1 or lin == 6: > peca['nome'] = 'p' > elif col == 0 or col == 7: > peca['nome'] = 't' > elif col == 1 or col == 6: > peca['nome'] = 'c' > elif col == 2 or col == 5: > peca['nome'] = 'b' > elif col == 3: > peca['nome'] = 'd' > else: > peca['nome'] = 'r' > tabuleiro[lin][col] = peca > print(str(lin) + ' ' + str(col) + ' ' + str(tabuleiro[lin][col])) > print() > print(tabuleiro) > >>>> >>>> preencherTabuleiroInicial() > 0 0 {'nome': 't', 'cor': 'b'} > 0 1 {'nome': 'c', 'cor': 'b'} > 0 2 {'nome': 'b', 'cor': 'b'} > 0 3 {'nome': 'd', 'cor': 'b'} > 0 4 {'nome': 'r', 'cor': 'b'} > 0 5 {'nome': 'b', 'cor': 'b'} > 0 6 {'nome': 'c', 'cor': 'b'} > 0 7 {'nome': 't', 'cor': 'b'} > 1 0 {'nome': 'p', 'cor': 'b'} > 1 1 {'nome': 'p', 'cor': 'b'} > 1 2 {'nome': 'p', 'cor': 'b'} > 1 3 {'nome': 'p', 'cor': 'b'} > 1 4 {'nome': 'p', 'cor': 'b'} > 1 5 {'nome': 'p', 'cor': 'b'} > 1 6 {'nome': 'p', 'cor': 'b'} > 1 7 {'nome': 'p', 'cor': 'b'} > 2 0 None > 2 1 None > 2 2 None > 2 3 None > 2 4 None > 2 5 None > 2 6 None > 2 7 None > 3 0 None > 3 1 None > 3 2 None > 3 3 None > 3 4 None > 3 5 None > 3 6 None > 3 7 None > 4 0 None > 4 1 None > 4 2 None > 4 3 None > 4 4 None > 4 5 None > 4 6 None > 4 7 None > 5 0 None > 5 1 None > 5 2 None > 5 3 None > 5 4 None > 5 5 None > 5 6 None > 5 7 None > 6 0 {'nome': 'p', 'cor': 'p'} > 6 1 {'nome': 'p', 'cor': 'p'} > 6 2 {'nome': 'p', 'cor': 'p'} > 6 3 {'nome': 'p', 'cor': 'p'} > 6 4 {'nome': 'p', 'cor': 'p'} > 6 5 {'nome': 'p', 'cor': 'p'} > 6 6 {'nome': 'p', 'cor': 'p'} > 6 7 {'nome': 'p', 'cor': 'p'} > 7 0 {'nome': 't', 'cor': 'p'} > 7 1 {'nome': 'c', 'cor': 'p'} > 7 2 {'nome': 'b', 'cor': 'p'} > 7 3 {'nome': 'd', 'cor': 'p'} > 7 4 {'nome': 'r', 'cor': 'p'} > 7 5 {'nome': 'b', 'cor': 'p'} > 7 6 {'nome': 'c', 'cor': 'p'} > 7 7 {'nome': 't', 'cor': 'p'} > > [[{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}], [{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}], [{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome' > : 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}]] >>>> > -- > https://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Tue Sep 15 20:11:11 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 16 Sep 2015 01:11:11 +0100 Subject: Problem with lists In-Reply-To: <008a92e2-9e56-4ac8-aa5f-2b121380778a@googlegroups.com> References: <008a92e2-9e56-4ac8-aa5f-2b121380778a@googlegroups.com> Message-ID: <55F8B39F.5070305@mrabarnett.plus.com> On 2015-09-16 00:45, Rafael David wrote: > Hi guys, > > I'm newbie in Python (but not a newbie developer). I'm facing a > problem with a bidimensional list (list of lists) containing > dictionaries. I don't know if I didn't understand how lists and > dictionaries work in Python or if there is a mistake in my code that > I can't see. In the code I'm printing the list values just after the > assignment and they are ok, but when I try to print the list at the > end of the function the values are different (repeated). Below is > the code and the result in Python 3.4.0. Could you guys please help > me with that? > > Thanks a lot! > > Rafael > >>>> def preencherTabuleiroInicial(): > tabuleiro = [[None for x in range(8)] for y in range(8)] > peca = {} > for lin in range(8): > for col in range(8): > if lin == 0 or lin == 1 or lin == 6 or lin == 7: > if lin == 0 or lin == 1: > peca['cor'] = 'b' > elif lin == 6 or lin == 7: > peca['cor'] = 'p' > if lin == 1 or lin == 6: > peca['nome'] = 'p' > elif col == 0 or col == 7: > peca['nome'] = 't' > elif col == 1 or col == 6: > peca['nome'] = 'c' > elif col == 2 or col == 5: > peca['nome'] = 'b' > elif col == 3: > peca['nome'] = 'd' > else: > peca['nome'] = 'r' > tabuleiro[lin][col] = peca > print(str(lin) + ' ' + str(col) + ' ' + str(tabuleiro[lin][col])) > print() > print(tabuleiro) > >>>> >>>> preencherTabuleiroInicial() > 0 0 {'nome': 't', 'cor': 'b'} > 0 1 {'nome': 'c', 'cor': 'b'} > 0 2 {'nome': 'b', 'cor': 'b'} > 0 3 {'nome': 'd', 'cor': 'b'} > 0 4 {'nome': 'r', 'cor': 'b'} > 0 5 {'nome': 'b', 'cor': 'b'} > 0 6 {'nome': 'c', 'cor': 'b'} > 0 7 {'nome': 't', 'cor': 'b'} > 1 0 {'nome': 'p', 'cor': 'b'} > 1 1 {'nome': 'p', 'cor': 'b'} > 1 2 {'nome': 'p', 'cor': 'b'} > 1 3 {'nome': 'p', 'cor': 'b'} > 1 4 {'nome': 'p', 'cor': 'b'} > 1 5 {'nome': 'p', 'cor': 'b'} > 1 6 {'nome': 'p', 'cor': 'b'} > 1 7 {'nome': 'p', 'cor': 'b'} > 2 0 None > 2 1 None > 2 2 None > 2 3 None > 2 4 None > 2 5 None > 2 6 None > 2 7 None > 3 0 None > 3 1 None > 3 2 None > 3 3 None > 3 4 None > 3 5 None > 3 6 None > 3 7 None > 4 0 None > 4 1 None > 4 2 None > 4 3 None > 4 4 None > 4 5 None > 4 6 None > 4 7 None > 5 0 None > 5 1 None > 5 2 None > 5 3 None > 5 4 None > 5 5 None > 5 6 None > 5 7 None > 6 0 {'nome': 'p', 'cor': 'p'} > 6 1 {'nome': 'p', 'cor': 'p'} > 6 2 {'nome': 'p', 'cor': 'p'} > 6 3 {'nome': 'p', 'cor': 'p'} > 6 4 {'nome': 'p', 'cor': 'p'} > 6 5 {'nome': 'p', 'cor': 'p'} > 6 6 {'nome': 'p', 'cor': 'p'} > 6 7 {'nome': 'p', 'cor': 'p'} > 7 0 {'nome': 't', 'cor': 'p'} > 7 1 {'nome': 'c', 'cor': 'p'} > 7 2 {'nome': 'b', 'cor': 'p'} > 7 3 {'nome': 'd', 'cor': 'p'} > 7 4 {'nome': 'r', 'cor': 'p'} > 7 5 {'nome': 'b', 'cor': 'p'} > 7 6 {'nome': 'c', 'cor': 'p'} > 7 7 {'nome': 't', 'cor': 'p'} > > [[{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}], [{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}], [{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'no me' > : 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}]] >>>> > You're creating a dict: peca = {} putting entries into it: peca['cor'] = ... or: peca['nome'] = ... and then putting it into one of the lists of lists: tabuleiro[lin][col] = peca but it's the same dict; you're re-using it. From rdavid.br at gmail.com Tue Sep 15 20:29:14 2015 From: rdavid.br at gmail.com (Rafael David) Date: Tue, 15 Sep 2015 17:29:14 -0700 (PDT) Subject: Problem with lists In-Reply-To: References: <008a92e2-9e56-4ac8-aa5f-2b121380778a@googlegroups.com> Message-ID: <14692e48-f543-4719-87ce-3eb38adf4db4@googlegroups.com> Em ter?a-feira, 15 de setembro de 2015 21:11:38 UTC-3, MRAB escreveu: > On 2015-09-16 00:45, Rafael David wrote: > > Hi guys, > > > > I'm newbie in Python (but not a newbie developer). I'm facing a > > problem with a bidimensional list (list of lists) containing > > dictionaries. I don't know if I didn't understand how lists and > > dictionaries work in Python or if there is a mistake in my code that > > I can't see. In the code I'm printing the list values just after the > > assignment and they are ok, but when I try to print the list at the > > end of the function the values are different (repeated). Below is > > the code and the result in Python 3.4.0. Could you guys please help > > me with that? > > > > Thanks a lot! > > > > Rafael > > > >>>> def preencherTabuleiroInicial(): > > tabuleiro = [[None for x in range(8)] for y in range(8)] > > peca = {} > > for lin in range(8): > > for col in range(8): > > if lin == 0 or lin == 1 or lin == 6 or lin == 7: > > if lin == 0 or lin == 1: > > peca['cor'] = 'b' > > elif lin == 6 or lin == 7: > > peca['cor'] = 'p' > > if lin == 1 or lin == 6: > > peca['nome'] = 'p' > > elif col == 0 or col == 7: > > peca['nome'] = 't' > > elif col == 1 or col == 6: > > peca['nome'] = 'c' > > elif col == 2 or col == 5: > > peca['nome'] = 'b' > > elif col == 3: > > peca['nome'] = 'd' > > else: > > peca['nome'] = 'r' > > tabuleiro[lin][col] = peca > > print(str(lin) + ' ' + str(col) + ' ' + str(tabuleiro[lin][col])) > > print() > > print(tabuleiro) > > > >>>> > >>>> preencherTabuleiroInicial() > > 0 0 {'nome': 't', 'cor': 'b'} > > 0 1 {'nome': 'c', 'cor': 'b'} > > 0 2 {'nome': 'b', 'cor': 'b'} > > 0 3 {'nome': 'd', 'cor': 'b'} > > 0 4 {'nome': 'r', 'cor': 'b'} > > 0 5 {'nome': 'b', 'cor': 'b'} > > 0 6 {'nome': 'c', 'cor': 'b'} > > 0 7 {'nome': 't', 'cor': 'b'} > > 1 0 {'nome': 'p', 'cor': 'b'} > > 1 1 {'nome': 'p', 'cor': 'b'} > > 1 2 {'nome': 'p', 'cor': 'b'} > > 1 3 {'nome': 'p', 'cor': 'b'} > > 1 4 {'nome': 'p', 'cor': 'b'} > > 1 5 {'nome': 'p', 'cor': 'b'} > > 1 6 {'nome': 'p', 'cor': 'b'} > > 1 7 {'nome': 'p', 'cor': 'b'} > > 2 0 None > > 2 1 None > > 2 2 None > > 2 3 None > > 2 4 None > > 2 5 None > > 2 6 None > > 2 7 None > > 3 0 None > > 3 1 None > > 3 2 None > > 3 3 None > > 3 4 None > > 3 5 None > > 3 6 None > > 3 7 None > > 4 0 None > > 4 1 None > > 4 2 None > > 4 3 None > > 4 4 None > > 4 5 None > > 4 6 None > > 4 7 None > > 5 0 None > > 5 1 None > > 5 2 None > > 5 3 None > > 5 4 None > > 5 5 None > > 5 6 None > > 5 7 None > > 6 0 {'nome': 'p', 'cor': 'p'} > > 6 1 {'nome': 'p', 'cor': 'p'} > > 6 2 {'nome': 'p', 'cor': 'p'} > > 6 3 {'nome': 'p', 'cor': 'p'} > > 6 4 {'nome': 'p', 'cor': 'p'} > > 6 5 {'nome': 'p', 'cor': 'p'} > > 6 6 {'nome': 'p', 'cor': 'p'} > > 6 7 {'nome': 'p', 'cor': 'p'} > > 7 0 {'nome': 't', 'cor': 'p'} > > 7 1 {'nome': 'c', 'cor': 'p'} > > 7 2 {'nome': 'b', 'cor': 'p'} > > 7 3 {'nome': 'd', 'cor': 'p'} > > 7 4 {'nome': 'r', 'cor': 'p'} > > 7 5 {'nome': 'b', 'cor': 'p'} > > 7 6 {'nome': 'c', 'cor': 'p'} > > 7 7 {'nome': 't', 'cor': 'p'} > > > > [[{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}], [{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None], [{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}], [{'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'no > me' > > : 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}, {'nome': 't', 'cor': 'p'}]] > >>>> > > > You're creating a dict: > > peca = {} > > putting entries into it: > > peca['cor'] = ... > > or: > peca['nome'] = ... > > and then putting it into one of the lists of lists: > > tabuleiro[lin][col] = peca > > but it's the same dict; you're re-using it. Oooohhh ... I think I got it! I'm assigning a reference to peca and not the value itself! Thank you very much MRAB and C Smith for the enlightenment :) Rafael From rosuav at gmail.com Tue Sep 15 20:46:48 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Sep 2015 10:46:48 +1000 Subject: Problem with lists In-Reply-To: <14692e48-f543-4719-87ce-3eb38adf4db4@googlegroups.com> References: <008a92e2-9e56-4ac8-aa5f-2b121380778a@googlegroups.com> <14692e48-f543-4719-87ce-3eb38adf4db4@googlegroups.com> Message-ID: On Wed, Sep 16, 2015 at 10:29 AM, Rafael David wrote: > Oooohhh ... I think I got it! I'm assigning a reference to peca and not the value itself! Thank you very much MRAB and C Smith for the enlightenment :) Right! That's how Python's assignment always works. You may find, in your case, that you can simply reassign peca={} every time through the loop. No copying necessary - just make yourself a new dict for each iteration. And you might be able to do the whole thing with a gigantic list/list/dict comprehension, but that may or may not be an improvement on your code :) ChrisA From steve at pearwood.info Tue Sep 15 21:13:44 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 16 Sep 2015 11:13:44 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F130CE.5060203@rece.vub.ac.be> <55F191CD.8040901@gmail.com> <55f3a08d$0$1674$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f8c248$0$1649$c3e8da3$5496439d@news.astraweb.com> On Mon, 14 Sep 2015 06:30 pm, Antoon Pardon wrote: > Op 12-09-15 om 05:48 schreef Steven D'Aprano: >> I believe I already acknowledged that assignment-as-expression was fine >> if it avoided the = versus == error, from the perspective of avoiding >> errors. But from the perspective of a clean and logical programming >> model, perhaps not so much. Assignment is imperative, not functional, and >> requiring it to return a result is somewhat unclean. > > I thought practicallity beats purity? AFAICS python doesn't use such a > clean and logical programming model and it isn't given much critique over > it. So I don't think it is fair to critique assignment as an expression > because of this aspect. Python is a remarkably clean and consistent language. There's only one kind of value (the object -- everything is an object, even classes are objects). The syntax isn't full of special cases. For example, there's nothing like this horror from Ruby: #!/usr/bin/ruby def a(x=4) x+2 end b = 1 print "a + b => ", (a + b), "\n" print "a+b => ", (a+b), "\n" print "a+ b => ", (a+ b), "\n" print "a +b => ", (a +b), "\n" which prints: 7 7 7 3 This is not a bug in the language (well, yes it is, it's a design bug), but it is a consequence of the syntax. Python has nothing like this. Python's syntax is quite clean and consistent. [...] > But we are not talking about all commands, we are just talking about > assignments. Sure an assignment has a side effect. But so has ls.pop(). So > something having a side-effect and a value is not unheard of even within a > python context. Sure, I already said that some commands might return a value. But assignment? Assignment is a pure command. There's nothing to return. Having `x = 23` return 23 is, well, weird. If we start from the premise that a return result is generated from a *calculation* or a *query*, we have to ask what is being calculated or asked? I'm not quite willing to say that assignment-as-expression is an error, because I acknowledge that it could be useful in some places. But it seems bolted on and arbitrary, like having del return the name you just unbound: assert (del x) == 'x' And one other reason why I dislike it: it makes for a verbose and messy interactive experience. Take Ruby: irb(main):001:0> a = 23 => 23 I don't need to see 23 printed, because I already know what the value is, so that takes two lines where one would do. (On the rare case I did want to see the value of something I had just assigned to, I could just print the expression.) -- Steven From steve at pearwood.info Tue Sep 15 21:20:15 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 16 Sep 2015 11:20:15 +1000 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F130CE.5060203@rece.vub.ac.be> <55F191CD.8040901@gmail.com> <55f3a08d$0$1674$c3e8da3$5496439d@news.astraweb.com> <55f8c248$0$1649$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55f8c3d0$0$1672$c3e8da3$5496439d@news.astraweb.com> On Wed, 16 Sep 2015 11:13 am, Steven D'Aprano wrote: > Python is a remarkably clean and consistent language. There's only one > kind of value (the object -- everything is an object, even classes are > objects). The syntax isn't full of special cases. For example, there's > nothing like this horror from Ruby: > > #!/usr/bin/ruby > def a(x=4) > x+2 > end > > b = 1 > print "a + b => ", (a + b), "\n" > print "a+b => ", (a+b), "\n" > print "a+ b => ", (a+ b), "\n" > print "a +b => ", (a +b), "\n" > > > which prints: > > 7 > 7 > 7 > 3 Of course it doesn't. It prints: a + b => 7 a+b => 7 a+ b => 7 a +b => 3 Sorry about that. -- Steven From random832 at fastmail.com Tue Sep 15 21:54:02 2015 From: random832 at fastmail.com (Random832) Date: Tue, 15 Sep 2015 21:54:02 -0400 Subject: Python handles globals badly. References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F130CE.5060203@rece.vub.ac.be> <55F191CD.8040901@gmail.com> <55f3a08d$0$1674$c3e8da3$5496439d@news.astraweb.com> <55f8c248$0$1649$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > I don't need to see 23 printed, because I already know what the value is, so > that takes two lines where one would do. (On the rare case I did want to > see the value of something I had just assigned to, I could just print the > expression.) Of course, you could just as well say that you _never_ need to see anything printed unless you ask for it. The first time I used the REPL I was irritated by the fact that None wasn't printed. The reason that None isn't printed is, of course, because Python has no distinction between a function that returns None as a value and a function that doesn't return a value. The alternative is to make assignments special within the REPL, or even turn it into something that looks less like a REPL and more like the variable/expression list that some IDE debuggers have. From rosuav at gmail.com Tue Sep 15 21:58:36 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Sep 2015 11:58:36 +1000 Subject: Python handles globals badly. In-Reply-To: <55f8c3d0$0$1672$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F130CE.5060203@rece.vub.ac.be> <55F191CD.8040901@gmail.com> <55f3a08d$0$1674$c3e8da3$5496439d@news.astraweb.com> <55f8c248$0$1649$c3e8da3$5496439d@news.astraweb.com> <55f8c3d0$0$1672$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 16, 2015 at 11:20 AM, Steven D'Aprano wrote: > On Wed, 16 Sep 2015 11:13 am, Steven D'Aprano wrote: > >> Python is a remarkably clean and consistent language. There's only one >> kind of value (the object -- everything is an object, even classes are >> objects). The syntax isn't full of special cases. For example, there's >> nothing like this horror from Ruby: >> >> #!/usr/bin/ruby >> def a(x=4) >> x+2 >> end >> >> b = 1 >> print "a + b => ", (a + b), "\n" >> print "a+b => ", (a+b), "\n" >> print "a+ b => ", (a+ b), "\n" >> print "a +b => ", (a +b), "\n" >> >> >> which prints: >> >> 7 >> 7 >> 7 >> 3 > > > Of course it doesn't. It prints: > > a + b => 7 > a+b => 7 > a+ b => 7 > a +b => 3 > > > Sorry about that. I'm not a Rubyist, but my reading of this is that the last one is calling a with +b as its argument, where all the others are calling a with no argument, and then using the result in an expression. ISTM the problem here is omitting the parentheses on a function call. ChrisA From alexander.belopolsky at gmail.com Tue Sep 15 22:53:21 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Tue, 15 Sep 2015 22:53:21 -0400 Subject: Adding PEP 495 support to dateutil Message-ID: On Sat, Sep 12, 2015 at 9:58 PM, Tim Peters wrote: > I think acceptance of 495 should be contingent upon > someone first completing a fully functional (if not releasable) > fold-aware zoneinfo wrapping. > After studying both pytz and dateutil offerings, I decided that it is easier to add "fold-awareness" to the later. I created a fork [1] on Github and added [2] fold-awareness logic to the tzrange class that appears to be the base class for most other tzinfo implementations. I was surprised how few test cases had to be changed. It looks like dateutil test suit does not test questionable (in the absence of fold) behavior. I will need to beef up the test coverage. I am making all development public early on and hope to see code reviews and pull requests from interested parties. Pull requests with additional test cases are most welcome. [1]: https://github.com/abalkin/dateutil/tree/pep-0495 [2]: https://github.com/abalkin/dateutil/commit/57ecdbf481de7e21335ece8fcc5673d59252ec3f -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Wed Sep 16 00:49:35 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 16 Sep 2015 05:49:35 +0100 Subject: how to build windows extensions for python 3.5 In-Reply-To: <55F8416E.6010901@chamonix.reportlab.co.uk> References: <55F6ED53.9080103@chamonix.reportlab.co.uk> <55F80353.9080609@chamonix.reportlab.co.uk> <55F81DE0.5050100@chamonix.reportlab.co.uk> <55F8416E.6010901@chamonix.reportlab.co.uk> Message-ID: On 15/09/2015 17:03, Robin Becker wrote: > On 15/09/2015 16:54, Zachary Ware wrote: >> On Tue, Sep 15, 2015 at 8:32 AM, Robin Becker >> wrote: > ........ >> >> I'm a bit surprised that you can successfully use the same .libs for >> 2.7 and 3.3/3.4. But since that seems to work, I'd say go ahead and >> try it with 3.5, and if the build succeeds test the crap out of it :) >> > I've downloaded the vs2015 iso from msdn and I'll give the install a try > tomorrow. It can't be that hard to build our extensions since Christoph > Golhke has done a reportlab wheel for 3.5 at > http://www.lfd.uci.edu/~gohlke/pythonlibs/ I'd be inclined to check out anything on the bug tracker involving Christoph Golhke, there was certainly one show stopper within the last few days. It make take a few minutes, on the other hand it might save you days :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From dieter at handshake.de Wed Sep 16 01:57:50 2015 From: dieter at handshake.de (dieter) Date: Wed, 16 Sep 2015 07:57:50 +0200 Subject: From logging to files to a better solution: syslog, Sentry, Logstash, .... References: <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> Message-ID: <878u86dhy9.fsf@handshake.de> Thomas G?ttler writes: > Am Freitag, 11. September 2015 11:03:52 UTC+2 schrieb jmp: > ... >> Something like (python 2.7) >> >> import logging >> >> logCfg = { >> 'remote':( >> logging.StreamHandler(), >> logging.Formatter('Remote - %(levelname)s - %(message)s'), >> logging.INFO, >> ), >> 'vpn':( >> logging.StreamHandler(), >> logging.Formatter('VPN - %(levelname)s - %(message)s'), >> logging.ERROR, >> ), >> } > > > .... Yes, I could do it this way. > > But somehow I am not happy with this solution. > > I think the filtering should be outside of python. Do you think, it will be easier there? You could also use the "syslog" handler and use "syslog" configuration features to separate the various message levels. >From my point of view, this will not be easier - but outside of Python :-) And you can develop your own Python logging handler delegating logging to your favorite external logging subsystem and then configure that. Likely the hardest approach... From mail at timgolden.me.uk Wed Sep 16 03:45:11 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 16 Sep 2015 08:45:11 +0100 Subject: broken install? In-Reply-To: <55F7F634.9040008@gmail.com> References: <55F7F634.9040008@gmail.com> Message-ID: <55F91E07.5060401@timgolden.me.uk> On 15/09/2015 11:43, Serj wrote: > Hi there! > > I just downloaded 3.5.0 install package for Win32 > (python-3.5.0-webinstall.exe) and I see some strange behaviour under Win > XP: there is no "Next" or "Run" button in wizard ))) > > Clicked into space near "Cancel" I opened "options" screen, while > clicked in another place (closer to center of window) setup started > without any options at all ))) Python has dropped support for Windows XP: https://docs.python.org/3.5/whatsnew/3.5.html#unsupported-operating-systems TJG From rosuav at gmail.com Wed Sep 16 03:51:18 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Sep 2015 17:51:18 +1000 Subject: broken install? In-Reply-To: <55F7F634.9040008@gmail.com> References: <55F7F634.9040008@gmail.com> Message-ID: On Tue, Sep 15, 2015 at 8:43 PM, Serj wrote: > I just downloaded 3.5.0 install package for Win32 > (python-3.5.0-webinstall.exe) and I see some strange behaviour under Win > XP: there is no "Next" or "Run" button in wizard ))) Python 3.5 no longer supports Windows XP, sorry. You can continue to use Python 3.4, or you can upgrade to a newer operating system (Windows 7... or Debian Linux "Jessie" :) ), but CPython 3.5 uses functionality that Windows XP simply doesn't offer. ChrisA From greg.ewing at canterbury.ac.nz Wed Sep 16 04:14:41 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 16 Sep 2015 20:14:41 +1200 Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <55f6fdd9$0$1640$c3e8da3$5496439d@news.astraweb.com> <1442252093.231783.383350001.6CF3FF6F@webmail.messagingengine.com> Message-ID: Emile van Sebille wrote: > Shroedingers-cat-was-just-a-cat-in-a-box-too-ly y'rs, The real question is, if you kill Schroedinger's cat, does Heisenberg's cat die too? If so, then either they're the same cat, or they're two entangled cats. This suggests an alternative model for Python computation. All data is represented by cats. A variable is a box containing a cat. Assignment replaces one cat with an entangled copy of another cat, so that mutating either one affects the other. -- Greg From rosuav at gmail.com Wed Sep 16 04:18:59 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Sep 2015 18:18:59 +1000 Subject: Terminology: "reference" versus "pointer" In-Reply-To: References: <85io7g6xy4.fsf@benfinney.id.au> <85egi46wng.fsf@benfinney.id.au> <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <55f6fdd9$0$1640$c3e8da3$5496439d@news.astraweb.com> <1442252093.231783.383350001.6CF3FF6F@webmail.messagingengine.com> Message-ID: On Wed, Sep 16, 2015 at 6:14 PM, Gregory Ewing wrote: > Emile van Sebille wrote: > >> Shroedingers-cat-was-just-a-cat-in-a-box-too-ly y'rs, > > > The real question is, if you kill Schroedinger's cat, does > Heisenberg's cat die too? If so, then either they're the > same cat, or they're two entangled cats. > > This suggests an alternative model for Python computation. > All data is represented by cats. A variable is a box > containing a cat. Assignment replaces one cat with an > entangled copy of another cat, so that mutating either > one affects the other. Quantum computing is the way of the future! ChrisA From ben+python at benfinney.id.au Wed Sep 16 04:24:57 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 16 Sep 2015 18:24:57 +1000 Subject: Terminology: "reference" versus "pointer" References: <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <55f6fdd9$0$1640$c3e8da3$5496439d@news.astraweb.com> <1442252093.231783.383350001.6CF3FF6F@webmail.messagingengine.com> Message-ID: <8537ye6aau.fsf@benfinney.id.au> Chris Angelico writes: > On Wed, Sep 16, 2015 at 6:14 PM, Gregory Ewing > wrote: > > This suggests an alternative model for Python computation. All data > > is represented by cats. A variable is a box containing a cat. > > Assignment replaces one cat with an entangled copy of another cat, > > so that mutating either one affects the other. > > Quantum computing is the way of the future! Tachyon computing is the way of the future *and* the past. -- \ ?[Entrenched media corporations will] maintain the status quo, | `\ or die trying. Either is better than actually WORKING for a | _o__) living.? ?ringsnake.livejournal.com, 2007-11-12 | Ben Finney From info at egenix.com Wed Sep 16 04:25:33 2015 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 16 Sep 2015 10:25:33 +0200 Subject: ANN: PyDDF Python Sprint 2015 Message-ID: <55F9277D.5040004@egenix.com> [This announcement is in German since it targets a Python sprint in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG PyDDF Python Sprint 2015 in D?sseldorf Samstag, 26.09.2015, 10:00-18:00 Uhr Sonntag, 27.09.2015, 10:00-18:00 Uhr trivago GmbH, Karl-Arnold-Platz 1A, 40474 D?sseldorf 4. Stock, Raum 25 "Madrid" Python Meeting D?sseldorf http://pyddf.de/sprint2015/ ________________________________________________________________________ INFORMATION Das Python Meeting D?sseldorf (PyDDF) veranstaltet mit freundlicher Unterst?tzung der *trivago GmbH* ein Python Sprint Wochenende im September. Der Sprint findet am Wochenende 26/27.09.2015 im 4. Stock der trivago Niederlassung am Karl-Arnold-Platz 1A statt (nicht am Bennigsen-Platz 1). Bitte beim Pf?rtner melden. Google Maps: https://www.google.de/maps/dir/51.2452741,6.7711581//@51.2450432,6.7714612,18.17z?hl=de Folgende Themengebiete haben wir als Anregung angedacht: * Openpyxl Openpyxl ist eine Python Bibliothek, mit der man Excel 2010 Dateien lesen und schreiben kann. Charlie ist Co-Maintainer des Pakets. * Python 3 Portierung von mxDateTime mxDateTime ist ein Python Bibliothek f?r Datums- und Zeitgr??en, die fr?her der Standard f?r solche Datentypen war, bevor das datetime Modul zu Python hinzukam. Die Bibliothek wird von einer ganzen Reihe Projekten verwendet und soll auf Python 3 portiert werden. Marc-Andre hat mxDateTime geschrieben. F?r die Portierung sind Kenntnisse in Python 2.7, 3.4 und ANSI C von Vorteil. Fehlende Kenntnisse k?nnen aber nat?rlich schnell erlernt werden. Nat?rlich kann jeder Teilnehmer weitere Themen vorschlagen, z.B. * Kivy * Raspberry Pi * FritzConnection * OpenCV * u.a. Alles weitere und die Anmeldung findet Ihr auf der Sprint Seite: http://pyddf.de/sprint2015/ Teilnehmer sollten sich zudem auf der PyDDF Liste anmelden, da wir uns dort koordinieren: https://www.egenix.com/mailman/listinfo/pyddf ________________________________________________________________________ ?BER UNS Das Python Meeting D?sseldorf (PyDDF) ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: * http://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Sep 16 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ 2015-09-14: Released mxODBC Plone/Zope DA 2.2.3 http://egenix.com/go84 2015-09-18: PyCon UK 2015 ... 2 days to go 2015-09-26: Python Meeting Duesseldorf Sprint 2015 10 days to go eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From hv at tbz-pariv.de Wed Sep 16 04:31:41 2015 From: hv at tbz-pariv.de (=?ISO-8859-1?Q?Thomas_G=FCttler?=) Date: Wed, 16 Sep 2015 01:31:41 -0700 (PDT) Subject: From logging to files to a better solution: syslog, Sentry, Logstash, .... In-Reply-To: References: <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> Message-ID: <42f609d7-0acc-4753-a8e5-6a95e111f47b@googlegroups.com> Am Mittwoch, 16. September 2015 07:58:11 UTC+2 schrieb dieter: > Thomas G?ttler writes: > > Am Freitag, 11. September 2015 11:03:52 UTC+2 schrieb jmp: > > ... > >> Something like (python 2.7) > >> > >> import logging > >> > >> logCfg = { > >> 'remote':( > >> logging.StreamHandler(), > >> logging.Formatter('Remote - %(levelname)s - %(message)s'), > >> logging.INFO, > >> ), > >> 'vpn':( > >> logging.StreamHandler(), > >> logging.Formatter('VPN - %(levelname)s - %(message)s'), > >> logging.ERROR, > >> ), > >> } > > > > > > .... Yes, I could do it this way. > > > > But somehow I am not happy with this solution. > > > > I think the filtering should be outside of python. > > Do you think, it will be easier there? > > You could also use the "syslog" handler and use "syslog" > configuration features to separate the various message levels. > >From my point of view, this will not be easier - but outside of Python :-) > > And you can develop your own Python logging handler delegating logging to > your favorite external logging subsystem and then configure that. > Likely the hardest approach... Yes, this is a python list. I like python programming. But I don't want to solve everything with one tool. I wanted to know how python folks handle their logs. I think filtering mails should be done outside the python interpreter. Strange that no one seems to use one of the mentioned tools for log handling. Regards, Thomas From rosuav at gmail.com Wed Sep 16 04:33:39 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Sep 2015 18:33:39 +1000 Subject: Terminology: "reference" versus "pointer" In-Reply-To: <8537ye6aau.fsf@benfinney.id.au> References: <1a1a1f6a-27ce-4c1b-807a-43eabaa04abb@googlegroups.com> <04ca9d7c-d02b-4329-bd94-4d18d86b3edf@googlegroups.com> <87egi375wb.fsf@gmail.com> <87wpvu5h7f.fsf@gmail.com> <87pp1l6h9a.fsf@gmail.com> <1442187517.2372486.382584889.2ED1B071@webmail.messagingengine.com> <874mix5a63.fsf@gmail.com> <55f6fdd9$0$1640$c3e8da3$5496439d@news.astraweb.com> <1442252093.231783.383350001.6CF3FF6F@webmail.messagingengine.com> <8537ye6aau.fsf@benfinney.id.au> Message-ID: On Wed, Sep 16, 2015 at 6:24 PM, Ben Finney wrote: > Chris Angelico writes: > >> On Wed, Sep 16, 2015 at 6:14 PM, Gregory Ewing >> wrote: >> > This suggests an alternative model for Python computation. All data >> > is represented by cats. A variable is a box containing a cat. >> > Assignment replaces one cat with an entangled copy of another cat, >> > so that mutating either one affects the other. >> >> Quantum computing is the way of the future! > > Tachyon computing is the way of the future *and* the past. What do we want? Guido's time machine!! When do we want it? Before feature freeze... unless we get an exemption... actually, yaknow, it doesn't much matter. ChrisA From antoon.pardon at rece.vub.ac.be Wed Sep 16 04:51:08 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 16 Sep 2015 10:51:08 +0200 Subject: Python handles globals badly. In-Reply-To: <55f8c248$0$1649$c3e8da3$5496439d@news.astraweb.com> References: <86fa425b-d660-45ba-b0f7-3beebdec8e14@googlegroups.com> <55EE9EEC.1060907@rece.vub.ac.be> <55EEDD37.5090602@gmx.com> <55f072aa$0$1669$c3e8da3$5496439d@news.astraweb.com> <55F130CE.5060203@rece.vub.ac.be> <55F191CD.8040901@gmail.com> <55f3a08d$0$1674$c3e8da3$5496439d@news.astraweb.com> <55f8c248$0$1649$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55F92D7C.6090102@rece.vub.ac.be> Op 16-09-15 om 03:13 schreef Steven D'Aprano: > On Mon, 14 Sep 2015 06:30 pm, Antoon Pardon wrote: > >> Op 12-09-15 om 05:48 schreef Steven D'Aprano: >>> I believe I already acknowledged that assignment-as-expression was fine >>> if it avoided the = versus == error, from the perspective of avoiding >>> errors. But from the perspective of a clean and logical programming >>> model, perhaps not so much. Assignment is imperative, not functional, and >>> requiring it to return a result is somewhat unclean. >> I thought practicallity beats purity? AFAICS python doesn't use such a >> clean and logical programming model and it isn't given much critique over >> it. So I don't think it is fair to critique assignment as an expression >> because of this aspect. > Python is a remarkably clean and consistent language. Which is beside the point. Python may generally be a remarkable clean and consistent language, we were not discussing the language in general but a specific aspect. Arguing against C because it doesn't makes a clear seperation between questions and actions (because the assignment is an expression) while python doesn't either (but in other places) strikes me as disingineous. >> But we are not talking about all commands, we are just talking about >> assignments. Sure an assignment has a side effect. But so has ls.pop(). So >> something having a side-effect and a value is not unheard of even within a >> python context. > Sure, I already said that some commands might return a value. > > But assignment? Assignment is a pure command. There's nothing to return. > Having `x = 23` return 23 is, well, weird. If we start from the premise > that a return result is generated from a *calculation* or a *query*, we > have to ask what is being calculated or asked? You are stating your opinion as fact. Suppose I write the following class class SetGet: def __init__(self, value): self.val = value def get(self): return self.val def set(self, value): self.val = value return value So now I can write the following index = SetGet(0) while index.set(index.get() + 1) < 10: do_what_ever So how would you answer your question as to what is calculated or asked in the while condition here? The answer would be similar if we had just allowed an assignment in the condition. > And one other reason why I dislike it: it makes for a verbose and messy > interactive experience. Take Ruby: We are not talking about likes and dislikes. This discussion started by you stating the the assignment as an expression in C was a design flaw in the language. I can understand people preferring the assignment not to be an operator. But when people start suggesting that assignment as an operator is some kind of design flaw, which they use to criticise a specific language, personal likes and dislikes are not important. -- Antoon Pardon From victorhooi at gmail.com Wed Sep 16 05:27:44 2015 From: victorhooi at gmail.com (Victor Hooi) Date: Wed, 16 Sep 2015 02:27:44 -0700 (PDT) Subject: Reading in large logfiles, and processing lines in batches - maximising throughput? Message-ID: I'm using Python to parse metrics out of logfiles. The logfiles are fairly large (multiple GBs), so I'm keen to do this in a reasonably performant way. The metrics are being sent to a InfluxDB database - so it's better if I can batch multiple metrics into a batch ,rather than sending them individually. Currently, I'm using the grouper() recipe from the itertools documentation to process multiples lines in "chunks" - I then send the collected points to the database: def grouper(iterable, n, fillvalue=None): "Collect data into fixed-length chunks or blocks" # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx args = [iter(iterable)] * n return zip_longest(fillvalue=fillvalue, *args) with open(args.input_file, 'r') as f: line_counter = 0 for chunk in grouper(f, args.batch_size): json_points = [] for line in chunk: line_counter +=1 # Do some processing json_points.append(some_metrics) if json_points: write_points(logger, client, json_points, line_counter) However, not every line will produce metrics - so I'm batching on the number of input lines, rather than on the items I send to the database. My question is, would it make sense to simply have a json_points list that accumulated metrics, check the size each iteration and then send them off when it reaches a certain size. Eg.: BATCH_SIZE = 1000 with open(args.input_file, 'r') as f: json_points = [] for line_number, line in enumerate(f): # Do some processing json_points.append(some_metrics) if len(json_points) >= BATCH_SIZE: write_points(logger, client, json_points, line_counter) json_points = [] Also, I originally used grouper because I thought it better to process lines in batches, rather than individually. However, is there actually any throughput advantage from doing it this way in Python? Or is there a better way of getting better throughput? We can assume for now that the CPU load of the processing is fairly light (mainly string splitting, and date parsing). From chenchao at inhand.com.cn Wed Sep 16 05:35:18 2015 From: chenchao at inhand.com.cn (chenchao at inhand.com.cn) Date: Wed, 16 Sep 2015 17:35:18 +0800 Subject: python how to load multiple C libraries Message-ID: <55F937D6.6040104@inhand.com.cn> hi: I encountered a problem. I use ctypes load multiple C libraries, but the libraries have dependence each other.So, how can i load these libraries. For example, I have two libraries:A?B, but A depends on B, B depends on A. So how do I load them? Is there anybody know how to do it? From rosuav at gmail.com Wed Sep 16 05:40:14 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Sep 2015 19:40:14 +1000 Subject: Reading in large logfiles, and processing lines in batches - maximising throughput? In-Reply-To: References: Message-ID: On Wed, Sep 16, 2015 at 7:27 PM, Victor Hooi wrote: > Also, I originally used grouper because I thought it better to process lines in batches, rather than individually. However, is there actually any throughput advantage from doing it this way in Python? Or is there a better way of getting better throughput? > I very much doubt it'll improve throughput; what you're doing there is reading individual lines, then batching them up into blocks of 1000, and then stepping through the batches. In terms of disk read performance, you're already covered, because the file object should be buffered; if you're not doing much actual work in Python, that's probably where your bottleneck is. But keep in mind the basic rules of performance optimization: 1) Don't. 2) For experts only: Don't yet. 3) Measure first. If you remember only the first rule, you're going to be correct most of the time. Write your code to be idiomatic and clean, and *don't worry* about performance. The second rule comes into play once you have a fully working program, and you find that it's running too slowly. (For example, you run "cat filename >/dev/null" and it takes half a second, but you run your program on the same input file and it takes half a day.) Okay, so you know your program needs some work. But which parts of it are actually taking the time? If you just stare at your code and make a guess, *you will be wrong*. So you follow the third rule: Add a boatload of timing marks to the code. They'll slow it down, of course, but you'll usually find that large slabs of the code are so fast you can't even measure the time they're taking, so there's no point optimizing them in any way. Only once you've proven (a) that your program is "too slow" (for some measure of "slow"), and (b) that it's _this part_ that's taking the bulk of the time, *then* you can start improving performance. So get rid of the grouper; it's violating all three rules. Give the program a try without it, and see if you actually have a problem at all. Maybe you don't! ChrisA From rosuav at gmail.com Wed Sep 16 05:41:08 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Sep 2015 19:41:08 +1000 Subject: python how to load multiple C libraries In-Reply-To: <55F937D6.6040104@inhand.com.cn> References: <55F937D6.6040104@inhand.com.cn> Message-ID: On Wed, Sep 16, 2015 at 7:35 PM, chenchao at inhand.com.cn wrote: > I encountered a problem. I use ctypes load multiple C libraries, but the > libraries have dependence each other.So, how can i load these libraries. For > example, I have two libraries:A?B, but A depends on B, B depends on A. So > how do I load them? Is there anybody know how to do it? How are the libraries built? A circular dependency is always a problem. How would a C program handle this? ChrisA From chenchao at inhand.com.cn Wed Sep 16 06:25:57 2015 From: chenchao at inhand.com.cn (chenchao at inhand.com.cn) Date: Wed, 16 Sep 2015 18:25:57 +0800 Subject: python how to load multiple C libraries In-Reply-To: References: <55F937D6.6040104@inhand.com.cn> Message-ID: <55F943B5.5000709@inhand.com.cn> hi: Most current compilers and linkers will search all object files, regard-less of order, but since not all compilers do this it is best to follow the convention of ordering object files from left to right . Python do that. So, is there anybody know how to solve the follow problem? On 09/16/2015 05:41 PM, Chris Angelico wrote: > On Wed, Sep 16, 2015 at 7:35 PM, chenchao at inhand.com.cn > wrote: >> I encountered a problem. I use ctypes load multiple C libraries, but the >> libraries have dependence each other.So, how can i load these libraries. For >> example, I have two libraries:A?B, but A depends on B, B depends on A. So >> how do I load them? Is there anybody know how to do it? > How are the libraries built? A circular dependency is always a > problem. How would a C program handle this? > > ChrisA From blake.garretson at gmail.com Wed Sep 16 08:16:21 2015 From: blake.garretson at gmail.com (Blake T. Garretson) Date: Wed, 16 Sep 2015 05:16:21 -0700 (PDT) Subject: True == 1 weirdness Message-ID: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> I am maintaining some old code where the programmer used 1 for True because booleans hadn't been added to Python yet. I'm getting some weird behaviour, so I created some simple tests to illustrate my issue. >>> 1 in {1:1} #test1 True >>> 1 in {1:1} == 1 #test2 False >>> (1 in {1:1}) == 1 #test3 True >>> 1 in ({1:1} == 1) #test4 Traceback (most recent call last): File "", line 1, in TypeError: argument of type 'bool' is not iterable >>> You can see that in the first test we get True as expected. The second test yield False, because True does not equal 1, apparently. Fair enough. But then the third test yields True. Weird. Okay, so maybe it was evaluating the right side first? So I put the parens over to the right and it fails, so that wasn't it. So why do the second and third test differ? From harvesting at makes.email.invalid Wed Sep 16 08:53:44 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Wed, 16 Sep 2015 15:53:44 +0300 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> Message-ID: Blake T. Garretson writes: > I am maintaining some old code where the programmer used 1 for True > because booleans hadn't been added to Python yet. I'm getting some > weird behaviour, so I created some simple tests to illustrate my > issue. > > >>> 1 in {1:1} #test1 > True > >>> 1 in {1:1} == 1 #test2 > False > >>> (1 in {1:1}) == 1 #test3 > True > >>> 1 in ({1:1} == 1) #test4 > Traceback (most recent call last): > File "", line 1, in > TypeError: argument of type 'bool' is not iterable > >>> Ouch. I love chained comparisons more than most people, but this took a while to decipher. I blame you! Your parentheses mis-primed me for the wrong reading :) But now I expect to see a long thread about whether chained comparisons are a natural thing to have in the language. The second test, test2, is interpreted (almost) as >>>> (1 in {1:1}) and ({1:1} == 1) which is obviously False. From rosuav at gmail.com Wed Sep 16 09:05:03 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Sep 2015 23:05:03 +1000 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> Message-ID: On Wed, Sep 16, 2015 at 10:53 PM, Jussi Piitulainen wrote: > Ouch. I love chained comparisons more than most people, but this took a > while to decipher. I blame you! Your parentheses mis-primed me for the > wrong reading :) But now I expect to see a long thread about whether > chained comparisons are a natural thing to have in the language. > > The second test, test2, is interpreted (almost) as > > >>>> (1 in {1:1}) and ({1:1} == 1) > > which is obviously False. My view is that they should remain in the language, but that dissimilar comparisons should raise linter warnings. I can't imagine a sane reason for chaining 'in' and equality like that (since the RHS of 'in' will be a container, and if you're testing the whole container for equality, you probably don't care about one member in it), but for language consistency, it's good to support it. Chained comparisons of the same type are a great feature: if 1 < x < 4: And "same type" doesn't just mean the exact same operator: if 1 < x <= 4: It's only when you mix them up in bizarre ways that it's getting a bit weird. ChrisA From jeanmichel at sequans.com Wed Sep 16 09:08:26 2015 From: jeanmichel at sequans.com (jmp) Date: Wed, 16 Sep 2015 15:08:26 +0200 Subject: True == 1 weirdness In-Reply-To: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> Message-ID: On 09/16/2015 02:16 PM, Blake T. Garretson wrote: >>>> 1 in {1:1} == 1 #test2 >The second test yield False, because True does not equal 1, apparently. Fair enough. No, it yields False because {1:1} == 1 is false. Test 2 looks actually like (1 in {1:1}) and ({1:1} == 1). Which in your example does not make any sense but think of this one: x = 5 3 < x < 10 JM From lac at openend.se Wed Sep 16 09:13:41 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 16 Sep 2015 15:13:41 +0200 Subject: python how to load multiple C libraries In-Reply-To: <55F937D6.6040104@inhand.com.cn> References: <55F937D6.6040104@inhand.com.cn> Message-ID: <201509161313.t8GDDfUM017723@fido.openend.se> In a message of Wed, 16 Sep 2015 17:35:18 +0800, "chenchao at inhand.com.cn" write s: >hi: >I encountered a problem. I use ctypes load multiple C libraries, but >the libraries have dependence each other.So, how can i load these >libraries. For example, I have two libraries:A?B, but A depends on B, B >depends on A. So how do I load them? Is there anybody know how to do it? I don't know how to do this with ctypes (which doesn't mean it cannot be done, just that I haven't ever wanted to do this). What happens if you make a small file that loads both separately and loads that one first? It may be that you can get what you want with by loading the first lib RTLD_LAZY instead of RTLD_NOW. see: http://stackoverflow.com/questions/22591472/dyanamic-library-linking-by-rtld-lazy see: this very old thread, maybe CTypes knows about it now. http://osdir.com/ml/python.ctypes/2006-10/msg00029.html But I have never tried. These days I used cffi instead of ctypes. If you use cffi https://pypi.python.org/pypi/cffi there should not be any problem if you use ffi.set_source(), only once, but mentioning both libs in the libraries=[...] argument. Laura From blake.garretson at gmail.com Wed Sep 16 09:14:47 2015 From: blake.garretson at gmail.com (Blake T. Garretson) Date: Wed, 16 Sep 2015 06:14:47 -0700 (PDT) Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> Message-ID: <5f27c92d-71a1-40a3-8129-64d789b5498f@googlegroups.com> On Wednesday, September 16, 2015 at 8:54:07 AM UTC-4, Jussi Piitulainen wrote: > The second test, test2, is interpreted (almost) as > > >>>> (1 in {1:1}) and ({1:1} == 1) > > which is obviously False. Ah, that makes sense. It didn't occur to me that Python would interpret it that way, and I've been using Python daily for 15 years. I try to avoid ambiguous chained comparisons, and I use parenthesis even when I don't need them for clarity. Thanks! From blake.garretson at gmail.com Wed Sep 16 09:17:25 2015 From: blake.garretson at gmail.com (Blake T. Garretson) Date: Wed, 16 Sep 2015 06:17:25 -0700 (PDT) Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> Message-ID: <3c5c897f-5351-4acc-8024-f3cc43431e19@googlegroups.com> On Wednesday, September 16, 2015 at 9:08:54 AM UTC-4, jmp wrote: > x = 5 > 3 < x < 10 That's a great example. I use this case all the time and didn't think to apply the same principal to the in/== case. I assumed that "in" was evaluated first, and then the == comparison was made. Thanks! From pwatson at phs.org Wed Sep 16 09:45:07 2015 From: pwatson at phs.org (Watson, Paul) Date: Wed, 16 Sep 2015 13:45:07 +0000 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> Message-ID: In terms of operator precedence, is "==" evaluated before "in"? ============================================ *-*-*- PRESBYTERIAN_HEALTHCARE_SERVICES_DISCLAIMER -*-*-* This message originates from Presbyterian Healthcare Services or one of its affiliated organizations. It contains information, which may be confidential or privileged, and is intended only for the individual or entity named above. It is prohibited for anyone else to disclose, copy, distribute or use the contents of this message. All personal messages express views solely of the sender, which are not to be attributed to Presbyterian Healthcare Services or any of its affiliated organizations, and may not be distributed without this disclaimer. If you received this message in error, please notify us immediately at info at phs.org. If you would like more information about Presbyterian Healthcare Services please visit our web site http://www.phs.org ============================================ From skip.montanaro at gmail.com Wed Sep 16 09:47:01 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 16 Sep 2015 08:47:01 -0500 Subject: datetime.datetime.today() Message-ID: This surprised me today: >>> import datetime >>> datetime.datetime.today(), datetime.datetime.now() (datetime.datetime(2015, 9, 16, 8, 44, 7, 723560), datetime.datetime(2015, 9, 16, 8, 44, 7, 723577)) I naively expected today() to always return a datetime.date object. Oh well, bug in my code has been squashed. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From nick.a.sarbicki at gmail.com Wed Sep 16 09:55:02 2015 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Wed, 16 Sep 2015 14:55:02 +0100 Subject: datetime.datetime.today() In-Reply-To: References: Message-ID: > This surprised me today: > > >>> import datetime > >>> datetime.datetime.today(), datetime.datetime.now() > (datetime.datetime(2015, 9, 16, 8, 44, 7, 723560), datetime.datetime(2015, > 9, 16, 8, 44, 7, 723577)) > > I naively expected today() to always return a datetime.date object. Oh > well, bug in my code has been squashed. > Just in the case you didn't figure it out: >>> datetime.datetime.today() datetime.datetime(2015, 9, 16, 14, 50, 47, 700828) >>> datetime.date.today() datetime.date(2015, 9, 16) You were accessing the today method of the datetime property which inevitably returns a datetime object. Getting today from the date object will return an actual date. Now and today are very, very, similar - but now may be more accurate and gives flexibility with timezones as per https://docs.python.org/3/library/datetime.html#datetime.datetime.now - Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From random832 at fastmail.com Wed Sep 16 10:03:50 2015 From: random832 at fastmail.com (Random832) Date: Wed, 16 Sep 2015 10:03:50 -0400 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> Message-ID: <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> On Wed, Sep 16, 2015, at 09:05, Chris Angelico wrote: > My view is that they should remain in the language, but that > dissimilar comparisons should raise linter warnings. I can't imagine a > sane reason for chaining 'in' and equality like that (since the RHS of > 'in' will be a container, and if you're testing the whole container > for equality, you probably don't care about one member in it), but for > language consistency, it's good to support it. > > Chained comparisons of the same type are a great feature: Do chained "in" comparisons ever really make sense, even when they're all the same type? I mean, I suppose 1 in (1, 2) in ((1, 2), (3, 4)) is technically true, but how useful is it really? From skip.montanaro at gmail.com Wed Sep 16 10:16:36 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 16 Sep 2015 09:16:36 -0500 Subject: datetime.datetime.today() In-Reply-To: References: Message-ID: On Wed, Sep 16, 2015 at 8:55 AM, Nick Sarbicki wrote: > Just in the case you didn't figure it out: > > >>> datetime.datetime.today() > datetime.datetime(2015, 9, 16, 14, 50, 47, 700828) > >>> datetime.date.today() > datetime.date(2015, 9, 16) > Yeah, I was aware of that. That is partly why I thought datetime.datetime.today() would return a date object. In English, "today" and "now" mean different things, so it makes some sense that they would behave differently as methods of datetime objects. Thx, S -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Sep 16 10:26:16 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Sep 2015 00:26:16 +1000 Subject: True == 1 weirdness In-Reply-To: <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: On Thu, Sep 17, 2015 at 12:03 AM, Random832 wrote: > On Wed, Sep 16, 2015, at 09:05, Chris Angelico wrote: >> My view is that they should remain in the language, but that >> dissimilar comparisons should raise linter warnings. I can't imagine a >> sane reason for chaining 'in' and equality like that (since the RHS of >> 'in' will be a container, and if you're testing the whole container >> for equality, you probably don't care about one member in it), but for >> language consistency, it's good to support it. >> >> Chained comparisons of the same type are a great feature: > > Do chained "in" comparisons ever really make sense, even when they're > all the same type? > > I mean, I suppose 1 in (1, 2) in ((1, 2), (3, 4)) is technically true, > but how useful is it really? Quite probably never. But are there _any_ comparison operators which are unchainable? If not, there's no reason to disallow 'in'; this is the distinction between language-level features and usage recommendations. All comparisons can be chained, and the semantics of (X op1 Y op2 Z) will always be ((X op1 Y) and (Y op2 Z)) but with Y evaluated only once. That definition is fairly simple, and even though it's a little wordy, it makes perfect sense; and the rule "all comparisons" is way WAY simpler than "this specific set of chainable operators", even if the only ones you'd ever actually want to chain are the classic numeric operators (==, !=, <, >, <=, >=). According to the operator precedence table [1], all comparison operators stand together, and dividing that would mean making a once-for-everyone decision about which are plausibly chainable. Remember, the language rules can't know what kinds of objects we're working with; I can write a __contains__ method that does whatever I want, but I can't decide whether or not 'x in y in z' is evaluated as 'x in y and y in z', or '(x in y) in z', or 'x in (y in z)', no matter what the types of x, y, and z. Far as I can see, the only operator that you might want to disallow chaining on is 'in' (and its mate 'not in', of course). It isn't common, but "x is y is z is None" is a perfectly reasonable way to ascertain whether or not they're all None, just as "x = y = z = None" is a perfectly reasonable way to set them all to None; the arguments as to whether it should be "the wordy operators don't chain" or "everything except 'in' chains" would be interminable. Much simpler to stick with "all operators chain", which (conveniently) is status quo. :) ChrisA [1] https://docs.python.org/3/reference/expressions.html#operator-precedence From gokoproject at gmail.com Wed Sep 16 10:34:19 2015 From: gokoproject at gmail.com (John Wong) Date: Wed, 16 Sep 2015 10:34:19 -0400 Subject: [Tutor] Is context manager the answer to synchronous function calls? In-Reply-To: References: Message-ID: On Wed, Sep 16, 2015 at 7:54 AM, Mark Lawrence wrote: > > Assuming your (Alan's) guess is correct, and I certainly agree it's > plausible, I suspect this might be better asked on the main Python mailing > list, I don't see this as tutor material. > > Sorry first time posting to tutor / general list. Usually on TIP list. As per Mark's recommendation, now posting to python-list at python.org. On Wed, Sep 16, 2015 at 6:56 AM, Alan Gauld wrote: > > You don't actually specify but I'm guessing VM > means Virtual Machine? Is it a specific type > of VM? eg VMWare/VirtualBox or somesuch, or is > it more of a sandbox environment like virtualenv? > That might help us understand the restrictions better. In my case my underlying functions will use boto (Amazon Web Service's Python SDK) but I thought to abstract the details away from posting because as you know I want to simply return an object. But yes, boto will simply return the call with a response object. For example, to create an RDS database, the call is returned and I will to query for the status of the database before I can perform further actions to the instance such as changing password (which is covered in the modify_vm function call). But creating VM such as EC2 has an equal synchronous nature. I would be tempted to use an asynchronous approach with a > when_ready() function that takes my function as an input > parameter. You could then run the when_ready in a thread > or, I suspect, utilize the asyncio or asyncore modules, > although I haven't tried using them for this kind of > thing myself. > The bottom line is you need to wait for the status to > change. How you do that wait is up to you but you can > make it more readable for the user. The easier it is for > the user the harder it will be for you. > > Sounds like to make it readable and user friendly, also to have separation of concern, I almost am locked into implementing in OOP style. Imperative seems to be okay but lack the "shininess." Thank you. John -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Wed Sep 16 10:38:51 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 16 Sep 2015 09:38:51 -0500 Subject: True == 1 weirdness In-Reply-To: <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: <20150916093851.4e45f745@bigbox.christie.dr> On 2015-09-16 10:03, Random832 wrote: > Do chained "in" comparisons ever really make sense, even when > they're all the same type? > > I mean, I suppose 1 in (1, 2) in ((1, 2), (3, 4)) is technically > true, but how useful is it really? I could concoct a "useful" example where "in" is involved in a chain, something like set_of_valid_ids = generate_valid_ids_maybe_negative() if 0 < i in set_of_valid_ids: do_something(i) This would unpack as "if 0 > i and i in set_of_valid_ids". However the "useful"ness of it doesn't outweigh the horrible readability IMHO. So I'd never actually *use* this, even if it might be "useful". -tkc From rosuav at gmail.com Wed Sep 16 10:53:34 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Sep 2015 00:53:34 +1000 Subject: [Tutor] Is context manager the answer to synchronous function calls? In-Reply-To: References: Message-ID: On Thu, Sep 17, 2015 at 12:34 AM, John Wong wrote: > Sorry first time posting to tutor / general list. Usually on TIP list. As > per Mark's recommendation, now posting to python-list at python.org. But, sadly, without a lot of context. When you change lists, it's helpful to include a lot of extra verbiage so folks who don't follow the other list can pick up where you were. ChrisA From rosuav at gmail.com Wed Sep 16 10:57:08 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Sep 2015 00:57:08 +1000 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> Message-ID: On Wed, Sep 16, 2015 at 11:45 PM, Watson, Paul wrote: > In terms of operator precedence, is "==" evaluated before "in"? No, they're at the same precedence level. Within that, all comparison operators are evaluated left-to-right, with the chaining that was described earlier. ChrisA From motoom at xs4all.nl Wed Sep 16 11:01:39 2015 From: motoom at xs4all.nl (Michiel Overtoom) Date: Wed, 16 Sep 2015 17:01:39 +0200 Subject: datetime.datetime.today() In-Reply-To: References: Message-ID: This bit me once. I was comparing a date to a datetime, both representing the same day, so I expected them to be the same, but I was wrong. What I should have done was extracting the date of the datetime with the .date() function, and only then compare it to the other date: >>> import datetime >>> a = datetime.datetime.today() >>> a datetime.datetime(2015, 9, 16, 16, 57, 45, 150069) >>> b = datetime.date.today() >>> a == b False >>> a.date() datetime.date(2015, 9, 16) >>> a.date() == b True Greetings, From paul.hermeneutic at gmail.com Wed Sep 16 11:26:47 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Wed, 16 Sep 2015 09:26:47 -0600 Subject: broken install? In-Reply-To: References: <55F7F634.9040008@gmail.com> Message-ID: The installer should detect that it is being run on an unsupported system and do something helpful. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Sep 16 11:40:29 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Sep 2015 01:40:29 +1000 Subject: broken install? In-Reply-To: References: <55F7F634.9040008@gmail.com> Message-ID: On Thu, Sep 17, 2015 at 1:26 AM, wrote: > The installer should detect that it is being run on an unsupported system > and do something helpful. Fair point. Want to raise a tracker issue on bugs.python.org about it? ChrisA From random832 at fastmail.com Wed Sep 16 11:40:44 2015 From: random832 at fastmail.com (Random832) Date: Wed, 16 Sep 2015 11:40:44 -0400 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: <1442418044.1785156.385384641.26FBE65B@webmail.messagingengine.com> On Wed, Sep 16, 2015, at 10:26, Chris Angelico wrote: > Quite probably never. But are there _any_ comparison operators which > are unchainable? If not, there's no reason to disallow 'in' "in" suggests a relationship between objects of different types (X and "something that can contain X") - all the other comparison operators are meant to work on objects of the same or similar types. Why not make isinstance a comparison operator and have "1 instanceof int instanceof type"? Having chaining apply to things that are not *semantically* comparisons is just baffling. >; this is > the distinction between language-level features and usage > recommendations. All comparisons can be chained, and the semantics of > (X op1 Y op2 Z) will always be ((X op1 Y) and (Y op2 Z)) but with Y > evaluated only once. That definition is fairly simple, and even though > it's a little wordy, it makes perfect sense; and the rule "all > comparisons" is way WAY simpler than "this specific set of chainable > operators", It's the same thing - you've just named that set "comparisons". I don't think "in" is semantically a comparison at all. From marko at pacujo.net Wed Sep 16 12:16:45 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 16 Sep 2015 19:16:45 +0300 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: <87oah2jq4y.fsf@elektro.pacujo.net> Chris Angelico : > Far as I can see, the only operator that you might want to disallow > chaining on is 'in' (and its mate 'not in', of course). It isn't > common, but "x is y is z is None" is a perfectly reasonable way to > ascertain whether or not they're all None, just as "x = y = z = None" > is a perfectly reasonable way to set them all to None; Then you can have: first_node is not node is not last_node No, seriously, that's not reasonable. Frankly, I don't think chaining was all that great of an idea. Marko From srkunze at mail.de Wed Sep 16 12:37:47 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 16 Sep 2015 18:37:47 +0200 Subject: True == 1 weirdness In-Reply-To: <87oah2jq4y.fsf@elektro.pacujo.net> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> Message-ID: <55F99ADB.5020405@mail.de> On 16.09.2015 18:16, Marko Rauhamaa wrote: > Chris Angelico : > >> Far as I can see, the only operator that you might want to disallow >> chaining on is 'in' (and its mate 'not in', of course). It isn't >> common, but "x is y is z is None" is a perfectly reasonable way to >> ascertain whether or not they're all None, just as "x = y = z = None" >> is a perfectly reasonable way to set them all to None; > Then you can have: > > first_node is not node is not last_node > > No, seriously, that's not reasonable. > > Frankly, I don't think chaining was all that great of an idea. I like it for x < y < z. But I agree more than this often helps confusion more than it helps clarity. > > Marko From marko at pacujo.net Wed Sep 16 12:53:16 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 16 Sep 2015 19:53:16 +0300 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> Message-ID: <87fv2ejog3.fsf@elektro.pacujo.net> "Sven R. Kunze" : > On 16.09.2015 18:16, Marko Rauhamaa wrote: >> Frankly, I don't think chaining was all that great of an idea. > > I like it for x < y < z. > > But I agree more than this often helps confusion more than it helps > clarity. I see what you did there. Marko From random832 at fastmail.com Wed Sep 16 12:57:52 2015 From: random832 at fastmail.com (Random832) Date: Wed, 16 Sep 2015 12:57:52 -0400 Subject: True == 1 weirdness In-Reply-To: <55F99ADB.5020405@mail.de> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> Message-ID: <1442422672.1804523.385461961.6F1DFD96@webmail.messagingengine.com> On Wed, Sep 16, 2015, at 12:37, Sven R. Kunze wrote: > I like it for x < y < z. > > But I agree more than this often helps confusion more than it helps > clarity. I think that chaining should be limited to: A) all operators are "=" B) all operators are "is" C) all operators are either >= or > D) all operators are either <= or < There's no other scenario, if the operators have natural meanings, that it would actually be natural to write it that way. (Actually, I'm not entirely convinced any harm would be done by allowing you to put "is"/= anywhere, but there certainly shouldn't be opposite direction comparisons, "is not", !=, or "in".) Certainly I think this should be enforced by any sort of lint tool, even if the other uses are not actually removed from the language. I also think it should be part of PEP 8. From cjermain at gmail.com Wed Sep 16 13:09:50 2015 From: cjermain at gmail.com (cjermain at gmail.com) Date: Wed, 16 Sep 2015 10:09:50 -0700 (PDT) Subject: Python 3 unbuffered IO Message-ID: <822a18ba-727c-4fb5-a9e5-cd482b508c01@googlegroups.com> What is the best way to determine if a file object is unbuffered? In Python 3.4, if I open the file with buffering=0, I get a FileIO object. >>> fh = open("tmp", "rb+", buffering=0) >>> fh <_io.FileIO name='tmp' mode='rb+'> Is the FileIO object always unbuffered? If I open it without buffering=0, I get a BufferedRandom. >>> fh = open("tmp", "rb+") >>> fh <_io.BufferedRandom name='tmp'> Should I just compare the file object class to determine buffering? Ultimately, I'd like to determine when a file object is unbuffered to fix an issue in a CPython section of numpy. Thanks for your help! From srkunze at mail.de Wed Sep 16 13:23:55 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 16 Sep 2015 19:23:55 +0200 Subject: True == 1 weirdness In-Reply-To: <1442422672.1804523.385461961.6F1DFD96@webmail.messagingengine.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <1442422672.1804523.385461961.6F1DFD96@webmail.messagingengine.com> Message-ID: <55F9A5AB.2000005@mail.de> On 16.09.2015 18:57, Random832 wrote: > I think that chaining should be limited to: > > A) all operators are "=" > B) all operators are "is" > C) all operators are either >= or > > D) all operators are either <= or < That certainly would be a fine guideline. Only use it with all operators the same. Everything else might cause headaches. Restricting it language-wise? I don't know. I have to admit I've never seen this in production anyway. Most languages I see people working with don't have this feature at all. So, they don't know it exists in Python. Best, Sven From steve at pearwood.info Wed Sep 16 13:24:58 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 17 Sep 2015 03:24:58 +1000 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> Message-ID: <55f9a5e9$0$1643$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Sep 2015 12:03 am, Random832 wrote: > Do chained "in" comparisons ever really make sense, even when they're > all the same type? > > I mean, I suppose 1 in (1, 2) in ((1, 2), (3, 4)) is technically true, > but how useful is it really? if fly in spider in rat in cat in dog in old_woman: print("I don't know why she swallowed the fly") For a less whimsical example: if word in line in text: print("word in line and line in text") But I agree with Tim Chase: I wouldn't use it, even though it's legal. -- Steven From invalid at invalid.invalid Wed Sep 16 13:27:28 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 16 Sep 2015 17:27:28 +0000 (UTC) Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <1442422672.1804523.385461961.6F1DFD96@webmail.messagingengine.com> Message-ID: On 2015-09-16, Sven R. Kunze wrote: > On 16.09.2015 18:57, Random832 wrote: >> I think that chaining should be limited to: >> >> A) all operators are "=" >> B) all operators are "is" >> C) all operators are either >= or > >> D) all operators are either <= or < > > That certainly would be a fine guideline. Only use it with all operators > the same. I find that the only times I use chaining (intentionally), are in cases C and D. All other instances of chaining in my code are invariably typos/bugs. > Everything else might cause headaches. I'm not all that sure A and B should be allowed. > Restricting it language-wise? I don't know. I have to admit I've never > seen this in production anyway. Most languages I see people working with > don't have this feature at all. So, they don't know it exists in Python. I use C and D intentionally, and have tripped accidentally over other cases. -- Grant Edwards grant.b.edwards Yow! Hey, waiter! I want at a NEW SHIRT and a PONY TAIL gmail.com with lemon sauce! From steve at pearwood.info Wed Sep 16 13:33:24 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 17 Sep 2015 03:33:24 +1000 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Sep 2015 01:40 am, Random832 wrote: > "in" suggests a relationship between objects of different types (X and > "something that can contain X") - all the other comparison operators are > meant to work on objects of the same or similar types. `is` and the equality operators are intended to work on arbitrary objects, as are their inverses `is not` and inequality. And with operator overloading, < <= > and => could have any meaning you like: graph = a => b => c <= d <= e > Why not make isinstance a comparison operator and have "1 instanceof int > instanceof type"? Having chaining apply to things that are not > semantically comparisons is just baffling. Somewhat ugly, I grant you, but if baffling? -- Steven From random832 at fastmail.com Wed Sep 16 13:36:52 2015 From: random832 at fastmail.com (Random832) Date: Wed, 16 Sep 2015 13:36:52 -0400 Subject: True == 1 weirdness In-Reply-To: <55f9a5e9$0$1643$c3e8da3$5496439d@news.astraweb.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <55f9a5e9$0$1643$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1442425012.1812534.385496193.511532C4@webmail.messagingengine.com> On Wed, Sep 16, 2015, at 13:24, Steven D'Aprano wrote: > On Thu, 17 Sep 2015 12:03 am, Random832 wrote: > > if word in line in text: > print("word in line and line in text") > > But I agree with Tim Chase: I wouldn't use it, even though it's legal. I just had another thought on *why* the other cases make me so uneasy. The reason this is reasonable for simple cases like a > b > c or a < b <= c is that, in their normal meanings, these operations are transitive. a > b and b > c implies a > c. a < b and b <= c implies a < c. This is also a good reason for allowing "==" or "is" anywhere - because it's a natural way to write a graph including an equivalence class: a < b == c < d implies b < d, a < c, and a < d. So it's a natural way of writing it. On the other hand, a in b in c doesn't imply a in c for several common cases, and a > b < c doesn't imply anything about the relationship between a and c, so it really shouldn't be a single expression. A chained comparison doesn't *actually* compare non-adjacent elements, but with well-defined transitive relationships (or... semi-transitive? is there a word for this? My point being that when you include some == or mix <= and < together, it still allows you to make some statements about their relationships), you are essentially saying "a, b, c are ordered". The generalization to mixing arbitrary operators loses this aspect. From steve at pearwood.info Wed Sep 16 13:39:26 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 17 Sep 2015 03:39:26 +1000 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> Message-ID: <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Sep 2015 02:57 am, Random832 wrote: > I think that chaining should be limited to: > > A) all operators are "=" > B) all operators are "is" > C) all operators are either >= or > > D) all operators are either <= or < > > There's no other scenario, if the operators have natural meanings, that > it would actually be natural to write it that way. 0 <= x < y == z The main reason for supporting arbitrary chained operators is that they could be overloaded and have some meaning that makes sense: node = left <= ptr => right -- Steven From emile at fenx.com Wed Sep 16 13:41:08 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 16 Sep 2015 10:41:08 -0700 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <1442422672.1804523.385461961.6F1DFD96@webmail.messagingengine.com> Message-ID: On 9/16/2015 10:27 AM, Grant Edwards wrote: > On 2015-09-16, Sven R. Kunze wrote: >> On 16.09.2015 18:57, Random832 wrote: >>> I think that chaining should be limited to: >>> >>> A) all operators are "=" >>> B) all operators are "is" >>> C) all operators are either >= or > >>> D) all operators are either <= or < >> > I'm not all that sure A and B should be allowed. I find A convenient for initializing: aname = bname = cname = None Nut I don't recall ever having used is this way. Emile From srkunze at mail.de Wed Sep 16 13:41:21 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 16 Sep 2015 19:41:21 +0200 Subject: True == 1 weirdness In-Reply-To: <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55F9A9C1.7060001@mail.de> On 16.09.2015 19:33, Steven D'Aprano wrote: > On Thu, 17 Sep 2015 01:40 am, Random832 wrote: > >> "in" suggests a relationship between objects of different types (X and >> "something that can contain X") - all the other comparison operators are >> meant to work on objects of the same or similar types. > `is` and the equality operators are intended to work on arbitrary objects, > as are their inverses `is not` and inequality. > > And with operator overloading, < <= > and => could have any meaning you > like: > > graph = a => b => c <= d <= e > Sorry? What are you trying to do here? >> Why not make isinstance a comparison operator and have "1 instanceof int >> instanceof type"? Having chaining apply to things that are not >> semantically comparisons is just baffling. > Somewhat ugly, I grant you, but if baffling? > > > From steve at pearwood.info Wed Sep 16 13:42:01 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 17 Sep 2015 03:42:01 +1000 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <1442422672.1804523.385461961.6F1DFD96@webmail.messagingengine.com> Message-ID: <55f9a9e8$0$1641$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Sep 2015 03:27 am, Grant Edwards wrote: > On 2015-09-16, Sven R. Kunze wrote: >> On 16.09.2015 18:57, Random832 wrote: >>> I think that chaining should be limited to: >>> >>> A) all operators are "=" >>> B) all operators are "is" [...] > I'm not all that sure A and B should be allowed. You can take `x == y == z` off me when you pry it from my cold, dead hands. -- Steven From marko at pacujo.net Wed Sep 16 13:42:05 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 16 Sep 2015 20:42:05 +0300 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878u86jm6q.fsf@elektro.pacujo.net> Steven D'Aprano : > The main reason for supporting arbitrary chained operators is that > they could be overloaded and have some meaning that makes sense: Operator overloading is yet another unfortunate language feature. Marko From invalid at invalid.invalid Wed Sep 16 13:44:42 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 16 Sep 2015 17:44:42 +0000 (UTC) Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <1442422672.1804523.385461961.6F1DFD96@webmail.messagingengine.com> <55f9a9e8$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2015-09-16, Steven D'Aprano wrote: > On Thu, 17 Sep 2015 03:27 am, Grant Edwards wrote: > >> On 2015-09-16, Sven R. Kunze wrote: >>> On 16.09.2015 18:57, Random832 wrote: >>>> I think that chaining should be limited to: >>>> >>>> A) all operators are "=" >>>> B) all operators are "is" > > [...] >> I'm not all that sure A and B should be allowed. > > You can take `x == y == z` off me when you pry it from my cold, dead hands. Well, that case hadn't been mentioned yet. But, I agree that should be added as case E and be allowed. -- Grant Edwards grant.b.edwards Yow! ... or were you at driving the PONTIAC that gmail.com HONKED at me in MIAMI last Tuesday? From invalid at invalid.invalid Wed Sep 16 13:46:45 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 16 Sep 2015 17:46:45 +0000 (UTC) Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2015-09-16, Steven D'Aprano wrote: > On Thu, 17 Sep 2015 02:57 am, Random832 wrote: > > >> I think that chaining should be limited to: >> >> A) all operators are "=" >> B) all operators are "is" >> C) all operators are either >= or > >> D) all operators are either <= or < >> >> There's no other scenario, if the operators have natural meanings, that >> it would actually be natural to write it that way. > > > 0 <= x < y == z > > The main reason for supporting arbitrary chained operators is that they > could be overloaded and have some meaning that makes sense: In my experience, that just doesn't happen. Yes, they can be overloaded, but doing that and then chaining them isn't going to make sense to anybody but the author (and temporarily even then). > node = left <= ptr => right Exactly. I've no clue what that means. ;) -- Grant Edwards grant.b.edwards Yow! Zippy's brain cells at are straining to bridge gmail.com synapses ... From random832 at fastmail.com Wed Sep 16 13:47:15 2015 From: random832 at fastmail.com (Random832) Date: Wed, 16 Sep 2015 13:47:15 -0400 Subject: True == 1 weirdness In-Reply-To: <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1442425635.1814499.385505017.0BBFAF5F@webmail.messagingengine.com> On Wed, Sep 16, 2015, at 13:33, Steven D'Aprano wrote: > On Thu, 17 Sep 2015 01:40 am, Random832 wrote: > > > "in" suggests a relationship between objects of different types (X and > > "something that can contain X") - all the other comparison operators are > > meant to work on objects of the same or similar types. > > `is` and the equality operators are intended to work on arbitrary > objects, > as are their inverses `is not` and inequality. But they won't return *true* unless they're the same or similar types. > And with operator overloading, < <= > and => could have any meaning you > like: > > graph = a => b => c <= d <= e Are you suggesting that all objects concerned are a magical "graph node object", the <= and [sic] => operators of which return "edge objects", the and operator of which constructs a graph object containing all such edges? That's *horrifying*. And won't actually work. We haven't actually got an => operator, thankfully, and you can't overload 'and'. I bet you could do it in C++ though. From invalid at invalid.invalid Wed Sep 16 13:52:30 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 16 Sep 2015 17:52:30 +0000 (UTC) Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2015-09-16, Random832 wrote: > On Wed, Sep 16, 2015, at 13:33, Steven D'Aprano wrote: [...] >> graph = a => b => c <= d <= e > > Are you suggesting that all objects concerned are a magical "graph node > object", the <= and [sic] => operators of which return "edge objects", > the and operator of which constructs a graph object containing all such > edges? That's *horrifying*. And won't actually work. We haven't actually > got an => operator, thankfully, and you can't overload 'and'. > > I bet you could do it in C++ though. If that isn't a damning indictment, I don't know what is. :) -- Grant Edwards grant.b.edwards Yow! I wish I was a at sex-starved manicurist gmail.com found dead in the Bronx!! From srkunze at mail.de Wed Sep 16 13:53:49 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 16 Sep 2015 19:53:49 +0200 Subject: True == 1 weirdness In-Reply-To: <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55F9ACAD.7080508@mail.de> On 16.09.2015 19:39, Steven D'Aprano wrote: > node = left <= ptr => right Wow. I have absolutely no idea what this is supposed to mean. Do you care to elaborate? Best, Sven From random832 at fastmail.com Wed Sep 16 13:55:24 2015 From: random832 at fastmail.com (Random832) Date: Wed, 16 Sep 2015 13:55:24 -0400 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <1442422672.1804523.385461961.6F1DFD96@webmail.messagingengine.com> <55f9a9e8$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1442426124.1817493.385519241.1AE5F689@webmail.messagingengine.com> On Wed, Sep 16, 2015, at 13:44, Grant Edwards wrote: > Well, that case hadn't been mentioned yet. But, I agree that should be > added as case E and be allowed. That's actually what I meant by A, I just spelled it wrong. Multiple assignment isn't really the same construct as chained comparisons, I didn't consider it in scope for this discussion. From ian.g.kelly at gmail.com Wed Sep 16 13:55:34 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 16 Sep 2015 11:55:34 -0600 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <1442422672.1804523.385461961.6F1DFD96@webmail.messagingengine.com> <55f9a9e8$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 16, 2015 at 11:44 AM, Grant Edwards wrote: > On 2015-09-16, Steven D'Aprano wrote: >> On Thu, 17 Sep 2015 03:27 am, Grant Edwards wrote: >> >>> On 2015-09-16, Sven R. Kunze wrote: >>>> On 16.09.2015 18:57, Random832 wrote: >>>>> I think that chaining should be limited to: >>>>> >>>>> A) all operators are "=" >>>>> B) all operators are "is" >> >> [...] >>> I'm not all that sure A and B should be allowed. >> >> You can take `x == y == z` off me when you pry it from my cold, dead hands. > > Well, that case hadn't been mentioned yet. But, I agree that should be > added as case E and be allowed. It was mentioned as case A, albeit mistakenly using "=" (which isn't even a comparison operator) instead of "==". From ian.g.kelly at gmail.com Wed Sep 16 13:57:12 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 16 Sep 2015 11:57:12 -0600 Subject: True == 1 weirdness In-Reply-To: <55f9a5e9$0$1643$c3e8da3$5496439d@news.astraweb.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <55f9a5e9$0$1643$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 16, 2015 at 11:24 AM, Steven D'Aprano wrote: > > if word in line in text: > print("word in line and line in text") It find it hard to imagine how one would arrive at the situation of needing to check this. From srkunze at mail.de Wed Sep 16 13:57:27 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 16 Sep 2015 19:57:27 +0200 Subject: True == 1 weirdness In-Reply-To: <1442425012.1812534.385496193.511532C4@webmail.messagingengine.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <55f9a5e9$0$1643$c3e8da3$5496439d@news.astraweb.com> <1442425012.1812534.385496193.511532C4@webmail.messagingengine.com> Message-ID: <55F9AD87.6020705@mail.de> On 16.09.2015 19:36, Random832 wrote: > I just had another thought on *why* the other cases make me so uneasy. > > The reason this is reasonable for simple cases like a > b > c or a < b > <= c is that, in their normal meanings, these operations are transitive. > a > b and b > c implies a > c. a < b and b <= c implies a < c. This is > also a good reason for allowing "==" or "is" anywhere - because it's a > natural way to write a graph including an equivalence class: a < b == c > < d implies b < d, a < c, and a < d. So it's a natural way of writing > it. On the other hand, a in b in c doesn't imply a in c for several > common cases, and a > b < c doesn't imply anything about the > relationship between a and c, so it really shouldn't be a single > expression. > > A chained comparison doesn't *actually* compare non-adjacent elements, > but with well-defined transitive relationships (or... semi-transitive? > is there a word for this? My point being that when you include some == > or mix <= and < together, it still allows you to make some statements > about their relationships), you are essentially saying "a, b, c are > ordered". The generalization to mixing arbitrary operators loses this > aspect. Well said! From srkunze at mail.de Wed Sep 16 14:13:08 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 16 Sep 2015 20:13:08 +0200 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55F9B134.5060101@mail.de> On 16.09.2015 19:46, Grant Edwards wrote: > On 2015-09-16, Steven D'Aprano wrote: >> node = left <= ptr => right > Exactly. I've no clue what that means. ;) > Modern art. ;) Best, Sven From emile at fenx.com Wed Sep 16 14:46:45 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 16 Sep 2015 11:46:45 -0700 Subject: True == 1 weirdness In-Reply-To: <878u86jm6q.fsf@elektro.pacujo.net> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <878u86jm6q.fsf@elektro.pacujo.net> Message-ID: On 9/16/2015 10:42 AM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> The main reason for supporting arbitrary chained operators is that >> they could be overloaded and have some meaning that makes sense: > > Operator overloading is yet another unfortunate language feature. dunder methods are there for consenting adults -- I don't consider it a wart. Emile From kawazu428 at gmail.com Wed Sep 16 15:29:23 2015 From: kawazu428 at gmail.com (Kristian Rink) Date: Wed, 16 Sep 2015 21:29:23 +0200 Subject: Packaging and deployment of standalone Python applications? In-Reply-To: References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> Message-ID: <55F9C313.8040202@gmail.com> Am 15.09.2015 um 08:59 schrieb paul.hermeneutic at gmail.com: > > https://docs.python.org/3/library/venv.html?highlight=venv#module-venv Thanks, this already is pretty close to what I need. Playing with this and virtualenv, I figured out that this way it's pretty easily possible to have isolated Python environments _locally_. However I failed to package one of these environments and move it to, say, from my Ubuntu development host to a remote Debian server, I end up with errors like these while trying to run the Python off the environment on that host: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found I bundled all the stuff in the virtualenv and also made sure to dereference the symlinks in there. Are Python binaries so closely tied to a particular Linux environment / distribution that what I am about to do is impossible? Is there a "generic" Python for Linux binary that works on all distributions, as things are for Java? TIA and all the best, Kristian From invalid at invalid.invalid Wed Sep 16 15:47:34 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 16 Sep 2015 19:47:34 +0000 (UTC) Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2015-09-16, Sven R. Kunze wrote: > On 16.09.2015 19:46, Grant Edwards wrote: >> On 2015-09-16, Steven D'Aprano wrote: >> >>> node = left <= ptr => right >> >> Exactly. I've no clue what that means. ;) > > Modern art. ;) Ah, well I know that _that_ means: "I think it exemplifies the angst and conflict inherent in modern society". You can say that while standing in front of any piece of modern art, and most everybody will just nod. Try it. -- Grant Edwards grant.b.edwards Yow! These PRESERVES should at be FORCE-FED to PENTAGON gmail.com OFFICIALS!! From marko at pacujo.net Wed Sep 16 15:47:52 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 16 Sep 2015 22:47:52 +0300 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wpvqi1sn.fsf@elektro.pacujo.net> "Sven R. Kunze" : > On 16.09.2015 19:39, Steven D'Aprano wrote: >> node = left <= ptr => right > > Wow. I have absolutely no idea what this is supposed to mean. Do you > care to elaborate? Python is an HC Language for HC Developers. Marko From gokoproject at gmail.com Wed Sep 16 15:50:14 2015 From: gokoproject at gmail.com (John Wong) Date: Wed, 16 Sep 2015 15:50:14 -0400 Subject: [Tutor] Is context manager the answer to synchronous function calls? In-Reply-To: References: Message-ID: Ah. Thanks.. I removed the previous code. Please excuse me. I will rewrite the question so it is clear. Here is my current solution in an imperative way. My application will work with AWS boto library to create EC2 instances and RDS instances. Assuming my API will simply send the request, and return if the request is accepted, I need to lock until the instance is ready before I can start the next operation. def create_vm(.....): # returns vm object def modify_vm(.....): return new vm object def get_vm_status(.....): return status # NOTE: This is obviously a simplified version, but pretty much half of the code. def lock_until_ready(conn, get_status_func, _id, max_wait=60): wait_count = 1 status = get_status_func(conn, _id) while status != 'available' and wait_count < max_wait: print("Querying status (attempt {i}): {status}".format( i=wait_count, status=status)) wait_count += 1 time.sleep(10) status = get_status_func(conn, _id) def clone(data_center, image_id, options): conn = get_connection(data_center) vm_id = create_vm(conn, image_id, ....) lock_until_ready(conn, get_vm_status, vm_id, max_wait=30) modify_vm(conn, options) lock_until_ready(conn, get_vm_status, vm_id, max_wait=30) I hope this doesn't come across as a code review. This works. I made my lock function extensible and testable, but I feel like there should be a better more user-friendly way, even in the imperative world in Python. I thought of context manager because I can do some clean up on entry (verify the db name has not been taken), and exit (if fail rollback). If you are familiar with cloudformation, it almost seems like that's what I am doing. I am writing this because I have custom needs that cloudformation can't do elegantly without many hops. API is much more flexible for my current task, FYI. Any feedback is welcome. Thank you. John On Wed, Sep 16, 2015 at 10:53 AM, Chris Angelico wrote: > On Thu, Sep 17, 2015 at 12:34 AM, John Wong wrote: > > Sorry first time posting to tutor / general list. Usually on TIP list. As > > per Mark's recommendation, now posting to python-list at python.org. > > But, sadly, without a lot of context. When you change lists, it's > helpful to include a lot of extra verbiage so folks who don't follow > the other list can pick up where you were. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Wed Sep 16 16:17:44 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 16 Sep 2015 21:17:44 +0100 Subject: True == 1 weirdness In-Reply-To: <87oah2jq4y.fsf@elektro.pacujo.net> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> Message-ID: On 16/09/2015 17:16, Marko Rauhamaa wrote: > Chris Angelico : > >> Far as I can see, the only operator that you might want to disallow >> chaining on is 'in' (and its mate 'not in', of course). It isn't >> common, but "x is y is z is None" is a perfectly reasonable way to >> ascertain whether or not they're all None, just as "x = y = z = None" >> is a perfectly reasonable way to set them all to None; > > Then you can have: > > first_node is not node is not last_node > > No, seriously, that's not reasonable. > > Frankly, I don't think chaining was all that great of an idea. > > > Marko > I disagree, perfectly logical where I sit. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Wed Sep 16 16:22:51 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 16 Sep 2015 21:22:51 +0100 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <1442422672.1804523.385461961.6F1DFD96@webmail.messagingengine.com> Message-ID: On 16/09/2015 18:41, Emile van Sebille wrote: > On 9/16/2015 10:27 AM, Grant Edwards wrote: >> On 2015-09-16, Sven R. Kunze wrote: >>> On 16.09.2015 18:57, Random832 wrote: >>>> I think that chaining should be limited to: >>>> >>>> A) all operators are "=" >>>> B) all operators are "is" >>>> C) all operators are either >= or > >>>> D) all operators are either <= or < >>> > > >> I'm not all that sure A and B should be allowed. > > I find A convenient for initializing: > > aname = bname = cname = None > > Nut I don't recall ever having used is this way. > > Emile > You're replying to a typo, it should have been "==" not "=". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Wed Sep 16 16:25:37 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 16 Sep 2015 21:25:37 +0100 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 16/09/2015 20:47, Grant Edwards wrote: > On 2015-09-16, Sven R. Kunze wrote: >> On 16.09.2015 19:46, Grant Edwards wrote: >>> On 2015-09-16, Steven D'Aprano wrote: >>> >>>> node = left <= ptr => right >>> >>> Exactly. I've no clue what that means. ;) >> >> Modern art. ;) > > Ah, well I know that _that_ means: > > "I think it exemplifies the angst and conflict inherent in modern > society". > > You can say that while standing in front of any piece of modern art, > and most everybody will just nod. Try it. > Is it:- modern art == crap or modern art = crap ? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Wed Sep 16 16:29:48 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 16 Sep 2015 21:29:48 +0100 Subject: True == 1 weirdness In-Reply-To: <55F9ACAD.7080508@mail.de> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9ACAD.7080508@mail.de> Message-ID: On 16/09/2015 18:53, Sven R. Kunze wrote: > On 16.09.2015 19:39, Steven D'Aprano wrote: >> node = left <= ptr => right > > Wow. I have absolutely no idea what this is supposed to mean. Do you > care to elaborate? > > > Best, > Sven Simple, straight forward easy to read bit of Python, where is the problem? node is bound to the boolean ptr is greater than or equal to left and right. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Wed Sep 16 16:38:30 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 16 Sep 2015 21:38:30 +0100 Subject: True == 1 weirdness In-Reply-To: <55F9A9C1.7060001@mail.de> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> <55F9A9C1.7060001@mail.de> Message-ID: On 16/09/2015 18:41, Sven R. Kunze wrote: > On 16.09.2015 19:33, Steven D'Aprano wrote: >> On Thu, 17 Sep 2015 01:40 am, Random832 wrote: >> >>> "in" suggests a relationship between objects of different types (X and >>> "something that can contain X") - all the other comparison operators are >>> meant to work on objects of the same or similar types. >> `is` and the equality operators are intended to work on arbitrary >> objects, >> as are their inverses `is not` and inequality. >> >> And with operator overloading, < <= > and => could have any meaning you >> like: >> >> graph = a => b => c <= d <= e >> > > Sorry? What are you trying to do here? > Typo I'd hazard a guess at, should be graph = a >= b >= c <= d <= e Assuming that I'm correct, graph is True if a is greater than or equal to b and b is greater than equal to c and c is less than or equal to d and d is less than or equal to e else False. So where is the problem? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From carl at oddbird.net Wed Sep 16 16:39:07 2015 From: carl at oddbird.net (Carl Meyer) Date: Wed, 16 Sep 2015 14:39:07 -0600 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9ACAD.7080508@mail.de> Message-ID: <55F9D36B.40501@oddbird.net> On 09/16/2015 02:29 PM, Mark Lawrence wrote: > On 16/09/2015 18:53, Sven R. Kunze wrote: >> On 16.09.2015 19:39, Steven D'Aprano wrote: >>> node = left <= ptr => right >> >> Wow. I have absolutely no idea what this is supposed to mean. Do you >> care to elaborate? >> >> >> Best, >> Sven > > Simple, straight forward easy to read bit of Python, where is the > problem? node is bound to the boolean ptr is greater than or equal to > left and right. Except it's a SyntaxError because Python has no => operator. Carl -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From random832 at fastmail.com Wed Sep 16 16:55:07 2015 From: random832 at fastmail.com (Random832) Date: Wed, 16 Sep 2015 16:55:07 -0400 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> <55F9A9C1.7060001@mail.de> Message-ID: <1442436907.1857884.385688025.352D99A1@webmail.messagingengine.com> On Wed, Sep 16, 2015, at 16:38, Mark Lawrence wrote: > On 16/09/2015 18:41, Sven R. Kunze wrote: > > On 16.09.2015 19:33, Steven D'Aprano wrote: > >> And with operator overloading, < <= > and => could have any meaning you > >> like: > >> > >> graph = a => b => c <= d <= e > > > > Sorry? What are you trying to do here? > > Typo I'd hazard a guess at, should be graph = a >= b >= c <= d <= e > > Assuming that I'm correct, graph is True if a is greater than or equal > to b and b is greater than equal to c and c is less than or equal to d > and d is less than or equal to e else False. So where is the problem? Except in context, he was suggesting that they have a meaning other than "greater than or equal" and "less than or equal". (see "could have any meaning you like"). It seemed implied that he was suggesting there was some arrangement of operator overloads that could cause this statement to generate a directed graph with the structure shown. From srkunze at mail.de Wed Sep 16 17:03:41 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 16 Sep 2015 23:03:41 +0200 Subject: True == 1 weirdness In-Reply-To: <1442436907.1857884.385688025.352D99A1@webmail.messagingengine.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> <55F9A9C1.7060001@mail.de> <1442436907.1857884.385688025.352D99A1@webmail.messagingengine.com> Message-ID: <55F9D92D.8080609@mail.de> On 16.09.2015 22:55, Random832 wrote: > On Wed, Sep 16, 2015, at 16:38, Mark Lawrence wrote: >> On 16/09/2015 18:41, Sven R. Kunze wrote: >>> On 16.09.2015 19:33, Steven D'Aprano wrote: >>>> And with operator overloading, < <= > and => could have any meaning you >>>> like: >>>> >>>> graph = a => b => c <= d <= e >>> Sorry? What are you trying to do here? >> Typo I'd hazard a guess at, should be graph = a >= b >= c <= d <= e >> >> Assuming that I'm correct, graph is True if a is greater than or equal >> to b and b is greater than equal to c and c is less than or equal to d >> and d is less than or equal to e else False. So where is the problem? > Except in context, he was suggesting that they have a meaning other than > "greater than or equal" and "less than or equal". (see "could have any > meaning you like"). It seemed implied that he was suggesting there was > some arrangement of operator overloads that could cause this statement > to generate a directed graph with the structure shown. Yes. Let's introduce ASCII art an way to describe graphs in Python. Best, Sven From srkunze at mail.de Wed Sep 16 17:05:12 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Wed, 16 Sep 2015 23:05:12 +0200 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55F9D988.7060001@mail.de> On 16.09.2015 21:47, Grant Edwards wrote: > On 2015-09-16, Sven R. Kunze wrote: >> On 16.09.2015 19:46, Grant Edwards wrote: >>> On 2015-09-16, Steven D'Aprano wrote: >>> >>>> node = left <= ptr => right >>> Exactly. I've no clue what that means. ;) >> Modern art. ;) > Ah, well I know that _that_ means: > > "I think it exemplifies the angst and conflict inherent in modern > society". > > You can say that while standing in front of any piece of modern art, > and most everybody will just nod. Try it. > So right. But hey, it's a sport. ;) Btw. ASCII art is also art. So, why does Python not have ASCII art to define graphs and diagrams? Best, Sven From breamoreboy at yahoo.co.uk Wed Sep 16 17:27:01 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 16 Sep 2015 22:27:01 +0100 Subject: True == 1 weirdness In-Reply-To: <55F9D36B.40501@oddbird.net> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9ACAD.7080508@mail.de> <55F9D36B.40501@oddbird.net> Message-ID: On 16/09/2015 21:39, Carl Meyer wrote: > On 09/16/2015 02:29 PM, Mark Lawrence wrote: >> On 16/09/2015 18:53, Sven R. Kunze wrote: >>> On 16.09.2015 19:39, Steven D'Aprano wrote: >>>> node = left <= ptr => right >>> >>> Wow. I have absolutely no idea what this is supposed to mean. Do you >>> care to elaborate? >>> >>> >>> Best, >>> Sven >> >> Simple, straight forward easy to read bit of Python, where is the >> problem? node is bound to the boolean ptr is greater than or equal to >> left and right. > > Except it's a SyntaxError because Python has no => operator. > > Carl > Yes, Steven has made this mistake elsewhere. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Wed Sep 16 17:30:33 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 16 Sep 2015 22:30:33 +0100 Subject: True == 1 weirdness In-Reply-To: <55F9D988.7060001@mail.de> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9D988.7060001@mail.de> Message-ID: On 16/09/2015 22:05, Sven R. Kunze wrote: > > > On 16.09.2015 21:47, Grant Edwards wrote: >> On 2015-09-16, Sven R. Kunze wrote: >>> On 16.09.2015 19:46, Grant Edwards wrote: >>>> On 2015-09-16, Steven D'Aprano wrote: >>>> >>>>> node = left <= ptr => right >>>> Exactly. I've no clue what that means. ;) >>> Modern art. ;) >> Ah, well I know that _that_ means: >> >> "I think it exemplifies the angst and conflict inherent in modern >> society". >> >> You can say that while standing in front of any piece of modern art, >> and most everybody will just nod. Try it. > > So right. But hey, it's a sport. ;) > > > Btw. ASCII art is also art. So, why does Python not have ASCII art to > define graphs and diagrams? > > Best, > Sven Barry John art is also art. So, why does Python not have Barry John art to define graphs and diagrams? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From srkunze at mail.de Wed Sep 16 18:15:39 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 17 Sep 2015 00:15:39 +0200 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9D988.7060001@mail.de> Message-ID: <55F9EA0B.9050103@mail.de> On 16.09.2015 23:30, Mark Lawrence wrote: > Barry John art is also art. So, why does Python not have Barry John > art to define graphs and diagrams? Too colorful for a grammer? From lac at openend.se Wed Sep 16 18:19:26 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 17 Sep 2015 00:19:26 +0200 Subject: Packaging and deployment of standalone Python applications? In-Reply-To: <55F9C313.8040202@gmail.com> References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> <55F9C313.8040202@gmail.com> Message-ID: <201509162219.t8GMJQeI024717@fido.openend.se> In a message of Wed, 16 Sep 2015 21:29:23 +0200, Kristian Rink writes: >Am 15.09.2015 um 08:59 schrieb paul.hermeneutic at gmail.com: >> >> https://docs.python.org/3/library/venv.html?highlight=venv#module-venv > >Thanks, this already is pretty close to what I need. Playing with this >and virtualenv, I figured out that this way it's pretty easily possible >to have isolated Python environments _locally_. However I failed to >package one of these environments and move it to, say, from my Ubuntu >development host to a remote Debian server, I end up with errors like >these while trying to run the Python off the environment on that host: > >/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found > >I bundled all the stuff in the virtualenv and also made sure to >dereference the symlinks in there. Are Python binaries so closely tied >to a particular Linux environment / distribution that what I am about to >do is impossible? Is there a "generic" Python for Linux binary that >works on all distributions, as things are for Java? > >TIA and all the best, >Kristian >-- >https://mail.python.org/mailman/listinfo/python-list Your problem is likely with the shared library search paths. Different distributions put them in different places. It's a real pain, and the reason why docker is getting more popular. According to http://www.eyrie.org/~eagle/notes/rpath.html there is a way to get around this by encoding the rpath in your application, but I cannot vouch for it personally. Laura From python.list at tim.thechases.com Wed Sep 16 19:10:48 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 16 Sep 2015 18:10:48 -0500 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20150916181048.47405a8d@bigbox.christie.dr> On 2015-09-16 21:25, Mark Lawrence wrote: > Is it:- > > modern art == crap > > or > > modern art = crap Pretty sure they're both wrong... modern art < crap ;-) -tkc From huurmanfrank at gmail.com Wed Sep 16 19:45:03 2015 From: huurmanfrank at gmail.com (Frank Huurman) Date: Thu, 17 Sep 2015 01:45:03 +0200 Subject: foldername change killed python Message-ID: Heya, I just uninstalled Python 3.5 so I can reinstall it with the default path. Took me a day to figure out why my extra modules weren't importing in py2exe properly and why the Python for windows extensions kept on telling me I didn't have Python 3.5 installed while in fact I did. It wasn't a well known 64 bit/32 bit case this time but the fact that I installed Python 3.5 to C:\Python35 and changed the name to C:\Python 3.5 After that everything just went haywire cause the python for windows extensions where looking at the wrong folder and stuff was telling me that Python 3.5 didn't exist while IDLE was just sitting there in my start menu. It's a stupid thing but I know for sure a lot of people are going nuts because they did something like I did today. Kind Regards, Frank. -------------- next part -------------- An HTML attachment was scrubbed... URL: From huurmanfrank at gmail.com Wed Sep 16 19:55:00 2015 From: huurmanfrank at gmail.com (Frank Huurman) Date: Thu, 17 Sep 2015 01:55:00 +0200 Subject: foldername change killed python In-Reply-To: References: Message-ID: Still doesn't work with the default path. For some reason the script that worked 20 mins ago in IDLE using "import win32com.client" can't find the module anymore so I messed it up somewhere. 2015-09-17 1:45 GMT+02:00 Frank Huurman : > Heya, I just uninstalled Python 3.5 so I can reinstall it with the default > path. > > Took me a day to figure out why my extra modules weren't importing in > py2exe properly and why the Python for windows extensions kept on telling > me I didn't have Python 3.5 installed while in fact I did. > It wasn't a well known 64 bit/32 bit case this time but the fact that I > installed Python 3.5 to C:\Python35 > > and changed the name to C:\Python 3.5 > > After that everything just went haywire cause the python for windows > extensions where looking at the wrong folder and stuff was telling me that > Python 3.5 didn't exist while IDLE was just sitting there in my start menu. > > > It's a stupid thing but I know for sure a lot of people are going nuts > because they did something like I did today. > > > Kind Regards, > > Frank. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Wed Sep 16 20:06:37 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 17 Sep 2015 01:06:37 +0100 Subject: True == 1 weirdness In-Reply-To: <55F9EA0B.9050103@mail.de> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9D988.7060001@mail.de> <55F9EA0B.9050103@mail.de> Message-ID: On 16/09/2015 23:15, Sven R. Kunze wrote: > On 16.09.2015 23:30, Mark Lawrence wrote: >> Barry John art is also art. So, why does Python not have Barry John >> art to define graphs and diagrams? > > Too colorful for a grammer? I'm not with you, sorry. Is "grammer" the US spelling of the UK "grammar"? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Wed Sep 16 20:53:32 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Sep 2015 10:53:32 +1000 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9D988.7060001@mail.de> <55F9EA0B.9050103@mail.de> Message-ID: On Thu, Sep 17, 2015 at 10:06 AM, Mark Lawrence wrote: > On 16/09/2015 23:15, Sven R. Kunze wrote: >> >> On 16.09.2015 23:30, Mark Lawrence wrote: >>> >>> Barry John art is also art. So, why does Python not have Barry John >>> art to define graphs and diagrams? >> >> >> Too colorful for a grammer? > > > I'm not with you, sorry. Is "grammer" the US spelling of the UK "grammar"? Certainly not. A grammer is something which grams. A gram is one thousandth of an SI unit. ChrisA From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Wed Sep 16 21:02:28 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Thu, 17 Sep 2015 02:02:28 +0100 Subject: kivy editable multicolumn list References: Message-ID: ?s 08:44 de 15-09-2015, David Aldrich escreveu: >> Not sure if this is the place to ask about kivy ... > > Try the kivy users list here: > > https://groups.google.com/forum/#!forum/kivy-users Thanks for the link. From emile at fenx.com Wed Sep 16 21:12:25 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 16 Sep 2015 18:12:25 -0700 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9D988.7060001@mail.de> <55F9EA0B.9050103@mail.de> Message-ID: On 9/16/2015 5:53 PM, Chris Angelico wrote: > On Thu, Sep 17, 2015 at 10:06 AM, Mark Lawrence wrote: >> On 16/09/2015 23:15, Sven R. Kunze wrote: >>> >>> On 16.09.2015 23:30, Mark Lawrence wrote: >>>> >>>> Barry John art is also art. So, why does Python not have Barry John >>>> art to define graphs and diagrams? >>> >>> >>> Too colorful for a grammer? >> >> >> I'm not with you, sorry. Is "grammer" the US spelling of the UK "grammar"? > > Certainly not. A grammer is something which grams. A gram is one > thousandth of an SI unit. My grammer used to say some pretty colorful things. :) Thankfully-my-daughter-the-english-teacher-won't-see-this-ly y'rs, Emile From steve at pearwood.info Wed Sep 16 21:16:25 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 17 Sep 2015 11:16:25 +1000 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <1442422672.1804523.385461961.6F1DFD96@webmail.messagingengine.com> <55f9a9e8$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55fa1469$0$1636$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Sep 2015 03:44 am, Grant Edwards wrote: > On 2015-09-16, Steven D'Aprano wrote: >> On Thu, 17 Sep 2015 03:27 am, Grant Edwards wrote: >> >>> On 2015-09-16, Sven R. Kunze wrote: >>>> On 16.09.2015 18:57, Random832 wrote: >>>>> I think that chaining should be limited to: >>>>> >>>>> A) all operators are "=" >>>>> B) all operators are "is" >> >> [...] >>> I'm not all that sure A and B should be allowed. >> >> You can take `x == y == z` off me when you pry it from my cold, dead >> hands. > > Well, that case hadn't been mentioned yet. But, I agree that should be > added as case E and be allowed. I assumed that since we were talking about *operators* and *comparisons*, Random832 had merely typoed "=" when (s)he meant "==", since assignment = is neither an operator nor a comparison. But while we're at it, you can also take away chained assignments over my dead body -- and even then, I'll probably come back from the grave as vengeful spirit to wreck bloody retribution on all those responsible. -- Steven From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Wed Sep 16 21:17:09 2015 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Thu, 17 Sep 2015 02:17:09 +0100 Subject: kivy editable multicolumn list References: Message-ID: ?s 11:42 de 15-09-2015, Laura Creighton escreveu: > In a message of Tue, 15 Sep 2015 03:31:49 +0100, Paulo da Silva writes: ... >> Now I would like to change the background color the editable field. >> ... > > I just hardcoded it like this: > > integers_dict = {str(i): {'text': str(i), 'is_selected': False} > for i in range(100)} > > which I pasted out of http://kivy.org/docs/api-kivy.uix.listview.html > 'Using an Item View Template'. This may have no relation to what you > really want. The example is closely based on an example that comes with kivy and is supposed to run in the same directory. The fixtures there contain the same as you hardcoded. > > you also need a line > from kivy.graphics import Color, Rectangle It's there. I just forgot to mention it. > > Then you change your class definition to be: > > class EditableLabel(ListItemLabel): > def __init__(self,**kwargs): > super(EditableLabel, self).__init__(**kwargs) > self.bind(pos=self.redraw) > self.bind(size=self.redraw) > > def redraw(self, *args): > self.canvas.clear() > with self.canvas: > Color(.5,.5,.5) > Rectangle(pos=self.pos,size=self.size) > This works but not as I expected. So it fixes the bug but the result I got is not the pretended one. I was trying to change the background color of the editable field. That's the reason for the colored rectangle. But the rectangle overlaps the text! So the entered text is hidden. > I don't know why changing self.canvas.before: to self.canvas: in the redraw > method was needed here. I expected self.canvas.before to be what was > needed, but doesn't seem that way. > > If you don't clear the canvas first, in the redraw the results look very > silly to me. In both situations redraw is entered with wrong self.pos and self.size values. So there are extra rectangles drawn at wrong places and sizes. I can't understand why. Changing self.canvas.before to self.canvas and inserting self.canvas.clear() fixes the problem. But as I said the drawn rectangle hides the label text. Thank you Laura. From steve at pearwood.info Wed Sep 16 21:22:19 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 17 Sep 2015 11:22:19 +1000 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55fa15cb$0$1659$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Sep 2015 03:41 am, Sven R. Kunze wrote: > On 16.09.2015 19:33, Steven D'Aprano wrote: >> On Thu, 17 Sep 2015 01:40 am, Random832 wrote: >> >>> "in" suggests a relationship between objects of different types (X and >>> "something that can contain X") - all the other comparison operators are >>> meant to work on objects of the same or similar types. >> `is` and the equality operators are intended to work on arbitrary >> objects, as are their inverses `is not` and inequality. >> >> And with operator overloading, < <= > and => could have any meaning you >> like: >> >> graph = a => b => c <= d <= e >> > > Sorry? What are you trying to do here? Anything you like, I just made it up. That's the point: if a, b, etc have overloaded the operators, they could mean anything. The idea I vaguely had was that they constructed a graph, using => and <= as "arrows" so that the above would be equivalent to the graph: a -> b -> c <- d <- e (a to b, b to c; e to d, d also to c) -- Steven From steve at pearwood.info Wed Sep 16 21:25:06 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 17 Sep 2015 11:25:06 +1000 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55fa1672$0$1659$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Sep 2015 03:47 am, Random832 wrote: > On Wed, Sep 16, 2015, at 13:33, Steven D'Aprano wrote: >> On Thu, 17 Sep 2015 01:40 am, Random832 wrote: >> >> > "in" suggests a relationship between objects of different types (X and >> > "something that can contain X") - all the other comparison operators >> > are meant to work on objects of the same or similar types. >> >> `is` and the equality operators are intended to work on arbitrary >> objects, >> as are their inverses `is not` and inequality. > > But they won't return *true* unless they're the same or similar types. So what? The intended purpose of `is` and `==` is not to return True. It is to perform a comparison which may return False, or True. >> And with operator overloading, < <= > and => could have any meaning you >> like: >> >> graph = a => b => c <= d <= e > > Are you suggesting that all objects concerned are a magical "graph node > object", the <= and [sic] => operators of which return "edge objects", > the and operator of which constructs a graph object containing all such > edges? That's *horrifying*. And won't actually work. We haven't actually > got an => operator, thankfully, and you can't overload 'and'. Ah yes, well, there is that. Oops. > I bet you could do it in C++ though. Almost certainly. -- Steven From steve at pearwood.info Wed Sep 16 21:33:19 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 17 Sep 2015 11:33:19 +1000 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9D988.7060001@mail.de> <55F9EA0B.9050103@mail.de> Message-ID: <55fa185f$0$1666$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Sep 2015 10:06 am, Mark Lawrence wrote: > On 16/09/2015 23:15, Sven R. Kunze wrote: >> On 16.09.2015 23:30, Mark Lawrence wrote: >>> Barry John art is also art. So, why does Python not have Barry John >>> art to define graphs and diagrams? >> >> Too colorful for a grammer? > > I'm not with you, sorry. Is "grammer" the US spelling of the UK > "grammar"? Mark, take a close look at Sven's name, and his email address. When your German is better than his English, then you can pick on his spelling. -- Steven From rdavid.br at gmail.com Wed Sep 16 21:37:56 2015 From: rdavid.br at gmail.com (Rafael David) Date: Wed, 16 Sep 2015 18:37:56 -0700 (PDT) Subject: Problem with lists In-Reply-To: References: <008a92e2-9e56-4ac8-aa5f-2b121380778a@googlegroups.com> <14692e48-f543-4719-87ce-3eb38adf4db4@googlegroups.com> Message-ID: <32c0ed39-59d8-42c5-b7fd-175af6a96021@googlegroups.com> Em ter?a-feira, 15 de setembro de 2015 21:47:10 UTC-3, Chris Angelico escreveu: > On Wed, Sep 16, 2015 at 10:29 AM, Rafael David wrote: > > Oooohhh ... I think I got it! I'm assigning a reference to peca and not the value itself! Thank you very much MRAB and C Smith for the enlightenment :) > > Right! That's how Python's assignment always works. You may find, in > your case, that you can simply reassign peca={} every time through the > loop. No copying necessary - just make yourself a new dict for each > iteration. > > And you might be able to do the whole thing with a gigantic > list/list/dict comprehension, but that may or may not be an > improvement on your code :) > > ChrisA Yes, got it. Thanks Chris! Guys, this group rocks :) From steve at pearwood.info Wed Sep 16 22:31:32 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 17 Sep 2015 12:31:32 +1000 Subject: Context-aware return References: <55f1c3c6$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55fa2604$0$1652$c3e8da3$5496439d@news.astraweb.com> On Sun, 13 Sep 2015 09:27 am, Ned Batchelder wrote: > On Thursday, September 10, 2015 at 8:44:01 PM UTC-4, Denis McMahon wrote: >> On Fri, 11 Sep 2015 03:54:14 +1000, Steven D'Aprano wrote: >> >> > If I did this thing, would people follow me down the street booing and >> > jeering and throwing things at me? >> >> Yes >> >> >>> x = func() >> >>> x >> >>> func() >> >>> print x == func() >> >>> assert x == func() >> >> Would you expect the last two calls to func() to return 999 or "Awesome"? >> Why? What is the material difference if any between interpreter (a) >> displaying the return value and (b) comparing the return value with >> another value. >> >> Debugging nightmare! > > I'll add my voice to the rising chorus condemning the very notion > of a function that behaves this way! > > Then, I'll give you an implementation (Python 2): Excellent! *cough* I mean, well, that's interesting. Of course no sane developer would ever use such a thing. Thanks to everyone who tried to discourage me from using this. -- Steven From steve at pearwood.info Wed Sep 16 22:34:28 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 17 Sep 2015 12:34:28 +1000 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9D988.7060001@mail.de> <55F9EA0B.9050103@mail.de> Message-ID: <55fa26b4$0$1652$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Sep 2015 10:06 am, Mark Lawrence wrote: > On 16/09/2015 23:15, Sven R. Kunze wrote: >> On 16.09.2015 23:30, Mark Lawrence wrote: >>> Barry John art is also art. So, why does Python not have Barry John >>> art to define graphs and diagrams? >> >> Too colorful for a grammer? > > I'm not with you, sorry. Is "grammer" the US spelling of the UK > "grammar"? Mark, take a close look at Sven's name, and his email address. When your German is better than his English, then you can pick on his spelling. -- Steven From sol433tt at gmail.com Thu Sep 17 00:24:00 2015 From: sol433tt at gmail.com (sol433tt) Date: Thu, 17 Sep 2015 14:24:00 +1000 Subject: Sqlite pragma statement "locking_mode" set to "EXCLUSIVE" by default Message-ID: hello I would like to have the Sqlite pragma statement "locking_mode" set to "EXCLUSIVE" by default (RO database). Does this need to be compiled in? How might this be achieved? There is some performance to be gained. I have a number of python scripts, and don't want to alter the pragma statement for every script. This computer never writes to the databases. thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From random832 at fastmail.com Thu Sep 17 02:10:44 2015 From: random832 at fastmail.com (Random832) Date: Thu, 17 Sep 2015 02:10:44 -0400 Subject: True == 1 weirdness In-Reply-To: <55fa1672$0$1659$c3e8da3$5496439d@news.astraweb.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> <55fa1672$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1442470244.2993304.385993113.2B9CECFA@webmail.messagingengine.com> On Wed, Sep 16, 2015, at 21:25, Steven D'Aprano wrote: > So what? The intended purpose of `is` and `==` is not to return True. It > is > to perform a comparison which may return False, or True. Yeah, but there's no point in doing a comparison unless you're doing it in a context where it *might* return true. Semantics matter. From kawazu428 at gmail.com Thu Sep 17 02:23:52 2015 From: kawazu428 at gmail.com (Kristian Rink) Date: Thu, 17 Sep 2015 08:23:52 +0200 Subject: Packaging and deployment of standalone Python applications? In-Reply-To: <201509162219.t8GMJQeI024717@fido.openend.se> References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> <55F9C313.8040202@gmail.com> <201509162219.t8GMJQeI024717@fido.openend.se> Message-ID: <55FA5C78.2080308@gmail.com> Hi Laura; and first off, thanks bunches for your comment. Am 17.09.2015 um 00:19 schrieb Laura Creighton: > > Your problem is likely with the shared library search paths. > Different distributions put them in different places. It's a real > pain, and the reason why docker is getting more popular. Well I thought something like this but then again wondered whether this really would be the cause - after all, Thunderbird, Firefox, OpenOffice, Java and a bunch of other applications that are available as "binary" downloads for "generic Linux" do seem to work on RedHat/CentOS, Debian, Ubuntu without these issues. Are these all statically built? Would this be an option for distributing Python applications, as well? Or, other option: Would it work to, say, use venv, make sure there always is a Python of the same version on the target machine installed (say 3.4), and then distribute "just" the python parts without including the interpreter / binary itself? Thanks in advance and all the best, Kristian From greg.ewing at canterbury.ac.nz Thu Sep 17 02:24:56 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 17 Sep 2015 18:24:56 +1200 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: Chris Angelico wrote: > But are there _any_ comparison operators which > are unchainable? If not, there's no reason to disallow 'in'; My problem is that I find it difficult to remember that Python considers 'in' to be a comparison operator. To me, comparison is something you do between things of the same kind, whereas 'in' is a relationship between things of different kinds. Calling it a comparison is like comparing apples and oranges. Or apples and baskets of apples, or something. -- Greg From greg.ewing at canterbury.ac.nz Thu Sep 17 02:30:06 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 17 Sep 2015 18:30:06 +1200 Subject: True == 1 weirdness In-Reply-To: <87fv2ejog3.fsf@elektro.pacujo.net> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <87fv2ejog3.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > "Sven R. Kunze" : > >>But I agree more than this often helps confusion more than it helps >>clarity. > > I see what you did there. I see what you saw what he did there. -- Greg From greg.ewing at canterbury.ac.nz Thu Sep 17 02:36:29 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 17 Sep 2015 18:36:29 +1200 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: Mark Lawrence wrote: > Is it:- > > modern art == crap > > or > > modern art = crap It's modern == art == crap, surely? -- Greg From greg.ewing at canterbury.ac.nz Thu Sep 17 02:39:04 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 17 Sep 2015 18:39:04 +1200 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: Sven R. Kunze wrote: > Btw. ASCII art is also art. So, why does Python not have ASCII art to > define graphs and diagrams? Nowadays it would have to support Unicode art. Mustn't leave out all the world's non-English-speaking artists! -- Greg From greg.ewing at canterbury.ac.nz Thu Sep 17 02:42:05 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 17 Sep 2015 18:42:05 +1200 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9D988.7060001@mail.de> <55F9EA0B.9050103@mail.de> Message-ID: Chris Angelico wrote: > Certainly not. A grammer is something which grams. A gram is one > thousandth of an SI unit. Also, when ordering a hamburger in an SI-using country, instead of a quarter-pounder you need to ask for a 125-grammer. -- Greg From harvesting at makes.email.invalid Thu Sep 17 03:06:37 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Thu, 17 Sep 2015 10:06:37 +0300 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: Gregory Ewing writes: > My problem is that I find it difficult to remember that Python > considers 'in' to be a comparison operator. > > To me, comparison is something you do between things of the same kind, > whereas 'in' is a relationship between things of different > kinds. Calling it a comparison is like comparing apples and > oranges. Or apples and baskets of apples, or something. Ordinary binary operators not only combine things of the same type, they also produce a thing of that same type. So 'in' does not fit among them either. I feel it's _more_ at home among comparison operators. (Hm. That's 'operator' in a different sense.) From auriocus at gmx.de Thu Sep 17 03:24:35 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 17 Sep 2015 09:24:35 +0200 Subject: Packaging and deployment of standalone Python applications? In-Reply-To: References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> Message-ID: Am 16.09.15 um 21:29 schrieb Kristian Rink: > Thanks, this already is pretty close to what I need. Playing with this > and virtualenv, I figured out that this way it's pretty easily possible > to have isolated Python environments _locally_. However I failed to > package one of these environments and move it to, say, from my Ubuntu > development host to a remote Debian server, I end up with errors like > these while trying to run the Python off the environment on that host: > > /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found This is a typical problem on Linux when moving binaries between different distributions. The libc is the most basic library, used by programs compiled from C (virtually everything). Fortunately it has a very good version management which makes it backwards compatible. Have you compiled everything from source? The solution is to compile everything on the oldest machine which you can get hold of. If you want portable binaries on Linux, I suggest that you carry along with your program all shared libraries except libc & friends (libm, libstdc++,...), which really are part of the operating system, and to setup a VM with an old libc6-distribution where you compile your stuff. For instance try Ubuntu 10.04 LTS. There is a nice management tools for these VMs called Vagrant https://www.vagrantup.com/ If you think, that this is lots of tedious work, you are right - deployment is hard work. Ideally, you would have Python installation that can be carried along as a binary directory and in variants for all major OSes. In the case of the Java VM this is just easier because somebody else already did the hard work. On Windows, I used PortablePython in the past for a similar project, but this is gone. Another possibility is ActivePython, but I think the free license does not allow to carry it to other computers - in principle it could work. IMHO this is one of the lacks of CPython. Distributing source is not always practical, especially if the project involves modules written in C, or a large number of 3rd party libraries. To provide linux binaries as .rpm and .deb, as suggested elsewhere in this thread, is even more cumbersome than binaries in this case - you'd have to set the right dependencies for a huge variety of distributions, such that the package manager pulls, e.g. "python-pillow" on one distro and "libpillow" on another etc. A well maintained portable distribution for all major platforms could substantially ease that out. Christian From rosuav at gmail.com Thu Sep 17 03:38:43 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Sep 2015 17:38:43 +1000 Subject: Packaging and deployment of standalone Python applications? In-Reply-To: References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> Message-ID: On Thu, Sep 17, 2015 at 5:24 PM, Christian Gollwitzer wrote: > IMHO this is one of the lacks of CPython. Distributing source is not always > practical, especially if the project involves modules written in C, or a > large number of 3rd party libraries. To provide linux binaries as .rpm and > .deb, as suggested elsewhere in this thread, is even more cumbersome than > binaries in this case - you'd have to set the right dependencies for a huge > variety of distributions, such that the package manager pulls, e.g. > "python-pillow" on one distro and "libpillow" on another etc. A well > maintained portable distribution for all major platforms could substantially > ease that out. If you want to know what's state of the art there - and even more so: if you want to push the state of the art - join the distutils-sig mailing list: https://mail.python.org/mailman/listinfo/distutils-sig This is where these kinds of questions will be discussed, and (hopefully!) solved. ChrisA From chenchao at inhand.com.cn Thu Sep 17 03:41:26 2015 From: chenchao at inhand.com.cn (chenchao at inhand.com.cn) Date: Thu, 17 Sep 2015 15:41:26 +0800 Subject: python how to load multiple C libraries In-Reply-To: <201509161313.t8GDDfUM017723@fido.openend.se> References: <55F937D6.6040104@inhand.com.cn> <201509161313.t8GDDfUM017723@fido.openend.se> Message-ID: <55FA6EA6.1030405@inhand.com.cn> hi: I use ctypes load multiple C libraries. Code like this: ..... history = CDLL("/usr/lib/libhistory.so", mode=RTLD_GLOBAL|RTLD_LAZY) ncurses = CDLL("/usr/lib/libncurses.so", mode=RTLD_GLOBAL|RTLD_LAZY) readline = CDLL("/usr/lib/libreadline.so", mode=RTLD_GLOBAL|RTLD_LAZY) ... When I execute my python scripts, it come out followed error: /var/app/python/scripts # python test.py Traceback (most recent call last): File "test.py", line 4, in history = CDLL("/usr/lib/libhistory.so", mode=RTLD_GLOBAL|RTLD_LAZY) NameError: name 'RTLD_LAZY' is not defined. So, I checked my ctypes source code, I found RTLD_LAZY defined in dlfcn.h header file like this: /* The MODE argument to `dlopen' contains one of the following: */ #define RTLD_LAZY 0x00001 /* Lazy function call binding. */ #define RTLD_NOW 0x00002 /* Immediate function call binding. */ #define RTLD_BINDING_MASK 0x3 /* Mask of binding time value. */ #define RTLD_NOLOAD 0x00004 /* Do not load the object. */ #if 0 /* uClibc doesnt support these */ #define RTLD_DEEPBIND 0x00008 /* Use deep binding. */ #endif /* If the following bit is set in the MODE argument to `dlopen', the symbols of the loaded object and its dependencies are made visible as if the object were linked directly into the program. */ #define RTLD_GLOBAL 0x00100 /* Unix98 demands the following flag which is the inverse to RTLD_GLOBAL. The implementation does this by default and so we can define the value to zero. */ #define RTLD_LOCAL 0 /* Do not delete object when closed. */ #define RTLD_NODELETE 0x01000 The first of all, I have added followed codes in function: PyMODINIT_FUNC init_ctypes(void) {...} in _ctypes.c file. /* add RTLD_LAZY and RTLD_NOW definitions*/ PyModule_AddObject(m, "RTLD_LAZY", PyInt_FromLong(RTLD_LAZY)); PyModule_AddObject(m, "RTLD_NOW", PyInt_FromLong(RTLD_NOW)); So, Is there anybody know how the CDLL can accept mode flag:RTLD_LAZY? On 09/16/2015 09:13 PM, Laura Creighton wrote: > In a message of Wed, 16 Sep 2015 17:35:18 +0800, "chenchao at inhand.com.cn" write > s: >> hi: >> I encountered a problem. I use ctypes load multiple C libraries, but >> the libraries have dependence each other.So, how can i load these >> libraries. For example, I have two libraries:A?B, but A depends on B, B >> depends on A. So how do I load them? Is there anybody know how to do it? > I don't know how to do this with ctypes (which doesn't mean it cannot be > done, just that I haven't ever wanted to do this). What happens if you > make a small file that loads both separately and loads that one first? > > It may be that you can get what you want with by loading the first lib > RTLD_LAZY instead of RTLD_NOW. see: > http://stackoverflow.com/questions/22591472/dyanamic-library-linking-by-rtld-lazy > see: this very old thread, maybe CTypes knows about it now. > http://osdir.com/ml/python.ctypes/2006-10/msg00029.html > > But I have never tried. > > These days I used cffi instead of ctypes. > > If you use cffi https://pypi.python.org/pypi/cffi > there should not be any problem if you use ffi.set_source(), > only once, but mentioning both libs in the libraries=[...] argument. > > Laura > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Thu Sep 17 05:06:26 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 17 Sep 2015 11:06:26 +0200 Subject: Packaging and deployment of standalone Python applications? In-Reply-To: <55FA5C78.2080308@gmail.com> References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> <55F9C313.8040202@gmail.com> <201509162219.t8GMJQeI024717@fido.openend.se> <55FA5C78.2080308@gmail.com> Message-ID: <201509170906.t8H96QgJ024048@fido.openend.se> In a message of Thu, 17 Sep 2015 08:23:52 +0200, Kristian Rink writes: >Hi Laura; > >and first off, thanks bunches for your comment. > >Am 17.09.2015 um 00:19 schrieb Laura Creighton: > > >> Your problem is likely with the shared library search paths. >> Different distributions put them in different places. It's a real >> pain, and the reason why docker is getting more popular. > >Well I thought something like this but then again wondered whether this >really would be the cause - after all, Thunderbird, Firefox, OpenOffice, >Java and a bunch of other applications that are available as "binary" >downloads for "generic Linux" do seem to work on RedHat/CentOS, Debian, >Ubuntu without these issues. Are these all statically built? Would this >be an option for distributing Python applications, as well? Mozilla uses a hybrid static and binary build thing. http://www-archive.mozilla.org/build/static-build.html and confusingly calls that a static build. My Java didn't come as a generic Linux download. I had to use the debian package. Same for libreoffice. I needed a .deb for that. For instance, if you look at the libre office instructions it first hops up and down saying you should use whatever your package manager provides. https://www.libreoffice.org/get-help/install-howto/linux/ Then it leads to the wiki which leads to the download page http://www.libreoffice.org/download/libreoffice-fresh/ If you download from this page you will see that it detects what sort of linux you are running and gets you a .rmp or a .deb depending on what you need. That's 4 choices, because 32 bit and 64 bit is also different. If it makes a mistake and decides you need the wrong sort of binary package, you can demand that you get the sort you want. This will handle most of them, but if you need Gentoo linux you will have to do something else, and there are undoubtably other linux versions that don't understand .deb or .rpms Now go back to the wiki and read https://wiki.documentfoundation.org/Documentation/Install/Linux the section Terminal-Based Install As I warned you, it is a real horror. >Or, other option: Would it work to, say, use venv, make sure there >always is a Python of the same version on the target machine installed >(say 3.4), and then distribute "just" the python parts without including >the interpreter / binary itself? Getting a Python of the same version is rarely necessary. That's not where your problem is. Except that Python 3.x are not compatible with Python 2.x, the general rule is that later versions of Python are backwards compatible with earlier ones. If you can turn your pure python code into a python package, this will probably simplify your problem. But, no promises here. I don't know enough about what you are trying to do, and this is only a general rule of thumb. >Thanks in advance and all the best, >Kristian Here's the PyPy Story. PyPy is a fast version of Python written in Python. It has a JIT. On our download page: http://pypy.org/download.html These days PyPy is really popular. So there is a real official debian package, ubuntu package, red hat package, and a gentoo package and all the rest. Which means there is a real human being who is reponsible for making such things for each distro. This is a welcome outcome of being popular. It wasn't always that way. We had to make binaries for wherever we wanted to run (everywhere). The download page still contains a list of possible binaries. Linux x86 binary (32bit, tar.bz2 built on Ubuntu 12.04 - 14.04) (see [1]) Linux x86-64 binary (64bit, tar.bz2 built on Ubuntu 12.04 - 14.04) (see [1]) ARM Hardfloat Linux binary (ARMHF/gnueabihf, tar.bz2, Raspbian) (see [1]) ARM Hardfloat Linux binary (ARMHF/gnueabihf, tar.bz2, Ubuntu Raring) (see [1]) ARM Softfloat Linux binary (ARMEL/gnueabi, tar.bz2, Ubuntu Precise) (see [1]) ... Note 1 contains more language about if this is not your exact distro, it will not work. We say this all over the place and people still do not get it. Our binrary list used to be a whole lot longer. And the situation was impossible. We couldn't build pypys for every linux distro on the planet, because we didn't own every one. So we were dependent on having happy users make one from source, and giving it to us. Which people did. But it meant that every time we made a release we had to spend forever talking to people over irc or on the mailing list who couldn't get the source build to build. Make a symlink here, make a symlink there. When you add to the mix that building pypy, starting with CPython instead of an earlier version of PyPy can grind away for 3 hours and then fall flat over when you first try to run it because you didn't get the dependencies quite right .... It was nothing but pain. So when docker came out, we jumped at the chance to get out of this mess. It worked. We're deliriously happy with the result. And now we have portable binaries that run anywhere. Armin Rigo (I think) figured out how to hack the RPATH to get it to work most everywhere. I am not sure how that goes, but Armin will either explain it to you or point you at the correct document to read if you ask. He's very nice that way. see: https://github.com/squeaky-pl/portable-pypy#portable-pypy-distribution-for-linux Wish I could be more encouraging, Laura From arupneo2 at gmail.com Thu Sep 17 05:19:19 2015 From: arupneo2 at gmail.com (arupneo2 at gmail.com) Date: Thu, 17 Sep 2015 02:19:19 -0700 (PDT) Subject: Einstein's Riddle In-Reply-To: References: Message-ID: <1cef1669-1a62-4fe8-ac31-6fff385e77ed@googlegroups.com> This is not true that only two percent of this world can solve this puzzle. May be the 2% will solve it by a quick look on the statements. From pozzugno at gmail.com Thu Sep 17 05:28:04 2015 From: pozzugno at gmail.com (pozz) Date: Thu, 17 Sep 2015 11:28:04 +0200 Subject: pyserial and threads Message-ID: I'm trying to create a simple program in Python that opens N serial ports (through pyserial) and forward every byte received on one of those ports to the other ports. At startup I open the ports and create and start a thread to manage the receiving. When a byte is received, I call the .write() method for all the other ports. It works, but sometimes it seems to block. I think I haven't used correctly the threads. Below is my code, I hope someone can help me. Consider that I'm a newbie in python and I never used threads before. import serial import threading import sys, os import signal import time class Miniterm(object): def __init__(self, port, baudrate): self.serial = serial.Serial(port, baudrate, timeout=1) def start(self, com_list): self.alive = True self.com_list = com_list self._reader_alive = True self.receiver_thread = threading.Thread(target=self.reader) self.receiver_thread.setDaemon(True) self.receiver_thread.start() def stop(self): self.alive = False def reader(self): try: while self.alive and self._reader_alive: data = self.serial.read(1) if len(data) > 0: for p in self.com_list: if p[1] != self: p[1].write(data) except serial.SerialException: self.alive = False raise def write(self, data): self.serial.write(data) if __name__ == "__main__": ports = [] for com in sys.argv[1:]: try: miniterm = Miniterm(com, 38400) except serial.SerialException: sys.stderr.write("could not open port " + com) sys.exit(1) ports.append((com, miniterm)) for p in ports: p[1].start(ports) print("Port " + p[0] + " has started", flush=True) while True: time.sleep(1) From lac at openend.se Thu Sep 17 05:38:39 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 17 Sep 2015 11:38:39 +0200 Subject: python how to load multiple C libraries In-Reply-To: <55FA6EA6.1030405@inhand.com.cn> References: <55F937D6.6040104@inhand.com.cn> <201509161313.t8GDDfUM017723@fido.openend.se> <55FA6EA6.1030405@inhand.com.cn> Message-ID: <201509170938.t8H9cdS5032216@fido.openend.se> In a message of Thu, 17 Sep 2015 15:41:26 +0800, "chenchao at inhand.com.cn" write s: > So, I checked my ctypes source code, I found RTLD_LAZY defined in >dlfcn.h header file like this: >/* The MODE argument to `dlopen' contains one of the following: */ >#define RTLD_LAZY 0x00001 /* Lazy function call binding. */ >#define RTLD_NOW 0x00002 /* Immediate function call binding. */ >#define RTLD_BINDING_MASK 0x3 /* Mask of binding time value. */ >#define RTLD_NOLOAD 0x00004 /* Do not load the object. */ >#if 0 /* uClibc doesnt support these */ >#define RTLD_DEEPBIND 0x00008 /* Use deep binding. */ >#endif > >/* If the following bit is set in the MODE argument to `dlopen', > the symbols of the loaded object and its dependencies are made > visible as if the object were linked directly into the program. */ >#define RTLD_GLOBAL 0x00100 > >/* Unix98 demands the following flag which is the inverse to RTLD_GLOBAL. > The implementation does this by default and so we can define the > value to zero. */ >#define RTLD_LOCAL 0 > >/* Do not delete object when closed. */ >#define RTLD_NODELETE 0x01000 >The first of all, I have added followed codes in function: >PyMODINIT_FUNC init_ctypes(void) {...} in _ctypes.c file. > > /* add RTLD_LAZY and RTLD_NOW definitions*/ > PyModule_AddObject(m, "RTLD_LAZY", PyInt_FromLong(RTLD_LAZY)); > PyModule_AddObject(m, "RTLD_NOW", PyInt_FromLong(RTLD_NOW)); > >So, Is there anybody know how the CDLL can accept mode flag:RTLD_LAZY? It's a known open bug. https://bugs.python.org/issue20276 Some people who have really needed to get this to work with ctypes have modified the source for ctypes as discribed here: http://osdir.com/ml/python.ctypes/2006-10/msg00029.html I just stopped using ctypes and use cffi instead. https://cffi.readthedocs.org/en/latest/ Laura From rosuav at gmail.com Thu Sep 17 05:42:08 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Sep 2015 19:42:08 +1000 Subject: pyserial and threads In-Reply-To: References: Message-ID: On Thu, Sep 17, 2015 at 7:28 PM, pozz wrote: > At startup I open the ports and create and start a thread to manage the > receiving. When a byte is received, I call the .write() method for all the > other ports. > > It works, but sometimes it seems to block. I think I haven't used correctly > the threads. > Seems a fairly reasonable model. From what I'm seeing here, you start a thread to read from each serial port, but then those threads will make blocking writes to all the other serial ports. Is it possible that one of them is getting full? When I do this kind of thing with TCP/IP sockets, I usually end up having to go non-blocking in both directions, and maintaining a buffer of unsent text for each socket. You may find that you need to do the same thing here. Where's the code getting blocked? ChrisA From breamoreboy at yahoo.co.uk Thu Sep 17 05:56:07 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 17 Sep 2015 10:56:07 +0100 Subject: True == 1 weirdness In-Reply-To: <55fa185f$0$1666$c3e8da3$5496439d@news.astraweb.com> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9D988.7060001@mail.de> <55F9EA0B.9050103@mail.de> <55fa185f$0$1666$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 17/09/2015 02:33, Steven D'Aprano wrote: > On Thu, 17 Sep 2015 10:06 am, Mark Lawrence wrote: > >> On 16/09/2015 23:15, Sven R. Kunze wrote: >>> On 16.09.2015 23:30, Mark Lawrence wrote: >>>> Barry John art is also art. So, why does Python not have Barry John >>>> art to define graphs and diagrams? >>> >>> Too colorful for a grammer? >> >> I'm not with you, sorry. Is "grammer" the US spelling of the UK >> "grammar"? > > Mark, take a close look at Sven's name, and his email address. When your > German is better than his English, then you can pick on his spelling. > I've a German 'O' level from 42 years ago, is that close enough? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From kawazu428 at gmail.com Thu Sep 17 06:36:42 2015 From: kawazu428 at gmail.com (Kristian Rink) Date: Thu, 17 Sep 2015 12:36:42 +0200 Subject: Packaging and deployment of standalone Python applications? In-Reply-To: <201509170906.t8H96QgJ024048@fido.openend.se> References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> <55F9C313.8040202@gmail.com> <201509162219.t8GMJQeI024717@fido.openend.se> <55FA5C78.2080308@gmail.com> <201509170906.t8H96QgJ024048@fido.openend.se> Message-ID: <55FA97BA.1030900@gmail.com> Hi Laura; and first off, thank you very much for your very insightful response. Some thoughts on that: Am 17.09.2015 um 11:06 schrieb Laura Creighton: > > Mozilla uses a hybrid static and binary build thing. > http://www-archive.mozilla.org/build/static-build.html > and confusingly calls that a static build. > > My Java didn't come as a generic Linux download. I had to use the > debian package. Same for libreoffice. I needed a .deb for that. Ah ok. I haven't looked too deep into Mozilla or LibreOffice, but I know there are Firefox Linux und Linux 64bit downloads that, once unpacked, will run on Debian, Ubuntu, Fedora and any other distribution I tried so far. In LibreOffice, we do have some bundle (we didn't built ourselves) living somewhere in /opt, being copied to various production machines and this, too, runs on Debian and on CentOS without issues. I do have LibreOffice (off the Ubuntu ppa) installed on my workstation, but not on the production environment also because the LibreOffice in the Ubuntu repos, as far as I can tell, will pull X as dependency while we run headless servers. Similar about Java - here, at least in Ubuntu or Debian, in some situations I used Debian facilities to create deb packages out of the official Java download which is either an rpm or a tgz. That's why I wondered in the first place: In our current deployment of (Java) services, the Java runtime gets bundled with the service for some systems, zipped, moved to the host and started there. This works well across all Linux systems, as long as they are 64bit so far. That's why I tried doing the same for Python and initially thought about this in the first place. ;) [LibreOffice] > If you download from this page you will see that it detects > what sort of linux you are running and gets you a .rmp or a .deb > depending on what you need. That's 4 choices, because 32 bit and > 64 bit is also different. Well - yes, but have you so far tried unpacking, say, the rpm manually and running the files in there on Debian? Also, it's interesting to see they "just" make a difference between deb and rpm (32bit and 64bit of course). This would end up with the same deb being installed to Debian or Ubuntu - which works, while copying a Python interpreter binary from an Ubuntu to a Debian machine obviously doesn't seem to work. So in some ways they *do* get some sort of portability in this... ? > > If you can turn your pure python code into a python package, this > will probably simplify your problem. But, no promises here. I > don't know enough about what you are trying to do, and this is only > a general rule of thumb. I will have a look at this, then, thanks. :) So far, this morning I followed the venv approach, created a venv locally on my Ubuntu development workstation, made sure to have the same python version (3.4) installed on the server (built from source in Debian), and then copied the whole venv structure (including my application) to that machine, replacing only the link to the python binary in the venv (which lives in /usr/local on the Debian system). So far this works, and if this generally would work, it seems an acceptable way to me. :) > PyPy is a fast version of Python written in Python. It has a JIT. > On our download page:http://pypy.org/download.html Neat. I just read about it but so far never actually used it. In our environment, Jython is pretty familiar (because mostly we're still a Java house and Jython integrates rather well with Java), but PyPy is interesting, definitely. > So when docker came out, we jumped at the chance to get out of this mess. > It worked. We're deliriously happy with the result. > And now we have portable binaries that run anywhere. > Armin Rigo (I think) figured out how to hack the RPATH to get it to work > most everywhere. I am not sure how that goes, but Armin will > either explain it to you or point you at the correct document to > read if you ask. He's very nice that way. > I will have a look at this and happily get back to this if it will become necessary. :) Two things come to mind, however (feel free to take this off list as I am unsure whether this still relates to Python): (a) Why is distributing PyPy so difficult, after all? From where I stand, by now I see this a "Python implementation on top of Python". How does this relate to (C)Python? How much of the PyPy core is actually platform dependent? (b) How did / does Docker help you here? So far I just experienced Docker as a solution to easily manage loads of virtual machines on top of certain machine templates; I haven't made much use of it so far nevertheless... Thanks very much anyway, all the best! Kristian From mvoicem at gmail.com Thu Sep 17 06:39:52 2015 From: mvoicem at gmail.com (m) Date: Thu, 17 Sep 2015 12:39:52 +0200 Subject: Packaging and deployment of standalone Python applications? In-Reply-To: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> References: <7360db29-ba81-4b84-99eb-dbeca2a888b8@googlegroups.com> Message-ID: <55fa9874$0$8381$65785112@news.neostrada.pl> W dniu 14.09.2015 o 08:58, Kristian Rink pisze: [...] > > Any pointers, ideas, inspirations on that greatly appreciated - even > in total different ways if what I am about to do is completely off > anyone would do it in a Python environment. ;) Look at https://github.com/jordansissel/fpm/wiki - it's really nice tool, which converts python package into .deb, .rpm - so assuming that "everyone has some (2.x/3.x) python" is true, you can just ship .deb or .rpm files. reg m From David.Aldrich at EMEA.NEC.COM Thu Sep 17 07:07:29 2015 From: David.Aldrich at EMEA.NEC.COM (David Aldrich) Date: Thu, 17 Sep 2015 11:07:29 +0000 Subject: Automating Sphinx generated documentation Message-ID: <41302A7145AC054FA7A96CFD03835A0A0B9D749B@EX10MBX02.EU.NEC.COM> Hi I have setup Sphinx for my Python project. We keep all our code and documentation in Subversion. So, following changes to the Python code, I need to regenerate and commit the Sphinx generated documentation. I just wondered how people manage this. I'm thinking of using Jenkins (a continuous integration tool) to check for changes, regenerate the docs and check them in. Any suggestions please? Best regards David -------------- next part -------------- An HTML attachment was scrubbed... URL: From alister.nospam.ware at ntlworld.com Thu Sep 17 08:00:08 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 17 Sep 2015 12:00:08 +0000 (UTC) Subject: pyserial and threads References: Message-ID: On Thu, 17 Sep 2015 11:28:04 +0200, pozz wrote: > I'm trying to create a simple program in Python that opens N serial > ports (through pyserial) and forward every byte received on one of those > ports to the other ports. > > At startup I open the ports and create and start a thread to manage the > receiving. When a byte is received, I call the .write() method for all > the other ports. > > It works, but sometimes it seems to block. I think I haven't used > correctly the threads. > > Below is my code, I hope someone can help me. > > Consider that I'm a newbie in python and I never used threads before. > > > import serial import threading import sys, os import signal import time > > class Miniterm(object): > def __init__(self, port, baudrate): > self.serial = serial.Serial(port, baudrate, timeout=1) > > def start(self, com_list): > self.alive = True self.com_list = com_list self._reader_alive = > True self.receiver_thread = threading.Thread(target=self.reader) > self.receiver_thread.setDaemon(True) self.receiver_thread.start() > > def stop(self): > self.alive = False > > def reader(self): > try: > while self.alive and self._reader_alive: > data = self.serial.read(1) > if len(data) > 0: > for p in self.com_list: > if p[1] != self: > p[1].write(data) > except serial.SerialException: > self.alive = False raise > > def write(self, data): > self.serial.write(data) > > if __name__ == "__main__": > ports = [] > for com in sys.argv[1:]: > try: > miniterm = Miniterm(com, 38400) > except serial.SerialException: > sys.stderr.write("could not open port " + com) sys.exit(1) > ports.append((com, miniterm)) > for p in ports: > p[1].start(ports) > print("Port " + p[0] + " has started", flush=True) > while True: > time.sleep(1) I would like to know more about how many serial ports are connected & what the equipment they are connected to does and expects. I can see the data being transmitted snowballing & running away in a +ve feedback loop very easily. -- The only "ism" Hollywood believes in is plagiarism. -- Dorothy Parker From alister.nospam.ware at ntlworld.com Thu Sep 17 08:07:48 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Thu, 17 Sep 2015 12:07:48 +0000 (UTC) Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9D988.7060001@mail.de> <55F9EA0B.9050103@mail.de> <55fa185f$0$1666$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 17 Sep 2015 10:56:07 +0100, Mark Lawrence wrote: > On 17/09/2015 02:33, Steven D'Aprano wrote: >> On Thu, 17 Sep 2015 10:06 am, Mark Lawrence wrote: >> >>> On 16/09/2015 23:15, Sven R. Kunze wrote: >>>> On 16.09.2015 23:30, Mark Lawrence wrote: >>>>> Barry John art is also art. So, why does Python not have Barry John >>>>> art to define graphs and diagrams? >>>> >>>> Too colorful for a grammer? >>> >>> I'm not with you, sorry. Is "grammer" the US spelling of the UK >>> "grammar"? >> >> Mark, take a close look at Sven's name, and his email address. When >> your German is better than his English, then you can pick on his >> spelling. >> >> > I've a German 'O' level from 42 years ago, is that close enough? No -- Awright, which one of you hid my PENIS ENVY? From breamoreboy at yahoo.co.uk Thu Sep 17 08:27:12 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 17 Sep 2015 13:27:12 +0100 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55F9D988.7060001@mail.de> <55F9EA0B.9050103@mail.de> <55fa185f$0$1666$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 17/09/2015 13:07, alister wrote: > On Thu, 17 Sep 2015 10:56:07 +0100, Mark Lawrence wrote: > >> On 17/09/2015 02:33, Steven D'Aprano wrote: >>> On Thu, 17 Sep 2015 10:06 am, Mark Lawrence wrote: >>> >>>> On 16/09/2015 23:15, Sven R. Kunze wrote: >>>>> On 16.09.2015 23:30, Mark Lawrence wrote: >>>>>> Barry John art is also art. So, why does Python not have Barry John >>>>>> art to define graphs and diagrams? >>>>> >>>>> Too colorful for a grammer? >>>> >>>> I'm not with you, sorry. Is "grammer" the US spelling of the UK >>>> "grammar"? >>> >>> Mark, take a close look at Sven's name, and his email address. When >>> your German is better than his English, then you can pick on his >>> spelling. >>> >>> >> I've a German 'O' level from 42 years ago, is that close enough? > > No > Oh, I'm hurt :( -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Thu Sep 17 08:29:46 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Sep 2015 12:29:46 GMT Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <55f9a7e4$0$1661$c3e8da3$5496439d@news.astraweb.com> <55fa1672$0$1659$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55fab23a$0$1654$c3e8da3$5496439d@news.astraweb.com> On Thu, 17 Sep 2015 02:10:44 -0400, Random832 wrote: > On Wed, Sep 16, 2015, at 21:25, Steven D'Aprano wrote: >> So what? The intended purpose of `is` and `==` is not to return True. >> It is >> to perform a comparison which may return False, or True. > > Yeah, but there's no point in doing a comparison unless you're doing it > in a context where it *might* return true. Semantics matter. Have we all suddenly suffered a mass outbreak of early onset Alzheimer's Disease? :-) How about the most common use of `is` of all? if some_object is None: ... Next thing we know, people will be claiming that => is an operator *wink* -- Steven D'Aprano From lac at openend.se Thu Sep 17 08:36:01 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 17 Sep 2015 14:36:01 +0200 Subject: Automating Sphinx generated documentation In-Reply-To: <41302A7145AC054FA7A96CFD03835A0A0B9D749B@EX10MBX02.EU.NEC.COM> References: <41302A7145AC054FA7A96CFD03835A0A0B9D749B@EX10MBX02.EU.NEC.COM> Message-ID: <201509171236.t8HCa16b011693@fido.openend.se> If you have watchdog installed: https://pypi.python.org/pypi/watchdog Jacob Kaplan Moss came up with this very nice one liner to do this. $ watchmedo shell-command \ --patterns="*.txt" \ --ignore-pattern='_build/*' \ --recursive \ --command='make html' change to .rst if that is what your Sphinx docs make, etc. From pozzugno at gmail.com Thu Sep 17 09:22:32 2015 From: pozzugno at gmail.com (pozz) Date: Thu, 17 Sep 2015 15:22:32 +0200 Subject: pyserial and threads In-Reply-To: References: Message-ID: Il 17/09/2015 14:00, alister ha scritto: > I would like to know more about how many serial ports are connected One real serial port and two virtual serial ports, created by com0com (it's a free virtual serial port for Windows). > what the equipment they are connected to does and expects. Raw bytes arranged in a well defined protocol. I'm the author of the protocol and equipments :-) > I can see the data being transmitted snowballing & running away in a +ve > feedback loop very easily. No, because the byte received by first COM port is forwarded/transmitted to all the OTHERS COM ports in the list. From pozzugno at gmail.com Thu Sep 17 09:23:42 2015 From: pozzugno at gmail.com (pozz) Date: Thu, 17 Sep 2015 15:23:42 +0200 Subject: pyserial and threads In-Reply-To: References: Message-ID: Il 17/09/2015 15:04, Dennis Lee Bieber ha scritto: > On Thu, 17 Sep 2015 12:00:08 +0000 (UTC), alister > declaimed the following: > > >> I can see the data being transmitted snowballing & running away in a +ve >> feedback loop very easily. > > Especially if a few of the remote devices are configured to ECHO > data... No ECHO. > Main thing I'd probably change is... Since the COM port identification > is already being provided during initialization of the handler object, why > maintain a list of (com, handler) pairs, and the subsequent subscripting -- > just save the com port as an attribute of the object. > > One could also make a copy of the object list in the start method, and > at that point, scan the list and remove that one's own identity. That would > remove the need for always testing "is the object I'm about to send to > really me?" Ok, they are optimizations, but I don't think they solve my issue. From pozzugno at gmail.com Thu Sep 17 09:26:52 2015 From: pozzugno at gmail.com (pozz) Date: Thu, 17 Sep 2015 15:26:52 +0200 Subject: pyserial and threads In-Reply-To: References: Message-ID: Il 17/09/2015 11:42, Chris Angelico ha scritto: > On Thu, Sep 17, 2015 at 7:28 PM, pozz wrote: >> At startup I open the ports and create and start a thread to manage the >> receiving. When a byte is received, I call the .write() method for all the >> other ports. >> >> It works, but sometimes it seems to block. I think I haven't used correctly >> the threads. >> > > Seems a fairly reasonable model. From what I'm seeing here, you start > a thread to read from each serial port, but then those threads will > make blocking writes to all the other serial ports. Is it possible > that one of them is getting full? > > When I do this kind of thing with TCP/IP sockets, I usually end up > having to go non-blocking in both directions, and maintaining a buffer > of unsent text for each socket. You may find that you need to do the > same thing here. How to have a non-blocking write? Maybe the problem happens when port 1 thread is in .read() (it blocks for 1 second) and port 2 thread tries to write one byte (that was just received) to port 1. > Where's the code getting blocked? I don't knwo exactly. I can only see no more bytes are received on COM ports. From rosuav at gmail.com Thu Sep 17 09:45:58 2015 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Sep 2015 23:45:58 +1000 Subject: pyserial and threads In-Reply-To: References: Message-ID: On Thu, Sep 17, 2015 at 11:26 PM, pozz wrote: > How to have a non-blocking write? > > Maybe the problem happens when port 1 thread is in .read() (it blocks for 1 > second) and port 2 thread tries to write one byte (that was just received) > to port 1. I'm not sure, as I've never worked with serial ports in this way. What you'd want is some form of call that says "write these bytes if you can, but don't if you can't, and just tell me how many you wrote". A quick look at the pyserial docs suggests that you may be able to accomplish this by opening the port with writeTimeout=0, or possibly some other value (it'll wait that many seconds - float allowed - before giving up). If it returns 0, stating that the byte wasn't written, you'd need to hang onto that byte until it can write successfully. I've no idea how you'd go about knowing that. With TCP sockets, select.select() is your friend; if you're really lucky, pyserial will work with the same kind of structure. >> Where's the code getting blocked? > > I don't knwo exactly. I can only see no more bytes are received on COM > ports. Here's a way to test: Bracket each potentially-blocking call with a status update, and then have your main loop collect the statuses and print them out. Something like this: def reader(self): try: while self.alive and self._reader_alive: self.status = 'R' # Reading data = self.serial.read(1) self.status = 'P' # Processing if len(data) > 0: for n,p in enumerate(self.com_list): if p[1] != self: self.status = n # Writing to port n p[1].write(data) self.status = 'P' except serial.SerialException: # This looks like a job for try/finally, actually self.status = 'Z' # Dead self.alive = False raise Then your main thread, instead of just sleeping forever, does this: while True: time.sleep(1) print(" ".join(port.status for port in ports), end="\r", flush=True) You should normally see most of the threads blocked on reading, assuming that the traffic levels are lower than the ports' capacities. If you start seeing them blocked on writing, chances are they'll all be blocking on the same port, and that's the port that's holding you up. Caution: Code utterly untested. You may have to debug some stuff. ChrisA From jcasale at activenetwerx.com Thu Sep 17 10:44:00 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 17 Sep 2015 14:44:00 +0000 Subject: Writing a module to abstract a REST api Message-ID: <1b35c9c9b6864d7bb9bf11e0e3cb98ca@exch.activenetwerx.com> I need to write a module to abstract the RabbitMQ HTTP REST api. Before I do this, I would like to see how other projects have done similar in the hopes I make something consistent and generic etc. Does anyone regularly work with a library that abstracts a REST API and can recommend it for review? Thanks, jlc From jon+usenet at unequivocal.co.uk Thu Sep 17 11:06:59 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Thu, 17 Sep 2015 15:06:59 +0000 (UTC) Subject: Writing a module to abstract a REST api References: Message-ID: On 2015-09-17, Joseph L. Casale wrote: > I need to write a module to abstract the RabbitMQ HTTP REST api. > Before I do this, I would like to see how other projects have done > similar in the hopes I make something consistent and generic etc. > > Does anyone regularly work with a library that abstracts a REST API > and can recommend it for review? There is https://pypi.python.org/pypi/librabbitmq ? From korom at hotmail.co.uk Thu Sep 17 11:10:55 2015 From: korom at hotmail.co.uk (moon khondkar) Date: Thu, 17 Sep 2015 16:10:55 +0100 Subject: Hello Message-ID: Hello I have problem with python installation.I downloaded python 3.5 but I cannot use it on my computer.I can not open the idle. I get something like saying "users\local settings\Application data\programs\python\python35-32\pythonw.exe is not valid win32 application. Thanks that will be help if you can solve this. From jcasale at activenetwerx.com Thu Sep 17 11:19:15 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 17 Sep 2015 15:19:15 +0000 Subject: Writing a module to abstract a REST api In-Reply-To: References: , Message-ID: <1442503153420.66065@activenetwerx.com> > There is https://pypi.python.org/pypi/librabbitmq ? Hi Jon, That is the AMQP client that utilizes the c extensions, I am writing a module to interact with a plugin that exposes a REST API. So I am not really after anything AMQP specific, just a pointer to a project that abstracts anything with a REST API so I can see how they work with requests in an async nature. Thanks, jlc From jon+usenet at unequivocal.co.uk Thu Sep 17 11:26:23 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Thu, 17 Sep 2015 15:26:23 +0000 (UTC) Subject: Writing a module to abstract a REST api References: Message-ID: On 2015-09-17, Joseph L. Casale wrote: >> There is https://pypi.python.org/pypi/librabbitmq ? > > Hi Jon, > That is the AMQP client that utilizes the c extensions, I am writing a > module to interact with a plugin that exposes a REST API. > > So I am not really after anything AMQP specific, just a pointer to > a project that abstracts anything with a REST API so I can see how > they work with requests in an async nature. There's a bunch of Python Twitter libraries listed at the link below, they're all using a REST API? https://dev.twitter.com/overview/api/twitter-libraries From lac at openend.se Thu Sep 17 12:41:35 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 17 Sep 2015 18:41:35 +0200 Subject: Writing a module to abstract a REST api In-Reply-To: <1b35c9c9b6864d7bb9bf11e0e3cb98ca@exch.activenetwerx.com> References: <1b35c9c9b6864d7bb9bf11e0e3cb98ca@exch.activenetwerx.com> Message-ID: <201509171641.t8HGfZjb008471@fido.openend.se> In a message of Thu, 17 Sep 2015 14:44:00 -0000, "Joseph L. Casale" writes: >I need to write a module to abstract the RabbitMQ HTTP REST api. >Before I do this, I would like to see how other projects have done >similar in the hopes I make something consistent and generic etc. > >Does anyone regularly work with a library that abstracts a REST API >and can recommend it for review? > >Thanks, >jlc If I understand you: http://www.python-requests.org/en/latest/ is an example of what you are looking for? It's great. Also check out http://cramer.io/2014/05/20/mocking-requests-with-responses/ if you need to mock requests. Laura From jcasale at activenetwerx.com Thu Sep 17 14:04:39 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 17 Sep 2015 18:04:39 +0000 Subject: Writing a module to abstract a REST api In-Reply-To: <201509171641.t8HGfZjb008471@fido.openend.se> References: <1b35c9c9b6864d7bb9bf11e0e3cb98ca@exch.activenetwerx.com>, <201509171641.t8HGfZjb008471@fido.openend.se> Message-ID: <1442513079044.82368@activenetwerx.com> > If I understand you: > http://www.python-requests.org/en/latest/ > > is an example of what you are looking for? > > It's great. > > Also check out > http://cramer.io/2014/05/20/mocking-requests-with-responses/ > > if you need to mock requests. Hi Laura, The twitter samples Jon sent were good. What I am after is examples of modules that are written to interact with REST services. Its just not something I have written a module for and I am keen to see how well written modules have been implemented. Thanks, jlc From ian.g.kelly at gmail.com Thu Sep 17 14:44:05 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 17 Sep 2015 12:44:05 -0600 Subject: Einstein's Riddle In-Reply-To: <1cef1669-1a62-4fe8-ac31-6fff385e77ed@googlegroups.com> References: <1cef1669-1a62-4fe8-ac31-6fff385e77ed@googlegroups.com> Message-ID: On Thu, Sep 17, 2015 at 3:19 AM, wrote: > This is not true that only two percent of this world can solve this puzzle. May be the 2% will solve it by a quick look on the statements. Are you replying to this thread? https://mail.python.org/pipermail/python-list/2001-March/063293.html I had to google to find it, because if you'll take a look at the date you'll notice that it's over fourteen years old. From ian.g.kelly at gmail.com Thu Sep 17 14:49:06 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 17 Sep 2015 12:49:06 -0600 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: On Thu, Sep 17, 2015 at 1:06 AM, Jussi Piitulainen wrote: > Ordinary binary operators not only combine things of the same type, they > also produce a thing of that same type. So 'in' does not fit among them > either. > > I feel it's _more_ at home among comparison operators. (Hm. That's > 'operator' in a different sense.) Comparison operators *are* binary operators. All that "binary" means is that it takes two arguments. From rosuav at gmail.com Thu Sep 17 14:57:42 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Sep 2015 04:57:42 +1000 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: On Fri, Sep 18, 2015 at 4:49 AM, Ian Kelly wrote: > On Thu, Sep 17, 2015 at 1:06 AM, Jussi Piitulainen > wrote: >> Ordinary binary operators not only combine things of the same type, they >> also produce a thing of that same type. So 'in' does not fit among them >> either. >> >> I feel it's _more_ at home among comparison operators. (Hm. That's >> 'operator' in a different sense.) > > Comparison operators *are* binary operators. All that "binary" means > is that it takes two arguments. I think what Jussi is saying is that int+int yields int, and float*float yields float, and so on - but even that is true only of the arithmetic operators, and not all of them (int/int -> float in Py3). But generalizing from "arithmetic operators" to "ordinary operators" is a little unfair, unless you assume that the sole purpose of programming is to represent algebra. ChrisA From harvesting at makes.email.invalid Thu Sep 17 16:24:06 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Thu, 17 Sep 2015 23:24:06 +0300 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: Ian Kelly writes: > On Thu, Sep 17, 2015 at 1:06 AM, Jussi Piitulainen wrote: >> Ordinary binary operators not only combine things of the same type, >> they also produce a thing of that same type. So 'in' does not fit >> among them either. >> >> I feel it's _more_ at home among comparison operators. (Hm. That's >> 'operator' in a different sense.) > > Comparison operators *are* binary operators. All that "binary" means > is that it takes two arguments. I confused two words. It's operation I meant, not operator. A binary _operation_ is defined as any map X * X -> X (by Lawvere and Schanuel, Lawvere and Rosebrugh, at least; let's allow division as close enough). (The asterisk stands for the Cartesian product. I'm too lazy to look up the proper Unicode character for it and not willing to see a non-ASCII symbol come back to me in a mangled form again anyway. Not today.) Then comparisons are not binary _operations_ except in a very restricted case. Their types are of the form X * X -> W, where W stands for a set of truth values, {True, False}. A comparison of truth-values could be taken as a binary operation, W * W -> W; other comparisons, under this definition, not. And I'm saying 'in', being truth-valued, is more like a comparison than a proper binary operation that has its value in the same set as its two arguments. Proper binary operations produce results that can be fed back to them, as in either ((x - y) - z) or (x - (y -z)). ((x < y) < z) or (x < (y < z)) does not usually make sense. ((x in y) in z) more or less fails. (x in (y in z)) fails. Just trying to explain what I had in mind when I said that I feel that 'in' is more at home with comparisons (where it is now) than with, hm, arithmetic operations. From harvesting at makes.email.invalid Thu Sep 17 16:44:06 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Thu, 17 Sep 2015 23:44:06 +0300 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: Chris Angelico writes: > On Fri, Sep 18, 2015 at 4:49 AM, Ian Kelly wrote: >> On Thu, Sep 17, 2015 at 1:06 AM, Jussi Piitulainen >> wrote: >>> Ordinary binary operators not only combine things of the same type, they >>> also produce a thing of that same type. So 'in' does not fit among them >>> either. >>> >>> I feel it's _more_ at home among comparison operators. (Hm. That's >>> 'operator' in a different sense.) >> >> Comparison operators *are* binary operators. All that "binary" means >> is that it takes two arguments. > > I think what Jussi is saying is that int+int yields int, and > float*float yields float, and so on - but even that is true only of > the arithmetic operators, and not all of them (int/int -> float in > Py3). But generalizing from "arithmetic operators" to "ordinary > operators" is a little unfair, unless you assume that the sole purpose > of programming is to represent algebra. Yes, that's what I was trying to say, though I should have used the word "operation" not "operator". The operators that denote something like operations are routinely used to feed their values back to the same or related operations; doing that with truth-valued operators does not often make sense; their results are combined with and, or, and not instead. I can easily make up special cases myself, but now I'm trying to think of typical uses and say that Python got this quite right. From srkunze at mail.de Thu Sep 17 16:46:38 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 17 Sep 2015 22:46:38 +0200 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55FB26AE.1090900@mail.de> On 17.09.2015 08:39, Gregory Ewing wrote: > Sven R. Kunze wrote: > >> Btw. ASCII art is also art. So, why does Python not have ASCII art to >> define graphs and diagrams? > > Nowadays it would have to support Unicode art. Mustn't > leave out all the world's non-English-speaking artists! > How do I debug and more importantly fix graphs and diagrams made of non-English Unicode art? o.O From srkunze at mail.de Thu Sep 17 17:03:11 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 17 Sep 2015 23:03:11 +0200 Subject: Writing a module to abstract a REST api In-Reply-To: <1b35c9c9b6864d7bb9bf11e0e3cb98ca@exch.activenetwerx.com> References: <1b35c9c9b6864d7bb9bf11e0e3cb98ca@exch.activenetwerx.com> Message-ID: <55FB2A8F.9050501@mail.de> Well, I would be interested in seeing such a module as well. Most modules and frameworks, I know, providing REST and interacting with REST are more like traditional SOAP-like web services. You got your functions which have a 1-to-1 correspondence with some resource URLs and that's it. Actually REST is far more flexible than that, thus I still would love to see an authentic REST module. Best, Sven On 17.09.2015 16:44, Joseph L. Casale wrote: > I need to write a module to abstract the RabbitMQ HTTP REST api. > Before I do this, I would like to see how other projects have done > similar in the hopes I make something consistent and generic etc. > > Does anyone regularly work with a library that abstracts a REST API > and can recommend it for review? > > Thanks, > jlc From python.list at tim.thechases.com Thu Sep 17 17:26:39 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 17 Sep 2015 16:26:39 -0500 Subject: True == 1 weirdness In-Reply-To: <55FB26AE.1090900@mail.de> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55FB26AE.1090900@mail.de> Message-ID: <20150917162639.2aa445bc@bigbox.christie.dr> On 2015-09-17 22:46, Sven R. Kunze wrote: > >> Btw. ASCII art is also art. So, why does Python not have ASCII > >> art to define graphs and diagrams? > > > > Nowadays it would have to support Unicode art. Mustn't > > leave out all the world's non-English-speaking artists! > > How do I debug and more importantly fix graphs and diagrams made of > non-English Unicode art? o.O Um, use a decent editor? I mean, even GNU ed(1) handles UTF-8 just fine, as do Vim & Emacs. -tkc From random832 at fastmail.com Thu Sep 17 17:26:54 2015 From: random832 at fastmail.com (Random832) Date: Thu, 17 Sep 2015 17:26:54 -0400 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: <1442525214.2202731.386705153.5B3636BD@webmail.messagingengine.com> On Thu, Sep 17, 2015, at 16:24, Jussi Piitulainen wrote: > And I'm saying 'in', being truth-valued, is more like a comparison than > a proper binary operation that has its value in the same set as its two > arguments. The problem is that except for very specialized cases (strings), the two arguments are not (semantically, at least) in the same set as each other, either. It may be "more" like a comparison, but it's not *really* like either one. > Just trying to explain what I had in mind when I said that I feel that > 'in' is more at home with comparisons (where it is now) than with, hm, > arithmetic operations. Why does it have to be either one? I don't even think chaining should work for all *actual* comparison operations. Say you have this statement: (1) a < b = c <= d While it may *actually* mean this: (2) a < b and b = c and c <= d It *semantically* means this: (3) a < b and a < c and a < d and b = c and b <= d and c <= d The ones that are included logically imply the ones that are not, for any sane definition of these operators. And if your operators *aren't* sane, it's better to be explicit about what you are doing. It should not be applied to any combination of operations that cannot meaningfully be read as such a statement (e.g. mixing directions of less/greater comparisons, or including in, is not, or != at all), or to any values expected to have (2) not imply (3). It being *easier to implement* to have comparison operators be a single class and have chaining apply equally to all of them may be an excuse for the language to allow it, but it's certainly not an excuse for *actually* using it from a standpoint of good style and readability. From marko at pacujo.net Thu Sep 17 17:38:34 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 18 Sep 2015 00:38:34 +0300 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: <87vbb8hgkl.fsf@elektro.pacujo.net> Random832 : > It being *easier to implement* to have comparison operators be a > single class and have chaining apply equally to all of them may be an > excuse for the language to allow it, but it's certainly not an excuse > for *actually* using it from a standpoint of good style and > readability. In general, I don't like such caveats. Either something is in the language or it is not. You don't have to use all language features (I certainly don't), but if somebody takes advantage of them, you shouldn't consider it bad style. So if you don't like if prev_node is not node in excluded: ... take your complaints to whoever accepted the syntax in the language. Marko From srkunze at mail.de Thu Sep 17 17:49:30 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 17 Sep 2015 23:49:30 +0200 Subject: True == 1 weirdness In-Reply-To: <87vbb8hgkl.fsf@elektro.pacujo.net> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87vbb8hgkl.fsf@elektro.pacujo.net> Message-ID: <55FB356A.5060609@mail.de> On 17.09.2015 23:38, Marko Rauhamaa wrote: > Random832 : > >> It being *easier to implement* to have comparison operators be a >> single class and have chaining apply equally to all of them may be an >> excuse for the language to allow it, but it's certainly not an excuse >> for *actually* using it from a standpoint of good style and >> readability. > In general, I don't like such caveats. Either something is in the > language or it is not. > > You don't have to use all language features (I certainly don't), but if > somebody takes advantage of them, you shouldn't consider it bad style. > So if you don't like > > if prev_node is not node in excluded: > ... > > take your complaints to whoever accepted the syntax in the language. One cannot blame it all to the languages designers. They try hard to optimize the programming workflows. The responsibility is evenly split between the users and the designers to use and to design reasonable, maintainable and robust language features. Best, Sven From srkunze at mail.de Thu Sep 17 17:52:51 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Thu, 17 Sep 2015 23:52:51 +0200 Subject: True == 1 weirdness In-Reply-To: <20150917162639.2aa445bc@bigbox.christie.dr> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87oah2jq4y.fsf@elektro.pacujo.net> <55F99ADB.5020405@mail.de> <55f9a94d$0$1641$c3e8da3$5496439d@news.astraweb.com> <55FB26AE.1090900@mail.de> <20150917162639.2aa445bc@bigbox.christie.dr> Message-ID: <55FB3633.2030206@mail.de> On 17.09.2015 23:26, Tim Chase wrote: > On 2015-09-17 22:46, Sven R. Kunze wrote: >>>> Btw. ASCII art is also art. So, why does Python not have ASCII >>>> art to define graphs and diagrams? >>> Nowadays it would have to support Unicode art. Mustn't >>> leave out all the world's non-English-speaking artists! >> How do I debug and more importantly fix graphs and diagrams made of >> non-English Unicode art? o.O > Um, use a decent editor? I mean, even GNU ed(1) handles UTF-8 just > fine, as do Vim & Emacs. Since when has debugging and fixing something to do with the encoding? I somehow would need to actually understand and type those characters. Btw. PyCharm handles utf-8 as well. ;) Best, Sven From ben+python at benfinney.id.au Thu Sep 17 19:37:21 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 18 Sep 2015 09:37:21 +1000 Subject: Automating build from source (was: Automating Sphinx generated documentation) References: <41302A7145AC054FA7A96CFD03835A0A0B9D749B@EX10MBX02.EU.NEC.COM> Message-ID: <85vbb84nym.fsf@benfinney.id.au> David Aldrich writes: > I have setup Sphinx for my Python project. We keep all our code and > documentation in Subversion. It's a good idea to keep *source* files in VCS. It's a bad idea to keep automatically-generated files in VCS; it's especially bad to do so if they need to be generated again after changing the source files. > So, following changes to the Python code, I need to regenerate and > commit the Sphinx generated documentation. Instead, the build products ? anything generated automatically by the computer, such as the compiled code, compiled documentation ? should be flagged for ?ignore? by the VCS, and never committed. The VCS should track only those files that humans edit directly. > I just wondered how people manage this. I'm thinking of using Jenkins > (a continuous integration tool) to check for changes, regenerate the > docs and check them in. Deploying the code base, whether for testing or to staging or production or wherever, should entail a build step. That build step is responsible for going from source-files-only, checked out from the VCS, to a complete ready-to-deploy tree of files. That build step should always start from a clean source tree, so that you always know the end result reflects what was committed to VCS. Build tools include old-school Makefile, or newer tools like Meson. Note that this is automated build. This is a different question from automated deployment (you might like Fabric for that), and is a different question from automated integration (you might like Jenkins for that). First, though, you need an automated build, so you can separate ?what's tracked in VCS? versus ?what's generated automatically?. -- \ ?If we listen only to those who are like us, we will squander | `\ the great opportunity before us: To live together peacefully in | _o__) a world of unresolved differences.? ?David Weinberger | Ben Finney From shanvalleru at gmail.com Thu Sep 17 19:51:48 2015 From: shanvalleru at gmail.com (svalleru) Date: Thu, 17 Sep 2015 16:51:48 -0700 (PDT) Subject: Determining version of OpenSSL linked against python? In-Reply-To: References: Message-ID: <1442533908333-5171962.post@n6.nabble.com> AFAIK, there is no version variable for python2.6 ssl module but here a tip: Look for libeat32.dll (usually under Python2.6.1/Lib/site-packages), grep for 'OpenSSL' and you will see something like the following which will have the version string: ----- : SSLv3 part of OpenSSL 0.9.8d 28 Sep 2006 : cheers -- View this message in context: http://python.6.x6.nabble.com/Determining-version-of-OpenSSL-linked-against-python-tp4333385p5171962.html Sent from the Python - python-list mailing list archive at Nabble.com. From heidimtaylor at gmail.com Thu Sep 17 20:16:15 2015 From: heidimtaylor at gmail.com (heidimtaylor at gmail.com) Date: Thu, 17 Sep 2015 20:16:15 -0400 Subject: windows 10 Message-ID: <55fb57cb.8677810a.86f0c.ffffe39d@mx.google.com> I am using Windows 10. I cannot find the Python (command line). Do you know where I would find it? Thank you, Heidi Sent from Mail for Windows 10 -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Thu Sep 17 21:54:45 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 18 Sep 2015 01:54:45 +0000 (UTC) Subject: Automating build from source (was: Automating Sphinx generated documentation) References: <41302A7145AC054FA7A96CFD03835A0A0B9D749B@EX10MBX02.EU.NEC.COM> Message-ID: On 2015-09-17, Ben Finney wrote: > The VCS should track only those files that humans edit directly. While I agree that files automatically generated shouldn't be checked in to a VCS, I'm in favor of putting key binary files under VCS if they are required to do the build. We often check deveopment toolchains into Subversion. Subversion handles it just fine, and it saves having to come up with an entirely different scheme for archiving toolchain binaries. [If we build the toolchains ourselves, we will archive those sources as well.] -- Grant From jondy.zhao at gmail.com Thu Sep 17 21:58:53 2015 From: jondy.zhao at gmail.com (Jondy Zhao) Date: Thu, 17 Sep 2015 18:58:53 -0700 (PDT) Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: On Tuesday, September 15, 2015 at 5:36:52 PM UTC+8, Ben Finney wrote: > Jondy Zhao writes: > > > Pyarmor is a simple to use tool which is capable of importing or > > running encrypted Python script files. Moreover, it can apply encoding > > algorithms to your Python scripts, in order to help you protect them > > before you can distribute them. You may also generate license files > > with custom validity conditions. > > Protect them from whom? What is the threat model against which Pyarmor > is claimed to protect? Who is the attacker, who is being protected? > > > The program allows you to encrypt files, but to also open and run them > > as if no protection was applied. Moreover, it can run or import > > encrypted Python scripts in any target machine, only in specified > > machines or before a specified date. This aspect can be controlled by > > the creation of the license files: bound to a hard disk serial number > > or by an expiration date. > > So a Python file encrypted this way will be arbitrarily restricted in > how it can be inspected for debugging, performance monitoring, and > testing? > > This seems to explicitly treat the user of the Python software as a > hostile attacker. That is not a friendly or respectful position, and I > hope I misunderstand Pyarmor's operation. > > -- > \ "Any fool can write code that a computer can understand. Good | > `\ programmers write code that humans can understand." --Martin | > _o__) Fowler, _Refactoring_, 2000 | > Ben Finney Think that python developer is manufacturer, and he want to sell his product to the customers who don't know anything about programming. He don't hope his customers redistribute his product, that's protected by Pyarmor. From rosuav at gmail.com Thu Sep 17 22:03:26 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Sep 2015 12:03:26 +1000 Subject: True == 1 weirdness In-Reply-To: <87vbb8hgkl.fsf@elektro.pacujo.net> References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> <87vbb8hgkl.fsf@elektro.pacujo.net> Message-ID: On Fri, Sep 18, 2015 at 7:38 AM, Marko Rauhamaa wrote: > Random832 : > >> It being *easier to implement* to have comparison operators be a >> single class and have chaining apply equally to all of them may be an >> excuse for the language to allow it, but it's certainly not an excuse >> for *actually* using it from a standpoint of good style and >> readability. > > In general, I don't like such caveats. Either something is in the > language or it is not. > > You don't have to use all language features (I certainly don't), but if > somebody takes advantage of them, you shouldn't consider it bad style. > So if you don't like > > if prev_node is not node in excluded: > ... > > take your complaints to whoever accepted the syntax in the language. Strongly disagree. We have style guides because the language allows many things which are not good code. Given that Python programmers can't decide on whether the line limit should be 79, 80, 100, 120, or "79 but you can stretch to 100 if you have to", what should the syntax be coded to? It's just as bad style to produce a 500-character line as it is to abuse operator chaining, so should we take our complaints about over-long lines to "whoever didn't put a length limit into language syntax"? What about indenting with 5 spaces - should that have been disallowed at the language level? And what about misspelled comments - obviously they're bad style, so clearly Python should raise SyntaxError any time it comes across one, right? No. The language should be kept simple, and on matters of style, it should have MORE flexibility than we use - otherwise it's a straitjacket. ChrisA From rosuav at gmail.com Thu Sep 17 22:05:24 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Sep 2015 12:05:24 +1000 Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: On Fri, Sep 18, 2015 at 11:58 AM, Jondy Zhao wrote: > Think that python developer is manufacturer, and he want to sell his product to the customers who don't know anything about programming. He don't hope his customers redistribute his product, that's protected by Pyarmor. > The trouble with that thinking is that they _can_ redistribute his product. In fact, PyArmor isn't going to do anything about that. It might make it harder for them to reverse engineer that product, but it does nothing whatsoever for redistribution. ChrisA From ben+python at benfinney.id.au Thu Sep 17 22:27:12 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 18 Sep 2015 12:27:12 +1000 Subject: Pyarmor, guard your python scripts References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: <85r3lw4g3j.fsf@benfinney.id.au> Jondy Zhao writes: > Think that python developer is manufacturer, and he want to sell his > product to the customers who don't know anything about programming. Are you also assuming those customers have no-one they can talk with who knows programming? > He don't hope his customers redistribute his product, that's protected > by Pyarmor. Pyarmor is not going to stop them redistributing anything. If they're motivated to redistribute the code, this won't stop them. If they're motivated to examine what the code does, this will increase the effort but not stop them. At best, it will annoy customers who want to get someone's help in debugging the product. That sounds like an anti-feature. -- \ ?This world in arms is not spending money alone. It is spending | `\ the sweat of its laborers, the genius of its scientists, the | _o__) hopes of its children.? ?Dwight Eisenhower, 1953-04-16 | Ben Finney From jondy.zhao at gmail.com Thu Sep 17 22:40:56 2015 From: jondy.zhao at gmail.com (Jondy Zhao) Date: Thu, 17 Sep 2015 19:40:56 -0700 (PDT) Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: <22dc806f-f3f4-4e5d-a939-5ecc5e4bf946@googlegroups.com> On Tuesday, September 15, 2015 at 5:49:15 PM UTC+8, Chris Angelico wrote: > On Tue, Sep 15, 2015 at 7:21 PM, Jondy Zhao wrote: > > Pyarmor is dedicated to users who create their applications, components, scripts or any file with the help of the Python programming language. You may use this application to encrypt the files, in order to protect their content and your intellectual property, by encoding the scripts. > > > > > > The program allows you to encrypt files, but to also open and run them as if no protection was applied. > > If they can be run as if no protection had been applied, that > presumably means the loader is capable of decrypting them, right? So > what's to stop anyone from reading the loader, using it to decrypt the > actual code, and running it? > > ChrisA The loader only can see the compiled scripts as ast nodes, even if the load some tools could dump the separated ast node to bytecode and de-compile it, think of one script is divided into thousands of pieces, it's not easy to assemble them again. The final solution is to distribute the loader with encrypted scripts, only my own loader can run the encrypted scripts. Besides, From alexander.belopolsky at gmail.com Thu Sep 17 22:47:44 2015 From: alexander.belopolsky at gmail.com (Alexander Belopolsky) Date: Thu, 17 Sep 2015 22:47:44 -0400 Subject: Adding PEP 495 support to dateutil In-Reply-To: References: Message-ID: [Tim Peters] > > I think acceptance of 495 should be contingent upon > someone first completing a fully functional (if not releasable) > fold-aware zoneinfo wrapping. [Alexander Belopolsky] > > I am making all development public early on and hope to see code reviews and pull requests from interested parties. Pull requests with additional test cases are most welcome. I've made some additional progress in my dateutil fork [1]. The tzfile class is now fold-aware. The tzfile implementation of tzinfo takes the history of local time type changes from a binary zoneinfo file. These files are installed on the majority of UNIX platforms. More testing is needed, but I think my fork is now close to meeting Tim's challenge. Please note that you need to run the modified dateutil fork [1] code under PEP 495 fork of CPython. [2] [1]: https://github.com/abalkin/dateutil/tree/pep-0495 [2]: https://github.com/abalkin/cpython -------------- next part -------------- An HTML attachment was scrubbed... URL: From jondy.zhao at gmail.com Thu Sep 17 22:51:36 2015 From: jondy.zhao at gmail.com (Jondy Zhao) Date: Thu, 17 Sep 2015 19:51:36 -0700 (PDT) Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: On Friday, September 18, 2015 at 10:06:30 AM UTC+8, Chris Angelico wrote: > On Fri, Sep 18, 2015 at 11:58 AM, Jondy Zhao wrote: > > Think that python developer is manufacturer, and he want to sell his product to the customers who don't know anything about programming. He don't hope his customers redistribute his product, that's protected by Pyarmor. > > > > The trouble with that thinking is that they _can_ redistribute his > product. In fact, PyArmor isn't going to do anything about that. It > might make it harder for them to reverse engineer that product, but it > does nothing whatsoever for redistribution. > > ChrisA The encrypted scripts could be distributed to bind to hard disk of computer, so the customers could not simplely copy them to somewhere else. Except they could reverse all the bytecodes, and pyarmor does make it harder to reverse bytecode to source. From jondy.zhao at gmail.com Thu Sep 17 22:59:45 2015 From: jondy.zhao at gmail.com (Jondy Zhao) Date: Thu, 17 Sep 2015 19:59:45 -0700 (PDT) Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> Message-ID: <6978ab18-6154-4f62-9e97-0cd5c921015e@googlegroups.com> On Friday, September 18, 2015 at 10:27:35 AM UTC+8, Ben Finney wrote: > Jondy Zhao writes: > > > Think that python developer is manufacturer, and he want to sell his > > product to the customers who don't know anything about programming. > > Are you also assuming those customers have no-one they can talk with who > knows programming? > > > He don't hope his customers redistribute his product, that's protected > > by Pyarmor. > > Pyarmor is not going to stop them redistributing anything. If they're > motivated to redistribute the code, this won't stop them. If they're > motivated to examine what the code does, this will increase the effort > but not stop them. > > At best, it will annoy customers who want to get someone's help in > debugging the product. That sounds like an anti-feature. > > -- > \ "This world in arms is not spending money alone. It is spending | > `\ the sweat of its laborers, the genius of its scientists, the | > _o__) hopes of its children." --Dwight Eisenhower, 1953-04-16 | > Ben Finney For example, I develop a game by python. What I want to do is that the player or the agent could not simply copy the game to others. For the player or the agent, they needn't research the game. That's cases concerned by PyArmor. From ben+python at benfinney.id.au Thu Sep 17 23:06:03 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 18 Sep 2015 13:06:03 +1000 Subject: Pyarmor, guard your python scripts References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <6978ab18-6154-4f62-9e97-0cd5c921015e@googlegroups.com> Message-ID: <85mvwk4eas.fsf@benfinney.id.au> Jondy Zhao writes: > For example, I develop a game by python. What I want to do is that the > player or the agent could not simply copy the game to others. For the > player or the agent, they needn't research the game. Deciding for the customer what they may not do, on their own computer, is quite hostile. Please don't enable such restrictions. -- \ ?We must find our way to a time when faith, without evidence, | `\ disgraces anyone who would claim it.? ?Sam Harris, _The End of | _o__) Faith_, 2004 | Ben Finney From rosuav at gmail.com Fri Sep 18 01:01:50 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Sep 2015 15:01:50 +1000 Subject: Pyarmor, guard your python scripts In-Reply-To: <22dc806f-f3f4-4e5d-a939-5ecc5e4bf946@googlegroups.com> References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <22dc806f-f3f4-4e5d-a939-5ecc5e4bf946@googlegroups.com> Message-ID: On Fri, Sep 18, 2015 at 12:40 PM, Jondy Zhao wrote: > The loader only can see the compiled scripts as ast nodes, even if the load some tools could dump the separated ast node to bytecode and de-compile it, think of one script is divided into thousands of pieces, it's not easy to assemble them again. > > The final solution is to distribute the loader with encrypted scripts, only my own loader can run the encrypted scripts. So anyone who's going to run your program needs your loader. If someone wants to redistribute your code, s/he can simply distribute the loader as well - and you're right back where you started. You have still achieved nothing in terms of preventing redistribution. Please do not do this. Not only are you not achieving the goal you think you are, you're making a mess for people to have to deal with. ChrisA From jondy.zhao at gmail.com Fri Sep 18 01:38:32 2015 From: jondy.zhao at gmail.com (Jondy Zhao) Date: Thu, 17 Sep 2015 22:38:32 -0700 (PDT) Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <22dc806f-f3f4-4e5d-a939-5ecc5e4bf946@googlegroups.com> Message-ID: <74f43ca8-fc25-4622-8f18-784b71f781af@googlegroups.com> On Friday, September 18, 2015 at 1:02:09 PM UTC+8, Chris Angelico wrote: > On Fri, Sep 18, 2015 at 12:40 PM, Jondy Zhao wrote: > > The loader only can see the compiled scripts as ast nodes, even if the load some tools could dump the separated ast node to bytecode and de-compile it, think of one script is divided into thousands of pieces, it's not easy to assemble them again. > > > > The final solution is to distribute the loader with encrypted scripts, only my own loader can run the encrypted scripts. > > So anyone who's going to run your program needs your loader. If > someone wants to redistribute your code, s/he can simply distribute > the loader as well - and you're right back where you started. You have > still achieved nothing in terms of preventing redistribution. > > Please do not do this. Not only are you not achieving the goal you > think you are, you're making a mess for people to have to deal with. > > ChrisA But the loader and the encrypted scripts could be bind to one fixed computer when I distribute them to end users, so the end users can't redistribute them to any other machines. Actually this is what some commercial software does. From stane.niaina at hotmail.com Fri Sep 18 01:54:45 2015 From: stane.niaina at hotmail.com (Stephan) Date: Fri, 18 Sep 2015 07:54:45 +0200 Subject: Problem installing pip Message-ID: Good Morning, I've tried ten times to install pip with no success in windows 10 using python 64bit version. Is there a solution available? I'm looking forward hearing you soon. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jondy.zhao at gmail.com Fri Sep 18 01:55:05 2015 From: jondy.zhao at gmail.com (Jondy Zhao) Date: Thu, 17 Sep 2015 22:55:05 -0700 (PDT) Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <6978ab18-6154-4f62-9e97-0cd5c921015e@googlegroups.com> Message-ID: <6f60b49d-4621-4ea7-a50a-a07fe1b1dc58@googlegroups.com> On Friday, September 18, 2015 at 11:06:25 AM UTC+8, Ben Finney wrote: > Jondy Zhao writes: > > > For example, I develop a game by python. What I want to do is that the > > player or the agent could not simply copy the game to others. For the > > player or the agent, they needn't research the game. > > Deciding for the customer what they may not do, on their own computer, > is quite hostile. Please don't enable such restrictions. > This is only one possible way to distribute encrypted scripts. As I thought the user of Pyarmor would be the producer of commercial software, so they could bind their license file to netcard, harddisk, cpu, etc. > -- > \ "We must find our way to a time when faith, without evidence, | > `\ disgraces anyone who would claim it." --Sam Harris, _The End of | > _o__) Faith_, 2004 | > Ben Finney From rosuav at gmail.com Fri Sep 18 02:38:32 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Sep 2015 16:38:32 +1000 Subject: Automating build from source (was: Automating Sphinx generated documentation) In-Reply-To: <85vbb84nym.fsf@benfinney.id.au> References: <41302A7145AC054FA7A96CFD03835A0A0B9D749B@EX10MBX02.EU.NEC.COM> <85vbb84nym.fsf@benfinney.id.au> Message-ID: On Fri, Sep 18, 2015 at 9:37 AM, Ben Finney wrote: > David Aldrich writes: > >> I have setup Sphinx for my Python project. We keep all our code and >> documentation in Subversion. > > It's a good idea to keep *source* files in VCS. > > It's a bad idea to keep automatically-generated files in VCS; it's > especially bad to do so if they need to be generated again after > changing the source files. While I broadly agree, I would say this is a case of code smell rather than something outright verboten. There are a few situations where it's easier to commit the generated files as well; for instance, it can help you get around a bootstrapping problem - you use a previous build of Python to generate the frozen importlib, I think, and use that to build the next Python. (If that's not how CPython is built, my apologies; there are other projects that _do_ use this method, so it's just a flawed example.) If you don't commit the generated files, someone who wants to build from source has to first pick up a precompiled binary or somesuch. (Or, looking the other way: Disallowing generated files in source control restricts the generator to something that's already available on every build system.) But yes, as a general rule, I prefer to list all generated files in .gitignore or equivalent. ChrisA From __peter__ at web.de Fri Sep 18 02:50:43 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 18 Sep 2015 08:50:43 +0200 Subject: Automating build from source (was: Automating Sphinx generated documentation) References: <41302A7145AC054FA7A96CFD03835A0A0B9D749B@EX10MBX02.EU.NEC.COM> <85vbb84nym.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > David Aldrich writes: > >> I have setup Sphinx for my Python project. We keep all our code and >> documentation in Subversion. > > It's a good idea to keep *source* files in VCS. > > It's a bad idea to keep automatically-generated files in VCS; it's > especially bad to do so if they need to be generated again after > changing the source files. > >> So, following changes to the Python code, I need to regenerate and >> commit the Sphinx generated documentation. > > Instead, the build products ? anything generated automatically by the > computer, such as the compiled code, compiled documentation ? should be > flagged for ?ignore? by the VCS, and never committed. > > The VCS should track only those files that humans edit directly. Isn't this a case of purity versus practicality? I imagine it might be nice to get fairly up-to-date documentation along with your source code checkout "for free". From __peter__ at web.de Fri Sep 18 02:56:40 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 18 Sep 2015 08:56:40 +0200 Subject: Automating Sphinx generated documentation References: <41302A7145AC054FA7A96CFD03835A0A0B9D749B@EX10MBX02.EU.NEC.COM> Message-ID: David Aldrich wrote: > I have setup Sphinx for my Python project. We keep all our code and > documentation in Subversion. So, following changes to the Python code, I > need to regenerate and commit the Sphinx generated documentation. > > I just wondered how people manage this. I'm thinking of using Jenkins (a > continuous integration tool) to check for changes, regenerate the docs and > check them in. > > Any suggestions please? VCS typically have a few hooks to trigger scripts. I found "Making the Most of Commit Hooks with Subversion" http://www.linux-mag.com/id/7151/ Maybe you can use one of these to trigger a rebuilt of the docs. From harvesting at makes.email.invalid Fri Sep 18 03:10:29 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Fri, 18 Sep 2015 10:10:29 +0300 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: Random832 writes: > On Thu, Sep 17, 2015, at 16:24, Jussi Piitulainen wrote: >> And I'm saying 'in', being truth-valued, is more like a comparison >> than a proper binary operation that has its value in the same set as >> its two arguments. > > The problem is that except for very specialized cases (strings), the > two arguments are not (semantically, at least) in the same set as each > other, either. It may be "more" like a comparison, but it's not > *really* like either one. Agreed. (In hierarchical set theories like ZFC, the membership predicate is between things of the same type, too: sets, the only things there are. That's hardly relevant in a typed setting.) >> Just trying to explain what I had in mind when I said that I feel >> that 'in' is more at home with comparisons (where it is now) than >> with, hm, arithmetic operations. > > Why does it have to be either one? I don't even think chaining should > work for all *actual* comparison operations. To keep the rules simple. To keep the language comprehensible, and then I can take the responsibility to keep my code comprehensible. > Say you have this statement: > (1) a < b = c <= d > While it may *actually* mean this: > (2) a < b and b = c and c <= d > It *semantically* means this: > (3) a < b and a < c and a < d and b = c and b <= d and c <= d I prefer (1) with no hesitation. I start to worry about typos and thinkos when the expression gets longer, and transitivity is such a fundamental notion that I'd rather blame myself for not understanding transitivity than the code for being too concise. (Also, == :) Would really hate to be forced to spell it all out if there were more complicated expressions in the chain. > The ones that are included logically imply the ones that are not, for > any sane definition of these operators. And if your operators *aren't* > sane, it's better to be explicit about what you are doing. Yes. Those, in (1), are sane. > It should not be applied to any combination of operations that cannot > meaningfully be read as such a statement (e.g. mixing directions of > less/greater comparisons, or including in, is not, or != at all), or > to any values expected to have (2) not imply (3). I think (x != w != y) is ok to check that neither of x and y equals w. Even (x < w > y) seems surprisingly clear to me: it's comparing the extreme values to the middle value but not to each other. When in doubt, I might add a comment next to the expression. So in principle I agree. I just seem to tolerate more uses of chained comparisons than you. But longer chains are even rarer than 2-chains, and even 2-chains do not happen so often, and when they do happen, they tend to be (j < k < n). Shrug. > It being *easier to implement* to have comparison operators be a single > class and have chaining apply equally to all of them may be an excuse > for the language to allow it, but it's certainly not an excuse for > *actually* using it from a standpoint of good style and readability. It's also easier to document and comprehend, and on the whole they are a natural class. If something does go wrong, it's nice to find out that the explanation is simple, and not yet another special case that I was supposed to keep in mind. From rosuav at gmail.com Fri Sep 18 03:27:09 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Sep 2015 17:27:09 +1000 Subject: Pyarmor, guard your python scripts In-Reply-To: <6f60b49d-4621-4ea7-a50a-a07fe1b1dc58@googlegroups.com> References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <6978ab18-6154-4f62-9e97-0cd5c921015e@googlegroups.com> <6f60b49d-4621-4ea7-a50a-a07fe1b1dc58@googlegroups.com> Message-ID: On Fri, Sep 18, 2015 at 3:55 PM, Jondy Zhao wrote: > On Friday, September 18, 2015 at 11:06:25 AM UTC+8, Ben Finney wrote: >> Jondy Zhao writes: >> >> > For example, I develop a game by python. What I want to do is that the >> > player or the agent could not simply copy the game to others. For the >> > player or the agent, they needn't research the game. >> >> Deciding for the customer what they may not do, on their own computer, >> is quite hostile. Please don't enable such restrictions. >> > > This is only one possible way to distribute encrypted scripts. As I thought the user of Pyarmor would be the producer of commercial software, so they could bind their license file to netcard, harddisk, cpu, etc. > Great. Please put a big warning notice on your application: ATTENTION ALL USERS The author of this program believes that he controls your usage of it, to the extent that a legitimately-purchased copy will refuse to run if you upgrade your computer's hardware. It is therefore recommended that you pirate this program as per XKCD 488. If you don't like this, don't use the program. At least then you'll be being honest. ChrisA From jondy.zhao at gmail.com Fri Sep 18 04:05:17 2015 From: jondy.zhao at gmail.com (Jondy Zhao) Date: Fri, 18 Sep 2015 01:05:17 -0700 (PDT) Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <6978ab18-6154-4f62-9e97-0cd5c921015e@googlegroups.com> <6f60b49d-4621-4ea7-a50a-a07fe1b1dc58@googlegroups.com> Message-ID: <380f3e08-e518-4556-8d48-12fd4f3b798e@googlegroups.com> On Friday, September 18, 2015 at 3:27:28 PM UTC+8, Chris Angelico wrote: > On Fri, Sep 18, 2015 at 3:55 PM, Jondy Zhao wrote: > > On Friday, September 18, 2015 at 11:06:25 AM UTC+8, Ben Finney wrote: > >> Jondy Zhao writes: > >> > >> > For example, I develop a game by python. What I want to do is that the > >> > player or the agent could not simply copy the game to others. For the > >> > player or the agent, they needn't research the game. > >> > >> Deciding for the customer what they may not do, on their own computer, > >> is quite hostile. Please don't enable such restrictions. > >> > > > > This is only one possible way to distribute encrypted scripts. As I thought the user of Pyarmor would be the producer of commercial software, so they could bind their license file to netcard, harddisk, cpu, etc. > > > > Great. Please put a big warning notice on your application: > > ATTENTION ALL USERS > The author of this program believes that he controls your usage of it, > to the extent that a legitimately-purchased copy will refuse to run if > you upgrade your computer's hardware. > It is therefore recommended that you pirate this program as per XKCD 488. > If you don't like this, don't use the program. > > > At least then you'll be being honest. > I know you hate it. But I have purchased some commercial software in this way before, a tool named ERWIN used to create relation database. The license I got from software provider is bind to the network card of my PC. I can't use this tool in any other machine. This is true case. The world is wide, maybe it's better to be tolerant of all things. > ChrisA From alister.nospam.ware at ntlworld.com Fri Sep 18 04:08:41 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 18 Sep 2015 08:08:41 +0000 (UTC) Subject: Pyarmor, guard your python scripts References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <22dc806f-f3f4-4e5d-a939-5ecc5e4bf946@googlegroups.com> <74f43ca8-fc25-4622-8f18-784b71f781af@googlegroups.com> Message-ID: On Thu, 17 Sep 2015 22:38:32 -0700, Jondy Zhao wrote: > On Friday, September 18, 2015 at 1:02:09 PM UTC+8, Chris Angelico wrote: >> On Fri, Sep 18, 2015 at 12:40 PM, Jondy Zhao >> wrote: >> > The loader only can see the compiled scripts as ast nodes, even if >> > the load some tools could dump the separated ast node to bytecode and >> > de-compile it, think of one script is divided into thousands of >> > pieces, it's not easy to assemble them again. >> > >> > The final solution is to distribute the loader with encrypted >> > scripts, only my own loader can run the encrypted scripts. >> >> So anyone who's going to run your program needs your loader. If someone >> wants to redistribute your code, s/he can simply distribute the loader >> as well - and you're right back where you started. You have still >> achieved nothing in terms of preventing redistribution. >> >> Please do not do this. Not only are you not achieving the goal you >> think you are, you're making a mess for people to have to deal with. >> >> ChrisA > > But the loader and the encrypted scripts could be bind to one fixed > computer when I distribute them to end users, so the end users can't > redistribute them to any other machines. Actually this is what some > commercial software does. Making life difficult for legitimate users whilst causing Pirates minor difficulties at best (crack once distribute many).. Copyright legislation is what provides you with protection if you need it Commercial users do not risk running unlicensed software because of the damage a piracy case against them would cause to their business, not because they cant get it! From rosuav at gmail.com Fri Sep 18 04:16:04 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Sep 2015 18:16:04 +1000 Subject: Pyarmor, guard your python scripts In-Reply-To: <380f3e08-e518-4556-8d48-12fd4f3b798e@googlegroups.com> References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <6978ab18-6154-4f62-9e97-0cd5c921015e@googlegroups.com> <6f60b49d-4621-4ea7-a50a-a07fe1b1dc58@googlegroups.com> <380f3e08-e518-4556-8d48-12fd4f3b798e@googlegroups.com> Message-ID: On Fri, Sep 18, 2015 at 6:05 PM, Jondy Zhao wrote: > I know you hate it. But I have purchased some commercial software in this way before, a tool named ERWIN used to create relation database. The license I got from software provider is bind to the network card of my PC. I can't use this tool in any other machine. This is true case. > > The world is wide, maybe it's better to be tolerant of all things. Tolerant, perhaps - but that doesn't mean we encourage it. So, first and foremost, I *will not* code anything that encourages people to do this. And secondly, I generally will not buy anything that uses any form of DRM. (There are a *very* few exceptions.) Frankly, I'd prefer to pirate something and then make a donation to the author than buy it with DRM. So. no. No matter how wide the world is, I *WILL NOT* encourage the use of this software. ChrisA From jondy.zhao at gmail.com Fri Sep 18 04:31:50 2015 From: jondy.zhao at gmail.com (Jondy Zhao) Date: Fri, 18 Sep 2015 01:31:50 -0700 (PDT) Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <22dc806f-f3f4-4e5d-a939-5ecc5e4bf946@googlegroups.com> <74f43ca8-fc25-4622-8f18-784b71f781af@googlegroups.com> Message-ID: <63bd6da4-50ad-4b0c-bff7-5b5d26d161b3@googlegroups.com> On Friday, September 18, 2015 at 4:08:57 PM UTC+8, alister wrote: > On Thu, 17 Sep 2015 22:38:32 -0700, Jondy Zhao wrote: > > > On Friday, September 18, 2015 at 1:02:09 PM UTC+8, Chris Angelico wrote: > >> On Fri, Sep 18, 2015 at 12:40 PM, Jondy Zhao > >> wrote: > >> > The loader only can see the compiled scripts as ast nodes, even if > >> > the load some tools could dump the separated ast node to bytecode and > >> > de-compile it, think of one script is divided into thousands of > >> > pieces, it's not easy to assemble them again. > >> > > >> > The final solution is to distribute the loader with encrypted > >> > scripts, only my own loader can run the encrypted scripts. > >> > >> So anyone who's going to run your program needs your loader. If someone > >> wants to redistribute your code, s/he can simply distribute the loader > >> as well - and you're right back where you started. You have still > >> achieved nothing in terms of preventing redistribution. > >> > >> Please do not do this. Not only are you not achieving the goal you > >> think you are, you're making a mess for people to have to deal with. > >> > >> ChrisA > > > > But the loader and the encrypted scripts could be bind to one fixed > > computer when I distribute them to end users, so the end users can't > > redistribute them to any other machines. Actually this is what some > > commercial software does. > > Making life difficult for legitimate users whilst causing Pirates minor > difficulties at best (crack once distribute many).. > > Copyright legislation is what provides you with protection if you need it > > Commercial users do not risk running unlicensed software because of the > damage a piracy case against them would cause to their business, not > because they cant get it! I agree with you absolutely. Maybe I can show you the purpose of Pyarmor by the following case: When we express a box, we can close this box with a lock, this equals encrypted scripts, or we just close the box without a lock. Pyarmor is just as this lock, it make the box more security, but it can not protect the box completely. From bobertini at googlemail.com Fri Sep 18 05:06:05 2015 From: bobertini at googlemail.com (bobertini at googlemail.com) Date: Fri, 18 Sep 2015 02:06:05 -0700 (PDT) Subject: .bat file trouble. Message-ID: Hi, I have two files called module_scripts.py and build_q_scripts.bat. The problem being that when I go to run the bat file it produces a few errors which neither myself or the original owner of the files could understand. Errors: https://gyazo.com/c680f0d70cefe855c21ab0882d7c17b7 We originally thought that it was because it was missing the files: process_init.py and process_global_variables.py however they are right there in the same directory. File contents for the bat file: @echo off python process_init.py python process_global_variables.py python process_scripts.py @del *.pyc echo. echo ______________________________ echo. echo Script processing has ended. echo Press any key to exit. . . pause>nul If there is anyone with any idea how to fix it I'd love you forever :) From steve at pearwood.info Fri Sep 18 05:32:38 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 18 Sep 2015 19:32:38 +1000 Subject: .bat file trouble. References: Message-ID: <55fbda36$0$1646$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Sep 2015 07:06 pm, bobertini at googlemail.com wrote: > Hi, > > I have two files called module_scripts.py and build_q_scripts.bat. > > The problem being that when I go to run the bat file it produces a few > errors which neither myself or the original owner of the files could > understand. Can you copy and paste the errors? I presume that they are words rather than pictures. That way, people who use a screen reader can hear them, and so can people who aren't able or willing to click on random URLs to strange websites that will do who knows what. > Errors: > > https://gyazo.com/c680f0d70cefe855c21ab0882d7c17b7 I get: SSL error:host(gyazo.com)!=cert(*.gyazo.com) and when I continue, I get: Your browser is not supported in Gyazo. so I'm afraid I cannot help you further unless I guess: > We originally thought that it was because it was missing the files: > process_init.py and process_global_variables.py however they are right > there in the same directory. I'm going to look into my crystal ball and see what the spirits say... They say... - is it a permissions problem? - is it a path problem? - what happens if you run this batch file instead? @echo off python -c "import sys; print(sys.version)" echo Press any key to exit. . . pause>nul Is the printed version the version you expect? -- Steven From steve at pearwood.info Fri Sep 18 05:33:48 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 18 Sep 2015 19:33:48 +1000 Subject: Einstein's Riddle References: <1cef1669-1a62-4fe8-ac31-6fff385e77ed@googlegroups.com> Message-ID: <55fbda7c$0$1646$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Sep 2015 04:44 am, Ian Kelly wrote: > On Thu, Sep 17, 2015 at 3:19 AM, wrote: >> This is not true that only two percent of this world can solve this >> puzzle. May be the 2% will solve it by a quick look on the statements. > > Are you replying to this thread? > > https://mail.python.org/pipermail/python-list/2001-March/063293.html > > I had to google to find it, because if you'll take a look at the date > you'll notice that it's over fourteen years old. Time is relative. Perhaps the poster has been travelling at close to the speed of light, and for him it is only a few minutes after the original post was sent. -- Steven From nick.a.sarbicki at gmail.com Fri Sep 18 05:51:35 2015 From: nick.a.sarbicki at gmail.com (Nick Sarbicki) Date: Fri, 18 Sep 2015 10:51:35 +0100 Subject: Einstein's Riddle In-Reply-To: <55fbda7c$0$1646$c3e8da3$5496439d@news.astraweb.com> References: <1cef1669-1a62-4fe8-ac31-6fff385e77ed@googlegroups.com> <55fbda7c$0$1646$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 18, 2015 at 10:33 AM, Steven D'Aprano wrote: > On Fri, 18 Sep 2015 04:44 am, Ian Kelly wrote: > > > On Thu, Sep 17, 2015 at 3:19 AM, wrote: > >> This is not true that only two percent of this world can solve this > >> puzzle. May be the 2% will solve it by a quick look on the statements. > > > > Are you replying to this thread? > > > > https://mail.python.org/pipermail/python-list/2001-March/063293.html > > > > I had to google to find it, because if you'll take a look at the date > > you'll notice that it's over fourteen years old. > > Time is relative. Perhaps the poster has been travelling at close to the > speed of light, and for him it is only a few minutes after the original > post was sent. > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list > I prefer to think that it just took him this long to do it. - Nick -------------- next part -------------- An HTML attachment was scrubbed... URL: From alister.nospam.ware at ntlworld.com Fri Sep 18 06:06:37 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 18 Sep 2015 10:06:37 +0000 (UTC) Subject: Pyarmor, guard your python scripts References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <22dc806f-f3f4-4e5d-a939-5ecc5e4bf946@googlegroups.com> <74f43ca8-fc25-4622-8f18-784b71f781af@googlegroups.com> <63bd6da4-50ad-4b0c-bff7-5b5d26d161b3@googlegroups.com> Message-ID: On Fri, 18 Sep 2015 01:31:50 -0700, Jondy Zhao wrote: > On Friday, September 18, 2015 at 4:08:57 PM UTC+8, alister wrote: >> On Thu, 17 Sep 2015 22:38:32 -0700, Jondy Zhao wrote: >> >> > On Friday, September 18, 2015 at 1:02:09 PM UTC+8, Chris Angelico >> > wrote: >> >> On Fri, Sep 18, 2015 at 12:40 PM, Jondy Zhao >> >> wrote: >> >> > The loader only can see the compiled scripts as ast nodes, even if >> >> > the load some tools could dump the separated ast node to bytecode >> >> > and de-compile it, think of one script is divided into thousands >> >> > of pieces, it's not easy to assemble them again. >> >> > >> >> > The final solution is to distribute the loader with encrypted >> >> > scripts, only my own loader can run the encrypted scripts. >> >> >> >> So anyone who's going to run your program needs your loader. If >> >> someone wants to redistribute your code, s/he can simply distribute >> >> the loader as well - and you're right back where you started. You >> >> have still achieved nothing in terms of preventing redistribution. >> >> >> >> Please do not do this. Not only are you not achieving the goal you >> >> think you are, you're making a mess for people to have to deal with. >> >> >> >> ChrisA >> > >> > But the loader and the encrypted scripts could be bind to one fixed >> > computer when I distribute them to end users, so the end users can't >> > redistribute them to any other machines. Actually this is what some >> > commercial software does. >> >> Making life difficult for legitimate users whilst causing Pirates minor >> difficulties at best (crack once distribute many).. >> >> Copyright legislation is what provides you with protection if you need >> it >> >> Commercial users do not risk running unlicensed software because of the >> damage a piracy case against them would cause to their business, not >> because they cant get it! > > I agree with you absolutely. Maybe I can show you the purpose of Pyarmor > by the following case: > > When we express a box, we can close this box with a lock, this equals > encrypted scripts, or we just close the box without a lock. Pyarmor is > just as this lock, it make the box more security, but it can not protect > the box completely. And if the person at the other end looses the key it causes a great deal of trouble. Alternatively the highway man that holds up the delivery truck simply takes a pair of bolt cutters to the lock... yes it stops a casual snooper but that is all -- A statesman is a politician who's been dead 10 or 15 years. -- Harry S. Truman From jondy.zhao at gmail.com Fri Sep 18 07:41:08 2015 From: jondy.zhao at gmail.com (Jondy Zhao) Date: Fri, 18 Sep 2015 04:41:08 -0700 (PDT) Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <22dc806f-f3f4-4e5d-a939-5ecc5e4bf946@googlegroups.com> <74f43ca8-fc25-4622-8f18-784b71f781af@googlegroups.com> <63bd6da4-50ad-4b0c-bff7-5b5d26d161b3@googlegroups.com> Message-ID: On Friday, September 18, 2015 at 6:06:51 PM UTC+8, alister wrote: > On Fri, 18 Sep 2015 01:31:50 -0700, Jondy Zhao wrote: > > > On Friday, September 18, 2015 at 4:08:57 PM UTC+8, alister wrote: > >> On Thu, 17 Sep 2015 22:38:32 -0700, Jondy Zhao wrote: > >> > >> > On Friday, September 18, 2015 at 1:02:09 PM UTC+8, Chris Angelico > >> > wrote: > >> >> On Fri, Sep 18, 2015 at 12:40 PM, Jondy Zhao > >> >> wrote: > >> >> > The loader only can see the compiled scripts as ast nodes, even if > >> >> > the load some tools could dump the separated ast node to bytecode > >> >> > and de-compile it, think of one script is divided into thousands > >> >> > of pieces, it's not easy to assemble them again. > >> >> > > >> >> > The final solution is to distribute the loader with encrypted > >> >> > scripts, only my own loader can run the encrypted scripts. > >> >> > >> >> So anyone who's going to run your program needs your loader. If > >> >> someone wants to redistribute your code, s/he can simply distribute > >> >> the loader as well - and you're right back where you started. You > >> >> have still achieved nothing in terms of preventing redistribution. > >> >> > >> >> Please do not do this. Not only are you not achieving the goal you > >> >> think you are, you're making a mess for people to have to deal with. > >> >> > >> >> ChrisA > >> > > >> > But the loader and the encrypted scripts could be bind to one fixed > >> > computer when I distribute them to end users, so the end users can't > >> > redistribute them to any other machines. Actually this is what some > >> > commercial software does. > >> > >> Making life difficult for legitimate users whilst causing Pirates minor > >> difficulties at best (crack once distribute many).. > >> > >> Copyright legislation is what provides you with protection if you need > >> it > >> > >> Commercial users do not risk running unlicensed software because of the > >> damage a piracy case against them would cause to their business, not > >> because they cant get it! > > > > I agree with you absolutely. Maybe I can show you the purpose of Pyarmor > > by the following case: > > > > When we express a box, we can close this box with a lock, this equals > > encrypted scripts, or we just close the box without a lock. Pyarmor is > > just as this lock, it make the box more security, but it can not protect > > the box completely. > > And if the person at the other end looses the key it causes a great deal > of trouble. > > Alternatively the highway man that holds up the delivery truck simply > takes a pair of bolt cutters to the lock... > > yes it stops a casual snooper but that is all > > In reality, when we leave the house, we lock the door, even the lock could not make sure the safe of our property. It's just make it difficult. It's same in the software world. Someone need the lock in both of the world. And if the highway man need leave the trunk for many days, whether they lock the truck or ask someone to take care of it or not. > > > -- > A statesman is a politician who's been dead 10 or 15 years. > -- Harry S. Truman From ben+python at benfinney.id.au Fri Sep 18 07:52:04 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 18 Sep 2015 21:52:04 +1000 Subject: Pyarmor, guard your python scripts References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <22dc806f-f3f4-4e5d-a939-5ecc5e4bf946@googlegroups.com> <74f43ca8-fc25-4622-8f18-784b71f781af@googlegroups.com> <63bd6da4-50ad-4b0c-bff7-5b5d26d161b3@googlegroups.com> Message-ID: <85io783py3.fsf@benfinney.id.au> Jondy Zhao writes: > In reality, when we leave the house, we lock the door, even the lock > could not make sure the safe of our property. It's just make it > difficult. It's same in the software world. Someone need the lock in > both of the world. Yes, please don't encourage authors to put locks into people's computers that restrict those people's access to use them. And we won't come to install a lock that restricts your access to your house. In other words: Please don't arrogate to anyone the presumed right to restrict how people run programs on their own computers. -- \ ?It ain't so much the things we don't know that get us in | `\ trouble. It's the things we know that ain't so.? ?Artemus Ward | _o__) (1834?1867), U.S. journalist | Ben Finney From steve at pearwood.info Fri Sep 18 08:30:26 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 18 Sep 2015 22:30:26 +1000 Subject: True == 1 weirdness References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> <1442412230.1762717.385286049.20841F36@webmail.messagingengine.com> Message-ID: <55fc03e1$0$1664$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Sep 2015 07:26 am, Random832 wrote: > I don't even think chaining should > work for all *actual* comparison operations. I don't see why. Mathematicians chain comparisons all the time. If the language implements the same semantics as mathematicians already use, why do you dislike that? I don't see the benefit in restricting the language to something less expressive and more verbose than standard comparison chaining. > Say you have this statement: > (1) a < b = c <= d > While it may *actually* mean this: > (2) a < b and b = c and c <= d > > It *semantically* means this: > (3) a < b and a < c and a < d and b = c and b <= d and c <= d Only if the comparisons are transitive, which they may not be. If they are, then something like this: a < b < c implies a < c too. But not all comparisons are transitive. > The ones that are included logically imply the ones that are not, for > any sane definition of these operators. Transitivity is *not* required for sanity. Nontransitivity is a very useful property for games, e.g. Rock-Paper-Scissors. It would be a very boring game indeed if the relation Rock < Paper < Scissors (where < means "is beaten by") was transitive. https://en.wikipedia.org/wiki/Nontransitive_game Intransitivity is likewise very important in consumer preferences, psychology, and voting (voter preferences are often nontransitive, e.g. voters prefer the Flog-em-and-hang-em Party over the Treehugger Party, the Treehugger Party over the Raving Monster Loony Party, and the Raving Monster Loony Party over the Flog-em-and-hang-em Party. [Aside: some voting systems do guarantee transitivity, but only at the cost of some other desirable property, such as no negative votes or no dictator. Other voting systems make nontransitive elections unlikely.] Other real-world examples include status hierarchies and pecking orders, and nontransitive dice. (Google it, I'm too lazy to provide a link.) > And if your operators *aren't* > sane, it's better to be explicit about what you are doing. Why? The results are perfectly well-defined however you write them. Transitivity or not, "Rock beats Scissors beats Paper beats Rock" means the same thing as "Rock beats Scissors, and Scissors beats Paper, and Paper beats Rock" except it's much shorter. -- Steven From random832 at fastmail.com Fri Sep 18 08:47:59 2015 From: random832 at fastmail.com (Random832) Date: Fri, 18 Sep 2015 08:47:59 -0400 Subject: True == 1 weirdness Message-ID: <1442580479.2421580.387252273.049F0968@webmail.messagingengine.com> On Fri, Sep 18, 2015, at 08:30, Steven D'Aprano wrote: > On Fri, 18 Sep 2015 07:26 am, Random832 wrote: > > > I don't even think chaining should > > work for all *actual* comparison operations. > > I don't see why. Mathematicians chain comparisons all the time. If the > language implements the same semantics as mathematicians already use, why > do you dislike that? Please provide a citation for this claim. > Only if the comparisons are transitive, which they may not be. My *entire point* is that it *shouldn't be used* for non-transitive comparisons!!! From lorenzofsutton at gmail.com Fri Sep 18 09:07:31 2015 From: lorenzofsutton at gmail.com (Lorenzo Sutton) Date: Fri, 18 Sep 2015 15:07:31 +0200 Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <22dc806f-f3f4-4e5d-a939-5ecc5e4bf946@googlegroups.com> <74f43ca8-fc25-4622-8f18-784b71f781af@googlegroups.com> <63bd6da4-50ad-4b0c-bff7-5b5d26d161b3@googlegroups.com> Message-ID: <55FC0C93.2040605@gmail.com> On 18/09/2015 13:41, Jondy Zhao wrote: [...] > In reality, when we leave the house, we lock the door, even the lock could > not make sure the safe of our property. It's just make it difficult. > It's same in the software world. Someone need the lock in both of the world. I think you meant "in the *proprietary* software world". This discussion on the topic, and in particular this answer, on Stackoverflow are quite inspiring: http://stackoverflow.com/questions/261638/how-do-i-protect-python-code/261727#261727 Lorenzo. From steve at pearwood.info Fri Sep 18 09:14:52 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 18 Sep 2015 23:14:52 +1000 Subject: True == 1 weirdness References: Message-ID: <55fc0e4d$0$1645$c3e8da3$5496439d@news.astraweb.com> On Fri, 18 Sep 2015 10:47 pm, Random832 wrote: > On Fri, Sep 18, 2015, at 08:30, Steven D'Aprano wrote: >> On Fri, 18 Sep 2015 07:26 am, Random832 wrote: >> >> > I don't even think chaining should >> > work for all *actual* comparison operations. >> >> I don't see why. Mathematicians chain comparisons all the time. If the >> language implements the same semantics as mathematicians already use, why >> do you dislike that? > > Please provide a citation for this claim. Really? You're disputing that chained comparisons are a standard maths notation? https://en.wikipedia.org/wiki/Inequality_(mathematics)#Chained_notation Mathworld, for example, says: Solutions to the inequality |x-a|> Only if the comparisons are transitive, which they may not be. > > My *entire point* is that it *shouldn't be used* for non-transitive > comparisons!!! And my point is that there is no good reason for such a restriction, even if it were technically possible to enforce (which it is not). The mathematical chained notation doesn't rely on, or imply, transitivity. Given a < b < c, *if* the operator is transitive, then AND ONLY THEN can you conclude that a < c, but that's not implied by the chaining. It happens to be true for real numbers, but it isn't necessarily true. -- Steven From random832 at fastmail.com Fri Sep 18 09:40:52 2015 From: random832 at fastmail.com (Random832) Date: Fri, 18 Sep 2015 09:40:52 -0400 Subject: True == 1 weirdness In-Reply-To: <55fc0e4d$0$1645$c3e8da3$5496439d@news.astraweb.com> References: <55fc0e4d$0$1645$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1442583652.2433512.387297097.0C910B45@webmail.messagingengine.com> On Fri, Sep 18, 2015, at 09:14, Steven D'Aprano wrote: > On Fri, 18 Sep 2015 10:47 pm, Random832 wrote: > > > On Fri, Sep 18, 2015, at 08:30, Steven D'Aprano wrote: > >> On Fri, 18 Sep 2015 07:26 am, Random832 wrote: > >> > >> > I don't even think chaining should > >> > work for all *actual* comparison operations. > >> > >> I don't see why. Mathematicians chain comparisons all the time. If the > >> language implements the same semantics as mathematicians already use, why > >> do you dislike that? > > > > Please provide a citation for this claim. > > Really? You're disputing that chained comparisons are a standard maths > notation? I'm disputing that chained comparisons are used for the particular combinations that I am actually arguing should not be used in python. Such as a < b > c or a != b != c [whereas a may or may not be equal to c] or a in b in c. Your claim seemed to be that these combinations *are* used, since you claimed that python implements the *same* semantics. From auriocus at gmx.de Fri Sep 18 09:45:30 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 18 Sep 2015 15:45:30 +0200 Subject: .bat file trouble. In-Reply-To: References: Message-ID: Am 18.09.15 um 11:06 schrieb bobertini at googlemail.com: > Hi, > > I have two files called module_scripts.py and build_q_scripts.bat. > > The problem being that when I go to run the bat file it produces a > few errors which neither myself or the original owner of the files > could understand. > > Errors: > > https://gyazo.com/c680f0d70cefe855c21ab0882d7c17b7 The first error indicates, that you are running Python 3, and the script was made for Python 2. In Python 3, print is a function so you need parentheses around that print("Initializing...") - either fix that or install Python 2. The second error "TabError" also relates to it, it means that the file mixes tabs and spaces for indentation. Fix it by expanding all tabs to spaces in an editor. > We originally thought that it was because it was missing the files: > process_init.py and process_global_variables.py however they are > right there in the same directory. Concerning that, windows usually runs a .bat file in the directory where it is situated, so putting the python fies there /should/ work, but you can also set this using the right-click menu (execute in...), if you make a link to the desktop. Christian From jondy.zhao at gmail.com Fri Sep 18 09:57:05 2015 From: jondy.zhao at gmail.com (Jondy Zhao) Date: Fri, 18 Sep 2015 06:57:05 -0700 (PDT) Subject: Pyarmor, guard your python scripts In-Reply-To: References: <42f12eba-2504-4a97-a5bc-e7b9bfe2f1f9@googlegroups.com> <22dc806f-f3f4-4e5d-a939-5ecc5e4bf946@googlegroups.com> <74f43ca8-fc25-4622-8f18-784b71f781af@googlegroups.com> <63bd6da4-50ad-4b0c-bff7-5b5d26d161b3@googlegroups.com> Message-ID: On Friday, September 18, 2015 at 9:08:27 PM UTC+8, Lorenzo Sutton wrote: > On 18/09/2015 13:41, Jondy Zhao wrote: > [...] > > In reality, when we leave the house, we lock the door, even the lock could > > not make sure the safe of our property. It's just make it difficult. > > It's same in the software world. Someone need the lock in both of the world. > > I think you meant "in the *proprietary* software world". > Exactly. > This discussion on the topic, and in particular this answer, on > Stackoverflow are quite inspiring: > > http://stackoverflow.com/questions/261638/how-do-i-protect-python-code/261727#261727 > > Lorenzo. From gokoproject at gmail.com Fri Sep 18 10:42:40 2015 From: gokoproject at gmail.com (John Wong) Date: Fri, 18 Sep 2015 10:42:40 -0400 Subject: Automating build from source (was: Automating Sphinx generated documentation) In-Reply-To: References: <41302A7145AC054FA7A96CFD03835A0A0B9D749B@EX10MBX02.EU.NEC.COM> <85vbb84nym.fsf@benfinney.id.au> Message-ID: On Fri, Sep 18, 2015 at 2:50 AM, Peter Otten <__peter__ at web.de> wrote: > Ben Finney wrote: > > > David Aldrich writes: > > > >> I have setup Sphinx for my Python project. We keep all our code and > >> documentation in Subversion. > > > > It's a good idea to keep *source* files in VCS. > > > > The VCS should track only those files that humans edit directly. > > Isn't this a case of purity versus practicality? I imagine it might be nice > to get fairly up-to-date documentation along with your source code checkout > "for free". IMO, this is a decision an organization / individual has to make. But nothing stops anybody from using branch (and tags in hg) to differentiate pure source and pure build. On Thu, Sep 17, 2015 at 9:54 PM, Grant Edwards wrote: > On 2015-09-17, Ben Finney wrote: > > > The VCS should track only those files that humans edit directly. > > While I agree that files automatically generated shouldn't be checked > in to a VCS, I'm in favor of putting key binary files under VCS if > they are required to do the build. if you are okay with cloning a huge repository then I don't see a problem. You could have a separate repository for binary data, after VCS is just a software implements some smart versioning of an object in some format stored on somewhere. I know of no convenient mechanism to reduce size of my .git or my .hg once I committed my binary in my history. What I would do is provide the script a URL where you can get your files. Imagine infrastructure as code, I can't commit my oracle jdk/jre file all the time. I have a huge infrastructure to manage and it would be GBs to clone. It happened to me once and I regret it. Thanks. John -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Fri Sep 18 11:09:05 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 18 Sep 2015 15:09:05 +0000 (UTC) Subject: Automating build from source (was: Automating Sphinx generated documentation) References: <41302A7145AC054FA7A96CFD03835A0A0B9D749B@EX10MBX02.EU.NEC.COM> <85vbb84nym.fsf@benfinney.id.au> Message-ID: On 2015-09-18, John Wong wrote: > if you are okay with cloning a huge repository then I don't see a problem. Ah yes, if the repository got cloned a lot that would be a problem. The repository in question doesn't get cloned (it does get backed up). As I mentioned, it's subversion. Subversion isn't a distributed VCS like git. Subversion uses a single, central repository. -- Grant Edwards grant.b.edwards Yow! Are we laid back yet? at gmail.com From jcasale at activenetwerx.com Fri Sep 18 11:28:28 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Fri, 18 Sep 2015 15:28:28 +0000 Subject: Writing a module to abstract a REST api In-Reply-To: <55FB2A8F.9050501@mail.de> References: <1b35c9c9b6864d7bb9bf11e0e3cb98ca@exch.activenetwerx.com>, <55FB2A8F.9050501@mail.de> Message-ID: <1442590107897.9135@activenetwerx.com> > Well, I would be interested in seeing such a module as well. > > Most modules and frameworks, I know, providing REST and interacting with > REST are more like traditional SOAP-like web services. You got your > functions which have a 1-to-1 correspondence with some resource URLs and > that's it. > > Actually REST is far more flexible than that, thus I still would love to > see an authentic REST module. So a design pattern I use often is to create Python objects to represent objects returned from what ever api I am abstracting. For example I might create named tuples for static data I dont intend to change or for an object I can both query for and create, I might build a class to represent it. The problem now comes from the following: # foo now contains a handle to the remote api. foo = InstanceOfApiWrapper() # queues is a container of Queue classes. queues = foo.get_queues() queue = queues[0] queue.delete() In this case its possible for foo (InstanceOfApiWrapper) to inject a reference to itself so the delete() can actually make the call. # I want to create a queue from scratch... disparate_queue = Queue(x, y, z) # Now what happens? No handle to an api? disparate_queue.delete() An alternative is: foo.delete_queue(disparate_queue) That's not a pattern I prefer, what facilities in Python provide for a workaround here? One option is to put everything in one module and use globals. If the handle is initialized it'll just work. Problem with that is its not thread safe (without work) and I subscribe to one object per file (bloody hard with Python's import/load procedure. This is a design pattern I have struggled with in the past. jlc From usenet at markus-raab.org Fri Sep 18 11:47:06 2015 From: usenet at markus-raab.org (Markus Raab) Date: Fri, 18 Sep 2015 17:47:06 +0200 Subject: Elektra 0.8.13 with python plugins Message-ID: Hello everyone, ## Python Plugins A technical preview of [python3] (http://git.libelektra.org/blob/master/src/plugins/python) and [python2](http://git.libelektra.org/blob/master/src/plugins/python2) plugins has been added. With them its possible to write any plugin, not only applications, with the python language. Note, they are a technical preview. They might have severe bugs and the API might change in the future. Nevertheless, it is already possible to, e.g. develop storage plugins with it. They are not included in `ALL` plugins. To use it, you have to specify it: -PLUGINS="ALL;python;python2" Thanks to Manuel Mausz for to this work on the plugins and the patience in all the last minute fixes! Feedback and Contribution is welcome! Join us on [github](http://libelektra.org). # Rest of release notes for Elektra 0.8.13 follows: For a html site visit: http://doc.libelektra.org/news/3c00a5f1-c017-4555-92b5-a2cf6e0803e3.html For general information about Elektra, see [http://libelektra.org] (http://libelektra.org) ## Elektrify-getenv getenv(3) is one of the most popular ways to retrieve configuration, even though it has many known problems: - no standard way to modify it - relogin (or restart of shell) necessary - names are flat (no hierarchical structure) - cannot be set for individual applications - different in at, cron and similar scripts With elektrify-getenv we wrote a solution which solves most of the problems. We use the LD_PRELOAD technique to *additionally* retrieve values from Elektra, and not only the environment. You simply can do: ```bash kdb set user/env/override/HTTP_PROXY "http://my.proxy:8080" ``` This will set the `HTTP_PROXY` environment variable to `http://my.proxy:8080`. Configuration can be retrieved with `kdb get`: ```bash kdb get user/env/override/HTTP_PROXY lynx # or start another www-browser with the newly set HTTP_PROXY ``` Or using the man pages: kdb elektrify-getenv man man --elektra:MANWIDTH=40 Will use MANWIDTH 40 for this invocation of man man. This feature is handy, if an option is only available by environment, but not by command-line arguments, because sometimes environment variables are not trivial to set (e.g. in Makefiles). Some more examples: kdb set user/env/override/MANOPT -- "--regex -LC" kdb elektrify-getenv getenv MANOPT # to check if it is set as expected kdb getenv MANOPT # if /etc/ld.so.preload is active So is this the final solution for configuration and manual elektrification of applications is not needed anymore? The answer is: no and yes. It is quite satisfactory for configuration that is inherently sharable (not different from one application to another) *and* needs the environment semantics, i.e. some subprocesses should have different configuration than others, e.g. in a specific terminal. But it might not be a good solution for your own application, because libgetenv(3) implies many architectural decision, that other elektrified applications would decide differently, e.g.: - it uses global variables (getenv(3) has no handle) - it uses mutex for multi-threading safety - the API getenv(3) only returns `char*` and has no support for other data types For more information see [src/libgetenv/README.md] (http://git.libelektra.org/blob/master/src/libgetenv/README.md) ## Compatibility As always, the API and API is fully forward-compatible, i.e. programs compiled against an older 0.8 versions of Elektra will continue to work. Because `keyUnescapedName` and `keyGetUnescapedNameSize` is added in this release, it is not backward-compatible, i.e. programs compiled against 0.8.13, might *not* work with older 0.8 libraries. The function `keyUnescapedName` provides access to an unescaped name, i.e. one where `/` and `\\` are literal symbols and do not have any special meaning. `NULL` characters are used as path separators. This function makes it trivial and efficient to iterate over all path names, as already exploited in all bindings: - [jna (java)] (http://git.libelektra.org/blob/master/src/bindings/jna/HelloElektra.java) - [lua] (http://git.libelektra.org/blob/master/src/bindings/swig/lua/tests/test_key.lua) - [python2] (http://git.libelektra.org/blob/master/src/bindings/swig/python2/tests/testpy2_key.py) - [python3] (http://git.libelektra.org/blob/master/src/bindings/swig/python3/tests/test_key.py) Other small changes/additions in bindings: - fix key constructor, thanks to Manuel Mausz - add copy and deepcopy in python (+examples,+testcases), thanks to Manuel Mausz - dup() in python3 returned wrong type (SWIG wrapper), thanks to Toscano Pino for reporting, thanks to Manuel Mausz for fixing it Doxygen 1.8.8 is preferred and the configfile was updated to this version. The symbols of nickel (for the ni plugin) do not longer leak from the Elektra library. As such, old versions of testmod_ni won't work with Elektra 0.8.13. A version-script is now in use to only export following symbols: - kdb* - key* - ks* - libelektra* for module loading system - elektra* for proposed and other functions (no ABI/API compatibility here!) In this release, ENABLE_CXX11 was changed to `ON` by default. Note that in the next release 0.8.14 there will be two changes: - According to [issue #262](http://git.libelektra.org/issues/262), we plan to remove the option ENABLE_CXX11 and require the compiler to be C++11 compatible. If you have any system you are not able to build Elektra with - DENABLE_CXX11=ON (which is the default for 0.8.13) please report that immediately. - the python3 bindings will be renamed to python By not having to care for pre-C++11 compilers, we hope to attract more developers. The core part is still in C99 so that Elektra can be used on systems where libc++ is not available. Many new plugins are still written in C99, also with the purpose of not depending on C++. ## Qt-gui 0.0.8 The GUI was improved and the most annoying bugs are fixed: - only reload and write config files if something has changed - use merging in a way that only a conflict free merge will be written, thanks to Felix Berlakovich - made sure keys can only be renamed if the new name/value/metadata is different from the existing ones - fixed 1) and 2) of #233 - fixed #235 - fixed qml warning when deleting key - fixed qml typerror when accepting an edit A big thanks to Raffael Pancheri! ## KDB Tool The commandline tool `kdb` also got some improvements. Most noteworthy is that `kdb get -v` now gives a complete trace for every key that was tried. This is very handy if you have a complex specification with many fallback and override links. It also shows default values and warnings in the case of context-oriented features. Furthermore: - Add `-v` for setmeta - Copy will warn when it won't overwrite another key (behaviour did not change) - improve help text, thanks to Ian Donnelly ## Documentation Initiative As Michael Haberler from [machinekit](http://www.machinekit.io/) pointed out it was certainly not easy for someone to get started with Elektra. With the documentation initiative we are going to change that. - The discussion in [github issues](http://git.libelektra.org/issues) should clarify many things - We start writing man pages in ronn-format(7), thanks to Ian Donnelly for current work - Kurt Micheli is woring on improved doxygen docu + pdf generation - Daniel Bugl already restructed the main page - Daniel Bugl also improved formatting - doc: use @retval more, thanks to Pino Toscano - doxygen: fix template to use `@` and not `\\`. - SVG logo is preferred, thanks to Daniel Bugl - doc: use @retval more, thanks to Pino Toscano - many typo fixes, thanks to Pino Toscano - fix broken links, thanks to Manuel Mausz, Daniel Bugl and Michael Haberler Any further help is very welcome! This call is especially addressed to beginners in Elektra because they obviously know best which documentation is lacking and what they would need. ## Portability `kdb-full` and `kdb-static` work fine now for Windows 64bit, thanks to Manuel Mausz. The wresolver is now more relaxed with unset environment. All issues for Mac OS X were resolved. With the exception of elektrify- getenv everything should work now, thanks to Mihael Pranjic: - fix mktemp - testscripts - recursive mutex simplification - clearenv ifdef and thanks to Daniel Bugl: - RPATH fixed, so that `kdb` works furthermore: - fix `__FUNCTION__` to `__func__` (C99), thanks to Pino Toscano - avoid compilation error when JNI_VERSION_1_8 is missing - fix (twice, because of an accidental revert) the TARGET_CMAKE_FOLDER, thanks to Pino Toscano Thanks to Manuel Mausz for to testing and improving portability! ## Packaging Packages are available for most Linux distributions. Recent changes: - 0.8.12 packaged+migrated to testing (https://packages.qa.debian.org/e/elektra/news/20150726T155000Z.html), thanks to Pino Toscano ## Build System - fix build with external gtest, thanks to Pino Toscano - switch from FindElektra.cmake to ElektraConfig.cmake, thanks to Pino Toscano - use `cmake_parse_arguments` instead of `parse_arguments`, thanks to Manuel Mausz ## Further Fixes - Key::release() will also work when Key holds a null-pointer - Key::getName() avoids std::string exception - support for copy module was introduced, thanks to Manuel Mausz - be more POSIX compatible in shell scripts (`type` to `command -v` and avoid `echo -e`) thanks to Pino Toscano - fix vararg type for KEY_FLAGS, thanks to Pino Toscano - fix crash of example, thanks to Pino Toscano - add proper licence file for Modules (COPYING-CMAKE-SCRIPTS), thanks to Pino Toscano - fix XDG resolver issue when no given path in XDG_CONFIG_DIRS is valid - make dbus example work again - fix compiler warnings for gcc and clang - fix valgrind suppressions - Installation of GI binding is fixed, thanks to D?vis - make uninstall is fixed and docu improved ## Notes There are some misconceptions about Elektra and semi structured data (like XML, JSON). Elektra is a key/value storage, that internally represents everything with key and values. Even though, Elektra can use XML and JSON files elegantly, there are limitations whatXML and JSON can represent. XML, e.g., cannot have holes within its structure, while this is obviously easily possible with key/value. And JSON, e.g., cannot have non-array entries within an array. This is a more general issue of that configuration files in general are constrained in what they are able to express. The solution to this problem is validation, i.e. keys that does not fit in the underlying format are rejected. Note there is no issue the other way round: special characteristics of configuration files can always be captured in Elektra's metadata. ## Get It! You can download the release from [here](http://www.libelektra.org/ftp/elektra/releases/elektra-0.8.13.tar.gz) and now also [here on github] (https://github.com/ElektraInitiative/ftp/tree/master/releases/elektra-0.8.13.tar.gz) - name: elektra-0.8.13.tar.gz - size: 2141758 - md5sum: 6e7640338f440e67aba91bd64b64f613 - sha1: ca58524d78e5d39a540a4db83ad527354524db5e - sha256: f5c672ef9f7826023a577ca8643d0dcf20c3ad85720f36e39f98fe61ffe74637 This release tarball now is also available [signed by me using gpg] (http://www.libelektra.org/ftp/elektra/releases/elektra-0.8.13.tar.gz.gpg) already built API-Docu can be found [here] (http://doc.libelektra.org/api/0.8.13/html/) ## Stay tuned! ## Subscribe to the [RSS feed](http://doc.libelektra.org/news/feed.rss) to always get the release notifications. For any questions and comments, please contact the [Mailing List](https://lists.sourceforge.net/lists/listinfo/registry-list) the issue tracker [on github](http://git.libelektra.org/issues) or by mail elektra at markus-raab.org. [Permalink to this NEWS entry](http://doc.libelektra.org/news/3c00a5f1-c017-4555-92b5-a2cf6e0803e3.html) For more information, see [http://libelektra.org](http://libelektra.org) Best regards, Markus From james.harris.1 at gmail.com Fri Sep 18 13:17:27 2015 From: james.harris.1 at gmail.com (James Harris) Date: Fri, 18 Sep 2015 18:17:27 +0100 Subject: Shutting down a cross-platform multithreaded app Message-ID: Well, this is fun ... for some definition of the word. ;-( I have a multithreaded app that I want to be able to shut down easily such as by hitting control-c or sending it a signal. What follows is the way I have come up with given the common elements of different environments. Suggestions for improvement would be welcome or you may just find the convolutions and machinations interesting. The first issue is that only the main thread can receive signals, according to https://docs.python.org/2/library/signal.html It says: "the main thread will be the only one to receive signals (this is enforced by the Python signal module, even if the underlying thread implementation supports sending signals to individual threads)". That's OK. I can get the main thread to accept suitable signals but then I need some way for it to tell the other threads to shut themselves down too. In most (probably all) cases they will be sitting waiting for network IO. I could have the main thread set a value in a global variable and then have the sub-threads check the global in between accesses of the network in a polling loop (using select() with a timeout). But as has already been pointed out to me in the thread "Signal SIGINT ignored during socket.accept" such polling does not sit well with hosted OSes and it can keep the CPU from remaining at rest in a low-power mode. I can, however, use select() to monitor two file descriptors. One would be the socket the thread is using to communicate with the client. The other would be a control connection from the master thread. Now to make this cross platform.... According to the opening paragraph in the following link Windows select() won't work on arbitrary file descriptors but only works for sockets. https://docs.python.org/2/library/select.html Well, that can be dealt with. I thought of using AF_UNIX or something else but it seems there is nothing else which could be considered universal and, according to the next link, if socket.AF_UNIX is not defined then even the Unix protocol is not supported. https://docs.python.org/2/library/socket.html Needless to say, on a test Windows machine AF_UNIX is not present. The only cross-platform option, therefore, seems to be to use each subthread's select()s to monitor two AF_INET sockets: the one to the client and a control one from the master thread. I would seem to need IP socket pairs between the master thread and the subthreads. If the master thead receives a shutdown signal it will send a shutdown command to each subthread. The above seems logical but would use quite a few IP sockets. I cannot think of a better way, though. Any comments on the ideas above? James From srkunze at mail.de Fri Sep 18 13:51:48 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Fri, 18 Sep 2015 19:51:48 +0200 Subject: Writing a module to abstract a REST api In-Reply-To: <1442590107897.9135@activenetwerx.com> References: <1b35c9c9b6864d7bb9bf11e0e3cb98ca@exch.activenetwerx.com>, <55FB2A8F.9050501@mail.de> <1442590107897.9135@activenetwerx.com> Message-ID: <55FC4F34.2030800@mail.de> On 18.09.2015 17:28, Joseph L. Casale wrote: > So a design pattern I use often is to create Python objects to represent > objects returned from what ever api I am abstracting. For example I > might create named tuples for static data I dont intend to change or > for an object I can both query for and create, I might build a class to > represent it. > > The problem now comes from the following: > > # foo now contains a handle to the remote api. > foo = InstanceOfApiWrapper() Is it necessary to have an instance of that API? Just curiosity here. > # queues is a container of Queue classes. > queues = foo.get_queues() > > queue = queues[0] > queue.delete() Alright. I see you want to have concrete classes, so you work with HTTP like you would do with SOAP-bases web services. I actually was referring to the self-expanding capability of REST (please note, REST is not HTTP, HTTP is one protocol that can be use to build an REST-ful API). It's basically like: you query a resource which holds an link to another resource which you then you query by following that link and so on and so forth. So, all what you need for REST is one starting point to explore the resource graph. > In this case its possible for foo (InstanceOfApiWrapper) to inject a reference > to itself so the delete() can actually make the call. > > # I want to create a queue from scratch... > disparate_queue = Queue(x, y, z) > # Now what happens? No handle to an api? > disparate_queue.delete() I don't see an issue here. Looks quite readable. > An alternative is: > foo.delete_queue(disparate_queue) > > That's not a pattern I prefer, what facilities in Python provide for a workaround > here? You always can add attributes to objects. So, add something like an __api__ attribute (which nobody would ever use except you when creating these queue objects in "get_queues"). > One option is to put everything in one module and use globals. If the handle is > initialized it'll just work. > > Problem with that is its not thread safe (without work) and I subscribe to > one object per file (bloody hard with Python's import/load procedure. It's perfectly fine to add a "secret" API instance to the object. It's called aspect-oriented programming. You remove the aspect of how to correctly manage an API instance and put that knowledge into a separate piece of code. *thumbs up* Best, Sven From no.email at nospam.invalid Fri Sep 18 14:23:13 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 18 Sep 2015 11:23:13 -0700 Subject: Shutting down a cross-platform multithreaded app References: Message-ID: <87zj0jd1ta.fsf@jester.gateway.sonic.net> "James Harris" writes: > I have a multithreaded app that I want to be able to shut down easily > such as by hitting control-c or sending it a signal. Set the daemon flag on the worker threads, so when the main thread exits, the workers also exit. From tjreedy at udel.edu Fri Sep 18 14:24:14 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 18 Sep 2015 14:24:14 -0400 Subject: True == 1 weirdness In-Reply-To: <1442583652.2433512.387297097.0C910B45@webmail.messagingengine.com> References: <55fc0e4d$0$1645$c3e8da3$5496439d@news.astraweb.com> <1442583652.2433512.387297097.0C910B45@webmail.messagingengine.com> Message-ID: On 9/18/2015 9:40 AM, Random832 wrote: > I'm disputing that chained comparisons are used for the particular > combinations that I am actually arguing should not be used in python. You are free to dislike certain combinations, not use them yourself, and even request others not to use them (all in Python code). But claiming that they have never been used in math is quite different. > Such asa < b > c If a, b, c are members of a totally ordered set, so that < is transitive, this is equivalent to max(a,c) < b. But the latter makes an irrelevant comparison between a and c. If they are only partially ordered, so that a and c are not necessarily comparable, then the above is the most concise way to way what it says. I believe I have seen such. > or a != b != c [whereas a may or may not be equal to c] a != b != c != a says that all three are unequal to any of the other two. I believe I have seen such, with '!=' replaced with the single 'not equal' character. or a in b in c. If b and c are collections, such as sets, this is perfectly sensible. With 'in' replaced with the epsilon 'set membership' character, I may have seen such. If 'a in b in c', then 'a in Union(c)', where Union is the union of all collections in c. One might call this quasi-transitive. In reverse, 'a in Union(c)' implies 'exists b, a in b in c'. Similarly, if 'a in b for all b in c' is equivalent to 'a in Intersection(c)'. > Your claim seemed to be that these combinations *are* > used, since you claimed that python implements the *same* semantics. The semantics Python copies from math is "a op b op c == a op b and b op c", where 'op' is a binary predicate or comparison operator. I also happen to believe you are wrong in the specific examples. But the semantic copying would apply even if a particular combination had not yet ever been used. -- Terry Jan Reedy From james.harris.1 at gmail.com Fri Sep 18 15:09:19 2015 From: james.harris.1 at gmail.com (James Harris) Date: Fri, 18 Sep 2015 20:09:19 +0100 Subject: Shutting down a cross-platform multithreaded app References: <87zj0jd1ta.fsf@jester.gateway.sonic.net> Message-ID: "Paul Rubin" wrote in message news:87zj0jd1ta.fsf at jester.gateway.sonic.net... > "James Harris" writes: >> I have a multithreaded app that I want to be able to shut down easily >> such as by hitting control-c or sending it a signal. > > Set the daemon flag on the worker threads, so when the main thread > exits, the workers also exit. Interesting idea, and I did not know that a *thread* could be a daemon. Unfortunately, I think what you suggest would kill the threads stone dead and not allow them to close connections. That's a particular problem with TCP connections and would require the OS to keep TCP state around for a while. I would rather close the TCP connections or, rather, encourage the other end to close the connection so that the worker threads could then close the sockets in a way that would not hold on to resources. For anyone who is interested see the TCP state diagram such as the one at http://no-shoveling.com/wp-content/uploads/2013/11/TCPfsm.png The key transition is the way the server exits the ESTABLISHED state. If the server closes its end of the connection first the transition goes via the line labelled appl:close, send: FIN. In that case the socket will end up in the TIME_WAIT state wherein it can wait 2MSL or 2 maximum segment lifetimes before becoming free. According to https://en.wikipedia.org/wiki/Maximum_segment_lifetime MSL is arbitrarily defined to be two minutes. That means a TCP endpoint could sit in TIME_WAIT for a horribly long four minutes...! So, I would rather get the other end to send the first FIN, if possible. On the TCP state diagram that is the exit from ESTABLISHED labelled recv:FIN, send ACK. My end can then shutdown the socket, which would send a FIN, and wait for a final ACK. Bottom line: I need to do a controlled cleanup. James From random832 at fastmail.com Fri Sep 18 15:12:38 2015 From: random832 at fastmail.com (Random832) Date: Fri, 18 Sep 2015 15:12:38 -0400 Subject: True == 1 weirdness In-Reply-To: References: <55fc0e4d$0$1645$c3e8da3$5496439d@news.astraweb.com> <1442583652.2433512.387297097.0C910B45@webmail.messagingengine.com> Message-ID: <1442603558.2508492.387585473.6851D82C@webmail.messagingengine.com> On Fri, Sep 18, 2015, at 14:24, Terry Reedy wrote: > If a, b, c are members of a totally ordered set, so that < is > transitive, this is equivalent to max(a,c) < b. But the latter makes an > irrelevant comparison between a and c. But *who would write that?* It's not a natural form of notation. I'm not saying it doesn't mean anything in Python. Obviously everything that is allowed means something. I'm saying no-one would write that in an ordinary context of human communication and expect to be understood. > > Your claim seemed to be that these combinations *are* > > used, since you claimed that python implements the *same* semantics. > > The semantics Python copies from math is "a op b op c == a op b and b op > c", I don't believe those *are* the semantics in math. I believe that in math this notation is *specifically* meant to support "all of these things are related to all of the others in ways that can be summarized in a single expression" and that mixing operations in a way that does not allow that is a misuse of the notation. In other words, any "a op b op c" that does not allow you to make a statement on how a is related to c is a *mistake*, because it means that you're welding together two things that aren't logically connected to each other at all. If there is no operator op3 where a op1 b op2 c implies a op3 c, then you should not put a and c in the same inequality, full stop. > where 'op' is a binary predicate or comparison operator. I also > happen to believe you are wrong in the specific examples. But the > semantic copying would apply even if a particular combination had not > yet ever been used. From larry.martell at gmail.com Fri Sep 18 15:47:47 2015 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 18 Sep 2015 15:47:47 -0400 Subject: Catching exceptions from logging socket handler Message-ID: I have a socket logging handler and I want to be able to catch exceptions from it. Specifically, I want to know if the remote side has gone away so I can close the socket and reopen it when the remote side come back. What happens now is that I get Broken pipe and BAD_WRITE_RETRY exceptions, but it's not coming from any functions I directly call. is there any way to catch these? Traceback (most recent call last): File "/home/ecovent/python2.7.9/lib/python2.7/logging/handlers.py", line 579, in emit self.send(s) File "/home/ecovent/python2.7.9/lib/python2.7/logging/handlers.py", line 520, in send self.sock.sendall(s) File "/home/ecovent/python2.7.9/lib/python2.7/ssl.py", line 701, in sendall v = self.send(data[count:]) File "/home/ecovent/python2.7.9/lib/python2.7/ssl.py", line 667, in send v = self._sslobj.write(data) SSLError: [SSL: BAD_WRITE_RETRY] bad write retry (_ssl.c:1625) Traceback (most recent call last): File "/home/ecovent/python2.7.9/lib/python2.7/logging/handlers.py", line 579, in emit self.send(s) File "/home/ecovent/python2.7.9/lib/python2.7/logging/handlers.py", line 520, in send self.sock.sendall(s) File "/home/ecovent/python2.7.9/lib/python2.7/ssl.py", line 701, in sendall v = self.send(data[count:]) File "/home/ecovent/python2.7.9/lib/python2.7/ssl.py", line 667, in send v = self._sslobj.write(data) error: [Errno 32] Broken pipe From skip.montanaro at gmail.com Fri Sep 18 16:13:50 2015 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 18 Sep 2015 15:13:50 -0500 Subject: Conda problem/question Message-ID: I was following along with Lex Hider's PyCon Au talk about Conda: https://www.youtube.com/watch?v=Fqknoni5aX0 Everything was going swimmingly. I installed miniconda, tweaked PATH, installed some of the other stuff he talked about, then did the pip command: pip install theano keras tweepy word2vec This hiccuped during the process because it wanted to install Cython and (I think - it's now scrolled off the terminal window) h5py. It seems it tried to build h5py before Cython, though h5py depends on Cython. Anyway, at the end it told me it had installed everything, so I continued. My next step was (deep breath): conda install anaconda which failed almost immediately with: Error: Unsatisfiable package specifications. Generating hint: [ COMPLETE ]|###################################################| 100% Hint: the following packages conflict with each other: - anaconda - python 3.5* So I presume I can't do the whole ball of wax because of the Python 3.5 install. I guess I should start from scratch... There's not really a question there, but should I have known to leave off the "python=3" arg when creating the environment? Would there have been a way to figure out ahead of time that python=3 wouldn't work? Thx, Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Fri Sep 18 16:40:14 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 18 Sep 2015 23:40:14 +0300 Subject: Shutting down a cross-platform multithreaded app References: Message-ID: <87d1xfh369.fsf@elektro.pacujo.net> "James Harris" : > I have a multithreaded app that I want to be able to shut down easily > such as by hitting control-c or sending it a signal. The problem with threads is you cannot cause them to exit from the outside. You can do that to asyncio coroutines, however. Maybe you should consider porting your multithreaded app to asyncio. Marko From lac at openend.se Fri Sep 18 16:50:36 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 18 Sep 2015 22:50:36 +0200 Subject: Shutting down a cross-platform multithreaded app In-Reply-To: References: <87zj0jd1ta.fsf@jester.gateway.sonic.net> Message-ID: <201509182050.t8IKoa4E008282@fido.openend.se> In a message of Fri, 18 Sep 2015 20:09:19 +0100, "James Harris" writes: >> Set the daemon flag on the worker threads, so when the main thread >> exits, the workers also exit. > >Interesting idea, and I did not know that a *thread* could be a daemon. >Unfortunately, I think what you suggest would kill the threads stone >dead and not allow them to close connections. Can you stick your worker threads into a Queue. When the main thread exits have it tell the queue to clean itself up? see: http://code.activestate.com/recipes/82965-threads-tkinter-and-asynchronous-io/ The main thread doesn't have to be a gui ... (but the author of that recipe and I are now drunkly celebrating a birthday so maybe I ought not to be posting this idea ...) Laura From ian.g.kelly at gmail.com Fri Sep 18 17:13:34 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 18 Sep 2015 15:13:34 -0600 Subject: True == 1 weirdness In-Reply-To: <1442603558.2508492.387585473.6851D82C@webmail.messagingengine.com> References: <55fc0e4d$0$1645$c3e8da3$5496439d@news.astraweb.com> <1442583652.2433512.387297097.0C910B45@webmail.messagingengine.com> <1442603558.2508492.387585473.6851D82C@webmail.messagingengine.com> Message-ID: On Fri, Sep 18, 2015 at 1:12 PM, Random832 wrote: > On Fri, Sep 18, 2015, at 14:24, Terry Reedy wrote: >> The semantics Python copies from math is "a op b op c == a op b and b op >> c", > > I don't believe those *are* the semantics in math. I believe that in > math this notation is *specifically* meant to support "all of these > things are related to all of the others in ways that can be summarized > in a single expression" and that mixing operations in a way that does > not allow that is a misuse of the notation. In other words, any "a op b > op c" that does not allow you to make a statement on how a is related to > c is a *mistake*, because it means that you're welding together two > things that aren't logically connected to each other at all. > > If there is no operator op3 where a op1 b op2 c implies a op3 c, then > you should not put a and c in the same inequality, full stop. Whoever wrote the Wikipedia article disagrees: https://en.wikipedia.org/wiki/Inequality_(mathematics)#Chained_notation Although the reference to Python leads one to suspect that this could be based more on Python's semantics than on actual mathematics. From random832 at fastmail.com Fri Sep 18 17:21:06 2015 From: random832 at fastmail.com (Random832) Date: Fri, 18 Sep 2015 17:21:06 -0400 Subject: True == 1 weirdness In-Reply-To: References: <55fc0e4d$0$1645$c3e8da3$5496439d@news.astraweb.com> <1442583652.2433512.387297097.0C910B45@webmail.messagingengine.com> <1442603558.2508492.387585473.6851D82C@webmail.messagingengine.com> Message-ID: <1442611266.2535214.387675673.55764E75@webmail.messagingengine.com> On Fri, Sep 18, 2015, at 17:13, Ian Kelly wrote: > Whoever wrote the Wikipedia article disagrees: > > https://en.wikipedia.org/wiki/Inequality_(mathematics)#Chained_notation > > Although the reference to Python leads one to suspect that this could > be based more on Python's semantics than on actual mathematics. Also, it says "different directions", but the provided example doesn't actually *show* different directions (i.e. mixing less-operators with greater-operators). The provided example "a < b = c <= d" does allow you to infer relationships between all participants: a < b, a < c, a < d, b = c, b <= d, c <= d. From rosuav at gmail.com Fri Sep 18 17:40:36 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Sep 2015 07:40:36 +1000 Subject: Shutting down a cross-platform multithreaded app In-Reply-To: References: Message-ID: On Sat, Sep 19, 2015 at 3:17 AM, James Harris wrote: > Needless to say, on a test Windows machine AF_UNIX is not present. The only > cross-platform option, therefore, seems to be to use each subthread's > select()s to monitor two AF_INET sockets: the one to the client and a > control one from the master thread. I would seem to need IP socket pairs > between the master thread and the subthreads. If the master thead receives a > shutdown signal it will send a shutdown command to each subthread. > > The above seems logical but would use quite a few IP sockets. I cannot think > of a better way, though. Any comments on the ideas above? If you're using select() to monitor the sockets, you don't actually then have to _do_ anything with the shutdown socket. You could have a single socket that sends the shutdown signal to all your workers. Bear in mind, though, that Windows has no protection against other processes shutting you down. You can restrict it to 127.0.0.1 (of course) but any program running on the same computer as the server - regardless of user permissions etc - will be able to connect to your sockets. So it might be best to do something like this (all on the main thread): 1) Open a listening socket 2) Connect to the listening socket 3) Accept a connection 4) Close the original listening socket 5) Spin off all your threads, passing them the socket from step 2 6) To terminate them all, write a byte to the socket from step 3. This will make it difficult for ordinary userspace code to mess with you. It'd still be possible, I think, for something with raw sockets access to feign a termination signal; I have no idea what protections Windows offers you there. Give it a shot, see how it goes! ChrisA From jcasale at activenetwerx.com Fri Sep 18 17:43:13 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Fri, 18 Sep 2015 21:43:13 +0000 Subject: Writing a module to abstract a REST api In-Reply-To: <55FC4F34.2030800@mail.de> References: <1b35c9c9b6864d7bb9bf11e0e3cb98ca@exch.activenetwerx.com>, <55FB2A8F.9050501@mail.de> <1442590107897.9135@activenetwerx.com>,<55FC4F34.2030800@mail.de> Message-ID: <1442612592952.36609@activenetwerx.com> Hi Sven, >> The problem now comes from the following: >> >> # foo now contains a handle to the remote api. >> foo = InstanceOfApiWrapper() > > Is it necessary to have an instance of that API? Just curiosity here. Not always but often as the pattern here might rely on a handle to a c types based api handle for example which might be a pointer or it may hold a session with credentials and state (not for REST of course). >> # queues is a container of Queue classes. >> queues = foo.get_queues() >> >> queue = queues[0] >> queue.delete() > > Alright. I see you want to have concrete classes, so you work with HTTP > like you would do with SOAP-bases web services. Yup. > I actually was referring to the self-expanding capability of REST > (please note, REST is not HTTP, HTTP is one protocol that can be use to > build an REST-ful API). It's basically like: you query a resource which > holds an link to another resource which you then you query by following > that link and so on and so forth. So, all what you need for REST is one > starting point to explore the resource graph. Well that is true, but what of the credential object that gets created with the instance of InstanceOfApiWrapper? You are certainly right in that the instance of Queue being REST based will always have all it needs to perform the functions, it just lacks the credentials. >> In this case its possible for foo (InstanceOfApiWrapper) to inject a reference >> to itself so the delete() can actually make the call. >> >> # I want to create a queue from scratch... >> disparate_queue = Queue(x, y, z) >> # Now what happens? No handle to an api? >> disparate_queue.delete() > > I don't see an issue here. Looks quite readable. Well, what credentials does .delete() use? I should have actually stated that, sorry. >> An alternative is: >> foo.delete_queue(disparate_queue) >> >> That's not a pattern I prefer, what facilities in Python provide for a workaround >> here? > > You always can add attributes to objects. So, add something like an > __api__ attribute (which nobody would ever use except you when creating > these queue objects in "get_queues"). This is where I am going, but how do you perform dependency injection in Python? > It's perfectly fine to add a "secret" API instance to the object. It's > called aspect-oriented programming. You remove the aspect of how to > correctly manage an API instance and put that knowledge into a separate > piece of code. *thumbs up* Yea, I am glad you agree:) Its a model I certainly subscribe to. I just don't know how to make the disparate case "know" of the foo instance when foo didn't instantiate it (which gives the injection opportunity). That foo instance also serves of a starting point to make the GET type queries. How would you go about making disparate case lookup a handle, especially when I insist on placing all the objects in their files. I know, tough to do in Python, but its what I am used to. Thanks a lot for the knowledge and insight, I greatly appreciate this. jlc From random832 at fastmail.com Fri Sep 18 17:48:29 2015 From: random832 at fastmail.com (Random832) Date: Fri, 18 Sep 2015 17:48:29 -0400 Subject: Shutting down a cross-platform multithreaded app In-Reply-To: References: Message-ID: <1442612909.2539807.387692137.0E9C2446@webmail.messagingengine.com> On Fri, Sep 18, 2015, at 17:40, Chris Angelico wrote: > Bear in mind, though, that Windows has no protection against other > processes shutting you down. Neither does Unix. Any process that can send you a signal can send you SIGKILL. Of course, what Windows lacks is a generalized way for other processes to send "less destructive" signals that do give you a chance to clean up. (You can sometimes send a ctrl-break event, but that's it.) And most frameworks for "emulating" them (including python's os module) simulate sending other signals by calling TerminateProcess with an exit status related to the signal. From st.kooday at gmail.com Fri Sep 18 17:51:49 2015 From: st.kooday at gmail.com (Saint Desmond) Date: Fri, 18 Sep 2015 21:51:49 +0000 Subject: Local variables and thread safety Message-ID: Dear Team, Kindly advise if variables declared within a function are thread safe. I would like to share a snippet with you if you wouldn?t mind. Thanks. From rosuav at gmail.com Fri Sep 18 18:09:12 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Sep 2015 08:09:12 +1000 Subject: Shutting down a cross-platform multithreaded app In-Reply-To: <1442612909.2539807.387692137.0E9C2446@webmail.messagingengine.com> References: <1442612909.2539807.387692137.0E9C2446@webmail.messagingengine.com> Message-ID: On Sat, Sep 19, 2015 at 7:48 AM, Random832 wrote: > On Fri, Sep 18, 2015, at 17:40, Chris Angelico wrote: >> Bear in mind, though, that Windows has no protection against other >> processes shutting you down. > > Neither does Unix. Any process that can send you a signal can send you > SIGKILL. Incorrect. If your server is running as root, only root can kill it: rosuav at sikorsky:~$ kill -9 17080 bash: kill: (17080) - Operation not permitted If it's running as some other user, then that user can kill it (that includes the simple case where a non-root user starts a process and also tries to kill it), as can root, of course. So you have protection against direct signals (and not just 9/KILL, naturally); and you also have protection against an AF_UNIX socket, which is what I was talking about here. The control over sockets is a bit more flexible, as I'm fairly sure group permissions can't be set for process signals, but they can for named sockets: rosuav at sikorsky:~$ python3 Python 3.6.0a0 (default:30bc256f2346, Sep 17 2015, 02:01:45) [GCC 4.9.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) >>> s.bind("/tmp/demo_socket") >>> import os >>> os.chmod("/tmp/demo_socket",0o750) >>> s.listen(1) >>> s.accept() # program pauses here (, b'') In another terminal, using Python 2 for variety: rosuav at sikorsky:~$ sudo sudo -u tfr python Python 2.7.9 (default, Mar 1 2015, 12:57:24) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> s = socket.socket(socket.AF_UNIX) >>> s.connect("/tmp/demo_socket") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 13] Permission denied Err, nope! What if I don't change users? rosuav at sikorsky:~$ python Python 2.7.9 (default, Mar 1 2015, 12:57:24) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> s = socket.socket(socket.AF_UNIX) >>> s.connect("/tmp/demo_socket") >>> Looks good. (Feel free to concoct your own scenario that proves that group permissions work here; I don't have any handy demo cases.) Unix is designed for this exact sort of thing. Windows isn't, and privilege escalation attacks are far more common there. > Of course, what Windows lacks is a generalized way for other processes > to send "less destructive" signals that do give you a chance to clean > up. (You can sometimes send a ctrl-break event, but that's it.) And most > frameworks for "emulating" them (including python's os module) simulate > sending other signals by calling TerminateProcess with an exit status > related to the signal. Yeah, the whole notion of less-destructive (or even completely non-destructive - look at how a lot of daemons use SIGHUP) signals is absent on Windows. But that's not really the problem here; the problem is that there's no way to say "this is a socket for my process ONLY", which in Unix would be done with a socket.socketpair, but on Windows I think has to be simulated. That said, though.... socket.socketpair() IS supported on Windows... as of Python 3.5. I haven't tested it to see what it's like. If you can restrict your support to 3.5+, you might be able to do this instead of what I was describing above. ChrisA From 4kir4.1i at gmail.com Fri Sep 18 19:56:17 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Sat, 19 Sep 2015 02:56:17 +0300 Subject: Shutting down a cross-platform multithreaded app References: Message-ID: <87613746zi.fsf@gmail.com> "James Harris" writes: ... > Needless to say, on a test Windows machine AF_UNIX is not present. The > only cross-platform option, therefore, seems to be to use each > subthread's select()s to monitor two AF_INET sockets: the one to the > client and a control one from the master thread. I would seem to need > IP socket pairs between the master thread and the subthreads. If the > master thead receives a shutdown signal it will send a shutdown > command to each subthread. There is socket.socketpair() on Windows too (since Python 3.5) https://docs.python.org/3/library/socket.html#socket.socketpair http://bugs.python.org/issue18643 Note: you could use select() to handle signals in the main thread too (even on Windows since Python 3.5) if you use signal.set_wakeup_fd() https://docs.python.org/3/library/signal.html#signal.set_wakeup_fd It is known as a self-pipe trick http://www.sitepoint.com/the-self-pipe-trick-explained/ Look at *asyncio* source code, to see how to get a portable implementation for various issues with signals. Some issues might still be opened e.g., Ctrl+C behavior http://bugs.python.org/issue24080 Here's how to combine SIGCHLD signal handling with tkinter's event loop http://stackoverflow.com/questions/30087506/event-driven-system-call-in-python SIGCHLD, createfilehandler() are not portable but the code demonstrates possible set_wakeup_fd() issues and their solutions (O_NONBLOCK, dummy signal handler, SA_RESTART, signal coalescing). On threads and signals in CPython http://bugs.python.org/issue5315#msg102829 From katewinslet626 at gmail.com Sat Sep 19 02:13:20 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Fri, 18 Sep 2015 23:13:20 -0700 (PDT) Subject: ConnectionError handling problem Message-ID: I am learning python. I wrote a script using requests module. The scripts runs fine for sometime, but after a while it hangs. When I press CTRL+C it shows ConnectionError even though I have included exception handling. I am not sure as to why it cant handle ConnectionError when the script runs for a long time. This is a part(causing issues) of the script I am running: while(k<46656): j=res[k] url="http://172.16.68.6:8090/login.xml" query_args = {'mode':'191', 'username':str(i), 'password':str(j), 'a':'1442397582010', 'producttype':'0'} try: r=requests.post(url, data=query_args) except: print "Connection error" time.sleep(30) continue html=r.text if(len(html) < 10): continue if("The system could not log you on" not in html): print "hello" filehandle=open("ids", "a") filehandle.write(str(i)+'\n') filehandle.write(str(j)+'\n') filehandle.close() break k=k+1 Any help will be highly appreciated. From harvesting at makes.email.invalid Sat Sep 19 02:23:55 2015 From: harvesting at makes.email.invalid (Jussi Piitulainen) Date: Sat, 19 Sep 2015 09:23:55 +0300 Subject: True == 1 weirdness References: <55fc0e4d$0$1645$c3e8da3$5496439d@news.astraweb.com> <1442583652.2433512.387297097.0C910B45@webmail.messagingengine.com> Message-ID: Random832 writes: > On Fri, Sep 18, 2015, at 14:24, Terry Reedy wrote: >> If a, b, c are members of a totally ordered set, so that < is >> transitive, this is equivalent to max(a,c) < b. But the latter makes >> an irrelevant comparison between a and c. > > But *who would write that?* It's not a natural form of notation. I'm > not saying it doesn't mean anything in Python. Obviously everything > that is allowed means something. I'm saying no-one would write that in > an ordinary context of human communication and expect to be > understood. It might be natural when discussing partial orders, where (a < b > c) is compatible with there not being any max(a, c) or even sup(a, c) at all. Here's a class of strings ordered by inclusion as substrings. The comparison (u in w != u) in __lt__ came naturally when I wrote this. class S(object): def __init__(self, s): self.s = s def __lt__(self, other): return self.s in other.s != self.s def __eq__(self, other): return self.s == other.s def __str__(self): return 'S({})'.format(repr(self.s)) And here's looking for two distinct elements that have a common proper upper bound in a given set. data = ('a', 'oo', 'r', 'foo', 'bar') print(*( (x.s, y.s) for x in map(S, data) for y in map(S, data) for m in map(S, data) if y != x < m > y != x ), sep = '\n') Output: ('a', 'r') ('r', 'a') The question is whether some such conditions might, sometimes, somewhere, in context, look natural. I says yes. The condition as a whole states a verbalizable relation between x, y, m: that m is a common upper bound of distinct x, y. It's not stated whether x < y or x > y or neither. From greg.ewing at canterbury.ac.nz Sat Sep 19 03:19:33 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 19 Sep 2015 19:19:33 +1200 Subject: True == 1 weirdness In-Reply-To: References: <55fc0e4d$0$1645$c3e8da3$5496439d@news.astraweb.com> Message-ID: Random832 wrote: > I'm disputing that chained comparisons are used for the particular > combinations that I am actually arguing should not be used in python. > Such as a < b > c or a != b != c [whereas a may or may not be equal to > c] I can't remember offhand seeing a != b != c written by a mathematician, but if I did, I would suspect that he *intended* it to imply a != c, even if that's not a strict logical consequence of the notation. -- Greg From darryl.doherty at gmail.com Sat Sep 19 03:25:20 2015 From: darryl.doherty at gmail.com (Darryl Doherty) Date: Sat, 19 Sep 2015 00:25:20 -0700 (PDT) Subject: Add items from a python list to a javascript array Message-ID: I have a kiosk for digital signage which has a html index file with a javascript which rotates through other html files using iframe at timed intervals. What I want to do is edit the array in the index file with Python to add and remove the HTML file paths from the array. I have a list of all file paths in the python list, so I want to select a path from the list and add it to the javascript array. In addition I want to be able to use python to remove file paths from the array when needed. I'm new to Python so some code examples would be appreciated. Thanks. File paths: Python script: '/users/admin/desktop/update.py HTML file: '/users/admin/desktop/msa0007/content/index.html' Other html files live in sub directories under '/users/admin/desktop/msa0007/content/' Python List: mylist = ['/users/admin/desktop/msa0007/content/test1/test1.html', '/users/admin/desktop/msa0007/content/test2/test2.html', '/users/admin/desktop/msa0007/content/test3/test3.html', '/users/admin/desktop/msa0007/content/test4/test4.html', '/users/admin/desktop/msa0007/content/test5/test5.html', '/users/admin/desktop/msa0007/content/test6/test6.html'] Javascript Array: var frames = Array('/users/admin/desktop/msa0007/content/test1/test1.html', '/users/admin/desktop/msa0007/content/test2/test2.html', '/users/admin/desktop/msa0007/content/test3/test3.html', '/users/admin/desktop/msa0007/content/test4/test4.html'); Index.html: Changing Pages... Please Wait From denismfmcmahon at gmail.com Sat Sep 19 03:58:04 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 19 Sep 2015 07:58:04 +0000 (UTC) Subject: Add items from a python list to a javascript array References: Message-ID: On Sat, 19 Sep 2015 00:25:20 -0700, Darryl Doherty wrote: > I have a kiosk for digital signage which has a html index file with a > javascript which rotates through other html files using iframe at timed > intervals. What I want to do is edit the array in the index file with > Python to add and remove the HTML file paths from the array. I have a > list of all file paths in the python list, so I want to select a path > from the list and add it to the javascript array. In addition I want to > be able to use python to remove file paths from the array when needed. > I'm new to Python so some code examples would be appreciated. Thanks. I'm going to assume that the whole web page is being generated by python code with the web server, and that the list of files is available in the python code at the time of web page generation. First of all, you need to create a python list of the file names to use. This will use whatever the current data is when the web page is generated. Secondly, you need to write this list to a suitable javascript variable when you construct the web page. Assuming that all the file paths are standard ascii with no spaces etc in them, say you have a python list like this: Here is a very simple code example for a method (and there are others) of embedding such a list of paths held in python within a javascript variable inside a script element in a web page: #!/usr/bin/python files = ["/a/a.htm", "/a/b.htm", "/a/c.htm"] page = "\n" print page -- Denis McMahon, denismfmcmahon at gmail.com From james.harris.1 at gmail.com Sat Sep 19 05:49:55 2015 From: james.harris.1 at gmail.com (James Harris) Date: Sat, 19 Sep 2015 10:49:55 +0100 Subject: Shutting down a cross-platform multithreaded app References: Message-ID: "Chris Angelico" wrote in message news:mailman.8.1442612439.21674.python-list at python.org... > On Sat, Sep 19, 2015 at 3:17 AM, James Harris > wrote: >> Needless to say, on a test Windows machine AF_UNIX is not present. >> The only >> cross-platform option, therefore, seems to be to use each subthread's >> select()s to monitor two AF_INET sockets: the one to the client and a >> control one from the master thread. I would seem to need IP socket >> pairs >> between the master thread and the subthreads. If the master thead >> receives a >> shutdown signal it will send a shutdown command to each subthread. >> >> The above seems logical but would use quite a few IP sockets. I >> cannot think >> of a better way, though. Any comments on the ideas above? > > If you're using select() to monitor the sockets, you don't actually > then have to _do_ anything with the shutdown socket. You could have a > single socket that sends the shutdown signal to all your workers. I don't understand how a single socket could send the signal to all the workers. I did consider some form of multicast but thought it too complicated (and possibly infeasible). Re. not understanding the single sending socket idea that you mention perhaps I had better explain a bit of what I had in mind: 1. A worker thread would have a TCP socket connection to its client, and another socket for communicating with the master. That second socket has to be AF_INET for portability. It could be TCP or UDP. A connected UDP socket may be most appropriate and seems worth trying. 2. If something happens to the master thread so that it determines that the application should shut down it would iterate over the sockets to the workers and tell each one to shut down. It would then shut itself down. (Am not sure at the moment whether to wait for the worker threads.) 3. A worker thread, being told to shutdown (basically a single byte received from the master thread) would tell its client to close the TCP connection and then it would wait a little while for it to do so - maybe a second or two. When the client closes the TCP connection (or the timeout wait period expires) the worker thread will close its end and exit. > Bear in mind, though, that Windows has no protection against other > processes shutting you down. You can restrict it to 127.0.0.1 (of > course) but any program running on the same computer as the server - > regardless of user permissions etc - will be able to connect to your > sockets. I was thinking of a connected UDP socket. That way, AIUI, at least in the absence of forged datagrams, only the master thread will be able to communicate with the worker, due to connected UDP sockets demulitplexing datagrams based on their source as well as their destination, i.e. on a 5-tuple (UDP, source IP, source port, destination IP, destination port). > So it might be best to do something like this (all on the > main thread): > > 1) Open a listening socket > 2) Connect to the listening socket > 3) Accept a connection > 4) Close the original listening socket > 5) Spin off all your threads, passing them the socket from step 2 > 6) To terminate them all, write a byte to the socket from step 3. That sounds similar to what I had in mind but I am not sure why you would close the listening socket. Connections could come in at any time and threads could therefore be needed at any time so I was thinking that the master thread (the one with the listening TCP socket) would just sit waiting for new connection requests (or an interrupting signal). In reality, due to Windows not recognising signals while in the accept() call I think there would be a real master thread and a listening thread but I have omitted that in the descriptions above. As far as the normal worker threads are concerned they would be ready to be told to shut down by the listening thread, and it would be ready to be told to shut down by the master thread. Still with me? ;-) > This will make it difficult for ordinary userspace code to mess with > you. It'd still be possible, I think, for something with raw sockets > access to feign a termination signal; I have no idea what protections > Windows offers you there. Yes, something which could forge a packet could tell a worker to close down. I don't think there's any significant problem here, thought, because: * other programs are similarly vulnerable to forged packets * the only forgery effect is to tell a worker thread to stop - not a big loss * the shutdown protocol would/should cause the client to re-request * a forger would have to know the specific port number used by the master thread to communicate with that particular worker, and the port number that worker was using. Overall, I think it would be more than robust enough. Notwithstanding your comment about a single socket, above, no one seems so far to have objected to the number of sockets this would need, which was my main concern, so that's good! James From james.harris.1 at gmail.com Sat Sep 19 05:56:46 2015 From: james.harris.1 at gmail.com (James Harris) Date: Sat, 19 Sep 2015 10:56:46 +0100 Subject: Shutting down a cross-platform multithreaded app References: <87zj0jd1ta.fsf@jester.gateway.sonic.net> Message-ID: "Laura Creighton" wrote in message news:mailman.5.1442609448.21674.python-list at python.org... > In a message of Fri, 18 Sep 2015 20:09:19 +0100, "James Harris" > writes: >>> Set the daemon flag on the worker threads, so when the main thread >>> exits, the workers also exit. >> >>Interesting idea, and I did not know that a *thread* could be a >>daemon. >>Unfortunately, I think what you suggest would kill the threads stone >>dead and not allow them to close connections. > > Can you stick your worker threads into a Queue. When the main thread > exits > have it tell the queue to clean itself up? > > see: > http://code.activestate.com/recipes/82965-threads-tkinter-and-asynchronous-io/ > > The main thread doesn't have to be a gui ... > > (but the author of that recipe and I are now drunkly celebrating a > birthday > so maybe I ought not to be posting this idea ...) :-) I am not sure. The polling every 100ms or similar in periodicCall() is something I want to avoid. I think I have a way to do this without any polling. James From rosuav at gmail.com Sat Sep 19 06:14:58 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Sep 2015 20:14:58 +1000 Subject: Shutting down a cross-platform multithreaded app In-Reply-To: References: Message-ID: On Sat, Sep 19, 2015 at 7:49 PM, James Harris wrote: > "Chris Angelico" wrote in message > news:mailman.8.1442612439.21674.python-list at python.org... >> >> On Sat, Sep 19, 2015 at 3:17 AM, James Harris >> wrote: >>> >>> Needless to say, on a test Windows machine AF_UNIX is not present. The >>> only >>> cross-platform option, therefore, seems to be to use each subthread's >>> select()s to monitor two AF_INET sockets: the one to the client and a >>> control one from the master thread. I would seem to need IP socket pairs >>> between the master thread and the subthreads. If the master thead >>> receives a >>> shutdown signal it will send a shutdown command to each subthread. >>> >>> The above seems logical but would use quite a few IP sockets. I cannot >>> think >>> of a better way, though. Any comments on the ideas above? >> >> >> If you're using select() to monitor the sockets, you don't actually >> then have to _do_ anything with the shutdown socket. You could have a >> single socket that sends the shutdown signal to all your workers. > > > I don't understand how a single socket could send the signal to all the > workers. I did consider some form of multicast but thought it too > complicated (and possibly infeasible). The way I'm describing it, the workers never actually read from the socket. Once that socket becomes readable, they immediately shut down, without making the socket no-longer-readable. >> Bear in mind, though, that Windows has no protection against other >> processes shutting you down. You can restrict it to 127.0.0.1 (of >> course) but any program running on the same computer as the server - >> regardless of user permissions etc - will be able to connect to your >> sockets. > > > I was thinking of a connected UDP socket. That way, AIUI, at least in the > absence of forged datagrams, only the master thread will be able to > communicate with the worker, due to connected UDP sockets demulitplexing > datagrams based on their source as well as their destination, i.e. on a > 5-tuple (UDP, source IP, source port, destination IP, destination port). TCP sockets also work on that set of five. That's why I suggested a pre-connected TCP socket, with the original listening socket closed. (And as mentioned, Python 3.5 supports socketpair() on Windows. That would definitely be the best option.) > That sounds similar to what I had in mind but I am not sure why you would > close the listening socket. Connections could come in at any time and > threads could therefore be needed at any time so I was thinking that the > master thread (the one with the listening TCP socket) would just sit waiting > for new connection requests (or an interrupting signal). TCP sockets work on the basis of a master socket and any number of spawned sockets. The master is what gives you an open port; each spawned socket represents one connection with one client. Once you have an established connection, the master should be able to be closed without disrupting that. No other process will be able to connect to you, but you'll still be able to use one end of the socket to make the other end readable. >> This will make it difficult for ordinary userspace code to mess with >> you. It'd still be possible, I think, for something with raw sockets >> access to feign a termination signal; I have no idea what protections >> Windows offers you there. > > > Yes, something which could forge a packet could tell a worker to close down. > I don't think there's any significant problem here, thought, because: > > * other programs are similarly vulnerable to forged packets > * the only forgery effect is to tell a worker thread to stop - not a big > loss > * the shutdown protocol would/should cause the client to re-request > * a forger would have to know the specific port number used by the master > thread to communicate with that particular worker, and the port number that > worker was using. > > Overall, I think it would be more than robust enough. With UDP, any process that can send a UDP packet can flood the system with them until your workers shut down. You wouldn't even notice until it succeeds. With TCP, at least an attacker would need raw socket access. It's still not as protected as a Unix domain socket, but it's a bit harder for someone to do. > Notwithstanding your comment about a single socket, above, no one seems so > far to have objected to the number of sockets this would need, which was my > main concern, so that's good! Sure. Sockets are pretty cheap. Even if you had one for every worker, there's room for you to have thousands (maybe tens of thousands) of workers without a problem. I think you'll run into other scaling problems with that many workers on one computer :) ChrisA From james.harris.1 at gmail.com Sat Sep 19 06:48:11 2015 From: james.harris.1 at gmail.com (James Harris) Date: Sat, 19 Sep 2015 11:48:11 +0100 Subject: Shutting down a cross-platform multithreaded app References: Message-ID: "Chris Angelico" wrote in message news:mailman.13.1442657702.21674.python-list at python.org... > On Sat, Sep 19, 2015 at 7:49 PM, James Harris > wrote: >> "Chris Angelico" wrote in message >> news:mailman.8.1442612439.21674.python-list at python.org... ... >>> If you're using select() to monitor the sockets, you don't actually >>> then have to _do_ anything with the shutdown socket. You could have >>> a >>> single socket that sends the shutdown signal to all your workers. >> >> >> I don't understand how a single socket could send the signal to all >> the >> workers. I did consider some form of multicast but thought it too >> complicated (and possibly infeasible). > > The way I'm describing it, the workers never actually read from the > socket. Once that socket becomes readable, they immediately shut down, > without making the socket no-longer-readable. Understood. Good idea. Initial thoughts on it: Would work for threads. Would save on the number of sockets required. Would not work for processes if the model was ever changed. Would make it easier for rogue packets to shut a worker down. Would not allow any way to distinguish between shutdown priorities (not something I have mentioned). Definitely feasible. I'll keep it in mind. >>> Bear in mind, though, that Windows has no protection against other >>> processes shutting you down. You can restrict it to 127.0.0.1 (of >>> course) but any program running on the same computer as the server - >>> regardless of user permissions etc - will be able to connect to your >>> sockets. ... >> That sounds similar to what I had in mind but I am not sure why you >> would >> close the listening socket. Connections could come in at any time and >> threads could therefore be needed at any time so I was thinking that >> the >> master thread (the one with the listening TCP socket) would just sit >> waiting >> for new connection requests (or an interrupting signal). > > TCP sockets work on the basis of a master socket and any number of > spawned sockets. The master is what gives you an open port; each > spawned socket represents one connection with one client. Once you > have an established connection, the master should be able to be closed > without disrupting that. No other process will be able to connect to > you, but you'll still be able to use one end of the socket to make the > other end readable. Agreed but I need the listening socket to remain open and listening for new connections (at least until the whole program is told to shut down). >>> This will make it difficult for ordinary userspace code to mess with >>> you. It'd still be possible, I think, for something with raw sockets >>> access to feign a termination signal; I have no idea what >>> protections >>> Windows offers you there. >> >> >> Yes, something which could forge a packet could tell a worker to >> close down. >> I don't think there's any significant problem here, thought, because: >> >> * other programs are similarly vulnerable to forged packets >> * the only forgery effect is to tell a worker thread to stop - not a >> big >> loss >> * the shutdown protocol would/should cause the client to re-request >> * a forger would have to know the specific port number used by the >> master >> thread to communicate with that particular worker, and the port >> number that >> worker was using. >> >> Overall, I think it would be more than robust enough. > > With UDP, any process that can send a UDP packet can flood the system > with them until your workers shut down. You wouldn't even notice until > it succeeds. Is that true? You seem to be describing a non-forged attack but to get the source UDP port right wouldn't the attacker have to be runing on the same machine *and* to bind to the same port that the machine had allocated to my program? I might be wrong but I don't think the UDP stack would allow the same port to be bound again before the original had been closed. > With TCP, at least an attacker would need raw socket > access. It's still not as protected as a Unix domain socket, but it's > a bit harder for someone to do. > >> Notwithstanding your comment about a single socket, above, no one >> seems so >> far to have objected to the number of sockets this would need, which >> was my >> main concern, so that's good! > > Sure. Sockets are pretty cheap. Even if you had one for every worker, > there's room for you to have thousands (maybe tens of thousands) of > workers without a problem. I think you'll run into other scaling > problems with that many workers on one computer :) Let's see. If I stick with my original plan then each worker would have a TCP socket and a UDP socket. The "listener" thread would have its single listening TCP socket plus it would have a UDP socket for each worker thread. Total of three sockets per worker, two of which would be UDP sockets with port numbers assigned and thus consumed. If I go with a single "shutdown socket" then I would have just one socket per worker. That would use fewer sockets, for sure. James From srkunze at mail.de Sat Sep 19 06:56:16 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Sat, 19 Sep 2015 12:56:16 +0200 Subject: Writing a module to abstract a REST api In-Reply-To: <1442612592952.36609@activenetwerx.com> References: <1b35c9c9b6864d7bb9bf11e0e3cb98ca@exch.activenetwerx.com>, <55FB2A8F.9050501@mail.de> <1442590107897.9135@activenetwerx.com>, <55FC4F34.2030800@mail.de> <1442612592952.36609@activenetwerx.com> Message-ID: <55FD3F50.7070002@mail.de> Hi Joseph, the basic wiring instances together is done via the assignment operator: "=". Like: queue._api = foo. Now, the "queue" knows about its API instance. Question now is, when do you do "="? On 18.09.2015 23:43, Joseph L. Casale wrote: > This is where I am going, but how do you perform dependency injection > in Python? I am uncertain how large the application you want to build is supposed to be. I would definitely would start with less code (tighter coupled) which is easier to maintain in the first run. But if you are interesting the DI in Python in general, I think you would love to read those two resources: http://www.aleax.it/yt_pydi.pdf http://code.activestate.com/recipes/413268/ I am not saying you shouldn't do DI, but it's easier to tight-couple things and make them more flexible in the aftermath *when finally you know where you application is going*. Otherwise, it might turn out to be a waste of resources. >> It's perfectly fine to add a "secret" API instance to the object. It's >> called aspect-oriented programming. You remove the aspect of how to >> correctly manage an API instance and put that knowledge into a separate >> piece of code. *thumbs up* > Yea, I am glad you agree:) Its a model I certainly subscribe to. I just don't > know how to make the disparate case "know" of the foo instance when > foo didn't instantiate it (which gives the injection opportunity). As usual, somebody *needs**to know*. So, if the first version is only working hard-coupled because foo instantiated the queues, the second version then would, for example, assign the APIWrapper class instead of an APIWrapper instance to the _api attribute of all queue instances. The class could then work as a lookup/factory method*.*** If that is still not flexible enough and you find Queue and APIWrapper is still too much coupled, you can then refactor that out into a third module which is responsible only for wiring the instances together (or use the recipe). But remember, you increase the complexity more and more and you better decide whether it's worth it, taking maintenance and future development into account. I might reiterate here: I don't know of the scale of your application but if it is from scratch, you better start with tighter coupling and remove it bit by bit later, when you know where the journey goes AND if the tight coupling causes issues. It does not make sense to solve non-issues (at least economically). > That foo instance also serves of a starting point to make the GET type queries. > > How would you go about making disparate case lookup a handle, especially > when I insist on placing all the objects in their files. Why do you want to store the objects in files? Caching? > I know, tough to do in > Python, but its what I am used to. That's alright. Your thinking will change the longer you use Python. You are going to strive for the simples (non-complex), shortest, direct and most comprehensive solution. It's a development; don't forget what you've learned but be open for the Python style. :) Best, Sven -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Sep 19 06:59:31 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Sep 2015 20:59:31 +1000 Subject: Shutting down a cross-platform multithreaded app In-Reply-To: References: Message-ID: On Sat, Sep 19, 2015 at 8:48 PM, James Harris wrote: > "Chris Angelico" wrote in message > news:mailman.13.1442657702.21674.python-list at python.org... >> >> On Sat, Sep 19, 2015 at 7:49 PM, James Harris >> wrote: >>> >>> "Chris Angelico" wrote in message >>> news:mailman.8.1442612439.21674.python-list at python.org... >>>> If you're using select() to monitor the sockets, you don't actually >>>> then have to _do_ anything with the shutdown socket. You could have a >>>> single socket that sends the shutdown signal to all your workers. >>> >>> >>> >>> I don't understand how a single socket could send the signal to all the >>> workers. I did consider some form of multicast but thought it too >>> complicated (and possibly infeasible). >> >> >> The way I'm describing it, the workers never actually read from the >> socket. Once that socket becomes readable, they immediately shut down, >> without making the socket no-longer-readable. > > > Understood. Good idea. Initial thoughts on it: Would work for threads. Would > save on the number of sockets required. Would not work for processes if the > model was ever changed. Would make it easier for rogue packets to shut a > worker down. Would not allow any way to distinguish between shutdown > priorities (not something I have mentioned). Definitely feasible. I'll keep > it in mind. If you go to multiple processes, yeah, it probably wouldn't work *on Windows*. On Unix, you can fork and have multiple processes with the same socket. (It's very common to have, for instance, a subprocess's stdin/stdout/stderr linked to pipes of some sort; the calling process still retains control.) It would be _harder_ for rogue packets to shut a worker down this way. >> TCP sockets work on the basis of a master socket and any number of >> spawned sockets. The master is what gives you an open port; each >> spawned socket represents one connection with one client. Once you >> have an established connection, the master should be able to be closed >> without disrupting that. No other process will be able to connect to >> you, but you'll still be able to use one end of the socket to make the >> other end readable. > > Agreed but I need the listening socket to remain open and listening for new > connections (at least until the whole program is told to shut down). Not sure why. The sole purpose of this socket is to establish a (single) socket pair used for the termination signals - nothing more. You shouldn't need to listen for any new connections, even if you spawn new workers. >> With UDP, any process that can send a UDP packet can flood the system >> with them until your workers shut down. You wouldn't even notice until >> it succeeds. > > Is that true? You seem to be describing a non-forged attack but to get the > source UDP port right wouldn't the attacker have to be runing on the same > machine *and* to bind to the same port that the machine had allocated to my > program? I might be wrong but I don't think the UDP stack would allow the > same port to be bound again before the original had been closed. UDP basically doesn't have protections like that. TCP does, and though it _is_ possible to forge packets, it requires raw socket access. I don't know what protections Windows has around that, but certainly a software firewall should be able to notice that some program is spewing raw packets. > Let's see. If I stick with my original plan then each worker would have a > TCP socket and a UDP socket. The "listener" thread would have its single > listening TCP socket plus it would have a UDP socket for each worker thread. > Total of three sockets per worker, two of which would be UDP sockets with > port numbers assigned and thus consumed. > > If I go with a single "shutdown socket" then I would have just one socket > per worker. That would use fewer sockets, for sure. Yeah, it's pretty cheap either way. Your most scarce resource here would be UDP port numbers, and there's 64K of those. That'd let you go as far as 32K workers, and I don't think you can have that many threads without saturating something somewhere else. ChrisA From joel.goldstick at gmail.com Sat Sep 19 10:34:38 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 19 Sep 2015 10:34:38 -0400 Subject: windows 10 In-Reply-To: <55fb57cb.8677810a.86f0c.ffffe39d@mx.google.com> References: <55fb57cb.8677810a.86f0c.ffffe39d@mx.google.com> Message-ID: On Thu, Sep 17, 2015 at 8:16 PM, wrote: > I am using Windows 10. I cannot find the Python (command line). Do you > know where I would find it? > > > > Thank you, > > Heidi > > > > Sent from Mail for > Windows 10 > Did you try googling "windows 10 command line"? I did and found lots of > links. > -- > https://mail.python.org/mailman/listinfo/python-list > > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Sat Sep 19 12:15:00 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 19 Sep 2015 17:15:00 +0100 Subject: windows 10 In-Reply-To: <55fb57cb.8677810a.86f0c.ffffe39d@mx.google.com> References: <55fb57cb.8677810a.86f0c.ffffe39d@mx.google.com> Message-ID: On 18/09/2015 01:16, heidimtaylor at gmail.com wrote: > I am using Windows 10. I cannot find the Python (command line). Do you > know where I would find it? > > Thank you, > > Heidi > > Sent from Mail for > Windows 10 > Python doesn't come with Windows, you have to install it yourself. What do you actually mean by "Python (command line)"? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sat Sep 19 12:18:12 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 19 Sep 2015 17:18:12 +0100 Subject: ConnectionError handling problem In-Reply-To: References: Message-ID: On 19/09/2015 07:13, shiva upreti wrote: > I am learning python. I wrote a script using requests module. > The scripts runs fine for sometime, but after a while it hangs. When I press CTRL+C it shows ConnectionError even though I have included exception handling. > I am not sure as to why it cant handle ConnectionError when the script runs for a long time. > > This is a part(causing issues) of the script I am running: > > while(k<46656): > j=res[k] > url="http://172.16.68.6:8090/login.xml" > query_args = {'mode':'191', 'username':str(i), 'password':str(j), 'a':'1442397582010', 'producttype':'0'} > > try: > r=requests.post(url, data=query_args) > except: > print "Connection error" > time.sleep(30) > continue > > html=r.text > if(len(html) < 10): > continue > > if("The system could not log you on" not in html): > print "hello" > filehandle=open("ids", "a") > filehandle.write(str(i)+'\n') > filehandle.write(str(j)+'\n') > filehandle.close() > break > > k=k+1 > > Any help will be highly appreciated. > Never use a bare except in Python, always handle the bare minimum number of exceptions that you need to, in this case your ConnectionError. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From emile at fenx.com Sat Sep 19 12:20:54 2015 From: emile at fenx.com (Emile van Sebille) Date: Sat, 19 Sep 2015 09:20:54 -0700 Subject: Hello In-Reply-To: References: Message-ID: On 9/17/2015 8:10 AM, moon khondkar wrote: > Hello I have problem with python installation.I downloaded python 3.5 but I cannot use it on my computer.I can not open the idle. I get something like saying "users\local settings\Application data\programs\python\python35-32\pythonw.exe is not valid win32 application. Thanks that will be help if you can solve this. > you might want to try activestate's version from http://www.activestate.com/activepython/downloads 3.5 isn't available there yet, but it otherwise has always been the easiest to install and get a more complete level of windows compatibility. emile From random832 at fastmail.com Sat Sep 19 13:38:05 2015 From: random832 at fastmail.com (Random832) Date: Sat, 19 Sep 2015 13:38:05 -0400 Subject: Hello In-Reply-To: (Dennis Lee Bieber's message of "Sat, 19 Sep 2015 13:31:35 -0400") References: Message-ID: Dennis Lee Bieber writes: > While Windows likes to stuff things in directories with spaces in them, > I find third-party applications (especially those that are created for > multiple OSes) work better when installed in directories that have no > spaces... Hey, don't put this on being created for multiple OSes. Unix and Mac both supported spaces in filenames, at the OS level, *long* before Windows did. Programs that break on encountering them are broken everywhere. From breamoreboy at yahoo.co.uk Sat Sep 19 16:13:36 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 19 Sep 2015 21:13:36 +0100 Subject: Hello In-Reply-To: References: Message-ID: On 19/09/2015 18:31, Dennis Lee Bieber wrote: > On Thu, 17 Sep 2015 16:10:55 +0100, moon khondkar > declaimed the following: > >> Hello I have problem with python installation.I downloaded python 3.5 but I cannot use it on my computer.I can not open the idle. I get something like saying "users\local settings\Application data\programs\python\python35-32\pythonw.exe is not valid win32 application. Thanks that will be help if you can solve this. > > Given that path, you have a very strangely configured Windows system... > All change with 3.5, so that looks about right for a default user installation, with "install for all users" going under "Program Files". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From pwatson at phs.org Sat Sep 19 16:14:03 2015 From: pwatson at phs.org (Watson, Paul) Date: Sat, 19 Sep 2015 20:14:03 +0000 Subject: Hello In-Reply-To: References: Message-ID: > Hello I have problem with python installation.I downloaded python 3.5 but > I cannot use it on my computer.I can not open the idle. I get something like saying > "users\local settings\Application data\programs\python\python35-32\pythonw.exe > is not valid win32 application. Thanks that will be help if you can solve this. Did you verify that the md5sum for the file you downloaded is correct? https://www.python.org/downloads/release/python-350/ ============================================ *-*-*- PRESBYTERIAN_HEALTHCARE_SERVICES_DISCLAIMER -*-*-* This message originates from Presbyterian Healthcare Services or one of its affiliated organizations. It contains information, which may be confidential or privileged, and is intended only for the individual or entity named above. It is prohibited for anyone else to disclose, copy, distribute or use the contents of this message. All personal messages express views solely of the sender, which are not to be attributed to Presbyterian Healthcare Services or any of its affiliated organizations, and may not be distributed without this disclaimer. If you received this message in error, please notify us immediately at info at phs.org. If you would like more information about Presbyterian Healthcare Services please visit our web site http://www.phs.org ============================================ From torriem at gmail.com Sat Sep 19 23:27:47 2015 From: torriem at gmail.com (Michael Torrie) Date: Sat, 19 Sep 2015 21:27:47 -0600 Subject: Einstein's Riddle In-Reply-To: References: <1cef1669-1a62-4fe8-ac31-6fff385e77ed@googlegroups.com> <55fbda7c$0$1646$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55FE27B3.1090504@gmail.com> On 09/18/2015 03:51 AM, Nick Sarbicki wrote: > On Fri, Sep 18, 2015 at 10:33 AM, Steven D'Aprano >> Time is relative. Perhaps the poster has been travelling at close to the >> speed of light, and for him it is only a few minutes after the original >> post was sent. > > I prefer to think that it just took him this long to do it. Probably what happened is some computer somewhere was finally rebooted after 15 years of uptime, and this messages finally was processed after years stuck in the queue. I read once of a university that, upon decomissioning a mainframe, found a job that had been in the queue for many years but had never run. Probably some poor grad student's job. From dieter at handshake.de Sun Sep 20 02:02:34 2015 From: dieter at handshake.de (dieter) Date: Sun, 20 Sep 2015 08:02:34 +0200 Subject: Local variables and thread safety References: Message-ID: <87io75mxvp.fsf@handshake.de> Saint Desmond writes: > Dear Team, > Kindly advise if variables declared within a function are thread safe. In general, yes. However, there are exceptions. First of all, "variable" is not the optimal term to use in this context. In Python, a "variable" is nothing more than the binding of a name to an object. The local binding in a function itself is thread safe; however, operations on the bound object may not be thread safe. For example, if the bound object comes from outside the function (i.e. it is visible outside the function) then other threads could modify it and those modifications conflict with each other or modifications in this thread. Another example would be the use of a locally defined function (wich can access "variable"s defined in the enclosing function) as a thread. Look at Python's "threading" module to find general purpose utilities to assure thread safety. From mvoicem at gmail.com Sun Sep 20 02:41:24 2015 From: mvoicem at gmail.com (m) Date: Sun, 20 Sep 2015 08:41:24 +0200 Subject: Einstein's Riddle In-Reply-To: References: <1cef1669-1a62-4fe8-ac31-6fff385e77ed@googlegroups.com> <55fbda7c$0$1646$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55fe5511$0$613$65785112@news.neostrada.pl> W dniu 20.09.2015 o 05:27, Michael Torrie pisze: > On 09/18/2015 03:51 AM, Nick Sarbicki wrote: >> > On Fri, Sep 18, 2015 at 10:33 AM, Steven D'Aprano >>> >> Time is relative. Perhaps the poster has been travelling at close to the >>> >> speed of light, and for him it is only a few minutes after the original >>> >> post was sent. >> > >> > I prefer to think that it just took him this long to do it. > Probably what happened is some computer somewhere was finally rebooted > after 15 years of uptime, and this messages finally was processed after > years stuck in the queue. It's posted from @gmail account, and Gmail started near 2004 r. m. From denismfmcmahon at gmail.com Sun Sep 20 02:43:03 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 20 Sep 2015 06:43:03 +0000 (UTC) Subject: Einstein's Riddle References: <1cef1669-1a62-4fe8-ac31-6fff385e77ed@googlegroups.com> <55fbda7c$0$1646$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 19 Sep 2015 21:27:47 -0600, Michael Torrie wrote: > I read once of a university that, upon decomissioning a mainframe, found > a job that had been in the queue for many years but had never run. > Probably some poor grad student's job. Somewhere there's a computer sitting in the corner of a Pentagon office that makes an unanswered modem call to a telephone somewhere once a week. One day, someone will realise they have no idea why, and shut the computer off. When the doomsday silo on the other end stops receiving it's weekly "everything is ok" message, it's going to nuke Beijing and Moscow ..... (I really really really hope that this is indeed fiction!) -- Denis McMahon, denismfmcmahon at gmail.com From paul.anton.letnes at gmail.com Sun Sep 20 03:52:11 2015 From: paul.anton.letnes at gmail.com (paul.anton.letnes at gmail.com) Date: Sun, 20 Sep 2015 00:52:11 -0700 (PDT) Subject: Ordering dependent test failures Message-ID: <2663735f-f237-4ed4-ab41-e9068041358b@googlegroups.com> Hi! Fascinated by the concept of ordering dependent test failures [0], I've run the python test suite [1] with 256 different random seeds (took a little more than 12 hours). The results vary a lot - for instance, the number of tests reported as OK varies, the number of skips varies, etc. Since I'm not sure how to report or interpret them, I'll just post a summary below. The test suite was run on arch linux [2] with gcc 5.2.0, with the source code taken from a clone of the python repo yesterday [3]. What could I do with all this in order to make more sense of it, and could it be of any help what so ever to python development? I'll gladly make the full log files available to whomever is interested, in whatever format is convenient. In the meantime I'll run more random seeds, because why not. [0] https://docs.python.org/devguide/buildbots.html#ordering-dependent-failures [1] ./python -Wd -E -bb -m test -uall -rwW --randseed $k > testlog/${k}.log 2>&1 [2] https://www.archlinux.org/ [3] Python 3.6.0a0 (default:3704cea9fd8e, Sep 19 2015, 16:12:53) The command "grep OK *.log", where e.g. 5.log is the output of command [1] with "--randseed 5": 0.log:380 tests OK. 0.log:OK (skipped=15) 0.log:OK (skipped=15) 0.log:OK (skipped=15) 0.log:OK (skipped=2) 1.log:383 tests OK. 1.log:OK (skipped=2) 2.log:380 tests OK. 2.log:OK (skipped=15) 2.log:OK (skipped=15) 2.log:OK (skipped=15) 2.log:OK (skipped=2) 3.log:380 tests OK. 3.log:OK (skipped=15) 3.log:OK (skipped=15) 3.log:OK (skipped=2) 3.log:OK (skipped=37) 4.log:381 tests OK. 4.log:OK (skipped=15) 4.log:OK (skipped=15) 4.log:OK (skipped=2) 5.log:380 tests OK. 5.log:OK (skipped=15) 5.log:OK (skipped=15) 5.log:OK (skipped=15) 5.log:OK (skipped=2) 6.log:381 tests OK. 6.log:OK (skipped=15) 6.log:OK (skipped=15) 6.log:OK (skipped=2) 7.log:380 tests OK. 7.log:OK (skipped=15) 7.log:OK (skipped=15) 7.log:OK (skipped=15) 7.log:OK (skipped=2) 8.log:381 tests OK. 8.log:OK (skipped=15) 8.log:OK (skipped=15) 8.log:OK (skipped=2) 9.log:382 tests OK. 9.log:OK (skipped=15) 9.log:OK (skipped=2) 10.log:381 tests OK. 10.log:OK (skipped=15) 10.log:OK (skipped=15) 10.log:OK (skipped=2) 11.log:380 tests OK. 11.log:OK (skipped=15) 11.log:OK (skipped=15) 11.log:OK (skipped=2) 11.log:OK (skipped=37) 12.log:380 tests OK. 12.log:OK (skipped=15) 12.log:OK (skipped=15) 12.log:OK (skipped=15) 12.log:OK (skipped=2) 13.log:383 tests OK. 13.log:OK (skipped=2) 14.log:381 tests OK. 14.log:OK (skipped=15) 14.log:OK (skipped=2) 14.log:OK (skipped=39) 15.log:383 tests OK. 15.log:OK (skipped=2) 16.log:381 tests OK. 16.log:OK (skipped=15) 16.log:OK (skipped=15) 16.log:OK (skipped=2) 17.log:381 tests OK. 17.log:OK (skipped=15) 17.log:OK (skipped=15) 17.log:OK (skipped=2) 18.log:381 tests OK. 18.log:OK (skipped=15) 18.log:OK (skipped=15) 18.log:OK (skipped=2) 19.log:381 tests OK. 19.log:OK (skipped=15) 19.log:OK (skipped=15) 19.log:OK (skipped=2) 20.log:381 tests OK. 20.log:OK (skipped=15) 20.log:OK (skipped=15) 20.log:OK (skipped=2) 21.log:382 tests OK. 21.log:OK (skipped=15) 21.log:OK (skipped=2) 22.log:383 tests OK. 22.log:OK (skipped=2) 23.log:383 tests OK. 23.log:OK (skipped=2) 24.log:382 tests OK. 24.log:OK (skipped=15) 24.log:OK (skipped=2) 25.log:381 tests OK. 25.log:OK (skipped=15) 25.log:OK (skipped=15) 25.log:OK (skipped=2) 26.log:380 tests OK. 26.log:OK (skipped=15) 26.log:OK (skipped=15) 26.log:OK (skipped=15) 26.log:OK (skipped=2) 27.log:382 tests OK. 27.log:OK (skipped=15) 27.log:OK (skipped=2) 28.log:381 tests OK. 28.log:OK (skipped=15) 28.log:OK (skipped=15) 28.log:OK (skipped=2) 29.log:383 tests OK. 29.log:OK (skipped=2) 30.log:380 tests OK. 30.log:OK (skipped=15) 30.log:OK (skipped=15) 30.log:OK (skipped=15) 30.log:OK (skipped=2) 31.log:382 tests OK. 31.log:OK (skipped=15) 31.log:OK (skipped=2) 32.log:382 tests OK. 32.log:OK (skipped=15) 32.log:OK (skipped=2) 33.log:383 tests OK. 33.log:OK (skipped=2) 34.log:383 tests OK. 34.log:OK (skipped=2) 35.log:380 tests OK. 35.log:OK (skipped=15) 35.log:OK (skipped=15) 35.log:OK (skipped=15) 35.log:OK (skipped=2) 36.log:382 tests OK. 36.log:OK (skipped=15) 36.log:OK (skipped=2) 37.log:382 tests OK. 37.log:OK (skipped=15) 37.log:OK (skipped=2) 38.log:380 tests OK. 38.log:OK (skipped=15) 38.log:OK (skipped=15) 38.log:OK (skipped=15) 38.log:OK (skipped=2) 39.log:380 tests OK. 39.log:OK (skipped=15) 39.log:OK (skipped=15) 39.log:OK (skipped=15) 39.log:OK (skipped=2) 40.log:381 tests OK. 40.log:OK (skipped=15) 40.log:OK (skipped=15) 40.log:OK (skipped=2) 41.log:383 tests OK. 41.log:OK (skipped=2) 42.log:380 tests OK. 42.log:OK (skipped=15) 42.log:OK (skipped=15) 42.log:OK (skipped=15) 42.log:OK (skipped=2) 43.log:380 tests OK. 43.log:OK (skipped=15) 43.log:OK (skipped=15) 43.log:OK (skipped=15) 43.log:OK (skipped=2) 44.log:383 tests OK. 44.log:OK (skipped=2) 45.log:383 tests OK. 45.log:OK (skipped=2) 46.log:380 tests OK. 46.log:OK (skipped=15) 46.log:OK (skipped=15) 46.log:OK (skipped=15) 46.log:OK (skipped=2) 47.log:383 tests OK. 47.log:OK (skipped=2) 48.log:381 tests OK. 48.log:OK (skipped=15) 48.log:OK (skipped=15) 48.log:OK (skipped=2) 49.log:381 tests OK. 49.log:OK (skipped=15) 49.log:OK (skipped=15) 49.log:OK (skipped=2) 50.log:383 tests OK. 50.log:OK (skipped=2) 51.log:382 tests OK. 51.log:OK (skipped=15) 51.log:OK (skipped=2) 52.log:381 tests OK. 52.log:OK (skipped=15) 52.log:OK (skipped=15) 52.log:OK (skipped=2) 53.log:383 tests OK. 53.log:OK (skipped=2) 54.log:383 tests OK. 54.log:OK (skipped=2) 55.log:382 tests OK. 55.log:OK (skipped=15) 55.log:OK (skipped=2) 56.log:381 tests OK. 56.log:OK (skipped=15) 56.log:OK (skipped=15) 56.log:OK (skipped=2) 57.log:380 tests OK. 57.log:OK (skipped=15) 57.log:OK (skipped=15) 57.log:OK (skipped=15) 57.log:OK (skipped=2) 58.log:383 tests OK. 58.log:OK (skipped=2) 59.log:380 tests OK. 59.log:OK (skipped=15) 59.log:OK (skipped=15) 59.log:OK (skipped=15) 59.log:OK (skipped=2) 60.log:380 tests OK. 60.log:OK (skipped=15) 60.log:OK (skipped=15) 60.log:OK (skipped=15) 60.log:OK (skipped=2) 61.log:381 tests OK. 61.log:OK (skipped=15) 61.log:OK (skipped=15) 61.log:OK (skipped=2) 62.log:382 tests OK. 62.log:OK (skipped=15) 62.log:OK (skipped=2) 63.log:382 tests OK. 63.log:OK (skipped=15) 63.log:OK (skipped=2) 64.log:381 tests OK. 64.log:OK (skipped=15) 64.log:OK (skipped=15) 64.log:OK (skipped=2) 65.log:379 tests OK. 65.log:OK (skipped=15) 65.log:OK (skipped=15) 65.log:OK (skipped=15) 65.log:OK (skipped=2) 66.log:382 tests OK. 66.log:OK (skipped=15) 66.log:OK (skipped=2) 67.log:382 tests OK. 67.log:OK (skipped=15) 67.log:OK (skipped=2) 68.log:383 tests OK. 68.log:OK (skipped=2) 69.log:383 tests OK. 69.log:OK (skipped=2) 70.log:383 tests OK. 70.log:OK (skipped=2) 71.log:383 tests OK. 71.log:OK (skipped=2) 72.log:382 tests OK. 72.log:OK (skipped=15) 72.log:OK (skipped=2) 73.log:382 tests OK. 73.log:OK (skipped=15) 73.log:OK (skipped=2) 74.log:382 tests OK. 74.log:OK (skipped=2) 75.log:382 tests OK. 75.log:OK (skipped=2) 76.log:382 tests OK. 76.log:OK (skipped=15) 76.log:OK (skipped=2) 77.log:381 tests OK. 77.log:OK (skipped=15) 77.log:OK (skipped=15) 77.log:OK (skipped=2) 78.log:383 tests OK. 78.log:OK (skipped=2) 79.log:380 tests OK. 79.log:OK (skipped=15) 79.log:OK (skipped=15) 79.log:OK (skipped=15) 79.log:OK (skipped=2) 80.log:383 tests OK. 80.log:OK (skipped=2) 81.log:382 tests OK. 81.log:OK (skipped=15) 81.log:OK (skipped=2) 82.log:381 tests OK. 82.log:OK (skipped=15) 82.log:OK (skipped=15) 82.log:OK (skipped=2) 83.log:383 tests OK. 83.log:OK (skipped=2) 84.log:380 tests OK. 84.log:OK (skipped=15) 84.log:OK (skipped=15) 84.log:OK (skipped=15) 84.log:OK (skipped=2) 85.log:382 tests OK. 85.log:OK (skipped=15) 85.log:OK (skipped=2) 86.log:383 tests OK. 86.log:OK (skipped=2) 87.log:382 tests OK. 87.log:OK (skipped=15) 87.log:OK (skipped=2) 88.log:382 tests OK. 88.log:OK (skipped=15) 88.log:OK (skipped=2) 89.log:381 tests OK. 89.log:OK (skipped=15) 89.log:OK (skipped=2) 89.log:OK (skipped=37) 90.log:379 tests OK. 90.log:OK (skipped=15) 90.log:OK (skipped=15) 90.log:OK (skipped=15) 90.log:OK (skipped=2) 91.log:380 tests OK. 91.log:OK (skipped=15) 91.log:OK (skipped=15) 91.log:OK (skipped=15) 91.log:OK (skipped=2) 92.log:381 tests OK. 92.log:OK (skipped=15) 92.log:OK (skipped=15) 92.log:OK (skipped=2) 93.log:382 tests OK. 93.log:OK (skipped=2) 94.log:380 tests OK. 94.log:OK (skipped=15) 94.log:OK (skipped=15) 94.log:OK (skipped=15) 94.log:OK (skipped=2) 95.log:381 tests OK. 95.log:OK (skipped=15) 95.log:OK (skipped=15) 95.log:OK (skipped=2) 96.log:380 tests OK. 96.log:OK (skipped=15) 96.log:OK (skipped=15) 96.log:OK (skipped=15) 96.log:OK (skipped=2) 97.log:381 tests OK. 97.log:OK (skipped=15) 97.log:OK (skipped=15) 97.log:OK (skipped=2) 98.log:380 tests OK. 98.log:OK (skipped=15) 98.log:OK (skipped=15) 98.log:OK (skipped=15) 98.log:OK (skipped=2) 99.log:382 tests OK. 99.log:OK (skipped=15) 99.log:OK (skipped=2) 100.log:383 tests OK. 100.log:OK (skipped=2) 101.log:381 tests OK. 101.log:OK (skipped=15) 101.log:OK (skipped=15) 101.log:OK (skipped=2) 102.log:382 tests OK. 102.log:OK (skipped=15) 102.log:OK (skipped=2) 103.log:381 tests OK. 103.log:OK (skipped=15) 103.log:OK (skipped=2) 103.log:OK (skipped=37) 104.log:382 tests OK. 104.log:OK (skipped=2) 105.log:381 tests OK. 105.log:OK (skipped=15) 105.log:OK (skipped=15) 105.log:OK (skipped=2) 106.log:383 tests OK. 106.log:OK (skipped=2) 107.log:380 tests OK. 107.log:OK (skipped=15) 107.log:OK (skipped=15) 107.log:OK (skipped=15) 107.log:OK (skipped=2) 108.log:379 tests OK. 108.log:OK (skipped=15) 108.log:OK (skipped=15) 108.log:OK (skipped=15) 108.log:OK (skipped=2) 109.log:382 tests OK. 109.log:OK (skipped=15) 109.log:OK (skipped=2) 110.log:383 tests OK. 110.log:OK (skipped=2) 111.log:383 tests OK. 111.log:OK (skipped=2) 112.log:383 tests OK. 112.log:OK (skipped=2) 113.log:383 tests OK. 113.log:OK (skipped=2) 114.log:383 tests OK. 114.log:OK (skipped=2) 115.log:382 tests OK. 115.log:OK (skipped=15) 115.log:OK (skipped=2) 116.log:383 tests OK. 116.log:OK (skipped=2) 117.log:381 tests OK. 117.log:OK (skipped=15) 117.log:OK (skipped=15) 117.log:OK (skipped=2) 118.log:382 tests OK. 118.log:OK (skipped=15) 118.log:OK (skipped=2) 119.log:381 tests OK. 119.log:OK (skipped=15) 119.log:OK (skipped=15) 119.log:OK (skipped=2) 120.log:381 tests OK. 120.log:OK (skipped=15) 120.log:OK (skipped=15) 120.log:OK (skipped=2) 121.log:382 tests OK. 121.log:OK (skipped=15) 121.log:OK (skipped=2) 122.log:381 tests OK. 122.log:OK (skipped=15) 122.log:OK (skipped=15) 122.log:OK (skipped=2) 123.log:382 tests OK. 123.log:OK (skipped=15) 123.log:OK (skipped=2) 124.log:382 tests OK. 124.log:OK (skipped=15) 124.log:OK (skipped=2) 125.log:382 tests OK. 125.log:OK (skipped=15) 125.log:OK (skipped=2) 126.log:383 tests OK. 126.log:OK (skipped=2) 127.log:380 tests OK. 127.log:OK (skipped=15) 127.log:OK (skipped=15) 127.log:OK (skipped=15) 127.log:OK (skipped=2) 128.log:383 tests OK. 128.log:OK (skipped=2) 129.log:380 tests OK. 129.log:OK (skipped=15) 129.log:OK (skipped=15) 129.log:OK (skipped=15) 129.log:OK (skipped=2) 130.log:380 tests OK. 130.log:OK (skipped=15) 130.log:OK (skipped=15) 130.log:OK (skipped=15) 130.log:OK (skipped=2) 131.log:381 tests OK. 131.log:OK (skipped=15) 131.log:OK (skipped=15) 131.log:OK (skipped=2) 132.log:381 tests OK. 132.log:OK (skipped=2) 132.log:OK (skipped=37) 133.log:382 tests OK. 133.log:OK (skipped=2) 134.log:380 tests OK. 134.log:OK (skipped=15) 134.log:OK (skipped=15) 134.log:OK (skipped=15) 134.log:OK (skipped=2) 135.log:382 tests OK. 135.log:OK (skipped=2) 135.log:OK (skipped=39) 136.log:380 tests OK. 136.log:OK (skipped=15) 136.log:OK (skipped=15) 136.log:OK (skipped=15) 136.log:OK (skipped=2) 137.log:383 tests OK. 137.log:OK (skipped=2) 138.log:381 tests OK. 138.log:OK (skipped=15) 138.log:OK (skipped=15) 138.log:OK (skipped=2) 139.log:383 tests OK. 139.log:OK (skipped=2) 140.log:383 tests OK. 140.log:OK (skipped=2) 141.log:382 tests OK. 141.log:OK (skipped=15) 141.log:OK (skipped=2) 142.log:380 tests OK. 142.log:OK (skipped=15) 142.log:OK (skipped=15) 142.log:OK (skipped=15) 142.log:OK (skipped=2) 143.log:380 tests OK. 143.log:OK (skipped=15) 143.log:OK (skipped=15) 143.log:OK (skipped=15) 143.log:OK (skipped=2) 144.log:380 tests OK. 144.log:OK (skipped=15) 144.log:OK (skipped=15) 144.log:OK (skipped=15) 144.log:OK (skipped=2) 145.log:380 tests OK. 145.log:OK (skipped=15) 145.log:OK (skipped=15) 145.log:OK (skipped=15) 145.log:OK (skipped=2) 146.log:382 tests OK. 146.log:OK (skipped=15) 146.log:OK (skipped=2) 147.log:382 tests OK. 147.log:OK (skipped=15) 147.log:OK (skipped=2) 148.log:381 tests OK. 148.log:OK (skipped=15) 148.log:OK (skipped=15) 148.log:OK (skipped=2) 149.log:382 tests OK. 149.log:OK (skipped=15) 149.log:OK (skipped=2) 150.log:380 tests OK. 150.log:OK (skipped=15) 150.log:OK (skipped=15) 150.log:OK (skipped=15) 150.log:OK (skipped=2) 151.log:381 tests OK. 151.log:OK (skipped=15) 151.log:OK (skipped=15) 151.log:OK (skipped=2) 152.log:383 tests OK. 152.log:OK (skipped=2) 153.log:381 tests OK. 153.log:OK (skipped=15) 153.log:OK (skipped=15) 153.log:OK (skipped=2) 154.log:382 tests OK. 154.log:OK (skipped=15) 154.log:OK (skipped=2) 155.log:381 tests OK. 155.log:OK (skipped=15) 155.log:OK (skipped=15) 155.log:OK (skipped=2) 156.log:383 tests OK. 156.log:OK (skipped=2) 157.log:380 tests OK. 157.log:OK (skipped=15) 157.log:OK (skipped=15) 157.log:OK (skipped=15) 157.log:OK (skipped=2) 158.log:381 tests OK. 158.log:OK (skipped=15) 158.log:OK (skipped=15) 158.log:OK (skipped=2) 159.log:382 tests OK. 159.log:OK (skipped=15) 159.log:OK (skipped=2) 160.log:382 tests OK. 160.log:OK (skipped=15) 160.log:OK (skipped=2) 161.log:381 tests OK. 161.log:OK (skipped=15) 161.log:OK (skipped=15) 161.log:OK (skipped=2) 162.log:383 tests OK. 162.log:OK (skipped=2) 163.log:383 tests OK. 163.log:OK (skipped=2) 164.log:383 tests OK. 164.log:OK (skipped=2) 165.log:381 tests OK. 165.log:OK (skipped=15) 165.log:OK (skipped=15) 165.log:OK (skipped=2) 166.log:383 tests OK. 166.log:OK (skipped=2) 167.log:382 tests OK. 167.log:OK (skipped=15) 167.log:OK (skipped=2) 168.log:383 tests OK. 168.log:OK (skipped=2) 169.log:380 tests OK. 169.log:OK (skipped=15) 169.log:OK (skipped=15) 169.log:OK (skipped=15) 169.log:OK (skipped=2) 170.log:380 tests OK. 170.log:OK (skipped=15) 170.log:OK (skipped=15) 170.log:OK (skipped=15) 170.log:OK (skipped=2) 171.log:383 tests OK. 171.log:OK (skipped=2) 172.log:382 tests OK. 172.log:OK (skipped=15) 172.log:OK (skipped=2) 173.log:381 tests OK. 173.log:OK (skipped=15) 173.log:OK (skipped=15) 173.log:OK (skipped=2) 174.log:380 tests OK. 174.log:OK (skipped=15) 174.log:OK (skipped=15) 174.log:OK (skipped=15) 174.log:OK (skipped=2) 175.log:381 tests OK. 175.log:OK (skipped=15) 175.log:OK (skipped=15) 175.log:OK (skipped=2) 176.log:380 tests OK. 176.log:OK (skipped=15) 176.log:OK (skipped=15) 176.log:OK (skipped=15) 176.log:OK (skipped=2) 177.log:382 tests OK. 177.log:OK (skipped=15) 177.log:OK (skipped=2) 178.log:381 tests OK. 178.log:OK (skipped=15) 178.log:OK (skipped=15) 178.log:OK (skipped=2) 179.log:381 tests OK. 179.log:OK (skipped=15) 179.log:OK (skipped=15) 179.log:OK (skipped=2) 180.log:381 tests OK. 180.log:OK (skipped=15) 180.log:OK (skipped=15) 180.log:OK (skipped=2) 181.log:382 tests OK. 181.log:OK (skipped=15) 181.log:OK (skipped=2) 182.log:381 tests OK. 182.log:OK (skipped=15) 182.log:OK (skipped=15) 182.log:OK (skipped=2) 183.log:380 tests OK. 183.log:OK (skipped=15) 183.log:OK (skipped=15) 183.log:OK (skipped=15) 183.log:OK (skipped=2) 184.log:381 tests OK. 184.log:OK (skipped=15) 184.log:OK (skipped=15) 184.log:OK (skipped=2) 185.log:381 tests OK. 185.log:OK (skipped=15) 185.log:OK (skipped=15) 185.log:OK (skipped=2) 186.log:380 tests OK. 186.log:OK (skipped=15) 186.log:OK (skipped=15) 186.log:OK (skipped=15) 186.log:OK (skipped=2) 187.log:380 tests OK. 187.log:OK (skipped=15) 187.log:OK (skipped=15) 187.log:OK (skipped=15) 187.log:OK (skipped=2) 188.log:382 tests OK. 188.log:OK (skipped=15) 188.log:OK (skipped=2) 189.log:380 tests OK. 189.log:OK (skipped=15) 189.log:OK (skipped=15) 189.log:OK (skipped=15) 189.log:OK (skipped=2) 190.log:383 tests OK. 190.log:OK (skipped=2) 191.log:380 tests OK. 191.log:OK (skipped=15) 191.log:OK (skipped=15) 191.log:OK (skipped=15) 191.log:OK (skipped=2) 192.log:382 tests OK. 192.log:OK (skipped=15) 192.log:OK (skipped=2) 193.log:383 tests OK. 193.log:OK (skipped=2) 194.log:382 tests OK. 194.log:OK (skipped=2) 195.log:383 tests OK. 195.log:OK (skipped=2) 196.log:383 tests OK. 196.log:OK (skipped=2) 197.log:382 tests OK. 197.log:OK (skipped=15) 197.log:OK (skipped=2) 198.log:380 tests OK. 198.log:OK (skipped=15) 198.log:OK (skipped=15) 198.log:OK (skipped=15) 198.log:OK (skipped=2) 199.log:380 tests OK. 199.log:OK (skipped=15) 199.log:OK (skipped=15) 199.log:OK (skipped=15) 199.log:OK (skipped=2) 200.log:380 tests OK. 200.log:OK (skipped=15) 200.log:OK (skipped=15) 200.log:OK (skipped=15) 200.log:OK (skipped=2) 201.log:382 tests OK. 201.log:OK (skipped=15) 201.log:OK (skipped=2) 202.log:380 tests OK. 202.log:OK (skipped=15) 202.log:OK (skipped=15) 202.log:OK (skipped=15) 202.log:OK (skipped=2) 203.log:380 tests OK. 203.log:OK (skipped=15) 203.log:OK (skipped=15) 203.log:OK (skipped=15) 203.log:OK (skipped=2) 204.log:382 tests OK. 204.log:OK (skipped=15) 204.log:OK (skipped=2) 205.log:382 tests OK. 205.log:OK (skipped=15) 205.log:OK (skipped=2) 206.log:379 tests OK. 206.log:OK (skipped=15) 206.log:OK (skipped=15) 206.log:OK (skipped=15) 206.log:OK (skipped=2) 207.log:382 tests OK. 207.log:OK (skipped=15) 207.log:OK (skipped=2) 208.log:382 tests OK. 208.log:OK (skipped=15) 208.log:OK (skipped=2) 209.log:383 tests OK. 209.log:OK (skipped=2) 210.log:383 tests OK. 210.log:OK (skipped=2) 211.log:382 tests OK. 211.log:OK (skipped=2) 211.log:OK (skipped=39) 212.log:380 tests OK. 212.log:OK (skipped=15) 212.log:OK (skipped=15) 212.log:OK (skipped=15) 212.log:OK (skipped=2) 213.log:382 tests OK. 213.log:OK (skipped=15) 213.log:OK (skipped=2) 214.log:382 tests OK. 214.log:OK (skipped=15) 214.log:OK (skipped=2) 215.log:382 tests OK. 215.log:OK (skipped=15) 215.log:OK (skipped=2) 216.log:383 tests OK. 216.log:OK (skipped=2) 217.log:381 tests OK. 217.log:OK (skipped=15) 217.log:OK (skipped=15) 217.log:OK (skipped=2) 218.log:382 tests OK. 218.log:OK (skipped=15) 218.log:OK (skipped=2) 219.log:382 tests OK. 219.log:OK (skipped=15) 219.log:OK (skipped=2) 220.log:382 tests OK. 220.log:OK (skipped=15) 220.log:OK (skipped=2) 221.log:382 tests OK. 221.log:OK (skipped=15) 221.log:OK (skipped=2) 222.log:383 tests OK. 222.log:OK (skipped=2) 223.log:382 tests OK. 223.log:OK (skipped=15) 223.log:OK (skipped=2) 224.log:381 tests OK. 224.log:OK (skipped=15) 224.log:OK (skipped=15) 224.log:OK (skipped=2) 225.log:382 tests OK. 225.log:OK (skipped=15) 225.log:OK (skipped=2) 226.log:380 tests OK. 226.log:OK (skipped=15) 226.log:OK (skipped=15) 226.log:OK (skipped=15) 226.log:OK (skipped=2) 227.log:381 tests OK. 227.log:OK (skipped=15) 227.log:OK (skipped=15) 227.log:OK (skipped=2) 228.log:383 tests OK. 228.log:OK (skipped=2) 229.log:382 tests OK. 229.log:OK (skipped=15) 229.log:OK (skipped=2) 230.log:381 tests OK. 230.log:OK (skipped=15) 230.log:OK (skipped=15) 230.log:OK (skipped=2) 231.log:382 tests OK. 231.log:OK (skipped=15) 231.log:OK (skipped=2) 232.log:381 tests OK. 232.log:OK (skipped=15) 232.log:OK (skipped=15) 232.log:OK (skipped=2) 233.log:382 tests OK. 233.log:OK (skipped=15) 233.log:OK (skipped=2) 234.log:382 tests OK. 234.log:OK (skipped=15) 234.log:OK (skipped=2) 235.log:382 tests OK. 235.log:OK (skipped=2) 235.log:OK (skipped=37) 236.log:381 tests OK. 236.log:OK (skipped=15) 236.log:OK (skipped=15) 236.log:OK (skipped=2) 237.log:383 tests OK. 237.log:OK (skipped=2) 238.log:381 tests OK. 238.log:OK (skipped=15) 238.log:OK (skipped=15) 238.log:OK (skipped=2) 239.log:381 tests OK. 239.log:OK (skipped=15) 239.log:OK (skipped=15) 239.log:OK (skipped=2) 240.log:381 tests OK. 240.log:OK (skipped=15) 240.log:OK (skipped=15) 240.log:OK (skipped=2) 241.log:381 tests OK. 241.log:OK (skipped=15) 241.log:OK (skipped=15) 241.log:OK (skipped=2) 242.log:380 tests OK. 242.log:OK (skipped=15) 242.log:OK (skipped=15) 242.log:OK (skipped=15) 242.log:OK (skipped=2) 243.log:382 tests OK. 243.log:OK (skipped=15) 243.log:OK (skipped=2) 244.log:381 tests OK. 244.log:OK (skipped=15) 244.log:OK (skipped=15) 244.log:OK (skipped=2) 245.log:380 tests OK. 245.log:OK (skipped=15) 245.log:OK (skipped=15) 245.log:OK (skipped=15) 245.log:OK (skipped=2) 246.log:380 tests OK. 246.log:OK (skipped=15) 246.log:OK (skipped=15) 246.log:OK (skipped=15) 246.log:OK (skipped=2) 247.log:380 tests OK. 247.log:OK (skipped=15) 247.log:OK (skipped=15) 247.log:OK (skipped=15) 247.log:OK (skipped=2) 248.log:380 tests OK. 248.log:OK (skipped=15) 248.log:OK (skipped=15) 248.log:OK (skipped=15) 248.log:OK (skipped=2) 249.log:381 tests OK. 249.log:OK (skipped=15) 249.log:OK (skipped=15) 249.log:OK (skipped=2) 250.log:380 tests OK. 250.log:OK (skipped=15) 250.log:OK (skipped=15) 250.log:OK (skipped=15) 250.log:OK (skipped=2) 251.log:383 tests OK. 251.log:OK (skipped=2) 252.log:383 tests OK. 252.log:OK (skipped=2) 253.log:383 tests OK. 253.log:OK (skipped=2) 254.log:382 tests OK. 254.log:OK (skipped=2) 254.log:OK (skipped=37) 255.log:379 tests OK. 255.log:OK (skipped=15) 255.log:OK (skipped=15) 255.log:OK (skipped=15) 255.log:OK (skipped=2) 255.log:OK (skipped=37) From katewinslet626 at gmail.com Sun Sep 20 03:55:50 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Sun, 20 Sep 2015 00:55:50 -0700 (PDT) Subject: for loop Message-ID: <876f56d8-0c57-4158-a75c-5f3cd6bcbcc5@googlegroups.com> https://ideone.com/BPflPk Please tell me why 'print s' statement is being executed inside loop, though I put it outside. Please help. I am new to python. From kwpolska at gmail.com Sun Sep 20 04:03:36 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Sun, 20 Sep 2015 10:03:36 +0200 Subject: for loop In-Reply-To: <876f56d8-0c57-4158-a75c-5f3cd6bcbcc5@googlegroups.com> References: <876f56d8-0c57-4158-a75c-5f3cd6bcbcc5@googlegroups.com> Message-ID: On 20 September 2015 at 09:55, shiva upreti wrote: > https://ideone.com/BPflPk > > Please tell me why 'print s' statement is being executed inside loop, though I put it outside. > Please help. I am new to python. > -- > https://mail.python.org/mailman/listinfo/python-list You have mixed indentation. Your code contains both tabs and spaces. Python interprets tabs as 8 spaces, while your other indentation is 4 spaces, leading to bad parsing. Please make sure you use only spaces (reconfigure your editor to always insert 4 spaces and reindent everything with tabs) -- Chris Warrick PGP: 5EAAEA16 From paul.anton.letnes at gmail.com Sun Sep 20 04:04:22 2015 From: paul.anton.letnes at gmail.com (paul.anton.letnes at gmail.com) Date: Sun, 20 Sep 2015 01:04:22 -0700 (PDT) Subject: for loop In-Reply-To: <876f56d8-0c57-4158-a75c-5f3cd6bcbcc5@googlegroups.com> References: <876f56d8-0c57-4158-a75c-5f3cd6bcbcc5@googlegroups.com> Message-ID: <4bae6ac5-40c3-4613-997b-a4a95941af5a@googlegroups.com> On Sunday, September 20, 2015 at 9:56:06 AM UTC+2, shiva upreti wrote: > https://ideone.com/BPflPk > > Please tell me why 'print s' statement is being executed inside loop, though I put it outside. > Please help. I am new to python. Hi! Welcome to python, the most awesome programming language! The code you pasted used both spaces and tabs for indentation. The thing is that python, by default, interprets one tab character as 8 spaces, but the editor you've used shows it as 4 spaces. To avoid these kinds of headaches, I always 1) set my editor to show tabs, so I can detect them, and 2) never use tabs when I write code myself. I set my editor to insert 4 spaces whenever I hit the "tab" key on my keyboard. If you post the name of your editor, maybe someone knows how to do that in yours. You can also detect mixed space/tab issues by running "python -t" instead of just "python". So, your "print s" is in fact inside the loop, since the for loop is indented with 4 spaces, and "print s" is indented with 1 tab = 8 spaces. It just doesn't look like that to you. It looks like you're coding in python 2. If you're new to python, I'd recommend using a python 3 version, maybe 3.4 or 3.5. You can easily pick up python 2 later if you need to maintain old code. Of course, it's not a big deal learning python 3 if you know python 2 either, but why spend energy on it? Cheers Paul From katewinslet626 at gmail.com Sun Sep 20 04:39:17 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Sun, 20 Sep 2015 01:39:17 -0700 (PDT) Subject: for loop In-Reply-To: References: <876f56d8-0c57-4158-a75c-5f3cd6bcbcc5@googlegroups.com> Message-ID: On Sunday, September 20, 2015 at 1:33:57 PM UTC+5:30, Chris Warrick wrote: > On 20 September 2015 at 09:55, shiva upreti wrote: > > https://ideone.com/BPflPk > > > > Please tell me why 'print s' statement is being executed inside loop, though I put it outside. > > Please help. I am new to python. > > -- > > https://mail.python.org/mailman/listinfo/python-list > > You have mixed indentation. Your code contains both tabs and spaces. > Python interprets tabs as 8 spaces, while your other indentation is 4 > spaces, leading to bad parsing. > > Please make sure you use only spaces (reconfigure your editor to > always insert 4 spaces and reindent everything with tabs) > > -- > Chris Warrick > PGP: 5EAAEA16 Thanks. It works fine now.:) From katewinslet626 at gmail.com Sun Sep 20 04:39:47 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Sun, 20 Sep 2015 01:39:47 -0700 (PDT) Subject: for loop In-Reply-To: <4bae6ac5-40c3-4613-997b-a4a95941af5a@googlegroups.com> References: <876f56d8-0c57-4158-a75c-5f3cd6bcbcc5@googlegroups.com> <4bae6ac5-40c3-4613-997b-a4a95941af5a@googlegroups.com> Message-ID: On Sunday, September 20, 2015 at 1:34:32 PM UTC+5:30, paul.ant... at gmail.com wrote: > On Sunday, September 20, 2015 at 9:56:06 AM UTC+2, shiva upreti wrote: > > https://ideone.com/BPflPk > > > > Please tell me why 'print s' statement is being executed inside loop, though I put it outside. > > Please help. I am new to python. > > Hi! > > Welcome to python, the most awesome programming language! > > The code you pasted used both spaces and tabs for indentation. The thing is that python, by default, interprets one tab character as 8 spaces, but the editor you've used shows it as 4 spaces. To avoid these kinds of headaches, I always 1) set my editor to show tabs, so I can detect them, and 2) never use tabs when I write code myself. I set my editor to insert 4 spaces whenever I hit the "tab" key on my keyboard. If you post the name of your editor, maybe someone knows how to do that in yours. You can also detect mixed space/tab issues by running "python -t" instead of just "python". > > So, your "print s" is in fact inside the loop, since the for loop is indented with 4 spaces, and "print s" is indented with 1 tab = 8 spaces. It just doesn't look like that to you. > > It looks like you're coding in python 2. If you're new to python, I'd recommend using a python 3 version, maybe 3.4 or 3.5. You can easily pick up python 2 later if you need to maintain old code. Of course, it's not a big deal learning python 3 if you know python 2 either, but why spend energy on it? > > Cheers > Paul Thanks.:) I use gedit in ubuntu 1 From __peter__ at web.de Sun Sep 20 04:58:53 2015 From: __peter__ at web.de (Peter Otten) Date: Sun, 20 Sep 2015 10:58:53 +0200 Subject: Ordering dependent test failures References: <2663735f-f237-4ed4-ab41-e9068041358b@googlegroups.com> Message-ID: paul.anton.letnes at gmail.com wrote: > Fascinated by the concept of ordering dependent test failures [0], I've > run the python test suite [1] with 256 different random seeds (took a > little more than 12 hours). The results vary a lot - for instance, the > number of tests reported as OK varies, the number of skips varies, etc. > Since I'm not sure how to report or interpret them, I'll just post a > summary below. > > The test suite was run on arch linux [2] with gcc 5.2.0, with the source > code taken from a clone of the python repo yesterday [3]. > > What could I do with all this in order to make more sense of it, and could > it be of any help what so ever to python development? I'll gladly make the > full log files available to whomever is interested, in whatever format is > convenient. In the meantime I'll run more random seeds, because why not. Given that the most likely interference is between two tests instead of the shotgun approach you could run the unit tests in such a way that for any pair of tests a, b the tests are run at least once with a before b and with a after b. Assuming that a test c does not "destroy" the interference when run between a and b for three tests this could be achieved with 1 abc covers ab, ac, bc 2 cba covers ba, ca, cb If b fails in run 1 you'll assume a to be the culprit. If c fails in run 1 you'll follow up with 1.1 ac 1.2 bc to identify the predecessor causing the failure. Of course there are some complications, e. g. - Neither 1.1 nor 1.2 or both may fail - The typical test suite comprises more than three tests - Should the sequence aa be covered, i. e. a test case interfering with itself? From james.harris.1 at gmail.com Sun Sep 20 06:22:03 2015 From: james.harris.1 at gmail.com (James Harris) Date: Sun, 20 Sep 2015 11:22:03 +0100 Subject: Lightwight socket IO wrapper Message-ID: I guess there have been many attempts to make socket IO easier to handle and a good number of those have been in Python. The trouble with trying to improve something which is already well designed (and conciously left as is) is that the so-called improvement can become much more complex and overly elaborate. That can apply to the initial idea, for sure, but when writing helper or convenience functions perhaps it applies more to the temptation to keep adding just a little bit extra. The end result can be overly elaborate such as a framework which is fine where such is needed but is overkill for simpler requirements. Do you guys have any recommendations of some *lightweight* additions to Python socket IO before I write any more of my own? Something built in to Python would be much preferred over any modules which have to be added. I had in the back of my mind that there was a high-level socket-IO library - much as threading was added as a wrapper to the basic thread module - but I cannot find anything above socket. Is there any? A current specific to illustrate where basic socket IO is limited: it normally provides no guarantees over how many bytes are transferred at a time (AFAICS that's true for both streams and datagrams) so the delimiting of messages/records needs to be handled by the sender and receiver. I do already handle some of this myself but I wondered if there was a prebuilt solution that I should be using instead - to save me adding just a little bit extra. ;-) James From jon+usenet at unequivocal.co.uk Sun Sep 20 08:45:47 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Sun, 20 Sep 2015 12:45:47 +0000 (UTC) Subject: ConnectionError handling problem References: Message-ID: On 2015-09-19, Mark Lawrence wrote: > On 19/09/2015 07:13, shiva upreti wrote: >> try: >> r=requests.post(url, data=query_args) >> except: >> print "Connection error" > > Never use a bare except in Python, always handle the bare minimum number > of exceptions that you need to, in this case your ConnectionError. While I entirely agree with the principle of being specific in what exceptions you are catching (with the absolute maximum being 'Exception'), it is often not obvious which ones you need to specify. The code above probably actually needs to catch EnvironmentError if it is intended to intercept all network problems. From breamoreboy at yahoo.co.uk Sun Sep 20 09:13:21 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 20 Sep 2015 14:13:21 +0100 Subject: ConnectionError handling problem In-Reply-To: References: Message-ID: On 20/09/2015 13:45, Jon Ribbens wrote: > On 2015-09-19, Mark Lawrence wrote: >> On 19/09/2015 07:13, shiva upreti wrote: >>> try: >>> r=requests.post(url, data=query_args) >>> except: >>> print "Connection error" >> >> Never use a bare except in Python, always handle the bare minimum number >> of exceptions that you need to, in this case your ConnectionError. > > While I entirely agree with the principle of being specific in what > exceptions you are catching (with the absolute maximum being > 'Exception'), it is often not obvious which ones you need to specify. > The code above probably actually needs to catch EnvironmentError if > it is intended to intercept all network problems. > I doubt it, as from the docs "The following exceptions are kept for compatibility with previous versions; starting from Python 3.3, they are aliases of OSError.". EnvironmentError is one of those listed. I'd have thought it far more likely that you'd want to catch one or more of the OSError subclasses, as finer grained exceptions was part of the rationale behind PEP 3151 -- Reworking the OS and IO exception hierarchy. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From 4kir4.1i at gmail.com Sun Sep 20 09:15:07 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Sun, 20 Sep 2015 16:15:07 +0300 Subject: Lightwight socket IO wrapper References: Message-ID: <87pp1d2pwk.fsf@gmail.com> "James Harris" writes: > I guess there have been many attempts to make socket IO easier to > handle and a good number of those have been in Python. > > The trouble with trying to improve something which is already well > designed (and conciously left as is) is that the so-called improvement > can become much more complex and overly elaborate. That can apply to > the initial idea, for sure, but when writing helper or convenience > functions perhaps it applies more to the temptation to keep adding > just a little bit extra. The end result can be overly elaborate such > as a framework which is fine where such is needed but is overkill for > simpler requirements. > > Do you guys have any recommendations of some *lightweight* additions > to Python socket IO before I write any more of my own? Something built > in to Python would be much preferred over any modules which have to be > added. I had in the back of my mind that there was a high-level > socket-IO library - much as threading was added as a wrapper to the > basic thread module - but I cannot find anything above socket. Is > there any? Does ?MQ qualify as lightweight? > A current specific to illustrate where basic socket IO is limited: it > normally provides no guarantees over how many bytes are transferred at > a time (AFAICS that's true for both streams and datagrams) so the > delimiting of messages/records needs to be handled by the sender and > receiver. I do already handle some of this myself but I wondered if > there was a prebuilt solution that I should be using instead - to save > me adding just a little bit extra. ;-) There are already convenience functions in stdlib such as sock.sendall(), sock.sendfile(), socket.create_connection() in addition to BSD Sockets API. If you want to extend this list and have specific suggestions; see https://docs.python.org/devguide/stdlibchanges.html Or just describe your current specific issue in more detail here. From rosuav at gmail.com Sun Sep 20 09:25:58 2015 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 20 Sep 2015 23:25:58 +1000 Subject: ConnectionError handling problem In-Reply-To: References: Message-ID: On Sun, Sep 20, 2015 at 10:45 PM, Jon Ribbens wrote: > On 2015-09-19, Mark Lawrence wrote: >> On 19/09/2015 07:13, shiva upreti wrote: >>> try: >>> r=requests.post(url, data=query_args) >>> except: >>> print "Connection error" >> >> Never use a bare except in Python, always handle the bare minimum number >> of exceptions that you need to, in this case your ConnectionError. > > While I entirely agree with the principle of being specific in what > exceptions you are catching (with the absolute maximum being > 'Exception'), it is often not obvious which ones you need to specify. > The code above probably actually needs to catch EnvironmentError if > it is intended to intercept all network problems. General principle: If you don't know what you should be catching, _catch nothing_. Anything that happens will get printed to the console. Then when you find that something's getting thrown, you check out what its name is, and maybe what its superclasses are (in case there's a broader one worth catching), and only THEN do you stick in a try/except. ChrisA From jon+usenet at unequivocal.co.uk Sun Sep 20 09:28:51 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Sun, 20 Sep 2015 13:28:51 +0000 (UTC) Subject: ConnectionError handling problem References: Message-ID: On 2015-09-20, Mark Lawrence wrote: > On 20/09/2015 13:45, Jon Ribbens wrote: >> On 2015-09-19, Mark Lawrence wrote: >>> On 19/09/2015 07:13, shiva upreti wrote: >>>> try: >>>> r=requests.post(url, data=query_args) >>>> except: >>>> print "Connection error" >>> >>> Never use a bare except in Python, always handle the bare minimum number >>> of exceptions that you need to, in this case your ConnectionError. >> >> While I entirely agree with the principle of being specific in what >> exceptions you are catching (with the absolute maximum being >> 'Exception'), it is often not obvious which ones you need to specify. >> The code above probably actually needs to catch EnvironmentError if >> it is intended to intercept all network problems. > > I doubt it, as from the docs "The following exceptions are kept for > compatibility with previous versions; starting from Python 3.3, they are > aliases of OSError.". EnvironmentError is one of those listed. I'd > have thought it far more likely that you'd want to catch one or more of > the OSError subclasses, as finer grained exceptions was part of the > rationale behind PEP 3151 -- Reworking the OS and IO exception hierarchy. PEP 3151 has nothing to do with it, as the code in question in this thread is running under Python 2 not Python 3. If you catch only OSError then you will miss almost all the likely exceptions raised by requests. From jon+usenet at unequivocal.co.uk Sun Sep 20 09:33:06 2015 From: jon+usenet at unequivocal.co.uk (Jon Ribbens) Date: Sun, 20 Sep 2015 13:33:06 +0000 (UTC) Subject: ConnectionError handling problem References: Message-ID: On 2015-09-20, Chris Angelico wrote: > On Sun, Sep 20, 2015 at 10:45 PM, Jon Ribbens > wrote: >> On 2015-09-19, Mark Lawrence wrote: >>> On 19/09/2015 07:13, shiva upreti wrote: >>>> try: >>>> r=requests.post(url, data=query_args) >>>> except: >>>> print "Connection error" >>> >>> Never use a bare except in Python, always handle the bare minimum number >>> of exceptions that you need to, in this case your ConnectionError. >> >> While I entirely agree with the principle of being specific in what >> exceptions you are catching (with the absolute maximum being >> 'Exception'), it is often not obvious which ones you need to specify. >> The code above probably actually needs to catch EnvironmentError if >> it is intended to intercept all network problems. > > General principle: If you don't know what you should be catching, > _catch nothing_. Anything that happens will get printed to the > console. Then when you find that something's getting thrown, you check > out what its name is, and maybe what its superclasses are (in case > there's a broader one worth catching), and only THEN do you stick in a > try/except. I'm afraid I think that's absolutely terrible advice. I agree that you should not be afraid to let exceptions propagate up the stack (one of the things that's disastrously wrong about Java) but the case at hand of "try and fetch this network resource and then do something if it didn't succeed" is perfectly reasonable, and trying to code that by trial and error is a perfect example of bad programming. From lac at openend.se Sun Sep 20 10:40:13 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 20 Sep 2015 16:40:13 +0200 Subject: ConnectionError handling problem In-Reply-To: References: Message-ID: <201509201440.t8KEeDVZ016026@fido.openend.se> The discussion about why or why not to use a bare except has gotten us away from the problem reported, which is "why is my script hanging?" In a message of Sat, 19 Sep 2015 17:18:12 +0100, Mark Lawrence writes: >> I am learning python. I wrote a script using requests module. >> The scripts runs fine for sometime, but after a while it hangs. When I press CTRL+C it shows ConnectionError even though I have included exception handling. >> I am not sure as to why it cant handle ConnectionError when the script runs for a long time. >> >> This is a part(causing issues) of the script I am running: >> >> while(k<46656): >> j=res[k] >> url="http://172.16.68.6:8090/login.xml" >> query_args = {'mode':'191', 'username':str(i), 'password':str(j), 'a':'1442397582010', 'producttype':'0'} >> >> try: >> r=requests.post(url, data=query_args) >> except: >> print "Connection error" >> time.sleep(30) >> continue >> >> html=r.text >> if(len(html) < 10): >> continue >> >> if("The system could not log you on" not in html): >> print "hello" >> filehandle=open("ids", "a") >> filehandle.write(str(i)+'\n') >> filehandle.write(str(j)+'\n') >> filehandle.close() >> break >> >> k=k+1 >> >> Any help will be highly appreciated. So, when it hangs there are two main problems you can have. One sort is that the other side, http://172.16.68.6:8090/ it in itself configured to only let people use a connection for a certain amount of time. If you are using it for longer, it will disconnect you. Or the other sort is that the other side disconnects people who have been silent for a certain amount of time. If you haven't send anything for a certain amount of time it will log you off. There are lots of other things that work this way -- the system may see many attempts to login and think you are trying to break into the system, the machine may have crashed ... but the bottom line is that the reason your script hangs is that there is nobody there on the other end. The other sort of problem you can have is that the other end is alive and well and talking to you, but you don't understand what you are getting, and you are ignoring things you don't understand. This can look exactly the same. To find out what is going on you need to log what it is that you are getting, to see if the answer is 'nothing' or 'garbage'. Laura From eryksun at gmail.com Sun Sep 20 10:53:12 2015 From: eryksun at gmail.com (eryksun) Date: Sun, 20 Sep 2015 09:53:12 -0500 Subject: .bat file trouble. In-Reply-To: References: Message-ID: On 9/18/15, Christian Gollwitzer wrote: > Am 18.09.15 um 11:06 schrieb bobertini at googlemail.com: > >> We originally thought that it was because it was missing the files: >> process_init.py and process_global_variables.py however they are >> right there in the same directory. > > Concerning that, windows usually runs a .bat file in the directory where > it is situated, so putting the python fies there /should/ work, but you > can also set this using the right-click menu (execute in...), if you > make a link to the desktop. It's fragile to depend on being started by Explorer or a shell link. For example, if the batch is run from an existing cmd shell, then it runs with cmd's current working directory. Or another process could run the batch file with a different working directory. If you actually want the batch to find the scripts relative to its own directory, then it should use the %0 environment variable, which references the fully-qualified path of the batch file. Getting just the directory, i.e. its [d]rive and [p]ath, is expressed as %~dp0. Note that this path includes a trailing backslash. From skybuck2000 at hotmail.com Sun Sep 20 11:03:31 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Sun, 20 Sep 2015 17:03:31 +0200 Subject: Dummy Decoder Example (was Re: Parallel decoding lesson for you.) In-Reply-To: <6d8e8$55fec8fa$d47876e2$62254@news.ziggo.nl> References: <62ee4$55f9719c$d47876e2$58812@news.ziggo.nl> <98c6d$55fd6d25$d47876e2$35825@news.ziggo.nl> <80671$55fd6f0a$d47876e2$43083@news.ziggo.nl> <6da10$55fd7ac4$d47876e2$19200@news.ziggo.nl> <72397$55fd7db9$d47876e2$29766@news.ziggo.nl> <9aca0$55fd863e$d47876e2$56488@news.ziggo.nl> <39418$55fd8fac$d47876e2$21797@news.ziggo.nl> <9f6cc$55fd9981$d47876e2$58134@news.ziggo.nl> <109e3$55fda507$d47876e2$30929@news.ziggo.nl> <5d560$55fda6eb$d47876e2$37866@news.ziggo.nl> <956248d4-2f8c-475b-8e41-533370589170@googlegroups.com> <4fe26$55fe0126$d47876e2$49025@news.ziggo.nl> <9c80f$55feb011$d47876e2$2668@news.ziggo.nl> <6d8e8$55fec8fa$d47876e2$62254@news.ziggo.nl> Message-ID: Since more people might be interested in this I will re-post this a second time to include more newsgroups... those two threads will need to be followed if all responses are to be seen ;) Here is your dummy decoder example: Let's turn this into a somewhat of a contest and ofcourse also teaching lesson... now I am a true teacher... I provided you with most of the code. The code you will need to write yourself/replace is indicated by // *** Good luck and may the force be with you ! Ofcourse as announced earlier on 29 september 2015 I will reveal my parallel solution to all of you ! So you have now 9 days to come up with your own solution before I publish mine ! ;) =D For those that missed the start/most of this thread, try googling for comp.arch and "Parallel decoding lesson for you" by Skybuck. // Begin of Dummy Decoder Example program TestProgram; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; function Constrain( Para : integer ) : integer; begin result := Para; if Para < 0 then Result := 0; if Para >= 1 then Result := 1; end; procedure Main; // must put variables here otherwise won't show up in debugger. var // information stream, input Stream : array[0..20] of integer; // bits representing fields of data a1,a2,a3,a4 : integer; b1,b2,b3 : integer; c1 : integer; d1,d2,d3,d4,d5,d6 : integer; // output RowIndex : integer; RowCount : integer; RowLength : array[0..5] of integer; RowOffset : array[0..5] of integer; DataOffset : integer; FieldCount : integer; FieldLength : array[0..3] of integer; Processor : array[0..3] of integer; // debug fields FieldA : integer; FieldB : integer; FieldC : integer; FieldD : integer; begin a1 := 1; a2 := 1; a3:= 1; a4 := 1; b1 := 1; b2 := 1; b3 := 1; c1 := 1; d1 := 1; d2 := 1; d3 := 1; d4 := 1; d5 := 1; d6 := 1; // compute input fields to compare it later with output fields FieldA := (a1) or (a2 shl 1) or (a3 shl 2) or (a4 shl 3); FieldB := (b1) or (b2 shl 1) or (b3 shl 2); FieldC := (c1); FieldD := (d1) or (d2 shl 1) or (d3 shl 2) or (d4 shl 3) or (d5 shl 4) or (d6 shl 5); // print field values writeln( 'FieldD: ', FieldD ); writeln( 'FieldA: ', FieldA ); writeln( 'FieldB: ', FieldB ); writeln( 'FieldC: ', FieldC ); writeln; // number of rows Stream[0] := 6; // row lengths Stream[1] := 4; Stream[2] := 3; Stream[3] := 3; Stream[4] := 2; Stream[5] := 1; Stream[6] := 1; // sorted information stream: // d1a1b1c1d2a2b2d3a3b3d4a4d5d6 // data bits Stream[7] := d1; Stream[8] := a1; Stream[9] := b1; Stream[10] := c1; Stream[11] := d2; Stream[12] := a2; Stream[13] := b2; Stream[14] := d3; Stream[15] := a3; Stream[16] := b3; Stream[17] := d4; Stream[18] := a4; Stream[19] := d5; Stream[20] := d6; // now the decoding algorithm: // determine number of rows RowCount := Stream[0]; // extract row lengths RowLength[0] := Stream[1]; RowLength[1] := Stream[2]; RowLength[2] := Stream[3]; RowLength[3] := Stream[4]; RowLength[4] := Stream[5]; RowLength[5] := Stream[6]; // determine field count FieldCount := RowLength[0]; // row[0] indicates number of fields. // I will help out a bit... by leaving this code in ! ;) seems somewhat obvious ;) // first determine data offset properly ! ;) :) 1 for the row count + RowCount to skip over row lengths. DataOffset := 1 + RowCount; RowOffset[0] := DataOffset; RowOffset[1] := RowOffset[0] + RowLength[0]; RowOffset[2] := RowOffset[1] + RowLength[1]; RowOffset[3] := RowOffset[2] + RowLength[2]; RowOffset[4] := RowOffset[3] + RowLength[3]; RowOffset[5] := RowOffset[4] + RowLength[4]; // some how the data bits from the stream needs to end up in these 4 processors so that it produces the same values // as below: // fields may be processed in a different order though. // *** You will need to replace this code with your own code... and preferably it should be parallel, fast and somewhat general/scalable. *** Processor[0] := FieldD; Processor[1] := FieldA; Processor[2] := FieldB; Processor[3] := FieldC; // print processor values. writeln( 'Processor[0]: ', Processor[0] ); writeln( 'Processor[1]: ', Processor[1] ); writeln( 'Processor[2]: ', Processor[2] ); writeln( 'Processor[3]: ', Processor[3] ); writeln; end; begin try Main; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; ReadLn; end. // End of Dummy Decoder Example Oh one last thing when you think you have a valid solution and/or need to test more, replace the initialization of the test data bits with this initialization for example: a1 := 1; a2 := 0; a3:= 0; a4 := 1; b1 := 1; b2 := 1; b3 := 0; c1 := 1; d1 := 1; d2 := 1; d3 := 0; d4 := 0; d5 := 1; d6 := 0; in the original posting (the one before this they were all set to 1). This helped a bit during the development just to see if it was reading anything at all at the somewhat correct places. But this may later put you off if the values are not matching input vs output. So this test data in this posting is better to spot any inconsistencies/bugs in your solution(s). Bye, Skybuck. From ian.g.kelly at gmail.com Sun Sep 20 11:43:19 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 20 Sep 2015 09:43:19 -0600 Subject: .bat file trouble. In-Reply-To: References: Message-ID: On Fri, Sep 18, 2015 at 7:45 AM, Christian Gollwitzer wrote: > The first error indicates, that you are running Python 3, and the script was > made for Python 2. In Python 3, print is a function so you need parentheses > around that print("Initializing...") - either fix that > or install Python 2. > > The second error "TabError" also relates to it, it means that the file mixes > tabs and spaces for indentation. Fix it by expanding all tabs to spaces in > an editor. Note that even if you fix these, there could be other less obvious compatibility issues with running this script in Python 3. The safest and most straightforward way to proceed is to install Python 2 and use that to run the script. However, in the long term you may want to consider upgrading the script to Python 3 anyway. Python 2.7 is only guaranteed to be supported through the year 2020. From Cecil at decebal.nl Sun Sep 20 11:49:52 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 20 Sep 2015 17:49:52 +0200 Subject: Started to work with SQLite3 in Python3 Message-ID: <87fv29rsyn.fsf@Equus.decebal.nl> I started a little project in Python3 with SQLite3: https://github.com/CecilWesterhof/CarApplication I do not mind to get some feedback on it. I was wondering about two things: - Would it be better to split the code into several parts. (For example the SQL statements.) - I understood that with for fuel in fuel_cursor: a fetchall will be executed. At the moment I do not see this as a problem, but if the table would become very big it could. Would it be better to rewrite it with a fetchone? But that is then needed inside and before the loop. What would be a little ugly. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From baladjy at gmail.com Sun Sep 20 12:20:10 2015 From: baladjy at gmail.com (Bala Ji) Date: Sun, 20 Sep 2015 09:20:10 -0700 (PDT) Subject: Postscript to pdf Message-ID: Hello, I'm doing a software to make an id card for a school club so i used TKINTER to make this software. So i can enter details like name, student number etc.. So finally i got a Postscript file the problem is that i want to make a pdf file do you have any ideas? "convert ps to pdf" Thank u regards From lac at openend.se Sun Sep 20 12:40:18 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 20 Sep 2015 18:40:18 +0200 Subject: Postscript to pdf In-Reply-To: References: Message-ID: <201509201640.t8KGeIdZ013580@fido.openend.se> In a message of Sun, 20 Sep 2015 09:20:10 -0700, Bala Ji writes: >Hello, > >I'm doing a software to make an id card for a school club so i used TKINTER to make this software. >So i can enter details like name, student number etc.. > >So finally i got a Postscript file the problem is that i want to make a pdf file do you have any ideas? "convert ps to pdf" > >Thank u >regards There is a free program that does this called ps2pdf which is available for linux, windows and mac os. Laura From rosuav at gmail.com Sun Sep 20 12:44:31 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Sep 2015 02:44:31 +1000 Subject: Started to work with SQLite3 in Python3 In-Reply-To: <87fv29rsyn.fsf@Equus.decebal.nl> References: <87fv29rsyn.fsf@Equus.decebal.nl> Message-ID: On Mon, Sep 21, 2015 at 1:49 AM, Cecil Westerhof wrote: > - I understood that with > for fuel in fuel_cursor: > a fetchall will be executed. > At the moment I do not see this as a problem, but if the table would > become very big it could. Would it be better to rewrite it with a > fetchone? > But that is then needed inside and before the loop. What would be a > little ugly. It iterates over the query, but it doesn't fetchall() into a list. So it's as good as using fetchone(). ChrisA From baladjy at gmail.com Sun Sep 20 12:50:02 2015 From: baladjy at gmail.com (Bala Ji) Date: Sun, 20 Sep 2015 09:50:02 -0700 (PDT) Subject: Postscript to pdf In-Reply-To: References: Message-ID: Thank u laura, I tired it but the problem when i use it there is only half of the image its like the software cut the image From skybuck2000 at hotmail.com Sun Sep 20 13:08:41 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Sun, 20 Sep 2015 19:08:41 +0200 Subject: Dummy Decoder Example (was Re: Parallel decoding lesson for you.) In-Reply-To: References: <62ee4$55f9719c$d47876e2$58812@news.ziggo.nl> <98c6d$55fd6d25$d47876e2$35825@news.ziggo.nl> <80671$55fd6f0a$d47876e2$43083@news.ziggo.nl> <6da10$55fd7ac4$d47876e2$19200@news.ziggo.nl> <72397$55fd7db9$d47876e2$29766@news.ziggo.nl> <9aca0$55fd863e$d47876e2$56488@news.ziggo.nl> <39418$55fd8fac$d47876e2$21797@news.ziggo.nl> <9f6cc$55fd9981$d47876e2$58134@news.ziggo.nl> <109e3$55fda507$d47876e2$30929@news.ziggo.nl> <5d560$55fda6eb$d47876e2$37866@news.ziggo.nl> <956248d4-2f8c-475b-8e41-533370589170@googlegroups.com> <4fe26$55fe0126$d47876e2$49025@news.ziggo.nl> <9c80f$55feb011$d47876e2$2668@news.ziggo.nl> <6d8e8$55fec8fa$d47876e2$62254@news.ziggo.nl> Message-ID: Or point your newsgroup reader to newsgroup: comp.arch Then see thread/topic: "Parallel decoding lesson for you" by Skybuck. Bye, Skybuck. From ward_kingkade at msn.com Sun Sep 20 13:13:22 2015 From: ward_kingkade at msn.com (Ward Kingkade) Date: Sun, 20 Sep 2015 13:13:22 -0400 Subject: Python 2.7 Configuration Message-ID: Hello All, I'm new to Python. I downloaded the 64-bit build of Python 2.7.10 from www.python.org/downloads/release/python-2710. I run Windows 7 Pro on a Dell PC. I find that the installation package creates a folder called "Python 2.7" in my Start menu, with both a command prompt and IDLE GUI options. I hold my scripts in another directory that is parallel to but not under the one where Python 2.7 resides, so I set the Environment Variable PYTHONPATH to include the directory where my scripts reside. Unfortunately, I am unable to reach them in either the IDLE GUI or the "Python command line" in that folder in my start menu. The only way I have managed to run Python scripts is to open an ordinary command prompt from Accessories, navigate to the directory with the scripts, and run python from the command prompt in that directory. Can anyone let me know what I'm not doing that I should be doing to run Python and my scripts from the parallel directory under the GUI or the command line from the start menu folder ? Thanks. Ward Kingkade 1201 Belle View Boulevard Apartment B1 Alexandria, VA 22307 Ward_Kingkade at msn.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Sun Sep 20 14:12:33 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 20 Sep 2015 20:12:33 +0200 Subject: Postscript to pdf In-Reply-To: References: Message-ID: <201509201812.t8KICXHu004041@fido.openend.se> In a message of Sun, 20 Sep 2015 09:50:02 -0700, Bala Ji writes: >Thank u laura, >I tired it but the problem when i use it there is only half of the image >its like the software cut the image >-- >https://mail.python.org/mailman/listinfo/python-list Ok. We need more information. What OS are you using? What version of ps2pdf did you use, and where did you get it? The next thing we need to find out is whether your ps file contained all the infomation, or whether you lost data before you tried to convert it to a pdf. Do you know? Have you seen your ps file and are sure it is ok? We will get this to work. Laura From baladjy at gmail.com Sun Sep 20 14:27:48 2015 From: baladjy at gmail.com (Baladjy KICHENASSAMY) Date: Sun, 20 Sep 2015 20:27:48 +0200 Subject: Postscript to pdf In-Reply-To: <201509201812.t8KICXHu004041@fido.openend.se> References: <201509201812.t8KICXHu004041@fido.openend.se> Message-ID: Hello, I'm using macosx, ps2pdf version i don't know :/ sorry.... ok actually i found what is the problem... There is no problem with the ps file every thing is fine =) Can u please just tell me how to change paper settings ? i want to go from portait to landscape ? 2015-09-20 20:12 GMT+02:00 Laura Creighton : > In a message of Sun, 20 Sep 2015 09:50:02 -0700, Bala Ji writes: >>Thank u laura, >>I tired it but the problem when i use it there is only half of the image >>its like the software cut the image >>-- >>https://mail.python.org/mailman/listinfo/python-list > > Ok. We need more information. > What OS are you using? > What version of ps2pdf did you use, and where did you get it? > > The next thing we need to find out is whether your ps file contained > all the infomation, or whether you lost data before you tried to > convert it to a pdf. Do you know? Have you seen your ps file > and are sure it is ok? > > We will get this to work. > > Laura -- KICHENASSAMY Baladjy Ing?nieur en G?nie M?canique Sp?cialiste Contr?le Non Destructif et Qualification des proc?d?s sp?ciaux COSAC CND Niveau 2 RT et PT Aircelle SAFRAN Tel:06.03.72.53.12 From Cecil at decebal.nl Sun Sep 20 14:40:13 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 20 Sep 2015 20:40:13 +0200 Subject: Started to work with SQLite3 in Python3 References: <87fv29rsyn.fsf@Equus.decebal.nl> Message-ID: <874miprl2q.fsf@Equus.decebal.nl> On Sunday 20 Sep 2015 18:44 CEST, Chris Angelico wrote: > On Mon, Sep 21, 2015 at 1:49 AM, Cecil Westerhof wrote: >> - I understood that with for fuel in fuel_cursor: a fetchall will >> be executed. At the moment I do not see this as a problem, but if >> the table would become very big it could. Would it be better to >> rewrite it with a fetchone? But that is then needed inside and >> before the loop. What would be a little ugly. > > It iterates over the query, but it doesn't fetchall() into a list. > So it's as good as using fetchone(). You are right. I found this: http://pythoncentral.io/introduction-to-sqlite-in-python/ where at: Retrieving Data (SELECT) with SQLite it says: The cursor object works as an iterator, invoking fetchall() automatically: but all other places (I did a more extended search now) say the same as you. So this problem is solved. :-) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Sun Sep 20 14:57:58 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 20 Sep 2015 20:57:58 +0200 Subject: Started to work with SQLite3 in Python3 References: <87fv29rsyn.fsf@Equus.decebal.nl> Message-ID: <87zj0grk95.fsf@Equus.decebal.nl> On Sunday 20 Sep 2015 17:49 CEST, Cecil Westerhof wrote: > I started a little project in Python3 with SQLite3: > https://github.com/CecilWesterhof/CarApplication > > I do not mind to get some feedback on it. I think I found a bug. In init I should put a: conn.commit() after: fill_tables() At the moment it is not a problem, but if the program gets some functionality and would crash after a long run, the changes would be lost. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From Cecil at decebal.nl Sun Sep 20 15:03:38 2015 From: Cecil at decebal.nl (Cecil Westerhof) Date: Sun, 20 Sep 2015 21:03:38 +0200 Subject: Started to work with SQLite3 in Python3 References: <87fv29rsyn.fsf@Equus.decebal.nl> Message-ID: <87vbb4rjzp.fsf@Equus.decebal.nl> On Sunday 20 Sep 2015 17:49 CEST, Cecil Westerhof wrote: > I started a little project in Python3 with SQLite3: > https://github.com/CecilWesterhof/CarApplication > > I do not mind to get some feedback on it. > > I was wondering about two things: > - Would it be better to split the code into several parts. (For > example the SQL statements.) I changed this part. I put the initialisation of the variables with SQL statements into sqlStatements.py and use in the program: from sqlStatements import * Is this the correct way of doing this? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From lac at openend.se Sun Sep 20 15:09:03 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 20 Sep 2015 21:09:03 +0200 Subject: Postscript to pdf In-Reply-To: References: <201509201812.t8KICXHu004041@fido.openend.se> Message-ID: <201509201909.t8KJ93oU018314@fido.openend.se> In a message of Sun, 20 Sep 2015 20:27:48 +0200, Baladjy KICHENASSAMY writes: >Hello, > >I'm using macosx, ps2pdf version i don't know :/ sorry.... >ok actually i found what is the problem... > >There is no problem with the ps file every thing is fine =) > >Can u please just tell me how to change paper settings ? >i want to go from portait to landscape ? > Aha! Great to know. Do you have a real printer there, in which case is this a printer problem? If so, I need the name of the printer and its model number to help look up the way to make it do landscape. If you just want to have ps2pdf produce landscape files, that is surprisingly difficult, for the ps2pdf that uses ghostscript to get the work done. ps2pdf 'guesses' what is the correct orientation and, stupidly, there is no way to tell it 'stop guessing, I know what I want'. It's very bad at guessing things that don't have text -- or enough text -- in them. Most of the time ps2pdf is just this: gs \ -o output.pdf \ -sDEVICE=pdfwrite \ -dPDFSETTINGS=/prepress \ -dHaveTrueTypes=true \ -dEmbedAllFonts=true \ -dSubsetFonts=false \ -c ".setpdfwrite <> setdistillerparams" \ -f input.ps where input.ps is the file you have and output.pdf is the pdf you want. and we can make gs orient itself as you want with -c "<> setpagedevice" Orientation 3 is landscape. Orientation 0 is portrait. If this is your problem, then see if you have gs (ghostscript) and in that case see if this horrible long command works. Laura From torque.india at gmail.com Sun Sep 20 15:30:01 2015 From: torque.india at gmail.com (OmPs) Date: Mon, 21 Sep 2015 01:00:01 +0530 Subject: error while installing using pip. Message-ID: Hi all, I am getting the below error while I am trying to install atfork package from pip repositories. I have done a thorough google search but am not able to find and appropriate solution for it.Installation of SSL packages and ssl package from python too do not solve the mystry. # pip install --allow-external atfork atforkCollecting atfork Could not find a version that satisfies the requirement atfork (from versions: ) Some insecure and unverifiable files were ignored (use --allow-unverified atfork to allow). No matching distribution found for atfork It says no matching distribution, but at pypi repo I am able to see it. https://pypi.python.org/pypi/atfork/0.1.2 -------------- next part -------------- An HTML attachment was scrubbed... URL: From baladjy at gmail.com Sun Sep 20 15:32:34 2015 From: baladjy at gmail.com (Baladjy KICHENASSAMY) Date: Sun, 20 Sep 2015 21:32:34 +0200 Subject: Postscript to pdf In-Reply-To: <201509201909.t8KJ93oU018314@fido.openend.se> References: <201509201812.t8KICXHu004041@fido.openend.se> <201509201909.t8KJ93oU018314@fido.openend.se> Message-ID: ohhhh ok i got it actually it's very easy the commande is : ps2pdf -dEPSCrop image.ps sorry but i'm new to python my last question is how to integrate this to python... i want that the output file must be a pdf ? 1) i created a button which i'll save my id card as "ps" file def save(): Canevas.update() Canevas.postscript(file=tkFileDialog.asksaveasfilename(), colormode='color') 2) so now i want to create a button to convert this "ps" file into "pdf" .... def convert(): help :/ Regards 2015-09-20 21:09 GMT+02:00 Laura Creighton : > In a message of Sun, 20 Sep 2015 20:27:48 +0200, Baladjy KICHENASSAMY writes: >>Hello, >> >>I'm using macosx, ps2pdf version i don't know :/ sorry.... >>ok actually i found what is the problem... >> >>There is no problem with the ps file every thing is fine =) >> >>Can u please just tell me how to change paper settings ? >>i want to go from portait to landscape ? >> > > Aha! Great to know. > Do you have a real printer there, in which case is this a printer problem? > If so, I need the name of the printer and its model number to help look up > the way to make it do landscape. > > If you just want to have ps2pdf produce landscape files, that is > surprisingly difficult, for the ps2pdf that uses ghostscript to > get the work done. ps2pdf 'guesses' what is the correct orientation > and, stupidly, there is no way to tell it 'stop guessing, I know > what I want'. It's very bad at guessing things that don't have > text -- or enough text -- in them. > > Most of the time ps2pdf is just this: > > gs \ > -o output.pdf \ > -sDEVICE=pdfwrite \ > -dPDFSETTINGS=/prepress \ > -dHaveTrueTypes=true \ > -dEmbedAllFonts=true \ > -dSubsetFonts=false \ > -c ".setpdfwrite <> setdistillerparams" \ > -f input.ps > > where input.ps is the file you have and output.pdf is the pdf you want. > and we can make gs orient itself as you want with > > -c "<> setpagedevice" > > Orientation 3 is landscape. Orientation 0 is portrait. > > If this is your problem, then see if you have gs (ghostscript) > and in that case see if this horrible long command works. > > Laura > -- KICHENASSAMY Baladjy Ing?nieur en G?nie M?canique Sp?cialiste Contr?le Non Destructif et Qualification des proc?d?s sp?ciaux COSAC CND Niveau 2 RT et PT Aircelle SAFRAN Tel:06.03.72.53.12 From lac at openend.se Sun Sep 20 15:37:19 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 20 Sep 2015 21:37:19 +0200 Subject: error while installing using pip. In-Reply-To: References: Message-ID: <201509201937.t8KJbJc0025505@fido.openend.se> In a message of Mon, 21 Sep 2015 01:00:01 +0530, OmPs writes: >Hi all, > >I am getting the below error while I am trying to install atfork package >from pip repositories. I have done a thorough google search but am not able >to find and appropriate solution for it.Installation of SSL packages and >ssl package from python too do not solve the mystry. > ># pip install --allow-external atfork atforkCollecting atfork > Could not find a version that satisfies the requirement atfork (from >versions: ) > Some insecure and unverifiable files were ignored (use --allow-unverified >atfork to allow). >No matching distribution found for atfork > > >It says no matching distribution, but at pypi repo I am able to see it. > >https://pypi.python.org/pypi/atfork/0.1.2 If you get no useful answers here, try distutils-sig at python.org https://mail.python.org/mailman/listinfo/distutils-sig If you have a problem with pip, these are the people to talk to. And having them verify that pip is fine, the package is nuts would at least simplify your problem. Laura From lac at openend.se Sun Sep 20 15:52:43 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 20 Sep 2015 21:52:43 +0200 Subject: Postscript to pdf In-Reply-To: References: <201509201812.t8KICXHu004041@fido.openend.se> <201509201909.t8KJ93oU018314@fido.openend.se> Message-ID: <201509201952.t8KJqh7W029272@fido.openend.se> In a message of Sun, 20 Sep 2015 21:32:34 +0200, Baladjy KICHENASSAMY writes: >ohhhh ok i got it >actually it's very easy the commande is : >ps2pdf -dEPSCrop image.ps > >sorry but i'm new to python my last question is how to integrate this >to python... i want that the output file must be a pdf ? > >1) i created a button which i'll save my id card as "ps" file > >def save(): > Canevas.update() > Canevas.postscript(file=tkFileDialog.asksaveasfilename(), colormode='color') >2) so now i want to create a button to convert this "ps" file into "pdf" .... > >def convert(): > help :/ You need to run the subprocess module to run your command. https://docs.python.org/2/library/subprocess.html (for python 2) https://docs.python.org/3.4/library/subprocess.html (for python 3) is this enough or do you need more help getting it to work? Laura From breamoreboy at yahoo.co.uk Sun Sep 20 16:27:47 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 20 Sep 2015 21:27:47 +0100 Subject: error while installing using pip. In-Reply-To: References: Message-ID: On 20/09/2015 20:30, OmPs wrote: > Hi all, > > I am getting the below error while I am trying to install atfork package > from pip repositories. I have done a thorough google search but am not > able to find and appropriate solution for it.Installation of SSL > packages and ssl package from python too do not solve the mystry. > > # pip install --allow-external atfork atforkCollecting atfork > Could not find a version that satisfies the requirement atfork (from > versions: ) > Some insecure and unverifiable files were ignored (use > --allow-unverified atfork to allow). > No matching distribution found for atfork > > It says no matching distribution, but at pypi repo I am able to see it. > > https://pypi.python.org/pypi/atfork/0.1.2 > I tried several combinations of things and each one failed dismally. I then went to https://github.com/google/python-atfork and saw that nothing has been committed for six years. The readme states "Work on this project has been abandoned." Are you sure that you still want this package? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From lac at openend.se Sun Sep 20 16:42:59 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 20 Sep 2015 22:42:59 +0200 Subject: error while installing using pip. In-Reply-To: References: Message-ID: <201509202042.t8KKgxNc009750@fido.openend.se> There is an atfork patch supplied as part of this issue https://bugs.python.org/issue16500 Maybe it can do what you want? Laura From baladjy at gmail.com Sun Sep 20 17:11:20 2015 From: baladjy at gmail.com (Baladjy KICHENASSAMY) Date: Sun, 20 Sep 2015 23:11:20 +0200 Subject: Postscript to pdf In-Reply-To: <201509201952.t8KJqh7W029272@fido.openend.se> References: <201509201812.t8KICXHu004041@fido.openend.se> <201509201909.t8KJ93oU018314@fido.openend.se> <201509201952.t8KJqh7W029272@fido.openend.se> Message-ID: well one more question :/ i tried this def save(): Canevas.update() Canevas.postscript(file=tkFileDialog.asksaveasfilename(), colormode='color') subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"]) i got the ps file but i didn't get the pdf file :/ 2015-09-20 21:52 GMT+02:00 Laura Creighton : > In a message of Sun, 20 Sep 2015 21:32:34 +0200, Baladjy KICHENASSAMY writes: >>ohhhh ok i got it >>actually it's very easy the commande is : >>ps2pdf -dEPSCrop image.ps >> >>sorry but i'm new to python my last question is how to integrate this >>to python... i want that the output file must be a pdf ? >> >>1) i created a button which i'll save my id card as "ps" file >> >>def save(): >> Canevas.update() >> Canevas.postscript(file=tkFileDialog.asksaveasfilename(), colormode='color') > >>2) so now i want to create a button to convert this "ps" file into "pdf" .... >> >>def convert(): >> help :/ > > You need to run the subprocess module to run your command. > https://docs.python.org/2/library/subprocess.html (for python 2) > https://docs.python.org/3.4/library/subprocess.html (for python 3) > > is this enough or do you need more help getting it to work? > > Laura > -- KICHENASSAMY Baladjy Ing?nieur en G?nie M?canique Sp?cialiste Contr?le Non Destructif et Qualification des proc?d?s sp?ciaux COSAC CND Niveau 2 RT et PT Aircelle SAFRAN Tel:06.03.72.53.12 From rosuav at gmail.com Sun Sep 20 18:35:06 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Sep 2015 08:35:06 +1000 Subject: error while installing using pip. In-Reply-To: References: Message-ID: On Mon, Sep 21, 2015 at 5:30 AM, OmPs wrote: > It says no matching distribution, but at pypi repo I am able to see it. > > https://pypi.python.org/pypi/atfork/0.1.2 That has a version number of zero. I think that might count as a pre-release version, so you need the --pre option to pip or it won't install. ChrisA From james.harris.1 at gmail.com Sun Sep 20 18:36:30 2015 From: james.harris.1 at gmail.com (James Harris) Date: Sun, 20 Sep 2015 23:36:30 +0100 Subject: Lightwight socket IO wrapper References: Message-ID: "Akira Li" <4kir4.1i at gmail.com> wrote in message news:mailman.37.1442754893.21674.python-list at python.org... > "James Harris" writes: > >> I guess there have been many attempts to make socket IO easier to >> handle and a good number of those have been in Python. >> >> The trouble with trying to improve something which is already well >> designed (and conciously left as is) is that the so-called >> improvement >> can become much more complex and overly elaborate. That can apply to >> the initial idea, for sure, but when writing helper or convenience >> functions perhaps it applies more to the temptation to keep adding >> just a little bit extra. The end result can be overly elaborate such >> as a framework which is fine where such is needed but is overkill for >> simpler requirements. >> >> Do you guys have any recommendations of some *lightweight* additions >> to Python socket IO before I write any more of my own? Something >> built >> in to Python would be much preferred over any modules which have to >> be >> added. I had in the back of my mind that there was a high-level >> socket-IO library - much as threading was added as a wrapper to the >> basic thread module - but I cannot find anything above socket. Is >> there any? > > Does ?MQ qualify as lightweight? It's certainly interesting. It's puzzling, too. For example, http://zguide.zeromq.org/py:hwserver The Python code there includes message = socket.recv() but given that this is a TCP socket it doesn't look like there is any way for the stack to know how many bytes to return. Either ZeroMQ layers another end-to-end protocol on top of TCP (which would be no good) or it will be guessing (which would not be good either). There are probably answers to that query but there is a lot of documentation, including on reliable communication, and that in itself makes ZeroMQ seem overkill, even if it can be persuaded to do what I want. I am impressed that they show code in many languages. I may come back to it but for the moment it doesn't seem to be what I was looking for. And it is not built in. >> A current specific to illustrate where basic socket IO is limited: it >> normally provides no guarantees over how many bytes are transferred >> at >> a time (AFAICS that's true for both streams and datagrams) so the >> delimiting of messages/records needs to be handled by the sender and >> receiver. I do already handle some of this myself but I wondered if >> there was a prebuilt solution that I should be using instead - to >> save >> me adding just a little bit extra. ;-) > > There are already convenience functions in stdlib such as > sock.sendall(), sock.sendfile(), socket.create_connection() in > addition > to BSD Sockets API. > > If you want to extend this list and have specific suggestions; see > https://docs.python.org/devguide/stdlibchanges.html That may be a bit overkill just now but it's a good suggestion. > Or just describe your current specific issue in more detail here. There are a few things and more crop up as time goes on. For example, over TCP it would be helpful to have a function to receive a specific number of bytes or one to read bytes until reaching a certain delimiter such as newline or zero or space etc. Even better would be to be able to use the iteration protocol so you could just code next() and get the next such chunk of read in a for loop. When sending it would be good to just say to send a bunch of bytes but know that you will get told how many were sent (or didn't get sent) if it fails. Sock.sendall() doesn't do that. I thought UDP would deliver (or drop) a whole datagram but cannot find anything in the Python documentaiton to guarantee that. In fact documentation for the send() call says that apps are responsible for checking that all data has been sent. They may mean that to apply to stream protocols only but it doesn't state that. (Of course, UDP datagrams are limited in size so the call may validly indicate incomplete transmission even when the first part of a big message is sent successfully.) Receiving no bytes is taken as indicating the end of the communication. That's OK for TCP but not for UDP so there should be a way to distinguish between the end of data and receiving an empty datagram. The recv calls require a buffer size to be supplied which is a technical detail. A Python wrapper could save the programmer dealing with that. Reminder to self: encoding issues. None of the above is difficult to write and I have written the bits I need myself but, basically, there are things that would make socket IO easier and yet still compatible with more long-winded code. So I wondered if there were already some Python modules which were more convenient than what I found in the documentation. James From lac at openend.se Sun Sep 20 18:50:12 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 21 Sep 2015 00:50:12 +0200 Subject: Postscript to pdf In-Reply-To: References: <201509201812.t8KICXHu004041@fido.openend.se> <201509201909.t8KJ93oU018314@fido.openend.se> <201509201952.t8KJqh7W029272@fido.openend.se> Message-ID: <201509202250.t8KMoC0h009296@fido.openend.se> In a message of Sun, 20 Sep 2015 23:11:20 +0200, Baladjy KICHENASSAMY writes: >well one more question :/ > >i tried this > >def save(): > Canevas.update() > Canevas.postscript(file=tkFileDialog.asksaveasfilename(), >colormode='color') > subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"]) > > >i got the ps file but i didn't get the pdf file :/ It's 00:41 here in Sweden, and I have an 08:00 meeting. I am off to bed. Perhaps somebody else can help now, otherwise I will be back tomorrow. I've never tried to get subprocess to run as part of a savefile dialog. Try building a tkinter app that takes a filename argument (somepostscript file you have lying around) and then push the button, in the same dir makes a pdf of your ps using subprocess. If that works, then see about getting save to run that subprocess as part of the save process. I am very curious about whether that can be done -- but first check that your subprocess is working, period. The wretched thing is slightly different between windows and linux, and even between different linuxes, so needing to fiddle a bit here is normal (and frustrating). So right now I cannot tell if your problem is 'save doesn't like it like that' or 'your subprocess isn't working'. But nothing in Tkinter likes 'Canevas' -- (which is great French but rotten English) you must have written Canvas in your code. Paste the real thing in next time, ok? Sorry I am off now, Laura From rosuav at gmail.com Sun Sep 20 20:34:53 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Sep 2015 10:34:53 +1000 Subject: Lightwight socket IO wrapper In-Reply-To: References: Message-ID: On Mon, Sep 21, 2015 at 10:19 AM, Dennis Lee Bieber wrote: > Even if the IP layer has to fragment a UDP packet to meet limits of the > transport media, it should put them back together on the other end before > passing it up to the UDP layer. To my knowledge, UDP does not have a size > limit on the message (well -- a 16-bit length field in the UDP header). But > since it /is/ "got it all" or "dropped" with no inherent confirmation, one > would have to embed their own protocol within it -- sequence numbers with > ACK/NAK, for example. Problem: if using LARGE UDP packets, this protocol > would mean having LARGE resends should packets be dropped or arrive out of > sequence (and since the ACK/NAK could be dropped too, you may have to > handle the case of a duplicated packet -- also large). > If you're going to add sequencing and acknowledgements to UDP, wouldn't it be easier to use TCP and simply prefix every message with a two-byte length? UDP is great when order doesn't matter and each packet stands entirely alone. DNS is a well-known example - the question "What is the IP address for www.rosuav.com?" doesn't in any way affect the question "What is the mail server for gmail.com?", so you fire off UDP packets for each one, and get responses whenever you get them. UDP's also perfect for a heartbeat system - you send out a packet every however-often, and if the monitor hasn't heard from you in X seconds, it starts alerting people. No need for responses of any kind there. But for working with a stream, I usually find it's a lot easier to build on top of TCP than UDP. ChrisA From cs at zip.com.au Sun Sep 20 21:55:14 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 21 Sep 2015 11:55:14 +1000 Subject: Lightwight socket IO wrapper In-Reply-To: References: Message-ID: <20150921015514.GA70236@cskk.homeip.net> On 21Sep2015 10:34, Chris Angelico wrote: >If you're going to add sequencing and acknowledgements to UDP, >wouldn't it be easier to use TCP and simply prefix every message with >a two-byte length? Frankly, often yes. That's what I do. (different length encoding, but otherwise...) UDP's neat if you do not care if a packet fails to arrive and if you can guarentee that your data fits in a packet in the face of different MTUs. I like TCP myself, most of the time. Another nice thing about TCP is that wil a little effort you get to pack multiple data packets (or partial data packets) into a network packet, etc. Cheers, Cameron Simpson If you lie to the compiler, it will get its revenge. - Henry Spencer From rosuav at gmail.com Sun Sep 20 22:40:03 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Sep 2015 12:40:03 +1000 Subject: Lightwight socket IO wrapper In-Reply-To: <20150921015514.GA70236@cskk.homeip.net> References: <20150921015514.GA70236@cskk.homeip.net> Message-ID: On Mon, Sep 21, 2015 at 11:55 AM, Cameron Simpson wrote: > On 21Sep2015 10:34, Chris Angelico wrote: >> >> If you're going to add sequencing and acknowledgements to UDP, >> wouldn't it be easier to use TCP and simply prefix every message with >> a two-byte length? > > > Frankly, often yes. That's what I do. (different length encoding, but > otherwise...) Out of interest, what encoding? With most protocols, I would prefer to encode in ASCII digits terminated by end-of-line, but for arbitrary content you're packaging up, it's usually easier to read 2 bytes (or 4 or whatever you want to specify), then read that many bytes, and that's your content. No buffering required - you'll never read past the end of a packet. > UDP's neat if you do not care if a packet fails to arrive and if you can > guarentee that your data fits in a packet in the face of different MTUs. > I like TCP myself, most of the time. Another nice thing about TCP is that > wil a little effort you get to pack multiple data packets (or partial data > packets) into a network packet, etc. Emphatically - a little effort sometimes, and other times no effort at all! If you write a packet of data, then write another one, and another, and another, and another, without waiting for responses, Nagling should combine them automatically. And even if they're not deliberately queued by Nagle's Algorithm, packets can get combined for other reasons. So, yeah! Definitely can help a lot with packet counts on small writes. ChrisA From kacyjones at lclark.edu Sun Sep 20 23:00:11 2015 From: kacyjones at lclark.edu (kacyjones at lclark.edu) Date: Sun, 20 Sep 2015 20:00:11 -0700 (PDT) Subject: Fixing Python install on the Mac after running 'CleanMyMac' (fwd) In-Reply-To: References: Message-ID: On Friday, May 29, 2015 at 12:56:49 PM UTC-7, Laura Creighton wrote: > Good news, we are getting closer to understanding what to do. > This in from Ned. I will continue after the message: > > ------- Forwarded Message > > Return-Path: > From: Ned Deily > Subject: Re: Fixing Python install on the Mac after running 'CleanMyMac' > Date: Fri, 29 May 2015 10:28:19 -0700 > Lines: 63 > > > Might that appear to work at first, but leave some subtle issues which are > > not at first apparent? I don't know how intertwined Apple's Python instance > > is in the day-to-day operation of the operating system (it certainly seems > > to be on some Linux distros), but it's possible that some Apple-specific > > package isn't available at part of the stock Python 2.7 distribution. > > Installing a python.org Python (/usr/local/bin/python*) is independent > of and does not interfere with use of the Apple-supplied system Pythons > (/usr/bin/python*). Apple does ship various third-party Python packages > ("distributions") with its system Python, like numpy, but they tend to > be old and outdated versions and there are a few Apple-only packages. > But, should that issue arise, that can be resolved by choosing the right > path (/usr/local/bin vs /usr/bin) or removing /usr/local/bin from $PATH. > > The thing is the original message in this thread had this: > > They are getting: > > Utility has encountered a fatal error, and will now terminate. A > > Python runtime could not be located. You may need to install a > > framework build of Python or edit the PyRuntimeLocations array in this > > applications info.plist file. Then there are two oblong circles. One > > says Open Console. The other says Terminate. > > But ... I just did what I should have done earlier: googled for that > message. And I find that the message is coming from a py2app-built > application (and it seems I answered the question 3 years ago!): > > http://stackoverflow.com/questions/10184974/py2app-is-not-copying-the-pyt > hon-framework-to-the-new-app-while-using-virutalenv > > The py2app glue code could be looking for Pythons in various spots > including the system Python. So, let's make sure the system Python is > still working. On the most up-to-date 10.7 Lion system (10.7.5), typing > the following two commands should give results the same as those shown > (->): > > /usr/bin/python2.7 -c 'import sys;print(sys.version)' > - -> 2.7.1 (r271:86832, Jul 31 2011, 19:30:53) > - -> [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] > > /usr/bin/python2.7 -c 'import numpy;print(numpy.__file__)' > - -> > /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/pytho > n/numpy/__init__.py > > If not, then it really may be necessary to restore system files which, > as I noted before, is most safely and accurately done by following > Apple's directions to restore the system from the recovery partition and > a good backup of user files. > > - -- > Ned Deily, > nad at acm.org > > - -- > https://mail.python.org/mailman/listinfo/python-list > > ------- End of Forwarded Message > > So please type > > /usr/bin/python2.7 -c 'import sys;print(sys.version)' > > and tell me what you get as an answer. > > Then type > > /usr/bin/python2.7 -c 'import numpy;print(numpy.__file__)' > > and again tell me what you get. > > But if it isn't as Ned expects, then you may have to go back to > your backups. > > Laura I was having this same problem, entered those commands and got this as a response: MacBook-Pro:~ kacyjones$ /usr/bin/python2.7 -c 'import numpy;print(numpy.__file__)' /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/__init__.pyc MacBook-Pro:~ kacyjones$ MacBook-Pro:~ kacyjones$ /usr/bin/python2.7 -c 'import sys;print(sys.version)' 2.7.10 (default, Jul 14 2015, 19:46:27) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] Any idea what that means for my system? From 4kir4.1i at gmail.com Sun Sep 20 23:07:56 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Mon, 21 Sep 2015 06:07:56 +0300 Subject: Lightwight socket IO wrapper References: Message-ID: <87k2rk31wz.fsf@gmail.com> "James Harris" writes: ... > There are a few things and more crop up as time goes on. For example, > over TCP it would be helpful to have a function to receive a specific > number of bytes or one to read bytes until reaching a certain > delimiter such as newline or zero or space etc. The answer is sock.makefile('rb') then `file.read(nbytes)` returns a specific number of bytes. `file.readline()` reads until newline (b'\n') There is Python Issue: "Add support for reading records with arbitrary separators to the standard IO stack" http://bugs.python.org/issue1152248 See also http://bugs.python.org/issue17083 Perhaps, it is easier to implement read_until(sep) that is best suited for a particular case. > Even better would be to be able to use the iteration protocol so you > could just code next() and get the next such chunk of read in a for > loop. file is an iterator over lines i.e., next(file) works. > When sending it would be good to just say to send a bunch of bytes but > know that you will get told how many were sent (or didn't get sent) if > it fails. Sock.sendall() doesn't do that. sock.send() returns the number of bytes sent that may be less than given. You could reimplement sock.sendall() to include the number of bytes successfully sent in case of an error. > I thought UDP would deliver (or drop) a whole datagram but cannot find > anything in the Python documentaiton to guarantee that. In fact > documentation for the send() call says that apps are responsible for > checking that all data has been sent. They may mean that to apply to > stream protocols only but it doesn't state that. (Of course, UDP > datagrams are limited in size so the call may validly indicate > incomplete transmission even when the first part of a big message is > sent successfully.) > > Receiving no bytes is taken as indicating the end of the > communication. That's OK for TCP but not for UDP so there should be a > way to distinguish between the end of data and receiving an empty > datagram. There is no end of communication in UDP and therefore there is no end of data. If you've got a zero bytes in return then it means that you've received a zero length datagram. sock.recvfrom() is a thin wrapper around the corresponding C function. You could read any docs you like about UDP sockets. http://stackoverflow.com/questions/5307031/how-to-detect-receipt-of-a-0-length-udp-datagram > The recv calls require a buffer size to be supplied which is a > technical detail. A Python wrapper could save the programmer dealing > with that. It is not just a buffer size. It is the maximum amount of data to be received at once i.e., sock.recv() may return less but never more. You could use makefile() and read() if recv() is too low-level. > Reminder to self: encoding issues. > > None of the above is difficult to write and I have written the bits I > need myself but, basically, there are things that would make socket IO > easier and yet still compatible with more long-winded code. So I > wondered if there were already some Python modules which were more > convenient than what I found in the documentation. > > James From tjreedy at udel.edu Mon Sep 21 00:17:47 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 21 Sep 2015 00:17:47 -0400 Subject: Postscript to pdf In-Reply-To: References: Message-ID: On 9/20/2015 12:20 PM, Bala Ji wrote: > Hello, > > I'm doing a software to make an id card for a school club so i used > TKINTER to make this software. So i can enter details like name, > student number etc.. > > So finally i got a Postscript file the problem is that i want to make > a pdf file do you have any ideas? "convert ps to pdf" Where does the .ps file come from? tkinter canvas to .ps? If so, I suggest not to do that. Get reportlab or another python pdf generator (search pypi.python.org for 'pdf' or web for 'python generate pdf'.) -- Terry Jan Reedy From marko at pacujo.net Mon Sep 21 00:39:24 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 21 Sep 2015 07:39:24 +0300 Subject: Lightwight socket IO wrapper References: <20150921015514.GA70236@cskk.homeip.net> Message-ID: <876134e683.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Sep 21, 2015 at 11:55 AM, Cameron Simpson wrote: >> Another nice thing about TCP is that wil a little effort you get to >> pack multiple data packets (or partial data packets) into a network >> packet, etc. > > Emphatically - a little effort sometimes, and other times no effort at > all! If you write a packet of data, then write another one, and > another, and another, and another, without waiting for responses, > Nagling should combine them automatically. And even if they're not > deliberately queued by Nagle's Algorithm, packets can get combined for > other reasons. So, yeah! Definitely can help a lot with packet counts > on small writes. Unfortunately, Nagle and delayed ACK, which are both defaults, don't go well together (you get nasty 200-millisecond hickups). I recommend using socket.TCP_CORK with socket.TCP_NODELAY where they are available (Linux). They give you Nagle without delayed ACK. See As for the topic, TCP doesn't need wrappers to abstract away the difficult bits. That's a superficially good idea that leads to trouble. Marko From rosuav at gmail.com Mon Sep 21 00:48:25 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Sep 2015 14:48:25 +1000 Subject: Lightwight socket IO wrapper In-Reply-To: <876134e683.fsf@elektro.pacujo.net> References: <20150921015514.GA70236@cskk.homeip.net> <876134e683.fsf@elektro.pacujo.net> Message-ID: On Mon, Sep 21, 2015 at 2:39 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Sep 21, 2015 at 11:55 AM, Cameron Simpson wrote: >>> Another nice thing about TCP is that wil a little effort you get to >>> pack multiple data packets (or partial data packets) into a network >>> packet, etc. >> >> Emphatically - a little effort sometimes, and other times no effort at >> all! If you write a packet of data, then write another one, and >> another, and another, and another, without waiting for responses, >> Nagling should combine them automatically. And even if they're not >> deliberately queued by Nagle's Algorithm, packets can get combined for >> other reasons. So, yeah! Definitely can help a lot with packet counts >> on small writes. > > Unfortunately, Nagle and delayed ACK, which are both defaults, don't go > well together (you get nasty 200-millisecond hickups). Only in the write-write-read scenario. If you write-read-write-read, or if your reads don't depend on your writes, then Nagle + delayed ACK works just fine. But if you write a bunch of stuff, then block waiting for the other end to respond, and then write multiple times, and wait for a response, _then_ the pair work badly together, yes. > As for the topic, TCP doesn't need wrappers to abstract away the > difficult bits. That's a superficially good idea that leads to trouble. Depends what you're doing - if you're working with a higher level protocol like HTTP, then abstracting away the difficult bits of TCP is part of abstracting away the difficult bits of HTTP, and something like 'requests' is superb. But if you're inventing your own protocol, directly on top of a BSD socket, then I would agree - just call socket functions directly. Otherwise you risk nasty surprises when your file-like object has ridiculous performance problems. ChrisA From greg.ewing at canterbury.ac.nz Mon Sep 21 01:46:29 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 21 Sep 2015 17:46:29 +1200 Subject: Lightwight socket IO wrapper In-Reply-To: References: Message-ID: Dennis Lee Bieber wrote: > worst case: each TCP packet is broken up to fit Hollerith > cards; Or printed on strips of paper and tied to pigeons: https://en.wikipedia.org/wiki/IP_over_Avian_Carriers -- Greg From cs at zip.com.au Mon Sep 21 02:27:13 2015 From: cs at zip.com.au (Cameron Simpson) Date: Mon, 21 Sep 2015 16:27:13 +1000 Subject: Lightwight socket IO wrapper In-Reply-To: References: Message-ID: <20150921062713.GA77399@cskk.homeip.net> On 21Sep2015 12:40, Chris Angelico wrote: >On Mon, Sep 21, 2015 at 11:55 AM, Cameron Simpson wrote: >> On 21Sep2015 10:34, Chris Angelico wrote: >>> If you're going to add sequencing and acknowledgements to UDP, >>> wouldn't it be easier to use TCP and simply prefix every message with >>> a two-byte length? >> >> Frankly, often yes. That's what I do. (different length encoding, but >> otherwise...) > >Out of interest, what encoding? NB: this is for binary protocols. I don't like embedding arbitrary size limits in protocols or data formats if I can easily avoid it. So (for my home grown binary protocols) I encode unsigned integers as big endian octets with the top bit meaning "another octet follows" and the bottom 7 bits going to the value. So my packets look like: encoded(length)data For sizes below 128, one byte of length. For sizes 128-16383, two bytes. And so on. Compact yet unbounded. My new protocols ar probably going to derive from the scheme implemented in the code cited below. "New" means as of some weeks ago, when I completely rewrote a painful ad hoc protocol of mine and pulled out the general features into what follows. The actual packet format is implemented by the Packet class at the bottom of this: https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/serialise.py Simple and flexible. As for using that data format multiplexed with multiple channels, see the PacketConnection class here: https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/stream.py Broadly, the packets are length[tag,flags[,channel#],payload] and one implements whatever semantics one needs on top of that. You can see this exercised over UNIX pipes and TCP streams in the unit tests here: https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/stream_tests.py On the subject of packet stuffing, my preferred loop for that is visible in the PacketConnection._send worker thread method, which goes: fp = self._send_fp Q = self._sendQ for P in Q: sig = (P.channel, P.tag, P.is_request) if sig in self.__sent: raise RuntimeError("second send of %s" % (P,)) self.__sent.add(sig) write_Packet(fp, P) if Q.empty(): fp.flush() fp.close() In short: get packets from the queue and write them to the stream buffer. If the queue gets empty, _only then_ flush the buffer. This assures synchronicity in comms while giving the IO library a chance to fill a buffer with several packets. Cheers, Cameron Simpson ERROR 155 - You can't do that. - Data General S200 Fortran error code list From skybuck2000 at hotmail.com Mon Sep 21 02:55:21 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Mon, 21 Sep 2015 08:55:21 +0200 Subject: Dummy Decoder Example (was Re: Parallel decoding lesson for you.) In-Reply-To: References: <62ee4$55f9719c$d47876e2$58812@news.ziggo.nl> <98c6d$55fd6d25$d47876e2$35825@news.ziggo.nl> <80671$55fd6f0a$d47876e2$43083@news.ziggo.nl> <6da10$55fd7ac4$d47876e2$19200@news.ziggo.nl> <72397$55fd7db9$d47876e2$29766@news.ziggo.nl> <9aca0$55fd863e$d47876e2$56488@news.ziggo.nl> <39418$55fd8fac$d47876e2$21797@news.ziggo.nl> <9f6cc$55fd9981$d47876e2$58134@news.ziggo.nl> <109e3$55fda507$d47876e2$30929@news.ziggo.nl> <5d560$55fda6eb$d47876e2$37866@news.ziggo.nl> <956248d4-2f8c-475b-8e41-533370589170@googlegroups.com> <4fe26$55fe0126$d47876e2$49025@news.ziggo.nl> <9c80f$55feb011$d47876e2$2668@news.ziggo.nl> <6d8e8$55fec8fa$d47876e2$62254@news.ziggo.nl> Message-ID: Just to be clear on this, the code you have to write doesn't need to be truely parallel. It must be parallel in potential, so it should be able to execute independenlty from each other and out of order. Bye, Skybuck. From marko at pacujo.net Mon Sep 21 02:56:44 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 21 Sep 2015 09:56:44 +0300 Subject: Lightwight socket IO wrapper References: <20150921015514.GA70236@cskk.homeip.net> <876134e683.fsf@elektro.pacujo.net> Message-ID: <87fv28p8er.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Sep 21, 2015 at 2:39 PM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> If you write a packet of data, then write another one, and another, >>> and another, and another, without waiting for responses, Nagling >>> should combine them automatically. [...] >> >> Unfortunately, Nagle and delayed ACK, which are both defaults, don't go >> well together (you get nasty 200-millisecond hickups). > > Only in the write-write-read scenario. Which is the case you brought up. Ideally, application code should be oblivious to the inner heuristics of the TCP implementation. IOW, write-write-read is perfectly valid and shouldn't lead to performance degradation. Unfortunately, the socket API doesn't provide a standard way for the application to tell the kernel that it is done sending for now. Linux's TCP_CORK+TCP_NODELAY is a nonstandard way but does the job quite nicely. >> As for the topic, TCP doesn't need wrappers to abstract away the >> difficult bits. That's a superficially good idea that leads to >> trouble. > > Depends what you're doing - if you're working with a higher level > protocol like HTTP, then abstracting away the difficult bits of TCP is > part of abstracting away the difficult bits of HTTP, and something > like 'requests' is superb. Naturally, a higher-level protocol hides the lower-level protocol. It in turn has intricacies of its own. Unfortunately, Python's stdlib HTTP facilities are too naive (ie, blocking, incompatible with asyncio) to be usable. Marko From michael at stroeder.com Mon Sep 21 03:02:22 2015 From: michael at stroeder.com (=?UTF-8?Q?Michael_Str=c3=b6der?=) Date: Mon, 21 Sep 2015 09:02:22 +0200 Subject: Lightwight socket IO wrapper In-Reply-To: <876134e683.fsf@elektro.pacujo.net> References: <20150921015514.GA70236@cskk.homeip.net> <876134e683.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > I recommend using socket.TCP_CORK with socket.TCP_NODELAY where they are > available (Linux). If these options are not available are both option constants also not available? Or does the implementation have to look into sys.platform? Ciao, Michael. From rosuav at gmail.com Mon Sep 21 03:57:19 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Sep 2015 17:57:19 +1000 Subject: Lightwight socket IO wrapper In-Reply-To: <20150921062713.GA77399@cskk.homeip.net> References: <20150921062713.GA77399@cskk.homeip.net> Message-ID: On Mon, Sep 21, 2015 at 4:27 PM, Cameron Simpson wrote: > I don't like embedding arbitrary size limits in protocols or data formats if > I can easily avoid it. So (for my home grown binary protocols) I encode > unsigned integers as big endian octets with the top bit meaning "another > octet follows" and the bottom 7 bits going to the value. So my packets look > like: > > encoded(length)data > > For sizes below 128, one byte of length. For sizes 128-16383, two bytes. And > so on. Compact yet unbounded. Ah, the MIDI Variable-Length Integer. Decent. It's generally a lot faster to do a read(2) than a loop with any number of read(1), and you get some kind of bound on your allocations. Whether that's important to you or not is another question, but certainly your chosen encoding is a good way of allowing arbitrary integer values. ChrisA From marko at pacujo.net Mon Sep 21 03:57:24 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 21 Sep 2015 10:57:24 +0300 Subject: Lightwight socket IO wrapper References: <20150921015514.GA70236@cskk.homeip.net> <876134e683.fsf@elektro.pacujo.net> Message-ID: <87a8sgp5ln.fsf@elektro.pacujo.net> Michael Str?der : > Marko Rauhamaa wrote: >> I recommend using socket.TCP_CORK with socket.TCP_NODELAY where they >> are available (Linux). > > If these options are not available are both option constants also not > available? Or does the implementation have to look into sys.platform? >>> import socket >>> 'TCP_CORK' in dir(socket) True The TCP_NODELAY option is available everywhere but has special semantics with TCP_CORK. Marko From marko at pacujo.net Mon Sep 21 03:59:39 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 21 Sep 2015 10:59:39 +0300 Subject: Lightwight socket IO wrapper References: <20150921062713.GA77399@cskk.homeip.net> Message-ID: <876134p5hw.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Sep 21, 2015 at 4:27 PM, Cameron Simpson wrote: >> For sizes below 128, one byte of length. For sizes 128-16383, two bytes. And >> so on. Compact yet unbounded. > > [...] > > It's generally a lot faster to do a read(2) than a loop with any > number of read(1), and you get some kind of bound on your allocations. > Whether that's important to you or not is another question, but > certainly your chosen encoding is a good way of allowing arbitrary > integer values. You can read a full buffer even if you have a variable-length length encoding. Marko From rosuav at gmail.com Mon Sep 21 04:07:23 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Sep 2015 18:07:23 +1000 Subject: Lightwight socket IO wrapper In-Reply-To: <876134p5hw.fsf@elektro.pacujo.net> References: <20150921062713.GA77399@cskk.homeip.net> <876134p5hw.fsf@elektro.pacujo.net> Message-ID: On Mon, Sep 21, 2015 at 5:59 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Sep 21, 2015 at 4:27 PM, Cameron Simpson wrote: >>> For sizes below 128, one byte of length. For sizes 128-16383, two bytes. And >>> so on. Compact yet unbounded. >> >> [...] >> >> It's generally a lot faster to do a read(2) than a loop with any >> number of read(1), and you get some kind of bound on your allocations. >> Whether that's important to you or not is another question, but >> certainly your chosen encoding is a good way of allowing arbitrary >> integer values. > > You can read a full buffer even if you have a variable-length length > encoding. Not sure what you mean there. Unless you can absolutely guarantee that you didn't read too much, or can absolutely guarantee that your buffering function will be the ONLY way anything reads from the socket, buffering is a problem. ChrisA From michael at stroeder.com Mon Sep 21 04:29:45 2015 From: michael at stroeder.com (=?UTF-8?Q?Michael_Str=c3=b6der?=) Date: Mon, 21 Sep 2015 10:29:45 +0200 Subject: Lightwight socket IO wrapper In-Reply-To: <87a8sgp5ln.fsf@elektro.pacujo.net> References: <20150921015514.GA70236@cskk.homeip.net> <876134e683.fsf@elektro.pacujo.net> <87a8sgp5ln.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Michael Str?der : > >> Marko Rauhamaa wrote: >>> I recommend using socket.TCP_CORK with socket.TCP_NODELAY where they >>> are available (Linux). >> >> If these options are not available are both option constants also not >> available? Or does the implementation have to look into sys.platform? > > >>> import socket > >>> 'TCP_CORK' in dir(socket) > True On which platform was this done? To rephrase myquestion: How to automagically detect whether TCP_CORK is really available on a platform? 'TCP_CORK' in dir(socket) or catch AttributeError sys.platform=='linux2' hoping that Linux 2.1 or prior is not around anymore... ... Ciao, Michael. From marko at pacujo.net Mon Sep 21 04:38:38 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 21 Sep 2015 11:38:38 +0300 Subject: Lightwight socket IO wrapper References: <20150921062713.GA77399@cskk.homeip.net> <876134p5hw.fsf@elektro.pacujo.net> Message-ID: <871tdsp3ox.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Sep 21, 2015 at 5:59 PM, Marko Rauhamaa wrote: >> You can read a full buffer even if you have a variable-length length >> encoding. > > Not sure what you mean there. Unless you can absolutely guarantee that > you didn't read too much, or can absolutely guarantee that your > buffering function will be the ONLY way anything reads from the > socket, buffering is a problem. Only one reader can read a socket safely at any given time so mutual exclusion is needed. If you read "too much," the excess can be put in the application's read buffer where it is available for whoever wants to process the next message. Marko From rosuav at gmail.com Mon Sep 21 04:45:48 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Sep 2015 18:45:48 +1000 Subject: Lightwight socket IO wrapper In-Reply-To: <871tdsp3ox.fsf@elektro.pacujo.net> References: <20150921062713.GA77399@cskk.homeip.net> <876134p5hw.fsf@elektro.pacujo.net> <871tdsp3ox.fsf@elektro.pacujo.net> Message-ID: On Mon, Sep 21, 2015 at 6:38 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Sep 21, 2015 at 5:59 PM, Marko Rauhamaa wrote: >>> You can read a full buffer even if you have a variable-length length >>> encoding. >> >> Not sure what you mean there. Unless you can absolutely guarantee that >> you didn't read too much, or can absolutely guarantee that your >> buffering function will be the ONLY way anything reads from the >> socket, buffering is a problem. > > Only one reader can read a socket safely at any given time so mutual > exclusion is needed. > > If you read "too much," the excess can be put in the application's read > buffer where it is available for whoever wants to process the next > message. Which works only if you have a single concept of "application's read buffer". That means that you have only one place that can ever read data. Imagine a From marko at pacujo.net Mon Sep 21 04:47:11 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 21 Sep 2015 11:47:11 +0300 Subject: Lightwight socket IO wrapper References: <20150921015514.GA70236@cskk.homeip.net> <876134e683.fsf@elektro.pacujo.net> <87a8sgp5ln.fsf@elektro.pacujo.net> Message-ID: <87wpvknoq8.fsf@elektro.pacujo.net> Michael Str?der : > Marko Rauhamaa wrote: >> Michael Str?der : >> >>> Marko Rauhamaa wrote: >>>> I recommend using socket.TCP_CORK with socket.TCP_NODELAY where they >>>> are available (Linux). >>> >>> If these options are not available are both option constants also not >>> available? Or does the implementation have to look into sys.platform? >> >> >>> import socket >> >>> 'TCP_CORK' in dir(socket) >> True > > On which platform was this done? Python3 on Fedora 21. Python2 on RHEL4. Sorry, don't have non-Linux machines to try. > How to automagically detect whether TCP_CORK is really available on a > platform? I sure hope 'TCP_CORK' in dir(socket) evaluates to False on non-Linux machines. Marko From marko at pacujo.net Mon Sep 21 04:48:17 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 21 Sep 2015 11:48:17 +0300 Subject: Lightwight socket IO wrapper References: <20150921062713.GA77399@cskk.homeip.net> <876134p5hw.fsf@elektro.pacujo.net> <871tdsp3ox.fsf@elektro.pacujo.net> Message-ID: <87si68nooe.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Sep 21, 2015 at 6:38 PM, Marko Rauhamaa wrote: >> Only one reader can read a socket safely at any given time so mutual >> exclusion is needed. >> >> If you read "too much," the excess can be put in the application's read >> buffer where it is available for whoever wants to process the next >> message. > > Which works only if you have a single concept of "application's read > buffer". Well, the socket's read buffer. Marko From marko at pacujo.net Mon Sep 21 04:49:46 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 21 Sep 2015 11:49:46 +0300 Subject: Lightwight socket IO wrapper References: <20150921062713.GA77399@cskk.homeip.net> <876134p5hw.fsf@elektro.pacujo.net> <871tdsp3ox.fsf@elektro.pacujo.net> <87si68nooe.fsf@elektro.pacujo.net> Message-ID: <87lhc0nolx.fsf@elektro.pacujo.net> Marko Rauhamaa : > Chris Angelico : > >> On Mon, Sep 21, 2015 at 6:38 PM, Marko Rauhamaa wrote: >>> Only one reader can read a socket safely at any given time so mutual >>> exclusion is needed. >>> >>> If you read "too much," the excess can be put in the application's read >>> buffer where it is available for whoever wants to process the next >>> message. >> >> Which works only if you have a single concept of "application's read >> buffer". > > Well, the socket's read buffer. To be exact, the application should associate a read buffer with each socket. Marko From rosuav at gmail.com Mon Sep 21 04:50:08 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Sep 2015 18:50:08 +1000 Subject: Lightwight socket IO wrapper In-Reply-To: <871tdsp3ox.fsf@elektro.pacujo.net> References: <20150921062713.GA77399@cskk.homeip.net> <876134p5hw.fsf@elektro.pacujo.net> <871tdsp3ox.fsf@elektro.pacujo.net> Message-ID: On Mon, Sep 21, 2015 at 6:38 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Sep 21, 2015 at 5:59 PM, Marko Rauhamaa wrote: >>> You can read a full buffer even if you have a variable-length length >>> encoding. >> >> Not sure what you mean there. Unless you can absolutely guarantee that >> you didn't read too much, or can absolutely guarantee that your >> buffering function will be the ONLY way anything reads from the >> socket, buffering is a problem. > > Only one reader can read a socket safely at any given time so mutual > exclusion is needed. > > If you read "too much," the excess can be put in the application's read > buffer where it is available for whoever wants to process the next > message. Oops, premature send - sorry! Trying again. Which works only if you have a single concept of "application's read buffer". That means that you have only one place that can ever read data. Imagine a protocol that mainly consists of lines of text terminated by CRLF, but allows binary data to be transmitted by sending "DATA N\r\n" followed by N arbitrary bytes. The simplest and most obvious way to handle the base protocol is to buffer your reads as much as possible, but that means potentially reading the beginning of the data stream along with its header. You therefore cannot use the basic read() method to read that data - you have to use something from your line-based wrapper, even though you are decidedly NOT using a line-based protocol at that point. That's what I mean by guaranteeing that your buffering function is the only way data gets read from the socket. Either that, or you need an underlying facility for un-reading a bunch of data - de-buffering and making it readable again. ChrisA From gengyangcai at gmail.com Mon Sep 21 05:38:29 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 21 Sep 2015 02:38:29 -0700 (PDT) Subject: A photo/image/video sharing app in Python Message-ID: <2ee220b0-dfd2-4701-8760-71af9eee9f67@googlegroups.com> Hello, So, I want to use Python to design a photo/image/video sharing app that i can test on users. I have Python 2.7.10, 3.3.2 and 3.3.4 downloaded and am using a Mac OS X Yosemite Version 10.10.2 laptop and having gone through the Python course on CodeAcademy a while ago (though I probably forgot most of it my now) How / where do i start ? Any suggestions / resources / recommendations appreciated. Thanks a lot ! Cai Gengyang From grahn+nntp at snipabacken.se Mon Sep 21 07:25:21 2015 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 21 Sep 2015 11:25:21 GMT Subject: Lightwight socket IO wrapper References: Message-ID: On Mon, 2015-09-21, Dennis Lee Bieber wrote: > On Sun, 20 Sep 2015 23:36:30 +0100, "James Harris" > declaimed the following: ... >>I thought UDP would deliver (or drop) a whole datagram but cannot find >>anything in the Python documentaiton to guarantee that. In fact >>documentation for the send() call says that apps are responsible for >>checking that all data has been sent. They may mean that to apply to >>stream protocols only but it doesn't state that. (Of course, UDP >>datagrams are limited in size so the call may validly indicate >>incomplete transmission even when the first part of a big message is >>sent successfully.) >> > Looking in the wrong documentation > > You probably should be looking at the UDP RFC. Or maybe just > > http://www.diffen.com/difference/TCP_vs_UDP > > """ > Packets are sent individually and are checked for integrity only if they > arrive. Packets have definite boundaries which are honored upon receipt, > meaning a read operation at the receiver socket will yield an entire > message as it was originally sent. > """ > > Even if the IP layer has to fragment a UDP packet to meet limits of the > transport media, it should put them back together on the other end before > passing it up to the UDP layer. To my knowledge, UDP does not have a size > limit on the message (well -- a 16-bit length field in the UDP header). So they are "limited in size" like the OP wrote. (A TCP stream OTOH is potentially infinite.) But also, the IPv4 RFC says: All hosts must be prepared to accept datagrams of up to 576 octets (whether they arrive whole or in fragments). It is recommended that hosts only send datagrams larger than 576 octets if they have assurance that the destination is prepared to accept the larger datagrams. As for "all or nothing" with UDP datagrams, you also have the socket layer case where the user does read() into a 1000 octet buffer and the datagram was 1200 octets. With BSD sockets you can (if you try) detect this, but the extra 200 octets are lost forever. > But since it /is/ "got it all" or "dropped" with no inherent confirmation, one > would have to embed their own protocol within it -- sequence numbers with > ACK/NAK, for example. Problem: if using LARGE UDP packets, this protocol > would mean having LARGE resends should packets be dropped or arrive out of > sequence (and since the ACK/NAK could be dropped too, you may have to > handle the case of a duplicated packet -- also large). > > TCP is a stream protocol -- the protocol will ensure that all data > arrives, and that it arrives in order, but does not enforce any boundaries > on the data; what started as a relatively large packet at one end may > arrive as lots of small packets due to intermediate transport limits (one > can visualize a worst case: each TCP packet is broken up to fit Hollerith > cards; 20bytes for header and 60 bytes of data -- then fed to a reader and > sent on AS-IS). The problem is IMO more this: the chunks of data that the application writes doesn't map to what the other application reads. In the lower layers, I don't expect TCP segments to be split, and IP fragmentation (if it happens at all) operates at an even lower level. However the end result is still just as you write: > Boundaries are the end-user responsibility... line endings > (look at SMTP, where an email message ends on a line containing just a ".") > or embedded length counter (not the TCP packet length). > >>Receiving no bytes is taken as indicating the end of the communication. >>That's OK for TCP but not for UDP so there should be a way to >>distinguish between the end of data and receiving an empty datagram. >> > I don't believe UDP supports a truly empty datagram (length of 0) -- > presuming a sending stack actually sends one, the receiving stack will > probably drop it as there is no data to pass on to a client UDP datagrams of length 0 work (just tried it on Linux). There's nothing special about it. > (there is a PR > at work because we have a UDP driver that doesn't drop 0-length messages, > but also can't deliver them -- so the circular buffer might fill with > undeliverable headers) Those messages should be delivered to the receiving socket, in the sense that they are sanity-checked, used to wake up the application and mark the socket readable, fill up one entry in the read queue and so on ... Of course your system at work may have the rights to be more restrictive, if it's special-purpose. /Jorgen -- // Jorgen Grahn O o . From breamoreboy at yahoo.co.uk Mon Sep 21 07:29:34 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 21 Sep 2015 12:29:34 +0100 Subject: Problem installing pip In-Reply-To: References: Message-ID: On 18/09/2015 06:54, Stephan wrote: > Good Morning, > > I?ve tried ten times to install pip with no success in windows 10 using > python 64bit version. > > Is there a solution available? > > I?m looking forward hearing you soon. > The obvious solution is to get a version of Python like 3.4.3 or 3.5.0 which comes with pip. Failing that please cut and paste what you tried and what went wrong, we're not mind readers :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From arsh840 at gmail.com Mon Sep 21 07:37:43 2015 From: arsh840 at gmail.com (Great Avenger Singh) Date: Mon, 21 Sep 2015 04:37:43 -0700 (PDT) Subject: A photo/image/video sharing app in Python In-Reply-To: <2ee220b0-dfd2-4701-8760-71af9eee9f67@googlegroups.com> References: <2ee220b0-dfd2-4701-8760-71af9eee9f67@googlegroups.com> Message-ID: On Monday, 21 September 2015 15:08:53 UTC+5:30, Cai Gengyang wrote: > Hello, > > > So, I want to use Python to design a photo/image/video sharing app that i can >test on users. One Example is DropBox doing this at very large extent. ;) > I have Python 2.7.10, 3.3.2 and 3.3.4 downloaded and am using a Mac OS X Yosemite Version 10.10.2 laptop and having gone through the Python course on CodeAcademy a while ago (though I probably forgot most of it my now) > > How / where do i start ? Any suggestions / resources / recommendations >appreciated. As you have not mentioned how you want your application to be, One way is using Dropbox/Google-drive Python API so user can get space somewhere online and generate Public Link to Share file. Or If User want to share it locally with other computers using LAN/Bluetooth?WI-FI, If you want to make it use with Android or IOS Kivy is there for you.(I am fantasized with Kivy!) Or First you have to decide what kind of Architecture you want with your application or features. I guess my answer is vague so your question was ;) From jeanmichel at sequans.com Mon Sep 21 08:01:55 2015 From: jeanmichel at sequans.com (jmp) Date: Mon, 21 Sep 2015 14:01:55 +0200 Subject: True == 1 weirdness In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> Message-ID: On 09/16/2015 02:53 PM, Jussi Piitulainen wrote: > But now I expect to see a long thread about whether > chained comparisons are a natural thing to have in the language. Nice forecast by the way. JM From python at mrabarnett.plus.com Mon Sep 21 08:26:49 2015 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 21 Sep 2015 13:26:49 +0100 Subject: Lightwight socket IO wrapper In-Reply-To: <87wpvknoq8.fsf@elektro.pacujo.net> References: <20150921015514.GA70236@cskk.homeip.net> <876134e683.fsf@elektro.pacujo.net> <87a8sgp5ln.fsf@elektro.pacujo.net> <87wpvknoq8.fsf@elektro.pacujo.net> Message-ID: <55FFF789.2090906@mrabarnett.plus.com> On 2015-09-21 09:47, Marko Rauhamaa wrote: > Michael Str?der : > >> Marko Rauhamaa wrote: >>> Michael Str?der : >>> >>>> Marko Rauhamaa wrote: >>>>> I recommend using socket.TCP_CORK with socket.TCP_NODELAY where they >>>>> are available (Linux). >>>> >>>> If these options are not available are both option constants also not >>>> available? Or does the implementation have to look into sys.platform? >>> >>> >>> import socket >>> >>> 'TCP_CORK' in dir(socket) >>> True >> >> On which platform was this done? > > Python3 on Fedora 21. > Python2 on RHEL4. > > Sorry, don't have non-Linux machines to try. > >> How to automagically detect whether TCP_CORK is really available on a >> platform? > > I sure hope 'TCP_CORK' in dir(socket) evaluates to False on non-Linux > machines. > On Windows 10: Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> 'TCP_CORK' in dir(socket) False >>> From gengyangcai at gmail.com Mon Sep 21 08:53:34 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 21 Sep 2015 05:53:34 -0700 (PDT) Subject: A photo/image/video sharing app in Python In-Reply-To: References: <2ee220b0-dfd2-4701-8760-71af9eee9f67@googlegroups.com> Message-ID: <3de6acc7-6c55-4f78-adb9-960e21bb3617@googlegroups.com> On Monday, September 21, 2015 at 7:38:21 PM UTC+8, Great Avenger Singh wrote: > On Monday, 21 September 2015 15:08:53 UTC+5:30, Cai Gengyang wrote: > > Hello, > > > > > > So, I want to use Python to design a photo/image/video sharing app that i can >test on users. > > One Example is DropBox doing this at very large extent. ;) > > > > I have Python 2.7.10, 3.3.2 and 3.3.4 downloaded and am using a Mac OS X Yosemite Version 10.10.2 laptop and having gone through the Python course on CodeAcademy a while ago (though I probably forgot most of it my now) > > > > How / where do i start ? Any suggestions / resources / recommendations >appreciated. > > As you have not mentioned how you want your application to be, > One way is using Dropbox/Google-drive Python API so user can get space somewhere online and generate Public Link to Share file. > > Or If User want to share it locally with other computers using LAN/Bluetooth?WI-FI, > > If you want to make it use with Android or IOS Kivy is there for you.(I am fantasized with Kivy!) > > Or First you have to decide what kind of Architecture you want with your application or features. I guess my answer is vague so your question was ;) Ok, so basically these are the features I want the app to have : 1) A system where users can upload photos/images/videos of their loved ones and family onto the web-based app (It's going to be web-based website) 2) A system where where the users can then edit these photos/images/videos into short , funny cartoons/videos 3) A system where users can create an account with username/password/log in information 4) A system where users can then share and publish these pictures on the website itself using their account and also link and upload onto other traditional social networks like Facebook, Twitter and Google+ accounts and also onto their other handheld devices like IPhone , Apple Devices, Samsung handphones etc As for the architecture itself , it will probably be similar to wedpics (https://www.wedpics.com/) but better designed with gorgeous and pristine features and a system where users can edit their pictures/photos/videos into cartoons with different themes with their faces on it (funny, natural, science) --- i.e. imagine you are able to make a cartoon of your bride , family members and friends at your wedding ceremony into a funny cartoon with your faces imprinted on cartoon characters , the have these cartoons published on the website and also link with other social networks where you can publish these cartoons on them as well .... My plan is to build this and get some users to test the product by posting the product online on sites like these, hacker news, word of mouth and also invite strangers on Facebook, Googles+ and Twitter to test this prototype and continuously iterate the product according to user feedback. Hope that is detailed enough to give you an idea of how it roughly would look like ! I currently have minimal experience with programming , and have only done a course on Python on CodeAcademy(That's about it) , so I am posting here to ask for help --- where is the best place to start and resources? Thanks a lot , appreciate it ! Cai Gengyang From robin at reportlab.com Mon Sep 21 08:55:44 2015 From: robin at reportlab.com (Robin Becker) Date: Mon, 21 Sep 2015 13:55:44 +0100 Subject: problem building python 3.5 extensions for windows Message-ID: <55FFFE50.8090703@chamonix.reportlab.co.uk> I have installed VS2015; this is the full version and was a great deal of trouble to install. First time out it started whining and I had to 'repair' it. Anyhow after the 'repair' it said all was OK and no complaints. However, when I try to use it I don't see options for starting C++ projects, but instead only C#. I get an error like this trying to build for x86 or amd64 | building 'reportlab.lib._rl_accel' extension Stderr: | error: Unable to find vcvarsall.bat There is a folder "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC", but it doesn't contain any batch scripts. Document https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx claims to be about VS2015, but has as example cd "\Program Files (x86)\Microsoft Visual Studio 12.0\VC" which is presumably not for VS2015. Any ideas how to get this to work? Should I try a full reinstall of VS2015? I can start the VS2015 Developer command prompt, but it doesn't then know about the "cl" command. -- Robin Becker From nobody at nowhere.invalid Mon Sep 21 08:56:29 2015 From: nobody at nowhere.invalid (Nobody) Date: Mon, 21 Sep 2015 13:56:29 +0100 Subject: Postscript to pdf References: <201509201812.t8KICXHu004041@fido.openend.se> <201509201909.t8KJ93oU018314@fido.openend.se> <201509201952.t8KJqh7W029272@fido.openend.se> Message-ID: On Sun, 20 Sep 2015 23:11:20 +0200, Baladjy KICHENASSAMY wrote: > i tried this > > def save(): > Canevas.update() > Canevas.postscript(file=tkFileDialog.asksaveasfilename(), > colormode='color') > subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"]) > > > i got the ps file but i didn't get the pdf file :/ Check that subprocess.call() returns zero, or use subprocess.check_output() instead. Also, if this is a GUI program and you have no easy way to check what is written to stdout or stderr, try: p = subprocess.Popen(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"], stderr=subprocess.PIPE) out, err = p.communicate() if p.returncode != 0: raise RuntimeError(err) From rosuav at gmail.com Mon Sep 21 09:17:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Sep 2015 23:17:38 +1000 Subject: A photo/image/video sharing app in Python In-Reply-To: <3de6acc7-6c55-4f78-adb9-960e21bb3617@googlegroups.com> References: <2ee220b0-dfd2-4701-8760-71af9eee9f67@googlegroups.com> <3de6acc7-6c55-4f78-adb9-960e21bb3617@googlegroups.com> Message-ID: On Mon, Sep 21, 2015 at 10:53 PM, Cai Gengyang wrote: > Ok, so basically these are the features I want the app to have : > > 1) A system where users can upload photos/images/videos of their loved ones and family onto the web-based app (It's going to be web-based website) > 2) A system where where the users can then edit these photos/images/videos into short , funny cartoons/videos > 3) A system where users can create an account with username/password/log in information > 4) A system where users can then share and publish these pictures on the website itself using their account and also link and upload onto other traditional social networks like Facebook, Twitter and Google+ accounts and also onto their other handheld devices like IPhone , Apple Devices, Samsung handphones etc > > As for the architecture itself , it will probably be similar to wedpics (https://www.wedpics.com/) but better designed with gorgeous and pristine features and a system where users can edit their pictures/photos/videos into cartoons with different themes with their faces on it (funny, natural, science) --- i.e. imagine you are able to make a cartoon of your bride , family members and friends at your wedding ceremony into a funny cartoon with your faces imprinted on cartoon characters , the have these cartoons published on the website and also link with other social networks where you can publish these cartoons on them as well .... > > I currently have minimal experience with programming , and have only done a course on Python on CodeAcademy(That's about it) , so I am posting here to ask for help --- where is the best place to start and resources? > You've done the first step - figure out what you want, and (more importantly) how it's different from existing services you know about. Great! The next step, though, is to get some idea of the scope of the project. Let's take a quick run through your basic features. > 1) A system where users can upload photos/images/videos of their loved ones and family onto the web-based app (It's going to be web-based website) Creating a web site using Python is pretty easy. Grab Flask, Django, etc, and off you go. Uploading files isn't difficult, although since you're working with large files here, you'll eventually need some beefy hardware to run this on (free accounts might not have enough storage and/or bandwidth to handle lots of users). > 2) A system where where the users can then edit these photos/images/videos into short , funny cartoons/videos This one's a bit open-ended, but more importantly, it needs a lot of front-end work. Editing images in Python code won't be particularly hard; but letting your users choose how those images are put together? That's going to require a boatload of JavaScript work. How good are you at front-end design and coding? > 3) A system where users can create an account with username/password/log in information Subtly tricky to get right if you do it manually, but trivially easy to get someone else to do the work for you. Grab something like Flask-Login and the job's done. > 4) A system where users can then share and publish these pictures on the website itself using their account and also link and upload onto other traditional social networks like Facebook, Twitter and Google+ accounts and also onto their other handheld devices like IPhone , Apple Devices, Samsung handphones etc > Fundamentally, all this requires is stable URLs that people can post. That's pretty easy (esp if you're using a good framework). Making sure they work properly on mobile phones is generally a matter of starting with something simple, and then testing every change on lots of devices. It's a bit of work, but nothing unattainable. Your hardest part is #2, and sadly, that's also the part that makes or breaks this service. Without that, all you're doing is recreating FTP. So that's what you have to think about: Can you write all that front-end code? This will not be simple; it'll be a pretty big project. ChrisA From breamoreboy at yahoo.co.uk Mon Sep 21 09:27:24 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 21 Sep 2015 14:27:24 +0100 Subject: problem building python 3.5 extensions for windows In-Reply-To: <55FFFE50.8090703@chamonix.reportlab.co.uk> References: <55FFFE50.8090703@chamonix.reportlab.co.uk> Message-ID: On 21/09/2015 13:55, Robin Becker wrote: > I have installed VS2015; this is the full version and was a great deal > of trouble to install. First time out it started whining and I had to > 'repair' it. > > Anyhow after the 'repair' it said all was OK and no complaints. > > However, when I try to use it I don't see options for starting C++ > projects, but instead only C#. > > I get an error like this trying to build for x86 or amd64 > > | building 'reportlab.lib._rl_accel' extension > Stderr: | error: Unable to find vcvarsall.bat The most reported problem trying to build anything on Windows that is Python related. > > There is a folder "C:\Program Files (x86)\Microsoft Visual Studio > 14.0\VC", but it doesn't contain any batch scripts. Document > https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx claims to be > about VS2015, but has as example > > cd "\Program Files (x86)\Microsoft Visual Studio 12.0\VC" > > which is presumably not for VS2015. Correct, the folder you referenced first should contain the batch file. > > Any ideas how to get this to work? Should I try a full reinstall of > VS2015? I can start the VS2015 Developer command prompt, but it doesn't > then know about the "cl" command. I'd be inclined to go for the reinstall, painful as that might be. I've tried finding the batch file as a separate download but there's just too many hits about "download Visual Studio". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Mon Sep 21 09:36:40 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 21 Sep 2015 23:36:40 +1000 Subject: problem building python 3.5 extensions for windows In-Reply-To: References: <55FFFE50.8090703@chamonix.reportlab.co.uk> Message-ID: On Mon, Sep 21, 2015 at 11:27 PM, Mark Lawrence wrote: >> There is a folder "C:\Program Files (x86)\Microsoft Visual Studio >> 14.0\VC", but it doesn't contain any batch scripts. Document >> https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx claims to be >> about VS2015, but has as example >> >> cd "\Program Files (x86)\Microsoft Visual Studio 12.0\VC" >> >> which is presumably not for VS2015. > > > Correct, the folder you referenced first should contain the batch file. > Which indicates a possible text bug in the linked-to document. None of us can change that, though. For some actually Python-specific info, I'd recommend checking out what Steve Dower has written: http://stevedower.id.au/blog/building-for-python-3-5-part-two/ Poking around on his blog and web site might turn up some other useful info, too. I'm not a Windows guy so I can't help any more than that, sorry. ChrisA From auriocus at gmx.de Mon Sep 21 09:39:25 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 21 Sep 2015 15:39:25 +0200 Subject: Postscript to pdf In-Reply-To: References: <201509201812.t8KICXHu004041@fido.openend.se> Message-ID: Am 20.09.15 um 20:27 schrieb Baladjy KICHENASSAMY: > Hello, > > I'm using macosx, ps2pdf version i don't know :/ sorry.... > ok actually i found what is the problem... > > There is no problem with the ps file every thing is fine =) You could try ps2pdf -dEPSCrop input.ps output.pdf that should create a PDF with the papersize derived from an EPS image. Christian From dave.combinatrix at gmail.com Mon Sep 21 09:58:40 2015 From: dave.combinatrix at gmail.com (Dave Green) Date: Mon, 21 Sep 2015 14:58:40 +0100 Subject: Can't Install Python 3.5.0 Message-ID: Hi I have just spent the last few hours trying to install Python 3.5 64 bit and 32 bit as I am trying to inst?all pygame so I can learn Python. However the only versions that seems to work are Python-2.7.10 with pygame-1.91.win32-py2.7. I have tried loads of variations but nothing apart from these 2 work. They all throw up the error below. I am running Windows 10 latest release, but the problem appears to be with the handling of the import function. Unfortunately I need Python 3.5 install to follow my course book. Any suggestion would be most welcome. Thank you. Dave -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Python 3.5 NOT WORKING.PNG Type: image/png Size: 308824 bytes Desc: not available URL: From robin at reportlab.com Mon Sep 21 10:00:54 2015 From: robin at reportlab.com (Robin Becker) Date: Mon, 21 Sep 2015 15:00:54 +0100 Subject: problem building python 3.5 extensions for windows In-Reply-To: References: <55FFFE50.8090703@chamonix.reportlab.co.uk> Message-ID: <56000D96.2070400@chamonix.reportlab.co.uk> ........ > > The most reported problem trying to build anything on Windows that is Python > related. > ......... > > I'd be inclined to go for the reinstall, painful as that might be. I've tried > finding the batch file as a separate download but there's just too many hits > about "download Visual Studio". > I think that's where I'm headed. Sadly this has been the worst python upgrade for a long time in windows land. I would gladly forgo all the bells and whistles for a simple install of the C compiler, but I'm never certain that I'll be able to do cross-compiles etc etc etc :( -- Robin Becker From robin at reportlab.com Mon Sep 21 10:00:54 2015 From: robin at reportlab.com (Robin Becker) Date: Mon, 21 Sep 2015 15:00:54 +0100 Subject: problem building python 3.5 extensions for windows In-Reply-To: References: <55FFFE50.8090703@chamonix.reportlab.co.uk> Message-ID: <56000D96.2070400@chamonix.reportlab.co.uk> ........ > > The most reported problem trying to build anything on Windows that is Python > related. > ......... > > I'd be inclined to go for the reinstall, painful as that might be. I've tried > finding the batch file as a separate download but there's just too many hits > about "download Visual Studio". > I think that's where I'm headed. Sadly this has been the worst python upgrade for a long time in windows land. I would gladly forgo all the bells and whistles for a simple install of the C compiler, but I'm never certain that I'll be able to do cross-compiles etc etc etc :( -- Robin Becker From breamoreboy at yahoo.co.uk Mon Sep 21 10:30:10 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 21 Sep 2015 15:30:10 +0100 Subject: problem building python 3.5 extensions for windows In-Reply-To: <56000D96.2070400@chamonix.reportlab.co.uk> References: <55FFFE50.8090703@chamonix.reportlab.co.uk> <56000D96.2070400@chamonix.reportlab.co.uk> Message-ID: On 21/09/2015 15:00, Robin Becker wrote: > ........ >> >> The most reported problem trying to build anything on Windows that is >> Python >> related. >> > ......... >> >> I'd be inclined to go for the reinstall, painful as that might be. >> I've tried >> finding the batch file as a separate download but there's just too >> many hits >> about "download Visual Studio". >> > I think that's where I'm headed. > > Sadly this has been the worst python upgrade for a long time in windows > land. I would gladly forgo all the bells and whistles for a simple > install of the C compiler, but I'm never certain that I'll be able to do > cross-compiles etc etc etc :( You used to be able to work around the "can't find vcvarsall.bat" problem by hard coding the path to it, but that now fails with some other obscure message, so I've given up trying to build anything other than core Python. An essential site for anybody trying to do serious work on Windows is Christoph Gohlke's "Unofficial Windows Binaries for Python Extension Packages" at http://www.lfd.uci.edu/~gohlke/pythonlibs/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From phil at riverbankcomputing.com Mon Sep 21 11:01:51 2015 From: phil at riverbankcomputing.com (Phil Thompson) Date: Mon, 21 Sep 2015 16:01:51 +0100 Subject: problem building python 3.5 extensions for windows In-Reply-To: <56000D96.2070400@chamonix.reportlab.co.uk> References: <55FFFE50.8090703@chamonix.reportlab.co.uk> <56000D96.2070400@chamonix.reportlab.co.uk> Message-ID: <344F9373-2774-437C-B456-420BEDFC97CA@riverbankcomputing.com> On 21 Sep 2015, at 3:00 pm, Robin Becker wrote: > > ........ >> >> The most reported problem trying to build anything on Windows that is Python >> related. >> > ......... >> >> I'd be inclined to go for the reinstall, painful as that might be. I've tried >> finding the batch file as a separate download but there's just too many hits >> about "download Visual Studio". >> > I think that's where I'm headed. > > Sadly this has been the worst python upgrade for a long time in windows land. I would gladly forgo all the bells and whistles for a simple install of the C compiler, but I'm never certain that I'll be able to do cross-compiles etc etc etc :( I had no problems with the community edition. Just select a Custom install and select "Common Tools for Visual C++ 2015" as the only feature. That gave me command shells in the start menu for native and cross-compilers. Phil From zachary.ware+pylist at gmail.com Mon Sep 21 11:14:17 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 21 Sep 2015 10:14:17 -0500 Subject: problem building python 3.5 extensions for windows In-Reply-To: <55FFFE50.8090703@chamonix.reportlab.co.uk> References: <55FFFE50.8090703@chamonix.reportlab.co.uk> Message-ID: On Mon, Sep 21, 2015 at 7:55 AM, Robin Becker wrote: > I have installed VS2015; this is the full version and was a great deal of > trouble to install. First time out it started whining and I had to 'repair' > it. > > Anyhow after the 'repair' it said all was OK and no complaints. > > However, when I try to use it I don't see options for starting C++ projects, > but instead only C#. This ... > I get an error like this trying to build for x86 or amd64 > > | building 'reportlab.lib._rl_accel' extension > Stderr: | error: Unable to find vcvarsall.bat > > There is a folder "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC", > but it doesn't contain any batch scripts. ... and especially this make it sound like somehow the C++ options in the installer were not checked (or not enough of them were). I seem to remember having to be sure to choose options carefully, as they weren't selected by default. > Any ideas how to get this to work? Should I try a full reinstall of VS2015? > I can start the VS2015 Developer command prompt, but it doesn't then know > about the "cl" command. This also sounds like the C++ stuff just wasn't installed. I'm afraid reinstallation is probably your best bet. -- Zach From gengyangcai at gmail.com Mon Sep 21 11:16:06 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 21 Sep 2015 08:16:06 -0700 (PDT) Subject: A photo/image/video sharing app in Python In-Reply-To: References: <2ee220b0-dfd2-4701-8760-71af9eee9f67@googlegroups.com> <3de6acc7-6c55-4f78-adb9-960e21bb3617@googlegroups.com> Message-ID: <512780c8-64e2-403f-87b7-cc95ab8eaeae@googlegroups.com> Hi ChrisA, 1) A system where users can upload photos/images/videos of their loved ones and family onto the web-based app (It's going to be web-based website) Creating a web site using Python is pretty easy. Grab Flask, Django, etc, and off you go.Uploading files isn't difficult, although since you're working with large files here, you'll eventually need some beefy hardware to run this on (free accounts might not have enough storage and/or bandwidth to handle lots of users). ---- Sure , sounds good. 2) A system where where the users can then edit these photos/images/videos into short , funny cartoons/videos This one's a bit open-ended, but more importantly, it needs a lot of front-end work. Editing images in Python code won't be particularly hard; but letting your users choose how those images are put together? That's going to require a boatload of JavaScript work. How good are you at front-end design and coding? ---- No experience at all. Guess I'll have to learn Javascript to do this. I'll also need the capability to let users edit their photos/images and videos into great looking real-time cartoons based on themes (what technologies would I need to learn to create this?) 3) A system where users can create an account with username/password/log in information Subtly tricky to get right if you do it manually, but trivially easy to get someone else to do the work for you. Grab something like Flask-Login and the job's done. ---- Ok , sounds good 4) A system where users can then share and publish these pictures on the website itself using their account and also link and upload onto other traditional social networks like Facebook, Twitter and Google+ accounts and also onto their other handheld devices like IPhone , Apple Devices, Samsung handphones etc Fundamentally, all this requires is stable URLs that people can post. That's pretty easy (esp if you're using a good framework). Making sure they work properly on mobile phones is generally a matter of starting with something simple, and then testing every change on lots of devices. It's a bit of work, but nothing unattainable. ----- Ok, sounds good Your hardest part is #2, and sadly, that's also the part that makes or breaks this service. Without that, all you're doing is recreating FTP. So that's what you have to think about: Can you write all that front-end code? This will not be simple; it'll be a pretty big project. ----- Yup, I'll have to find a way to make it work really well. The user must have the capability to create and design really good-looking real-time video-cartoons that they can then share with other users. It's going to be what differentiates my product from other services (as far as I can tell, no other site currently in existence has such a capability) Guess the first step I would need to do is to create a basic website in Python using Flask, Django then .... Cai Gengyang From zachary.ware+pylist at gmail.com Mon Sep 21 11:17:47 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 21 Sep 2015 10:17:47 -0500 Subject: Hello In-Reply-To: References: Message-ID: On Thu, Sep 17, 2015 at 10:10 AM, moon khondkar wrote: > Hello I have problem with python installation.I downloaded python 3.5 but I cannot use it on my computer.I can not open the idle. I get something like saying "users\local settings\Application data\programs\python\python35-32\pythonw.exe is not valid win32 application. Thanks that will be help if you can solve this. This sounds suspiciously like you tried to install on Windows XP or Windows Server 2003, both of which are not supported by Python 3.5. -- Zach From baladjy at gmail.com Mon Sep 21 11:20:47 2015 From: baladjy at gmail.com (Baladjy KICHENASSAMY) Date: Mon, 21 Sep 2015 17:20:47 +0200 Subject: Postscript to pdf In-Reply-To: <201509202250.t8KMoC0h009296@fido.openend.se> References: <201509201812.t8KICXHu004041@fido.openend.se> <201509201909.t8KJ93oU018314@fido.openend.se> <201509201952.t8KJqh7W029272@fido.openend.se> <201509202250.t8KMoC0h009296@fido.openend.se> Message-ID: Hello, This is my programe : on mac i was able to output ps file but i didn't got the pdf file :/ # -*- coding: utf-8 -*- # script lecture_gif.py from Tkinter import * import tkMessageBox import Tkconstants import tkFileDialog from PIL import ImageTk import PIL.Image import os, sys import subprocess def Ouvrir(): Canevas.delete(ALL) # on efface la zone graphique filename = tkFileDialog.askopenfilename(title="Ouvrir une image",filetypes=[('gif files','.gif'),('all files','.*')]) print(filename) photo = PhotoImage(file=filename) gifdict[filename] = photo # r?f?rence print(gifdict) Canevas.create_image(0,0,anchor=NW,image=photo) Canevas.config(height=photo.height(),width=photo.width()) Mafenetre.title("Image "+str(photo.width())+" x "+str(photo.height())) def insertimage(): n=tkFileDialog.askopenfilename(filetypes = [("Image Files", ("*.jpg", "*.gif")),("JPEG",'*.jpg'),("GIF",'*.gif'),('All','*')]) img = PIL.Image.open(n) img = img.resize((229, 253)) photoimg = ImageTk.PhotoImage(img) label = Label(image=photoimg) label.image = photoimg # keep a reference! Canevas.create_image(65,320,anchor=W,image = photoimg) def insertsign(): n=tkFileDialog.askopenfilename(filetypes = [("Image Files", ("*.jpg", "*.gif")),("JPEG",'*.jpg'),("GIF",'*.gif'),('All','*')]) img = PIL.Image.open(n) img = img.resize((300, 100)) photoimg = ImageTk.PhotoImage(img) Canevas.create_image(600,500,anchor=W,image = photoimg) Canvas.pack() def Fermer(): Canevas.delete(ALL) Mafenetre.title("Image") def save(): Canevas.update() Canevas.postscript(file=tkFileDialog.asksaveasfilename(), colormode='color') subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"]) # def convert(): # ps2pdf -dEPSCrop image.ps # convert -density 300 PASSPORTQUALITE.ps output.png # class TkFileDialogExample(Tkinter.Frame): # # def __init__(self, root): # # Tkinter.Frame.__init__(self, root) # button_opt = {'fill': Tkconstants.BOTH, 'padx': 5, 'pady': 5} # Tkinter.Button(self, text='Save', command=self.asksaveasfilename).pack(**button_opt) # # self.file_opt = options = {} # options['filetypes'] = [('all files', '.*'), ('text files', '.txt')] # options['initialfile'] = 'myfile.txt' # options['parent'] = root # # def asksaveasfilename(self): # filename = tkFileDialog.asksaveasfilename(**self.file_opt) # # if filename: # return open(filename, 'w') # # if __name__=='__main__': # root = Tkinter.Tk() # TkFileDialogExample(root).pack() # root.mainloop() def Apropos(): tkMessageBox.showinfo("A propos","Tutorial") def Write(): def delete(): e1.delete(0,END) e2.delete(0,END) e3.delete(0,END) e4.delete(0,END) e5.delete(0,END) e6.delete(0,END) Canevas.delete("e1") def valider(): Canevas.create_text(315,200,anchor=W,text="Surname/Nom",fill='Black',font='Arial 14') Canevas.create_text(315,220,anchor=W,text=e1.get(),fill='Black',font='Arial 30',tags ="e1") Canevas.create_text(315,250,anchor=W,text="Given name/Pr?nom",fill='Black',font='Arial 14') Canevas.create_text(315,270,anchor=W,text=e2.get(),fill='Black',font='Arial 30',tags ="e1") Canevas.create_text(315,300,anchor=W,text="Fonction/Function",fill='Black',font='Arial 14') Canevas.create_text(315,320,anchor=W,text=e3.get(),fill='Black',font='Arial 30',tags ="e1") Canevas.create_text(470,395,anchor=W,text=e4.get(),fill='Black',font='Arial 30',tags ="e1") Canevas.create_text(500,438,anchor=W,text=e5.get(),fill='Black',font='Arial 30',tags ="e1") Canevas.create_text(228,503,anchor=W,text=e6.get(),fill='Black',font='Arial 30',tags ="e1") master = Tk() Label(master, text="Surname/Nom").grid(row=0) Label(master, text="Given name/Pr?nom").grid(row=1) Label(master, text="Fonction/Function").grid(row=2) Label(master, text="Validity Date").grid(row=3) Label(master, text="Chef").grid(row=4) Label(master, text="Student number").grid(row=5) e1 = Entry(master) e2 = Entry(master) e3 = Entry(master) e4 = Entry(master) e5 = Entry(master) e6 = Entry(master) e1.grid(row=0, column=1) e2.grid(row=1, column=1) e3.grid(row=2, column=1) e4.grid(row=3, column=1) e5.grid(row=4, column=1) e6.grid(row=5, column=1) Button(master, text='Ok', command=valider).grid(row=2, column=2, sticky=W, pady=4) Button(master, text='Delete', command=delete).grid(row=3, column=2, sticky=W, pady=4) mainloop( ) # Main window Mafenetre = Tk() Mafenetre.title("Image") # Cr?ation d'un widget Menu menubar = Menu(Mafenetre) menufichier = Menu(menubar,tearoff=0) menufichier.add_command(label="Open mask",command=Ouvrir) menufichier.add_command(label="Save mask",command=save) #menufichier.add_command(label="Convert pdf",command=convert) menufichier.add_command(label="Close mask",command=Fermer) menufichier.add_command(label="Quit",command=Mafenetre.destroy) menubar.add_cascade(label="File", menu=menufichier) menuwrite = Menu(menubar,tearoff=0) menuwrite.add_command(label="Insert informations",command=Write) menuwrite.add_command(label="Insert image",command=insertimage) menuwrite.add_command(label="Insert signature",command=insertsign) menubar.add_cascade(label="Informations", menu=menuwrite) menuaide = Menu(menubar,tearoff=0) menuaide.add_command(label="A propos",command=Apropos) menubar.add_cascade(label="Aide", menu=menuaide) # Affichage du menu Mafenetre.config(menu=menubar) # Cr?ation d'un widget Canvas Canevas = Canvas(Mafenetre) Canevas.pack(padx=5,pady=5) # Utilisation d'un dictionnaire pour conserver une r?f?rence gifdict={} Mafenetre.mainloop() 2015-09-21 0:50 GMT+02:00 Laura Creighton : > In a message of Sun, 20 Sep 2015 23:11:20 +0200, Baladjy KICHENASSAMY writes: >>well one more question :/ >> >>i tried this >> >>def save(): >> Canevas.update() >> Canevas.postscript(file=tkFileDialog.asksaveasfilename(), >>colormode='color') >> subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"]) >> >> >>i got the ps file but i didn't get the pdf file :/ > > It's 00:41 here in Sweden, and I have an 08:00 meeting. I am off to bed. > Perhaps somebody else can help now, otherwise I will be back > tomorrow. > > I've never tried to get subprocess to run as part of a savefile dialog. > Try building a tkinter app that takes a filename argument (somepostscript > file you have lying around) and then push the button, in the same dir > makes a pdf of your ps using subprocess. > > If that works, then see about getting save to run that subprocess as > part of the save process. I am very curious about whether that can > be done -- but first check that your subprocess is working, period. > The wretched thing is slightly different between windows and linux, > and even between different linuxes, so needing to fiddle a bit here is > normal (and frustrating). > > So right now I cannot tell if your problem is 'save doesn't like > it like that' or 'your subprocess isn't working'. > > But nothing in Tkinter likes 'Canevas' -- (which is great French > but rotten English) you must have written Canvas in your code. > > Paste the real thing in next time, ok? > > Sorry I am off now, > Laura -- KICHENASSAMY Baladjy Ing?nieur en G?nie M?canique Sp?cialiste Contr?le Non Destructif et Qualification des proc?d?s sp?ciaux COSAC CND Niveau 2 RT et PT Aircelle SAFRAN Tel:06.03.72.53.12 From liannebloemen at gmail.com Mon Sep 21 11:22:13 2015 From: liannebloemen at gmail.com (liannebloemen at gmail.com) Date: Mon, 21 Sep 2015 08:22:13 -0700 (PDT) Subject: Looking for a Database Developer with 2-3 years Python experience Message-ID: <6e5f04da-2bce-4221-8bfb-d0d89041180b@googlegroups.com> Looking for Database Developer - London (up to ?30k) The Database Developer requires a wide set of database development and data integration skills, along with demonstrated excellence in problem solving and communication. Experience with Python is highly essential, as we will be developing a bespoke Django framework that allows the organisation direct access to marketing software and their client database. You will work from the London office within a company that has invested significant resources in building what is already an impressive data management team. The Database Developer works on data querying and manipulation tools, marketing software, and automatising key business procedures. It is a must to have 2-3 year's experience in programming in Python! You will be supporting and adding to the bespoke data administering systems and improving ways to integrate the data with he rest of the organisation. Key skills * Python! * Experience manipulating databases * Basic HTML knowledge * Experience with web design and web app development * Django experience * Familiar with test-driven development working practices Apply now and send your CV to james at caseltonclark.co.uk Caselton Clark are a recruitment agency specialising in Media and Events based in Central London. For our latest vacancies please visit www.caseltonclark.co.uk From edanmizrahi at gmail.com Mon Sep 21 11:27:32 2015 From: edanmizrahi at gmail.com (edanmizrahi at gmail.com) Date: Mon, 21 Sep 2015 08:27:32 -0700 (PDT) Subject: Getting PyCharm to import sklearn Message-ID: <4a8504b8-3184-4b34-9fe8-b8a23c103287@googlegroups.com> Beginner here. I'm trying to use sklearn in pycharm. When importing sklearn I get an error that reads "Import error: No module named sklearn" The project interpreter in pycharm is set to 2.7.10 (/anaconda/bin/python.app), which should be the right one. Under default preferenes, project interpreter, I see all of anacondas packages. I've double clicked and installed the packages scikit learn and sklearn. I still receive the "Import error: No module named sklearn" Does anyone know how to solve this problem? From joel.goldstick at gmail.com Mon Sep 21 11:58:58 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 21 Sep 2015 11:58:58 -0400 Subject: Getting PyCharm to import sklearn In-Reply-To: <4a8504b8-3184-4b34-9fe8-b8a23c103287@googlegroups.com> References: <4a8504b8-3184-4b34-9fe8-b8a23c103287@googlegroups.com> Message-ID: On Mon, Sep 21, 2015 at 11:27 AM, wrote: > Beginner here. > > I'm trying to use sklearn in pycharm. When importing sklearn I get an > error that reads "Import error: No module named sklearn" The project > interpreter in pycharm is set to 2.7.10 (/anaconda/bin/python.app), which > should be the right one. Under default preferenes, project interpreter, I > see all of anacondas packages. I've double clicked and installed the > packages scikit learn and sklearn. I still receive the "Import error: No > module named sklearn" > > Does anyone know how to solve this problem? > -- > https://mail.python.org/mailman/listinfo/python-list > It looks like they changed the name. Maybe this link will help you: http://scikit-learn.org/stable/install.html -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From edanmizrahi at gmail.com Mon Sep 21 12:12:12 2015 From: edanmizrahi at gmail.com (edanmizrahi at gmail.com) Date: Mon, 21 Sep 2015 09:12:12 -0700 (PDT) Subject: Getting PyCharm to import sklearn In-Reply-To: References: <4a8504b8-3184-4b34-9fe8-b8a23c103287@googlegroups.com> Message-ID: <62b91554-8aee-4002-a96e-3adbfb3e964f@googlegroups.com> On Monday, September 21, 2015 at 9:00:16 AM UTC-7, Joel Goldstick wrote: > On Mon, Sep 21, 2015 at 11:27 AM, wrote: > Beginner here. > > > > I'm trying to use sklearn in pycharm. When importing sklearn I get an error that reads "Import error: No module named sklearn" The project interpreter in pycharm is set to 2.7.10 (/anaconda/bin/python.app), which should be the right one. Under default preferenes, project interpreter, I see all of anacondas packages. I've double clicked and installed the packages scikit learn and sklearn. I still receive the "Import error: No module named sklearn" > > > > Does anyone know how to solve this problem? > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > It looks like they changed the name.? Maybe this link will help you: > > > http://scikit-learn.org/stable/install.html > > > -- > > > > Joel Goldstick > http://joelgoldstick.com Thanks Joel. 1. In the terminal I get: Requirement already up-to-date: scikit-learn in /anaconda/lib/python2.7/site-packages" 2. In pycharm, a simple: import sklearn print sklearn.__file__ I get.. 3. /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/EdanMizrahi/PycharmProjects/untitled3/tryagain Traceback (most recent call last): File "/Users/EdanMizrahi/PycharmProjects/untitled3/tryagain", line 1, in import sklearn ImportError: No module named sklearn Process finished with exit code 1 From edanmizrahi at gmail.com Mon Sep 21 12:27:51 2015 From: edanmizrahi at gmail.com (edanmizrahi at gmail.com) Date: Mon, 21 Sep 2015 09:27:51 -0700 (PDT) Subject: Getting PyCharm to import sklearn In-Reply-To: <62b91554-8aee-4002-a96e-3adbfb3e964f@googlegroups.com> References: <4a8504b8-3184-4b34-9fe8-b8a23c103287@googlegroups.com> <62b91554-8aee-4002-a96e-3adbfb3e964f@googlegroups.com> Message-ID: <3548cb63-c92a-4551-8916-9c6da8d56269@googlegroups.com> On Monday, September 21, 2015 at 9:12:43 AM UTC-7, edanm... at gmail.com wrote: > On Monday, September 21, 2015 at 9:00:16 AM UTC-7, Joel Goldstick wrote: > > On Mon, Sep 21, 2015 at 11:27 AM, wrote: > > Beginner here. > > > > > > > > I'm trying to use sklearn in pycharm. When importing sklearn I get an error that reads "Import error: No module named sklearn" The project interpreter in pycharm is set to 2.7.10 (/anaconda/bin/python.app), which should be the right one. Under default preferenes, project interpreter, I see all of anacondas packages. I've double clicked and installed the packages scikit learn and sklearn. I still receive the "Import error: No module named sklearn" > > > > > > > > Does anyone know how to solve this problem? > > > > -- > > > > https://mail.python.org/mailman/listinfo/python-list > > > > > > It looks like they changed the name.? Maybe this link will help you: > > > > > > http://scikit-learn.org/stable/install.html > > > > > > -- > > > > > > > > Joel Goldstick > > http://joelgoldstick.com > > Thanks Joel. > 1. In the terminal I get: Requirement already up-to-date: scikit-learn in /anaconda/lib/python2.7/site-packages" > > 2. In pycharm, a simple: > import sklearn > print sklearn.__file__ > > I get.. > > 3. /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/EdanMizrahi/PycharmProjects/untitled3/tryagain > Traceback (most recent call last): > File "/Users/EdanMizrahi/PycharmProjects/untitled3/tryagain", line 1, in > import sklearn > ImportError: No module named sklearn > > Process finished with exit code 1 Nevermind. Got it to work. Thanks again Joel! From robin at reportlab.com Mon Sep 21 12:54:15 2015 From: robin at reportlab.com (Robin Becker) Date: Mon, 21 Sep 2015 17:54:15 +0100 Subject: problem building python 3.5 extensions for windows In-Reply-To: References: <55FFFE50.8090703@chamonix.reportlab.co.uk> Message-ID: <56003637.2040808@chamonix.reportlab.co.uk> ......... > > This also sounds like the C++ stuff just wasn't installed. I'm afraid > reinstallation is probably your best bet. > I used the default installation, but it failed first time around (perhaps a network thing) and I stupidly assumed 'repair' would work. After a full reinstallation at least vcvarsall is present and I can at least get the amd64/x86 compilers to work with bdist_wheel (I didn't get any errors from using my already compiled relocatable libs) and I can no build the open source reportlab extensions. One simple extension https://bitbucket.org/rptlab/pyrxp doesn't get built. For some reason I get a hang in the linker for both amd64 & x86. This builds fine for 27, 33 & 34. However, I see this in the output | creating C:\ux\XB33\repos\pyRXP\build\lib.win-amd64-3.5 | C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\ux\XB33\py35_amd64\libs /LIBPATH:C:\python35\libs /LIBPATH:C:\python35 /LIBPATH:C:\ux\XB33\py35_amd64\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Win dows Kits\10\lib\10.0.10150.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\lib\um\x64" "/LIBPATH :C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" wsock32.lib /EXPORT:PyInit_pyRXPU build\temp.win-amd64-3.5\ Release\ux\XB33\repos\pyRXP\src\pyRXP.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\xmlparser.obj bui ld\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\url.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\s rc\rxp\charset.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\string16.obj build\temp.win-amd64-3.5\Re lease\ux\XB33\repos\pyRXP\src\rxp\ctype16.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\dtd.obj build \temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\input.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\s rc\rxp\stdio16.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\system.obj build\temp.win-amd64-3.5\Rele ase\ux\XB33\repos\pyRXP\src\rxp\hash.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\version.obj build\ temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\namespaces.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyR XP\src\rxp\http.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\nf16check.obj build\temp.win-amd64-3.5\ Release\ux\XB33\repos\pyRXP\src\rxp\nf16data.obj /OUT:build\lib.win-amd64-3.5\pyRXPU.cp35-win_amd64.pyd /IMPLIB:build\te mp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.lib | pyRXP.obj : warning LNK4197: export 'PyInit_pyRXPU' specified multiple times; using first specification | Creating library build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.lib and ob ject build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.exp | Generating code Stderr: | error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\amd64\\link.exe' failed with exit status 1 so there are some warnings which I don't understand. Maybe I need to do something special for pyRXP (possibly I have some ifdefs poorly configured). -- Robin Becker From robin at reportlab.com Mon Sep 21 12:54:15 2015 From: robin at reportlab.com (Robin Becker) Date: Mon, 21 Sep 2015 17:54:15 +0100 Subject: problem building python 3.5 extensions for windows In-Reply-To: References: <55FFFE50.8090703@chamonix.reportlab.co.uk> Message-ID: <56003637.2040808@chamonix.reportlab.co.uk> ......... > > This also sounds like the C++ stuff just wasn't installed. I'm afraid > reinstallation is probably your best bet. > I used the default installation, but it failed first time around (perhaps a network thing) and I stupidly assumed 'repair' would work. After a full reinstallation at least vcvarsall is present and I can at least get the amd64/x86 compilers to work with bdist_wheel (I didn't get any errors from using my already compiled relocatable libs) and I can no build the open source reportlab extensions. One simple extension https://bitbucket.org/rptlab/pyrxp doesn't get built. For some reason I get a hang in the linker for both amd64 & x86. This builds fine for 27, 33 & 34. However, I see this in the output | creating C:\ux\XB33\repos\pyRXP\build\lib.win-amd64-3.5 | C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\ux\XB33\py35_amd64\libs /LIBPATH:C:\python35\libs /LIBPATH:C:\python35 /LIBPATH:C:\ux\XB33\py35_amd64\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Win dows Kits\10\lib\10.0.10150.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\lib\um\x64" "/LIBPATH :C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" wsock32.lib /EXPORT:PyInit_pyRXPU build\temp.win-amd64-3.5\ Release\ux\XB33\repos\pyRXP\src\pyRXP.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\xmlparser.obj bui ld\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\url.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\s rc\rxp\charset.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\string16.obj build\temp.win-amd64-3.5\Re lease\ux\XB33\repos\pyRXP\src\rxp\ctype16.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\dtd.obj build \temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\input.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\s rc\rxp\stdio16.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\system.obj build\temp.win-amd64-3.5\Rele ase\ux\XB33\repos\pyRXP\src\rxp\hash.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\version.obj build\ temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\namespaces.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyR XP\src\rxp\http.obj build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\nf16check.obj build\temp.win-amd64-3.5\ Release\ux\XB33\repos\pyRXP\src\rxp\nf16data.obj /OUT:build\lib.win-amd64-3.5\pyRXPU.cp35-win_amd64.pyd /IMPLIB:build\te mp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.lib | pyRXP.obj : warning LNK4197: export 'PyInit_pyRXPU' specified multiple times; using first specification | Creating library build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.lib and ob ject build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.exp | Generating code Stderr: | error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\amd64\\link.exe' failed with exit status 1 so there are some warnings which I don't understand. Maybe I need to do something special for pyRXP (possibly I have some ifdefs poorly configured). -- Robin Becker From loic.grobol at gmail.com Mon Sep 21 13:15:51 2015 From: loic.grobol at gmail.com (=?UTF-8?B?TG/Dr2MgR3JvYm9s?=) Date: Mon, 21 Sep 2015 19:15:51 +0200 Subject: [ANN] floatrange - a range() for floats In-Reply-To: <1495821.KiLcEpmzCW@soupir> References: <1495821.KiLcEpmzCW@soupir> Message-ID: Heureux de voir que Python r?siste encore et toujours au LIMSI! Merci pour ce travail. On 21 September 2015 at 13:15, Laurent Pointal wrote: > Hello, > > I'm please to publish a small utility module allowing to produce float based > range sequences, with I hope a complete range-like interface. Because of > floating point arithmetic, floatrange allows to specify a precision for > "equality" when working with operators like 'in'. > > It is Python2 and Python3 compatible. > > PyPI: https://pypi.python.org/pypi/floatrange/ > Doc: http://floatrange.readthedocs.org/ > Project: https://perso.limsi.fr/pointal/python:floatrange > > Float arithmetic: https://docs.python.org/3/tutorial/floatingpoint.html > > A+ > Laurent Pointal. > > -- > https://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ -- Lo?c Grobol. From tropical.dude.net at gmail.com Mon Sep 21 14:41:13 2015 From: tropical.dude.net at gmail.com (tropical.dude.net at gmail.com) Date: Mon, 21 Sep 2015 11:41:13 -0700 (PDT) Subject: Problem configuring apache to run python cgi on Ubuntu 14.04 Message-ID: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> Hello everybody, I installed the LAMP stack on in Ubuntu, but I am having problems configuring Apache to run python CGI scripts. I ran: sudo a2enmod cgi I added to apache2.conf Options +ExecCGI AddHandler cgi-script .py I created index.py: #!/usr/bin/env python # -*- coding: UTF-8 -*-# enable debugging import cgitb cgitb.enable() print("Content-Type: text/html;charset=utf-8") print("Hello World!") But it is still not working. Can anybody help me out? Thanks in advance. From sohcahtoa82 at gmail.com Mon Sep 21 15:19:43 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Mon, 21 Sep 2015 12:19:43 -0700 (PDT) Subject: Problem configuring apache to run python cgi on Ubuntu 14.04 In-Reply-To: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> References: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> Message-ID: <3304d91e-e707-4b74-a9df-d1a18fe26e3c@googlegroups.com> On Monday, September 21, 2015 at 11:41:54 AM UTC-7, tropical... at gmail.com wrote: > Hello everybody, > > I installed the LAMP stack on in Ubuntu, but I am having > problems configuring Apache to run python CGI scripts. > > I ran: > sudo a2enmod cgi > > I added to apache2.conf > > Options +ExecCGI > AddHandler cgi-script .py > > > I created index.py: > #!/usr/bin/env python > # -*- coding: UTF-8 -*-# enable debugging > import cgitb > > cgitb.enable() > print("Content-Type: text/html;charset=utf-8") > print("Hello World!") > > But it is still not working. > > Can anybody help me out? > > Thanks in advance. "It isn't working" is about as useful as telling a mechanic "My car doesn't work" without giving details on what exactly is happening. What exactly isn't working? What error message are you getting? The first thing I would check is to make sure the permissions on index.py are set to allow execution. It is easy to forget to do that. From albert.visser at gmail.com Mon Sep 21 15:28:54 2015 From: albert.visser at gmail.com (Albert Visser) Date: Mon, 21 Sep 2015 21:28:54 +0200 Subject: Problem configuring apache to run python cgi on Ubuntu 14.04 In-Reply-To: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> References: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> Message-ID: On Mon, 21 Sep 2015 20:41:13 +0200, wrote: > Hello everybody, > (...) > > I created index.py: > #!/usr/bin/env python > # -*- coding: UTF-8 -*-# enable debugging > import cgitb > > cgitb.enable() > print("Content-Type: text/html;charset=utf-8") > print("Hello World!") > > But it is still not working. > > Can anybody help me out? > > Thanks in advance. Which Python are you running? If it's Python 3, change the shebang accordingly because "python" is assuming Python 2. -- Vriendelijke groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/ From tropical.dude.net at gmail.com Mon Sep 21 15:39:34 2015 From: tropical.dude.net at gmail.com (tropical.dude.net at gmail.com) Date: Mon, 21 Sep 2015 12:39:34 -0700 (PDT) Subject: Problem configuring apache to run python cgi on Ubuntu 14.04 In-Reply-To: <3304d91e-e707-4b74-a9df-d1a18fe26e3c@googlegroups.com> References: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> <3304d91e-e707-4b74-a9df-d1a18fe26e3c@googlegroups.com> Message-ID: <44059d47-ecb9-417e-b68a-caaf73fc6bda@googlegroups.com> On Monday, September 21, 2015 at 9:20:22 PM UTC+2, sohca... at gmail.com wrote: > On Monday, September 21, 2015 at 11:41:54 AM UTC-7, tropical... at gmail.com wrote: > > Hello everybody, > > > > I installed the LAMP stack on in Ubuntu, but I am having > > problems configuring Apache to run python CGI scripts. > > > > I ran: > > sudo a2enmod cgi > > > > I added to apache2.conf > > > > Options +ExecCGI > > AddHandler cgi-script .py > > > > > > I created index.py: > > #!/usr/bin/env python > > # -*- coding: UTF-8 -*-# enable debugging > > import cgitb > > > > cgitb.enable() > > print("Content-Type: text/html;charset=utf-8") > > print("Hello World!") > > > > But it is still not working. > > > > Can anybody help me out? > > > > Thanks in advance. > > "It isn't working" is about as useful as telling a mechanic "My car doesn't work" without giving details on what exactly is happening. > > What exactly isn't working? What error message are you getting? > > The first thing I would check is to make sure the permissions on index.py are set to allow execution. It is easy to forget to do that. The error message that I am receiving in my browser is: 403: You don't have permission to access /index.py on this server. The permissions of index.py is 755 From gordon at panix.com Mon Sep 21 15:41:14 2015 From: gordon at panix.com (John Gordon) Date: Mon, 21 Sep 2015 19:41:14 +0000 (UTC) Subject: Problem configuring apache to run python cgi on Ubuntu 14.04 References: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> Message-ID: In <44e870a7-9567-40ba-8a65-d6b52a8c5d25 at googlegroups.com> tropical.dude.net at gmail.com writes: > print("Content-Type: text/html;charset=utf-8") > print("Hello World!") As I recall, you must have a blank line between the headers and the content. But that may or may not be your problem, as you haven't told us exactly what is going wrong. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From tropical.dude.net at gmail.com Mon Sep 21 15:44:06 2015 From: tropical.dude.net at gmail.com (tropical.dude.net at gmail.com) Date: Mon, 21 Sep 2015 12:44:06 -0700 (PDT) Subject: Problem configuring apache to run python cgi on Ubuntu 14.04 In-Reply-To: References: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> Message-ID: On Monday, September 21, 2015 at 9:30:11 PM UTC+2, Albert Visser wrote: > On Mon, 21 Sep 2015 20:41:13 +0200, wrote: > > > Hello everybody, > > > (...) > > > > I created index.py: > > #!/usr/bin/env python > > # -*- coding: UTF-8 -*-# enable debugging > > import cgitb > > > > cgitb.enable() > > print("Content-Type: text/html;charset=utf-8") > > print("Hello World!") > > > > But it is still not working. > > > > Can anybody help me out? > > > > Thanks in advance. > > Which Python are you running? If it's Python 3, change the shebang > accordingly because "python" is assuming Python 2. > > -- > Vriendelijke groeten / Kind regards, > > Albert Visser > > Using Opera's mail client: http://www.opera.com/mail/ I am running python3.4 From tropical.dude.net at gmail.com Mon Sep 21 15:47:20 2015 From: tropical.dude.net at gmail.com (tropical.dude.net at gmail.com) Date: Mon, 21 Sep 2015 12:47:20 -0700 (PDT) Subject: Problem configuring apache to run python cgi on Ubuntu 14.04 In-Reply-To: References: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> Message-ID: On Monday, September 21, 2015 at 9:41:29 PM UTC+2, John Gordon wrote: > In <44e870a7-9567-40ba-8a65-d6b52a8c5d25 at googlegroups.com> tropical.dude.net at gmail.com writes: > > > print("Content-Type: text/html;charset=utf-8") > > print("Hello World!") > > As I recall, you must have a blank line between the headers and the > content. > > But that may or may not be your problem, as you haven't told us exactly > what is going wrong. > > -- > John Gordon A is for Amy, who fell down the stairs > gordon at panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" I am new to Ubuntu, is there a command so I can find out what the problem is? From tropical.dude.net at gmail.com Mon Sep 21 15:51:09 2015 From: tropical.dude.net at gmail.com (tropical.dude.net at gmail.com) Date: Mon, 21 Sep 2015 12:51:09 -0700 (PDT) Subject: Problem configuring apache to run python cgi on Ubuntu 14.04 In-Reply-To: References: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> Message-ID: <65b9162f-45e0-4ad8-82e9-e4813045c1cd@googlegroups.com> On Monday, September 21, 2015 at 9:47:33 PM UTC+2, tropical... at gmail.com wrote: > On Monday, September 21, 2015 at 9:41:29 PM UTC+2, John Gordon wrote: > > In <44e870a7-9567-40ba-8a65-d6b52a8c5d25 at googlegroups.com> tropical.dude.net at gmail.com writes: > > > > > print("Content-Type: text/html;charset=utf-8") > > > print("Hello World!") > > > > As I recall, you must have a blank line between the headers and the > > content. > > > > But that may or may not be your problem, as you haven't told us exactly > > what is going wrong. > > > > -- > > John Gordon A is for Amy, who fell down the stairs > > gordon at panix.com B is for Basil, assaulted by bears > > -- Edward Gorey, "The Gashlycrumb Tinies" > > I am new to Ubuntu, is there a command so I can find out what the problem is? The only error I can see right now is forbedden, you don't have permission to access /index.py on this server. From alister.nospam.ware at ntlworld.com Mon Sep 21 16:29:33 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Mon, 21 Sep 2015 20:29:33 +0000 (UTC) Subject: Problem configuring apache to run python cgi on Ubuntu 14.04 References: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> <65b9162f-45e0-4ad8-82e9-e4813045c1cd@googlegroups.com> Message-ID: On Mon, 21 Sep 2015 12:51:09 -0700, tropical.dude.net wrote: > On Monday, September 21, 2015 at 9:47:33 PM UTC+2, tropical... at gmail.com > wrote: >> On Monday, September 21, 2015 at 9:41:29 PM UTC+2, John Gordon wrote: >> > In <44e870a7-9567-40ba-8a65-d6b52a8c5d25 at googlegroups.com> >> > tropical.dude.net at gmail.com writes: >> > >> > > print("Content-Type: text/html;charset=utf-8") >> > > print("Hello World!") >> > >> > As I recall, you must have a blank line between the headers and the >> > content. >> > >> > But that may or may not be your problem, as you haven't told us >> > exactly what is going wrong. >> > >> > -- >> > John Gordon A is for Amy, who fell down the stairs >> > gordon at panix.com B is for Basil, assaulted by bears >> > -- Edward Gorey, "The Gashlycrumb >> > Tinies" >> >> I am new to Ubuntu, is there a command so I can find out what the >> problem is? > > The only error I can see right now is forbedden, you don't have > permission to access /index.py on this server. this is not a linux permissions error it is an error with the apache configuration you need to check roe acache config files (you may also want to investigate WSGI as CGI is outdated) -- Perfection is acheived only on the point of collapse. - C. N. Parkinson From auriocus at gmx.de Mon Sep 21 16:34:25 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 21 Sep 2015 22:34:25 +0200 Subject: A photo/image/video sharing app in Python In-Reply-To: <512780c8-64e2-403f-87b7-cc95ab8eaeae@googlegroups.com> References: <2ee220b0-dfd2-4701-8760-71af9eee9f67@googlegroups.com> <3de6acc7-6c55-4f78-adb9-960e21bb3617@googlegroups.com> <512780c8-64e2-403f-87b7-cc95ab8eaeae@googlegroups.com> Message-ID: Am 21.09.15 um 17:16 schrieb Cai Gengyang: > 2) A system where where the users can then edit these > photos/images/videos into short , funny cartoons/videos > > This one's a bit open-ended, but more importantly, it needs a lot of > front-end work. Editing images in Python code won't be particularly > hard; but letting your users choose how those images are put > together? That's going to require a boatload of JavaScript work. How > good are you at front-end design and coding? > > ---- No experience at all. Guess I'll have to learn Javascript to do > this. I'll also need the capability to let users edit their > photos/images and videos into great looking real-time cartoons based > on themes > > (what technologies would I need to learn to create this?) > Magic. Seriously, have you already seen a software which does approximately the image editing that you have in mind? If not, chances are that it is not possible or possible only by a group of experts. Drawing a cartoon is not a thing that a computer can do easily, much less if the only input is a photograph. Currently, cartoons are made by humans using computers, not by an algorithm. If you can make it work, you'll be a star on SIGGRAPH (a conference about image processing). Christian From invalid at invalid.invalid Mon Sep 21 16:43:13 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 21 Sep 2015 20:43:13 +0000 (UTC) Subject: A photo/image/video sharing app in Python References: <2ee220b0-dfd2-4701-8760-71af9eee9f67@googlegroups.com> <3de6acc7-6c55-4f78-adb9-960e21bb3617@googlegroups.com> <512780c8-64e2-403f-87b7-cc95ab8eaeae@googlegroups.com> Message-ID: On 2015-09-21, Cai Gengyang wrote: > I'll also need the capability to let users edit their photos/images > and videos into great looking real-time cartoons based on themes > (what technologies would I need to learn to create this?) Well, the usual technology for turning some images into greal looking real-time cartoons is to hire an animation studio and pay them tens/hundreds of thousands of dollars. Based on the names I seen in credits, I'd say there seem to be a lot of them in Korea. Alternatively, you could hire a team of artists, writers, animators and build a rendering farm. > [...] > Guess the first step I would need to do is to create a basic website > in Python using Flask, Django then .... 1) Create a basic website in Python using Flask, Django 2) ? 3) Profit! -- Grant Edwards grant.b.edwards Yow! Spreading peanut at butter reminds me of gmail.com opera!! I wonder why? From tropical.dude.net at gmail.com Mon Sep 21 17:36:23 2015 From: tropical.dude.net at gmail.com (tropical.dude.net at gmail.com) Date: Mon, 21 Sep 2015 14:36:23 -0700 (PDT) Subject: Problem configuring apache to run python cgi on Ubuntu 14.04 In-Reply-To: References: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> <65b9162f-45e0-4ad8-82e9-e4813045c1cd@googlegroups.com> Message-ID: <3a7eff56-10de-4382-aad5-1ebb3bcf6c90@googlegroups.com> On Monday, September 21, 2015 at 10:29:48 PM UTC+2, alister wrote: > On Mon, 21 Sep 2015 12:51:09 -0700, tropical.dude.net wrote: > > > On Monday, September 21, 2015 at 9:47:33 PM UTC+2, tropical... at gmail.com > > wrote: > >> On Monday, September 21, 2015 at 9:41:29 PM UTC+2, John Gordon wrote: > >> > In <44e870a7-9567-40ba-8a65-d6b52a8c5d25 at googlegroups.com> > >> > tropical.dude.net at gmail.com writes: > >> > > >> > > print("Content-Type: text/html;charset=utf-8") > >> > > print("Hello World!") > >> > > >> > As I recall, you must have a blank line between the headers and the > >> > content. > >> > > >> > But that may or may not be your problem, as you haven't told us > >> > exactly what is going wrong. > >> > > >> > -- > >> > John Gordon A is for Amy, who fell down the stairs > >> > gordon at panix.com B is for Basil, assaulted by bears > >> > -- Edward Gorey, "The Gashlycrumb > >> > Tinies" > >> > >> I am new to Ubuntu, is there a command so I can find out what the > >> problem is? > > > > The only error I can see right now is forbedden, you don't have > > permission to access /index.py on this server. > > this is not a linux permissions error it is an error with the apache > configuration you need to check roe acache config files > (you may also want to investigate WSGI as CGI is outdated) > > > > -- > Perfection is acheived only on the point of collapse. > - C. N. Parkinson Thank you very much. Can I write .py pages like in PHP or should I use a framework like Django, Web2py or TurboGears? From cs at zip.com.au Mon Sep 21 17:42:51 2015 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 22 Sep 2015 07:42:51 +1000 Subject: Lightwight socket IO wrapper In-Reply-To: References: Message-ID: <20150921214251.GA77309@cskk.homeip.net> On 21Sep2015 18:07, Chris Angelico wrote: >On Mon, Sep 21, 2015 at 5:59 PM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> On Mon, Sep 21, 2015 at 4:27 PM, Cameron Simpson wrote: >>>> For sizes below 128, one byte of length. For sizes 128-16383, two bytes. And >>>> so on. Compact yet unbounded. >>> >>> [...] >>> >>> It's generally a lot faster to do a read(2) than a loop with any >>> number of read(1), and you get some kind of bound on your allocations. >>> Whether that's important to you or not is another question, but >>> certainly your chosen encoding is a good way of allowing arbitrary >>> integer values. >> >> You can read a full buffer even if you have a variable-length length >> encoding. > >Not sure what you mean there. Unless you can absolutely guarantee that >you didn't read too much, or can absolutely guarantee that your >buffering function will be the ONLY way anything reads from the >socket, buffering is a problem. I'm using buffered io streams, so that layer will be reading in chunks. Pulling things from that buffer with fp.read(1) is cheap enough for my use. Cheers, Cameron Simpson From rosuav at gmail.com Mon Sep 21 18:36:48 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Sep 2015 08:36:48 +1000 Subject: Problem configuring apache to run python cgi on Ubuntu 14.04 In-Reply-To: <3a7eff56-10de-4382-aad5-1ebb3bcf6c90@googlegroups.com> References: <44e870a7-9567-40ba-8a65-d6b52a8c5d25@googlegroups.com> <65b9162f-45e0-4ad8-82e9-e4813045c1cd@googlegroups.com> <3a7eff56-10de-4382-aad5-1ebb3bcf6c90@googlegroups.com> Message-ID: On Tue, Sep 22, 2015 at 7:36 AM, wrote: > Thank you very much. Can I write .py pages like in PHP or should I > use a framework like Django, Web2py or TurboGears? I recommend using WSGI and a framework that uses it (my personal preference is Flask, but the above will also work). Here are a couple of simple sites: https://github.com/Rosuav/Flask1 https://github.com/Rosuav/MinstrelHall You can see them in operation here: http://rosuav.com/1/ http://minstrelhall.com/ Note how URLs are defined in the code, rather than by having a bunch of loose files (the way a PHP web site works). This makes it a lot easier to group things logically, and utility lines like redirects become very cheap. The maintenance burden is far lighter with this kind of one-file arrangement. These sites are really tiny, though, so if you have something a bit bigger, you'll probably want to split things into multiple files. Good news! You can do that, too - it's easy enough to split on any boundary you find logical. ChrisA From sol433tt at gmail.com Mon Sep 21 19:46:09 2015 From: sol433tt at gmail.com (Sol T) Date: Tue, 22 Sep 2015 09:46:09 +1000 Subject: Sqlite pragma statement "locking_mode" set to "EXCLUSIVE" by default In-Reply-To: References: Message-ID: Is anyone aware of documentation that describes how to compile various sqlite options? On Thu, Sep 17, 2015 at 2:24 PM, sol433tt wrote: > hello > > I would like to have the Sqlite pragma statement "locking_mode" set to > "EXCLUSIVE" by default (RO database). Does this need to be compiled in? How > might this be achieved? > > There is some performance to be gained. I have a number of python scripts, > and don't want to alter the pragma statement for every script. This > computer never writes to the databases. > > thank you > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjgohlke at gmail.com Mon Sep 21 20:36:39 2015 From: cjgohlke at gmail.com (cjgohlke at gmail.com) Date: Mon, 21 Sep 2015 17:36:39 -0700 (PDT) Subject: problem building python 3.5 extensions for windows In-Reply-To: References: <55FFFE50.8090703@chamonix.reportlab.co.uk> Message-ID: <7f633007-1391-4172-a022-262899537981@googlegroups.com> On Monday, September 21, 2015 at 9:54:51 AM UTC-7, Robin Becker wrote: > ......... > > > > This also sounds like the C++ stuff just wasn't installed. I'm afraid > > reinstallation is probably your best bet. > > > I used the default installation, but it failed first time around (perhaps a > network thing) and I stupidly assumed 'repair' would work. > > After a full reinstallation at least vcvarsall is present and I can at least > get the amd64/x86 compilers to work with bdist_wheel (I didn't get any errors > from using my already compiled relocatable libs) and I can no build the open > source reportlab extensions. > > One simple extension > > https://bitbucket.org/rptlab/pyrxp > > doesn't get built. For some reason I get a hang in the linker for both amd64 & > x86. This builds fine for 27, 33 & 34. > > > However, I see this in the output > > | creating C:\ux\XB33\repos\pyRXP\build\lib.win-amd64-3.5 > | C:\Program Files (x86)\Microsoft Visual Studio > 14.0\VC\BIN\amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL > /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\ux\XB33\py35_amd64\libs > /LIBPATH:C:\python35\libs /LIBPATH:C:\python35 > /LIBPATH:C:\ux\XB33\py35_amd64\PCbuild\amd64 "/LIBPATH:C:\Program Files > (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" > "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio > 14.0\VC\ATLMFC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Win > dows Kits\10\lib\10.0.10150.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows > Kits\NETFXSDK\4.6\lib\um\x64" "/LIBPATH > :C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" wsock32.lib > /EXPORT:PyInit_pyRXPU build\temp.win-amd64-3.5\ > Release\ux\XB33\repos\pyRXP\src\pyRXP.obj > build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\xmlparser.obj bui > ld\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\url.obj > build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\s > rc\rxp\charset.obj > build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\string16.obj > build\temp.win-amd64-3.5\Re > lease\ux\XB33\repos\pyRXP\src\rxp\ctype16.obj > build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\dtd.obj build > \temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\input.obj > build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\s > rc\rxp\stdio16.obj > build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\system.obj > build\temp.win-amd64-3.5\Rele > ase\ux\XB33\repos\pyRXP\src\rxp\hash.obj > build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\version.obj build\ > temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\namespaces.obj > build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyR > XP\src\rxp\http.obj > build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\rxp\nf16check.obj > build\temp.win-amd64-3.5\ > Release\ux\XB33\repos\pyRXP\src\rxp\nf16data.obj > /OUT:build\lib.win-amd64-3.5\pyRXPU.cp35-win_amd64.pyd /IMPLIB:build\te > mp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.lib > > | pyRXP.obj : warning LNK4197: export 'PyInit_pyRXPU' specified > multiple times; using first specification > | Creating library > build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.lib > and ob > ject > build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.exp > > > | Generating code > Stderr: | error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio > 14.0\\VC\\BIN\\amd64\\link.exe' failed with > exit status 1 > > so there are some warnings which I don't understand. Maybe I need to do > something special for pyRXP (possibly I have some ifdefs poorly configured). > -- > Robin Becker How long did you let it "hang"? For me the incremental linker took in the order of 30 minutes to link. I mentioned this on the Python issue tracker at . From ryan.stuart.85 at gmail.com Tue Sep 22 00:04:31 2015 From: ryan.stuart.85 at gmail.com (Ryan Stuart) Date: Tue, 22 Sep 2015 14:04:31 +1000 Subject: Sqlite pragma statement "locking_mode" set to "EXCLUSIVE" by default In-Reply-To: References: Message-ID: On Thu, Sep 17, 2015 at 2:24 PM, sol433tt wrote: > I would like to have the Sqlite pragma statement "locking_mode" set to > "EXCLUSIVE" by default (RO database). Does this need to be compiled in? How > might this be achieved? > You can issue any PRAGA statement you like using the execute method on a connection as per the documentation ( https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.execute). For information on the specific PRAGMA option you need, see https://www.sqlite.org/pragma.html#pragma_locking_mode. I can't see any mention of it being a compile time PRAGMA. Cheers > > There is some performance to be gained. I have a number of python scripts, > and don't want to alter the pragma statement for every script. This > computer never writes to the databases. > > thank you > > -- > https://mail.python.org/mailman/listinfo/python-list > > -- Ryan Stuart, B.Eng Software Engineer W: http://www.kapiche.com/ M: +61-431-299-036 -------------- next part -------------- An HTML attachment was scrubbed... URL: From gengyangcai at gmail.com Tue Sep 22 01:53:57 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 21 Sep 2015 22:53:57 -0700 (PDT) Subject: A photo/image/video sharing app in Python In-Reply-To: References: <2ee220b0-dfd2-4701-8760-71af9eee9f67@googlegroups.com> <3de6acc7-6c55-4f78-adb9-960e21bb3617@googlegroups.com> <512780c8-64e2-403f-87b7-cc95ab8eaeae@googlegroups.com> Message-ID: On Tuesday, September 22, 2015 at 4:34:45 AM UTC+8, Christian Gollwitzer wrote: > Am 21.09.15 um 17:16 schrieb Cai Gengyang: > > 2) A system where where the users can then edit these > > photos/images/videos into short , funny cartoons/videos > > > > This one's a bit open-ended, but more importantly, it needs a lot of > > front-end work. Editing images in Python code won't be particularly > > hard; but letting your users choose how those images are put > > together? That's going to require a boatload of JavaScript work. How > > good are you at front-end design and coding? > > > > ---- No experience at all. Guess I'll have to learn Javascript to do > > this. I'll also need the capability to let users edit their > > photos/images and videos into great looking real-time cartoons based > > on themes > > > > (what technologies would I need to learn to create this?) > > > > Magic. > > Seriously, have you already seen a software which does approximately the > image editing that you have in mind? If not, chances are that it is not > possible or possible only by a group of experts. Drawing a cartoon is > not a thing that a computer can do easily, much less if the only input > is a photograph. Currently, cartoons are made by humans using computers, > not by an algorithm. > > If you can make it work, you'll be a star on SIGGRAPH (a conference > about image processing). > > Christian Christian, A piece of software that would let end users easily create gorgeous real-life, real-time cartoons on the web might not exist yet. But if it were possible to invent this and get it commercialised , it could indeed become a great product that users love and pay good money to use ... You might even become a billionaire just through inventing and commercialising such a tool / system ... From rosuav at gmail.com Tue Sep 22 02:33:51 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 22 Sep 2015 16:33:51 +1000 Subject: A photo/image/video sharing app in Python In-Reply-To: References: <2ee220b0-dfd2-4701-8760-71af9eee9f67@googlegroups.com> <3de6acc7-6c55-4f78-adb9-960e21bb3617@googlegroups.com> <512780c8-64e2-403f-87b7-cc95ab8eaeae@googlegroups.com> Message-ID: On Tue, Sep 22, 2015 at 3:53 PM, Cai Gengyang wrote: > A piece of software that would let end users easily create gorgeous real-life, real-time cartoons on the web might not exist yet. But if it were possible to invent this and get it commercialised , it could indeed become a great product that users love and pay good money to use ... You might even become a billionaire just through inventing and commercialising such a tool / system ... > Yes, you might become a billionaire. Does that suggest something to you? If a project could make _that much money_, wouldn't someone have done it already? The scope of this project is enormous, and if you're to tackle it, you'll need to have a lot more than a basic notion of "hey wouldn't this be nice". ChrisA From sol433tt at gmail.com Tue Sep 22 03:12:56 2015 From: sol433tt at gmail.com (Sol T) Date: Tue, 22 Sep 2015 17:12:56 +1000 Subject: Sqlite pragma statement "locking_mode" set to "EXCLUSIVE" by default In-Reply-To: References: Message-ID: Hi, I know I can do this per connection, however how can I have it set to default? Does this need to be compiled into python? On Tue, Sep 22, 2015 at 2:04 PM, Ryan Stuart wrote: > On Thu, Sep 17, 2015 at 2:24 PM, sol433tt wrote: > >> I would like to have the Sqlite pragma statement "locking_mode" set to >> "EXCLUSIVE" by default (RO database). Does this need to be compiled in? How >> might this be achieved? >> > > You can issue any PRAGA statement you like using the execute method on a > connection as per the documentation ( > https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.execute). > For information on the specific PRAGMA option you need, see > https://www.sqlite.org/pragma.html#pragma_locking_mode. I can't see any > mention of it being a compile time PRAGMA. > > Cheers > > >> >> There is some performance to be gained. I have a number of python >> scripts, and don't want to alter the pragma statement for every script. >> This computer never writes to the databases. >> >> thank you >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > Ryan Stuart, B.Eng > Software Engineer > > W: http://www.kapiche.com/ > M: +61-431-299-036 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ian.g.kelly at gmail.com Tue Sep 22 03:31:59 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 22 Sep 2015 01:31:59 -0600 Subject: Can't Install Python 3.5.0 In-Reply-To: References: Message-ID: On Mon, Sep 21, 2015 at 7:58 AM, Dave Green wrote: > > Hi > I have just spent the last few hours trying to install Python 3.5 64 bit and 32 bit as I am > trying to install pygame so I can learn Python. However the only versions that seems to work > are Python-2.7.10 with pygame-1.91.win32-py2.7. > > I have tried loads of variations but nothing apart from these 2 work. > They all throw up the error below. > > I am running Windows 10 latest release, but the problem appears to be with the handling of the import function. Unfortunately I need Python 3.5 install to follow my course book. > > Any suggestion would be most welcome. Thank you. Dave Looks like Python 3.5 is working, but there's something wrong with your pygame installation. How did you try to install it? On the bitbucket page I see there are prebuilt Windows binaries for Python 3.4, but none for Python 3.5 yet, so it looks like you would need to build it yourself. -------------- next part -------------- An HTML attachment was scrubbed... URL: From grahn+nntp at snipabacken.se Tue Sep 22 03:47:53 2015 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 22 Sep 2015 07:47:53 GMT Subject: Lightwight socket IO wrapper References: Message-ID: On Mon, 2015-09-21, Cameron Simpson wrote: > On 21Sep2015 10:34, Chris Angelico wrote: >>If you're going to add sequencing and acknowledgements to UDP, >>wouldn't it be easier to use TCP and simply prefix every message with >>a two-byte length? > > Frankly, often yes. That's what I do. (different length encoding, but > otherwise...) > > UDP's neat if you do not care if a packet fails to arrive and if you can > guarentee that your data fits in a packet in the face of different MTUs. There's also the impact on your application. With TCP you need to consider that you may block when reading or writing, and you'll be using threads and/or a state machine driven by select() or something. UDP is more fire-and-forget. > I like TCP myself, most of the time. Another nice thing about TCP is that wil a > little effort you get to pack multiple data packets (or partial data packets) > into a network packet, etc. That, and also (again) the impact on the application. With UDP you can easily end up wasting a lot of time reading tiny datagrams one by one. It has often been a performance bottleneck for me, with certain UDP-based protocols which cannot pack multiple application-level messages into one datagram. Although perhaps you tend not to use Python in those situations. /Jorgen -- // Jorgen Grahn O o . From grahn+nntp at snipabacken.se Tue Sep 22 03:59:07 2015 From: grahn+nntp at snipabacken.se (Jorgen Grahn) Date: 22 Sep 2015 07:59:07 GMT Subject: Lightwight socket IO wrapper References: <20150921062713.GA77399@cskk.homeip.net> <876134p5hw.fsf@elektro.pacujo.net> <871tdsp3ox.fsf@elektro.pacujo.net> Message-ID: On Mon, 2015-09-21, Chris Angelico wrote: > On Mon, Sep 21, 2015 at 6:38 PM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> On Mon, Sep 21, 2015 at 5:59 PM, Marko Rauhamaa wrote: >>>> You can read a full buffer even if you have a variable-length length >>>> encoding. >>> >>> Not sure what you mean there. Unless you can absolutely guarantee that >>> you didn't read too much, or can absolutely guarantee that your >>> buffering function will be the ONLY way anything reads from the >>> socket, buffering is a problem. >> >> Only one reader can read a socket safely at any given time so mutual >> exclusion is needed. >> >> If you read "too much," the excess can be put in the application's read >> buffer where it is available for whoever wants to process the next >> message. > > Oops, premature send - sorry! Trying again. > > Which works only if you have a single concept of "application's read > buffer". That means that you have only one place that can ever read > data. Imagine a protocol that mainly consists of lines of text > terminated by CRLF, but allows binary data to be transmitted by > sending "DATA N\r\n" followed by N arbitrary bytes. The simplest and > most obvious way to handle the base protocol is to buffer your reads > as much as possible, but that means potentially reading the beginning > of the data stream along with its header. You therefore cannot use the > basic read() method to read that data - you have to use something from > your line-based wrapper, even though you are decidedly NOT using a > line-based protocol at that point. > > That's what I mean by guaranteeing that your buffering function is the > only way data gets read from the socket. Either that, or you need an > underlying facility for un-reading a bunch of data - de-buffering and > making it readable again. The way it seems to me, reading a TCP socket always ends up as: - keep an application buffer - do one socket read and append to the buffer - consume 0--more complete "entries" from the beginning of the buffer; keep the incomplete one which may exist at the end - go back and read some more when there's a chance more data has arrived So the buffer is a circular buffer of octets, which you chop up by parsing it so you can see it as a circular buffer of complete and incomplete entries or messages. At that level, yes, the line-oriented data and the binary data would coexist in the same application buffer. /Jorgen -- // Jorgen Grahn O o . From breamoreboy at yahoo.co.uk Tue Sep 22 05:15:23 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 22 Sep 2015 10:15:23 +0100 Subject: Can't Install Python 3.5.0 In-Reply-To: References: Message-ID: On 22/09/2015 08:31, Ian Kelly wrote: > On Mon, Sep 21, 2015 at 7:58 AM, Dave Green > wrote: > > > > Hi > > I have just spent the last few hours trying to install Python 3.5 64 > bit and 32 bit as I am > > trying to install pygame so I can learn Python. However the only > versions that seems to work > > are Python-2.7.10 with pygame-1.91.win32-py2.7. > > > > I have tried loads of variations but nothing apart from these 2 work. > > They all throw up the error below. > > > > I am running Windows 10 latest release, but the problem appears to be > with the handling of the import function. Unfortunately I need Python > 3.5 install to follow my course book. > > > > Any suggestion would be most welcome. Thank you. Dave > > Looks like Python 3.5 is working, but there's something wrong with your > pygame installation. How did you try to install it? On the bitbucket > page I see there are prebuilt Windows binaries for Python 3.4, but none > for Python 3.5 yet, so it looks like you would need to build it yourself. > http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame has Python 3.5 versions for 32 and 64 bit. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From gengyangcai at gmail.com Tue Sep 22 05:48:00 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 22 Sep 2015 02:48:00 -0700 (PDT) Subject: A photo/image/video sharing app in Python In-Reply-To: References: <2ee220b0-dfd2-4701-8760-71af9eee9f67@googlegroups.com> <3de6acc7-6c55-4f78-adb9-960e21bb3617@googlegroups.com> <512780c8-64e2-403f-87b7-cc95ab8eaeae@googlegroups.com> Message-ID: <60612e38-814d-470b-aed6-6900c650266b@googlegroups.com> On Tuesday, September 22, 2015 at 2:34:20 PM UTC+8, Chris Angelico wrote: > On Tue, Sep 22, 2015 at 3:53 PM, Cai Gengyang wrote: > > A piece of software that would let end users easily create gorgeous real-life, real-time cartoons on the web might not exist yet. But if it were possible to invent this and get it commercialised , it could indeed become a great product that users love and pay good money to use ... You might even become a billionaire just through inventing and commercialising such a tool / system ... > > > > Yes, you might become a billionaire. Does that suggest something to > you? If a project could make _that much money_, wouldn't someone have > done it already? The scope of this project is enormous, and if you're > to tackle it, you'll need to have a lot more than a basic notion of > "hey wouldn't this be nice". > > ChrisA Right .... Thats going to take a herculean effort and teamwork. (maybe next year) For now, I am just trying to download Django and Flask and learn how to use it. I am currently on this page --- https://www.djangoproject.com/download/ and clicked on the " Latest release: Django-1.8.4.tar.gz " link on the right side of the page For the impatient: Latest release: Django-1.8.4.tar.gz ------------------- This one! Checksums: Django-1.8.4.checksum.txt Release notes: Online documentation and managed to download a folder called django-docs-1. When I opened it ... there are a whole bunch of files and folders like "_downloads" , _images , _modules , _sources amongst others. What do I need to do next to install Django ? From robin at reportlab.com Tue Sep 22 06:14:36 2015 From: robin at reportlab.com (Robin Becker) Date: Tue, 22 Sep 2015 11:14:36 +0100 Subject: problem building python 3.5 extensions for windows In-Reply-To: <7f633007-1391-4172-a022-262899537981@googlegroups.com> References: <55FFFE50.8090703@chamonix.reportlab.co.uk> <7f633007-1391-4172-a022-262899537981@googlegroups.com> Message-ID: <56012A0C.5040805@chamonix.reportlab.co.uk> On 22/09/2015 01:36, cjgohlke at gmail.com wrote: > On Monday, September 21, 2015 at 9:54:51 AM UTC-7, Robin Becker wrote: ............ >> build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.lib >> and ob >> ject >> build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.exp >> >> >> | Generating code >> Stderr: | error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio >> 14.0\\VC\\BIN\\amd64\\link.exe' failed with >> exit status 1 >> >> so there are some warnings which I don't understand. Maybe I need to do >> something special for pyRXP (possibly I have some ifdefs poorly configured). >> -- >> Robin Becker > > How long did you let it "hang"? For me the incremental linker took in the order of 30 minutes to link. I mentioned this on the Python issue tracker at . > Thanks for the pointer Christoph. I certainly didn't let it run for 30 minutes. When I build with 2.7, 3.3 or 3.4 the whole build including reportlab stuff is over in a couple of minutes. I will try again, but a linker that takes 30 minutes to create an extension that ends up 204Kb long has to be seriously broken. Is it trying to hard? Most of the code size is in arrays for code points etc etc. -- Robin Becker From robin at reportlab.com Tue Sep 22 06:14:36 2015 From: robin at reportlab.com (Robin Becker) Date: Tue, 22 Sep 2015 11:14:36 +0100 Subject: problem building python 3.5 extensions for windows In-Reply-To: <7f633007-1391-4172-a022-262899537981@googlegroups.com> References: <55FFFE50.8090703@chamonix.reportlab.co.uk> <7f633007-1391-4172-a022-262899537981@googlegroups.com> Message-ID: <56012A0C.5040805@chamonix.reportlab.co.uk> On 22/09/2015 01:36, cjgohlke at gmail.com wrote: > On Monday, September 21, 2015 at 9:54:51 AM UTC-7, Robin Becker wrote: ............ >> build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.lib >> and ob >> ject >> build\temp.win-amd64-3.5\Release\ux\XB33\repos\pyRXP\src\pyRXPU.cp35-win_amd64.exp >> >> >> | Generating code >> Stderr: | error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio >> 14.0\\VC\\BIN\\amd64\\link.exe' failed with >> exit status 1 >> >> so there are some warnings which I don't understand. Maybe I need to do >> something special for pyRXP (possibly I have some ifdefs poorly configured). >> -- >> Robin Becker > > How long did you let it "hang"? For me the incremental linker took in the order of 30 minutes to link. I mentioned this on the Python issue tracker at . > Thanks for the pointer Christoph. I certainly didn't let it run for 30 minutes. When I build with 2.7, 3.3 or 3.4 the whole build including reportlab stuff is over in a couple of minutes. I will try again, but a linker that takes 30 minutes to create an extension that ends up 204Kb long has to be seriously broken. Is it trying to hard? Most of the code size is in arrays for code points etc etc. -- Robin Becker From gengyangcai at gmail.com Tue Sep 22 07:00:24 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 22 Sep 2015 04:00:24 -0700 (PDT) Subject: A photo/image/video sharing app in Python In-Reply-To: <60612e38-814d-470b-aed6-6900c650266b@googlegroups.com> References: <2ee220b0-dfd2-4701-8760-71af9eee9f67@googlegroups.com> <3de6acc7-6c55-4f78-adb9-960e21bb3617@googlegroups.com> <512780c8-64e2-403f-87b7-cc95ab8eaeae@googlegroups.com> <60612e38-814d-470b-aed6-6900c650266b@googlegroups.com> Message-ID: <4c1b2ead-986b-4b71-8dca-d1235e0d636f@googlegroups.com> On Tuesday, September 22, 2015 at 5:48:26 PM UTC+8, Cai Gengyang wrote: > On Tuesday, September 22, 2015 at 2:34:20 PM UTC+8, Chris Angelico wrote: > > On Tue, Sep 22, 2015 at 3:53 PM, Cai Gengyang wrote: > > > A piece of software that would let end users easily create gorgeous real-life, real-time cartoons on the web might not exist yet. But if it were possible to invent this and get it commercialised , it could indeed become a great product that users love and pay good money to use ... You might even become a billionaire just through inventing and commercialising such a tool / system ... > > > > > > > Yes, you might become a billionaire. Does that suggest something to > > you? If a project could make _that much money_, wouldn't someone have > > done it already? The scope of this project is enormous, and if you're > > to tackle it, you'll need to have a lot more than a basic notion of > > "hey wouldn't this be nice". > > > > ChrisA > > > Right .... Thats going to take a herculean effort and teamwork. (maybe next year) > > For now, I am just trying to download Django and Flask and learn how to use it. > > I am currently on this page --- https://www.djangoproject.com/download/ and clicked on the > " Latest release: Django-1.8.4.tar.gz " link on the right side of the page > > For the impatient: > > Latest release: Django-1.8.4.tar.gz ------------------- This one! > Checksums: Django-1.8.4.checksum.txt > Release notes: Online documentation > > and managed to download a folder called django-docs-1. When I opened it ... there are a whole bunch of files and folders like "_downloads" , _images , _modules , _sources amongst others. > > What do I need to do next to install Django ? Ok, so I typed these commands into "Terminal" in an attempt to install pip and use it to install Django. Can anybody let me know if I have performed this correctly ? Thanks a lot ... CaiGengYangs-MacBook-Pro:~ CaiGengYang$ pip Usage: pip [options] Commands: install Install packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. search Search PyPI for packages. wheel Build wheels from your requirements. zip DEPRECATED. Zip individual packages. unzip DEPRECATED. Unzip individual packages. help Show help for commands. General Options: -h, --help Show help. --isolated Run pip in an isolated mode, ignoring environment variables and user configuration. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. --log Path to a verbose appending log. --proxy Specify a proxy in the form [user:passwd@]proxy.server:port. --retries Maximum number of retries each connection should attempt (default 5 times). --timeout Set the socket timeout (default 15 seconds). --exists-action Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup. --trusted-host Mark this host as trusted, even though it does not have valid or any HTTPS. --cert Path to alternate CA bundle. --client-cert Path to SSL client certificate, a single file containing the private key and the certificate in PEM format. --cache-dir Store the cache data in . --no-cache-dir Disable the cache. --disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index. CaiGengYangs-MacBook-Pro:~ CaiGengYang$ pip install django You are using pip version 6.1.1, however version 7.1.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting django Downloading Django-1.8.4-py2.py3-none-any.whl (6.2MB) 100% |????????????????????????????????| 6.2MB 79kB/s Installing collected packages: django Successfully installed django-1.8.4 CaiGengYangs-MacBook-Pro:~ CaiGengYang$ From gengyangcai at gmail.com Tue Sep 22 07:07:35 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 22 Sep 2015 04:07:35 -0700 (PDT) Subject: Installing pip and django Message-ID: <431e68bd-dace-44b5-97ce-1824af62db04@googlegroups.com> So these are my results when I type these commands into "Terminal" in an attempt to install pip and django --- From the output, it seems that I have successfully installed pip and django CaiGengYangs-MacBook-Pro:~ CaiGengYang$ pip Usage: pip [options] Commands: install Install packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. search Search PyPI for packages. wheel Build wheels from your requirements. zip DEPRECATED. Zip individual packages. unzip DEPRECATED. Unzip individual packages. help Show help for commands. General Options: -h, --help Show help. --isolated Run pip in an isolated mode, ignoring environment variables and user configuration. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. --log Path to a verbose appending log. --proxy Specify a proxy in the form [user:passwd@]proxy.server:port. --retries Maximum number of retries each connection should attempt (default 5 times). --timeout Set the socket timeout (default 15 seconds). --exists-action Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup. --trusted-host Mark this host as trusted, even though it does not have valid or any HTTPS. --cert Path to alternate CA bundle. --client-cert Path to SSL client certificate, a single file containing the private key and the certificate in PEM format. --cache-dir Store the cache data in . --no-cache-dir Disable the cache. --disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index. CaiGengYangs-MacBook-Pro:~ CaiGengYang$ pip install django You are using pip version 6.1.1, however version 7.1.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting django Downloading Django-1.8.4-py2.py3-none-any.whl (6.2MB) 100% |????????????????????????????????| 6.2MB 79kB/s Installing collected packages: django Successfully installed django-1.8.4 CaiGengYangs-MacBook-Pro:~ CaiGengYang$ python Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> print(django.get_version()) 1.8.4 >>> From timgeek951 at gmail.com Tue Sep 22 07:19:49 2015 From: timgeek951 at gmail.com (Timon Rhynix) Date: Tue, 22 Sep 2015 04:19:49 -0700 (PDT) Subject: Successfully send sms with python Message-ID: <05ab0edd-7285-4aca-b603-76e94dd8f0aa@googlegroups.com> Hello, I have used pyserial, sms0.4 and other libraries to send sms via huawei E1750 modem. The code runs well and no error is thrown but the text message is not sent/delivered to the number. One of my code is as follows: import serial import time class TextMessage: def __init__(self, recipient="0123456789", message="TextMessage.content not set."): self.recipient = recipient self.content = message def setRecipient(self, number): self.recipient = number def setContent(self, message): self.content = message def connectPhone(self): conn = 'COM13' self.ser = serial.Serial(conn, 460800, timeout=5) time.sleep(1) def sendMessage(self): self.ser.write('ATZ\r') time.sleep(1) self.ser.write('AT+CMGF=1\r') time.sleep(1) self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''') time.sleep(1) self.ser.write(self.content + "\r") time.sleep(1) self.ser.write(chr(26)) time.sleep(1) print "message sent!" def disconnectPhone(self): self.ser.close() When run it, the "message sent!" is printed but no message is sent/delivered. Please assist on what I am missing. Thank you From ryan.stuart.85 at gmail.com Tue Sep 22 08:04:29 2015 From: ryan.stuart.85 at gmail.com (Ryan Stuart) Date: Tue, 22 Sep 2015 22:04:29 +1000 Subject: Sqlite pragma statement "locking_mode" set to "EXCLUSIVE" by default In-Reply-To: References: Message-ID: On Tue, Sep 22, 2015 at 5:12 PM, Sol T wrote: > I know I can do this per connection, however how can I have it set to > default? Does this need to be compiled into python? > If you need to compile sqlite you might want to look at apsw: https://github.com/rogerbinns/apsw Cheers > > On Tue, Sep 22, 2015 at 2:04 PM, Ryan Stuart > wrote: > >> On Thu, Sep 17, 2015 at 2:24 PM, sol433tt wrote: >> >>> I would like to have the Sqlite pragma statement "locking_mode" set to >>> "EXCLUSIVE" by default (RO database). Does this need to be compiled in? How >>> might this be achieved? >>> >> >> You can issue any PRAGA statement you like using the execute method on a >> connection as per the documentation ( >> https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.execute). >> For information on the specific PRAGMA option you need, see >> https://www.sqlite.org/pragma.html#pragma_locking_mode. I can't see any >> mention of it being a compile time PRAGMA. >> >> Cheers >> >> >>> >>> There is some performance to be gained. I have a number of python >>> scripts, and don't want to alter the pragma statement for every script. >>> This computer never writes to the databases. >>> >>> thank you >>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >>> >> >> >> -- >> Ryan Stuart, B.Eng >> Software Engineer >> >> W: http://www.kapiche.com/ >> M: +61-431-299-036 >> > > -- Ryan Stuart, B.Eng Software Engineer W: http://www.kapiche.com/ M: +61-431-299-036 -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavel at schon.cz Tue Sep 22 08:16:28 2015 From: pavel at schon.cz (Pavel S) Date: Tue, 22 Sep 2015 05:16:28 -0700 (PDT) Subject: Successfully send sms with python In-Reply-To: <05ab0edd-7285-4aca-b603-76e94dd8f0aa@googlegroups.com> References: <05ab0edd-7285-4aca-b603-76e94dd8f0aa@googlegroups.com> Message-ID: <17ead219-f3cc-45be-be56-74d5ac274731@googlegroups.com> On Tuesday, September 22, 2015 at 1:20:07 PM UTC+2, Timon Rhynix wrote: > Hello, I have used pyserial, sms0.4 and other libraries to send sms via huawei E1750 modem. > The code runs well and no error is thrown but the text message is not sent/delivered to the number. > One of my code is as follows: > > import serial > import time > > class TextMessage: > def __init__(self, recipient="0123456789", message="TextMessage.content not set."): > self.recipient = recipient > self.content = message > > def setRecipient(self, number): > self.recipient = number > > def setContent(self, message): > self.content = message > > def connectPhone(self): > conn = 'COM13' > self.ser = serial.Serial(conn, 460800, timeout=5) > time.sleep(1) > > def sendMessage(self): > self.ser.write('ATZ\r') > time.sleep(1) > self.ser.write('AT+CMGF=1\r') > time.sleep(1) > self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''') > time.sleep(1) > self.ser.write(self.content + "\r") > time.sleep(1) > self.ser.write(chr(26)) > time.sleep(1) > print "message sent!" > > def disconnectPhone(self): > self.ser.close() > > When run it, the "message sent!" is printed but no message is sent/delivered. > Please assist on what I am missing. Thank you Hi, why don't you use http://wammu.eu/python-gammu/ ? From robin at reportlab.com Tue Sep 22 09:35:00 2015 From: robin at reportlab.com (Robin Becker) Date: Tue, 22 Sep 2015 14:35:00 +0100 Subject: problem building python 3.5 extensions for windows In-Reply-To: <56012A0C.5040805@chamonix.reportlab.co.uk> References: <55FFFE50.8090703@chamonix.reportlab.co.uk> <7f633007-1391-4172-a022-262899537981@googlegroups.com> <56012A0C.5040805@chamonix.reportlab.co.uk> Message-ID: <56015904.8050608@chamonix.reportlab.co.uk> On 22/09/2015 11:14, Robin Becker wrote: > On 22/09/2015 01:36, cjgohlke at gmail.com wrote: .........t >> . >> > Thanks for the pointer Christoph. > > I certainly didn't let it run for 30 minutes. When I build with 2.7, 3.3 or 3.4 > the whole build including reportlab stuff is over in a couple of minutes. I will > try again, but a linker that takes 30 minutes to create an extension that ends > up 204Kb long has to be seriously broken. Is it trying to hard? Most of the code > size is in arrays for code points etc etc. I timed my builds of pyRXPU for x86 + amd64; these are on a core i5-3470 @ 3.20Ghz with 4Gb memory. python 3.4 1 minute 14 seconds python 3.5 52 minutes 50 seconds so with VS2015 it will now take me an hour to make and test any changes to this extension. I don't see how the issue can be considered closed. VS2015 is clearly not the way forward for any reasonable development process. -- Robin Becker From robin at reportlab.com Tue Sep 22 09:35:00 2015 From: robin at reportlab.com (Robin Becker) Date: Tue, 22 Sep 2015 14:35:00 +0100 Subject: problem building python 3.5 extensions for windows In-Reply-To: <56012A0C.5040805@chamonix.reportlab.co.uk> References: <55FFFE50.8090703@chamonix.reportlab.co.uk> <7f633007-1391-4172-a022-262899537981@googlegroups.com> <56012A0C.5040805@chamonix.reportlab.co.uk> Message-ID: <56015904.8050608@chamonix.reportlab.co.uk> On 22/09/2015 11:14, Robin Becker wrote: > On 22/09/2015 01:36, cjgohlke at gmail.com wrote: .........t >> . >> > Thanks for the pointer Christoph. > > I certainly didn't let it run for 30 minutes. When I build with 2.7, 3.3 or 3.4 > the whole build including reportlab stuff is over in a couple of minutes. I will > try again, but a linker that takes 30 minutes to create an extension that ends > up 204Kb long has to be seriously broken. Is it trying to hard? Most of the code > size is in arrays for code points etc etc. I timed my builds of pyRXPU for x86 + amd64; these are on a core i5-3470 @ 3.20Ghz with 4Gb memory. python 3.4 1 minute 14 seconds python 3.5 52 minutes 50 seconds so with VS2015 it will now take me an hour to make and test any changes to this extension. I don't see how the issue can be considered closed. VS2015 is clearly not the way forward for any reasonable development process. -- Robin Becker From none at mailinator.com Tue Sep 22 12:27:35 2015 From: none at mailinator.com (mm0fmf) Date: Tue, 22 Sep 2015 17:27:35 +0100 Subject: Successfully send sms with python In-Reply-To: <05ab0edd-7285-4aca-b603-76e94dd8f0aa@googlegroups.com> References: <05ab0edd-7285-4aca-b603-76e94dd8f0aa@googlegroups.com> Message-ID: On 22/09/2015 12:19, Timon Rhynix wrote: > Hello, I have used pyserial, sms0.4 and other libraries to send sms via huawei E1750 modem. > The code runs well and no error is thrown but the text message is not sent/delivered to the number. > One of my code is as follows: > > import serial > import time > > class TextMessage: > def __init__(self, recipient="0123456789", message="TextMessage.content not set."): > self.recipient = recipient > self.content = message > > def setRecipient(self, number): > self.recipient = number > > def setContent(self, message): > self.content = message > > def connectPhone(self): > conn = 'COM13' > self.ser = serial.Serial(conn, 460800, timeout=5) > time.sleep(1) > > def sendMessage(self): > self.ser.write('ATZ\r') > time.sleep(1) > self.ser.write('AT+CMGF=1\r') > time.sleep(1) > self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''') > time.sleep(1) > self.ser.write(self.content + "\r") > time.sleep(1) > self.ser.write(chr(26)) > time.sleep(1) > print "message sent!" > > def disconnectPhone(self): > self.ser.close() > > When run it, the "message sent!" is printed but no message is sent/delivered. > Please assist on what I am missing. Thank you > If it's like the GSM modem I used then you should replace those "\r" strings with "\r\n". From ljfc2000 at yahoo.com Tue Sep 22 14:43:57 2015 From: ljfc2000 at yahoo.com (Python_Teacher) Date: Tue, 22 Sep 2015 11:43:57 -0700 (PDT) Subject: =?UTF-8?Q?A_little_test_for_you_Guys=F0=9F=98=9C?= Message-ID: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> you have 10 minutes? Good luck!! 1. What is PEP8 ? 2. What are the different ways to distribute some python source code ? 2 Lists Let's define the function plural : def plural(words): plurals = [] for word in words: plurals.append(word + 's') return plurals for word in plural(['cabagge','owl','toy']): print word Question : How could the code of the function plural be optimised? 3 Dictionaries Here are two dictionnaries : input = { 'foo1': 'bar1', 'chose': 'truc', 'foo2': 'bar2', } output = { 'bar1': 'foo1', 'truc': 'chose', 'bar2': 'foo2' } Question : Propose a function that returns output when you provide input ? 4 Iterators Let's consider this program : def program_1(): yield 1 yield 2 yield 3 g = program_1() a = list(g) b = list(g) c = g() Question : At the end of the program, 1. What is the type of g ? 2. What is the value of a ? 3. What is the value of b ? 4. What is the value of c ? 5 Decorators Let's consider now : def str2print(f): def str2print_wrap(*args, **kwargs): """wrapper""" s = f(*args, **kwargs) print s return str2print_wrap def hello(s): """ Return "Hello $s" """ return "%s %s" % ("Hello", s) Questions : 1. Decorate the method 'hello' with 'str2printf' and write the corresponding code. 2. What is the effect of the decorator on a call to the new method 'hello' ? 3. What is the return value of hello.__doc__ From ian.g.kelly at gmail.com Tue Sep 22 15:14:10 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 22 Sep 2015 13:14:10 -0600 Subject: =?UTF-8?Q?Re=3A_A_little_test_for_you_Guys=F0=9F=98=9C?= In-Reply-To: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Message-ID: On Tue, Sep 22, 2015 at 12:43 PM, Python_Teacher via Python-list wrote: > you have 10 minutes? Good luck!! Sorry, I'm more interested in critiquing the questions than answering them. > Let's define the function plural : > > def plural(words): > plurals = [] > for word in words: > plurals.append(word + 's') > return plurals > > for word in plural(['cabagge','owl','toy']): > print word > > Question : How could the code of the function plural be optimised? Optimized in what way? To be faster? Use less memory? Be more readable? > 3 Dictionaries > > Here are two dictionnaries : > > input = { > 'foo1': 'bar1', > 'chose': 'truc', > 'foo2': 'bar2', > } > output = { > 'bar1': 'foo1', > 'truc': 'chose', > 'bar2': 'foo2' > } > > Question : Propose a function that returns output when you provide input ? def f(maybe_input): if maybe_input == input: return output I don't think I really understand what it is that you're asking for here. > 3. What is the return value of hello.__doc__ hello.__doc__ isn't a function, so it doesn't have a return value. I think you mean to ask what the expression evaluates to. From srkunze at mail.de Tue Sep 22 15:42:41 2015 From: srkunze at mail.de (Sven R. Kunze) Date: Tue, 22 Sep 2015 21:42:41 +0200 Subject: A little test for you =?UTF-8?B?R3V5c/CfmJw=?= In-Reply-To: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Message-ID: <5601AF31.60904@mail.de> Hmm, why not. :D On 22.09.2015 20:43, Python_Teacher via Python-list wrote: > you have 10 minutes? Good luck!! > > > 1. What is PEP8 ? A PEP. > 2. What are the different ways to distribute some python source code ? unison, rsync, scp, ftp, sftp, samba, http, https, mail, git, .... > 2 Lists > > Let's define the function plural : > > def plural(words): > plurals = [] > for word in words: > plurals.append(word + 's') > return plurals > > for word in plural(['cabagge','owl','toy']): > print word > > Question : How could the code of the function plural be optimised? Don't optimized until you need to. So, we leave it as is. ;) > 3 Dictionaries > > Here are two dictionnaries : > > input = { > 'foo1': 'bar1', > 'chose': 'truc', > 'foo2': 'bar2', > } > output = { > 'bar1': 'foo1', > 'truc': 'chose', > 'bar2': 'foo2' > } > > Question : Propose a function that returns output when you provide input ? # :-P def function(input): return output > 4 Iterators > > Let's consider this program : > > def program_1(): > yield 1 > yield 2 > yield 3 > > g = program_1() > a = list(g) > b = list(g) > c = g() > > Question : At the end of the program, > > 1. What is the type of g ? > 2. What is the value of a ? > 3. What is the value of b ? > 4. What is the value of c ? The program ends with a traceback. So, my variables are all gone. :( > 5 Decorators > > Let's consider now : > > def str2print(f): > def str2print_wrap(*args, **kwargs): > """wrapper""" > s = f(*args, **kwargs) > print s > return str2print_wrap > > def hello(s): > """ Return "Hello $s" """ > return "%s %s" % ("Hello", s) > > Questions : > > 1. Decorate the method 'hello' with 'str2printf' and write the corresponding code. @str2print def hello(s): """ Return "Hello $s" but actually returns None """ return "%s %s" % ("Hello", s) > 2. What is the effect of the decorator on a call to the new method 'hello' ? It prints "Hello {s}" and returns None. > 3. What is the return value of hello.__doc__ 'wrapper' Best, Sven From james.harris.1 at gmail.com Tue Sep 22 15:45:24 2015 From: james.harris.1 at gmail.com (James Harris) Date: Tue, 22 Sep 2015 20:45:24 +0100 Subject: Lightwight socket IO wrapper References: Message-ID: "Dennis Lee Bieber" wrote in message news:mailman.12.1442794762.28679.python-list at python.org... > On Sun, 20 Sep 2015 23:36:30 +0100, "James Harris" > declaimed the following: > > >> >>There are a few things and more crop up as time goes on. For example, >>over TCP it would be helpful to have a function to receive a specific >>number of bytes or one to read bytes until reaching a certain >>delimiter >>such as newline or zero or space etc. Even better would be to be able >>to >>use the iteration protocol so you could just code next() and get the >>next such chunk of read in a for loop. When sending it would be good >>to >>just say to send a bunch of bytes but know that you will get told how >>many were sent (or didn't get sent) if it fails. Sock.sendall() >>doesn't >>do that. > > Note that the "buffer size" option on a TCP socket.recv() gives you > your "specific number of bytes" -- if available at that time. "If" is a big word! AIUI the buffer size is not guaranteed to relate to the number of bytes returned except that you won't/shouldn't(!) get more than the buffer size. > I wouldn't want to user .recv(1) though to implement your "reaching a > certain delimiter"... Much better to read as much as available and > search > it for the delimiter. Yes, that's what I do at the moment. I keep a block of bytes, add any new stuff to it and scan it for delimiters. > I'll confess, adding a .readln() FOR TCP ONLY, might > be a nice extension over BSD sockets (might need to allow option for > whether line-ends are Internet standard or some other marker, > and > whether they should be converted upon reading to the native format for > the > host). Akira Li pointed out that there is just such an extension: makefile. Scanning to is what I do just now as that includes too and I leave them on the string. IIRC file.readline works in the same way. >>I thought UDP would deliver (or drop) a whole datagram but cannot find >>anything in the Python documentaiton to guarantee that. In fact >>documentation for the send() call says that apps are responsible for >>checking that all data has been sent. They may mean that to apply to >>stream protocols only but it doesn't state that. (Of course, UDP >>datagrams are limited in size so the call may validly indicate >>incomplete transmission even when the first part of a big message is >>sent successfully.) >> > Looking in the wrong documentation > > You probably should be looking at the UDP RFC. Or maybe just > > http://www.diffen.com/difference/TCP_vs_UDP > > """ > Packets are sent individually and are checked for integrity only if > they > arrive. Packets have definite boundaries which are honored upon > receipt, > meaning a read operation at the receiver socket will yield an entire > message as it was originally sent. > """ I would rather see it in the Python docs because we program to the language standard and there can be - and often are, for good reason - areas where Python does not work in the same way as underlying systems. > Even if the IP layer has to fragment a UDP packet to meet limits of > the > transport media, it should put them back together on the other end > before > passing it up to the UDP layer. To my knowledge, UDP does not have a > size > limit on the message (well -- a 16-bit length field in the UDP > header). But > since it /is/ "got it all" or "dropped" with no inherent confirmation, > one > would have to embed their own protocol within it -- sequence numbers > with > ACK/NAK, for example. Problem: if using LARGE UDP packets, this > protocol > would mean having LARGE resends should packets be dropped or arrive > out of > sequence (and since the ACK/NAK could be dropped too, you may have to > handle the case of a duplicated packet -- also large). Yes, it was the 16-bit limitation that I was talking about. > TCP is a stream protocol -- the protocol will ensure that all data > arrives, and that it arrives in order, but does not enforce any > boundaries > on the data; what started as a relatively large packet at one end may > arrive as lots of small packets due to intermediate transport limits > (one > can visualize a worst case: each TCP packet is broken up to fit > Hollerith > cards; 20bytes for header and 60 bytes of data -- then fed to a reader > and > sent on AS-IS). Boundaries are the end-user responsibility... line > endings > (look at SMTP, where an email message ends on a line containing just a > ".") > or embedded length counter (not the TCP packet length). Yes. >>Receiving no bytes is taken as indicating the end of the >>communication. >>That's OK for TCP but not for UDP so there should be a way to >>distinguish between the end of data and receiving an empty datagram. >> > I don't believe UDP supports a truly empty datagram (length of 0) -- > presuming a sending stack actually sends one, the receiving stack will > probably drop it as there is no data to pass on to a client (there is > a PR > at work because we have a UDP driver that doesn't drop 0-length > messages, > but also can't deliver them -- so the circular buffer might fill with > undeliverable headers) As others have pointed out, UDP implementations do seem to work with zero-byte datagrams properly. Again, I would rather see that in the Python documentation which is what, effectively, forms a contract that we should be able to rely on. James From 4kir4.1i at gmail.com Tue Sep 22 15:48:42 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Tue, 22 Sep 2015 22:48:42 +0300 Subject: A little test for you =?utf-8?Q?Guys=F0=9F=98=9C?= References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Message-ID: <878u7y2q1x.fsf@gmail.com> Python_Teacher via Python-list writes: ... > Let's define the function plural : > > def plural(words): > plurals = [] > for word in words: > plurals.append(word + 's') > return plurals > > for word in plural(['cabagge','owl','toy']): > print word plural() should accept a single word. To handle list of words, call map(plural, words) ... > def str2print(f): > def str2print_wrap(*args, **kwargs): > """wrapper""" > s = f(*args, **kwargs) > print s > return str2print_wrap > > def hello(s): > """ Return "Hello $s" """ > return "%s %s" % ("Hello", s) Use functools.wraps() to preserve the function info for introspection: import functools def prints_result(function): @functools.wraps(function) def wrapper(*args, **kwargs): result = function(*args, **kwargs) print(result) return result #XXX return return wrapper @prints_result def hello(...): pass From james.harris.1 at gmail.com Tue Sep 22 16:05:08 2015 From: james.harris.1 at gmail.com (James Harris) Date: Tue, 22 Sep 2015 21:05:08 +0100 Subject: Lightwight socket IO wrapper References: Message-ID: "Akira Li" <4kir4.1i at gmail.com> wrote in message news:mailman.18.1442804862.28679.python-list at python.org... > "James Harris" writes: > ... >> There are a few things and more crop up as time goes on. For example, >> over TCP it would be helpful to have a function to receive a specific >> number of bytes or one to read bytes until reaching a certain >> delimiter such as newline or zero or space etc. > > The answer is sock.makefile('rb') then `file.read(nbytes)` returns a > specific number of bytes. Thanks, I hadn't seen that. Now I know of it I see references to it all over the place but beforehand it was in hiding.... It is exactly the type of convenience wrapper I was expecting Python to have but expected it to be in another module. It looks as though it will definitely cover some of the issues I had. > `file.readline()` reads until newline (b'\n') There is Python Issue: > "Add support for reading records with arbitrary separators to the > standard IO stack" > http://bugs.python.org/issue1152248 > See also > http://bugs.python.org/issue17083 > > Perhaps, it is easier to implement read_until(sep) that is best suited > for a particular case. OK. ... >> When sending it would be good to just say to send a bunch of bytes >> but >> know that you will get told how many were sent (or didn't get sent) >> if >> it fails. Sock.sendall() doesn't do that. > > sock.send() returns the number of bytes sent that may be less than > given. > You could reimplement sock.sendall() to include the number of bytes > successfully sent in case of an error. I know. As mentioned, I wondered if there were already such functions to save me using my own. >> I thought UDP would deliver (or drop) a whole datagram but cannot >> find >> anything in the Python documentaiton to guarantee that. In fact >> documentation for the send() call says that apps are responsible for >> checking that all data has been sent. They may mean that to apply to >> stream protocols only but it doesn't state that. (Of course, UDP >> datagrams are limited in size so the call may validly indicate >> incomplete transmission even when the first part of a big message is >> sent successfully.) >> >> Receiving no bytes is taken as indicating the end of the >> communication. That's OK for TCP but not for UDP so there should be a >> way to distinguish between the end of data and receiving an empty >> datagram. > > There is no end of communication in UDP and therefore there is no end > of > data. If you've got a zero bytes in return then it means that you've > received a zero length datagram. > > sock.recvfrom() is a thin wrapper around the corresponding C > function. You could read any docs you like about UDP sockets. > > http://stackoverflow.com/questions/5307031/how-to-detect-receipt-of-a-0-length-udp-datagram As mentioned to Dennis just now, I would prefer to write code to conform with the documented behaviour of Python and its libraries, as long as they were known to be reliable implementations of what was documented, of course. I agree with what you say. A zero-length UDP datagram should be possible and not indicate end of input but is that guaranteed and portable? (Rhetorical.) It seems not. Even the Linux man page for recv says: "If no messages are available at the socket, the receive calls wait for a message to arrive, unless the socket is nonblocking...." In that case, of course, what it defines as a "message" - and whether it can be zero length or not - is not stated. >> The recv calls require a buffer size to be supplied which is a >> technical detail. A Python wrapper could save the programmer dealing >> with that. > > It is not just a buffer size. It is the maximum amount of data to be > received at once i.e., sock.recv() may return less but never more. My point was that we might want to request the entire next line or next field of input and not know a maximum length. *C* programmers are used to giving buffers fixed sizes often because then they can avoid fiddling with memory management but Python normally does that for us. I was suggesting that the thin wrapper around the socket recv() call is too thin! The makefile() approach that you mentioned seems more Pythonesque, though. > You could use makefile() and read() if recv() is too low-level. Yes. James From james.harris.1 at gmail.com Tue Sep 22 16:28:30 2015 From: james.harris.1 at gmail.com (James Harris) Date: Tue, 22 Sep 2015 13:28:30 -0700 (PDT) Subject: =?UTF-8?Q?Re=3A_A_little_test_for_you_Guys=F0=9F=98=9C?= In-Reply-To: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Message-ID: <8e38d7e1-cda6-490f-8f79-99b23ff5706b@googlegroups.com> On Tuesday, September 22, 2015 at 7:45:00 PM UTC+1, Lj Fc wrote: > you have 10 minutes? Good luck!! A good set of questions, IMO. Am answering as someone coming back to Python after a few years. > 1. What is PEP8 ? Coding guidelines, I think. > 2. What are the different ways to distribute some python source code ? I don't know what that's getting at as it specifically mentions source code apart from tar/gzip or zip. Maybe git or other scm? > 2 Lists > > Let's define the function plural : > > def plural(words): > plurals = [] > for word in words: > plurals.append(word + 's') > return plurals > > for word in plural(['cabagge','owl','toy']): > print word > > Question : How could the code of the function plural be optimised? I would go for [word + 's' for word in words] > 3 Dictionaries > > Here are two dictionnaries : > > input = { > 'foo1': 'bar1', > 'chose': 'truc', > 'foo2': 'bar2', > } > output = { > 'bar1': 'foo1', > 'truc': 'chose', > 'bar2': 'foo2' > } > > Question : Propose a function that returns output when you provide input ? def f(input): output = {} for k,v in input.items(): output[v] = k return output > 4 Iterators > > Let's consider this program : > > def program_1(): > yield 1 > yield 2 > yield 3 > > g = program_1() > a = list(g) > b = list(g) > c = g() > > Question : At the end of the program, > > 1. What is the type of g ? > 2. What is the value of a ? > 3. What is the value of b ? > 4. What is the value of c ? Good one. I checked this and only got 1 and 2 right. > 5 Decorators No idea! James From tjreedy at udel.edu Tue Sep 22 16:48:33 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 22 Sep 2015 16:48:33 -0400 Subject: problem building python 3.5 extensions for windows In-Reply-To: <56015904.8050608@chamonix.reportlab.co.uk> References: <55FFFE50.8090703@chamonix.reportlab.co.uk> <7f633007-1391-4172-a022-262899537981@googlegroups.com> <56012A0C.5040805@chamonix.reportlab.co.uk> <56015904.8050608@chamonix.reportlab.co.uk> Message-ID: On 9/22/2015 9:35 AM, Robin Becker wrote: > On 22/09/2015 11:14, Robin Becker wrote: >> On 22/09/2015 01:36, cjgohlke at gmail.com wrote: > .........t >>> . >>> >> Thanks for the pointer Christoph. >> >> I certainly didn't let it run for 30 minutes. When I build with 2.7, >> 3.3 or 3.4 >> the whole build including reportlab stuff is over in a couple of >> minutes. I will >> try again, but a linker that takes 30 minutes to create an extension >> that ends >> up 204Kb long has to be seriously broken. Is it trying to hard? Most >> of the code >> size is in arrays for code points etc etc. > > I timed my builds of pyRXPU for x86 + amd64; these are on a core i5-3470 > @ 3.20Ghz with 4Gb memory. > > python 3.4 1 minute 14 seconds > python 3.5 52 minutes 50 seconds > > so with VS2015 it will now take me an hour to make and test any changes > to this extension. I don't see how the issue can be considered closed. > VS2015 is clearly not the way forward for any reasonable development > process. I think you should add the above to the issue. -- Terry Jan Reedy From marko at pacujo.net Tue Sep 22 17:00:37 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 23 Sep 2015 00:00:37 +0300 Subject: Lightwight socket IO wrapper References: Message-ID: <8737y6cgp6.fsf@elektro.pacujo.net> "James Harris" : > I agree with what you say. A zero-length UDP datagram should be > possible and not indicate end of input but is that guaranteed and > portable? The zero-length payload size shouldn't be an issue, but UDP doesn't make any guarantees about delivering the message. Your UDP application must be prepared for some, most or all of the messages disappearing without any error indication. In practice, you'd end up implementing your own TCP on top of UDP (retries, timeouts, acknowledgements, sequence numbers etc). Marko From sohcahtoa82 at gmail.com Tue Sep 22 17:18:29 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Tue, 22 Sep 2015 14:18:29 -0700 (PDT) Subject: =?UTF-8?Q?Re=3A_A_little_test_for_you_Guys=F0=9F=98=9C?= In-Reply-To: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Message-ID: <5218c7f9-74ea-4ca0-abd1-46a9bcd3dc2a@googlegroups.com> On Tuesday, September 22, 2015 at 11:45:00 AM UTC-7, Lj Fc wrote: > you have 10 minutes? Good luck!! > > > 1. What is PEP8 ? > > 2. What are the different ways to distribute some python source code ? > > 2 Lists > > Let's define the function plural : > > def plural(words): > plurals = [] > for word in words: > plurals.append(word + 's') > return plurals > > for word in plural(['cabagge','owl','toy']): > print word > > Question : How could the code of the function plural be optimised? > > 3 Dictionaries > > Here are two dictionnaries : > > input = { > 'foo1': 'bar1', > 'chose': 'truc', > 'foo2': 'bar2', > } > output = { > 'bar1': 'foo1', > 'truc': 'chose', > 'bar2': 'foo2' > } > > Question : Propose a function that returns output when you provide input ? > > 4 Iterators > > Let's consider this program : > > def program_1(): > yield 1 > yield 2 > yield 3 > > g = program_1() > a = list(g) > b = list(g) > c = g() > > Question : At the end of the program, > > 1. What is the type of g ? > 2. What is the value of a ? > 3. What is the value of b ? > 4. What is the value of c ? > > 5 Decorators > > Let's consider now : > > def str2print(f): > def str2print_wrap(*args, **kwargs): > """wrapper""" > s = f(*args, **kwargs) > print s > return str2print_wrap > > def hello(s): > """ Return "Hello $s" """ > return "%s %s" % ("Hello", s) > > Questions : > > 1. Decorate the method 'hello' with 'str2printf' and write the corresponding code. > 2. What is the effect of the decorator on a call to the new method 'hello' ? > 3. What is the return value of hello.__doc__ Pretty sure this guy is asking us to do his homework. :-P From james.harris.1 at gmail.com Tue Sep 22 17:28:41 2015 From: james.harris.1 at gmail.com (James Harris) Date: Tue, 22 Sep 2015 22:28:41 +0100 Subject: Lightwight socket IO wrapper References: <8737y6cgp6.fsf@elektro.pacujo.net> Message-ID: "Marko Rauhamaa" wrote in message news:8737y6cgp6.fsf at elektro.pacujo.net... > "James Harris" : > >> I agree with what you say. A zero-length UDP datagram should be >> possible and not indicate end of input but is that guaranteed and >> portable? > > The zero-length payload size shouldn't be an issue, but UDP doesn't > make > any guarantees about delivering the message. Your UDP application must > be prepared for some, most or all of the messages disappearing without > any error indication. > > In practice, you'd end up implementing your own TCP on top of UDP > (retries, timeouts, acknowledgements, sequence numbers etc). The unreliability of UDP was not the case in point here. Rather, it was about whether different platforms could be relied upon to deliver zero-length datagrams to the app if the datagrams got safely across the network. James From james.harris.1 at gmail.com Tue Sep 22 17:31:59 2015 From: james.harris.1 at gmail.com (James Harris) Date: Tue, 22 Sep 2015 22:31:59 +0100 Subject: =?UTF-8?Q?Re:_A_little_test_for_you_Guys=F0=9F=98=9C?= References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> <5218c7f9-74ea-4ca0-abd1-46a9bcd3dc2a@googlegroups.com> Message-ID: wrote in message news:5218c7f9-74ea-4ca0-abd1-46a9bcd3dc2a at googlegroups.com... ... > Pretty sure this guy is asking us to do his homework. :-P Maybe (and I hope not) but asking what PEP8 is could be easily found on the internet and asking what the values would be at the end of the program in question 4 could be easily found by trying it. James From ian.g.kelly at gmail.com Tue Sep 22 17:33:01 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 22 Sep 2015 15:33:01 -0600 Subject: =?UTF-8?Q?Re=3A_A_little_test_for_you_Guys=F0=9F=98=9C?= In-Reply-To: <5218c7f9-74ea-4ca0-abd1-46a9bcd3dc2a@googlegroups.com> References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> <5218c7f9-74ea-4ca0-abd1-46a9bcd3dc2a@googlegroups.com> Message-ID: On Tue, Sep 22, 2015 at 3:18 PM, wrote: > On Tuesday, September 22, 2015 at 11:45:00 AM UTC-7, Lj Fc wrote: >> you have 10 minutes? Good luck!! > > Pretty sure this guy is asking us to do his homework. :-P Well, looks like it was due 2 hours ago. From cjgohlke at gmail.com Tue Sep 22 17:37:41 2015 From: cjgohlke at gmail.com (cjgohlke at gmail.com) Date: Tue, 22 Sep 2015 14:37:41 -0700 (PDT) Subject: problem building python 3.5 extensions for windows In-Reply-To: References: <55FFFE50.8090703@chamonix.reportlab.co.uk> <7f633007-1391-4172-a022-262899537981@googlegroups.com> <56012A0C.5040805@chamonix.reportlab.co.uk> <56015904.8050608@chamonix.reportlab.co.uk> Message-ID: On Tuesday, September 22, 2015 at 1:49:16 PM UTC-7, Terry Reedy wrote: > On 9/22/2015 9:35 AM, Robin Becker wrote: > > On 22/09/2015 11:14, Robin Becker wrote: > >> On 22/09/2015 01:36, CG wrote: > > .........t > >>> . > >>> > >> Thanks for the pointer Christoph. > >> > >> I certainly didn't let it run for 30 minutes. When I build with 2.7, > >> 3.3 or 3.4 > >> the whole build including reportlab stuff is over in a couple of > >> minutes. I will > >> try again, but a linker that takes 30 minutes to create an extension > >> that ends > >> up 204Kb long has to be seriously broken. Is it trying to hard? Most > >> of the code > >> size is in arrays for code points etc etc. > > > > I timed my builds of pyRXPU for x86 + amd64; these are on a core i5-3470 > > @ 3.20Ghz with 4Gb memory. > > > > python 3.4 1 minute 14 seconds > > python 3.5 52 minutes 50 seconds > > > > so with VS2015 it will now take me an hour to make and test any changes > > to this extension. I don't see how the issue can be considered closed. > > VS2015 is clearly not the way forward for any reasonable development > > process. > > I think you should add the above to the issue. > > -- > Terry Jan Reedy It's a compiler bug. To work around, disable compiler optimizations, i.e. set `extra_compile_args=['/Od']` in setup.py. -- Christoph From thecjguy1 at gmail.com Tue Sep 22 17:43:55 2015 From: thecjguy1 at gmail.com (Chris Roberts) Date: Tue, 22 Sep 2015 14:43:55 -0700 (PDT) Subject: Python, convert an integer into an index? Message-ID: (How do I make it into an index? ) Preferably something fairly easy to understand as I am new at this. results = 134523 #(Integer) Desired: results = [1, 2, 3, 4, 5, 2, 3] #(INDEX) Somehow I see ways to convert index to list to int, but not back again. Thanks, crzzy1 From ian.g.kelly at gmail.com Tue Sep 22 18:13:45 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 22 Sep 2015 16:13:45 -0600 Subject: Python, convert an integer into an index? In-Reply-To: References: Message-ID: On Sep 22, 2015 3:46 PM, "Chris Roberts" wrote: > > > (How do I make it into an index? ) > Preferably something fairly easy to understand as I am new at this. > > results = 134523 #(Integer) > > Desired: > results = [1, 2, 3, 4, 5, 2, 3] #(INDEX) > > Somehow I see ways to convert index to list to int, but not back again. I'm not sure what you mean by "index" in this context, but do you just want to convert the integer into a list of its digits? The simple way is to convert it to a string, then convert each character back to an int, and put the results into a list. More efficient way would be to strip the digits off one at a time by dividing modulo 10. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Tue Sep 22 18:21:22 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 23 Sep 2015 00:21:22 +0200 Subject: Python, convert an integer into an index? In-Reply-To: References: Message-ID: <201509222221.t8MMLMi5015927@fido.openend.se> In a message of Tue, 22 Sep 2015 14:43:55 -0700, Chris Roberts writes: > > >(How do I make it into an index? ) >Preferably something fairly easy to understand as I am new at this. > >results = 134523 #(Integer) > >Desired: >results = [1, 2, 3, 4, 5, 2, 3] #(INDEX) > >Somehow I see ways to convert index to list to int, but not back again. > >Thanks, >crzzy1 You need to convert your results into a string first. result_int=1234523 result_list=[] for digit in str(result_int): result_list.append(int(digit)) digit will be assigned to successive 1 character long strings. Since you wanted a list of integers, you have to convert it back. If you are learning python you may be interested in the tutor mailing list. https://mail.python.org/mailman/listinfo/tutor Laura From ljfc2000 at yahoo.com Tue Sep 22 18:21:52 2015 From: ljfc2000 at yahoo.com (Lj Fc) Date: Tue, 22 Sep 2015 15:21:52 -0700 (PDT) Subject: =?UTF-8?Q?Re=3A_A_little_test_for_you_Guys=F0=9F=98=9C?= In-Reply-To: <5218c7f9-74ea-4ca0-abd1-46a9bcd3dc2a@googlegroups.com> References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> <5218c7f9-74ea-4ca0-abd1-46a9bcd3dc2a@googlegroups.com> Message-ID: On Tuesday, September 22, 2015 at 11:19:00 PM UTC+2, sohca... at gmail.com wrote: > On Tuesday, September 22, 2015 at 11:45:00 AM UTC-7, Lj Fc wrote: > > you have 10 minutes? Good luck!! > > > > > > 1. What is PEP8 ? > > > > 2. What are the different ways to distribute some python source code ? > > > > 2 Lists > > > > Let's define the function plural : > > > > def plural(words): > > plurals = [] > > for word in words: > > plurals.append(word + 's') > > return plurals > > > > for word in plural(['cabagge','owl','toy']): > > print word > > > > Question : How could the code of the function plural be optimised? > > > > 3 Dictionaries > > > > Here are two dictionnaries : > > > > input = { > > 'foo1': 'bar1', > > 'chose': 'truc', > > 'foo2': 'bar2', > > } > > output = { > > 'bar1': 'foo1', > > 'truc': 'chose', > > 'bar2': 'foo2' > > } > > > > Question : Propose a function that returns output when you provide input ? > > > > 4 Iterators > > > > Let's consider this program : > > > > def program_1(): > > yield 1 > > yield 2 > > yield 3 > > > > g = program_1() > > a = list(g) > > b = list(g) > > c = g() > > > > Question : At the end of the program, > > > > 1. What is the type of g ? > > 2. What is the value of a ? > > 3. What is the value of b ? > > 4. What is the value of c ? > > > > 5 Decorators > > > > Let's consider now : > > > > def str2print(f): > > def str2print_wrap(*args, **kwargs): > > """wrapper""" > > s = f(*args, **kwargs) > > print s > > return str2print_wrap > > > > def hello(s): > > """ Return "Hello $s" """ > > return "%s %s" % ("Hello", s) > > > > Questions : > > > > 1. Decorate the method 'hello' with 'str2printf' and write the corresponding code. > > 2. What is the effect of the decorator on a call to the new method 'hello' ? > > 3. What is the return value of hello.__doc__ > > Pretty sure this guy is asking us to do his homework. :-P See Not that Easy Dude...Simple Questions are sometimes the Toughest!! KISS? From larry.martell at gmail.com Tue Sep 22 18:42:55 2015 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 22 Sep 2015 18:42:55 -0400 Subject: sort help Message-ID: I currently have 3 lists of lists and I sort them based on a common field into a single list like this: def GetObjKey(a): return a[2] sorted(a + b + c, key=GetObjKey) Which works just fine. But now, I need to have just the first list (a) also sub sorted by another field and I can't quite figure out how to do this. So for example, if my initial data was this (I'll only show the fields involved with the sort - the first number is a[2] above and the second is the new additional sorting field, only present in a) a[1, 4] a[1, 2] a[2, 3] a[2, 1] a[5, 6] a[5, 2] b[2] b[5] c[1] c[6] Then I'd want my sorted list to be this: a[1,2] a[1,4] c[1] a[2,1] a[2,3] b[2] a[5,2] a[5,6] b[5] c[6] I hope that's clear. So is there some pythonic way to sort this without resorting to a brute force old fashioned plow through the data? From rosuav at gmail.com Tue Sep 22 18:55:24 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Sep 2015 08:55:24 +1000 Subject: sort help In-Reply-To: References: Message-ID: On Wed, Sep 23, 2015 at 8:42 AM, Larry Martell wrote: > I currently have 3 lists of lists and I sort them based on a common > field into a single list like this: > > def GetObjKey(a): > return a[2] > > sorted(a + b + c, key=GetObjKey) > > Which works just fine. > > But now, I need to have just the first list (a) also sub sorted by > another field and I can't quite figure out how to do this. Have you tried simply sorting a by the other field prior to doing your merge-and-sort? The Python list.sort() method is guaranteed to be stable. I can't find a comparable guarantee for sorted(), but worst case, you should be able to do your list merge, and then explicitly name it and sort it. ChrisA From ian.g.kelly at gmail.com Tue Sep 22 19:02:55 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 22 Sep 2015 17:02:55 -0600 Subject: sort help In-Reply-To: References: Message-ID: On Tue, Sep 22, 2015 at 4:55 PM, Chris Angelico wrote: > The Python list.sort() method is guaranteed to be > stable. I can't find a comparable guarantee for sorted() https://docs.python.org/3.5/library/functions.html#sorted From rosuav at gmail.com Tue Sep 22 19:06:39 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Sep 2015 09:06:39 +1000 Subject: sort help In-Reply-To: References: Message-ID: On Wed, Sep 23, 2015 at 9:02 AM, Ian Kelly wrote: > On Tue, Sep 22, 2015 at 4:55 PM, Chris Angelico wrote: >> The Python list.sort() method is guaranteed to be >> stable. I can't find a comparable guarantee for sorted() > > https://docs.python.org/3.5/library/functions.html#sorted Right, sorry. Since all I looked at was its docstring, I should have said so :) So, yep, sorted() is guaranteed stable too, and that would be the easiest way to subsort something. ChrisA From cs at zip.com.au Tue Sep 22 19:20:32 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 23 Sep 2015 09:20:32 +1000 Subject: Successfully send sms with python In-Reply-To: <05ab0edd-7285-4aca-b603-76e94dd8f0aa@googlegroups.com> References: <05ab0edd-7285-4aca-b603-76e94dd8f0aa@googlegroups.com> Message-ID: <20150922232032.GA91348@cskk.homeip.net> On 22Sep2015 04:19, Timon Rhynix wrote: >Hello, I have used pyserial, sms0.4 and other libraries to send sms via huawei E1750 modem. >The code runs well and no error is thrown but the text message is not sent/delivered to the number. >One of my code is as follows: > >import serial >import time > >class TextMessage: > def __init__(self, recipient="0123456789", message="TextMessage.content not set."): > self.recipient = recipient > self.content = message > > def setRecipient(self, number): > self.recipient = number > > def setContent(self, message): > self.content = message > > def connectPhone(self): > conn = 'COM13' > self.ser = serial.Serial(conn, 460800, timeout=5) > time.sleep(1) > > def sendMessage(self): > self.ser.write('ATZ\r') > time.sleep(1) > self.ser.write('AT+CMGF=1\r') > time.sleep(1) > self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''') > time.sleep(1) > self.ser.write(self.content + "\r") > time.sleep(1) > self.ser.write(chr(26)) > time.sleep(1) > print "message sent!" > > def disconnectPhone(self): > self.ser.close() > >When run it, the "message sent!" is printed but no message is sent/delivered. >Please assist on what I am missing. Thank you Two suggestions: as already suggested, you may need to send \r\n instead of just \r do you need to follow every .write() with a .flush()? if the Serial object is a buffered stream that will be necessary Cheers, Cameron Simpson Motorcycling is indeed a delightful pastime. - Honda Rider Training Film From breamoreboy at yahoo.co.uk Tue Sep 22 19:23:56 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 23 Sep 2015 00:23:56 +0100 Subject: Python, convert an integer into an index? In-Reply-To: References: Message-ID: On 22/09/2015 22:43, Chris Roberts wrote: > > (How do I make it into an index? ) > Preferably something fairly easy to understand as I am new at this. > > results = 134523 #(Integer) > > Desired: > results = [1, 2, 3, 4, 5, 2, 3] #(INDEX) > > Somehow I see ways to convert index to list to int, but not back again. > > Thanks, > crzzy1 > Please provide the algorithm to convert 134523 into [1, 2, 3, 4, 5, 2, 3], as I don't see how to convert a six digit integer into a list of seven integers. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From python at mrabarnett.plus.com Tue Sep 22 19:27:03 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 23 Sep 2015 00:27:03 +0100 Subject: Python, convert an integer into an index? In-Reply-To: <201509222221.t8MMLMi5015927@fido.openend.se> References: <201509222221.t8MMLMi5015927@fido.openend.se> Message-ID: <5601E3C7.1080203@mrabarnett.plus.com> On 2015-09-22 23:21, Laura Creighton wrote: > In a message of Tue, 22 Sep 2015 14:43:55 -0700, Chris Roberts writes: >> >> >>(How do I make it into an index? ) >>Preferably something fairly easy to understand as I am new at this. >> >>results = 134523 #(Integer) >> >>Desired: >>results = [1, 2, 3, 4, 5, 2, 3] #(INDEX) >> >>Somehow I see ways to convert index to list to int, but not back again. >> >>Thanks, >>crzzy1 > > You need to convert your results into a string first. > > result_int=1234523 > result_list=[] > > for digit in str(result_int): > result_list.append(int(digit)) > > digit will be assigned to successive 1 character long strings. Since > you wanted a list of integers, you have to convert it back. > > If you are learning python you may be interested in the tutor mailing > list. https://mail.python.org/mailman/listinfo/tutor > A shorter way using strings: >>> results = 134523 >>> list(map(int, str(results))) [1, 3, 4, 5, 2, 3] From breamoreboy at yahoo.co.uk Tue Sep 22 19:32:18 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 23 Sep 2015 00:32:18 +0100 Subject: =?UTF-8?Q?Re:_A_little_test_for_you_Guys=f0=9f=98=9c?= In-Reply-To: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Message-ID: On 22/09/2015 19:43, Python_Teacher via Python-list wrote: > you have 10 minutes? Good luck!! > > > 1. What is PEP8 ? It's the one between PEP7 and PEP9. > > 2. What are the different ways to distribute some python source code ? Write on sheet of paper, fold into paper dart, throw from window. > > 2 Lists Tut, tut, tut. > > Let's define the function plural : > > def plural(words): > plurals = [] > for word in words: > plurals.append(word + 's') > return plurals > > for word in plural(['cabagge','owl','toy']): > print word > > Question : How could the code of the function plural be optimised? It is all ready optimised for programmer time so don't bother with it unless there are unforeseen bugs. > > 3 Dictionaries > > Here are two dictionnaries : > > input = { > 'foo1': 'bar1', > 'chose': 'truc', > 'foo2': 'bar2', > } > output = { > 'bar1': 'foo1', > 'truc': 'chose', > 'bar2': 'foo2' > } > > Question : Propose a function that returns output when you provide input ? def function(): return input("Who cares?") > > 4 Iterators > > Let's consider this program : > > def program_1(): > yield 1 > yield 2 > yield 3 > > g = program_1() > a = list(g) > b = list(g) > c = g() > > Question : At the end of the program, > > 1. What is the type of g ? > 2. What is the value of a ? > 3. What is the value of b ? > 4. What is the value of c ? How the hell would I know? > > 5 Decorators > > Let's consider now : > > def str2print(f): > def str2print_wrap(*args, **kwargs): > """wrapper""" > s = f(*args, **kwargs) > print s > return str2print_wrap > > def hello(s): > """ Return "Hello $s" """ > return "%s %s" % ("Hello", s) > > Questions : > > 1. Decorate the method 'hello' with 'str2printf' and write the corresponding code. > 2. What is the effect of the decorator on a call to the new method 'hello' ? > 3. What is the return value of hello.__doc__ > Can't afford decorators, they cost an arm and a leg in the UK. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ikorot01 at gmail.com Tue Sep 22 19:41:39 2015 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 22 Sep 2015 19:41:39 -0400 Subject: =?UTF-8?Q?Re=3A_A_little_test_for_you_Guys=F0=9F=98=9C?= In-Reply-To: References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Message-ID: Hi, On Tue, Sep 22, 2015 at 7:32 PM, Mark Lawrence wrote: > On 22/09/2015 19:43, Python_Teacher via Python-list wrote: > >> you have 10 minutes? Good luck!! >> >> >> 1. What is PEP8 ? >> > > It's the one between PEP7 and PEP9. > > >> 2. What are the different ways to distribute some python source code ? >> > > Write on sheet of paper, fold into paper dart, throw from window. > > >> 2 Lists >> > > Tut, tut, tut. > > >> Let's define the function plural : >> >> def plural(words): >> plurals = [] >> for word in words: >> plurals.append(word + 's') >> return plurals >> >> for word in plural(['cabagge','owl','toy']): >> print word >> >> Question : How could the code of the function plural be optimised? >> > > It is all ready optimised for programmer time so don't bother with it > unless there are unforeseen bugs. > > >> 3 Dictionaries >> >> Here are two dictionnaries : >> >> input = { >> 'foo1': 'bar1', >> 'chose': 'truc', >> 'foo2': 'bar2', >> } >> output = { >> 'bar1': 'foo1', >> 'truc': 'chose', >> 'bar2': 'foo2' >> } >> >> Question : Propose a function that returns output when you provide input ? >> > > def function(): > return input("Who cares?") > > >> 4 Iterators >> >> Let's consider this program : >> >> def program_1(): >> yield 1 >> yield 2 >> yield 3 >> >> g = program_1() >> a = list(g) >> b = list(g) >> c = g() >> >> Question : At the end of the program, >> >> 1. What is the type of g ? >> 2. What is the value of a ? >> 3. What is the value of b ? >> 4. What is the value of c ? >> > > How the hell would I know? > > >> 5 Decorators >> >> Let's consider now : >> >> def str2print(f): >> def str2print_wrap(*args, **kwargs): >> """wrapper""" >> s = f(*args, **kwargs) >> print s >> return str2print_wrap >> >> def hello(s): >> """ Return "Hello $s" """ >> return "%s %s" % ("Hello", s) >> >> Questions : >> >> 1. Decorate the method 'hello' with 'str2printf' and write the >> corresponding code. >> 2. What is the effect of the decorator on a call to the new method >> 'hello' ? >> 3. What is the return value of hello.__doc__ >> >> > Can't afford decorators, they cost an arm and a leg in the UK. Is it possible those questions are an interview questions? ;-) Thank you. > > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Sep 22 19:45:35 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Sep 2015 09:45:35 +1000 Subject: =?UTF-8?Q?Re=3A_A_little_test_for_you_Guys=F0=9F=98=9C?= In-Reply-To: References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Message-ID: On Wed, Sep 23, 2015 at 9:32 AM, Mark Lawrence wrote: >> >> 1. What is the type of g ? >> 2. What is the value of a ? >> 3. What is the value of b ? >> 4. What is the value of c ? > > > How the hell would I know? Basic schooling, Mark, basic schooling. 1. Newton meters squared per kilogram squared. 2. One ampere is equal to one coulomb per second. 3. Quite considerable; given the amount of traffic that /b/ sees, I would expect it to sell for a high price. 4. 3e8 meters per second. Bless me, what DO they teach them at these schools... ChrisA From random832 at fastmail.com Tue Sep 22 19:52:54 2015 From: random832 at fastmail.com (Random832) Date: Tue, 22 Sep 2015 19:52:54 -0400 Subject: Lightwight socket IO wrapper In-Reply-To: References: Message-ID: <1442965974.4020976.390989489.1EAEE42F@webmail.messagingengine.com> On Tue, Sep 22, 2015, at 15:45, James Harris wrote: > "Dennis Lee Bieber" wrote in message > news:mailman.12.1442794762.28679.python-list at python.org... > > On Sun, 20 Sep 2015 23:36:30 +0100, "James Harris" > > declaimed the following: > >>Receiving no bytes is taken as indicating the end of the > >>communication. > >>That's OK for TCP but not for UDP so there should be a way to > >>distinguish between the end of data and receiving an empty datagram. > >> > > I don't believe UDP supports a truly empty datagram (length of 0) -- > > presuming a sending stack actually sends one, the receiving stack will > > probably drop it as there is no data to pass on to a client (there is > > a PR > > at work because we have a UDP driver that doesn't drop 0-length > > messages, > > but also can't deliver them -- so the circular buffer might fill with > > undeliverable headers) > > As others have pointed out, UDP implementations do seem to work with > zero-byte datagrams properly. Again, I would rather see that in the > Python documentation which is what, effectively, forms a contract that > we should be able to rely on. Isn't this technically the same problem as pressing ctrl-d at a terminal - it's not _really_ the end of the input (you can continue reading after), but it sends the program something it will interpret as such? From python at mrabarnett.plus.com Tue Sep 22 19:56:19 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 23 Sep 2015 00:56:19 +0100 Subject: =?UTF-8?Q?Re:_A_little_test_for_you_Guys=f0=9f=98=9c?= In-Reply-To: References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Message-ID: <5601EAA3.5020001@mrabarnett.plus.com> On 2015-09-23 00:32, Mark Lawrence wrote: > On 22/09/2015 19:43, Python_Teacher via Python-list wrote: >> you have 10 minutes? Good luck!! >> >> >> 1. What is PEP8 ? > > It's the one between PEP7 and PEP9. > >> >> 2. What are the different ways to distribute some python source code ? > > Write on sheet of paper, fold into paper dart, throw from window. > >> >> 2 Lists > > Tut, tut, tut. > >> >> Let's define the function plural : >> >> def plural(words): >> plurals = [] >> for word in words: >> plurals.append(word + 's') >> return plurals >> >> for word in plural(['cabagge','owl','toy']): >> print word >> >> Question : How could the code of the function plural be optimised? > > It is all ready optimised for programmer time so don't bother with it > unless there are unforeseen bugs. > >> >> 3 Dictionaries >> >> Here are two dictionnaries : >> >> input = { >> 'foo1': 'bar1', >> 'chose': 'truc', >> 'foo2': 'bar2', >> } >> output = { >> 'bar1': 'foo1', >> 'truc': 'chose', >> 'bar2': 'foo2' >> } >> >> Question : Propose a function that returns output when you provide input ? > > def function(): > return input("Who cares?") > You have a couple of problems: 1. 'input' is already bound to a dict. 2. From question 2, it's clear that Python 2 is being used, so you should be using 'raw_input' instead. [snip] From greg.ewing at canterbury.ac.nz Tue Sep 22 20:47:25 2015 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 23 Sep 2015 12:47:25 +1200 Subject: Lightwight socket IO wrapper In-Reply-To: References: Message-ID: Random832 wrote: > Isn't this technically the same problem as pressing ctrl-d at a terminal > - it's not _really_ the end of the input (you can continue reading > after), but it sends the program something it will interpret as such? Yes. There's no concept of "closing the connection" with UDP, because there's no connection. So if a read returns 0 bytes, it must be because someone sent you a 0-length datagram. -- Greg From rgacote at appropriatesolutions.com Tue Sep 22 22:29:34 2015 From: rgacote at appropriatesolutions.com (Ray Cote) Date: Tue, 22 Sep 2015 22:29:34 -0400 Subject: =?UTF-8?Q?Re=3A_A_little_test_for_you_Guys=F0=9F=98=9C?= In-Reply-To: References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Message-ID: On Tue, Sep 22, 2015 at 7:32 PM, Mark Lawrence wrote: > >> 2 Lists >> > > Tut, tut, tut. That is not a list, that is a tutple. -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Tue Sep 22 22:40:01 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 22 Sep 2015 19:40:01 -0700 Subject: sort help References: Message-ID: <87io71dfjy.fsf@jester.gateway.sonic.net> Larry Martell writes: > def GetObjKey(a): > return a[2] This function is called operator.itemgetter: from operator import itemgetter sorted(a + b + c, key=itemgetter(2)) > So for example, if my initial data was this (I'll only show the fields > involved with the sort - the first number is a[2] above and the second > is the new additional sorting field, only present in a) sorted(sorted(a, key=itemgetter(5)) + b + c, key = itemgetter(2)) or whatever the new field (instead of 5) is for a. From torriem at gmail.com Wed Sep 23 00:25:31 2015 From: torriem at gmail.com (Michael Torrie) Date: Tue, 22 Sep 2015 22:25:31 -0600 Subject: Successfully send sms with python In-Reply-To: <05ab0edd-7285-4aca-b603-76e94dd8f0aa@googlegroups.com> References: <05ab0edd-7285-4aca-b603-76e94dd8f0aa@googlegroups.com> Message-ID: <560229BB.7030501@gmail.com> On 09/22/2015 05:19 AM, Timon Rhynix wrote: > When run it, the "message sent!" is printed but no message is sent/delivered. > Please assist on what I am missing. Thank you Is this "message sent!" from your code or is it a message you get back on the serial port from the gsm modem? Oh nevermind I see that it comes from your own code. Just an observation, but your code looks quite Java-like. Seems to me that wrapping this up in a class is not necessary, since the goal is to provide an interface to send a text message, I'd just use a plain function, stored in its own module so it can also store things like the name of the serial port, timeout values, etc. There's no need to make the caller save any state. Consider something like this with no error checking when using the serial port, no context managers for the serial device: file sms.py: ---------------------- import serial import time serial_port = 'COM13' timeout = 5 baud = 460800 def send_message(recipient, message): ser = serial.Serial(serial_port, baud, timeout=timeout) time.sleep(1) self.ser.write('ATZ\r') time.sleep(1) self.ser.write('AT+CMGF=1\r') time.sleep(1) self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r\n''') time.sleep(1) self.ser.write(self.content + "\r\n") time.sleep(1) self.ser.write(chr(26)) time.sleep(1) print "message sent!" ser.close() ------------------------ Someone can just do: import sms sms.serial_port = "/dev/ttyUSB2" sms.send_message("5555555","Hi there") Call it good. Unlike Java, Python does not require everything to be wrapped up in a class. Particularly if what you really want is a singleton. In many respects you can treat a python module (a python file) as a singleton. You can use its namespace to store some state or basic config information, and define the functions you want others to use. Private helper functions can start with an underscore, telling others not to use them. From jondy.zhao at gmail.com Wed Sep 23 01:27:55 2015 From: jondy.zhao at gmail.com (Jondy Zhao) Date: Tue, 22 Sep 2015 22:27:55 -0700 (PDT) Subject: Line by Line Debug Python Scripts In GDB Message-ID: There is a gdb extension "libpython.py" within Python sources, it could print Python frame, locals/globals variable, Python sources in GDB. But it couldn't set breakpoints in Python scripts directly. Finally, I decided to write a debugger to extend GDB could debug Python scripts line by line, just like debugging c/c++. This project is published in github, https://jondy.github.io/pyddd The purpose of this project is to debug Python scripts line by line as debug C/C++ in GDB, so that we can easily debug Python scripts and C/C++ extensions within GDB. From auriocus at gmx.de Wed Sep 23 02:26:15 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 23 Sep 2015 08:26:15 +0200 Subject: A little test for you =?UTF-8?B?R3V5c/CfmJw=?= In-Reply-To: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Message-ID: You've got a lot of sensible answers, but let me add to this one: Am 22.09.15 um 20:43 schrieb Python_Teacher: > input = { > 'foo1': 'bar1', > 'chose': 'truc', > 'foo2': 'bar2', > } > output = { > 'bar1': 'foo1', > 'truc': 'chose', > 'bar2': 'foo2' > } This one can be done as a dict comprehension: >>> p = {'foo1': 'bar1', 'foo2': 'bar2', 'chose': 'truc'} >>> { v:k for k,v in p.items()} {'bar1': 'foo1', 'truc': 'chose', 'bar2': 'foo2'} list/dict comprehension is actually one of the features in Python that I like most, because it can greatly ease such transformations. ....and, as others said, these questions are lightyears apart from showing that somebody understands Python programming. They can be solved by trying it or googling, and that is what a real programmer would actually do if he is stuck. Christian From auriocus at gmx.de Wed Sep 23 02:40:58 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 23 Sep 2015 08:40:58 +0200 Subject: Postscript to pdf In-Reply-To: References: <201509201812.t8KICXHu004041@fido.openend.se> <201509201909.t8KJ93oU018314@fido.openend.se> <201509201952.t8KJqh7W029272@fido.openend.se> <201509202250.t8KMoC0h009296@fido.openend.se> Message-ID: Am 21.09.15 um 17:20 schrieb Baladjy KICHENASSAMY: > Hello, > This is my programe : on mac i was able to output ps file but i didn't > got the pdf file :/ Maybe ps2pdf is not installed? I think it doesn't come with the Mac. You need to get it via fink, homebrew, macports or an official ghostscript binary. The same holds true for convert, which is a tool from ImageMagick. Yet another option would be to wrap the pdf4tcl library: http://sourceforge.net/projects/pdf4tcl/ It can create PDF from a canvas without an external dependency. The Tcl code for it looks like this: > package require pdf4tcl > set size [list [winfo width $win] [winfo height $win]] > set pdf [pdf4tcl::new %AUTO% -paper $size -compress false] > $pdf canvas $win > $pdf write -file $fn > $pdf destroy In principle, you could run this code via Tkinter.eval() You would need to set "win" to your canvas path and "fn" to the file name path. Yet another option would be to use a Python package like Reportlab to create the PDFs, which requires you to reimplement the drawing code. Christian From marco.nawijn at colosso.nl Wed Sep 23 02:55:52 2015 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Tue, 22 Sep 2015 23:55:52 -0700 (PDT) Subject: Python, convert an integer into an index? In-Reply-To: References: <201509222221.t8MMLMi5015927@fido.openend.se> Message-ID: <819c13d8-670c-46e2-8a43-c8224b42867f@googlegroups.com> On Wednesday, September 23, 2015 at 1:27:51 AM UTC+2, MRAB wrote: > On 2015-09-22 23:21, Laura Creighton wrote: > > In a message of Tue, 22 Sep 2015 14:43:55 -0700, Chris Roberts writes: > >> > >> > >>(How do I make it into an index? ) > >>Preferably something fairly easy to understand as I am new at this. > >> > >>results = 134523 #(Integer) > >> > >>Desired: > >>results = [1, 2, 3, 4, 5, 2, 3] #(INDEX) > >> > >>Somehow I see ways to convert index to list to int, but not back again. > >> > >>Thanks, > >>crzzy1 > > > > You need to convert your results into a string first. > > > > result_int=1234523 > > result_list=[] > > > > for digit in str(result_int): > > result_list.append(int(digit)) > > > > digit will be assigned to successive 1 character long strings. Since > > you wanted a list of integers, you have to convert it back. > > > > If you are learning python you may be interested in the tutor mailing > > list. https://mail.python.org/mailman/listinfo/tutor > > > A shorter way using strings: > > >>> results = 134523 > >>> list(map(int, str(results))) > [1, 3, 4, 5, 2, 3] Or you can use a list comprehension: >>> result = [int(c) for c in str(134523)] >>> print result [1, 3, 4, 5, 2, 3] From __peter__ at web.de Wed Sep 23 03:05:25 2015 From: __peter__ at web.de (Peter Otten) Date: Wed, 23 Sep 2015 09:05:25 +0200 Subject: sort help References: Message-ID: Larry Martell wrote: > I currently have 3 lists of lists and I sort them based on a common > field into a single list like this: > > def GetObjKey(a): > return a[2] > > sorted(a + b + c, key=GetObjKey) > > Which works just fine. > > But now, I need to have just the first list (a) also sub sorted by > another field and I can't quite figure out how to do this. > > So for example, if my initial data was this (I'll only show the fields > involved with the sort - the first number is a[2] above and the second > is the new additional sorting field, only present in a) > > a[1, 4] > a[1, 2] > a[2, 3] > a[2, 1] > a[5, 6] > a[5, 2] > b[2] > b[5] > c[1] > c[6] > > Then I'd want my sorted list to be this: > > a[1,2] > a[1,4] > c[1] > a[2,1] > a[2,3] > b[2] > a[5,2] > a[5,6] > b[5] > c[6] > > I hope that's clear. > > So is there some pythonic way to sort this without resorting to a > brute force old fashioned plow through the data? Performing two sorts as suggested by Chris and Paul is cleaner, but it is possible to write the key function you were probably looking for. def get_obj_key(a): if has_extra_field(a): return a[2], 0, a[-1] # assuming a[-1] is the extra field else: return a[2], 1 You have to write the has_extra_field() test yourself as I don't know what distinguishes the items in a from those in the other sequences. For example: >>> a = [[1, 4], [1, 2], [2, 3], [2, 1], [5, 6], [5, 2]] >>> b = [[2], [5]] >>> c = [[1], [6]] >>> sorted(a + b + c, ... key=lambda a: (a[0], 0, a[-1]) if len(a) > 1 else (a[0], 1)) [[1, 2], [1, 4], [1], [2, 1], [2, 3], [2], [5, 2], [5, 6], [5], [6]] From james.matthews at neuralt.com Wed Sep 23 04:03:21 2015 From: james.matthews at neuralt.com (James Matthews) Date: Wed, 23 Sep 2015 09:03:21 +0100 Subject: 64bit Python builds on HP-UX ia64 and PA-RISC (Using GCC) Message-ID: Hi, I'm having some issues getting 64bit Python builds on HP-UX. I'm using the GCC version available from the HP website. I've also tried using HP's compiler but don't have much success either, even following the readme. These are the results I get: PA-RISC: ./configure CC=/opt/hp-gcc64-4.7.1/bin/gcc make Traceback (most recent call last): File "./setup.py", line 2240, in main() File "./setup.py", line 2235, in main 'Lib/smtpd.py'] File "/tmp/jxm/Python-2.7.10/Lib/distutils/core.py", line 151, in setup dist.run_commands() File "/tmp/jxm/Python-2.7.10/Lib/distutils/dist.py", line 953, in run_commands self.run_command(cmd) File "/tmp/jxm/Python-2.7.10/Lib/distutils/dist.py", line 972, in run_command cmd_obj.run() File "/tmp/jxm/Python-2.7.10/Lib/distutils/command/build.py", line 127, in run self.run_command(cmd_name) File "/tmp/jxm/Python-2.7.10/Lib/distutils/cmd.py", line 326, in run_command self.distribution.run_command(command) File "/tmp/jxm/Python-2.7.10/Lib/distutils/dist.py", line 972, in run_command cmd_obj.run() File "/tmp/jxm/Python-2.7.10/Lib/distutils/command/build_ext.py", line 337, in run self.build_extensions() File "./setup.py", line 251, in build_extensions build_ext.build_extensions(self) File "/tmp/jxm/Python-2.7.10/Lib/distutils/command/build_ext.py", line 446, in build_extensions self.build_extension(ext) File "./setup.py", line 287, in build_extension if not self.configure_ctypes(ext): File "./setup.py", line 2041, in configure_ctypes exec f in fficonfig File "build/temp.hp-ux-B.11.31-9000-800-2.7/libffi/fficonfig.py", line 33, in ffi_sources += ffi_platforms['PA64_HPUX'] KeyError: 'PA64_HPUX' *** Error exit code 1 During make I also get lots of errors like this: ./pyconfig.h:1188:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default] ia64: ./configure CC=/opt/hp-gcc-4.7.1/bin/gcc CFLAGS="-mlp64" Make ./pyconfig.h:1188:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default] :0:0: note: this is the location of the previous definition /opt/hp-gcc-4.7.1/bin/gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes Parser/acceler.o Parser/grammar1.o Parser/listnode.o Parser/node.o Parser/parser.o Parser/parsetok.o Parser/bitset.o Parser/metagrammar.o Parser/firstsets.o Parser/grammar.o Parser/pgen.o Objects/obmalloc.o Python/mysnprintf.o Python/pyctype.o Parser/tokenizer_pgen.o Parser/printgrammar.o Parser/pgenmain.o -lnsl -lrt -ldld -ldl -o Parser/pgen ld: Mismatched Data ABI. Expected None but found EF_IA_64_ABI64 in file Parser/acceler.o Fatal error. collect2: error: ld returned 1 exit status *** Error exit code 1 Stop. *** Error exit code 1 Seems to be a library mismatch? Any help would be appreciated. Regards, James From info at egenix.com Wed Sep 23 04:12:11 2015 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 23 Sep 2015 10:12:11 +0200 Subject: ANN: eGenix mxODBC Connect 2.1.4 - Remote Python Database Interface Message-ID: <56025EDB.8080508@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com mxODBC Connect Remote Python Database Interface Version 2.1.4 mxODBC Connect is our commercially supported client-server product for connecting Python applications to relational databases in a truly platform independent way. This announcement is also available on our website for online reading: http://www.egenix.com/company/news/eGenix-mxODBC-Connect-2.1.4-GA.html ________________________________________________________________________ INTRODUCTION The mxODBC Connect Database Interface for Python allows users to easily connect Python applications to all major databases on the market today in a highly portable, convenient and secure way. Python Database Connectivity the Easy Way ----------------------------------------- Building on our mxODBC database interface for Python, mxODBC Connect is designed as client-server application, so you no longer need to find production quality database drivers for all platforms you target with your Python application. Instead, you use an easy to install royalty-free Python client library which connects directly to the mxODBC Connect database server over the network. This makes mxODBC Connect a great basis for writing cross-platform multi-tier database applications and utilities in Python, especially if you run applications that need to communicate with databases such as MS SQL Server and MS Access, Oracle Database, IBM DB2 and Informix, Sybase ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more, that run on Windows or Linux machines. Ideal for Database Driven Client Applications --------------------------------------------- By removing the need to install and configure ODBC drivers on the client side and dealing with complicated network setups for each set of drivers, mxODBC Connect greatly simplifies deployment of database driven client applications, while at the same time making the network communication between client and database server more efficient and more secure. For more information, please have a look at the mxODBC Connect product page, in particular, the full list of available features. For more information, please see the product page: http://www.egenix.com/products/python/mxODBCConnect/ ________________________________________________________________________ NEWS mxODBC Connect 2.1.4 is a patch level release of our successful mxODBC Connect database product. It includes these enhancements and fixes: Security Enhancements --------------------- * Updated included OpenSSL libraries to 1.0.1p. Please see the egenix-pyopenssl change log for a complete list of changes. Among other security fixes, this addresses the Logjam attack. http://www.egenix.com/products/python/pyOpenSSL/changelog.html mxODBC Connect Enhancements --------------------------- * Added support for the BinaryNull work-around added to mxODBC 3.3.5 in order to better support VARBINARY columns in MS SQL Server. Both mxODBC Connect Client and Server will need to upgraded to version 2.1.4 in order to be able to use the new singleton. * The mxODBC Connect Client can now be compiled to a wheel file to simplify deployment. Simply point the pip at the prebuilt archive. mxODBC API Enhancements ----------------------- * Upgraded the mxODBC Connect Server to mxODBC 3.3.5: http://www.egenix.com/company/news/eGenix-mxODBC-3.3.5-GA.html MS SQL Server ------------- * Documented and recommended use of SET NOCOUNT ON for running multiple statements or stored procedures. This can not only resolve issues with error reporting, it also results in better performance. * Added a work-around for MS SQL Server Native Client to be able to support VARCHAR/VARBINARY(MAX) columns when using the Native Client with direct execution mode or Python type binding mode. Thanks to ZeOmega for reporting this. * Added new helper singleton BinaryNull to allow binding a NULL to a VARBINARY column with SQL Server in direct execution mode or Python type binding mode (as used for FreeTDS). Using the usual None doesn't work in those cases, since SQL Server does not accept a VARCHAR data type as input for VARBINARY, except by using an explicit "CAST(? AS VARBINARY)". mxODBC binds None as VARCHAR for best compatibility, when not getting any type hints from the ODBC driver. * Added a fix for the MS SQL Server Native Client error "[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]The data types varchar and text are incompatible in the equal to operator." when trying to bind a string of more than 256 bytes to a VARCHAR column while using cursor.executedirect(). cursor.execute() was unaffected by this. Thanks to Paul Perez for reporting this. * Added a note to avoid using "execute " when calling stored procedures with MS SQL Server. This can result in '[Microsoft][SQL Native Client]Invalid Descriptor Index' errors. Simply dropping the "execute " will have the error go away. * Added a work-around to address the FreeTDS driver error '[FreeTDS][SQL Server]The data types varbinary and image are incompatible in the equal to operator.' when trying to bind binary strings longer than 256 bytes to a VARBINARY column. This problem does not occur with the MS SQL Server Native Client. * Reenabled returning cursor.rowcount for FreeTDS >= 0.91. In previous versions, FreeTDS could return wrong data for .rowcount when using SELECTs.This should make SQLAlchemy users happy again. * Add work-around to have FreeTDS ODBC driver accept binary data in strings as input for VARBINARY columns. A side effect of this is that FreeTDS will now also accept binary data in VARCHAR columns. SAP Sybase ASE -------------- * Added work-arounds and improvements for Sybase ASE ODBC drivers to enable working with BINARY and VARBINARY columns. * Added a work-around for a cursor.rowcount problem with Sybase ASE's ODBC driver on 64-bit platforms. It sometimes returns 4294967295 instead of -1. * Added note about random segfault problems with the Sybase ASE 15.7 ODBC driver on Windows. Unfortunately, there's nothing much we can do about this, other than recommend using the Sybase ASE 15.5 ODBC driver version which does not have these stability problems. Fixes --------------------- * Added improved documentation on the direct execution model available in mxODBC. This can help in more complex parameter binding situations and also provides performance boosts for a few databases, including e.g. MS SQL Server. For the full set of changes, including those of the 2.1 series of mxODBC Connect, please check the mxODBC Connect change log: http://www.egenix.com/products/python/mxODBCConnect/changelog.html ________________________________________________________________________ UPGRADING You are encouraged to upgrade to this latest mxODBC Connect release. When upgrading, please always upgrade both the server and the client installations to the same version - even for patch level releases. We will give out 20% discount coupons for upgrade purchases going from mxODBC Connect Server 1.x to 2.1 and 50% coupons for upgrades from mxODBC Connect Server 2.x to 2.1. Please contact the eGenix.com Sales Team (sales at egenix.com) with your existing license serials for details. Users of our stand-alone mxODBC product will have to purchase new licenses from our online shop in order to use mxODBC Connect. You can request free 30-day evaluation licenses by visiting our web-site or writing to sales at egenix.com, stating your name (or the name of the company) and the number of eval licenses that you need. http://www.egenix.com/products/python/mxODBCConnect/#Evaluation ________________________________________________________________________ DOWNLOADS The download archives as well as instructions for installation and configuration of the product can be found on the product page: http://www.egenix.com/products/python/mxODBCConnect/ If you want to try the package, jump straight to the download instructions: http://www.egenix.com/products/python/mxODBCConnect/#Download Fully functional evaluation licenses for the mxODBC Connect Server are available free of charge: http://www.egenix.com/products/python/mxODBCConnect/#Evaluation The mxODBC Connect Client is always free of charge. _______________________________________________________________________ SUPPORT Commercial support for this product is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. _______________________________________________________________________ INFORMATION About eGenix (http://www.egenix.com/): eGenix is a Python software project, consulting and product company delivering expert services and professional quality products for companies, Python users and developers. We specialize in database driven applications, large scale software designs and integration. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Sep 23 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ 2015-09-14: Released mxODBC Plone/Zope DA 2.2.3 http://egenix.com/go84 2015-09-26: Python Meeting Duesseldorf Sprint 2015 3 days to go 2015-10-21: Python Meeting Duesseldorf ... 28 days to go eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ From pavel at schon.cz Wed Sep 23 04:46:57 2015 From: pavel at schon.cz (Pavel S) Date: Wed, 23 Sep 2015 01:46:57 -0700 (PDT) Subject: Successfully send sms with python In-Reply-To: <05ab0edd-7285-4aca-b603-76e94dd8f0aa@googlegroups.com> References: <05ab0edd-7285-4aca-b603-76e94dd8f0aa@googlegroups.com> Message-ID: <60b3f59b-bf9e-4e77-ae78-67c3c54962d4@googlegroups.com> I don't understand why all of you are telling him about '\r\n\, write(),..' instead of recommending to use take library which already has all problems resolved (python-gammu / wammu). When one will write custom templating stuff, you would also recommend him to take jinja. From as at sci.fi Wed Sep 23 05:01:58 2015 From: as at sci.fi (Anssi Saari) Date: Wed, 23 Sep 2015 12:01:58 +0300 Subject: Python, convert an integer into an index? References: <201509222221.t8MMLMi5015927@fido.openend.se> Message-ID: Dennis Lee Bieber writes: > On Wed, 23 Sep 2015 00:21:22 +0200, Laura Creighton > declaimed the following: > > >> >>You need to convert your results into a string first. >> >>result_int=1234523 >>result_list=[] >> >>for digit in str(result_int): >> result_list.append(int(digit)) >> > > Rather wordy... > >>>> [int(i) for i in str(1234523)] > [1, 2, 3, 4, 5, 2, 3] I'm suprised. Why not just: list(str(results)) In other words, is there something else the list constructor should do with a string other than convert it to a list? From lac at openend.se Wed Sep 23 05:17:35 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 23 Sep 2015 11:17:35 +0200 Subject: 64bit Python builds on HP-UX ia64 and PA-RISC (Using GCC) In-Reply-To: References: Message-ID: <201509230917.t8N9HZ9K031140@fido.openend.se> In a message of Wed, 23 Sep 2015 09:03:21 +0100, James Matthews writes: >Hi, > >I'm having some issues getting 64bit Python builds on HP-UX. I'm using the >GCC version available from the HP website. I've also tried using HP's >compiler but don't have much success either, even following the readme. >These are the results I get: > >PA-RISC: > >./configure CC=/opt/hp-gcc64-4.7.1/bin/gcc >make > >Traceback (most recent call last): > File "./setup.py", line 2240, in > main() > File "./setup.py", line 2235, in main > 'Lib/smtpd.py'] > File "/tmp/jxm/Python-2.7.10/Lib/distutils/core.py", line 151, in setup > dist.run_commands() > File "/tmp/jxm/Python-2.7.10/Lib/distutils/dist.py", line 953, in >run_commands > self.run_command(cmd) > File "/tmp/jxm/Python-2.7.10/Lib/distutils/dist.py", line 972, in >run_command > cmd_obj.run() > File "/tmp/jxm/Python-2.7.10/Lib/distutils/command/build.py", line 127, >in run > self.run_command(cmd_name) > File "/tmp/jxm/Python-2.7.10/Lib/distutils/cmd.py", line 326, in >run_command > self.distribution.run_command(command) > File "/tmp/jxm/Python-2.7.10/Lib/distutils/dist.py", line 972, in >run_command > cmd_obj.run() > File "/tmp/jxm/Python-2.7.10/Lib/distutils/command/build_ext.py", line >337, in run > self.build_extensions() > File "./setup.py", line 251, in build_extensions > build_ext.build_extensions(self) > File "/tmp/jxm/Python-2.7.10/Lib/distutils/command/build_ext.py", line >446, in build_extensions > self.build_extension(ext) > File "./setup.py", line 287, in build_extension > if not self.configure_ctypes(ext): > File "./setup.py", line 2041, in configure_ctypes > exec f in fficonfig > File "build/temp.hp-ux-B.11.31-9000-800-2.7/libffi/fficonfig.py", line >33, in > ffi_sources += ffi_platforms['PA64_HPUX'] >KeyError: 'PA64_HPUX' >*** Error exit code 1 > >During make I also get lots of errors like this: ./pyconfig.h:1188:0: >warning: "_POSIX_C_SOURCE" redefined [enabled by default] > > >ia64: > >./configure CC=/opt/hp-gcc-4.7.1/bin/gcc CFLAGS="-mlp64" >Make > >./pyconfig.h:1188:0: warning: "_POSIX_C_SOURCE" redefined [enabled by >default] >:0:0: note: this is the location of the previous definition > /opt/hp-gcc-4.7.1/bin/gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall >-Wstrict-prototypes Parser/acceler.o Parser/grammar1.o >Parser/listnode.o Parser/node.o Parser/parser.o Parser/parsetok.o >Parser/bitset.o Parser/metagrammar.o Parser/firstsets.o >Parser/grammar.o Parser/pgen.o Objects/obmalloc.o Python/mysnprintf.o >Python/pyctype.o Parser/tokenizer_pgen.o Parser/printgrammar.o >Parser/pgenmain.o -lnsl -lrt -ldld -ldl -o Parser/pgen >ld: Mismatched Data ABI. Expected None but found EF_IA_64_ABI64 in file >Parser/acceler.o >Fatal error. >collect2: error: ld returned 1 exit status >*** Error exit code 1 >Stop. >*** Error exit code 1 > >Seems to be a library mismatch? > >Any help would be appreciated. > >Regards, >James >-- >https://mail.python.org/mailman/listinfo/python-list I think you have this problem. http://h30499.www3.hp.com/t5/Languages-and-Scripting/Conpilation-errors-on-HP-UX-11-31-IA64/td-p/4777801#.VgJtfUlZLZs Laura From skybuck2000 at hotmail.com Wed Sep 23 05:26:07 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Wed, 23 Sep 2015 11:26:07 +0200 Subject: Dummy Decoder Example (was Re: Parallel decoding lesson for you.) In-Reply-To: References: <62ee4$55f9719c$d47876e2$58812@news.ziggo.nl> <80671$55fd6f0a$d47876e2$43083@news.ziggo.nl> <6da10$55fd7ac4$d47876e2$19200@news.ziggo.nl> <72397$55fd7db9$d47876e2$29766@news.ziggo.nl> <9aca0$55fd863e$d47876e2$56488@news.ziggo.nl> <39418$55fd8fac$d47876e2$21797@news.ziggo.nl> <9f6cc$55fd9981$d47876e2$58134@news.ziggo.nl> <109e3$55fda507$d47876e2$30929@news.ziggo.nl> <5d560$55fda6eb$d47876e2$37866@news.ziggo.nl> <956248d4-2f8c-475b-8e41-533370589170@googlegroups.com> <4fe26$55fe0126$d47876e2$49025@news.ziggo.nl> <9c80f$55feb011$d47876e2$2668@news.ziggo.nl> <6d8e8$55fec8fa$d47876e2$62254@news.ziggo.nl> Message-ID: The example may be modified as much as needed. For now my solution needs a little reading pad to avoid costly mods or branches or whatever. I think this is a nice speedy solution, so code may be modified as follows: const MaxProcessorCount = 4; var // information stream, input Stream : array[0..20+(MaxProcessorCount-1)] of integer; // add max processor count to create a safe "padding" for reading so no out of bounds/range check errors with arrays. Bye, Sybuck. From lac at openend.se Wed Sep 23 05:30:29 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 23 Sep 2015 11:30:29 +0200 Subject: Successfully send sms with python In-Reply-To: <560229BB.7030501@gmail.com> References: <05ab0edd-7285-4aca-b603-76e94dd8f0aa@googlegroups.com> <560229BB.7030501@gmail.com> Message-ID: <201509230930.t8N9UTx7032238@fido.openend.se> In a message of Tue, 22 Sep 2015 22:25:31 -0600, Michael Torrie writes: >Consider something like this with no error checking when using the >serial port, no context managers for the serial device: >file sms.py: >---------------------- >import serial >import time > >serial_port = 'COM13' >timeout = 5 >baud = 460800 > >def send_message(recipient, message): > ser = serial.Serial(serial_port, baud, timeout=timeout) > time.sleep(1) > self.ser.write('ATZ\r') > time.sleep(1) > self.ser.write('AT+CMGF=1\r') > time.sleep(1) > self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r\n''') > time.sleep(1) > self.ser.write(self.content + "\r\n") > time.sleep(1) > self.ser.write(chr(26)) > time.sleep(1) > print "message sent!" > > ser.close() 2 questions. Why all the sleep(1)s? and don't you need to flush the thing after each write? Laura From cs at zip.com.au Wed Sep 23 05:30:36 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 23 Sep 2015 19:30:36 +1000 Subject: Successfully send sms with python In-Reply-To: <60b3f59b-bf9e-4e77-ae78-67c3c54962d4@googlegroups.com> References: <60b3f59b-bf9e-4e77-ae78-67c3c54962d4@googlegroups.com> Message-ID: <20150923093036.GA92566@cskk.homeip.net> On 23Sep2015 01:46, Pavel S wrote: >I don't understand why all of you are telling him about '\r\n\, write(),..' instead of recommending to use take library which already has all problems resolved (python-gammu / wammu). Sometimes it is useful to know how things are done instead of which big dumb button to push. Besides, he came here saying: I'm doing this, what am I doing wrong? We're trying to help him with this. It is not always about the final destination you know. Cheers, Cameron Simpson From skybuck2000 at hotmail.com Wed Sep 23 05:39:38 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Wed, 23 Sep 2015 11:39:38 +0200 Subject: Dummy Decoder Example (was Re: Parallel decoding lesson for you.) In-Reply-To: References: <62ee4$55f9719c$d47876e2$58812@news.ziggo.nl> <80671$55fd6f0a$d47876e2$43083@news.ziggo.nl> <6da10$55fd7ac4$d47876e2$19200@news.ziggo.nl> <72397$55fd7db9$d47876e2$29766@news.ziggo.nl> <9aca0$55fd863e$d47876e2$56488@news.ziggo.nl> <39418$55fd8fac$d47876e2$21797@news.ziggo.nl> <9f6cc$55fd9981$d47876e2$58134@news.ziggo.nl> <109e3$55fda507$d47876e2$30929@news.ziggo.nl> <5d560$55fda6eb$d47876e2$37866@news.ziggo.nl> <956248d4-2f8c-475b-8e41-533370589170@googlegroups.com> <4fe26$55fe0126$d47876e2$49025@news.ziggo.nl> <9c80f$55feb011$d47876e2$2668@news.ziggo.nl> <6d8e8$55fec8fa$d47876e2$62254@news.ziggo.nl> Message-ID: Here is the C version of the example in case your Delphi-to-C skills are not so great or you lazy lol =D: // ParallelDecodingCVersion.cpp : Defines the entry point for the console application. // #include "stdafx.h" // Begin of Dummy Decoder Example const int MaxProcessorCount = 4; int _tmain(int argc, _TCHAR* argv[]) { // information stream, input int Stream[21+(MaxProcessorCount-1)]; // add max processor count to create a safe "padding" for reading so no out of bounds/range check errors with arrays. // bits representing fields of data int a1,a2,a3,a4; int b1,b2,b3; int c1; int d1,d2,d3,d4,d5,d6; // output int RowIndex; int RowCount; int RowLength[6]; int RowOffset[6]; int DataOffset; int FieldCount; int FieldLength; int Processor[4]; // debug fields int FieldA; int FieldB; int FieldC; int FieldD; a1 = 1; a2 = 1; a3 = 1; a4 = 1; b1 = 1; b2 = 1; b3 = 1; c1 = 1; d1 = 1; d2 = 1; d3 = 1; d4 = 1; d5 = 1; d6 = 1; // compute input fields to compare it later with output fields FieldA = (a1) | (a2 << 1) | (a3 << 2) | (a4 << 3); FieldB = (b1) | (b2 << 1) | (b3 << 2); FieldC = (c1); FieldD = (d1) | (d2 << 1) | (d3 << 2) | (d4 << 3) | (d5 << 4) | (d6 << 5); // print field values printf( "FieldD: %d \n", FieldD ); printf( "FieldA: %d \n", FieldA ); printf( "FieldB: %d \n", FieldB ); printf( "FieldC: %d \n\n", FieldC ); // number of rows Stream[0] = 6; // row lengths Stream[1] = 4; Stream[2] = 3; Stream[3] = 3; Stream[4] = 2; Stream[5] = 1; Stream[6] = 1; // sorted information stream: // d1a1b1c1d2a2b2d3a3b3d4a4d5d6 // data bits Stream[7] = d1; Stream[8] = a1; Stream[9] = b1; Stream[10] = c1; Stream[11] = d2; Stream[12] = a2; Stream[13] = b2; Stream[14] = d3; Stream[15] = a3; Stream[16] = b3; Stream[17] = d4; Stream[18] = a4; Stream[19] = d5; Stream[20] = d6; // now the decoding algorithm: // determine number of rows RowCount = Stream[0]; // extract row lengths RowLength[0] = Stream[1]; RowLength[1] = Stream[2]; RowLength[2] = Stream[3]; RowLength[3] = Stream[4]; RowLength[4] = Stream[5]; RowLength[5] = Stream[6]; // determine field count FieldCount = RowLength[0]; // row[0] indicates number of fields. // I will help out a bit... by leaving this code in ! ;) seems somewhat obvious ;) // first determine data offset properly ! ;) :) 1 for the row count + // RowCount to skip over row lengths. DataOffset = 1 + RowCount; RowOffset[0] = DataOffset; RowOffset[1] = RowOffset[0] + RowLength[0]; RowOffset[2] = RowOffset[1] + RowLength[1]; RowOffset[3] = RowOffset[2] + RowLength[2]; RowOffset[4] = RowOffset[3] + RowLength[3]; RowOffset[5] = RowOffset[4] + RowLength[4]; // some how the data bits from the stream needs to end up in these 4 // processors so that it produces the same values // as below: // fields may be processed in a different order though. // *** You will need to replace this code with your own code... and // preferably it should be parallel, fast and somewhat general/scalable. *** Processor[0] = FieldD; Processor[1] = FieldA; Processor[2] = FieldB; Processor[3] = FieldC; // print processor values. printf( "Processor[0]: %d \n", Processor[0] ); printf( "Processor[1]: %d \n", Processor[1] ); printf( "Processor[2]: %d \n", Processor[2] ); printf( "Processor[3]: %d \n\n", Processor[3] ); return 0; } // End of Dummy Decoder Example Bye, Skybuck :) From skybuck2000 at hotmail.com Wed Sep 23 05:43:40 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Wed, 23 Sep 2015 11:43:40 +0200 Subject: Dummy Decoder Example (was Re: Parallel decoding lesson for you.) In-Reply-To: References: <62ee4$55f9719c$d47876e2$58812@news.ziggo.nl> <80671$55fd6f0a$d47876e2$43083@news.ziggo.nl> <6da10$55fd7ac4$d47876e2$19200@news.ziggo.nl> <72397$55fd7db9$d47876e2$29766@news.ziggo.nl> <9aca0$55fd863e$d47876e2$56488@news.ziggo.nl> <39418$55fd8fac$d47876e2$21797@news.ziggo.nl> <9f6cc$55fd9981$d47876e2$58134@news.ziggo.nl> <109e3$55fda507$d47876e2$30929@news.ziggo.nl> <5d560$55fda6eb$d47876e2$37866@news.ziggo.nl> <956248d4-2f8c-475b-8e41-533370589170@googlegroups.com> <4fe26$55fe0126$d47876e2$49025@news.ziggo.nl> <9c80f$55feb011$d47876e2$2668@news.ziggo.nl> <6d8e8$55fec8fa$d47876e2$62254@news.ziggo.nl> Message-ID: <8e2e1$5602744b$d47876e2$21409@news.ziggo.nl> Also here is test set 2 to test input values: // input test 2, c version a1 = 1; a2 = 0; a3 = 0; a4 = 1; b1 = 1; b2 = 1; b3 = 0; c1 = 1; d1 = 1; d2 = 1; d3 = 0; d4 = 0; d5 = 1; d6 = 0; Bye, Skybuck. From jldunn2000 at gmail.com Wed Sep 23 05:51:53 2015 From: jldunn2000 at gmail.com (loial) Date: Wed, 23 Sep 2015 02:51:53 -0700 (PDT) Subject: Modify environment variable for subprocess Message-ID: <6f8c6233-9777-488f-9026-fec729fef6d1@googlegroups.com> I need to modify the LIBPATH environment variable when running a process via subprocess, but otherwise retain the existing environment. Whats the best way to do that? From cs at zip.com.au Wed Sep 23 06:00:41 2015 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 23 Sep 2015 20:00:41 +1000 Subject: Modify environment variable for subprocess In-Reply-To: <6f8c6233-9777-488f-9026-fec729fef6d1@googlegroups.com> References: <6f8c6233-9777-488f-9026-fec729fef6d1@googlegroups.com> Message-ID: <20150923100041.GA47662@cskk.homeip.net> On 23Sep2015 02:51, loial wrote: >I need to modify the LIBPATH environment variable when running a process via subprocess, but otherwise retain the existing environment. > >Whats the best way to do that? Make a copy of os.environ, modify the copy, pass it via the env=parameter of subprocess.Popen. That is the most direct and controllable method. Cheers, Cameron Simpson Tachyon: A gluon that's not completely dry. From robin at reportlab.com Wed Sep 23 06:20:06 2015 From: robin at reportlab.com (Robin Becker) Date: Wed, 23 Sep 2015 11:20:06 +0100 Subject: problem building python 3.5 extensions for windows In-Reply-To: References: <55FFFE50.8090703@chamonix.reportlab.co.uk> <7f633007-1391-4172-a022-262899537981@googlegroups.com> <56012A0C.5040805@chamonix.reportlab.co.uk> <56015904.8050608@chamonix.reportlab.co.uk> Message-ID: <56027CD6.8050406@chamonix.reportlab.co.uk> On 22/09/2015 22:37, cjgohlke at gmail.com wrote: > On Tuesday, September 22, 2015 at 1:49:16 PM UTC-7, Terry Reedy wrote: >> On 9/22/2015 9:35 AM, Robin Becker wrote: >>> On 22/09/2015 11:14, Robin Becker wrote: >>>> On 22/09/2015 01:36, CG wrote: >>> .........t >>>>> . >>>>> >>>> Thanks for the pointer Christoph. >>>> >>>> I certainly didn't let it run for 30 minutes. When I build with 2.7, >>>> 3.3 or 3.4 >>>> the whole build including reportlab stuff is over in a couple of >>>> minutes. I will >>>> try again, but a linker that takes 30 minutes to create an extension >>>> that ends >>>> up 204Kb long has to be seriously broken. Is it trying to hard? Most >>>> of the code >>>> size is in arrays for code points etc etc. >>> >>> I timed my builds of pyRXPU for x86 + amd64; these are on a core i5-3470 >>> @ 3.20Ghz with 4Gb memory. >>> >>> python 3.4 1 minute 14 seconds >>> python 3.5 52 minutes 50 seconds >>> >>> so with VS2015 it will now take me an hour to make and test any changes >>> to this extension. I don't see how the issue can be considered closed. >>> VS2015 is clearly not the way forward for any reasonable development >>> process. >> >> I think you should add the above to the issue. >> >> -- >> Terry Jan Reedy > > It's a compiler bug. To work around, disable compiler optimizations, i.e. set `extra_compile_args=['/Od']` in setup.py. > > -- > Christoph > Thanks Christoph, I guessed it must be something like that. I suppose it's trying desperately to place small chunks of encoding tables or something. -- Robin Becker From lac at openend.se Wed Sep 23 06:37:23 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 23 Sep 2015 12:37:23 +0200 Subject: Modify environment variable for subprocess In-Reply-To: <6f8c6233-9777-488f-9026-fec729fef6d1@googlegroups.com> References: <6f8c6233-9777-488f-9026-fec729fef6d1@googlegroups.com> Message-ID: <201509231037.t8NAbNGq005091@fido.openend.se> In a message of Wed, 23 Sep 2015 02:51:53 -0700, loial writes: >I need to modify the LIBPATH environment variable when running a process via subprocess, but otherwise retain the existing environment. > >Whats the best way to do that? import subprocess, os my_env = os.environ # if your program should be able to modify the current env # otherwise my_env = os.environ.copy() # if it shouldn't # if you just want to add something to the existing LIBPATH my_env["LIBPATH"] = "/where/I/want/to/look/first:" + my_env["LIBPATH"] # otherwise my_env["LIBPATH"] = "/what/I/want" subprocess.Popen(my_program, env=my_env) Setting os.environ leaks memory under Mac OS and FreeBSD. I am not sure if this means that if you do this a gazillion times on a Mac you will have a problem. Laura From michi.schwarz at gmail.com Wed Sep 23 06:43:25 2015 From: michi.schwarz at gmail.com (Michael Schwarz) Date: Wed, 23 Sep 2015 12:43:25 +0200 Subject: True == 1 weirdness In-Reply-To: References: <55fc0e4d$0$1645$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6D16DDCF-9B8C-4D53-9A28-407FDA2F0E86@gmail.com> On 2015-09-19, at 09:19, Gregory Ewing wrote: > Random832 wrote: >> I'm disputing that chained comparisons are used for the particular >> combinations that I am actually arguing should not be used in python. >> Such as a < b > c or a != b != c [whereas a may or may not be equal to >> c] > > I can't remember offhand seeing a != b != c written by a > mathematician, but if I did, I would suspect that he > *intended* it to imply a != c, even if that's not a strict > logical consequence of the notation. Mathematica interprets a != b != c as "none of a, b or c are equal". See [0]. It does this by parsing it to Unequal[a, b, c] (square brackets are function calls), where Unequal then implements that operation. Normally I'm used to Mathematica being a very consistent language. But being prepared by this thread, I of course wondered where the inconsistencies start here and whether inequalities mix well with comparisons. They don't: While b != c != d gets parsed as this: Unequal[b, c, d] But a < b != c != d < e gets parsed as this: And[Less[a, b], Unequal[b, c], Unequal[c, d], Less[d, e]] Which means that a != b != c is interpreted differently depending on context. I don't think every mathematician would agree which of these interpretations make sense. :) [0]: https://reference.wolfram.com/language/ref/Unequal.html -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 842 bytes Desc: Message signed with OpenPGP using GPGMail URL: From skybuck2000 at hotmail.com Wed Sep 23 07:10:14 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Wed, 23 Sep 2015 13:10:14 +0200 Subject: Cyber Grand Challenge, prizes up to 2 million dollars ! (DARPA) Message-ID: (Click on little icon on website top left for menu): Information about challenge: http://www.cybergrandchallenge.com/site/index.html#about https://cgc.darpa.mil/CGC_Rules_16_May_14_Version_2.pdf Perhaps this will be a yearly contest. There is a catch though, to collect the prizes: "The prize recipient shall be a citizen, a permanent resident of the United States, or a US Entity. " Bye, Skybuck. From skybuck2000 at hotmail.com Wed Sep 23 07:25:24 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Wed, 23 Sep 2015 13:25:24 +0200 Subject: Cyber Grand Challenge, prizes up to 2 million dollars ! (DARPA) In-Reply-To: References: Message-ID: <88171$56028c23$d47876e2$27690@news.ziggo.nl> Also very interesting read: https://cgc.darpa.mil/CGC_FAQ.pdf Just the list of common programming mistakes is already pretty interesting ! ;) =D Bye, Skybuck. From skybuck2000 at hotmail.com Wed Sep 23 07:37:34 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Wed, 23 Sep 2015 13:37:34 +0200 Subject: Cyber Grand Challenge, prizes up to 2 million dollars ! (DARPA) In-Reply-To: <88171$56028c23$d47876e2$27690@news.ziggo.nl> References: <88171$56028c23$d47876e2$27690@news.ziggo.nl> Message-ID: Also very interesting read: http://blog.trailofbits.com/2015/07/15/how-we-fared-in-the-cyber-grand-challenge/ " How We Fared in the Cyber Grand Challenge July 15, 2015 by Artem Dinaburg 6 Comments The Cyber Grand Challenge qualifying event was held on June 3rd, at exactly noon Eastern time. At that instant, our Cyber Reasoning System (CRS) was given 131 purposely built insecure programs. During the following 24 hour period, our CRS was able to identify vulnerabilities in 65 of those programs and rewrite 94 of them to eliminate bugs built in their code. This proves, without a doubt, that it is not only possible but achievable to automate the actions of a talented software auditor. Despite the success of our CRS at finding and patching vulnerabilities, we did not qualify for the final event, to be held next year. There was a fatal flaw that lowered our overall score to 9th, below the 7th place threshold for qualification. In this blog post we?ll discuss how our CRS works, how it performed against competitor systems, what doomed its score, and what we are going to do next. Cyber Grand Challenge Background The goal of the Cyber Grand Challenge (CGC) is to combine the speed and scale of automation with the reasoning capabilities of human experts. Multiple teams create Cyber Reasoning Systems (CRSs) that autonomously reason about arbitrary networked programs, prove the existence of flaws in those programs, and automatically formulate effective defenses against those flaws. How well these systems work is evaluated through head-to-head tournament-style competition. The competition has two main events: the qualifying event and the final event. The qualifying event was held on June 3, 2015. The final event is set to take place during August 2016. Only the top 7 competitors from the qualifying event proceed to the final event. During the qualifying event, each competitor was given the same 131 challenges, or purposely built vulnerable programs, each of which contained at least one intentional vulnerability. For 24 hours, the competing CRSes faced off against each other and were scored according to four criteria. The full details are in the CGC Rules, but here?s a quick summary: The CRS had to work without human intervention. Any teams found to use human assistance were disqualified. The CRS had to patch bugs in challenges. Points were gained for every bug successfully patched. Challenges with no patched bugs received zero points. The CRS could prove bugs exist in challenges. The points from patched challenges were doubled if the CRS could generate an input that crashed the challenge. The patched challenges had to function and perform almost as well as the originals. Points were lost based on performance and functionality loss in the patched challenges. A spreadsheet with all the qualifying event scores and other data used to make the graphs in this post is available from DARPA (Trail of Bits is the ninth place team). With the scoring in mind, let?s review the Trail of Bits CRS architecture and the design decisions we made. Preparation We?re a small company with a distributed workforce, so we couldn?t physically host a lot of servers. Naturally, we went with cloud computing to do processing; specifically, Amazon EC2. Those who saw our tweets know we used a lot of EC2 time. Most of that usage was purely out of caution. We didn?t know how many challenges would be in the qualifying event ? just that it would be ?more than 100.? We prepared for a thousand, with each accompanied by multi-gigabyte network traffic captures. We were also terrified of an EC2 region-wide failure, so we provisioned three different CRS instances, one in each US-based EC2 region, affectionately named Biggie (us-east-1), Tupac (us-west-2), and Dre (us-west-1). It turns out that there were only 131 challenges and no gigantic network captures in the qualifying event. During the qualifying event, all EC2 regions worked normally. We could have comfortably done the qualifying event with 17 c4.8xlarge EC2 instances, but instead we used 297. Out of our abundance of caution, we over-provisioned by a factor of ~17x. Bug Finding The Trail of Bits CRS was ranked second by the number of verified bugs found (Figure 1). This result is impressive considering that we started with nothing while several other teams already had existing bug finding systems prior to CGC. Figure 1: Teams in the qualifying event ranked by number of bugs found. Orange bars signify finalists. Our CRS used a multi-pronged strategy to find bugs (Figure 2). First, there was fuzzing. Our fuzzer is implemented with a custom dynamic binary translator (DBT) capable of running several 32-bit challenges in a single 64-bit address space. This is ideal for challenges that feature multiple binaries communicating with one another. The fuzzer?s instrumentation and mutation are separated, allowing for pluggable mutation strategies. The DBT framework can also snapshot binaries at any point during execution. This greatly improves fuzzing speed, since it?s possible to avoid replaying previous inputs when exploring new input space. Figure 2: Our bug finding architecture. It is a feedback-based architecture that explores the state space of a program using fuzzing and symbolic execution. Figure 2: Our bug finding architecture. It is a feedback-based architecture that explores the state space of a program using fuzzing and symbolic execution. In addition to fuzzing, we had not one but two symbolic execution engines. The first operated on the original unmodified binaries, and the second operated on the translated LLVM from mcsema. Each symbolic execution engine had its own strengths, and both contributed to bug finding. The fuzzer and symbolic execution engines operate in a feedback loop mediated by a system we call MinSet. The MinSet uses branch coverage to maintain a minimum set of maximal coverage inputs. The inputs come from any source capable of generating them: PCAPs, fuzzing, symbolic execution, etc. Every tool gets original inputs from MinSet, and feeds any newly generated inputs into MinSet. This feedback loop lets us explore the possible input state with both fuzzers and symbolic execution in parallel. In practice this is very effective. We log the provenance of our crashes, and most of them look something like: Network Capture ? Fuzzer ? SymEx1 ? Fuzzer ? Crash Some bugs can only be triggered when the input replays a previous nonce, which would be different on every execution of the challenge. Our bug finding system can produce inputs that contain variables based on program outputs, enabling our CRS to handle such cases. Additionally, our symbolic executors are able to identify which inputs affect program state at the point of a crash. This is a key requirement for the success of any team competing in the final as it enables the CRS to create a more controlled crash. Patching Our CRS?s patching effectiveness, as measured by the security score, ranks as fourth (Figure 3). Figure 3: Teams in the qualifying event ranked by patch effectiveness (security score). Orange bars signify finalists. Figure 3: Teams in the qualifying event ranked by patch effectiveness (security score). Orange bars signify finalists. Our CRS patches bugs by translating challenges into LLVM bitcode with mcsema. Patches are applied to the LLVM bitcode, optimized, and then converted back into executable code. The actual patching works by gracefully terminating the challenge when invalid memory accesses are detected. Patching the LLVM bitcode representation of challenges provides us with enormous power and flexibility: We can easily validate any memory access and keep track of all memory allocations. Complex algorithms, such as dataflow tracking, dominator trees, dead store elimination, loop detection, etc., are very simple to implement using the LLVM compiler infrastructure. Our patching method can be used on real-world software, not just CGC challenges. We created two main patching strategies: generic patching and bug-based patching. Generic patching is an exclusion-based strategy: it first assumes that every memory access must be verified, and then excludes accesses that are provably safe. The benefit of generic patching is that it patches all possible invalid memory accesses in a challenge. Bug-based patching is an inclusion-based strategy: it first assumes only one memory access (where the CRS found a bug) must be verified, and then includes nearby accesses that may be unsafe. Each patching strategy has multiple heuristics to determine which accesses should be included or excluded from verification. The inclusion and exclusion heuristics generate patched challenges with different security/performance tradeoffs. The patched challenges generated by these heuristics were tested for performance and security to determine which heuristic performed best while still fixing the bug. For the qualifying event, we evaluated both generic and bug-based patching, but ultimately chose a generic-only patching strategy. Bug-based patching was slightly more performant, but generic patching was more comprehensive and it patched bugs that our CRS couldn?t find. Functionality and Performance Functionality and performance scores combine to create an availability score. The availability score is used as a scaling factor for points gained by patching and bug finding. This scaling factor only matters for successfully patched challenges, since those are the only challenges that can score points. The following graphs only consider functionality and performance of successfully patched challenges. Functionality Out of the 94 challenges that our CRS successfully patched, 56 retained full functionality, 30 retained partial functionality, and 8 were nonfunctional. Of the top 10 teams in the qualifying event, our CRS ranks 5th in terms of fully functional patched challenges (Figure 4). We suspect our patched challenges lost functionality due to problems in mcsema, our x86 to LLVM translator. We hope to verify and address these issues once DARPA open-sources the qualifying event challenges. Figure 4: The count of perfectly functional, partially functional, and nonfunctional challenges submitted by each of the top 10 teams in the qualifying event. Orange bars signify finalists. Figure 4: The count of perfectly functional, partially functional, and nonfunctional challenges submitted by each of the top 10 teams in the qualifying event. Orange bars signify finalists. Performance The performance of patched challenges is how our CRS snatched defeat from the jaws of victory. Of the top ten teams in the qualifying event, our CRS placed last in terms of patched challenge performance (Figure 5). Figure 5: Average and median performance scores of the top ten qualifying event participants. Orange bars signify finalists. Figure 5: Average and median performance scores of the top ten qualifying event participants. Orange bars signify finalists. Our CRS produces slow binaries for two reasons: technical and operational. The technical reason is that performance of our patched challenges is an artifact of our patching process, which translates challenges into LLVM bitcode and then re-emits them as executable binaries. The operational reason is that our patching was developed late and optimized for the wrong performance measurements. So, why did we optimize for the wrong performance measurements? The official CGC performance measurement tools were kept secret, because the organizers wanted to ensure that no one could cheat by gaming the performance measurements. Therefore, we had to measure performance ourselves, and our metrics showed that CPU overhead of our patched challenges was usually negligible. The main flaw that we observed was that our patched challenges used too much memory. Because of this, we spent time and effort optimizing our patching to use less memory in favor of using more CPU time. It turns out we optimized for the wrong thing, because our self-measurement did not agree with the official measurement tools (Table 1). When self-measuring, our worst-performing patching method had a median CPU overhead of 33% and a median memory overhead of 69%. The official qualifying event measured us at 76% CPU overhead and 28% memory overhead. Clearly, our self-measurements were considerably different from official measurements. Measurement Median CPU Overhead Median Memory Overhead Worst Self-Measured Patching Method 33% 69% Official Qualifying Event 76% 28% Table 1: Self measured CPU and memory overhead and the official qualifying event CPU and memory overhead. Our CRS measured its overall score with our own performance metrics. The self-measured score of our CRS was 106, which would have put us in second place. The real overall score was 21.36, putting us in ninth. An important aspect of software development is choosing where to focus your efforts, and we chose poorly. CGC participants had access to the official measuring system during two scored events held during the year, one in December 2014 and one in April 2015. We should have evaluated our patching system thoroughly during both scored events. Unfortunately, our patching wasn?t fully operational until after the second scored event, so we had no way to verify the accuracy of our self-measurement. The performance penalty of our patching isn?t a fundamental issue. Had we known how bad it was, we would have fixed it. However, according to our own measurements the patching was acceptable so we focused efforts elsewhere. What?s Next? According to the CGC FAQ (Question 46), teams are allowed to combine after the qualifying event. We hope to join forces with another team that qualified for the CGC final event, and use the best of both our technologies to win. The technology behind our CRS will provide a significant advantage to any team that partners with us. If you would like to discuss a potential partnership for the CGC final, please contact us at cgc at trailofbits.com. If we cannot find a partner for the CGC final, we will focus our efforts on adapting our CRS to automatically find and patch vulnerabilities in real software. Our system is up to the task: it has already proven that it can find bugs, and all of its core components were derived from software that works on real Linux binaries. Several components even have Windows and 64-bit support, and adding support for other platforms is a possibility. If you are interested in commercial applications of our technology, please get in touch with us at cgc at trailofbits.com. Finally, we plan to contribute back fixes and updates to the open source projects utilized in our CRS. We used numerous open source projects during development, and have made several custom fixes and modifications. We look forward to contributing these back to the community so that everyone benefits from our improvements. " Bye, Skybuck =D From narges.asadi at ymail.com Wed Sep 23 07:37:56 2015 From: narges.asadi at ymail.com (Narges Asadi) Date: Wed, 23 Sep 2015 11:37:56 +0000 (UTC) Subject: an installing problem Message-ID: <1121531331.192221.1443008276312.JavaMail.yahoo@mail.yahoo.com> Hello I?ve encountered a problem when I wanted to install Python3.5. I? sent you the?log file.Please help me to fix the problem. ? ? Thanks The Best Narges Asadi? -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Python 3.5.0 (32-bit)_20150923145319.log Type: application/octet-stream Size: 67024 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Error.png Type: image/png Size: 54927 bytes Desc: not available URL: From larry.martell at gmail.com Wed Sep 23 08:21:34 2015 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 23 Sep 2015 08:21:34 -0400 Subject: sort help In-Reply-To: References: Message-ID: On Tue, Sep 22, 2015 at 6:55 PM, Chris Angelico wrote: > On Wed, Sep 23, 2015 at 8:42 AM, Larry Martell wrote: >> I currently have 3 lists of lists and I sort them based on a common >> field into a single list like this: >> >> def GetObjKey(a): >> return a[2] >> >> sorted(a + b + c, key=GetObjKey) >> >> Which works just fine. >> >> But now, I need to have just the first list (a) also sub sorted by >> another field and I can't quite figure out how to do this. > > Have you tried simply sorting a by the other field prior to doing your > merge-and-sort? The Python list.sort() method is guaranteed to be > stable. I can't find a comparable guarantee for sorted(), but worst > case, you should be able to do your list merge, and then explicitly > name it and sort it. Thanks to everyone for the replied. I ended up just presorting he first list, then merging and sorting all 3. Very simple. Not sure why I didn't see that. Probably comes from working 75 hours/week. From lorenzofsutton at gmail.com Wed Sep 23 08:23:28 2015 From: lorenzofsutton at gmail.com (Lorenzo Sutton) Date: Wed, 23 Sep 2015 14:23:28 +0200 Subject: Python 3 windows installer problem [WAS: Re: an installing problem] In-Reply-To: <1121531331.192221.1443008276312.JavaMail.yahoo@mail.yahoo.com> References: <1121531331.192221.1443008276312.JavaMail.yahoo@mail.yahoo.com> Message-ID: <560299C0.2030601@gmail.com> Hi, Not too familiar with the 'new' Python 3 installer on windows.. but On 23/09/2015 13:37, Narges Asadi wrote: > Hello > I?ve encountered a problem when I wanted to install Python 3.5. > I sent you the log file. Please help me to fix the problem. From the log: [0F4C:1110][2015-09-23T14:54:17]e000: Error 0x80072ee7: Failed to send request to URL: https://www.python.org/ftp/python/3.5.0/win32/core_pdb.msi, trying to process HTTP status code anyway. which seems to be reachable now... so maybe a network problem when you were installing?? Look here about installing without downloading, it might be helpful. https://docs.python.org/3/using/windows.html#installing-without-downloading This bug report might also be relevant: https://bugs.python.org/issue25126 Hope this helps. Lorenzo. From shankarphy at gmail.com Wed Sep 23 08:47:14 2015 From: shankarphy at gmail.com (SANKAR .) Date: Wed, 23 Sep 2015 22:47:14 +1000 Subject: Readlines returns non ASCII character Message-ID: Hi all, I am not a expert programmer but I have to extract information from a large file. I used codecs.open(..) with UTF16 encoding to read this file. It could read all the lines in the file but returns with the non Ascii characters. Below are 5 sample lines. How do I avoid having this non Ascii items. Is there a better way to read this? Thanks Sankar ? ??? 2 0 1 5 - 0 8 - 2 8 ???1 7 : 2 2 : 0 3 ? ?  0???E L E K T A _ E O S _ R T D _ V X 2 ??? ??? 0??? ??? ??? 0??? ??? ??? 0??? ??? ??? ? 0??? ???M L C X ???M L C X  P???0 . 0 ???0 . 0 ???0 . 0  P??? ??? ???N o n e  P??? ??? ???0  P??? ??? ???O U T  P??? ??? ???0  P??? ??? ???- 5 . 0  P??? ??? ???6 0 . 0 P??? ??? ???0 . 5 2 P??? ??? ???6 . 4 9 P??? ??? ???2 0 . 0 0 -------------- next part -------------- An HTML attachment was scrubbed... URL: From denismfmcmahon at gmail.com Wed Sep 23 11:32:47 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 23 Sep 2015 15:32:47 +0000 (UTC) Subject: Python, convert an integer into an index? References: Message-ID: On Tue, 22 Sep 2015 14:43:55 -0700, Chris Roberts wrote: > results = 134523 #(Integer) This appears to be an integer expressed (presumably) in base 10 with 6 digits > Desired: > results = [1, 2, 3, 4, 5, 2, 3] #(INDEX) This appears to be a python list of 7 elements, with the first and the the third through seventh elements corresponding to the first and the second through sixth most significant digits respectively of the previously discussed integer. I can't actually see any direct method of creating the list given from the number given. However, if I understand the intent of the question you meant to ask, you might find that the following code does something interesting: x = 9876543210 y = [] while x > 0: y.append(x % 10) x = int(x / 10) y = list(reversed(y)) print y -- Denis McMahon, denismfmcmahon at gmail.com From tundra at bogus-city.tundraware.com Wed Sep 23 11:55:17 2015 From: tundra at bogus-city.tundraware.com (Tim Daneliuk) Date: Wed, 23 Sep 2015 10:55:17 -0500 Subject: Python, convert an integer into an index? In-Reply-To: References: Message-ID: <5kuadc-qg4.ln1@oceanview.tundraware.com> On 09/22/2015 04:43 PM, Chris Roberts wrote: > > (How do I make it into an index? ) > Preferably something fairly easy to understand as I am new at this. > > results = 134523 #(Integer) > > Desired: > results = [1, 2, 3, 4, 5, 2, 3] #(INDEX) > > Somehow I see ways to convert index to list to int, but not back again. > > Thanks, > crzzy1 > results = [x for x in str(results)] From ian.g.kelly at gmail.com Wed Sep 23 12:07:36 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 23 Sep 2015 10:07:36 -0600 Subject: Readlines returns non ASCII character In-Reply-To: References: Message-ID: On Wed, Sep 23, 2015 at 6:47 AM, SANKAR . wrote: > Hi all, > > I am not a expert programmer but I have to extract information from a large > file. > I used codecs.open(..) with UTF16 encoding to read this file. It could > read all the lines in the file but returns with the non Ascii characters. > Below are 5 sample lines. How do I avoid having this non Ascii items. Is > there a better way to read this? I suspect that what you want is not "non-ASCII" but just to read the file without all the mojibake, which is likely an indication that you're using the wrong encoding. Do you know that UTF-16 is actually the encoding of the file? Based on the spaces that appear between adjacent characters, I would guess that this is probably in a 32-bit encoding, perhaps UTF-32. On the other hand, the repeated 0x00ff 0x00fe 0x00ff are very curious; I don't see how that could be valid UTF-32. Are you sure that this is a text file and not some propietary binary data format? From thecjguy1 at gmail.com Wed Sep 23 12:18:42 2015 From: thecjguy1 at gmail.com (Chris Roberts) Date: Wed, 23 Sep 2015 12:18:42 -0400 Subject: Python, convert an integer into an index? In-Reply-To: <201509222221.t8MMLMi5015927@fido.openend.se> References: <201509222221.t8MMLMi5015927@fido.openend.se> Message-ID: Fantastic! I started a course, but I have been having issues with string/index/list/integer conversions and manipulations. This variation wasn't in any of my texts or class exercises either. Your way was both simple enough to understand and very informative! Thanks. On Tue, Sep 22, 2015 at 6:21 PM, Laura Creighton wrote: > In a message of Tue, 22 Sep 2015 14:43:55 -0700, Chris Roberts writes: > > > > > >(How do I make it into an index? ) > >Preferably something fairly easy to understand as I am new at this. > > > >results = 134523 #(Integer) > > > >Desired: > >results = [1, 2, 3, 4, 5, 2, 3] #(INDEX) > > > >Somehow I see ways to convert index to list to int, but not back again. > > > >Thanks, > >crzzy1 > > You need to convert your results into a string first. > > result_int=1234523 > result_list=[] > > for digit in str(result_int): > result_list.append(int(digit)) > > digit will be assigned to successive 1 character long strings. Since > you wanted a list of integers, you have to convert it back. > > If you are learning python you may be interested in the tutor mailing > list. https://mail.python.org/mailman/listinfo/tutor > > Laura > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hemla21 at gmail.com Wed Sep 23 12:20:43 2015 From: hemla21 at gmail.com (Heli Nix) Date: Wed, 23 Sep 2015 09:20:43 -0700 (PDT) Subject: PyInstaller+ Python3.5 (h5py import error) In-Reply-To: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> Message-ID: <4ca597c9-5b1f-4709-a88b-5ecc78d1c590@googlegroups.com> Dear all, Thanks a lot for your replies. Very helpful. I have already done some trials with Virtualenv, but PyInstaller is much closer to the idea of an installer you can pass to someone. I have been using development version of PyInstaller in order to be able to use it with my script written with Python versin 3.3.5. I started with a very simple script just to test. I use the following command to create the distribution folder. pyinstaller test.py my script contains the following few lines and it runs ok on my own machine. import numpy as np import h5py a=np.arange(10) print(a) inputFiles="test.h5" with h5py.File(inputFiles, 'w') as inputFileOpen: pass I am getting the following error related to importing h5py. test returned -1 Traceback (most recent call last): File "", line 2, in File "/usr/lib/python3.3/site-packages/PyInstaller-3.0.dev2-py3.3.egg/PyInstaller/loader/pyimod03_importers.py", line 311, in load_module File "/usr/lib64/python3.3/site-packages/h5py/__init__.py", line 23, in File "/usr/lib/python3.3/site-packages/PyInstaller-3.0.dev2-py3.3.egg/PyInstaller/loader/pyimod03_importers.py", line 493, in load_module File "h5r.pxd", line 21, in init h5py._conv (/tmp/pip_build_root/h5py/h5py/_conv.c:6563) File "/usr/lib/python3.3/site-packages/PyInstaller-3.0.dev2-py3.3.egg/PyInstaller/loader/pyimod03_importers.py", line 493, in load_module File "_objects.pxd", line 12, in init h5py.h5r (/tmp/pip_build_root/h5py/h5py/h5r.c:2708) File "/usr/lib/python3.3/site-packages/PyInstaller-3.0.dev2-py3.3.egg/PyInstaller/loader/pyimod03_importers.py", line 493, in load_module File "_objects.pyx", line 1, in init h5py._objects (/tmp/pip_build_root/h5py/h5py/_objects.c:6407) ImportError: No module named 'h5py.defs' If I modify my script to import numpy as np import h5py a=np.arange(10) print(a) then, the created exectuable will run successfully on other linux machines. Does anybody have any idea why I am getting the following h5py import error? My spec file also looks like this: # -*- mode: python -*- block_cipher = None a = Analysis(['test.py'], pathex=['/home/albert/test'], binaries=None, datas=None, hiddenimports=[], hookspath=None, runtime_hooks=None, excludes=None, win_no_prefer_redirects=None, win_private_assemblies=None, cipher=block_cipher) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE(pyz, a.scripts, exclude_binaries=True, name='test', debug=False, strip=None, upx=True, console=True ) coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=None, upx=True, name='test') Thank you very much in Advance for your help, From gengyangcai at gmail.com Wed Sep 23 13:46:21 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Wed, 23 Sep 2015 10:46:21 -0700 (PDT) Subject: Video Tutorial Online On How To Create a Basic Dynamic Website In Python? Message-ID: <1d8574ba-f319-4d8f-822f-00687266b4ff@googlegroups.com> Hello! So I have Python 2.7.10, 3.3.2, 3.3.4 downloaded on my Mac OS X Yosemite 10.10.2 and also downloaded pip and django. Is there an online tutorial on how to create a basic dynamic website in Python where I can put my image/photo/video sharing app ? I find it much easier to learn from something visual which I can follow step-by-step ... Thanks a lot. Cai Gengyang From alister.nospam.ware at ntlworld.com Wed Sep 23 14:06:19 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 23 Sep 2015 18:06:19 +0000 (UTC) Subject: A little test for you =?UTF-8?B?R3V5c/CfmJw=?= References: <78fc66f6-04f9-4b84-8410-2e74fb75fbb4@googlegroups.com> Message-ID: On Wed, 23 Sep 2015 00:56:19 +0100, MRAB wrote: > On 2015-09-23 00:32, Mark Lawrence wrote: >> On 22/09/2015 19:43, Python_Teacher via Python-list wrote: >>> you have 10 minutes? Good luck!! >>> >>> >>> 1. What is PEP8 ? >> >> It's the one between PEP7 and PEP9. >> >> >>> 2. What are the different ways to distribute some python source code ? >> >> Write on sheet of paper, fold into paper dart, throw from window. >> >> >>> 2 Lists >> >> Tut, tut, tut. >> >> >>> Let's define the function plural : >>> >>> def plural(words): >>> plurals = [] >>> for word in words: >>> plurals.append(word + 's') >>> return plurals >>> >>> for word in plural(['cabagge','owl','toy']): >>> print word >>> >>> Question : How could the code of the function plural be optimised? >> >> It is all ready optimised for programmer time so don't bother with it >> unless there are unforeseen bugs. >> >> >>> 3 Dictionaries >>> >>> Here are two dictionnaries : >>> >>> input = { >>> 'foo1': 'bar1', 'chose': 'truc', 'foo2': 'bar2', >>> } >>> output = { >>> 'bar1': 'foo1', 'truc': 'chose', 'bar2': 'foo2' >>> } >>> >>> Question : Propose a function that returns output when you provide >>> input ? >> >> def function(): >> return input("Who cares?") >> > You have a couple of problems: > > 1. 'input' is already bound to a dict. > > 2. From question 2, it's clear that Python 2 is being used, so you > should be using 'raw_input' instead. > > [snip] the question also shadows a builtin :-) -- This is for all ill-treated fellows Unborn and unbegot, For them to read when they're in trouble And I am not. -- A. E. Housman From auriocus at gmx.de Wed Sep 23 14:07:44 2015 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 23 Sep 2015 20:07:44 +0200 Subject: PyInstaller+ Python3.5 (h5py import error) In-Reply-To: <4ca597c9-5b1f-4709-a88b-5ecc78d1c590@googlegroups.com> References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> <4ca597c9-5b1f-4709-a88b-5ecc78d1c590@googlegroups.com> Message-ID: Am 23.09.15 um 18:20 schrieb Heli Nix: > Dear all, > > Thanks a lot for your replies. Very helpful. I have already done some trials with Virtualenv, but PyInstaller is much closer to the idea of an installer you can pass to someone. > > I have been using development version of PyInstaller in order to be able to use it with my script written with Python versin 3.3.5. > > I started with a very simple script just to test. I use the following command to create the distribution folder. > > pyinstaller test.py > > my script contains the following few lines and it runs ok on my own machine. > > import numpy as np > import h5py > > a=np.arange(10) > print(a) > inputFiles="test.h5" > with h5py.File(inputFiles, 'w') as inputFileOpen: > pass > > I am getting the following error related to importing h5py. > > [...] > ImportError: No module named 'h5py.defs' pyinstaller guesses from the code which modules are imported. It looks like if h5py imports a module h5py.defs, which is missing. For some programs, you need to support pyinstaller with additional information, especially if modules are loaded at runtime. Try: pyinstaller --hidden-import=h5py.defs test.py > If I modify my script to > > import numpy as np > import h5py > a=np.arange(10) > print(a) This is another hint: obviously h5py defers module loading until you first really open a HDF5 file. There pyinstaller has no means to find this out. Christian From james.harris.1 at gmail.com Wed Sep 23 14:12:37 2015 From: james.harris.1 at gmail.com (James Harris) Date: Wed, 23 Sep 2015 19:12:37 +0100 Subject: List comprehensions and evaluation of elements therein Message-ID: A list comprehension has various components. Anyone know when each of the elements is evaluated? In the form [v0 for v0 in expr0 if expr1] If v0 appears in expr0 or expr1 the evaluation order matters. I think of the above as being a rewrite of results = [] for v0 in expr0: if expr1: results.append(v0) return results Further, [v0, v2 for v0 in expr0 if expr1 for v2 in expr2 if expr3] leads to results = [] for v0 in expr0: if expr1: for v2 in expr2: if expr3: results.append((v0, v2)) return results First of all, is that a correct analog of the list comprehension? With this latter expansion the values of v0 and v2 could appear in expr4 or expr5. Again, the evaluation order would matter. James From ian.g.kelly at gmail.com Wed Sep 23 14:24:20 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 23 Sep 2015 12:24:20 -0600 Subject: List comprehensions and evaluation of elements therein In-Reply-To: References: Message-ID: On Wed, Sep 23, 2015 at 12:12 PM, James Harris wrote: > A list comprehension has various components. Anyone know when each of the > elements is evaluated? In the form > > [v0 for v0 in expr0 if expr1] > > If v0 appears in expr0 or expr1 the evaluation order matters. > > I think of the above as being a rewrite of > > results = [] > for v0 in expr0: > if expr1: > results.append(v0) > return results > > Further, > > [v0, v2 for v0 in expr0 if expr1 for v2 in expr2 if expr3] > > leads to > > results = [] > for v0 in expr0: > if expr1: > for v2 in expr2: > if expr3: > results.append((v0, v2)) > return results > > First of all, is that a correct analog of the list comprehension? Looks right, see: https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries Note that the last sentence there about names not "leaking" is only true for Python 3. You may also be interested in PEPs 202 and 289. From kenseehart at gmail.com Wed Sep 23 15:02:07 2015 From: kenseehart at gmail.com (kenseehart at gmail.com) Date: Wed, 23 Sep 2015 12:02:07 -0700 (PDT) Subject: Sending a python argument to a Boost.Python function Message-ID: I have a python class that wraps a boost.python object. I am using a boost.python library function that requires the raw boost.python object. I want to be able to pass the python object to the boost api function. Is there a hook available on the python side that instructs boost to perform a conversion? Hypothetically, it would be something like this: class EggWrapper(object): def __init__(self, egg): object.__setattr__(self, '_egg', egg) def __getattribute__(self, name): egg = object.__getattribute__(self, '_egg') if name=='_egg': return egg if name in EggWrapper.__dict__: return object.__getattribute__(self, name) return getattr(egg, name) def __setattr__(self, name, value): egg = object.__getattribute__(self, '_egg') setattr(egg, name, value) def magic_boost_conversion_unicorn_hook(self): 'this is automatically called by boost to convert arguments' egg = object.__getattribute__(self, '_egg') return egg import myboostlib egg = EggWrapper(myboostlib.getEgg()) myboostlib.spam(egg) Where the signature for spam is: spam(class boost::python::api::object) And myboostlib.getEgg() returns a boost::python::api::object - I do not have the ability to modify the library or any C/C++ code, the solution must be entirely on the python side. - I can't change the calling convention. The wrapped object must be used (i.e. I can't just say myboostlib.spam(egg._egg), though that is the desired result). So the solution should be incorporated into the EggWrapper class. - I'm only interested in solutions that reflect expert knowledge of Boost.Python, since I believe I have already considered all the trivial solutions. So my question is, does magic_boost_conversion_unicorn_hook() exist, and if so, how is it spelled? Thanks, ~ Ken From ian.g.kelly at gmail.com Wed Sep 23 17:49:57 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 23 Sep 2015 15:49:57 -0600 Subject: Readlines returns non ASCII character In-Reply-To: References: Message-ID: On Wed, Sep 23, 2015 at 3:02 PM, SANKAR . wrote: > Thanks Ian, > this isn't a text file, but when I read with readline I get the data I need > along with mojibake. UTF 32 returns following error: > > Traceback (most recent call last): > File "D:\RV\RV1.py", line 17, in > linenumx1 = file.readlines() > File "C:\Python27\lib\codecs.py", line 682, in readlines > return self.reader.readlines(sizehint) > File "C:\Python27\lib\codecs.py", line 591, in readlines > data = self.read() > File "C:\Python27\lib\codecs.py", line 480, in read > newchars, decodedbytes = self.decode(data, self.errors) > File "C:\Python27\lib\encodings\utf_32.py", line 130, in decode > codecs.utf_32_ex_decode(input, errors, 0, False) > UnicodeDecodeError: 'utf32' codec can't decode bytes in position 0-3: code > point not in range(0x110000) 1) Open the file in binary mode using the open function, not using codecs.open. 2) Find out or figure out the file format. 3) Read the file and extract the particular fields that you're interested in from the file as bytes objects. 4) Decode those bytes objects and only those using UTF-32. From paul.hermeneutic at gmail.com Wed Sep 23 19:51:03 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Wed, 23 Sep 2015 17:51:03 -0600 Subject: Readlines returns non ASCII character In-Reply-To: References: Message-ID: If this starts at the beginning of the file, then it indicates that the file is UTF-16 (LE). UTF-8[t 1] EF BB BF 239 187 191 UTF-16 (BE) FE FF 254 255 UTF-16 (LE) FF FE 255 254 UTF-32 (BE) 00 00 FE FF 0 0 254 255 UTF-32 (LE) FF FE 00 00 255 254 0 0 From curtis.rendon at gmail.com Wed Sep 23 20:01:56 2015 From: curtis.rendon at gmail.com (mithra) Date: Wed, 23 Sep 2015 17:01:56 -0700 (PDT) Subject: Postscript to pdf In-Reply-To: References: <201509201812.t8KICXHu004041@fido.openend.se> <201509201909.t8KJ93oU018314@fido.openend.se> <201509201952.t8KJqh7W029272@fido.openend.se> <201509202250.t8KMoC0h009296@fido.openend.se> Message-ID: <681fe58f-92c2-461c-85d8-b700bcc893b9@googlegroups.com> On Tuesday, September 22, 2015 at 2:20:56 AM UTC-5, Bala Ji wrote: > Hello, > This is my programe : on mac i was able to output ps file but i didn't > got the pdf file :/ > > # -*- coding: utf-8 -*- > # script lecture_gif.py > from Tkinter import * > import tkMessageBox > import Tkconstants > import tkFileDialog > from PIL import ImageTk > import PIL.Image > import os, sys > import subprocess > > > def Ouvrir(): > Canevas.delete(ALL) # on efface la zone graphique > > filename = tkFileDialog.askopenfilename(title="Ouvrir une > image",filetypes=[('gif files','.gif'),('all files','.*')]) > print(filename) > photo = PhotoImage(file=filename) > gifdict[filename] = photo # r?f?rence > print(gifdict) > > Canevas.create_image(0,0,anchor=NW,image=photo) > Canevas.config(height=photo.height(),width=photo.width()) > > Mafenetre.title("Image "+str(photo.width())+" x "+str(photo.height())) > > def insertimage(): > n=tkFileDialog.askopenfilename(filetypes = [("Image Files", ("*.jpg", > "*.gif")),("JPEG",'*.jpg'),("GIF",'*.gif'),('All','*')]) > img = PIL.Image.open(n) > img = img.resize((229, 253)) > photoimg = ImageTk.PhotoImage(img) > label = Label(image=photoimg) > label.image = photoimg # keep a reference! > Canevas.create_image(65,320,anchor=W,image = photoimg) > def insertsign(): > n=tkFileDialog.askopenfilename(filetypes = [("Image Files", ("*.jpg", > "*.gif")),("JPEG",'*.jpg'),("GIF",'*.gif'),('All','*')]) > img = PIL.Image.open(n) > img = img.resize((300, 100)) > photoimg = ImageTk.PhotoImage(img) > Canevas.create_image(600,500,anchor=W,image = photoimg) > Canvas.pack() > > def Fermer(): > Canevas.delete(ALL) > Mafenetre.title("Image") > > def save(): > Canevas.update() > Canevas.postscript(file=tkFileDialog.asksaveasfilename(), colormode='color') > subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"]) > > # def convert(): > # ps2pdf -dEPSCrop image.ps > # convert -density 300 PASSPORTQUALITE.ps output.png > > # class TkFileDialogExample(Tkinter.Frame): > # > # def __init__(self, root): > # > # Tkinter.Frame.__init__(self, root) > # button_opt = {'fill': Tkconstants.BOTH, 'padx': 5, 'pady': 5} > # Tkinter.Button(self, text='Save', > command=self.asksaveasfilename).pack(**button_opt) > # > # self.file_opt = options = {} > # options['filetypes'] = [('all files', '.*'), ('text files', '.txt')] > # options['initialfile'] = 'myfile.txt' > # options['parent'] = root > # > # def asksaveasfilename(self): > # filename = tkFileDialog.asksaveasfilename(**self.file_opt) > # > # if filename: > # return open(filename, 'w') > # > # if __name__=='__main__': > # root = Tkinter.Tk() > # TkFileDialogExample(root).pack() > # root.mainloop() > def Apropos(): > tkMessageBox.showinfo("A propos","Tutorial") > > def Write(): > def delete(): > e1.delete(0,END) > e2.delete(0,END) > e3.delete(0,END) > e4.delete(0,END) > e5.delete(0,END) > e6.delete(0,END) > Canevas.delete("e1") > def valider(): > Canevas.create_text(315,200,anchor=W,text="Surname/Nom",fill='Black',font='Arial > 14') > Canevas.create_text(315,220,anchor=W,text=e1.get(),fill='Black',font='Arial > 30',tags ="e1") > Canevas.create_text(315,250,anchor=W,text="Given > name/Pr?nom",fill='Black',font='Arial 14') > Canevas.create_text(315,270,anchor=W,text=e2.get(),fill='Black',font='Arial > 30',tags ="e1") > Canevas.create_text(315,300,anchor=W,text="Fonction/Function",fill='Black',font='Arial > 14') > Canevas.create_text(315,320,anchor=W,text=e3.get(),fill='Black',font='Arial > 30',tags ="e1") > Canevas.create_text(470,395,anchor=W,text=e4.get(),fill='Black',font='Arial > 30',tags ="e1") > Canevas.create_text(500,438,anchor=W,text=e5.get(),fill='Black',font='Arial > 30',tags ="e1") > Canevas.create_text(228,503,anchor=W,text=e6.get(),fill='Black',font='Arial > 30',tags ="e1") > master = Tk() > Label(master, text="Surname/Nom").grid(row=0) > Label(master, text="Given name/Pr?nom").grid(row=1) > Label(master, text="Fonction/Function").grid(row=2) > Label(master, text="Validity Date").grid(row=3) > Label(master, text="Chef").grid(row=4) > Label(master, text="Student number").grid(row=5) > e1 = Entry(master) > e2 = Entry(master) > e3 = Entry(master) > e4 = Entry(master) > e5 = Entry(master) > e6 = Entry(master) > e1.grid(row=0, column=1) > e2.grid(row=1, column=1) > e3.grid(row=2, column=1) > e4.grid(row=3, column=1) > e5.grid(row=4, column=1) > e6.grid(row=5, column=1) > Button(master, text='Ok', command=valider).grid(row=2, column=2, > sticky=W, pady=4) > Button(master, text='Delete', command=delete).grid(row=3, column=2, > sticky=W, pady=4) > mainloop( ) > > # Main window > Mafenetre = Tk() > Mafenetre.title("Image") > > # Cr?ation d'un widget Menu > menubar = Menu(Mafenetre) > > menufichier = Menu(menubar,tearoff=0) > menufichier.add_command(label="Open mask",command=Ouvrir) > menufichier.add_command(label="Save mask",command=save) > #menufichier.add_command(label="Convert pdf",command=convert) > menufichier.add_command(label="Close mask",command=Fermer) > menufichier.add_command(label="Quit",command=Mafenetre.destroy) > menubar.add_cascade(label="File", menu=menufichier) > > menuwrite = Menu(menubar,tearoff=0) > menuwrite.add_command(label="Insert informations",command=Write) > menuwrite.add_command(label="Insert image",command=insertimage) > menuwrite.add_command(label="Insert signature",command=insertsign) > menubar.add_cascade(label="Informations", menu=menuwrite) > > > menuaide = Menu(menubar,tearoff=0) > menuaide.add_command(label="A propos",command=Apropos) > menubar.add_cascade(label="Aide", menu=menuaide) > > # Affichage du menu > Mafenetre.config(menu=menubar) > > # Cr?ation d'un widget Canvas > Canevas = Canvas(Mafenetre) > Canevas.pack(padx=5,pady=5) > > # Utilisation d'un dictionnaire pour conserver une r?f?rence > gifdict={} > > Mafenetre.mainloop() > > 2015-09-21 0:50 GMT+02:00 Laura Creighton : > > In a message of Sun, 20 Sep 2015 23:11:20 +0200, Baladjy KICHENASSAMY writes: > >>well one more question :/ > >> > >>i tried this > >> > >>def save(): > >> Canevas.update() > >> Canevas.postscript(file=tkFileDialog.asksaveasfilename(), > >>colormode='color') > >> subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"]) > >> Try putting the entire path to ps2pdf in the subprocess call, something like: /usr/local/bin/ps2pdf From paul.hermeneutic at gmail.com Wed Sep 23 20:07:14 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Wed, 23 Sep 2015 18:07:14 -0600 Subject: Readlines returns non ASCII character In-Reply-To: References: Message-ID: After looking at this briefly, I am not sure that this is a plain-text file. Interpreting it as UTF-16 LE shows that the characters are as they appear. Immediately after the BOM is: SINGLE LOW-9 QUOTATION MARK' (U+201A) START OF HEADING (U+0001) SPACE (U+0020) SPACE (U+0020) LATIN SMALL LETTER Y WITH DIAERESIS (U+00FF) LATIN SMALL LETTER THORN (U+00FE) LATIN SMALL LETTER Y WITH DIAERESIS (U+00FF) From python at mrabarnett.plus.com Wed Sep 23 20:09:58 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 24 Sep 2015 01:09:58 +0100 Subject: Readlines returns non ASCII character In-Reply-To: References: Message-ID: <56033F56.1020308@mrabarnett.plus.com> On 2015-09-24 00:51, paul.hermeneutic at gmail.com wrote: > If this starts at the beginning of the file, then it indicates that > the file is UTF-16 (LE). > > UTF-8[t 1] EF BB BF 239 187 191 > UTF-16 (BE) FE FF 254 255 > UTF-16 (LE) FF FE 255 254 > UTF-32 (BE) 00 00 FE FF 0 0 254 255 > UTF-32 (LE) FF FE 00 00 255 254 0 0 > The "signature" EF BB BF indicates the encoding called "utf-8-sig" by Python. It occurs on Windows. If the file doesn't start with any of these, then it could be using any encoding (except UTF-16 or UTF-32). From 4kir4.1i at gmail.com Wed Sep 23 20:12:01 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Thu, 24 Sep 2015 03:12:01 +0300 Subject: Modify environment variable for subprocess References: <6f8c6233-9777-488f-9026-fec729fef6d1@googlegroups.com> Message-ID: <871tdo3cby.fsf@gmail.com> loial writes: > I need to modify the LIBPATH environment variable when running a > process via subprocess, but otherwise retain the existing environment. > > Whats the best way to do that? Pass env=dict(os.environ, LIBPATH=value) parameter: import os import subprocess subprocess.check_call('echo $LIBPATH', shell=True, env=dict(os.environ, LIBPATH='/some/path')) From ian.g.kelly at gmail.com Wed Sep 23 21:37:43 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 23 Sep 2015 19:37:43 -0600 Subject: Readlines returns non ASCII character In-Reply-To: <56033F56.1020308@mrabarnett.plus.com> References: <56033F56.1020308@mrabarnett.plus.com> Message-ID: On Wed, Sep 23, 2015 at 6:09 PM, MRAB wrote: > On 2015-09-24 00:51, paul.hermeneutic at gmail.com wrote: >> >> If this starts at the beginning of the file, then it indicates that >> the file is UTF-16 (LE). >> >> UTF-8[t 1] EF BB BF 239 187 191 >> UTF-16 (BE) FE FF 254 255 >> UTF-16 (LE) FF FE 255 254 >> UTF-32 (BE) 00 00 FE FF 0 0 254 255 >> UTF-32 (LE) FF FE 00 00 255 254 0 0 >> > The "signature" EF BB BF indicates the encoding called "utf-8-sig" by > Python. It occurs on Windows. > > If the file doesn't start with any of these, then it could be using any > encoding (except UTF-16 or UTF-32). Yes, but what does it mean when the signature is 00 FF 00 FE 00 FF and occurs not at the beginning but repeatedly throughout the file, as appears in the OP's case? At least, I'm assuming that the high-order bytes are 00 based on what the OP posted. I wouldn't be surprised though if they're just being mangled by the terminal, if it happens to be a certain one that will not be named but uses CP 1252. From python at mrabarnett.plus.com Wed Sep 23 22:02:21 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 24 Sep 2015 03:02:21 +0100 Subject: Readlines returns non ASCII character In-Reply-To: References: <56033F56.1020308@mrabarnett.plus.com> Message-ID: <560359AD.1050600@mrabarnett.plus.com> On 2015-09-24 02:37, Ian Kelly wrote: > On Wed, Sep 23, 2015 at 6:09 PM, MRAB wrote: >> On 2015-09-24 00:51, paul.hermeneutic at gmail.com wrote: >>> >>> If this starts at the beginning of the file, then it indicates that >>> the file is UTF-16 (LE). >>> >>> UTF-8[t 1] EF BB BF 239 187 191 >>> UTF-16 (BE) FE FF 254 255 >>> UTF-16 (LE) FF FE 255 254 >>> UTF-32 (BE) 00 00 FE FF 0 0 254 255 >>> UTF-32 (LE) FF FE 00 00 255 254 0 0 >>> >> The "signature" EF BB BF indicates the encoding called "utf-8-sig" by >> Python. It occurs on Windows. >> >> If the file doesn't start with any of these, then it could be using any >> encoding (except UTF-16 or UTF-32). > > Yes, but what does it mean when the signature is 00 FF 00 FE 00 FF and > occurs not at the beginning but repeatedly throughout the file, as > appears in the OP's case? > > At least, I'm assuming that the high-order bytes are 00 based on what > the OP posted. I wouldn't be surprised though if they're just being > mangled by the terminal, if it happens to be a certain one that will > not be named but uses CP 1252. > Yes, a byte-string literal or a hex dump of, say, the first 256 bytes would've been better. From katewinslet626 at gmail.com Wed Sep 23 22:49:17 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Wed, 23 Sep 2015 19:49:17 -0700 (PDT) Subject: ConnectionError handling problem In-Reply-To: References: Message-ID: On Sunday, September 20, 2015 at 8:11:18 PM UTC+5:30, Laura Creighton wrote: > The discussion about why or why not to use a bare except has gotten us > away from the problem reported, which is "why is my script hanging?" > > In a message of Sat, 19 Sep 2015 17:18:12 +0100, Mark Lawrence writes: > >> I am learning python. I wrote a script using requests module. > >> The scripts runs fine for sometime, but after a while it hangs. When I press CTRL+C it shows ConnectionError even though I have included exception handling. > >> I am not sure as to why it cant handle ConnectionError when the script runs for a long time. > >> > >> This is a part(causing issues) of the script I am running: > >> > >> while(k<46656): > >> j=res[k] > >> url="http://172.16.68.6:8090/login.xml" > >> query_args = {'mode':'191', 'username':str(i), 'password':str(j), 'a':'1442397582010', 'producttype':'0'} > >> > >> try: > >> r=requests.post(url, data=query_args) > >> except: > >> print "Connection error" > >> time.sleep(30) > >> continue > >> > >> html=r.text > >> if(len(html) < 10): > >> continue > >> > >> if("The system could not log you on" not in html): > >> print "hello" > >> filehandle=open("ids", "a") > >> filehandle.write(str(i)+'\n') > >> filehandle.write(str(j)+'\n') > >> filehandle.close() > >> break > >> > >> k=k+1 > >> > >> Any help will be highly appreciated. > > So, when it hangs there are two main problems you can have. One sort > is that the other side, http://172.16.68.6:8090/ it in itself > configured to only let people use a connection for a certain amount of > time. If you are using it for longer, it will disconnect you. Or the > other sort is that the other side disconnects people who have been > silent for a certain amount of time. If you haven't send anything for > a certain amount of time it will log you off. There are lots of other > things that work this way -- the system may see many attempts to login > and think you are trying to break into the system, the machine may > have crashed ... but the bottom line is that the reason your script > hangs is that there is nobody there on the other end. > > The other sort of problem you can have is that the other end is > alive and well and talking to you, but you don't understand what > you are getting, and you are ignoring things you don't understand. > This can look exactly the same. > > To find out what is going on you need to log what it is that you > are getting, to see if the answer is 'nothing' or 'garbage'. > > Laura Hi If my script hangs because of the reasons you mentioned above, why doesnt it catch ConnectionError? My script stops for a while and when I press CTRL+C, it shows ConnectionError without terminating the process, and the script resumes from where it left off. From paul.hermeneutic at gmail.com Wed Sep 23 22:56:21 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Wed, 23 Sep 2015 20:56:21 -0600 Subject: Readlines returns non ASCII character In-Reply-To: References: Message-ID: After looking at this briefly, I am not sure that this is a plain-text file. Interpreting it as UTF-16 LE shows that the characters are as they appear. Immediately after the BOM is: SINGLE LOW-9 QUOTATION MARK' (U+201A) START OF HEADING (U+0001) SPACE (U+0020) SPACE (U+0020) LATIN SMALL LETTER Y WITH DIAERESIS (U+00FF) LATIN SMALL LETTER THORN (U+00FE) LATIN SMALL LETTER Y WITH DIAERESIS (U+00FF) -------------- next part -------------- An HTML attachment was scrubbed... URL: From robertbaer at localnet.com Thu Sep 24 01:25:33 2015 From: robertbaer at localnet.com (Robert Baer) Date: Wed, 23 Sep 2015 22:25:33 -0700 Subject: Cyber Grand Challenge, prizes up to 2 million dollars ! (DARPA) In-Reply-To: References: Message-ID: Skybuck Flying wrote: > (Click on little icon on website top left for menu): > > Information about challenge: > > http://www.cybergrandchallenge.com/site/index.html#about > > https://cgc.darpa.mil/CGC_Rules_16_May_14_Version_2.pdf > > Perhaps this will be a yearly contest. > > There is a catch though, to collect the prizes: "The prize recipient > shall be a citizen, a permanent resident of the United States, or a US > Entity. " > > Bye, > Skybuck. With 1024x768 screen: "Please use a wider window to browse cybergrandchallenge.com" All else black, NO "contest" info. From steve+comp.lang.python at pearwood.info Thu Sep 24 02:02:15 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 24 Sep 2015 16:02:15 +1000 Subject: Idiosyncratic python Message-ID: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> I was looking at an in-house code base today, and the author seems to have a rather idiosyncratic approach to Python. For example: for k, v in mydict.items(): del(k) ... instead of the more obvious for v in mydict.values(): ... What are your favorite not-wrong-just-weird Python moments? -- Steve From no.email at nospam.invalid Thu Sep 24 02:16:02 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 23 Sep 2015 23:16:02 -0700 Subject: Idiosyncratic python References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: <87twqkbavx.fsf@jester.gateway.sonic.net> Steven D'Aprano writes: > for k, v in mydict.items(): > del(k) That looks wrong: it's deleting k from what? > instead of the more obvious > for v in mydict.values(): > ... Maybe you mean while mydict: k, v = mydict.popitem() ... From steve+comp.lang.python at pearwood.info Thu Sep 24 02:35:27 2015 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 24 Sep 2015 16:35:27 +1000 Subject: Idiosyncratic python References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <87twqkbavx.fsf@jester.gateway.sonic.net> Message-ID: <560399b0$0$1511$c3e8da3$5496439d@news.astraweb.com> On Thursday 24 September 2015 16:16, Paul Rubin wrote: > Steven D'Aprano writes: >> for k, v in mydict.items(): >> del(k) > > That looks wrong: it's deleting k from what? The local namespace. py> k = 23 py> print k 23 py> del k py> print k Traceback (most recent call last): File "", line 1, in NameError: name 'k' is not defined >> instead of the more obvious >> for v in mydict.values(): >> ... > > Maybe you mean > > while mydict: > k, v = mydict.popitem() > ... Hah, no, you're the second person to make that mistake! One of the guys I work with suggested `mydict = {}` to empty the dict. `del k` (aside: no need for parens, del is a statement, not a function) doesn't delete the key from the dictionary. It just deletes the name k. The obvious intent is to iterate over the *values* of the dictionary, but the coder didn't know about values, so he iterated over (key,value) pairs, then deleted the key local variable (not the key in the dict!) to keep the namespace clean. -- Steve From ben+python at benfinney.id.au Thu Sep 24 02:54:14 2015 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 24 Sep 2015 16:54:14 +1000 Subject: Idiosyncratic python References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <87twqkbavx.fsf@jester.gateway.sonic.net> <560399b0$0$1511$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85613048a1.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thursday 24 September 2015 16:16, Paul Rubin wrote: > > > Steven D'Aprano writes: > >> for k, v in mydict.items(): > >> del(k) > > [?] The obvious intent is to iterate over the *values* of the > dictionary, but the coder didn't know about values, so he iterated > over (key,value) pairs, then deleted the key local variable (not the > key in the dict!) to keep the namespace clean. That's not obvious to me. It's plausible, now that you say it. I find it also plausible, though, that the author is under the mistaken impression that the key and value must both be deleted, and has found a way that appears to do that. Perhaps what we're illustrating here is exactly why such idiosyncratic code *is* bad: it obscures the intent of the code for programmers who know idiomatic Python. And those readers are hopefully the ones the author should be trying to communicate to, on the theory that we've all got the goal to become a programmer who knows idiomatic Python. -- \ ?The fact of your own existence is the most astonishing fact | `\ you'll ever have to confront. Don't dare ever see your life as | _o__) boring, monotonous, or joyless.? ?Richard Dawkins, 2010-03-10 | Ben Finney From tjreedy at udel.edu Thu Sep 24 02:54:16 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 24 Sep 2015 02:54:16 -0400 Subject: Idiosyncratic python In-Reply-To: <560399b0$0$1511$c3e8da3$5496439d@news.astraweb.com> References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <87twqkbavx.fsf@jester.gateway.sonic.net> <560399b0$0$1511$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/24/2015 2:35 AM, Steven D'Aprano wrote: > On Thursday 24 September 2015 16:16, Paul Rubin wrote: > >> Steven D'Aprano writes: >>> for k, v in mydict.items(): >>> del(k) >> >> That looks wrong: it's deleting k from what? > > The local namespace. > > py> k = 23 > py> print k > 23 > py> del k > py> print k > Traceback (most recent call last): > File "", line 1, in > NameError: name 'k' is not defined > > >>> instead of the more obvious >>> for v in mydict.values(): >>> ... >> >> Maybe you mean >> >> while mydict: >> k, v = mydict.popitem() >> ... > > > Hah, no, you're the second person to make that mistake! One of the guys I > work with suggested `mydict = {}` to empty the dict. > > `del k` (aside: no need for parens, del is a statement, not a function) > doesn't delete the key from the dictionary. It just deletes the name k. The > obvious intent is to iterate over the *values* of the dictionary, but the > coder didn't know about values, so he iterated over (key,value) pairs, then > deleted the key local variable (not the key in the dict!) to keep the > namespace clean. but, but, each iteration rebinds k, so del k is only needed after the loop .. unless one is super fanatic about cleanliness within the loop ;-) -- Terry Jan Reedy From wxjmfauth at gmail.com Thu Sep 24 03:06:45 2015 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 24 Sep 2015 00:06:45 -0700 (PDT) Subject: Idiosyncratic python In-Reply-To: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: <3901ccc9-2ff9-49f2-bafb-fb4326a868b4@googlegroups.com> Le jeudi 24 septembre 2015 08:02:38 UTC+2, Steven D'Aprano a ?crit?: > > > What are your favorite not-wrong-just-weird Python moments? > > Showing how to make Python 3.5.0 crash by just using an "?", U+00E9. jmf From jeanmichel at sequans.com Thu Sep 24 05:12:36 2015 From: jeanmichel at sequans.com (jmp) Date: Thu, 24 Sep 2015 11:12:36 +0200 Subject: Idiosyncratic python In-Reply-To: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: On 09/24/2015 08:02 AM, Steven D'Aprano wrote: > I was looking at an in-house code base today, and the author seems to have a > rather idiosyncratic approach to Python. For example: > > > for k, v in mydict.items(): > del(k) > ... > > > instead of the more obvious > > for v in mydict.values(): > ... > > > > What are your favorite not-wrong-just-weird Python moments? A lot of our in base weird python comes from heavily C-wired people: The classic for i in range(len(alist)): print alist[i] with its twin brother i=0 while i < len(alist): print alist[i] i += 1 And the even more annoying result = Result() getResult(result) JM From hemla21 at gmail.com Thu Sep 24 05:58:35 2015 From: hemla21 at gmail.com (Heli Nix) Date: Thu, 24 Sep 2015 02:58:35 -0700 (PDT) Subject: PyInstaller+ Python3.5 (h5py import error) In-Reply-To: References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> <4ca597c9-5b1f-4709-a88b-5ecc78d1c590@googlegroups.com> Message-ID: <4f9cdd42-fff9-4f0c-b36d-277df25d109f@googlegroups.com> Thanks Christian, It turned out that h5py.defs was not the only hidden import that I needed to add. I managed to get it working with the follwoing command adding 4 hidden imports. pyinstaller --hidden-import=h5py.defs --hidden-import=h5py.utils --hidden-import=h5py.h5ac --hidden-import=h5py._proxy test.py is there anyway that you can use to add all h5py submodules all together? Thanks, From lac at openend.se Thu Sep 24 06:38:29 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 24 Sep 2015 12:38:29 +0200 Subject: ConnectionError handling problem In-Reply-To: References: Message-ID: <201509241038.t8OAcT1Z013215@fido.openend.se> In a message of Wed, 23 Sep 2015 19:49:17 -0700, shiva upreti writes: >Hi >If my script hangs because of the reasons you mentioned above, why doesnt it catch ConnectionError? >My script stops for a while and when I press CTRL+C, it shows ConnectionError without terminating the process, and the script resumes from where it left off. This is exactly what you asked it to do. :) >> try: >> r=requests.post(url, data=query_args) >> except: >> print "Connection error" >> time.sleep(30) >> continue try to do something until you get an Exception. Since that is a naked except, absolutely any Exception will do. That you print out 'Connection error' doesn't mean that you are only catching exceptions raised by trying to send something to the other end ... any Exception will do. So what happens when you press Control-C? You get a KeyboardInterrupt exception! :) see: https://docs.python.org/2/library/exceptions.html And you are catching it :) And when you catch it you print Connection error and keep on trying. This is why people were telling you that naked try:except: pairs, are rarely what you want. You didn't want to catch control-c but you caught it anyway. Laura From lac at openend.se Thu Sep 24 07:11:53 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 24 Sep 2015 13:11:53 +0200 Subject: PyInstaller+ Python3.5 (h5py import error) In-Reply-To: <4f9cdd42-fff9-4f0c-b36d-277df25d109f@googlegroups.com> References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> <4ca597c9-5b1f-4709-a88b-5ecc78d1c590@googlegroups.com> <4f9cdd42-fff9-4f0c-b36d-277df25d109f@googlegroups.com> Message-ID: <201509241111.t8OBBra5016200@fido.openend.se> In a message of Thu, 24 Sep 2015 02:58:35 -0700, Heli Nix writes: >Thanks Christian, > >It turned out that h5py.defs was not the only hidden import that I needed to add. > >I managed to get it working with the follwoing command adding 4 hidden imports. > > >pyinstaller --hidden-import=h5py.defs --hidden-import=h5py.utils --hidden-import=h5py.h5ac --hidden-import=h5py._proxy test.py > > >is there anyway that you can use to add all h5py submodules all together? > >Thanks, > Yes. You can use a hook file. see: https://pythonhosted.org/PyInstaller/#using-hook-files Laura From paul.hermeneutic at gmail.com Thu Sep 24 08:50:05 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Thu, 24 Sep 2015 06:50:05 -0600 Subject: Idiosyncratic python In-Reply-To: References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: > A lot of our in base weird python comes from heavily C-wired people: > > The classic > for i in range(len(alist)): > print alist[i] > > with its twin brother > > i=0 > while i < len(alist): > print alist[i] > i += 1 > > And the even more annoying > > result = Result() > getResult(result) > > JM Please follow up with good ways to write these. I hear that creating one really good way is a Python maxim. -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Thu Sep 24 09:09:28 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 24 Sep 2015 14:09:28 +0100 Subject: Idiosyncratic python In-Reply-To: References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: On 24/09/2015 13:50, paul.hermeneutic at gmail.com wrote: > > A lot of our in base weird python comes from heavily C-wired people: > > > > The classic > > for i in range(len(alist)): > > print alist[i] > > > > with its twin brother > > > > i=0 > > while i < len(alist): > > print alist[i] > > i += 1 > > > > And the even more annoying > > > > result = Result() > > getResult(result) > > > > JM > > Please follow up with good ways to write these. I hear that creating one > really good way is a Python maxim. > for item in alist: print(item) If you *think* you need the index:- for i, item in enumerate(alist): print(i, item) `i` defaults to 0, but there is a `start` keyword argument that lets you set it to anything you like. Better IMHO is to see what the itertools module[1] offers, either directly or through recipes. The latter are available on pypi as more-itertools[2]. [1] https://docs.python.org/3/library/itertools.html [2] https://pypi.python.org/pypi/more-itertools/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From lac at openend.se Thu Sep 24 09:16:42 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 24 Sep 2015 15:16:42 +0200 Subject: Sending a python argument to a Boost.Python function In-Reply-To: References: Message-ID: <201509241316.t8ODGg9m025014@fido.openend.se> Try that question here: https://mail.python.org/mailman/listinfo/cplusplus-sig Laura From python at mrabarnett.plus.com Thu Sep 24 09:30:22 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 24 Sep 2015 14:30:22 +0100 Subject: Python, convert an integer into an index? In-Reply-To: References: <201509222221.t8MMLMi5015927@fido.openend.se> Message-ID: <5603FAEE.1060101@mrabarnett.plus.com> On 2015-09-23 10:01, Anssi Saari wrote: > Dennis Lee Bieber writes: > >> On Wed, 23 Sep 2015 00:21:22 +0200, Laura Creighton >> declaimed the following: >> >> >>> >>>You need to convert your results into a string first. >>> >>>result_int=1234523 >>>result_list=[] >>> >>>for digit in str(result_int): >>> result_list.append(int(digit)) >>> >> >> Rather wordy... >> >>>>> [int(i) for i in str(1234523)] >> [1, 2, 3, 4, 5, 2, 3] > > I'm suprised. Why not just: > > list(str(results)) > > In other words, is there something else the list constructor should do > with a string other than convert it to a list? > The OP wanted the result to be a list of ints, not a list of strings. From paul.hermeneutic at gmail.com Thu Sep 24 09:45:50 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Thu, 24 Sep 2015 07:45:50 -0600 Subject: Python, convert an integer into an index? In-Reply-To: <5603FAEE.1060101@mrabarnett.plus.com> References: <201509222221.t8MMLMi5015927@fido.openend.se> <5603FAEE.1060101@mrabarnett.plus.com> Message-ID: >> I'm suprised. Why not just: >> >> list(str(results)) >> >> In other words, is there something else the list constructor should do >> with a string other than convert it to a list? >> > The OP wanted the result to be a list of ints, not a list of strings. [int(x) for x in list(str(results))] -------------- next part -------------- An HTML attachment was scrubbed... URL: From heenameena1234 at gmail.com Thu Sep 24 09:49:23 2015 From: heenameena1234 at gmail.com (heenameena1234 at gmail.com) Date: Thu, 24 Sep 2015 06:49:23 -0700 (PDT) Subject: querying hive database using python Message-ID: <7ea90b3f-5d25-4c70-ac65-40ce140e4564@googlegroups.com> I have server A and Server B. Server B is a hadoop cluster which has hive database and etc.. Server A has python 2.7. I would like to write a hive query using python on Server A to pull data from Server B. Server A and B has connectivity and no issues with network etc.. I have installed all necessary python packages on Server A. I wrote a python code using hive_utils package but it seems this code doesn't throw error or pull data, just hangs there. Can you please take a look at it and let me know what is the issue with code or suggest if you have better way or package could be used to pull data with example code. Thank you for your help. here is the code I wrote. CODE: SELECT ALL #!/usr/bin/env python import hive_utils query = """ SELECT * FROM test """ hive_client = hive_utils.HiveClient( server='10.25.36.75', port=10000, db='camp' ) a = hive_client.execute(query) a = list(a) From ashwath at nanoheal.com Thu Sep 24 09:58:14 2015 From: ashwath at nanoheal.com (ashwath at nanoheal.com) Date: Thu, 24 Sep 2015 06:58:14 -0700 Subject: Installing pywin32. Message-ID: <20150924065814.d600875ec5143fcc53c5b00e1a6550c2.0fbf42eaf1.mailapi@email23.secureserver.net> Hi Sir/Madam When I try to run my python program where I am using the pywin32 module I am getting the error as win32api module not found so how to install this module please let me know ASP. Thank You Ashwath B H -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Thu Sep 24 10:07:13 2015 From: jeanmichel at sequans.com (jmp) Date: Thu, 24 Sep 2015 16:07:13 +0200 Subject: Idiosyncratic python In-Reply-To: References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: On 09/24/2015 02:50 PM, paul.hermeneutic at gmail.com wrote: > > A lot of our in base weird python comes from heavily C-wired people: > > > > The classic > > for i in range(len(alist)): > > print alist[i] > > > > with its twin brother > > > > i=0 > > while i < len(alist): > > print alist[i] > > i += 1 > > > > And the even more annoying > > > > result = Result() > > getResult(result) > > > > JM > > Please follow up with good ways to write these. I hear that creating one > really good way is a Python maxim. for item in alist: print item and result = getResult() For the later, the original weird form come from a C habit to allocate returned structures within the caller and provide a pointer to it so the function can fill the data in, otherwise the structure is lost as the stack is popped out and the structure content is garbage. None of this make any sense in python. JM From jeanmichel at sequans.com Thu Sep 24 10:14:02 2015 From: jeanmichel at sequans.com (jmp) Date: Thu, 24 Sep 2015 16:14:02 +0200 Subject: Python, convert an integer into an index? In-Reply-To: References: <201509222221.t8MMLMi5015927@fido.openend.se> <5603FAEE.1060101@mrabarnett.plus.com> Message-ID: On 09/24/2015 03:45 PM, paul.hermeneutic at gmail.com wrote: > >> I'm suprised. Why not just: > >> > >> list(str(results)) > >> > >> In other words, is there something else the list constructor should do > >> with a string other than convert it to a list? > >> > > The OP wanted the result to be a list of ints, not a list of strings. > > [int(x) for x in list(str(results))] Side note : strings are already iterable, the list function is superfluous. jm From ian.g.kelly at gmail.com Thu Sep 24 10:26:11 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 24 Sep 2015 08:26:11 -0600 Subject: Idiosyncratic python In-Reply-To: References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Sep 24, 2015 at 8:07 AM, jmp wrote: > result = getResult() > > For the later, the original weird form come from a C habit to allocate > returned structures within the caller and provide a pointer to it so the > function can fill the data in, otherwise the structure is lost as the stack > is popped out and the structure content is garbage. None of this make any > sense in python. Only if the structure is allocated on the stack and returned by pointer. If it's returned by value, then the content remains intact, but at the expense of copying it. The other option of course would be to allocate it on the heap and return the pointer, but this needlessly incurs malloc overhead and creates an opportunity for a memory leak if the variable is naturally stack-scoped. Python effectively takes this option, as everything is allocated on the heap. Leaving it up to the caller to provide a pointer also gives the caller the option of allocating on the stack or the heap as best fits the context. From paul.hermeneutic at gmail.com Thu Sep 24 10:36:12 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Thu, 24 Sep 2015 08:36:12 -0600 Subject: Python, convert an integer into an index? In-Reply-To: References: <201509222221.t8MMLMi5015927@fido.openend.se> <5603FAEE.1060101@mrabarnett.plus.com> Message-ID: Good idea. >>> [int(x) for x in str(results)] [1, 2, 3] -------------- next part -------------- An HTML attachment was scrubbed... URL: From zachary.ware+pylist at gmail.com Thu Sep 24 11:19:18 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Thu, 24 Sep 2015 10:19:18 -0500 Subject: Installing pywin32. In-Reply-To: <20150924065814.d600875ec5143fcc53c5b00e1a6550c2.0fbf42eaf1.mailapi@email23.secureserver.net> References: <20150924065814.d600875ec5143fcc53c5b00e1a6550c2.0fbf42eaf1.mailapi@email23.secureserver.net> Message-ID: On Thu, Sep 24, 2015 at 8:58 AM, wrote: > Hi Sir/Madam > > > When I try to run my python program where I am using the pywin32 module I am > getting the error as win32api module not found so how to install this module > please let me know ASP. Have you already installed or tried to install pywin32? What version of Python are you running, where did you get it, and on which version of Windows? In the absence of further information, I'll give you the quick and easy incantation for installing pywin32: `python -m pip install pypiwin32`. There are any number of ways that can fail depending on your answers to my questions, though. -- Zach From zachary.ware+pylist at gmail.com Thu Sep 24 11:59:29 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Thu, 24 Sep 2015 10:59:29 -0500 Subject: Installing pywin32. In-Reply-To: <20150924083924.d600875ec5143fcc53c5b00e1a6550c2.baa773dc3f.mailapi@email23.secureserver.net> References: <20150924083924.d600875ec5143fcc53c5b00e1a6550c2.baa773dc3f.mailapi@email23.secureserver.net> Message-ID: Two notes about local etiquette: 1) Please reply to the list rather than to me directly. I only include your address in the cc: in case you aren't subscribed (which you should be, unless you're reading via the newsgroup), since I don't recognize you as a regular poster. I'll soon stop doing so. 2) Please do not top-post. Rather, add your reply directly beneath the particular line you're replying to, as I do below. On Thu, Sep 24, 2015 at 10:39 AM, wrote: > Hi > > I am pleased with your reply thanks for it..... > System environment is like this > > OS - windows 7 64 bit machine. > Python - pywin3.5 Where did you get it from? I don't know of any product named "pywin3.5". There's 'pywin32' (as in 'Python interface to Win32', available from http://pywin32.sourceforge.net/) and Python 3.5 (as in 'CPython 3.5.0 for Windows', available from https://www.python.org/). > even pip is not installed if I run pip its shows like pip command not found. Installing pip is an option in the Python 3.5 (and 3.4, and 2.7.10) installer. If you didn't select it, it won't be installed. You can try running 'python -m ensurepip' to install pip after the main installation of Python. > From which path I have to run this python -m pip install pypiwin32 Doesn't matter; as long as the 'python' command can be found and that Python has pip installed, this command will install pywin32 into the global site-packages directory of that Python. Also, I should have directed you to `py -m pip install pypiwin32` to make use of the Python Launcher, which is always on PATH (if it was installed, it's also an option in the installer). -- Zach From lorenzofsutton at gmail.com Thu Sep 24 12:13:14 2015 From: lorenzofsutton at gmail.com (Lorenzo Sutton) Date: Thu, 24 Sep 2015 18:13:14 +0200 Subject: Python, convert an integer into an index? In-Reply-To: References: Message-ID: <5604211A.3020700@gmail.com> On 23/09/2015 17:32, Denis McMahon wrote: > On Tue, 22 Sep 2015 14:43:55 -0700, Chris Roberts wrote: > >> results = 134523 #(Integer) > > This appears to be an integer expressed (presumably) in base 10 with 6 > digits > >> Desired: >> results = [1, 2, 3, 4, 5, 2, 3] #(INDEX) > > This appears to be a python list of 7 elements, with the first and the > the third through seventh elements corresponding to the first and the > second through sixth most significant digits respectively of the > previously discussed integer. > > I can't actually see any direct method of creating the list given from > the number given. > > However, if I understand the intent of the question you meant to ask, you > might find that the following code does something interesting: > > x = 9876543210 > y = [] > > while x > 0: > y.append(x % 10) > x = int(x / 10) > > y = list(reversed(y)) > print y I like the math approach even if the pythonic list string is quicker... One 'math' way would also be (avoiding the list reverse, but need to import math): >>> import math >>> result = 1234567 >>> digits = int(math.log10(result) + 1) >>> y = [] >>> for x in range(digits, 0, -1): number = result % (10 ** x) / (10 **(x-1)) y.append(int(number)) >>> y [1, 2, 3, 4, 5, 6, 7] From toddrjen at gmail.com Thu Sep 24 12:54:03 2015 From: toddrjen at gmail.com (Todd) Date: Thu, 24 Sep 2015 18:54:03 +0200 Subject: Idiosyncratic python In-Reply-To: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: Using list indexing with booleans in place of a ternary operator. a = False b = [var2, var1][a] Instead of: b = var1 if a else var2 On Sep 24, 2015 8:06 AM, "Steven D'Aprano" < steve+comp.lang.python at pearwood.info> wrote: > I was looking at an in-house code base today, and the author seems to have > a > rather idiosyncratic approach to Python. For example: > > > for k, v in mydict.items(): > del(k) > ... > > > instead of the more obvious > > for v in mydict.values(): > ... > > > > What are your favorite not-wrong-just-weird Python moments? > > > > -- > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Sep 24 12:57:54 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Sep 2015 02:57:54 +1000 Subject: Idiosyncratic python In-Reply-To: References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: On Fri, Sep 25, 2015 at 2:54 AM, Todd wrote: > Using list indexing with booleans in place of a ternary operator. > > a = False > b = [var2, var1][a] > > Instead of: > > b = var1 if a else var2 Be careful - these are not semantically identical. The first one evaluates both var1 and var2, while the second will evaluate only the one it needs. This might be significant if they're not simple names. ChrisA From laurent.pointal at free.fr Thu Sep 24 13:50:29 2015 From: laurent.pointal at free.fr (Laurent Pointal) Date: Thu, 24 Sep 2015 19:50:29 +0200 Subject: Idiosyncratic python References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <3901ccc9-2ff9-49f2-bafb-fb4326a868b4@googlegroups.com> Message-ID: <560437e5$0$3354$426a74cc@news.free.fr> wxjmfauth at gmail.com wrote: > Le jeudi 24 septembre 2015 08:02:38 UTC+2, Steven D'Aprano a ?crit : >> >> >> What are your favorite not-wrong-just-weird Python moments? >> >> > Showing how to make Python 3.5.0 crash by > just using an "?", U+00E9. Like this ? Python 3.5.0 (default, Sep 24 2015, 19:47:57) [GCC 4.9.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> s = "\u00E9" >>> print(s) ? From jeanmichel at sequans.com Thu Sep 24 14:04:17 2015 From: jeanmichel at sequans.com (jmp) Date: Thu, 24 Sep 2015 20:04:17 +0200 Subject: Idiosyncratic python In-Reply-To: References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: On 09/24/2015 04:26 PM, Ian Kelly wrote: > On Thu, Sep 24, 2015 at 8:07 AM, jmp wrote: >> result = getResult() >> >> For the later, the original weird form come from a C habit to allocate >> returned structures within the caller and provide a pointer to it so the >> function can fill the data in, otherwise the structure is lost as the stack >> is popped out and the structure content is garbage. None of this make any >> sense in python. > > Only if the structure is allocated on the stack and returned by > pointer. If it's returned by value, then the content remains intact, > but at the expense of copying it. The other option of course would be > to allocate it on the heap and return the pointer, but this needlessly > incurs malloc overhead and creates an opportunity for a memory leak if > the variable is naturally stack-scoped. Python effectively takes this > option, as everything is allocated on the heap. Leaving it up to the > caller to provide a pointer also gives the caller the option of > allocating on the stack or the heap as best fits the context. > I'm not an expert but I think this "return by value thing" is only for C++. In vintage C, you can only return something that fits within a register. Anyway, there's a lot of legit C code in which functions are plagued by 'out parameters' and somehow it has transpired in some python code for no reason :o) jm From ian.g.kelly at gmail.com Thu Sep 24 14:19:33 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 24 Sep 2015 12:19:33 -0600 Subject: Idiosyncratic python In-Reply-To: References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: On Thu, Sep 24, 2015 at 12:04 PM, jmp wrote: > I'm not an expert but I think this "return by value thing" is only for C++. > In vintage C, you can only return something that fits within a register. If that was true at one time, it was before ANSI C. $ cat test.c #include struct foo { int a; long b; float c; double d; }; struct foo get_foo() { struct foo value; value.a = 12; value.b = 92L; value.c = 4.5f; value.d = -21.5; return value; } int main() { struct foo value = get_foo(); assert(value.a == 12); assert(value.b == 92L); assert(value.c == 4.5f); assert(value.d == -21.5); return 0; } $ gcc -Wall -O0 -std=c89 test.c $ ./a.out $ There is a danger however in that it's only a shallow copy. If any struct members are pointers, then the pointer value will be copied, not the thing pointed to. From toddrjen at gmail.com Thu Sep 24 14:21:14 2015 From: toddrjen at gmail.com (Todd) Date: Thu, 24 Sep 2015 20:21:14 +0200 Subject: Idiosyncratic python In-Reply-To: References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: On Sep 24, 2015 18:59, "Chris Angelico" wrote: > > On Fri, Sep 25, 2015 at 2:54 AM, Todd wrote: > > Using list indexing with booleans in place of a ternary operator. > > > > a = False > > b = [var2, var1][a] > > > > Instead of: > > > > b = var1 if a else var2 > > Be careful - these are not semantically identical. The first one > evaluates both var1 and var2, while the second will evaluate only the > one it needs. This might be significant if they're not simple names. True, but the code I saw doing this was just choosing between simple float literals. -------------- next part -------------- An HTML attachment was scrubbed... URL: From codywcox at gmail.com Thu Sep 24 14:45:06 2015 From: codywcox at gmail.com (codywcox at gmail.com) Date: Thu, 24 Sep 2015 11:45:06 -0700 (PDT) Subject: Learning Modules, Arguments, Parameters (imma noob) Message-ID: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> I seem to be having a problem understanding how arguments and parameters work, Most likely why my code will not run. Can anyone elaborate on what I am doing wrong? ''' Cody Cox 9/16/2015 Programming Exercise 1 - Kilometer Converter Design a modular program that asks the user to enter a distance in kilometers and then convert it to miles Miles = Kilometers * 0.6214 ''' def main(): get_input() convert_kilo() def get_input(kilo): kilo = float(input('Enter Kilometers: ')) return kilo def convert_kilo(kilo,miles): miles = float(kilo * 0.6214) print( kilo,' kilometers converts to ',miles,' miles') main() From joel.goldstick at gmail.com Thu Sep 24 15:15:06 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 24 Sep 2015 15:15:06 -0400 Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: On Thu, Sep 24, 2015 at 2:45 PM, wrote: > I seem to be having a problem understanding how arguments and parameters > work, Most likely why my code will not run. > Can anyone elaborate on what I am doing wrong? > > ''' > Cody Cox > 9/16/2015 > Programming Exercise 1 - Kilometer Converter > Design a modular program that asks the user to enter a distance in > kilometers and then convert it to miles > Miles = Kilometers * 0.6214 > ''' > > def main(): > get_input() > Change the above call to: kilos = get_input() This is because your function returns that value > convert_kilo() > This one you need to pass the kilos argument, and you don't need to pass the miles parameter (see below) convert_kilo(kilos) > > > def get_input(kilo): > You defined get_input with no parameters, so it gets no arguments when you call it: def get_input(): > kilo = float(input('Enter Kilometers: ')) > return kilo > > def convert_kilo(kilo,miles): > Make the above: def convert_kilo(kilo): > miles = float(kilo * 0.6214) > print( kilo,' kilometers converts to ',miles,' miles') > > main() > When you define a function, the names between the parentheses are called parameters. When you call the function, they are called arguments. They need to match. When you return a value from a function, you need to put a name to it, or it is lost. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Sep 24 15:25:55 2015 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 24 Sep 2015 20:25:55 +0100 Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: <56044E43.90205@mrabarnett.plus.com> On 2015-09-24 19:45, codywcox at gmail.com wrote: > I seem to be having a problem understanding how arguments and parameters work, Most likely why my code will not run. > Can anyone elaborate on what I am doing wrong? > > ''' > Cody Cox > 9/16/2015 > Programming Exercise 1 - Kilometer Converter > Design a modular program that asks the user to enter a distance in kilometers and then convert it to miles > Miles = Kilometers * 0.6214 > ''' > First of all, it looks like your indentation is slightly off because "def main" line is that the left margin and the other 2 "def" lines and the "main()" line aren't. > def main(): You're not passing anything into 'get_input', neither are you saving any result that it might be returning. > get_input() You're not passing anything into 'convert_kilo'. > convert_kilo() > > You're defining 'get_input' to accept 1 parameter 'kilo'. Why? You're assigning to 'kilo' in the first line, so any value you _did_ pass in would be ignored. > def get_input(kilo): > kilo = float(input('Enter Kilometers: ')) > return kilo > You're defining 'convert_kilo' to accept 2 parameters. You're using the 'kilo' parameter, but not the 'miles' parameter because you're assigning to it on the first line, so any value you _did_ pass in would be ignored. > def convert_kilo(kilo,miles): 'kilo' is already a float, and you're multiplying it by a float, so the 'float' call is pointless. > miles = float(kilo * 0.6214) > print( kilo,' kilometers converts to ',miles,' miles') > > main() > From gordon at panix.com Thu Sep 24 15:32:14 2015 From: gordon at panix.com (John Gordon) Date: Thu, 24 Sep 2015 19:32:14 +0000 (UTC) Subject: Learning Modules, Arguments, Parameters (imma noob) References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: In <7ad8941d-04aa-42c5-82e9-10cdf02ab695 at googlegroups.com> codywcox at gmail.com writes: > I seem to be having a problem understanding how arguments and parameters > work, Most likely why my code will not run. Can anyone elaborate on what > I am doing wrong? > def get_input(kilo): > kilo = float(input('Enter Kilometers: ')) > return kilo get_input() gets all its input from the keyboard. It doesn't need any arguments. > def convert_kilo(kilo,miles): > miles = float(kilo * 0.6214) > print( kilo,' kilometers converts to ',miles,' miles') convert_kilo() calculates miles on its own, so you don't need to pass it as an argument. > def main(): > get_input() > convert_kilo() > > main() When calling get_input, you need to save the return value in a variable, and then pass that variable as an argument to convert_kilo. The updated code would look like this: def main(): kilo = get_input() convert_kilo(kilo) def get_input(): kilo = float(input('Enter Kilometers: ')) return kilo def convert_kilo(kilo): miles = float(kilo * 0.6214) print( kilo,' kilometers converts to ',miles,' miles') main() -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From breamoreboy at yahoo.co.uk Thu Sep 24 16:05:09 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 24 Sep 2015 21:05:09 +0100 Subject: Idiosyncratic python In-Reply-To: <560437e5$0$3354$426a74cc@news.free.fr> References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <3901ccc9-2ff9-49f2-bafb-fb4326a868b4@googlegroups.com> <560437e5$0$3354$426a74cc@news.free.fr> Message-ID: On 24/09/2015 18:50, Laurent Pointal wrote: > wxjmfauth at gmail.com wrote: > >> Le jeudi 24 septembre 2015 08:02:38 UTC+2, Steven D'Aprano a ?crit : >>> >>> >>> What are your favorite not-wrong-just-weird Python moments? >>> >>> >> Showing how to make Python 3.5.0 crash by >> just using an "?", U+00E9. Would you like to show us all how, or do you think you'd be far too embarassed by once again showing that you haven't got the faintest idea what you're talking about? > > Like this ? > > > Python 3.5.0 (default, Sep 24 2015, 19:47:57) > [GCC 4.9.2] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> s = "\u00E9" >>>> print(s) > ? > Your test must be wrong as the RUE knows everything. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From orgnut at yahoo.com Thu Sep 24 16:27:22 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Thu, 24 Sep 2015 13:27:22 -0700 Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: On 09/24/2015 11:45 AM, codywcox at gmail.com wrote: > I seem to be having a problem understanding how arguments and parameters work, Most likely why my code will not run. > Can anyone elaborate on what I am doing wrong? > > ''' > Cody Cox > 9/16/2015 > Programming Exercise 1 - Kilometer Converter > Design a modular program that asks the user to enter a distance in kilometers and then convert it to miles > Miles = Kilometers * 0.6214 > ''' > > def main(): > get_input() > convert_kilo() > > > def get_input(kilo): > kilo = float(input('Enter Kilometers: ')) > return kilo > > def convert_kilo(kilo,miles): > miles = float(kilo * 0.6214) > print( kilo,' kilometers converts to ',miles,' miles') > > main() > ---------------------------------- > def main(): > ... I'm going to discribe this last > def get_input(kilo): > kilo = float(input('Enter Kilometers: ')) > return kilo > 1) def get_input(kilo): has a leading space. This is an indenting error 2) You use parameters to send data TO the function, NOT to return it (generally, there are exceptions). Leave out the kilo, you want simply 'def get_input():' 3) The body, kilo = ... and return ..., is ok, but can be shortened to a single line: return float(input('Enter Kilometers: ')) > def convert_kilo(kilo,miles): > miles = float(kilo * 0.6214) > print( kilo,' kilometers converts to ',miles,' miles') > 1) Again indenting error, and miles (an output) is not needed as a parameter. 2) miles = float(kilo * 0.6214): kilo and 0.6214 are already floats. There is no need to _convert_ to float. Doesn't hurt, but it is redundant. 3) The print is acceptable, but has unnecessary spaces. Print() by default puts a space between the items, so using spaces inside the strings gives you double-spaces, one from the print() and one from the string. > def main(): > get_input() > convert_kilo() > 1) get_input() as you have it written requires a parameter, you are not giving it one. However, as I explained above, get_input() should not have a parameter anyway. 2) get_imput() returns a value (kilo), but here you are throwing it away. This needs to be: kilo = get_input() 3) convert_kilo() _requires_ a parameter, you are not giving one. And it does NOT need the second (miles) parameter that you originally wrote. What you want is: convert_kilo(kilo) I hope you can make sense out of my explanations. -=- Larry -=- From jcasale at activenetwerx.com Thu Sep 24 16:28:11 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 24 Sep 2015 20:28:11 +0000 Subject: Modifying signature of ctor in class Message-ID: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> I have a class factory where I dynamically add a constructor to the class output. The method is a closure and works just fine, however to accommodate the varied input its signature is (*args, **kwargs). While I modify the doc strings, the ctor sig is not optimal. Without building this a string and using eval, is there anything that can be done about this? Thanks, jlc From gal.kauffman at gmail.com Thu Sep 24 16:37:35 2015 From: gal.kauffman at gmail.com (gal kauffman) Date: Thu, 24 Sep 2015 13:37:35 -0700 Subject: Modifying signature of ctor in class In-Reply-To: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> References: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> Message-ID: You can use the FunctionType class found in the types module (and its friends) to create functions on the run. And you can use the 'inspect' module to inspect existing functions, if you need to base the new function on an existing one. On Sep 24, 2015 11:28 PM, "Joseph L. Casale" wrote: > I have a class factory where I dynamically add a constructor to the class > output. > The method is a closure and works just fine, however to accommodate the > varied > input its signature is (*args, **kwargs). > > While I modify the doc strings, the ctor sig is not optimal. Without > building > this a string and using eval, is there anything that can be done about > this? > > Thanks, > jlc > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ned at nedbatchelder.com Thu Sep 24 16:46:27 2015 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 24 Sep 2015 13:46:27 -0700 (PDT) Subject: Idiosyncratic python In-Reply-To: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: <00884c56-4c94-406b-9902-b94dda9d66b3@googlegroups.com> On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano wrote: > What are your favorite not-wrong-just-weird Python moments? I've seen this a number of times: dict_of_values.update({'key': some_value}) why not: dict_of_values['key'] = some_value I've considered writing a Pylint plugin to flag these... --Ned. From lac at openend.se Thu Sep 24 17:08:58 2015 From: lac at openend.se (Laura Creighton) Date: Thu, 24 Sep 2015 23:08:58 +0200 Subject: Idiosyncratic python In-Reply-To: <00884c56-4c94-406b-9902-b94dda9d66b3@googlegroups.com> References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <00884c56-4c94-406b-9902-b94dda9d66b3@googlegroups.com> Message-ID: <201509242108.t8OL8wQs026851@fido.openend.se> In a message of Thu, 24 Sep 2015 13:46:27 -0700, Ned Batchelder writes: >On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano wrote: >> What are your favorite not-wrong-just-weird Python moments? > >I've seen this a number of times: > > dict_of_values.update({'key': some_value}) > >why not: > > dict_of_values['key'] = some_value > >I've considered writing a Pylint plugin to flag these... > >--Ned. A student today had a similar version of this one: Every time he wanted to change the value of dictionary mapping he would write: w={'key': new_value} dict_of_values.update(w) Laura From rosuav at gmail.com Thu Sep 24 17:38:58 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Sep 2015 07:38:58 +1000 Subject: Modifying signature of ctor in class In-Reply-To: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> References: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> Message-ID: On Fri, Sep 25, 2015 at 6:28 AM, Joseph L. Casale wrote: > I have a class factory where I dynamically add a constructor to the class output. > The method is a closure and works just fine, however to accommodate the varied > input its signature is (*args, **kwargs). > > While I modify the doc strings, the ctor sig is not optimal. Without building > this a string and using eval, is there anything that can be done about this? > I don't think you can easily change the function's own definition, other than by using eval (or equivalent shenanigans, like crafting your own bytecode); but as of Python 3.something, the help() function looks for a __wrapped__ attribute and will take function args from that instead of the function itself. That way, when you use functools.wraps(), it copies in the docstring and stuff, and as far as help() is concerned, copies in the argument list too. No idea whether you'll be able to do that too, but it's a fairly effective way to get around the problem if you can. ChrisA From jcasale at activenetwerx.com Thu Sep 24 17:41:44 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 24 Sep 2015 21:41:44 +0000 Subject: Modifying signature of ctor in class In-Reply-To: References: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com>, Message-ID: <1443130904427.81369@activenetwerx.com> > You can use the FunctionType class found in the types module (and its friends) to create functions on the run. > And you can use the 'inspect' module to inspect existing functions, if you need to base the new function on an existing one. Hi Gal, Seems the types module docs do not even have a single line of docs for FunctionType and there isn't any that I found online. From the few examples on StackOverflow it appears like it might do the job however I do not see how to specify a signature, I only see how to specify defaults. Do you have any ideas? Thanks for the info, jlc From jcasale at activenetwerx.com Thu Sep 24 17:45:45 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 24 Sep 2015 21:45:45 +0000 Subject: Modifying signature of ctor in class In-Reply-To: References: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com>, Message-ID: <1443131144678.39404@activenetwerx.com> > I don't think you can easily change the function's own definition, > other than by using eval (or equivalent shenanigans, like crafting > your own bytecode); but as of Python 3.something, the help() function > looks for a __wrapped__ attribute and will take function args from > that instead of the function itself. That way, when you use > functools.wraps(), it copies in the docstring and stuff, and as far as > help() is concerned, copies in the argument list too. > > No idea whether you'll be able to do that too, but it's a fairly > effective way to get around the problem if you can. Hi Chris, That is helpful. It still leaves me with generating a string function and eval'ing or compiling it to swipe the sig. At the point I could rebuild the entire function and simply apply it. Where all but a valid sig helps is for introspection such as tab completing with ipython or using an IDE etc. Thanks everyone, jlc From rosuav at gmail.com Thu Sep 24 17:49:02 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Sep 2015 07:49:02 +1000 Subject: Idiosyncratic python In-Reply-To: <201509242108.t8OL8wQs026851@fido.openend.se> References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <00884c56-4c94-406b-9902-b94dda9d66b3@googlegroups.com> <201509242108.t8OL8wQs026851@fido.openend.se> Message-ID: On Fri, Sep 25, 2015 at 7:08 AM, Laura Creighton wrote: > In a message of Thu, 24 Sep 2015 13:46:27 -0700, Ned Batchelder writes: >>On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano wrote: >>> What are your favorite not-wrong-just-weird Python moments? >> >>I've seen this a number of times: >> >> dict_of_values.update({'key': some_value}) >> >>why not: >> >> dict_of_values['key'] = some_value >> >>I've considered writing a Pylint plugin to flag these... >> >>--Ned. > > A student today had a similar version of this one: > > Every time he wanted to change the value of dictionary mapping he would > write: > w={'key': new_value} > dict_of_values.update(w) That's a new one on me! The oddest dictionary code any of my students has come out with (so far!) was a slavish habit of always iterating over them thus: for k,v in some_dict.items(): where some_dict is the only part that changed. So everywhere through the code - even in nested loops - all dictionary iteration used "k" and "v". But I suspect it's exactly the same. Saw some code somewhere, found that it worked, used it. If you don't understand something, don't change it... which is a good policy in general, I suppose :) ChrisA From gal.kauffman at gmail.com Thu Sep 24 18:07:06 2015 From: gal.kauffman at gmail.com (gal kauffman) Date: Thu, 24 Sep 2015 15:07:06 -0700 Subject: Modifying signature of ctor in class In-Reply-To: <1443131144678.39404@activenetwerx.com> References: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> <1443131144678.39404@activenetwerx.com> Message-ID: Sorry, you really can't give FunctionType an argument list. Maybe you can wrap the function with a callable object, this way you can change the argument list returned, and doest have to eval or compile code. On Sep 25, 2015 12:46 AM, "Joseph L. Casale" wrote: > > I don't think you can easily change the function's own definition, > > other than by using eval (or equivalent shenanigans, like crafting > > your own bytecode); but as of Python 3.something, the help() function > > looks for a __wrapped__ attribute and will take function args from > > that instead of the function itself. That way, when you use > > functools.wraps(), it copies in the docstring and stuff, and as far as > > help() is concerned, copies in the argument list too. > > > > No idea whether you'll be able to do that too, but it's a fairly > > effective way to get around the problem if you can. > > Hi Chris, > That is helpful. It still leaves me with generating a string function > and eval'ing or compiling it to swipe the sig. At the point I could > rebuild the entire function and simply apply it. > > Where all but a valid sig helps is for introspection such as tab completing > with ipython or using an IDE etc. > > Thanks everyone, > jlc > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Sep 24 18:07:26 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Sep 2015 08:07:26 +1000 Subject: Modifying signature of ctor in class In-Reply-To: <1443131144678.39404@activenetwerx.com> References: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> <1443131144678.39404@activenetwerx.com> Message-ID: On Fri, Sep 25, 2015 at 7:45 AM, Joseph L. Casale wrote: >> I don't think you can easily change the function's own definition, >> other than by using eval (or equivalent shenanigans, like crafting >> your own bytecode); but as of Python 3.something, the help() function >> looks for a __wrapped__ attribute and will take function args from >> that instead of the function itself. That way, when you use >> functools.wraps(), it copies in the docstring and stuff, and as far as >> help() is concerned, copies in the argument list too. >> >> No idea whether you'll be able to do that too, but it's a fairly >> effective way to get around the problem if you can. > > Hi Chris, > That is helpful. It still leaves me with generating a string function > and eval'ing or compiling it to swipe the sig. At the point I could > rebuild the entire function and simply apply it. > > Where all but a valid sig helps is for introspection such as tab completing > with ipython or using an IDE etc. I've no idea what your tab completion tools are going to be looking at, so you'd have to dig into that and find out. This trick may or may not work, but if it does, it'd mean you could possibly come up with something that pretends to be a function (for introspection purposes), without actually being one. That would let you construct a class that ducktypes as a function and can return whatever it likes from inspect.signature(). ChrisA From ian.g.kelly at gmail.com Thu Sep 24 18:10:17 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 24 Sep 2015 16:10:17 -0600 Subject: Modifying signature of ctor in class In-Reply-To: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> References: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> Message-ID: On Thu, Sep 24, 2015 at 2:28 PM, Joseph L. Casale wrote: > I have a class factory where I dynamically add a constructor to the class output. > The method is a closure and works just fine, however to accommodate the varied > input its signature is (*args, **kwargs). > > While I modify the doc strings, the ctor sig is not optimal. Without building > this a string and using eval, is there anything that can be done about this? In Python 3.3+ you can attach a Signature object to a function by setting the function's __signature__ attribute. In Python 3.4+ the __signature__ is used in generating the signature for PyDoc and help(). From ian.g.kelly at gmail.com Thu Sep 24 18:19:30 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 24 Sep 2015 16:19:30 -0600 Subject: Modifying signature of ctor in class In-Reply-To: References: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> Message-ID: On Thu, Sep 24, 2015 at 4:10 PM, Ian Kelly wrote: > On Thu, Sep 24, 2015 at 2:28 PM, Joseph L. Casale > wrote: >> I have a class factory where I dynamically add a constructor to the class output. >> The method is a closure and works just fine, however to accommodate the varied >> input its signature is (*args, **kwargs). >> >> While I modify the doc strings, the ctor sig is not optimal. Without building >> this a string and using eval, is there anything that can be done about this? > > In Python 3.3+ you can attach a Signature object to a function by > setting the function's __signature__ attribute. In Python 3.4+ the > __signature__ is used in generating the signature for PyDoc and > help(). Quick and dirty example: py> from inspect import Signature, Parameter py> def foo(*args, **kwargs): pass ... py> foo.__signature__ = Signature([Parameter('x', Parameter.POSITIONAL_OR_KEYWORD), Parameter('y', Parameter.KEYWORD_ONLY)]) py> help(foo) Help on function foo in module __main__: foo(x, *, y) From rosuav at gmail.com Thu Sep 24 18:23:12 2015 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 25 Sep 2015 08:23:12 +1000 Subject: Modifying signature of ctor in class In-Reply-To: References: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> Message-ID: On Fri, Sep 25, 2015 at 8:19 AM, Ian Kelly wrote: > Quick and dirty example: > > py> from inspect import Signature, Parameter > py> def foo(*args, **kwargs): pass > ... > py> foo.__signature__ = Signature([Parameter('x', > Parameter.POSITIONAL_OR_KEYWORD), Parameter('y', > Parameter.KEYWORD_ONLY)]) > py> help(foo) > Help on function foo in module __main__: > > foo(x, *, y) Okay, that's a LOT easier than the stuff I was playing around with :) Of course, it still requires that inspect.signature be used. ChrisA From sohcahtoa82 at gmail.com Thu Sep 24 18:32:22 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Thu, 24 Sep 2015 15:32:22 -0700 (PDT) Subject: Idiosyncratic python In-Reply-To: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: On Wednesday, September 23, 2015 at 11:02:38 PM UTC-7, Steven D'Aprano wrote: > I was looking at an in-house code base today, and the author seems to have a > rather idiosyncratic approach to Python. For example: > > > for k, v in mydict.items(): > del(k) > ... > > > instead of the more obvious > > for v in mydict.values(): > ... > > > > What are your favorite not-wrong-just-weird Python moments? > > > > -- > Steve I used to work with a guy that would put the verb at the END of a function name, rather than the beginning. For example, rather then "GetSupportedVersion", he'd use "SupportedVersionGet". Of course, I know plenty of people here will say it should be "get_supported_version", but that's another discussion entirely. Another guy would frequently use "Grab" instead of "Get". The fact that he used a different verb than the common convention though wasn't NEARLY as infuriating as the fact that he was inconsistent about it. From jcasale at activenetwerx.com Thu Sep 24 19:01:24 2015 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 24 Sep 2015 23:01:24 +0000 Subject: Modifying signature of ctor in class In-Reply-To: References: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> , Message-ID: <1443135684451.3744@activenetwerx.com> > py> from inspect import Signature, Parameter > py> def foo(*args, **kwargs): pass > ... > py> foo.__signature__ = Signature([Parameter('x', > Parameter.POSITIONAL_OR_KEYWORD), Parameter('y', > Parameter.KEYWORD_ONLY)]) > py> help(foo) > Help on function foo in module __main__: > > foo(x, *, y) That actually should harmlessly support Python versions less than 3.3 while simply accomplishing nothing. I don't even need a test for the version. I'll go with that as a decent trade off. Thanks! jlc From cs at zip.com.au Thu Sep 24 19:25:38 2015 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 25 Sep 2015 09:25:38 +1000 Subject: ConnectionError handling problem In-Reply-To: <201509241038.t8OAcT1Z013215@fido.openend.se> References: <201509241038.t8OAcT1Z013215@fido.openend.se> Message-ID: <20150924232538.GA61919@cskk.homeip.net> On 24Sep2015 12:38, Laura Creighton wrote: >In a message of Wed, 23 Sep 2015 19:49:17 -0700, shiva upreti writes: >>If my script hangs because of the reasons you mentioned above, why doesnt it >>catch ConnectionError? >>My script stops for a while and when I press CTRL+C, it shows ConnectionError without terminating the process, and the script resumes from where it left off. > >This is exactly what you asked it to do. :) > >>> try: >>> r=requests.post(url, data=query_args) >>> except: >>> print "Connection error" >>> time.sleep(30) >>> continue > >try to do something until you get an Exception. Since that is a >naked except, absolutely any Exception will do. That you >print out 'Connection error' doesn't mean that you are only >catching exceptions raised by trying to send something to the >other end ... any Exception will do. [... snip ...] Since nobody has offered this advice, let me: Firstly, as already remarked bare excepts are overkill - they catch all sorts of things you shouldn't be handling. That said, if you _don't know_ what exceptions are going to boils out of new code, this is one way to see them all. However, you are catching _everything_ but _not_ finding out what happened. Try this: try: r=requests.post(url, data=query_args) except Exception as e: print "Exception:", e That will at least _tell_ you what happened. You code is blithely presuming Connection Error and telling you that, but it is usually a lie. Once you have characterised what exceptions you get, and which particular ones to handle, then modify your code to catch _only_ those and perform the specific suitable actions, and let the rest escape. Cheers, Cameron Simpson From ian.g.kelly at gmail.com Thu Sep 24 19:31:37 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 24 Sep 2015 17:31:37 -0600 Subject: Modifying signature of ctor in class In-Reply-To: <1443135684451.3744@activenetwerx.com> References: <5cb33b569cf14dfea9424c006c9abc95@exch.activenetwerx.com> <1443135684451.3744@activenetwerx.com> Message-ID: On Thu, Sep 24, 2015 at 5:01 PM, Joseph L. Casale wrote: >> py> from inspect import Signature, Parameter >> py> def foo(*args, **kwargs): pass >> ... >> py> foo.__signature__ = Signature([Parameter('x', >> Parameter.POSITIONAL_OR_KEYWORD), Parameter('y', >> Parameter.KEYWORD_ONLY)]) >> py> help(foo) >> Help on function foo in module __main__: >> >> foo(x, *, y) > > That actually should harmlessly support Python versions less than 3.3 > while simply accomplishing nothing. I don't even need a test for the version. > > I'll go with that as a decent trade off. Well, setting the __signature__ attribute is harmless, but do note that inspect.Signature doesn't exist before 3.3. From breamoreboy at yahoo.co.uk Thu Sep 24 19:40:11 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 25 Sep 2015 00:40:11 +0100 Subject: Idiosyncratic python In-Reply-To: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: On 24/09/2015 07:02, Steven D'Aprano wrote: > I was looking at an in-house code base today, and the author seems to have a > rather idiosyncratic approach to Python. For example: > > for k, v in mydict.items(): > del(k) > ... > > instead of the more obvious > > for v in mydict.values(): > ... > > What are your favorite not-wrong-just-weird Python moments? > My favourite was from a guy I worked with years ago. In C but I'm sure you'll enjoy it. In all functions, something like:- int flag = 0; if flag { printf("\nthe string"); } else{ printf("the string"); flag = 1; } At least I think I've got it correct, too lazy to check, sorry :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From 4kir4.1i at gmail.com Thu Sep 24 20:04:04 2015 From: 4kir4.1i at gmail.com (Akira Li) Date: Fri, 25 Sep 2015 03:04:04 +0300 Subject: Idiosyncratic python References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: <87k2rf1i17.fsf@gmail.com> Mark Lawrence writes: > On 24/09/2015 07:02, Steven D'Aprano wrote: >> I was looking at an in-house code base today, and the author seems to have a >> rather idiosyncratic approach to Python. For example: >> >> for k, v in mydict.items(): >> del(k) >> ... >> >> instead of the more obvious >> >> for v in mydict.values(): >> ... >> >> What are your favorite not-wrong-just-weird Python moments? >> > > My favourite was from a guy I worked with years ago. In C but I'm > sure you'll enjoy it. In all functions, something like:- > > int flag = 0; > if flag { > printf("\nthe string"); > } > else{ > printf("the string"); > flag = 1; > } > > At least I think I've got it correct, too lazy to check, sorry :) It looks like a sys.stdout.softspace hack in Python 2: print line, # comma! From steve at pearwood.info Thu Sep 24 20:08:13 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 25 Sep 2015 10:08:13 +1000 Subject: Idiosyncratic python References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Message-ID: <5604906f$0$1597$c3e8da3$5496439d@news.astraweb.com> On Fri, 25 Sep 2015 02:54 am, Todd wrote: > Using list indexing with booleans in place of a ternary operator. > > a = False > b = [var2, var1][a] > > Instead of: > > b = var1 if a else var2 Ah, you youngsters... :-) Using a bool to index into a list used to be the standard idiom, before the ternary if was added to the language. So I don't consider it "weird", especially as a lot of my code still supports Python 2.4 which doesn't include the ternary if. Sometimes, instead of a list, I'll use a dict: {True: value1, False: value2}[flag] to emulate ternary if. -- Steven From steve at pearwood.info Thu Sep 24 20:55:09 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 25 Sep 2015 10:55:09 +1000 Subject: Idiosyncratic python References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <00884c56-4c94-406b-9902-b94dda9d66b3@googlegroups.com> Message-ID: <56049b70$0$1618$c3e8da3$5496439d@news.astraweb.com> On Fri, 25 Sep 2015 06:46 am, Ned Batchelder wrote: > On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano > wrote: >> What are your favorite not-wrong-just-weird Python moments? > > I've seen this a number of times: > > dict_of_values.update({'key': some_value}) > > why not: > > dict_of_values['key'] = some_value > > I've considered writing a Pylint plugin to flag these... Awesome! I haven't seen it in the wild, but there's this too: dict_of_values.update(key=some_value) -- Steven From steve at pearwood.info Thu Sep 24 21:08:11 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Fri, 25 Sep 2015 11:08:11 +1000 Subject: Idiosyncratic python References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <87twqkbavx.fsf@jester.gateway.sonic.net> <560399b0$0$1511$c3e8da3$5496439d@news.astraweb.com> Message-ID: <56049e7b$0$1601$c3e8da3$5496439d@news.astraweb.com> On Thu, 24 Sep 2015 04:54 pm, Ben Finney wrote: > Steven D'Aprano writes: > >> On Thursday 24 September 2015 16:16, Paul Rubin wrote: >> >> > Steven D'Aprano writes: >> >> for k, v in mydict.items(): >> >> del(k) >> >> [?] The obvious intent is to iterate over the *values* of the >> dictionary, but the coder didn't know about values, so he iterated >> over (key,value) pairs, then deleted the key local variable (not the >> key in the dict!) to keep the namespace clean. > > That's not obvious to me. It's plausible, now that you say it. I find it > also plausible, though, that the author is under the mistaken impression > that the key and value must both be deleted, and has found a way that > appears to do that. In fairness, I have seen the rest of the loop, which I excised, and it uses the value v. There's no hint that the author thinks the dict has been cleared by the end of the loop. -- Steven From katewinslet626 at gmail.com Thu Sep 24 23:52:06 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Thu, 24 Sep 2015 20:52:06 -0700 (PDT) Subject: ConnectionError handling problem In-Reply-To: References: Message-ID: Thank you. I didnt know about keyboard interrupt exception. It means my code hangs without raising any exceptions, what should i do in this case? From katewinslet626 at gmail.com Thu Sep 24 23:57:00 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Thu, 24 Sep 2015 20:57:00 -0700 (PDT) Subject: ConnectionError handling problem In-Reply-To: References: <201509241038.t8OAcT1Z013215@fido.openend.se> Message-ID: <4852c463-0c47-4fef-956a-c6c20f59fc0e@googlegroups.com> Thank you Cameron. I think the problem with my code is that it just hangs without raising any exceptions. And as mentioned by Laura above that when I press CTRL+C, it just catches that exception and prints ConnectionError which is definitely a lie in this case as you mentioned. As my code doesnt raise any exception by itself, instead just hangs, I wont be able to characterize the exceptions and handle them individually. From cs at zip.com.au Fri Sep 25 00:59:19 2015 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 25 Sep 2015 14:59:19 +1000 Subject: ConnectionError handling problem In-Reply-To: <4852c463-0c47-4fef-956a-c6c20f59fc0e@googlegroups.com> References: <4852c463-0c47-4fef-956a-c6c20f59fc0e@googlegroups.com> Message-ID: <20150925045919.GA92950@cskk.homeip.net> On 24Sep2015 20:57, shiva upreti wrote: >Thank you Cameron. >I think the problem with my code is that it just hangs without raising any exceptions. And as mentioned by Laura above that when I press CTRL+C, it just catches that exception and prints ConnectionError which is definitely a lie in this case as you mentioned. Update it to report the _actual_ exception received. (If any.) At least then you will be sure. >As my code doesnt raise any exception by itself, instead just hangs, So, no "ConnectionError" message? >I wont be able to characterize the exceptions and handle them individually. Can you repost you code once it is modified to display the precise exception. Note that one easy way to catch all but progressively handle specific exceptions looks like this: try: ... code ... except OSError as e: print OSError received, specifics are:", e except Exception as e: print "unhandled exception:", e break and so on, inserting the exception types _above_ the final "except" as you add actions for them. Cheers, Cameron Simpson From katewinslet626 at gmail.com Fri Sep 25 01:41:30 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Thu, 24 Sep 2015 22:41:30 -0700 (PDT) Subject: ConnectionError handling problem In-Reply-To: References: Message-ID: <9768479d-6277-4ce1-9c5a-16cfbea5f100@googlegroups.com> On Thursday, September 24, 2015 at 4:09:04 PM UTC+5:30, Laura Creighton wrote: > In a message of Wed, 23 Sep 2015 19:49:17 -0700, shiva upreti writes: > >Hi > >If my script hangs because of the reasons you mentioned above, why doesnt it catch ConnectionError? > >My script stops for a while and when I press CTRL+C, it shows ConnectionError without terminating the process, and the script resumes from where it left off. > > This is exactly what you asked it to do. :) > > >> try: > >> r=requests.post(url, data=query_args) > >> except: > >> print "Connection error" > >> time.sleep(30) > >> continue > > try to do something until you get an Exception. Since that is a > naked except, absolutely any Exception will do. That you > print out 'Connection error' doesn't mean that you are only > catching exceptions raised by trying to send something to the > other end ... any Exception will do. > > So what happens when you press Control-C? > > You get a KeyboardInterrupt exception! :) > > see: https://docs.python.org/2/library/exceptions.html > > And you are catching it :) > And when you catch it you print Connection error and keep on > trying. > > This is why people were telling you that naked try:except: pairs, > are rarely what you want. You didn't want to catch control-c but > you caught it anyway. > > Laura Thank you. I didnt know about keyboard interrupt exception. It means my code hangs without raising any exceptions, what should i do in this case? From katewinslet626 at gmail.com Fri Sep 25 01:42:25 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Thu, 24 Sep 2015 22:42:25 -0700 (PDT) Subject: ConnectionError handling problem In-Reply-To: References: Message-ID: On Thursday, September 24, 2015 at 4:09:04 PM UTC+5:30, Laura Creighton wrote: > In a message of Wed, 23 Sep 2015 19:49:17 -0700, shiva upreti writes: > >Hi > >If my script hangs because of the reasons you mentioned above, why doesnt it catch ConnectionError? > >My script stops for a while and when I press CTRL+C, it shows ConnectionError without terminating the process, and the script resumes from where it left off. > > This is exactly what you asked it to do. :) > > >> try: > >> r=requests.post(url, data=query_args) > >> except: > >> print "Connection error" > >> time.sleep(30) > >> continue > > try to do something until you get an Exception. Since that is a > naked except, absolutely any Exception will do. That you > print out 'Connection error' doesn't mean that you are only > catching exceptions raised by trying to send something to the > other end ... any Exception will do. > > So what happens when you press Control-C? > > You get a KeyboardInterrupt exception! :) > > see: https://docs.python.org/2/library/exceptions.html > > And you are catching it :) > And when you catch it you print Connection error and keep on > trying. > > This is why people were telling you that naked try:except: pairs, > are rarely what you want. You didn't want to catch control-c but > you caught it anyway. > > Laura Thank you. I didnt know about keyboard interrupt exception. It means my code hangs without raising any exceptions, what should i do in this case? From katewinslet626 at gmail.com Fri Sep 25 01:46:20 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Thu, 24 Sep 2015 22:46:20 -0700 (PDT) Subject: ConnectionError handling problem In-Reply-To: References: <4852c463-0c47-4fef-956a-c6c20f59fc0e@googlegroups.com> Message-ID: <550e9854-1247-4f6b-b9c7-7c8d7ea6ae37@googlegroups.com> On Friday, September 25, 2015 at 10:55:45 AM UTC+5:30, Cameron Simpson wrote: > On 24Sep2015 20:57, shiva upreti wrote: > >Thank you Cameron. > >I think the problem with my code is that it just hangs without raising any exceptions. And as mentioned by Laura above that when I press CTRL+C, it just catches that exception and prints ConnectionError which is definitely a lie in this case as you mentioned. > > Update it to report the _actual_ exception received. (If any.) At least then > you will be sure. > > >As my code doesnt raise any exception by itself, instead just hangs, > > So, no "ConnectionError" message? > > >I wont be able to characterize the exceptions and handle them individually. > > Can you repost you code once it is modified to display the precise exception. > > Note that one easy way to catch all but progressively handle specific > exceptions looks like this: > > try: > ... code ... > except OSError as e: > print OSError received, specifics are:", e > except Exception as e: > print "unhandled exception:", e > break > > and so on, inserting the exception types _above_ the final "except" as you add > actions for them. > > Cheers, > Cameron Simpson Hi Cameron. I think you may have misunderstood my problem. When my code runs it doesnt throw any exception. It just hangs(stops executing) for unknown reasons. I want to know why. It doesnt even throw ConnectionError unless I press CTRL+C(only because I hard coded ConnectionError). I can repost the whole problem again if you want me to. Thanks.:) From guirguismichel at yahoo.co.uk Fri Sep 25 02:13:00 2015 From: guirguismichel at yahoo.co.uk (Michel Guirguis) Date: Fri, 25 Sep 2015 09:13:00 +0300 Subject: Problem to calculate the mean in version 3.4 Message-ID: Good morning, I have downloaded the version 3.4 and I have a problem to calculate the mean. The software does not recognise the function mean(). I am getting the following error. >>> mean([1, 2, 3, 4, 4]) Traceback (most recent call last): File "", line 1, in mean([1, 2, 3, 4, 4]) NameError: name 'mean' is not defined Could you please help. Is it possible to send me the version that calculate statistics. Thanks, Michel 9.7. statistics ? Mathematical statistics functions New in version 3.4. Source code: Lib/statistics.py This module provides functions for calculating mathematical statistics of numeric (Real-valued) data. NoteUnless explicitly noted otherwise, these functions support int, float, decimal.Decimal and fractions.Fraction. Behaviour with other types (whether in the numeric tower or not) is currently unsupported. Mixed types are also undefined and implementation-dependent. If your input data consists of mixed types, you may be able to use map() to ensure a consistent result, e.g. map(float,input_data). 9.7.1. Averages and measures of central location These functions calculate an average or typical value from a population or sample. mean() Arithmetic mean (?average?) of data. median() Median (middle value) of data. median_low() Low median of data. median_high() High median of data. median_grouped() Median, or 50th percentile, of grouped data. mode() Mode (most common value) of discrete data. 9.7.2. Measures of spread These functions calculate a measure of how much the population or sample tends to deviate from the typical or average values. pstdev() Population standard deviation of data. pvariance() Population variance of data. stdev() Sample standard deviation of data. variance() Sample variance of data. 9.7.3. Function details Note: The functions do not require the data given to them to be sorted. However, for reading convenience, most of the examples show sorted sequences. statistics.mean(data) Return the sample arithmetic mean of data, a sequence or iterator of real-valued numbers. The arithmetic mean is the sum of the data divided by the number of data points. It is commonly called ?the average?, although it is only one of many different mathematical averages. It is a measure of the central location of the data. If data is empty, StatisticsError will be raised. Some examples of use: >>> >>> mean([1, 2, 3, 4, 4]) 2.8 >>> mean([-1.0, 2.5, 3.25, 5.75]) 2.625 -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Sep 25 03:09:16 2015 From: __peter__ at web.de (Peter Otten) Date: Fri, 25 Sep 2015 09:09:16 +0200 Subject: Problem to calculate the mean in version 3.4 References: Message-ID: Michel Guirguis wrote: > I have downloaded the version 3.4 and I have a problem to calculate the > mean. The software does not recognise the function mean(). I am getting > the following error. > >>>> mean([1, 2, 3, 4, 4]) > Traceback (most recent call last): > File "", line 1, in > mean([1, 2, 3, 4, 4]) > NameError: name 'mean' is not defined > > Could you please help. Is it possible to send me the version that > calculate statistics. The help for the statistics and other modules assumes basic knowledge of Python. I recommend you read the tutorial or any other introductory text on Python before you proceed. Regarding your actual question: before you can use a function you have to import it. There are two ways: (1) Recommended: import the module and use the qualified name: >>> import statistics >>> statistics.mean([1, 2, 3, 4, 4]) 2.8 (2) Import the function. Typically done when you want to use it in the interactive interpreter, not in a script. >>> from statistics import mean >>> mean([1, 2, 3, 4, 4]) 2.8 From no.email at nospam.invalid Fri Sep 25 03:12:05 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 25 Sep 2015 00:12:05 -0700 Subject: Problem to calculate the mean in version 3.4 References: Message-ID: <87eghnas6y.fsf@jester.gateway.sonic.net> Michel Guirguis writes: >>>> mean([1, 2, 3, 4, 4]) > Traceback (most recent call last):... > NameError: name 'mean' is not defined Before you can use that function, you have to import the statistics module, e.g.: >>> import statistics >>> statistics.mean([1,2,3,4,4]) or >>> from statistics import mean >>> mean([1,2,3,4,4]) From cs at zip.com.au Fri Sep 25 03:24:30 2015 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 25 Sep 2015 17:24:30 +1000 Subject: ConnectionError handling problem In-Reply-To: <550e9854-1247-4f6b-b9c7-7c8d7ea6ae37@googlegroups.com> References: <550e9854-1247-4f6b-b9c7-7c8d7ea6ae37@googlegroups.com> Message-ID: <20150925072430.GA96892@cskk.homeip.net> On 24Sep2015 22:46, shiva upreti wrote: >On Friday, September 25, 2015 at 10:55:45 AM UTC+5:30, Cameron Simpson wrote: >> On 24Sep2015 20:57, shiva upreti wrote: >> >Thank you Cameron. >> >I think the problem with my code is that it just hangs without raising any >> >exceptions. And as mentioned by Laura above that when I press CTRL+C, it >> >just catches that exception and prints ConnectionError which is definitely >> >a lie in this case as you mentioned. Ok. You original code says: try: r=requests.post(url, data=query_args) except: print "Connection error" and presumably we think your code is hanging inside the requests.post call? You should probably try to verify that, because if it is elsewhere you need to figure out where (lots of print statements is a first start on that). I would open two terminals. Run your program until it hangs in one. While it is hung, examine the network status. I'll presume you're on a UNIX system of some kind, probably Linux? If not it may be harder (or just require someone other than me). If it is hung in the .post call, quite possibly it has an established connecion to the target server - maybe that server is hanging. The shell command: netstat -rn | fgrep 172.16.68.6 | fgrep 8090 will show every connection to your server hosting the URL "http://172.16.68.6:8090/login.xml". That will tell you if you have a connection (if you are the only person doing the connecting from your machine). If you have the "lsof" program (possibly in /usr/sbin, so "/usr/sbin/lsof") you can also examine the state of your hung Python program. This: lsof -p 12345 will report on the open files and network connections of the process with pid 12345. Adjust to suit: you can find your program's pid ("process id") with the "ps" command, or by backgrounding your program an issuing the "jobs" command, which should show the process id more directly. Cheers, Cameron Simpson From hemla21 at gmail.com Fri Sep 25 04:53:39 2015 From: hemla21 at gmail.com (Hedieh E) Date: Fri, 25 Sep 2015 01:53:39 -0700 (PDT) Subject: PyInstaller+ Python3.5 (h5py import error) In-Reply-To: References: <4d764608-4091-4600-a1ed-ac11bd790792@googlegroups.com> <4ca597c9-5b1f-4709-a88b-5ecc78d1c590@googlegroups.com> <4f9cdd42-fff9-4f0c-b36d-277df25d109f@googlegroups.com> Message-ID: <0063748a-75f1-40d5-8916-a73632bd9e6e@googlegroups.com> On Thursday, September 24, 2015 at 1:12:31 PM UTC+2, Laura Creighton wrote: > In a message of Thu, 24 Sep 2015 02:58:35 -0700, Heli Nix writes: > >Thanks Christian, > > > >It turned out that h5py.defs was not the only hidden import that I needed to add. > > > >I managed to get it working with the follwoing command adding 4 hidden imports. > > > > > >pyinstaller --hidden-import=h5py.defs --hidden-import=h5py.utils --hidden-import=h5py.h5ac --hidden-import=h5py._proxy test.py > > > > > >is there anyway that you can use to add all h5py submodules all together? > > > >Thanks, > > > > Yes. You can use a hook file. > see: https://pythonhosted.org/PyInstaller/#using-hook-files > > Laura Thanks Laura, Very Useful, From alister.nospam.ware at ntlworld.com Fri Sep 25 06:42:59 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Fri, 25 Sep 2015 10:42:59 +0000 (UTC) Subject: Learning Modules, Arguments, Parameters (imma noob) References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: On Thu, 24 Sep 2015 11:45:06 -0700, codywcox wrote: > I seem to be having a problem understanding how arguments and parameters > work, Most likely why my code will not run. > Can anyone elaborate on what I am doing wrong? > > ''' > Cody Cox 9/16/2015 Programming Exercise 1 - Kilometer Converter Design a > modular program that asks the user to enter a distance in kilometers and > then convert it to miles Miles = Kilometers * 0.6214 ''' > > def main(): > get_input() > convert_kilo() > > > def get_input(kilo): > kilo = float(input('Enter Kilometers: ')) > return kilo > > def convert_kilo(kilo,miles): > miles = float(kilo * 0.6214) > print( kilo,' kilometers converts to ',miles,' miles') > > main() clearly a homework exercise but you have asked for help in understanding & not just for a solution which is good. as others have pointed out you are throwing away the data returned from get_input I would also suggest that you return the result form convert_kilo instead of printing it in the function & print it in the main loop instead. kilo=get_input() miles=convert_kilo(kilo) print (miles) it does not matter for this trivial assignment but as you progress further you will discovery it is better to keep output seperated from the main logic of the program. -- What is mind? No matter. What is matter? Never mind. -- Thomas Hewitt Key, 1799-1875 From michael at stroeder.com Fri Sep 25 12:29:25 2015 From: michael at stroeder.com (=?UTF-8?Q?Michael_Str=c3=b6der?=) Date: Fri, 25 Sep 2015 18:29:25 +0200 Subject: ANN: python-ldap 2.4.21 Message-ID: Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.4.21 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAP URLs and LDAPv3 schema). Project's web site: http://www.python-ldap.org/ Checksums: $ md5sum python-ldap-2.4.21.tar.gz 1ce26617e066f412fd5ba95bfba4ba5a $ sha1sum python-ldap-2.4.21.tar.gz 35ed5913d804f14e952bec414c569e140feb889d $ sha256sum python-ldap-2.4.21.tar.gz 2a3ce606465d2d5fbd0a620516b6648ffd85c343d9305d49a2a1f7d338b8bbd4 Ciao, Michael. ---------------------------------------------------------------- Released 2.4.21 2015-09-25 Changes since 2.4.20: Lib/ * LDAPObject.read_s() now returns None instead of raising ldap.NO_SUCH_OBJECT in case the search operation returned emtpy result. * ldap.resiter.ResultProcessor.allresults() now takes new key-word argument add_ctrls which is internally passed to LDAPObject.result4() and lets the method also return response control along with the search results. * Added ldap.controls.deref implementing support for dereference control Tests/ * Unit tests for module ldif (thanks to Petr Viktorin) -- Michael Str?der E-Mail: michael at stroeder.com http://www.stroeder.com From bstrum at verizon.net Fri Sep 25 12:55:05 2015 From: bstrum at verizon.net (Bill Strum) Date: Fri, 25 Sep 2015 12:55:05 -0400 Subject: 64 bit python 3.5 Message-ID: Is there a 64 bit version of 3.5 and if so where can I get it. Thanks. -- Bill Strum -------------- next part -------------- An HTML attachment was scrubbed... URL: From codywcox at gmail.com Fri Sep 25 14:50:10 2015 From: codywcox at gmail.com (Cody Cox) Date: Fri, 25 Sep 2015 11:50:10 -0700 (PDT) Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: Awesome guys! Thank you for helping me understand this material. Parameters and Arguments are tricky. Looks like its mainly a game of connect the dots with variables. lol. When you return a variable, it needs somewhere to go, and that's why it goes to the next call into the argument area if I need to use that piece of information for a calculation, right? so if I understand correctly, when I create a function and return a variable, that variable needs to go in the argument when it is called? or into another functions argument for calculation? I apologize if I sound dumb. lol. I know this must be very elementary. Yes this is a homework assignment, but I was trying to figure out how parameters and arguments work, not get an answer, this was a huge help. I will keep looking over your details over and over to make sure I understand. Appreciate all the help and understanding! :) -Cody From codywcox at gmail.com Fri Sep 25 14:53:14 2015 From: codywcox at gmail.com (Cody Cox) Date: Fri, 25 Sep 2015 11:53:14 -0700 (PDT) Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: <683e63d0-e7d0-4d88-96d8-30878d595499@googlegroups.com> Oh, i also noticed that declaring the variable I was using and setting it =0.0 helped me out, seems the program had "garbage" in it... (that's what my professor said.) From codywcox at gmail.com Fri Sep 25 15:03:43 2015 From: codywcox at gmail.com (Cody Cox) Date: Fri, 25 Sep 2015 12:03:43 -0700 (PDT) Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: #Cody Cox #9/16/2015 #Programming Exercise 1 - Kilometer Converter #Design a modular program that asks the user to enter a distance in kilometers and then covert it to miles # Miles = Kilometers * 0.6214 def main(): #set the variable to 0.0, makes it a float and creates a place in memory for the variable. kilo = 0.0 ''' this I am not sure about, I set Kilo=get_input(kilo), but why do I need the argument when I am going to pass it to convert_to_kilometers? but the program works so I am guessing that is where it is saving the variable in order to be passed? so it needs to be returned as an argument to be passed as an argument for the next call??? ''' kilo = get_input(kilo) convert_to_kilometers(kilo) def get_input(kilo): kilo =float(input('Enter the amount of Kilometers: ')) return kilo def convert_to_kilometers(kilo): miles = kilo * .6214 print(kilo,'Kilometers converts to: ',miles, ' Miles.') main() ''' This was a great learning experience trying to understand modules and how parameters & arguments work together. Thanks for helping me understand ''' From ian.g.kelly at gmail.com Fri Sep 25 15:20:47 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 25 Sep 2015 13:20:47 -0600 Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: On Fri, Sep 25, 2015 at 1:03 PM, Cody Cox wrote: > def main(): > #set the variable to 0.0, makes it a float and creates a place in memory for the variable. > kilo = 0.0 This is addressing a symptom, not the actual problem. Initializing kilo here prevents Python from complaining when you try to access the kilo variable in the "kilo = get_input(kilo)" line below. However, you don't need it there either. > ''' > this I am not sure about, I set Kilo=get_input(kilo), but why do I need the argument when > I am going to pass it to convert_to_kilometers? but the program works so I am guessing that is where it is saving > the variable in order to be passed? so it needs to be returned as an argument to be passed as an argument for > the next call??? > > ''' > kilo = get_input(kilo) No, you don't need the argument at all. You use arguments to pass in data that the function needs to do its work. In this case you're passing in the *current* value of kilo, which you set above to be 0.0. This isn't data that is needed by get_input, so you shouldn't pass it in (and the get_input function should not require it). The result of the get_input call is then assigned to kilo, replacing the 0.0 which you don't need. It's fine for kilo to be initialized with this line rather than the one above. > convert_to_kilometers(kilo) This is okay, but as you get more advanced you will probably want this function to return a value, which you could store in another variable, e.g.: miles = convert_to_miles(kilo) > def get_input(kilo): > kilo =float(input('Enter the amount of Kilometers: ')) > return kilo As noted above, this function should not have kilo as a parameter. It never uses it. This function needs to return kilo *to* its caller, not take a value for kilo *from* its caller. > def convert_to_kilometers(kilo): > miles = kilo * .6214 > print(kilo,'Kilometers converts to: ',miles, ' Miles.') This is fine but poorly named. This function converts kilometers to miles. It doesn't convert anything to kilometers as suggested by the name. And again, as you get more advanced you would probably want this to return the value of miles rather than just print it. From lac at openend.se Fri Sep 25 16:15:26 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 25 Sep 2015 22:15:26 +0200 Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: <201509252015.t8PKFQO4028615@fido.openend.se> In a message of Fri, 25 Sep 2015 11:50:10 -0700, Cody Cox writes: >Awesome guys! Thank you for helping me understand this material. Parameters and Arguments are tricky. Looks like its mainly a game of connect the dots with variables. lol. > >When you return a variable, it needs somewhere to go, and that's why it goes to the next call into the argument area if I need to use that piece of information for a calculation, right? No. >so if I understand correctly, when I create a function and return a variable, that variable needs to go in the argument when it is called? or into another functions argument for calculation? >I apologize if I sound dumb. lol. I know this must be very elementary. No. >Yes this is a homework assignment, but I was trying to figure out how parameters and arguments work, not get an answer, this was a huge help. I will keep looking over your details over and over to make sure I understand. > >Appreciate all the help and understanding! :) > >-Cody You have a very basic conceptual misunderstanding. def main(): count = 0 animals = 'tigers' change_my_value_to_50_frogs(count, animals) print ("I fought", count, animals) def change_my_value_to_50_frogs(count, animals): count = 50 animals = 'frogs' main() ------------- I am pretty sure you expect this code to print 'I fought 50 frogs'. It doesn't. It prints 'I fought 0 tigers'. You have the idea that when you pass parameters to a function, by name, you want the values of those parameters to get changed by the function. (and I sort of cheated by calling the function change_my_value). This is not what happens. You cannot change values this way. so we rewrite change_my_value_to_50_frogs def fifty_frogs(): count = 50 animals = 'frogs' return count, animals Now fifty_frogs is going to happily return the changed values you wanted. But you have to set up your main program to receive those changed values you wanted. so we rewrite main as: def main(): count = 0 animals = 'tigers' count, animals = fifty_frogs() print ("I fought", count, animals) now main() says 'I fought 50 frogs'. NOTE: there is nothing, nothing, nothing special about the fact that in fifty_frogs I used the names 'count' and 'animals'. Let us try a new version of fifty_frogs() def fifty_frogs(): experience = 50 monsters = 'frogs' return experience, monsters All the same, just different words. Does that matter? No. You are going to return whatever is called 'experience' and whatever is called 'monsters' and assign them to 'count' and 'monsters'. Whether you name these things the same thing, or different things makes no difference. Does this make sense? If not, come back with more questions. And play around with the python interactive interpreter, or idle -- that is what it is for. neat little experiements like this. :) Laura From lac at openend.se Fri Sep 25 16:25:29 2015 From: lac at openend.se (Laura Creighton) Date: Fri, 25 Sep 2015 22:25:29 +0200 Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: <201509252015.t8PKFQO4028615@fido.openend.se> References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> <201509252015.t8PKFQO4028615@fido.openend.se> Message-ID: <201509252025.t8PKPT6R029468@fido.openend.se> In a message of Fri, 25 Sep 2015 22:15:26 +0200, Laura Creighton writes: >No. You are going to return whatever is called 'experience' and >whatever is called 'monsters' and assign them to 'count' and 'monsters'. ARRGH! I meant assign them to 'count' and 'animals'. (I read that 3 times and _still_ got it wrong!) I am very sorry for this confusion. Laura From codywcox at gmail.com Fri Sep 25 16:52:18 2015 From: codywcox at gmail.com (Cody Cox) Date: Fri, 25 Sep 2015 13:52:18 -0700 (PDT) Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> <201509252015.t8PKFQO4028615@fido.openend.se> Message-ID: <74135f8c-9e1c-486b-b474-e12278911c09@googlegroups.com> On Friday, September 25, 2015 at 1:26:02 PM UTC-7, Laura Creighton wrote: > In a message of Fri, 25 Sep 2015 22:15:26 +0200, Laura Creighton writes: > > >No. You are going to return whatever is called 'experience' and > >whatever is called 'monsters' and assign them to 'count' and 'monsters'. > > ARRGH! I meant > assign them to 'count' and 'animals'. > (I read that 3 times and _still_ got it wrong!) > I am very sorry for this confusion. > Laura All good, I got the idea, and you explained it very nicly. thank you for this example. I shall be back with more questions! haha. -Cody From denismfmcmahon at gmail.com Fri Sep 25 19:59:38 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 25 Sep 2015 23:59:38 +0000 (UTC) Subject: Learning Modules, Arguments, Parameters (imma noob) References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: On Fri, 25 Sep 2015 12:03:43 -0700, Cody Cox wrote: > #Design a modular program that asks the user to enter a distance in > kilometers and then covert it to miles # Miles = Kilometers * 0.6214 #!/usr/bin/python # main calls the input routine to get the km value, then # calls the conversion routine to convert the km value # to miles, then prints the output def main(): km = get_kms() mi = convert_km_mi(k) print "{} Km is {} miles.".format(km, mi) # get_float_input() reads a float input using the supplied # prompt. def get_float_input(prompt): return float(input(prompt)) # Get kms uses the generic get_float_input to read a km # value def get_kms(): return get_float_input("Enter Kms: ") # generic conversion function def convert_float_a_b(a, factor): return float(a * factor) # convert km_mi uses the generic converter # to convert km to miles def convert_km_mi(km): return convert_float_a_b(km, 0.6214) # now call main to kick it all off main() -- Denis McMahon, denismfmcmahon at gmail.com From tjreedy at udel.edu Fri Sep 25 20:08:01 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 25 Sep 2015 20:08:01 -0400 Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: On 9/25/2015 2:50 PM, Cody Cox wrote: > Awesome guys! Thank you for helping me understand this material. > Parameters and Arguments are tricky. Looks like its mainly a game of > connect the dots with variables. lol. If you stick with the convention that parameters are names in the header of a function definition, arguments are objects in a function call, and calls bind parameter names to argements (or sometimes collected arguments), then it is not so tricky. But also remember that not everyone follows this convention, or even any consistent usage. To reiterate about calling and binding. def f(x): pass f(2) binds the name 'x' to the int object with value 2. This is essentially the same as 'x = 2', except that the binding takes place in the local namespace of the function rather than in the local namespace of the call. -- Terry Jan Reedy From esawiek at gmail.com Fri Sep 25 23:43:17 2015 From: esawiek at gmail.com (Ek Esawi) Date: Fri, 25 Sep 2015 23:43:17 -0400 Subject: PY3.5 and nnumpy and scipy installation problem Message-ID: Hi All? I am a beginner in Python and new to this list, but I am an experienced programming in a few other languages. Last year I installed numpy and scipy for Python3.3 on my computer with windows 7, 64 bit OS. Today I downloaded Python3.5, but I the installation for numpy 1.9.2 or 1.9.3 nor scipy 0.16.0 did work on the same computer. Basically the setup for both numpy and scipy did not work. Any ideas are greatly appreciated. Thanks in advance, Sincerely, EKE -------------- next part -------------- An HTML attachment was scrubbed... URL: From orgnut at yahoo.com Sat Sep 26 01:55:13 2015 From: orgnut at yahoo.com (Larry Hudson) Date: Fri, 25 Sep 2015 22:55:13 -0700 Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: <5O6dnZH9L9vfrpvLnZ2dnUU7-aGdnZ2d@giganews.com> You've already received a lot of answers and guidance, but here is on more point... On 09/25/2015 12:03 PM, Cody Cox wrote: [snip] > this I am not sure about, I set Kilo=get_input(kilo), ... Watch your capitalization! Kilo is _NOT_ the same as kilo. Case is significant in Python (as well as in many other programming languages). Also, as has already been pointed out: what you want here is kilo=get_input(). Along with the corresponding change to the get_input() definition. This function does NOT need a passed parameter. -=- Larry -=- From steve at pearwood.info Sat Sep 26 02:20:25 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 26 Sep 2015 16:20:25 +1000 Subject: PY3.5 and nnumpy and scipy installation problem References: Message-ID: <5606392a$0$1592$c3e8da3$5496439d@news.astraweb.com> Hi Ek, and welcome, My responses below your questions. On Sat, 26 Sep 2015 01:43 pm, Ek Esawi wrote: > Hi All? > > I am a beginner in Python and new to this list, but I am an experienced > programming in a few other languages. > > Last year I installed numpy and scipy for Python3.3 on my computer with > windows 7, 64 bit OS. Today I downloaded Python3.5, but I the installation > for numpy 1.9.2 or 1.9.3 nor scipy 0.16.0 did work on the same computer. > Basically the setup for both numpy and scipy did not work. Any ideas are > greatly appreciated. While we are very knowledgeable, what we don't know is what went wrong. Can you describe what you mean by "did not work"? Preferably, if an error message was printed, please COPY and PASTE (don't retype, especially not from memory) the error message? If some other error occurred (Windows crash, computer caught fire...) please describe it. It may help if you explain the exact commands you used to install. Did you use a text-based installer from the command line, or a GUI? The more information you can give, the better the chances we can help. Regards, -- Steven From breamoreboy at yahoo.co.uk Sat Sep 26 02:49:36 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 26 Sep 2015 07:49:36 +0100 Subject: PY3.5 and nnumpy and scipy installation problem In-Reply-To: References: Message-ID: On 26/09/2015 04:43, Ek Esawi wrote: > Hi All? > > I am a beginner in Python and new to this list, but I am an experienced > programming in a few other languages. > > Last year I installed numpy and scipy for Python3.3 on my computer with > windows 7, 64 bit OS. Today I downloaded Python3.5, but I the > installation for numpy 1.9.2 or 1.9.3 nor scipy 0.16.0 did work on the > same computer. Basically the setup for both numpy and scipy did not > work. Any ideas are greatly appreciated. You don't have Visual Studio 2015 installed and so couldn't compile the code from a .tar.gz file or similar? Once again the cavalry comes charging over the hill. http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy Gohkle for World Vice President, after the BDFL :) > > Thanks in advance, > > Sincerely, EKE > -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at yahoo.co.uk Sat Sep 26 02:54:19 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 26 Sep 2015 07:54:19 +0100 Subject: 64 bit python 3.5 In-Reply-To: References: Message-ID: On 25/09/2015 17:55, Bill Strum wrote: > Is there a 64 bit version of 3.5 and if so where can I get it. > > Thanks. > > -- > Bill Strum > https://www.python.org/downloads/release/python-350/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From wxjmfauth at gmail.com Sat Sep 26 03:02:11 2015 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 26 Sep 2015 00:02:11 -0700 (PDT) Subject: Learning Modules, Arguments, Parameters (imma noob) In-Reply-To: References: <7ad8941d-04aa-42c5-82e9-10cdf02ab695@googlegroups.com> Message-ID: <0ca72920-576b-4767-8309-ca53d5f60ccf@googlegroups.com> > > print "{} Km is {} miles.".format(km, mi) > Prefix of SI units: km and not Km (lowercase "k"). http://www.bipm.org/en/about-us/ jmf From vinay_sajip at yahoo.co.uk Sat Sep 26 06:25:06 2015 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sat, 26 Sep 2015 10:25:06 +0000 (UTC) Subject: ANN: A new version (0.3.8) of python-gnupg has been released. In-Reply-To: <241091267.841934.1443133560070.JavaMail.yahoo@mail.yahoo.com> References: <241091267.841934.1443133560070.JavaMail.yahoo@mail.yahoo.com> Message-ID: <1378832746.1638414.1443263106461.JavaMail.yahoo@mail.yahoo.com> A new version of the Python module which wraps GnuPG has been released. What Changed? ============= This is an enhancement and bug-fix release, and all users are encouraged to upgrade. See the project website [1] for more information. Brief summary: * Fixed #22: handled PROGRESS messages during verification and signing. * Fixed #26: handled PINENTRY_LAUNCHED messages during verification, decryption and key generation. * Fixed #28: Allowed a default Name-Email to be computed even when neither of LOGNAME and USERNAME are in the environment. * Fixed #29: Included test files missing from the tarball in previous versions. * Fixed #39: On Python 3.x, passing a text instead of a binary stream caused file decryption to hang due to a UnicodeDecodeError. This has now been correctly handled: The decryption fails with a "no data" status. * Fixed #41: Handled Unicode filenames correctly by encoding them on 2.x using the file system encoding. * Fixed #43: handled PINENTRY_LAUNCHED messages during key export. Thanks to Ian Denhardt for looking into this. * Hide the console window which appears on Windows when gpg is spawned. Thanks to K?vin Bernard-Allies for the patch. * Subkey fingerprints are now captured. * The returned value from the list_keys method now has a new attribute, key_map, which is a dictionary mapping key and subkey fingerprints to the corresponding key's dictionary. With this change, you don't need to iterate over the (potentially large) returned list to search for a key with a given fingerprint - the key_map dict will take you straight to the key info, whether the fingerprint you have is for a key or a subkey. Thanks to Nick Daly for the initial suggestion. This release [2] has been signed with my code signing key: Vinay Sajip (CODE SIGNING KEY) Fingerprint: CA74 9061 914E AC13 8E66 EADB 9147 B477 339A 9B86 However, due to some error the signature for the source distribution (.tar.gz) didn't get uploaded. To rectify this, I have pasted it into the PyPI page for the release [2]. What Does It Do? ================ The gnupg module allows Python programs to make use of the functionality provided by the Gnu Privacy Guard (abbreviated GPG or GnuPG). Using this module, Python programs can encrypt and decrypt data, digitally sign documents and verify digital signatures, manage (generate, list and delete) encryption keys, using proven Public Key Infrastructure (PKI) encryption technology based on OpenPGP. This module is expected to be used with Python versions >= 2.4, as it makes use of the subprocess module which appeared in that version of Python. This module is a newer version derived from earlier work by Andrew Kuchling, Richard Jones and Steve Traugott. A test suite using unittest is included with the source distribution. Simple usage: >>> import gnupg >>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory') >>> gpg.list_keys() [{ ... 'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2', 'keyid': '197D5DAC68F1AAB2', 'length': '1024', 'type': 'pub', 'uids': ['', 'Gary Gross (A test user) ']}, { ... 'fingerprint': '37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A', 'keyid': '0C5FEFA7A921FC4A', 'length': '1024', ... 'uids': ['', 'Danny Davis (A test user) ']}] >>> encrypted = gpg.encrypt("Hello, world!", ['0C5FEFA7A921FC4A']) >>> str(encrypted) '-----BEGIN PGP MESSAGE-----\nVersion: GnuPG v1.4.9 (GNU/Linux)\n \nhQIOA/6NHMDTXUwcEAf . -----END PGP MESSAGE-----\n' >>> decrypted = gpg.decrypt(str(encrypted), passphrase='secret') >>> str(decrypted) 'Hello, world!' >>> signed = gpg.sign("Goodbye, world!", passphrase='secret') >>> verified = gpg.verify(str(signed)) >>> print "Verified" if verified else "Not verified" 'Verified' As always, your feedback is most welcome (especially bug reports [3], patches and suggestions for improvement, or any other points via the mailing list/discussion group [4]). Enjoy! Cheers Vinay Sajip Red Dove Consultants Ltd. [1] https://bitbucket.org/vinay.sajip/python-gnupg [2] https://pypi.python.org/pypi/python-gnupg/0.3.8 [3] https://bitbucket.org/vinay.sajip/python-gnupg/issues [4] https://groups.google.com/forum/#!forum/python-gnupg From esawiek at gmail.com Sat Sep 26 07:54:04 2015 From: esawiek at gmail.com (Ek Esawi) Date: Sat, 26 Sep 2015 07:54:04 -0400 Subject: PY3.5 and nnumpy and scipy installation problem Message-ID: Hi Steven, Thank you for the prompt response. What I meant by not working is the following: once I had py3.5 working, I downloaded numpy and scipy and unzipped them. After that I tried to install them. But there is no install file for either. There was a setup file which I thought would do the same. However, when I double clicked it, it showed a python window for a sec and that?s all. When I went to IDEL and typed import numpy as np I got the following error message which suggests PY did not find numpy. >>> import numpy as np Traceback (most recent call last): File "", line 1, in import numpy as np ImportError: No module named 'numpy' >>> Thanks again, EK -------------- next part -------------- An HTML attachment was scrubbed... URL: From gengyangcai at gmail.com Sat Sep 26 08:42:16 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sat, 26 Sep 2015 05:42:16 -0700 (PDT) Subject: Django (Python Web Framework) Tutorial Message-ID: <1421a34f-d8cc-4367-adab-2c2b46504d72@googlegroups.com> So I am using Mac OS X Yosemite Version 10.10.2, going through the django tutorial : https://docs.djangoproject.com/en/1.8/intro/tutorial01/ and learning to use it. Am currently on the 2nd chapter "Creating a Project" and got a question to ask : This is the series of steps I took to reach this point : A) I created a folder called "Weiqi" in my home directory. (named after the game I am best at!) B) Then I typed the command $ cd Weiqi in the "Terminal" CaiGengYangs-MacBook-Pro:~ CaiGengYang$ cd Weiqi --- input and got this output : CaiGengYangs-MacBook-Pro:Weiqi CaiGengYang$ --- output C) Then I ran the following command in the Terminal : $ django-admin startproject mysite. This created a mysite folder which appeared inside the original Weiqi folder in my home directory. When I clicked on the mysite folder, there is a manage.py file and another mysite folder inside the original mysite folder. When I click on the mysite folder, there are 4 files in it : __init__.py , settings.py , urls.py and wsgi.py. D) The next chapter of the tutorial says this : "Where should this code live? If your background is in plain old PHP (with no use of modern frameworks), you're probably used to putting code under the Web server's document root (in a place such as /var/www). With Django, you don't do that. It's not a good idea to put any of this Python code within your Web server's document root, because it risks the possibility that people may be able to view your code over the Web. That's not good for security. Put your code in some directory outside of the document root, such as /home/mycode." Question : I am a little confused about the last paragraph : What exactly is a "directory outside of the document root, such as /home/mycode." and how do you "Put your code in this directory" ? Thanks a lot ! Appreciate it Cai Gengyang From gvm2121 at gmail.com Sat Sep 26 09:46:34 2015 From: gvm2121 at gmail.com (Gonzalo V) Date: Sat, 26 Sep 2015 09:46:34 -0400 Subject: ConnectionError handling problem In-Reply-To: <20150925072430.GA96892@cskk.homeip.net> References: <550e9854-1247-4f6b-b9c7-7c8d7ea6ae37@googlegroups.com> <20150925072430.GA96892@cskk.homeip.net> Message-ID: Hi Cameron. i had the same problems and you have to tell to python what to do with the connect problem. try this: ... except *urllib.error.HTTPError* as e: if e.getcode()==504: disp = "SIN RESPUESTA DEL SERVIDOR" #(No answer from the server) nombre='' origen='' precioAhora='' print(e.getcode(),disp) pass that works for me. You can handle any error. 404, and 500 and more. but you have to tell him to python what to do. greeting from Chile. Sorry my english. Saludos, Gonzalo 2015-09-25 3:24 GMT-04:00 Cameron Simpson : > On 24Sep2015 22:46, shiva upreti wrote: > >> On Friday, September 25, 2015 at 10:55:45 AM UTC+5:30, Cameron Simpson >> wrote: >> >>> On 24Sep2015 20:57, shiva upreti wrote: >>> >Thank you Cameron. >>> >I think the problem with my code is that it just hangs without raising >>> any >exceptions. And as mentioned by Laura above that when I press CTRL+C, >>> it >just catches that exception and prints ConnectionError which is >>> definitely >a lie in this case as you mentioned. >>> >> > Ok. You original code says: > > try: > r=requests.post(url, data=query_args) > except: > print "Connection error" > > and presumably we think your code is hanging inside the requests.post > call? You should probably try to verify that, because if it is elsewhere > you need to figure out where (lots of print statements is a first start on > that). > > I would open two terminals. Run your program until it hangs in one. > > While it is hung, examine the network status. I'll presume you're on a > UNIX system of some kind, probably Linux? If not it may be harder (or just > require someone other than me). > > If it is hung in the .post call, quite possibly it has an established > connecion to the target server - maybe that server is hanging. > > The shell command: > > netstat -rn | fgrep 172.16.68.6 | fgrep 8090 > > will show every connection to your server hosting the URL " > http://172.16.68.6:8090/login.xml". That will tell you if you have a > connection (if you are the only person doing the connecting from your > machine). > > If you have the "lsof" program (possibly in /usr/sbin, so > "/usr/sbin/lsof") you can also examine the state of your hung Python > program. This: > > lsof -p 12345 > > will report on the open files and network connections of the process with > pid 12345. Adjust to suit: you can find your program's pid ("process id") > with the "ps" command, or by backgrounding your program an issuing the > "jobs" command, which should show the process id more directly. > > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nad at acm.org Sat Sep 26 10:00:21 2015 From: nad at acm.org (Ned Deily) Date: Sat, 26 Sep 2015 10:00:21 -0400 Subject: Fixing Python install on the Mac after running 'CleanMyMac' (fwd) References: Message-ID: In article , kacyjones at lclark.edu wrote: > I was having this same problem, entered those commands and got this as a > response: > > MacBook-Pro:~ kacyjones$ /usr/bin/python2.7 -c 'import > numpy;print(numpy.__file__)' > /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/num > py/__init__.pyc > MacBook-Pro:~ kacyjones$ > MacBook-Pro:~ kacyjones$ /usr/bin/python2.7 -c 'import > sys;print(sys.version)' > 2.7.10 (default, Jul 14 2015, 19:46:27) > [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] > > Any idea what that means for my system? Since the original reply, Apple has updated the version of the OS X 10.10.x system Python 2.7 to 2.7.10. So that looks good. -- Ned Deily, nad at acm.org From jacobchaar at live.ca Sat Sep 26 13:14:44 2015 From: jacobchaar at live.ca (Jacob Chaar) Date: Sat, 26 Sep 2015 13:14:44 -0400 Subject: Python IDLE won't start Message-ID: Hi there, So, I download Python 3.5.0 and I while I execute the Python IDLE, it won't start up. Also, I try to open the python command line and a message error pop up. If you can help me, it will be really appreciate. Regards, Jacob Chaar -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul.hermeneutic at gmail.com Sat Sep 26 14:13:17 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Sat, 26 Sep 2015 12:13:17 -0600 Subject: Failed to upgrade pip in fresh 2.7 install Message-ID: After a fresh install of Python 2.7 32-bit and 64-bit, upgrading pip using pip fails. Am I doing this incorrectly? Any suggestions? C:\Python27-32\Scripts>pip install --upgrade pip You are using pip version 7.0.1, however version 7.1.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting pip Using cached pip-7.1.2-py2.py3-none-any.whl Installing collected packages: pip Found existing installation: pip 7.0.1 Uninstalling pip-7.0.1: Successfully uninstalled pip-7.0.1 Exception: Traceback (most recent call last): File "C:\Python27-32\lib\site-packages\pip\basecommand.py", line 223, in main logger.debug('Exception information:', exc_info=True) File "C:\Python27-32\lib\site-packages\pip\commands\install.py", line 297, in run wb = WheelBuilder( File "C:\Python27-32\lib\site-packages\pip\req\req_set.py", line 633, in install for requirement in to_install: File "C:\Python27-32\lib\site-packages\pip\req\req_install.py", line 734, in commit_uninstall File "C:\Python27-32\lib\site-packages\pip\req\req_uninstall.py", line 153, in commit self.save_dir = None File "C:\Python27-32\lib\site-packages\pip\_vendor\retrying.py", line 49, in wrapped_f return Retrying(*dargs, **dkw).call(f, *args, **kw) File "C:\Python27-32\lib\site-packages\pip\_vendor\retrying.py", line 212, in call raise attempt.get() File "C:\Python27-32\lib\site-packages\pip\_vendor\retrying.py", line 247, in get six.reraise(self.value[0], self.value[1], self.value[2]) File "C:\Python27-32\lib\site-packages\pip\_vendor\retrying.py", line 200, in call attempt = Attempt(fn(*args, **kwargs), attempt_number, False) File "C:\Python27-32\lib\site-packages\pip\utils\__init__.py", line 89, in rmtree shutil.rmtree(dir, ignore_errors=ignore_errors, File "C:\Python27-32\lib\shutil.py", line 247, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python27-32\lib\shutil.py", line 247, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python27-32\lib\shutil.py", line 252, in rmtree onerror(os.remove, fullname, sys.exc_info()) File "C:\Python27-32\lib\site-packages\pip\utils\__init__.py", line 101, in rmtree_errorhandler # use the original function to repeat the operation WindowsError: [Error 5] Access is denied: 'c:\\users\\pwatson\\appdata\\local\\temp\\pip-4nt07e-uninstall\\python27-32\\scripts\\pip.exe' From joel.goldstick at gmail.com Sat Sep 26 14:52:37 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 26 Sep 2015 14:52:37 -0400 Subject: Failed to upgrade pip in fresh 2.7 install In-Reply-To: References: Message-ID: sudo pip ... etc On Sat, Sep 26, 2015 at 2:13 PM, wrote: > After a fresh install of Python 2.7 32-bit and 64-bit, upgrading pip > using pip fails. Am I doing this incorrectly? Any suggestions? > > C:\Python27-32\Scripts>pip install --upgrade pip > You are using pip version 7.0.1, however version 7.1.2 is available. > You should consider upgrading via the 'pip install --upgrade pip' command. > Collecting pip > Using cached pip-7.1.2-py2.py3-none-any.whl > Installing collected packages: pip > Found existing installation: pip 7.0.1 > Uninstalling pip-7.0.1: > Successfully uninstalled pip-7.0.1 > Exception: > Traceback (most recent call last): > File "C:\Python27-32\lib\site-packages\pip\basecommand.py", line 223, in > main > logger.debug('Exception information:', exc_info=True) > File "C:\Python27-32\lib\site-packages\pip\commands\install.py", > line 297, in run > wb = WheelBuilder( > File "C:\Python27-32\lib\site-packages\pip\req\req_set.py", line > 633, in install > for requirement in to_install: > File "C:\Python27-32\lib\site-packages\pip\req\req_install.py", line > 734, in commit_uninstall > > File "C:\Python27-32\lib\site-packages\pip\req\req_uninstall.py", > line 153, in commit > self.save_dir = None > File "C:\Python27-32\lib\site-packages\pip\_vendor\retrying.py", > line 49, in wrapped_f > return Retrying(*dargs, **dkw).call(f, *args, **kw) > File "C:\Python27-32\lib\site-packages\pip\_vendor\retrying.py", > line 212, in call > raise attempt.get() > File "C:\Python27-32\lib\site-packages\pip\_vendor\retrying.py", > line 247, in get > six.reraise(self.value[0], self.value[1], self.value[2]) > File "C:\Python27-32\lib\site-packages\pip\_vendor\retrying.py", > line 200, in call > attempt = Attempt(fn(*args, **kwargs), attempt_number, False) > File "C:\Python27-32\lib\site-packages\pip\utils\__init__.py", line > 89, in rmtree > shutil.rmtree(dir, ignore_errors=ignore_errors, > File "C:\Python27-32\lib\shutil.py", line 247, in rmtree > rmtree(fullname, ignore_errors, onerror) > File "C:\Python27-32\lib\shutil.py", line 247, in rmtree > rmtree(fullname, ignore_errors, onerror) > File "C:\Python27-32\lib\shutil.py", line 252, in rmtree > onerror(os.remove, fullname, sys.exc_info()) > File "C:\Python27-32\lib\site-packages\pip\utils\__init__.py", line > 101, in rmtree_errorhandler > # use the original function to repeat the operation > WindowsError: [Error 5] Access is denied: > > 'c:\\users\\pwatson\\appdata\\local\\temp\\pip-4nt07e-uninstall\\python27-32\\scripts\\pip.exe' > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Sat Sep 26 14:53:24 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 26 Sep 2015 14:53:24 -0400 Subject: Failed to upgrade pip in fresh 2.7 install In-Reply-To: References: Message-ID: On Sat, Sep 26, 2015 at 2:52 PM, Joel Goldstick wrote: > sudo pip ... etc > > On Sat, Sep 26, 2015 at 2:13 PM, wrote: > >> After a fresh install of Python 2.7 32-bit and 64-bit, upgrading pip >> using pip fails. Am I doing this incorrectly? Any suggestions? >> >> C:\Python27-32\Scripts>pip install --upgrade pip >> You are using pip version 7.0.1, however version 7.1.2 is available. >> You should consider upgrading via the 'pip install --upgrade pip' command. >> Collecting pip >> Using cached pip-7.1.2-py2.py3-none-any.whl >> Installing collected packages: pip >> Found existing installation: pip 7.0.1 >> Uninstalling pip-7.0.1: >> Successfully uninstalled pip-7.0.1 >> Exception: >> Traceback (most recent call last): >> File "C:\Python27-32\lib\site-packages\pip\basecommand.py", line 223, >> in main >> logger.debug('Exception information:', exc_info=True) >> File "C:\Python27-32\lib\site-packages\pip\commands\install.py", >> line 297, in run >> wb = WheelBuilder( >> File "C:\Python27-32\lib\site-packages\pip\req\req_set.py", line >> 633, in install >> for requirement in to_install: >> File "C:\Python27-32\lib\site-packages\pip\req\req_install.py", line >> 734, in commit_uninstall >> >> File "C:\Python27-32\lib\site-packages\pip\req\req_uninstall.py", >> line 153, in commit >> self.save_dir = None >> File "C:\Python27-32\lib\site-packages\pip\_vendor\retrying.py", >> line 49, in wrapped_f >> return Retrying(*dargs, **dkw).call(f, *args, **kw) >> File "C:\Python27-32\lib\site-packages\pip\_vendor\retrying.py", >> line 212, in call >> raise attempt.get() >> File "C:\Python27-32\lib\site-packages\pip\_vendor\retrying.py", >> line 247, in get >> six.reraise(self.value[0], self.value[1], self.value[2]) >> File "C:\Python27-32\lib\site-packages\pip\_vendor\retrying.py", >> line 200, in call >> attempt = Attempt(fn(*args, **kwargs), attempt_number, False) >> File "C:\Python27-32\lib\site-packages\pip\utils\__init__.py", line >> 89, in rmtree >> shutil.rmtree(dir, ignore_errors=ignore_errors, >> File "C:\Python27-32\lib\shutil.py", line 247, in rmtree >> rmtree(fullname, ignore_errors, onerror) >> File "C:\Python27-32\lib\shutil.py", line 247, in rmtree >> rmtree(fullname, ignore_errors, onerror) >> File "C:\Python27-32\lib\shutil.py", line 252, in rmtree >> onerror(os.remove, fullname, sys.exc_info()) >> File "C:\Python27-32\lib\site-packages\pip\utils\__init__.py", line >> 101, in rmtree_errorhandler >> # use the original function to repeat the operation >> WindowsError: [Error 5] Access is denied: >> >> 'c:\\users\\pwatson\\appdata\\local\\temp\\pip-4nt07e-uninstall\\python27-32\\scripts\\pip.exe' >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > sorry, you have windows. Do you need to be admin? > > -- > Joel Goldstick > http://joelgoldstick.com > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From zachary.ware+pylist at gmail.com Sat Sep 26 14:59:56 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Sat, 26 Sep 2015 13:59:56 -0500 Subject: Failed to upgrade pip in fresh 2.7 install In-Reply-To: References: Message-ID: On Sat, Sep 26, 2015 at 1:13 PM, wrote: > After a fresh install of Python 2.7 32-bit and 64-bit, upgrading pip > using pip fails. Am I doing this incorrectly? Any suggestions? This is a limitation of Windows: you can't replace the executable that you're currently running. To work around this, do "python -m pip install --upgrade pip" instead. If you have the Python Launcher for Windows installed (included with Python 3.3+), you can use in place of 'python' in that command, and be very sure about which python's pip is being upgraded. -- Zach From souissiroiya94 at gmail.com Sat Sep 26 16:28:39 2015 From: souissiroiya94 at gmail.com (=?ISO-8859-1?Q?Ro=EFya_souissi?=) Date: Sat, 26 Sep 2015 13:28:39 -0700 (PDT) Subject: Python program on induction heating Message-ID: <6e35b1b1-ae5b-433f-a87f-b802f6f56069@googlegroups.com> Hello, I have realized last year a mini project on induction heating and its application onto thermoelectricity. To back up my theoretical work, I created a python program ( I used mainly dictionnaries, PIL library and tkinter library). I have created a personal blog (https://souissiroiya.wordpress.com/) in a bid to publish my future works and projects and his the url to the python program in case you want to check it out (https://souissiroiya.wordpress.com/2015 ... en-python/). Best regards, From jeffvanderdoes at gmail.com Sat Sep 26 17:40:12 2015 From: jeffvanderdoes at gmail.com (Jeff VanderDoes) Date: Sat, 26 Sep 2015 15:40:12 -0600 Subject: Beginning question #compilersetup, #windows7, #vs2010 Message-ID: All, I'm fairly new to Python and was excited to start playing with it until I ran into need to compile some extensions under windows 7 64 bit. I've done some searching but after more hours than I care to count being unsuccessful setting up MS visual studio (2015, 2012, and 2010) with service packs and SDKs I can tell I'm spinning my wheels and going nowhere fast. After trying to search through archives and the net I get some things that are really old or are unique to their situation but just not what I would expect for such a widely used language. Are there any instructions/pointers that someone could point me to to be able to set up visual studio for use with python. I figure I'd just start with 3.5 but have tried under 3.4 and even went back to 2.7 with no luck. I see I'm not the only one with frustration with the error about not find vcvarsall.bat and the like. Thanks for your help! Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at zip.com.au Sat Sep 26 17:43:24 2015 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 27 Sep 2015 07:43:24 +1000 Subject: ConnectionError handling problem In-Reply-To: References: Message-ID: <20150926214324.GA5619@cskk.homeip.net> On 26Sep2015 09:46, Gonzalo V wrote: >Hi Cameron. >i had the same problems and you have to tell to python what to do with the >connect problem. Definitely. That's why we're encouraging him to handle specific exceptions. >try this: >... >except *urllib.error.HTTPError* as e: > if e.getcode()==504: > disp = "SIN RESPUESTA DEL SERVIDOR" #(No answer from the >server) > nombre='' > origen='' > > precioAhora='' > print(e.getcode(),disp) > pass You're aware that the "pass" there does nothing? Perhaps you're considering "continue"? Normally when I write a specific clause like that it looks a bit like this: try this: ... except *urllib.error.HTTPError* as e: if e.getcode()==504: warning("about 504 error...") nombre = '' else: raise This arranges that for _other_ HTTPErrors which I do not correctly handle that the exception is reraised. >greeting from Chile. Sorry my english. Don't apologise. Thank you for working in a second language to accomodate us. I apologise for my Spanish, which is nonexistent :-( Cheers, Cameron Simpson >Saludos, >Gonzalo > >2015-09-25 3:24 GMT-04:00 Cameron Simpson : > >> On 24Sep2015 22:46, shiva upreti wrote: >> >>> On Friday, September 25, 2015 at 10:55:45 AM UTC+5:30, Cameron Simpson >>> wrote: >>> >>>> On 24Sep2015 20:57, shiva upreti wrote: >>>> >Thank you Cameron. >>>> >I think the problem with my code is that it just hangs without raising >>>> any >exceptions. And as mentioned by Laura above that when I press CTRL+C, >>>> it >just catches that exception and prints ConnectionError which is >>>> definitely >a lie in this case as you mentioned. >>>> >>> >> Ok. You original code says: >> >> try: >> r=requests.post(url, data=query_args) >> except: >> print "Connection error" >> >> and presumably we think your code is hanging inside the requests.post >> call? You should probably try to verify that, because if it is elsewhere >> you need to figure out where (lots of print statements is a first start on >> that). >> >> I would open two terminals. Run your program until it hangs in one. >> >> While it is hung, examine the network status. I'll presume you're on a >> UNIX system of some kind, probably Linux? If not it may be harder (or just >> require someone other than me). >> >> If it is hung in the .post call, quite possibly it has an established >> connecion to the target server - maybe that server is hanging. >> >> The shell command: >> >> netstat -rn | fgrep 172.16.68.6 | fgrep 8090 >> >> will show every connection to your server hosting the URL " >> http://172.16.68.6:8090/login.xml". That will tell you if you have a >> connection (if you are the only person doing the connecting from your >> machine). >> >> If you have the "lsof" program (possibly in /usr/sbin, so >> "/usr/sbin/lsof") you can also examine the state of your hung Python >> program. This: >> >> lsof -p 12345 >> >> will report on the open files and network connections of the process with >> pid 12345. Adjust to suit: you can find your program's pid ("process id") >> with the "ps" command, or by backgrounding your program an issuing the >> "jobs" command, which should show the process id more directly. >> >> >> Cheers, >> Cameron Simpson From paul.hermeneutic at gmail.com Sat Sep 26 18:24:25 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Sat, 26 Sep 2015 16:24:25 -0600 Subject: Failed to upgrade pip in fresh 2.7 install In-Reply-To: References: Message-ID: Joel, no need for elevated (Administrator) execution. I did need to follow Zachary's suggestion and it worked well. From joel.goldstick at gmail.com Sat Sep 26 19:30:05 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 26 Sep 2015 19:30:05 -0400 Subject: Failed to upgrade pip in fresh 2.7 install In-Reply-To: References: Message-ID: On Sat, Sep 26, 2015 at 6:24 PM, wrote: > Joel, no need for elevated (Administrator) execution. I did need to > follow Zachary's suggestion and it worked well. > Good result. I'm not up on windows for many years -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From victory.josh.josh24 at gmail.com Sat Sep 26 20:25:26 2015 From: victory.josh.josh24 at gmail.com (Supra1983 Tech) Date: Sat, 26 Sep 2015 17:25:26 -0700 (PDT) Subject: Event Handling Error in Python 3.4.3 Message-ID: <982bf1e2-583b-4fa6-8a7f-7194f0714397@googlegroups.com> I have a python script for a game and the problem is that after running the game, the blocks start falling, but the game over message is not popping up at proper times. Here is my script: import pygame import time import random pygame.init() display_width = 800 display_height = 600 black = (0,0,0) white = (255,255,255) red = (255,0,0) car_width = 45.2 gameDisplay = pygame.display.set_mode((display_width,display_height)) pygame.display.set_caption('pyrace') clock = pygame.time.Clock() carImg = pygame.image.load('theracer 1car.png') def things_saved(count): font = pygame.font.SysFont(None, 25) text = font.render("Saved: "+str(count), True, black) gameDisplay.blit(text,(0,0)) def things(thingx, thingy, thingw, thingh, color): pygame.draw.rect(gameDisplay, color, [thingx, thingy, thingw, thingh]) def car(x,y): gameDisplay.blit(carImg,(x,y)) def text_objects(text, font): textSurface = font.render(text, True, black) return textSurface, textSurface.get_rect() def message_display(text): largeText = pygame.font.Font('freesansbold.ttf', 115) TextSurf, TextRect = text_objects(text, largeText) TextRect.center = ((display_width/2), (display_height/2)) gameDisplay.blit(TextSurf, TextRect) pygame.display.update() time.sleep(2) game_loop() def crash(): message_display('Game Over') def game_loop(): x = (display_width * 0.45) y = (display_height * 0.45) x_change = 0 thing_startx = random.randrange(0, display_width) thing_starty = -300 thing_speed = 7 thing_width = 100 thing_height = 100 saved = 0 gameExit = False while not gameExit: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: x_change = -5 elif event.key == pygame.K_RIGHT: x_change = 5 if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: x_change = 0 x += x_change gameDisplay.fill(white) #things(thingx, thingy, thingw, thingh, color) things(thing_startx, thing_starty, thing_width, thing_height, black) thing_starty += thing_speed car(x,y) things_saved(saved) if x > display_width - car_width or x < 0: crash() if thing_starty > display_height: thing_starty = 0 - thing_height thing_startx = random.randrange(0,display_width) saved += 1 if y < thing_starty+thing_height: if x > thing_startx and x < thing_startx + thing_width or x+car_width > thing_startx and x + car_width < thing_startx + thing_width: print('cross') crash() pygame.display.update() clock.tick(60) game_loop() pygame.quit() quit() From steve at pearwood.info Sat Sep 26 21:32:26 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 27 Sep 2015 11:32:26 +1000 Subject: Python program on induction heating References: <6e35b1b1-ae5b-433f-a87f-b802f6f56069@googlegroups.com> Message-ID: <5607472a$0$1592$c3e8da3$5496439d@news.astraweb.com> Hi, and welcome, On Sun, 27 Sep 2015 06:28 am, Ro?ya souissi wrote: > Hello, > I have realized last year a mini project on induction heating and its > application onto thermoelectricity. To back up my theoretical work, I > created a python program ( I used mainly dictionnaries, PIL library and > tkinter library). I have created a personal blog > (https://souissiroiya.wordpress.com/) in a bid to publish my future works > and projects and his the url to the python program in case you want to > check it out (https://souissiroiya.wordpress.com/2015 ... en-python/). Unfortunately that second link is broken and I don't understand enough French to find it from the home page. -- Steven From python at mrabarnett.plus.com Sat Sep 26 22:18:02 2015 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 27 Sep 2015 03:18:02 +0100 Subject: Python program on induction heating In-Reply-To: <5607472a$0$1592$c3e8da3$5496439d@news.astraweb.com> References: <6e35b1b1-ae5b-433f-a87f-b802f6f56069@googlegroups.com> <5607472a$0$1592$c3e8da3$5496439d@news.astraweb.com> Message-ID: <560751DA.2080304@mrabarnett.plus.com> On 2015-09-27 02:32, Steven D'Aprano wrote: > Hi, and welcome, > > On Sun, 27 Sep 2015 06:28 am, Ro?ya souissi wrote: > >> Hello, >> I have realized last year a mini project on induction heating and its >> application onto thermoelectricity. To back up my theoretical work, I >> created a python program ( I used mainly dictionnaries, PIL library and >> tkinter library). I have created a personal blog >> (https://souissiroiya.wordpress.com/) in a bid to publish my future works >> and projects and his the url to the python program in case you want to >> check it out (https://souissiroiya.wordpress.com/2015 ... en-python/). > > Unfortunately that second link is broken and I don't understand enough > French to find it from the home page. > > > You don't know what "Impl?mentation en Python" means? Couldn't you make a guess? :-) https://souissiroiya.wordpress.com/2015/09/23/implementation-en-python/ From gordon at panix.com Sat Sep 26 23:45:52 2015 From: gordon at panix.com (John Gordon) Date: Sun, 27 Sep 2015 03:45:52 +0000 (UTC) Subject: Django (Python Web Framework) Tutorial References: <1421a34f-d8cc-4367-adab-2c2b46504d72@googlegroups.com> Message-ID: In <1421a34f-d8cc-4367-adab-2c2b46504d72 at googlegroups.com> Cai Gengyang writes: > Question : I am a little confused about the last paragraph : What exactly > is a "directory outside of the document root, such as /home/mycode." and > how do you "Put your code in this directory" ? Django is a web application framework. So, you have to use it together with a web server. The "document root" is the directory where the web server expects to find files to be served as web pages. You said you put the Django project code in a subdirectory of your home directory. That should be fine. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From gengyangcai at gmail.com Sun Sep 27 00:12:21 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sat, 26 Sep 2015 21:12:21 -0700 (PDT) Subject: Django (Python Web Framework) Tutorial In-Reply-To: References: <1421a34f-d8cc-4367-adab-2c2b46504d72@googlegroups.com> Message-ID: <2835a1b1-e5f7-4ff7-b318-c0ebdd0f6d98@googlegroups.com> On Sunday, September 27, 2015 at 11:46:13 AM UTC+8, John Gordon wrote: > In <1421a34f-d8cc-4367-adab-2c2b46504d72 at googlegroups.com> Cai Gengyang writes: > > > Question : I am a little confused about the last paragraph : What exactly > > is a "directory outside of the document root, such as /home/mycode." and > > how do you "Put your code in this directory" ? > > Django is a web application framework. So, you have to use it together with > a web server. The "document root" is the directory where the web server > expects to find files to be served as web pages. > > You said you put the Django project code in a subdirectory of your home > directory. That should be fine. > > -- > John Gordon A is for Amy, who fell down the stairs > gordon at panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" Ok. As for the next chapter(Database setup), I opened up mysite/settings.py as per the instructions on the Django tutorial. However, when I try to run the following command : $ python manage.py migrate to create the tables in the database, CaiGengYangs-MacBook-Pro:Weiqi CaiGengYang$ python manage.py migrate ---- input I get the following error message : /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'manage.py': [Errno 2] No such file or directory ---- output Any idea how to solve this issue? Thanks a lot ! Gengyang From eryksun at gmail.com Sun Sep 27 00:23:29 2015 From: eryksun at gmail.com (eryksun) Date: Sat, 26 Sep 2015 23:23:29 -0500 Subject: Failed to upgrade pip in fresh 2.7 install In-Reply-To: References: Message-ID: On 9/26/15, Zachary Ware wrote: > On Sat, Sep 26, 2015 at 1:13 PM, wrote: >> After a fresh install of Python 2.7 32-bit and 64-bit, upgrading pip >> using pip fails. Am I doing this incorrectly? Any suggestions? > > This is a limitation of Windows: you can't replace the executable that > you're currently running. A memory-mapped file can be renamed, so replacing the executable is doable. The new name has to be on the same volume. That's doable. The problem is that Windows doesn't allow deleting the file. Maybe pip could spawn a clean-up script to which it pipes the list of renamed files. The script waits for pip to exit and then tries to remove the files. From gengyangcai at gmail.com Sun Sep 27 03:32:21 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sun, 27 Sep 2015 00:32:21 -0700 (PDT) Subject: Django Tutorial (Database setup) Question Message-ID: Hello all ! So I am going through the (Database setup) chapter of this tutorial (https://docs.djangoproject.com/en/1.8/intro/tutorial01/) --- Its the section right after the first chapter on "Creating a project" I opened up mysite/settings.py as per the instructions on the Django tutorial. However, when I try to run the following command : $ python manage.py migrate to create the tables in the database, CaiGengYangs-MacBook-Pro:Weiqi CaiGengYang$ python manage.py migrate ---- input I get the following error message : /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'manage.py': [Errno 2] No such file or directory ---- output Any idea how to solve this issue? Thanks a lot ! Gengyang From gengyangcai at gmail.com Sun Sep 27 08:03:23 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sun, 27 Sep 2015 05:03:23 -0700 (PDT) Subject: Python IDLE won't start In-Reply-To: References: Message-ID: On Sunday, September 27, 2015 at 4:41:54 PM UTC+8, Jacob Chaar wrote: > Hi there, > > So, I download Python 3.5.0 and I while I execute the Python IDLE, it won't start up. Also, I try to open the python command line and a message error pop up. > > If you can help me, it will be really appreciate. > > Regards, > Jacob Chaar It worked for me ... Step 1 : Download Python 3.5 from here --- https://www.python.org/downloads/ Step 2 : Install it Step 3 : Click on the 'IDLE' button --- for me , I am using a Mac so I click on 'Finder', then type IDLE in the search field on the top right corner of the 'Finder'. Step 4 : Click on the IDLE and it opens up, a happy looking 'Python 3.5.0' shell there. There is however a warning that this version may be unstable. However, I am able to execute commands on it like 1 + 2 = 3 From none at mailinator.com Sun Sep 27 08:48:20 2015 From: none at mailinator.com (mm0fmf) Date: Sun, 27 Sep 2015 13:48:20 +0100 Subject: Python IDLE won't start In-Reply-To: References: Message-ID: On 26/09/2015 18:14, Jacob Chaar wrote: > Hi there, > > So, I download Python 3.5.0 and I while I execute the Python IDLE, it > won?t start up. Also, I try to open the python command line and a > message error pop up. > > If you can help me, it will be really appreciate. > > Regards, > > Jacob Chaar > Maybe if you told us the error (cut & paste it, don't retype it) we could help? Similarly knowing the OS you are using would help. Without that info how can anyone help you? From lac at openend.se Sun Sep 27 08:56:27 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 27 Sep 2015 14:56:27 +0200 Subject: Python IDLE won't start In-Reply-To: References: Message-ID: <201509271256.t8RCuRGs008243@fido.openend.se> In a message of Sat, 26 Sep 2015 13:14:44 -0400, Jacob Chaar writes: >Hi there, > > > >So, I download Python 3.5.0 and I while I execute the Python IDLE, it won't >start up. Also, I try to open the python command line and a message error >pop up. > > > >If you can help me, it will be really appreciate. > > > >Regards, > >Jacob Chaar > > >-- >https://mail.python.org/mailman/listinfo/python-list > What OS are you running under? Just just typing python in the command window work? What about python3? If they work, so you have a python run 'python -m idlelib' in the command window. This should give you an error message. Paste it in here and we will see what we can do. Laura From tjreedy at udel.edu Sun Sep 27 09:22:44 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 27 Sep 2015 09:22:44 -0400 Subject: Python IDLE won't start In-Reply-To: References: Message-ID: On 9/27/2015 8:03 AM, Cai Gengyang wrote: > Step 1 : Download Python 3.5 from here --- > https://www.python.org/downloads/ Step 2 : Install it Step 3 : Click > on the 'IDLE' button --- for me , I am using a Mac so I click on > 'Finder', then type IDLE in the search field on the top right corner > of the 'Finder'. > Step 4 : Click on the IDLE and it opens up, a happy > looking 'Python 3.5.0' shell there. There is however a warning that > this version may be unstable. The warning is about the Apple-supplied version of tcl/tk, not about Idle. Any tkinter program could have a problem. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Sun Sep 27 11:00:14 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 27 Sep 2015 16:00:14 +0100 Subject: Beginning question #compilersetup, #windows7, #vs2010 In-Reply-To: References: Message-ID: On 26/09/2015 22:40, Jeff VanderDoes wrote: > All, > > I'm fairly new to Python and was excited to start playing with it until > I ran into need to compile some extensions under windows 7 64 bit. I've > done some searching but after more hours than I care to count being > unsuccessful setting up MS visual studio (2015, 2012, and 2010) with > service packs and SDKs I can tell I'm spinning my wheels and going > nowhere fast. > > After trying to search through archives and the net I get some things > that are really old or are unique to their situation but just not what I > would expect for such a widely used language. > > Are there any instructions/pointers that someone could point me to to be > able to set up visual studio for use with python. I figure I'd just > start with 3.5 but have tried under 3.4 and even went back to 2.7 with > no luck. I see I'm not the only one with frustration with the error > about not find vcvarsall.bat and the like. > > Thanks for your help! > > Jeff > > https://docs.python.org/devguide/setup.html#windows -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From joel.goldstick at gmail.com Sun Sep 27 12:08:32 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 27 Sep 2015 12:08:32 -0400 Subject: Django Tutorial (Database setup) Question In-Reply-To: References: Message-ID: On Sun, Sep 27, 2015 at 3:32 AM, Cai Gengyang wrote: > Hello all ! > > So I am going through the (Database setup) chapter of this tutorial ( > https://docs.djangoproject.com/en/1.8/intro/tutorial01/) --- Its the > section right after the first chapter on "Creating a project" > > I opened up mysite/settings.py as per the instructions on the Django > tutorial. > > However, when I try to run the following command : $ python manage.py > migrate to create the tables in the database, > > CaiGengYangs-MacBook-Pro:Weiqi CaiGengYang$ python manage.py migrate ---- > input > > I get the following error message : > > /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: > can't open file 'manage.py': [Errno 2] No such file or directory ---- output > > Any idea how to solve this issue? > > Thanks a lot ! > > You need to be in the directory that contains manage.py > Gengyang > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From gengyangcai at gmail.com Sun Sep 27 12:18:29 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 28 Sep 2015 00:18:29 +0800 Subject: Django Tutorial (Database setup) Question In-Reply-To: References: Message-ID: I believe I am already in the same directory that contains manage.py , but I still get an error (a syntax error). Checked the lines in settings.py and can't find anything wrong with them either. Posted my entire code below : CaiGengYangs-MacBook-Pro:~ CaiGengYang$ cd mysite folder CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ ls manage.py mysite CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ python manage.py migrate Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line utility.execute() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute settings.INSTALLED_APPS File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__ self._setup(name) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup self._wrapped = Settings(settings_module) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/Users/CaiGengYang/mysite/mysite/settings.py", line 45 'django.middleware.csrf.CsrfViewMiddleware', ^ SyntaxError: invalid syntax CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ On Mon, Sep 28, 2015 at 12:08 AM, Joel Goldstick wrote: > > > On Sun, Sep 27, 2015 at 3:32 AM, Cai Gengyang > wrote: > >> Hello all ! >> >> So I am going through the (Database setup) chapter of this tutorial ( >> https://docs.djangoproject.com/en/1.8/intro/tutorial01/) --- Its the >> section right after the first chapter on "Creating a project" >> >> I opened up mysite/settings.py as per the instructions on the Django >> tutorial. >> >> However, when I try to run the following command : $ python manage.py >> migrate to create the tables in the database, >> >> CaiGengYangs-MacBook-Pro:Weiqi CaiGengYang$ python manage.py migrate ---- >> input >> >> I get the following error message : >> >> /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: >> can't open file 'manage.py': [Errno 2] No such file or directory ---- output >> >> Any idea how to solve this issue? >> >> Thanks a lot ! >> >> You need to be in the directory that contains manage.py > >> Gengyang >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Joel Goldstick > http://joelgoldstick.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gengyangcai at gmail.com Sun Sep 27 12:19:46 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sun, 27 Sep 2015 09:19:46 -0700 (PDT) Subject: Django Tutorial (Database setup) Question In-Reply-To: References: Message-ID: I believe I am already in the same directory that contains manage.py , but I still get an error (a syntax error). Checked the lines in settings.py and can't find anything wrong with them either. Posted my entire code below : CaiGengYangs-MacBook-Pro:~ CaiGengYang$ cd mysite folder CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ ls manage.py mysite CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ python manage.py migrate Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line utility.execute() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute settings.INSTALLED_APPS File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__ self._setup(name) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup self._wrapped = Settings(settings_module) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/Users/CaiGengYang/mysite/mysite/settings.py", line 45 'django.middleware.csrf.CsrfViewMiddleware', ^ SyntaxError: invalid syntax CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ On Monday, September 28, 2015 at 12:09:04 AM UTC+8, Joel Goldstick wrote: > On Sun, Sep 27, 2015 at 3:32 AM, Cai Gengyang wrote: > Hello all ! > > > > So I am going through the (Database setup) chapter of this tutorial (https://docs.djangoproject.com/en/1.8/intro/tutorial01/) --- Its the section right after the first chapter on "Creating a project" > > > > I opened up mysite/settings.py as per the instructions on the Django tutorial. > > > > However, when I try to run the following command : $ python manage.py migrate to create the tables in the database, > > > > CaiGengYangs-MacBook-Pro:Weiqi CaiGengYang$ python manage.py migrate ---- input > > > > I get the following error message : > > > > /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'manage.py': [Errno 2] No such file or directory ---- output > > > > Any idea how to solve this issue? > > > > Thanks a lot ! > > > > You need to be in the directory that contains manage.py? > Gengyang > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > > > -- > > > > Joel Goldstick > http://joelgoldstick.com From gengyangcai at gmail.com Sun Sep 27 13:45:48 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sun, 27 Sep 2015 10:45:48 -0700 (PDT) Subject: Help with Debugging Message-ID: http://pastebin.com/RWt1mp7F --- If anybody can find any errors with this settings.py file, let me know ! Can't seem to find anything wrong with it ... From kwpolska at gmail.com Sun Sep 27 13:51:02 2015 From: kwpolska at gmail.com (Chris Warrick) Date: Sun, 27 Sep 2015 19:51:02 +0200 Subject: Fwd: Django Tutorial (Database setup) Question In-Reply-To: References: Message-ID: Forwarding to list (forgot about this stupid reply all thing, sorry). ---------- Forwarded message ---------- From: Chris Warrick Date: 27 September 2015 at 19:50 Subject: Re: Django Tutorial (Database setup) Question To: Cai Gengyang On 27 September 2015 at 19:39, Cai Gengyang wrote: > http://pastebin.com/index/RWt1mp7F ---- Looking through my code , can't seem > to find any errors yet. All the parentheses seem to be in place too, this is > weird ... > > On Mon, Sep 28, 2015 at 1:01 AM, Chris Warrick wrote: >> >> On 27 September 2015 at 18:18, Cai Gengyang wrote: >> > I believe I am already in the same directory that contains manage.py , >> > but I >> > still get an error (a syntax error). Checked the lines in settings.py >> > and >> > can't find anything wrong with them either. Posted my entire code below >> > : >> >> > File "/Users/CaiGengYang/mysite/mysite/settings.py", line 45 >> > 'django.middleware.csrf.CsrfViewMiddleware', >> > ^ >> > SyntaxError: invalid syntax >> >> There?s a typo on or before line 45. Pastebin your full settings.py >> file, and try looking for errors (like missing parentheses) yourself. >> >> -- >> Chris Warrick >> PGP: 5EAAEA16 > > On further inspection, this might be a Django or Python problem? try re-installing Django. I don?t really know what could be wrong here. -- Chris Warrick PGP: 5EAAEA16 From eryksun at gmail.com Sun Sep 27 16:10:17 2015 From: eryksun at gmail.com (eryksun) Date: Sun, 27 Sep 2015 15:10:17 -0500 Subject: Beginning question #compilersetup, #windows7, #vs2010 In-Reply-To: References: Message-ID: On Sat, Sep 26, 2015 at 4:40 PM, Jeff VanderDoes wrote: > > I'm fairly new to Python and was excited to start playing with it until I > ran into need to compile some extensions under windows 7 64 bit. I've done > some searching but after more hours than I care to count being unsuccessful > setting up MS visual studio (2015, 2012, and 2010) with service packs and > SDKs I can tell I'm spinning my wheels and going nowhere fast. For 3.5 you should be able to just install Visual Studio 2015 Community Edition. This is the current release of Visual Studio, so if you encounter problems, at least finding help won't be one of them. 2.7 is built with VS 2008, which is no longer supported. But, thanks to Steve Dower, Microsoft distributes an unsupported version for building Python 2.7 extension modules [1]. 3.4 is built with the fairly old VS 2010, for which the free Express edition is no longer available. But you should be able to configure a command-line build environment. Install the Windows SDK 7.1 [2] and the VC++ 2010 SP1 Compiler Update [3]. Then run the Windows SDK 7.1 Command Prompt [4], and enter SetEnv /Release /x64 If you plan to do native debugging outside of Visual Studio, install the Debugging Tools for Windows [5] when installing the SDK. You can download public debug symbols for operating system components using Microsoft's symbol server. To do this, create a "C:\Symbols" directory, and set the following environment variable: _NT_SYMBOL_PATH=symsrv*symsrv.dll*C:\Symbols*http://msdl.microsoft.com/download/symbols Additionally you'll need Python's debug symbols, such as for 64-bit 3.4.3 [6]. I typically copy a PDB next to its related DLL/EXE. This is what 3.5's installer does when you select the option to install debug symbols (nice job, Steve!). You can also unzip the PDBs to a directory that's in _NT_SYMBOL_PATH, or update the symbol path dynamically using .sympath+ and .reload [7]. [1]: https://www.microsoft.com/en-us/download/details.aspx?id=44266 [2]: https://www.microsoft.com/en-us/download/details.aspx?id=8279 [3]: https://www.microsoft.com/en-us/download/details.aspx?id=4422 [4]: https://msdn.microsoft.com/en-us/library/ff660764 [5]: https://msdn.microsoft.com/en-us/library/ff551063 [6]: https://www.python.org/ftp/python/3.4.3/python-3.4.3.amd64-pdb.zip [7]: https://msdn.microsoft.com/en-us/library/ff565407 From paul.anton.letnes at gmail.com Sun Sep 27 16:14:47 2015 From: paul.anton.letnes at gmail.com (paul.anton.letnes at gmail.com) Date: Sun, 27 Sep 2015 13:14:47 -0700 (PDT) Subject: PY3.5 and nnumpy and scipy installation problem In-Reply-To: References: Message-ID: Easiest way of installing is removing the python you've installed already and installing continuum's anaconda python 3.x (for x = 4 or 5). It has "batteries included" - numpy, scipy and many others! Paul From paul.anton.letnes at gmail.com Sun Sep 27 16:17:26 2015 From: paul.anton.letnes at gmail.com (paul.anton.letnes at gmail.com) Date: Sun, 27 Sep 2015 13:17:26 -0700 (PDT) Subject: PY3.5 and nnumpy and scipy installation problem In-Reply-To: References: Message-ID: <523eaaa9-bf1a-4994-b6e9-f42ebf0f01fd@googlegroups.com> I'll heartily recommend anaconda python. It's got everything you need prepackaged. Remove what you installed before. Cheers Pauk From paul.hermeneutic at gmail.com Sun Sep 27 17:05:37 2015 From: paul.hermeneutic at gmail.com (paul.hermeneutic at gmail.com) Date: Sun, 27 Sep 2015 15:05:37 -0600 Subject: Interacting with a web site, which lib? Message-ID: Does anyone have an opinion on the relative merits of using the following packages to interact with web sites? Mechanize - cannot run under Python 3 Requests Robobrowser From tundra at bogus-city.tundraware.com Sun Sep 27 17:20:46 2015 From: tundra at bogus-city.tundraware.com (Tim Daneliuk) Date: Sun, 27 Sep 2015 16:20:46 -0500 Subject: Are There Known Problems With tkinter And VPS Servers? Message-ID: I am the author of https://www.tundraware.com/Software/twander, a cross platform, macro- programmable file manager written in python/tkinter. Of late, I am seeing core dumps of this program (which has been stable/mature for some years) but only on VPS servers, both FreeBSD 10 and CentOS 6/7. Is there are know problem here and/or can anyone suggest and approach to isolate the fault? Thanks From tundra at bogus-city.tundraware.com Sun Sep 27 17:31:59 2015 From: tundra at bogus-city.tundraware.com (Tim Daneliuk) Date: Sun, 27 Sep 2015 16:31:59 -0500 Subject: Are There Known Problems With tkinter And VPS Servers? In-Reply-To: References: Message-ID: On 09/27/2015 04:20 PM, Tim Daneliuk wrote: > I am the author of https://www.tundraware.com/Software/twander, a cross platform, macro- > programmable file manager written in python/tkinter. > > Of late, I am seeing core dumps of this program (which has been stable/mature for some > years) but only on VPS servers, both FreeBSD 10 and CentOS 6/7. > > Is there are know problem here and/or can anyone suggest and approach to isolate the > fault? > > Thanks > Correction: It dumps core on FreeBSD 10.2 but on CentOS 6 I get: Traceback (most recent call last): File "/usr/local/TundraWare/bin/twander.py", line 5464, in UI = twanderUI(UIroot) File "/usr/local/TundraWare/bin/twander.py", line 2152, in __init__ self.CmdBtn = Menubutton(self.mBar, text=COMMANDMENU, underline=0, state=DISABLED) File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 2710, in __init__ Widget.__init__(self, master, 'menubutton', cnf, kw) File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 1932, in __init__ (widgetName, self._w) + extra + self._options(cnf)) _tkinter.TclError This code runs fine on physical FreeBSD/CentOS/Debian servers, Rasperberry PIs running Raspbian, OSX, VirtualBox and VMware Workstation Linux servers, Windows .... so I suspect this is somehow VPS related but not sure where to start. From lac at openend.se Sun Sep 27 17:58:47 2015 From: lac at openend.se (Laura Creighton) Date: Sun, 27 Sep 2015 23:58:47 +0200 Subject: Interacting with a web site, which lib? In-Reply-To: References: Message-ID: <201509272158.t8RLwlg2014152@fido.openend.se> In a message of Sun, 27 Sep 2015 15:05:37 -0600, paul.hermeneutic at gmail.com wri tes: >Does anyone have an opinion on the relative merits of using the >following packages to interact with web sites? > >Mechanize - cannot run under Python 3 >Requests >Robobrowser I don't know anything about mechanize or robobrowser. Requests is great stuff. Test it with responses https://github.com/getsentry/responses Laura From gvm2121 at gmail.com Sun Sep 27 18:16:07 2015 From: gvm2121 at gmail.com (Gonzalo V) Date: Sun, 27 Sep 2015 18:16:07 -0400 Subject: Interacting with a web site, which lib? In-Reply-To: <201509272158.t8RLwlg2014152@fido.openend.se> References: <201509272158.t8RLwlg2014152@fido.openend.se> Message-ID: I am working with selenium for.python. easy and powerful saludos, desde un m?vil. El sep 27, 2015 6:01 p.m., "Laura Creighton" escribi?: > In a message of Sun, 27 Sep 2015 15:05:37 -0600, > paul.hermeneutic at gmail.com wri > tes: > >Does anyone have an opinion on the relative merits of using the > >following packages to interact with web sites? > > > >Mechanize - cannot run under Python 3 > >Requests > >Robobrowser > > I don't know anything about mechanize or robobrowser. > Requests is great stuff. Test it with responses > https://github.com/getsentry/responses > > Laura > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gvm2121 at gmail.com Sun Sep 27 18:20:09 2015 From: gvm2121 at gmail.com (Gonzalo V) Date: Sun, 27 Sep 2015 18:20:09 -0400 Subject: Interacting with a web site, which lib? In-Reply-To: References: <201509272158.t8RLwlg2014152@fido.openend.se> Message-ID: Selenium https://selenium-python.readthedocs.org/ i used pip for install it. Saludos, Gonzalo 2015-09-27 18:16 GMT-04:00 Gonzalo V : > I am working with selenium for.python. easy and powerful > > saludos, > desde un m?vil. > El sep 27, 2015 6:01 p.m., "Laura Creighton" escribi?: > >> In a message of Sun, 27 Sep 2015 15:05:37 -0600, >> paul.hermeneutic at gmail.com wri >> tes: >> >Does anyone have an opinion on the relative merits of using the >> >following packages to interact with web sites? >> > >> >Mechanize - cannot run under Python 3 >> >Requests >> >Robobrowser >> >> I don't know anything about mechanize or robobrowser. >> Requests is great stuff. Test it with responses >> https://github.com/getsentry/responses >> >> Laura >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Sun Sep 27 18:29:12 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 27 Sep 2015 15:29:12 -0700 Subject: Are There Known Problems With tkinter And VPS Servers? References: Message-ID: <87y4fra43r.fsf@jester.gateway.sonic.net> Tim Daneliuk writes: > this is somehow VPS related but not sure where to start. How are you expecting tkinter to work on a vps, when there is no window system? It wouldn't surprise me if tk is crashing. From tjreedy at udel.edu Sun Sep 27 19:32:42 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 27 Sep 2015 19:32:42 -0400 Subject: Are There Known Problems With tkinter And VPS Servers? In-Reply-To: References: Message-ID: On 9/27/2015 5:31 PM, Tim Daneliuk wrote: >> Of late, I am seeing core dumps of this program (which has been stable/mature for some >> years) but only on VPS servers, both FreeBSD 10 and CentOS 6/7. > Correction: It dumps core on FreeBSD 10.2 Dumping core when there is no terminal server, instead of exiting gracefully, might be considered a bug. > but on CentOS 6 I get: > > Traceback (most recent call last): > File "/usr/local/TundraWare/bin/twander.py", line 5464, in > UI = twanderUI(UIroot) > File "/usr/local/TundraWare/bin/twander.py", line 2152, in __init__ > self.CmdBtn = Menubutton(self.mBar, text=COMMANDMENU, underline=0, state=DISABLED) > File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 2710, in __init__ > Widget.__init__(self, master, 'menubutton', cnf, kw) > File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 1932, in __init__ > (widgetName, self._w) + extra + self._options(cnf)) > _tkinter.TclError Beside Paul's comment, I suggest running with 2.7.latest and tk 8.6.latest if at all possible to get tkinter and tk bug fixed. Also, Menubutton is considered obsolete for Window level menus, so it may not be maintained as well. Just use Menu if at all possible. -- Terry Jan Reedy From no.email at nospam.invalid Sun Sep 27 19:55:38 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 27 Sep 2015 16:55:38 -0700 Subject: Are There Known Problems With tkinter And VPS Servers? References: Message-ID: <87twqfa03p.fsf@jester.gateway.sonic.net> Terry Reedy writes: > Dumping core when there is no terminal server, instead of exiting > gracefully, might be considered a bug. I wonder if it's a missing or wrong .so since there's no X and maybe no X libraries. That might lead to a crash. From tjreedy at udel.edu Sun Sep 27 19:57:34 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 27 Sep 2015 19:57:34 -0400 Subject: python.org bugs Message-ID: 1. No easy way to report bugs "Submit Website Bugs" takes me to https://github.com/python/pythondotorg/issues which wants me to get an account and login, even to report a typo, or in this case, a dead link. I won't do that. For bugs.python.org, one can report bugs here and someone who agree might file a bug. Anyone here with github account? 2. https://github.com/python/pythondotorg/issues links 'Grail' to grail.python.org, which seems to have been removed. 3. The site does not run link checks to find things like this itself. -- Terry Jan Reedy From steve at pearwood.info Sun Sep 27 20:10:08 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 28 Sep 2015 10:10:08 +1000 Subject: Help with Debugging References: Message-ID: <56088562$0$1585$c3e8da3$5496439d@news.astraweb.com> On Mon, 28 Sep 2015 03:45 am, Cai Gengyang wrote: > http://pastebin.com/RWt1mp7F --- If anybody can find any errors with this > settings.py file, let me know ! > > Can't seem to find anything wrong with it ... Perhaps there is nothing wrong with it. What makes you think that there is? Do you get an exception? If so, the exception will tell you where to start: read the error message, look at the line it says the error occurred at, and fix the problem. If you need help, COPY and PASTE the *entire* traceback, starting from the line "Traceback (most recent call last)" to the error message at the end, and send it to us. -- Steven From rosuav at gmail.com Sun Sep 27 20:38:12 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 28 Sep 2015 10:38:12 +1000 Subject: python.org bugs In-Reply-To: References: Message-ID: On Mon, Sep 28, 2015 at 9:57 AM, Terry Reedy wrote: > 1. No easy way to report bugs "Submit Website Bugs" takes me to > https://github.com/python/pythondotorg/issues > which wants me to get an account and login, even to report a typo, or in > this case, a dead link. I won't do that. > > For bugs.python.org, one can report bugs here and someone who agree might > file a bug. Anyone here with github account? Sure, I'll file a bug for you. So far, though, this is no different from pretty much any tracker I know of, except that github's tracker requires a github account as opposed to a specific-to-the-python-tracker account. What's the issue, precisely? > 2. https://github.com/python/pythondotorg/issues > links 'Grail' to grail.python.org, which seems to have been removed. Presumably this, but I don't follow. ChrisA From tundra at bogus-city.tundraware.com Sun Sep 27 22:33:08 2015 From: tundra at bogus-city.tundraware.com (Tim Daneliuk) Date: Sun, 27 Sep 2015 21:33:08 -0500 Subject: Are There Known Problems With tkinter And VPS Servers? In-Reply-To: References: Message-ID: <5608A6E4.7090100@bogus-city.tundraware.com> On 09/27/2015 06:32 PM, Terry Reedy wrote: > On 9/27/2015 5:31 PM, Tim Daneliuk wrote: > >>> Of late, I am seeing core dumps of this program (which has been stable/mature for some >>> years) but only on VPS servers, both FreeBSD 10 and CentOS 6/7. > >> Correction: It dumps core on FreeBSD 10.2 > > Dumping core when there is no terminal server, instead of exiting gracefully, might be considered a bug. > >> but on CentOS 6 I get: >> >> Traceback (most recent call last): >> File "/usr/local/TundraWare/bin/twander.py", line 5464, in >> UI = twanderUI(UIroot) >> File "/usr/local/TundraWare/bin/twander.py", line 2152, in __init__ >> self.CmdBtn = Menubutton(self.mBar, text=COMMANDMENU, underline=0, state=DISABLED) >> File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 2710, in __init__ >> Widget.__init__(self, master, 'menubutton', cnf, kw) >> File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 1932, in __init__ >> (widgetName, self._w) + extra + self._options(cnf)) >> _tkinter.TclError > > Beside Paul's comment, I suggest running with 2.7.latest and tk 8.6.latest if at all possible to get tkinter and tk bug fixed. > > Also, Menubutton is considered obsolete for Window level menus, so it may not be maintained as well. Just use Menu if at all possible. > Unfortunately, CentOS tracks the corresponding RHEL component versions pretty much exactly (that's sort of the point). Moreover, this exact OS release level works flawlessly in other kinds of VMs and physical instances. From tundra at bogus-city.tundraware.com Sun Sep 27 22:37:12 2015 From: tundra at bogus-city.tundraware.com (Tim Daneliuk) Date: Sun, 27 Sep 2015 21:37:12 -0500 Subject: Are There Known Problems With tkinter And VPS Servers? In-Reply-To: <87y4fra43r.fsf@jester.gateway.sonic.net> References: <87y4fra43r.fsf@jester.gateway.sonic.net> Message-ID: On 09/27/2015 05:29 PM, Paul Rubin wrote: > Tim Daneliuk writes: >> this is somehow VPS related but not sure where to start. > > How are you expecting tkinter to work on a vps, when there is no window > system? It wouldn't surprise me if tk is crashing. > You may have heard about this thing called X Windows and this other thing called ssh that easily permit VPS instances to run GUI code while displaying things on a remote X server. P.S. X applications like xterm work flawlessly on the hosts in question. P.P.S. You might want to dial down the snark, particularly since you seem to be unfamiliar with the basics here. From rosuav at gmail.com Sun Sep 27 22:44:49 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 28 Sep 2015 12:44:49 +1000 Subject: Are There Known Problems With tkinter And VPS Servers? In-Reply-To: References: <87y4fra43r.fsf@jester.gateway.sonic.net> Message-ID: On Mon, Sep 28, 2015 at 12:37 PM, Tim Daneliuk wrote: > You may have heard about this thing called X Windows and this other thing called > ssh that easily permit VPS instances to run GUI code while displaying things > on a remote X server. I'd still be curious about the possibility of a missing/broken .so file somewhere. On systems that don't have their own displays, stuff can be missing or broken and nobody would notice. What happens if you strace the thing? Are there any obvious issues with what it's loading up? ChrisA From tjreedy at udel.edu Sun Sep 27 23:54:20 2015 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 27 Sep 2015 23:54:20 -0400 Subject: python.org bugs In-Reply-To: References: Message-ID: On 9/27/2015 8:38 PM, Chris Angelico wrote: > What's the issue, precisely? > >> 2. https://github.com/python/pythondotorg/issues Sorry, this page https://www.python.org/doc/essays/omg-darpa-mcc-position/ at "Python has been used to implement a web browser (Grail). " >> links 'Grail' to grail.python.org, which seems to have been removed. -- Terry Jan Reedy From rosuav at gmail.com Mon Sep 28 00:04:47 2015 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 28 Sep 2015 14:04:47 +1000 Subject: python.org bugs In-Reply-To: References: Message-ID: On Mon, Sep 28, 2015 at 1:54 PM, Terry Reedy wrote: > Sorry, this page > https://www.python.org/doc/essays/omg-darpa-mcc-position/ > at "Python has been used to implement a web browser (Grail). " Got it, thanks. https://github.com/python/pythondotorg/issues/828 ChrisA From jeffvanderdoes at gmail.com Mon Sep 28 00:09:23 2015 From: jeffvanderdoes at gmail.com (Jeff VanderDoes) Date: Sun, 27 Sep 2015 22:09:23 -0600 Subject: Beginning question #compilersetup, #windows7, #vs2010 In-Reply-To: References: Message-ID: Thanks to both of you for the info. It'll take me a while to dig through it and make sense of it all. Today I was able to install visual studio community 2015 for use with python 3.5. Then I tried using pip to install python-pptx and xlwings. I believe on xlwings I got the following error (in part) didn't know if the whole thing would be useful. Thinking about this I'm not sure if this a compiler issue or a situation where lxml isn't supported in 3.5 yet. Might someone be able to shed some insight? Thanks, Jeff ... C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\vandeje1\AppDat a\Local\Temp\1\pip-build-ih2xe4gw\lxml\src\lxml\includes -IC:\Users\vandeje1\AppData\Local\Programs\Python\Python35-32\include -IC:\ Users\vandeje1\AppData\Local\Programs\Python\Python35-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.101 50.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared " "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tcsrc\lxml\lxml. etree.c /Fobuild\temp.win32-3.5\Release\src\lxml\lxml.etree.obj -w cl : Command line warning D9025 : overriding '/W3' with '/w' lxml.etree.c C:\Users\vandeje1\AppData\Local\Temp\1\pip-build-ih2xe4gw\lxml\src\lxml\includes\etree_defs.h(14): fatal error C1083: Cannot ope n include file: 'libxml/xmlversion.h': No such file or directory C:\Users\vandeje1\AppData\Local\Programs\Python\Python35-32\lib\distutils\dist.py:261: UserWarning: Unknown distribution option: 'bugtrack_url' warnings.warn(msg) error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2 ---------------------------------------- Command "C:\Users\vandeje1\AppData\Local\Programs\Python\Python35-32\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\ \vandeje1\\AppData\\Local\\Temp\\1\\pip-build-ih2xe4gw\\lxml\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read( ).replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\vandeje1\AppData\Local\Temp\1\pip-yz3bhof7-record\install-rec ord.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\vandeje1\AppData\Local\Temp\1\pip-build- ih2xe4gw\lxml On Sun, Sep 27, 2015 at 2:10 PM, eryksun wrote: > On Sat, Sep 26, 2015 at 4:40 PM, Jeff VanderDoes > wrote: > > > > I'm fairly new to Python and was excited to start playing with it until I > > ran into need to compile some extensions under windows 7 64 bit. I've > done > > some searching but after more hours than I care to count being > unsuccessful > > setting up MS visual studio (2015, 2012, and 2010) with service packs and > > SDKs I can tell I'm spinning my wheels and going nowhere fast. > > For 3.5 you should be able to just install Visual Studio 2015 > Community Edition. This is the current release of Visual Studio, so if > you encounter problems, at least finding help won't be one of them. > > 2.7 is built with VS 2008, which is no longer supported. But, thanks > to Steve Dower, Microsoft distributes an unsupported version for > building Python 2.7 extension modules [1]. > > 3.4 is built with the fairly old VS 2010, for which the free Express > edition is no longer available. But you should be able to configure a > command-line build environment. Install the Windows SDK 7.1 [2] and > the VC++ 2010 SP1 Compiler Update [3]. Then run the Windows SDK 7.1 > Command Prompt [4], and enter > > SetEnv /Release /x64 > > If you plan to do native debugging outside of Visual Studio, install > the Debugging Tools for Windows [5] when installing the SDK. You can > download public debug symbols for operating system components using > Microsoft's symbol server. To do this, create a "C:\Symbols" > directory, and set the following environment variable: > > _NT_SYMBOL_PATH=symsrv*symsrv.dll*C:\Symbols* > http://msdl.microsoft.com/download/symbols > > Additionally you'll need Python's debug symbols, such as for 64-bit > 3.4.3 [6]. I typically copy a PDB next to its related DLL/EXE. This is > what 3.5's installer does when you select the option to install debug > symbols (nice job, Steve!). You can also unzip the PDBs to a directory > that's in _NT_SYMBOL_PATH, or update the symbol path dynamically using > .sympath+ and .reload [7]. > > [1]: https://www.microsoft.com/en-us/download/details.aspx?id=44266 > [2]: https://www.microsoft.com/en-us/download/details.aspx?id=8279 > [3]: https://www.microsoft.com/en-us/download/details.aspx?id=4422 > [4]: https://msdn.microsoft.com/en-us/library/ff660764 > [5]: https://msdn.microsoft.com/en-us/library/ff551063 > [6]: https://www.python.org/ftp/python/3.4.3/python-3.4.3.amd64-pdb.zip > [7]: https://msdn.microsoft.com/en-us/library/ff565407 > -- > https://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gengyangcai at gmail.com Mon Sep 28 01:26:35 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sun, 27 Sep 2015 22:26:35 -0700 (PDT) Subject: Help with Debugging In-Reply-To: <56088562$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <56088562$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <2cc8e865-dc5e-4de9-ad5e-77de7b7bf5ee@googlegroups.com> This is my input and output error message (the whole thing) : CaiGengYangs-MacBook-Pro:~ CaiGengYang$ cd mysite folder CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ ls manage.py mysite CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ python manage.py migrate Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line utility.execute() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute settings.INSTALLED_APPS File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__ self._setup(name) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup self._wrapped = Settings(settings_module) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/Users/CaiGengYang/mysite/mysite/settings.py", line 45 'django.middleware.csrf.CsrfViewMiddleware', ^ SyntaxError: invalid syntax CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ On Monday, September 28, 2015 at 8:10:26 AM UTC+8, Steven D'Aprano wrote: > On Mon, 28 Sep 2015 03:45 am, Cai Gengyang wrote: > > > http://pastebin.com/RWt1mp7F --- If anybody can find any errors with this > > settings.py file, let me know ! > > > > Can't seem to find anything wrong with it ... > > Perhaps there is nothing wrong with it. What makes you think that there is? > > Do you get an exception? If so, the exception will tell you where to start: > read the error message, look at the line it says the error occurred at, and > fix the problem. > > If you need help, COPY and PASTE the *entire* traceback, starting from the > line "Traceback (most recent call last)" to the error message at the end, > and send it to us. > > > > -- > Steven From anddam+NOSPAM at brapi.net Mon Sep 28 02:20:24 2015 From: anddam+NOSPAM at brapi.net (Andrea D'Amore) Date: Mon, 28 Sep 2015 08:20:24 +0200 Subject: Help with Debugging References: <56088562$0$1585$c3e8da3$5496439d@news.astraweb.com> <2cc8e865-dc5e-4de9-ad5e-77de7b7bf5ee@googlegroups.com> Message-ID: On 2015-09-28 05:26:35 +0000, Cai Gengyang said: > File "/Users/CaiGengYang/mysite/mysite/settings.py", line 45 > > 'django.middleware.csrf.CsrfViewMiddleware', > > ^ > > SyntaxError: invalid syntax The syntax looks fine in the pastebin, did you possibly copy text from web thus pasting smartquotes or unprintables in your source file? -- Andrea From no.email at nospam.invalid Mon Sep 28 02:32:44 2015 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 27 Sep 2015 23:32:44 -0700 Subject: Are There Known Problems With tkinter And VPS Servers? References: <87y4fra43r.fsf@jester.gateway.sonic.net> Message-ID: <87lhbr9hpv.fsf@jester.gateway.sonic.net> Tim Daneliuk writes: > P.S. X applications like xterm work flawlessly on the hosts in question. It could still be that tk requires some client libraries that are missing, that xterm doesn't use. xterm is a much older and cruftier program. Does Gnome work? For that matter, does Idle work (it is a tkinter client)? I remember that a guy I used to work with ported tk to an embedded linux box with a working X server and display, but still had a rather rough time getting tk running. All I can suggest is curling up with gdb for a while. This has a few diagnostic suggestions that seem worth a try: http://ftp.ntua.gr/mirror/python/topics/tkinter/trouble.html Next thing after that is probably curl up with gdb for a while. From gengyangcai at gmail.com Mon Sep 28 02:33:12 2015 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sun, 27 Sep 2015 23:33:12 -0700 (PDT) Subject: Help with Debugging In-Reply-To: References: <56088562$0$1585$c3e8da3$5496439d@news.astraweb.com> <2cc8e865-dc5e-4de9-ad5e-77de7b7bf5ee@googlegroups.com> Message-ID: <7549afe2-3fda-4403-8f61-954092f8d825@googlegroups.com> I am glad to announce that it works now ! The error was an addition random 'qq' that somehow appeared in my settings.py file on line 44. Once I spotted and removed it , the code works. I have pasted the entire successful piece of code here for viewing and discussion ... CaiGengYangs-MacBook-Pro:~ CaiGengYang$ cd mysite folder CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ ls manage.py mysite CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ python manage.py migrate Operations to perform: Synchronize unmigrated apps: staticfiles, messages Apply all migrations: admin, contenttypes, auth, sessions Synchronizing apps without migrations: Creating tables... Running deferred SQL... Installing custom SQL... Running migrations: Rendering model states... DONE Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying sessions.0001_initial... OK CaiGengYangs-MacBook-Pro:mysite CaiGengYang$ On Monday, September 28, 2015 at 2:20:39 PM UTC+8, Andrea D'Amore wrote: > On 2015-09-28 05:26:35 +0000, Cai Gengyang said: > > > File "/Users/CaiGengYang/mysite/mysite/settings.py", line 45 > > > > 'django.middleware.csrf.CsrfViewMiddleware', > > > > ^ > > > > SyntaxError: invalid syntax > > The syntax looks fine in the pastebin, did you possibly copy text from > web thus pasting smartquotes or unprintables in your source file? > > > -- > Andrea From ashwath at nanoheal.com Mon Sep 28 02:56:44 2015 From: ashwath at nanoheal.com (ashwath at nanoheal.com) Date: Sun, 27 Sep 2015 23:56:44 -0700 Subject: Installing pywin32. In-Reply-To: Message-ID: <20150927235644.d600875ec5143fcc53c5b00e1a6550c2.35e7593ecf.mailapi@email23.secureserver.net> Hi I will give the team viewer ID of my machine so can you please install the pywin32 module to me. Thanks Ashwath --------- Original Message --------- Subject: Re: Re: Installing pywin32. From: "Zachary Ware" Date: 9/24/15 9:29 pm To: "python-list at python.org" Cc: ashwath at nanoheal.com Two notes about local etiquette: 1) Please reply to the list rather than to me directly. I only include your address in the cc: in case you aren't subscribed (which you should be, unless you're reading via the newsgroup), since I don't recognize you as a regular poster. I'll soon stop doing so. 2) Please do not top-post. Rather, add your reply directly beneath the particular line you're replying to, as I do below. On Thu, Sep 24, 2015 at 10:39 AM, wrote: > Hi > > I am pleased with your reply thanks for it..... > System environment is like this > > OS - windows 7 64 bit machine. > Python - pywin3.5 Where did you get it from? I don't know of any product named "pywin3.5". There's 'pywin32' (as in 'Python interface to Win32', available from http://pywin32.sourceforge.net/) and Python 3.5 (as in 'CPython 3.5.0 for Windows', available from https://www.python.org/). > even pip is not installed if I run pip its shows like pip command not found. Installing pip is an option in the Python 3.5 (and 3.4, and 2.7.10) installer. If you didn't select it, it won't be installed. You can try running 'python -m ensurepip' to install pip after the main installation of Python. > From which path I have to run this python -m pip install pypiwin32 Doesn't matter; as long as the 'python' command can be found and that Python has pip installed, this command will install pywin32 into the global site-packages directory of that Python. Also, I should have directed you to `py -m pip install pypiwin32` to make use of the Python Launcher, which is always on PATH (if it was installed, it's also an option in the installer). -- Zach -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Mon Sep 28 03:30:39 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 28 Sep 2015 09:30:39 +0200 Subject: python.org bugs In-Reply-To: References: Message-ID: <201509280730.t8S7UdlR001426@fido.openend.se> If you just send them to webmaster at python.org they will get dealt with (probably by me). Laura From lac at openend.se Mon Sep 28 03:45:40 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 28 Sep 2015 09:45:40 +0200 Subject: Beginning question #compilersetup, #windows7, #vs2010 In-Reply-To: References: Message-ID: <201509280745.t8S7jej3013122@fido.openend.se> 3.5 lxml over here: https://pypi.python.org/pypi/lxml/3.5.0b1 Laura From lac at openend.se Mon Sep 28 04:01:09 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 28 Sep 2015 10:01:09 +0200 Subject: Are There Known Problems With tkinter And VPS Servers? In-Reply-To: References: Message-ID: <201509280801.t8S819mB014694@fido.openend.se> In a message of Sun, 27 Sep 2015 16:31:59 -0500, Tim Daneliuk writes: >Traceback (most recent call last): > File "/usr/local/TundraWare/bin/twander.py", line 5464, in > UI = twanderUI(UIroot) > File "/usr/local/TundraWare/bin/twander.py", line 2152, in __init__ > self.CmdBtn = Menubutton(self.mBar, text=COMMANDMENU, underline=0, state=DISABLED) > File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 2710, in __init__ > Widget.__init__(self, master, 'menubutton', cnf, kw) > File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 1932, in __init__ > (widgetName, self._w) + extra + self._options(cnf)) >_tkinter.TclError You are getting a naked _tkinter.TclError? When the problem is 'couldn't get to the X server' I am used to getting _tkinter.TclError: no display name and no $DISPLAY environment variable and usually _tkinter is pretty good at giving you more information than TclError. The first thing I would do is to run: python -m test -ugui test_tk test_ttk_guionly test_idle which runs the tests for idle, and see if it finds anything suspicious. Laura From wolfgang.maier at biologie.uni-freiburg.de Mon Sep 28 04:48:58 2015 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 28 Sep 2015 10:48:58 +0200 Subject: python.org bugs In-Reply-To: <201509280730.t8S7UdlR001426@fido.openend.se> References: <201509280730.t8S7UdlR001426@fido.openend.se> Message-ID: <5608FEFA.2020500@biologie.uni-freiburg.de> On 28.09.2015 09:30, Laura Creighton wrote: > If you just send them to webmaster at python.org they will get dealt with > (probably by me). > > Laura > Does that apply to bugs on pypi, too? You still cannot select Python 3.5 as the Python Version for wheels and other files uploaded to pypi over the web interface. I've reported this almost a week ago on the pypi issue tracker on bitbucket, but there is no answer yet. Wolfgang From abhi.darkness at gmail.com Mon Sep 28 09:42:48 2015 From: abhi.darkness at gmail.com (Abhiram R) Date: Mon, 28 Sep 2015 19:12:48 +0530 Subject: Installing pywin32. In-Reply-To: <20150927235644.d600875ec5143fcc53c5b00e1a6550c2.35e7593ecf.mailapi@email23.secureserver.net> References: <20150927235644.d600875ec5143fcc53c5b00e1a6550c2.35e7593ecf.mailapi@email23.secureserver.net> Message-ID: > > I will give the team viewer ID of my machine so can you please install the pywin32 module to me. > Hi , It's best if you install it yourself. It isn't really complicated. :) and you'll learn it in the process as well Steps you could possibly Google - 1) installation of Python 3.5 (which i believe is done) 2) set PYTHONPATH in Windows 3) installation of pip on Windows 4) pip install pypiwin32 That's all there is to it. PS- I'm sure you must have searched for your original problem's solution as well. If not, here's the corresponding stackoverflow thread that can possibly help you as well - http://googleweblight.com/?lite_url=http://stackoverflow.com/questions/25257274/python-3-4-importerror-no-module-named-win32api&ei=rMvmto7N&lc=en-IN&s=1&m=978&ts=1443447404&sig=APONPFlqU_v1gaBPeJ1YluSJxcvkrCVpnQ Thanks Abhiram -------------- next part -------------- An HTML attachment was scrubbed... URL: From lac at openend.se Mon Sep 28 10:46:54 2015 From: lac at openend.se (Laura Creighton) Date: Mon, 28 Sep 2015 16:46:54 +0200 Subject: python.org bugs In-Reply-To: <5608FEFA.2020500@biologie.uni-freiburg.de> References: <201509280730.t8S7UdlR001426@fido.openend.se> <5608FEFA.2020500@biologie.uni-freiburg.de> Message-ID: <201509281446.t8SEksWU013376@fido.openend.se> In a message of Mon, 28 Sep 2015 10:48:58 +0200, Wolfgang Maier writes: >On 28.09.2015 09:30, Laura Creighton wrote: >> If you just send them to webmaster at python.org they will get dealt with >> (probably by me). >> >> Laura >> > >Does that apply to bugs on pypi, too? > >You still cannot select Python 3.5 as the Python Version for wheels and >other files uploaded to pypi over the web interface. I've reported this >almost a week ago on the pypi issue tracker on bitbucket, but there is >no answer yet. > >Wolfgang No. You subscribe to https://mail.python.org/mailman/listinfo/distutils-sig And then you ask the people there -- which includes all the people who are maintaining PyPi -- what is up. If you could volunteer to help fix something, that would be great, as they are overworked as it is. Laura From breamoreboy at yahoo.co.uk Mon Sep 28 11:15:20 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 28 Sep 2015 16:15:20 +0100 Subject: Installing pywin32. In-Reply-To: References: <20150927235644.d600875ec5143fcc53c5b00e1a6550c2.35e7593ecf.mailapi@email23.secureserver.net> Message-ID: On 28/09/2015 14:42, Abhiram R wrote: > > > > > I will give the team viewer ID of my machine so can you please > install the pywin32 module to me. > > > > Hi , > It's best if you install it yourself. It isn't really complicated. :) > and you'll learn it in the process as well > Steps you could possibly Google - > 1) installation of Python 3.5 (which i believe is done) > 2) set PYTHONPATH in Windows > 3) installation of pip on Windows You can skip 3) as pip can now be automatically installed with Python at step 1) > 4) pip install pypiwin32 > > That's all there is to it. > PS- I'm sure you must have searched for your original problem's solution > as well. If not, here's the corresponding stackoverflow thread that can > possibly help you as well - > http://googleweblight.com/?lite_url=http://stackoverflow.com/questions/25257274/python-3-4-importerror-no-module-named-win32api&ei=rMvmto7N&lc=en-IN&s=1&m=978&ts=1443447404&sig=APONPFlqU_v1gaBPeJ1YluSJxcvkrCVpnQ > > Thanks > Abhiram > -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From prouleau001 at gmail.com Mon Sep 28 11:19:53 2015 From: prouleau001 at gmail.com (Pierre Rouleau) Date: Mon, 28 Sep 2015 08:19:53 -0700 (PDT) Subject: Partially invalid sys.path - how can I fix it (not append to it)? Message-ID: Hi, On a OS/X 101.10.5 (Yosemite) system, the system Python just got updated to 2.7.10 but it sys.path is partially invalid. How can I fix that? I don't want to add something in PYTHONPATH. I know I can create a softlink at the invalid location to where the real files are located. I just want to understand why that sys.path[6] (see below) is invalid and fix it to point to the valid directory. Details follow: I am running Python 2.7.10: [~]$ python Python 2.7.10 (default, Jul 14 2015, 19:46:27) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> First, see when I get the sys.path before site.py is imported:: [~]$ python -S -c "import sys, pprint; print sys.prefix; pprint.pprint(sys.path)" /usr ['', '/usr/lib/python27.zip', '/usr/lib/python2.7/', '/usr/lib/python2.7/plat-darwin', '/usr/lib/python2.7/plat-mac', '/usr/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/lib/python2.7/../../Extras/lib/python', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload'] [~]$ python -c "import sys, pprint; print sys.prefix; pprint.pprint(sys.path)" /usr ['', '/usr/lib/python27.zip', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-darwin', '/usr/lib/python2.7/plat-mac', '/usr/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/Extras/lib/python', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages'] [~]$ Notice sys.path[6]. It is '/usr/lib/python2.7/../../Extras/lib/python', which when going through site gets normalized to '/usr/Extras/lib/python'. That directory is invalid on my system. It should either be: - The real location: /System/Library/Frameworks/Python.frameworks/Versions/2.7/Extras/lib/python or - the corresponding softlink to that: /usr/lib/python2.7/Extras/lib/python Also note that the sys.prefix is "/usr" I think it should be "/usr/lib/python2.7" or "/System/Library/Frameworks/Python.framework/Versions/2.7" Other Python installed on that system include Python 3.5 (installed via the Python 3.5 DMG installer) and Python 2.7.9 installed with homebrew. For these versions of Python I see something that matches the content of the system storage: - Python 3.5: sys.prefix = '/Library/Frameworks/Python.framework/Versions/3.5' - Python 2.7.9: sys.prefix = '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7' Does anyone know how to fix the path generated in sys.path without adding the real directory path in PYTHONPATH? Thanks! From zachary.ware+pylist at gmail.com Mon Sep 28 15:02:19 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 28 Sep 2015 14:02:19 -0500 Subject: Installing pywin32. In-Reply-To: References: <20150927235644.d600875ec5143fcc53c5b00e1a6550c2.35e7593ecf.mailapi@email23.secureserver.net> Message-ID: On Mon, Sep 28, 2015 at 10:15 AM, Mark Lawrence wrote: > On 28/09/2015 14:42, Abhiram R wrote: >> On Mon, Sep 28, 2015 at 1:56 AM, wrote: >>> I will give the team viewer ID of my machine so can you please >>> install the pywin32 module to me. Not going to happen, sorry. >> It's best if you install it yourself. It isn't really complicated. :) Seconded. >> and you'll learn it in the process as well >> Steps you could possibly Google - >> 1) installation of Python 3.5 (which i believe is done) >> 2) set PYTHONPATH in Windows >> 3) installation of pip on Windows > > You can skip 3) as pip can now be automatically installed with Python at > step 1) Agreed, as I mentioned in a previous message. I'll also note that step 2) is completely unnecessary in most cases (in fact, I have never set PYTHONPATH on Windows, except where venv did it for me), and in fact is likely to break things if you have more than one version of Python installed. Only set PYTHONPATH once you've determined that it's actually necessary. -- Zach From arielin82 at gmail.com Mon Sep 28 17:41:09 2015 From: arielin82 at gmail.com (=?UTF-8?Q?Ariel_Arga=C3=B1araz?=) Date: Mon, 28 Sep 2015 18:41:09 -0300 Subject: Create a .lua fle from Python Message-ID: Hi, This is my first post, I would like to know if a library that can help me with this. I want to parse a XML fle with Python and save the data into a Lua table called for example "newTable", then I want to create a "table.lua" fle with the "newTable" write on it. for example: the XML fle: cities.xml BuenosAires 30 Seatle 25 And I want to create a cities_temp.lua file cities_temps ={ ["Buenos Aires"] = 30, ["Seatle"] = 25, } Is that posible to do with LUPA (https://pypi.python.org/pypi/lupa)?? In the docs I read that you can create lua tables but I did not see if there is a way to create a .lua file with that table. I could do it with python writing to a file line per line but i want some more elegant. Can anyone give some help? Thanks. -- Ariel Arga?araz -------------- next part -------------- An HTML attachment was scrubbed... URL: From esawiek at gmail.com Mon Sep 28 19:40:45 2015 From: esawiek at gmail.com (Ek Esawi) Date: Mon, 28 Sep 2015 19:40:45 -0400 Subject: PY3.5 and nnumpy and scipy installation problem Message-ID: Hi All again? Thanks to all who have provided excellent tips for installing Python, Numpy, Scipy, etc. Paul suggested the use Anaconda which proved to be the best and easiest way for me. If I may add I stumbled on an academic site that spells out in great details how to install Python, numpy, scipy and others which helped me greatly. For any installation issue here is the link http://www.southampton.ac.uk/~fangohr/blog/installation-of-python-spyder-numpy-sympy-scipy-pytest-matplotlib-via-anaconda.html Thanks again---EK -------------- next part -------------- An HTML attachment was scrubbed... URL: From rmorgan466 at gmail.com Mon Sep 28 21:20:16 2015 From: rmorgan466 at gmail.com (Rita) Date: Mon, 28 Sep 2015 21:20:16 -0400 Subject: multiprocessing speedup Message-ID: I am using the multiprocessing with apply_async to do some work. Each task takes a few seconds but I have several thousand tasks. I was wondering if there is a more efficient method and especially when I plan to operate on a large memory arrays (numpy) Here is what I have now import multiprocessing as mp import random def f(x): count=0 for i in range(x): x=random.random() y=random.random() if x*x + y*y<=1: count+=1 return count def main(): resultObj=[] n=10000 P=mp.Pool(2) for arg in xrange(n): resultObj.append(P.apply_async(f,(arg,))) P.close() P.join() result = [ i.get() for i in resultObj ] print sum(result)/(n) if __name__=="__main__": main() 1) Does multiprocessing do a fork for each task? 2) If so, I assume thats costly due to setup and teardown. Would this be the case? 3) I plan to pass large arrays to function,f, therefore is there a more efficient method to achieve this? -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From laxmikant.general at gmail.com Tue Sep 29 00:46:04 2015 From: laxmikant.general at gmail.com (Laxmikant Chitare) Date: Tue, 29 Sep 2015 10:16:04 +0530 Subject: Check if a given value is out of certain range Message-ID: Hi, I know there is an elegant way to check if a given value is within certain range. Example - To check if x is between zero and ten, I can do 0 < x 10. Is there any similar elegant way to check if a value is out of certain range? Example - To check if x is either less than zero or greater than ten? Right now I am using x < 0 or x > 10. Regards, Laxmikant -------------- next part -------------- An HTML attachment was scrubbed... URL: From dieter at handshake.de Tue Sep 29 01:55:38 2015 From: dieter at handshake.de (dieter) Date: Tue, 29 Sep 2015 07:55:38 +0200 Subject: Partially invalid sys.path - how can I fix it (not append to it)? References: Message-ID: <8737xxixb9.fsf@handshake.de> Pierre Rouleau writes: > On a OS/X 101.10.5 (Yosemite) system, the system Python just got updated to 2.7.10 but it sys.path is partially invalid. How can I fix that? > ... details removed ... You have found out that the execution of "site.py" inserts the invalid entries to "sys.path". I remember that there is a document (it was somewhere on "python.org", when I last read it, but this was years ago) which describes what "site.py" does. In particular, it interprets "*.pth" files it finds via "sys.path" and extends "sys.path" according to the content of those files. I find it quite likely, that one of those "*.pth" files might cause the wrong entry in your "sys.path". > Also note that the sys.prefix is "/usr" > I think it should be "/usr/lib/python2.7" or "/System/Library/Frameworks/Python.framework/Versions/2.7" I think this is correct: Python expects the directory corresponding to "prefix" to have subdirectories "bin", "lib/python" and "include". From skybuck2000 at hotmail.com Tue Sep 29 03:09:09 2015 From: skybuck2000 at hotmail.com (Skybuck Flying) Date: Tue, 29 Sep 2015 09:09:09 +0200 Subject: Dummy Decoder Example (was Re: Parallel decoding lesson for you.) In-Reply-To: References: <62ee4$55f9719c$d47876e2$58812@news.ziggo.nl> <6da10$55fd7ac4$d47876e2$19200@news.ziggo.nl> <72397$55fd7db9$d47876e2$29766@news.ziggo.nl> <9aca0$55fd863e$d47876e2$56488@news.ziggo.nl> <39418$55fd8fac$d47876e2$21797@news.ziggo.nl> <9f6cc$55fd9981$d47876e2$58134@news.ziggo.nl> <109e3$55fda507$d47876e2$30929@news.ziggo.nl> <5d560$55fda6eb$d47876e2$37866@news.ziggo.nl> <956248d4-2f8c-475b-8e41-533370589170@googlegroups.com> <4fe26$55fe0126$d47876e2$49025@news.ziggo.nl> <9c80f$55feb011$d47876e2$2668@news.ziggo.nl> <6d8e8$55fec8fa$d47876e2$62254@news.ziggo.nl> Message-ID: Hello, (It is now 29 september 2015) As promised here is Skybuck's Parallel Universal Code demonstration program. This posting contains a Delphi and C/C++ version for you to learn from. (I was kinda thinking of adding some kind of case statement/array and out of order execution/randomization to proof that the lines can be executed in any order, though I didn't come around to that (yet) been playing World of Warships =D at 1 fps to 30 fps lol) (If anybody doubt that these lines can be executed out of order I may eventually add such a feature as welll.. maybe I will do it even for the fun of it ! ;)) (I was also maybe thinking of trying to through it all into a nice Tprocessor class with an actual thread to show it off as well... didn't come around to that yet either ;):)) (However if you clearly examine the indexes used you will discover that there is no overlap, all indexes are uniquely read and such... no write-read-write-read-sequential stuff going on... it can all be read in parallel... except for building rowoffset array). // ** Begin of Delphi Program *** program TestProgram; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; { Skybuck's Parallel Universal Code, Demonstration program version 0.01 created on 19 september 2015 This demonstration program will illustrate how to decode fields of data in parallel. For this demonstration program bit fiddling will be avoided by allowing 1 bit per array index to illustrate the general idea. Also lengths may be stored by 1 integer per array index. In a real world scenerio it would be Skybuck Universally Encoded. Skybuck's Parallel Universal Code, Design Document: version 1 created on 16 september 2015 (after seeing another mentioning of IBM's processor MIL which makes me sick, as if decoding fields in parallel is hard ! LOL ;) :)) (I also wrote a little introductionary question for it see other file for it and I even learned something from it: Parallel decoding lesson for you.txt) All bits of the fields are split up in such a way that the first bit of each field is right next to each other, the second bit of each field is also next to each other, and so forth. Conceptually view: First currently situation Field A consists out of a1a2a3a4 (4 bits) Field B consists out of b1b2b3 (3 bits) Field C consists out of c1 (1 bit) Field D consists out of d1d2d3d4d5d6 ( 6 bits) These bits are stored as follows: "First row": a1b1c1d1 "Second row": a2b2d2 "Third row": a3b3d3 "Fourth row": a4d4 "Fiveth row": d5 "Sixth row": d6 These rows will be stores sequentially as follows: a1b1c1d1a2b2d2a3b3d4a4d4d5d6 Now the question is: How does a processor know where each row begins ? and how many bits of each field there is, the answers are given below: The bit length of each row is stored preemptively/prefixed: "First row": 4 "Second row": 3 "Third row": 3 "Fourth row": 2 "Fiveth row": 1 "Sixth row" : 1 Now for each row their offset can be computed: First row starts at 0, Second row starts at 0 + 4 = 4 Third row starts at 0 + 4 + 3 = 7 Fouth row starts at 0 + 4 + 3 + 3 = 10 Fiveth row starts at 0 + 4 + 3 + 3 + 2 = 12 Sixth row starts at 0 + 4+ 3 + 3+ 2 + 1 = 13 Let's check if this is true: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 a1 b1 c1 d1 a2 b2 d2 a3 b3 d3 a4 d4 d5 d6 Bingo, all match. The processor can compute the offsets of each row. And thus the processor can reach each field in parallel as follows: Read field A bit 0 at offset 0 Read field B bit 0 at offset 4 Read field C bit 0 at offset 7 Read field D bit 0 at offset 10 Now the question is how can the processor know when to stop reading ? A marker/meta bit could be used like described in Skybuck's Universal Code version 1, which indicates if the field continues or stops. These bits can be stored in the same way as the data bits above. And thus for each data bit, a meta bit can be read as well. This way the processor knows that C2 does not exist and can stop reading field C For huffman codes that would not even be required, since the processor can see in the huffman tree when it reaches a leave/end node and then it will know the end of C was reached. So marker/beta bits can be avoided by using Huffman codes ! Pretty neeto ! ;) =D However huffman has a drawback that some fields might get large, and may not be suited for rare information and modifications and so forth ! ;) The last thing to do to make this usuable is to include another prefix field which indicates how many prefixes there are. So final stream will look something like: [Number of Fields][Set of Field Lengths][Set of Field Data Bits Intermixed/Parallel] First field can be universally coded. Second set of fields can be universally coded. Third set of field contains data bits intermixed/in parallel. Additional: The problem can be solved by sorting the fields from largest to smallest field, so new stream looks like: (sorting from smallest to largest would be possible too... but code below assumes first field is largest so it uses largest to smallest sorting solution which is also applied to the stream A, so stream A below is sorted that way) Stream A: 433211d1a1b1c1d2a2b2d3a3b3d4a4d5d6 Bye, Skybuck. } function Constrain( Para : integer ) : integer; begin result := Para; if Para < 0 then Result := 0; if Para >= 1 then Result := 1; end; procedure Main; // must put variables here otherwise won't show up in debugger. const MaxProcessorCount = 4; var // information stream, input Stream : array[0..20+(MaxProcessorCount-1)] of integer; // add max processor count to create a safe "padding" for reading so no out of bounds/range check errors with arrays. // bits representing fields of data a1,a2,a3,a4 : integer; b1,b2,b3 : integer; c1 : integer; d1,d2,d3,d4,d5,d6 : integer; // output RowIndex : integer; RowCount : integer; RowLength : array[0..5] of integer; RowOffset : array[0..5] of integer; FieldRowMultiplier : array[0..3,0..5] of integer; DataOffset : integer; FieldCount : integer; FieldLength : array[0..3] of integer; Processor : array[0..3] of integer; // debug fields FieldA : integer; FieldB : integer; FieldC : integer; FieldD : integer; begin a1 := 1; a2 := 1; a3:= 1; a4 := 1; b1 := 1; b2 := 1; b3 := 1; c1 := 1; d1 := 1; d2 := 1; d3 := 1; d4 := 1; d5 := 1; d6 := 1; // compute input fields to compare it later with output fields FieldA := (a1) or (a2 shl 1) or (a3 shl 2) or (a4 shl 3); FieldB := (b1) or (b2 shl 1) or (b3 shl 2); FieldC := (c1); FieldD := (d1) or (d2 shl 1) or (d3 shl 2) or (d4 shl 3) or (d5 shl 4) or (d6 shl 5); // print field values writeln( 'FieldA: ', FieldA ); writeln( 'FieldB: ', FieldB ); writeln( 'FieldC: ', FieldC ); writeln( 'FieldD: ', FieldD ); writeln; // number of rows Stream[0] := 6; // row lengths Stream[1] := 4; Stream[2] := 3; Stream[3] := 3; Stream[4] := 2; Stream[5] := 1; Stream[6] := 1; // sorted information stream: // d1a1b1c1d2a2b2d3a3b3d4a4d5d6 // data bits Stream[7] := d1; Stream[8] := a1; Stream[9] := b1; Stream[10] := c1; Stream[11] := d2; Stream[12] := a2; Stream[13] := b2; Stream[14] := d3; Stream[15] := a3; Stream[16] := b3; Stream[17] := d4; Stream[18] := a4; Stream[19] := d5; Stream[20] := d6; // now the decoding algorithm: // determine number of rows RowCount := Stream[0]; // extract row lengths RowLength[0] := Stream[1]; RowLength[1] := Stream[2]; RowLength[2] := Stream[3]; RowLength[3] := Stream[4]; RowLength[4] := Stream[5]; RowLength[5] := Stream[6]; // determine field count FieldCount := RowLength[0]; // row[0] indicates number of fields. // let's assume first field is largest so it always consumes all row information. // should be 0 if negative, should be zero if zero, should be 1 if positive so and will do the trick to constaint it. // the -0, -1, -2, -3 represents subtracting the processor number/identify from it... to allow parallel processing ! ;) // contraint is wrong... hahga unnt. FieldRowMultiplier[0,0] := Constrain(RowLength[0]-0); // shoudl be set to one if larger. FieldRowMultiplier[0,1] := Constrain(RowLength[1]-0); FieldRowMultiplier[0,2] := Constrain(RowLength[2]-0); FieldRowMultiplier[0,3] := Constrain(RowLength[3]-0); FieldRowMultiplier[0,4] := Constrain(RowLength[4]-0); FieldRowMultiplier[0,5] := Constrain(RowLength[5]-0); // now second field may consume less if there are not enough bits. FieldRowMultiplier[1,0] := Constrain(RowLength[0]-1); FieldRowMultiplier[1,1] := Constrain(RowLength[1]-1); FieldRowMultiplier[1,2] := Constrain(RowLength[2]-1); FieldRowMultiplier[1,3] := Constrain(RowLength[3]-1); FieldRowMultiplier[1,4] := Constrain(RowLength[4]-1); FieldRowMultiplier[1,5] := Constrain(RowLength[5]-1); // now third field may consume less if there are not enough bits. FieldRowMultiplier[2,0] := Constrain(RowLength[0]-2); FieldRowMultiplier[2,1] := Constrain(RowLength[1]-2); FieldRowMultiplier[2,2] := Constrain(RowLength[2]-2); FieldRowMultiplier[2,3] := Constrain(RowLength[3]-2); FieldRowMultiplier[2,4] := Constrain(RowLength[4]-2); FieldRowMultiplier[2,5] := Constrain(RowLength[5]-2); // now fourth field may consume less if there are not enough bits. FieldRowMultiplier[3,0] := Constrain(RowLength[0]-3); FieldRowMultiplier[3,1] := Constrain(RowLength[1]-3); FieldRowMultiplier[3,2] := Constrain(RowLength[2]-3); FieldRowMultiplier[3,3] := Constrain(RowLength[3]-3); FieldRowMultiplier[3,4] := Constrain(RowLength[4]-3); FieldRowMultiplier[3,5] := Constrain(RowLength[5]-3); // now compute field lengths // not necessary to multiply anything just add them up ! ;) =D FieldLength[0] := FieldRowMultiplier[0,0] + FieldRowMultiplier[0,1] + FieldRowMultiplier[0,2] + FieldRowMultiplier[0,3] + FieldRowMultiplier[0,4] + FieldRowMultiplier[0,5]; FieldLength[1] := FieldRowMultiplier[1,0] + FieldRowMultiplier[1,1] + FieldRowMultiplier[1,2] + FieldRowMultiplier[1,3] + FieldRowMultiplier[1,4] + FieldRowMultiplier[1,5]; FieldLength[2] := FieldRowMultiplier[2,0] + FieldRowMultiplier[2,1] + FieldRowMultiplier[2,2] + FieldRowMultiplier[2,3] + FieldRowMultiplier[2,4] + FieldRowMultiplier[2,5]; FieldLength[3] := FieldRowMultiplier[3,0] + FieldRowMultiplier[3,1] + FieldRowMultiplier[3,2] + FieldRowMultiplier[3,3] + FieldRowMultiplier[3,4] + FieldRowMultiplier[3,5]; // though the field multipliers could come in handy later to read the bits ! nice ! ;) =D // for each row the offset must be calculated this can be done serially or by all processors for themselfes at the same time: // row zero starts after the number of rows which is indicated by the first stream value =D // first determine data offset properly ! ;) :) 1 for the row count + RowCount to skip over row lengths. DataOffset := 1 + RowCount; RowOffset[0] := DataOffset; RowOffset[1] := RowOffset[0] + RowLength[0]; RowOffset[2] := RowOffset[1] + RowLength[1]; RowOffset[3] := RowOffset[2] + RowLength[2]; RowOffset[4] := RowOffset[3] + RowLength[3]; RowOffset[5] := RowOffset[4] + RowLength[4]; // now calculate and/ore detemrine length of each field // first determine number of fields // now that all row offsets are calculated it's possible to decode the stream into each processor, by each processor. // each processor knows it's own number/identitiy represented by the +0 +1 +2 +3 down below: // the general idea is: // row[] here is RowOffset[] { Processor[0] := Stream[Row[0]+0]+Stream[Row[1]+0]+Stream[Row[2]+0]+Stream[Row[3]+0]+Stream[Row[4]+0]+Stream[Row[5]+0]; Processor[1] := Stream[Row[0]+1]+Stream[Row[1]+1]+Stream[Row[2]+1]+Stream[Row[3]+1]+Stream[Row[4]+1]+Stream[Row[5]+1]; Processor[2] := Stream[Row[0]+2]+Stream[Row[1]+2]+Stream[Row[2]+2]+Stream[Row[3]+2]+Stream[Row[4]+2]+Stream[Row[5]+2]; Processor[3] := Stream[Row[0]+3]+Stream[Row[1]+3]+Stream[Row[2]+3]+Stream[Row[3]+3]+Stream[Row[4]+3]+Stream[Row[5]+3]; } // however a processor should only include the bits of a stream if it's within the field's length for that we need // to compute each field length and here we have an oops ! ;) :) cannot compute field length if multiple fields // per row. or can we ?! ;) :)perhaps we can... we know that fields have at least 1 bit because of row 0 // and we know which fields have 2 bits because of row 2 and so forth... and since all fields // are ditributed parallely... we don't actually need to know where their bits are.... cause they all packed lol... // we only need to know what max length is or something... though how can we dan be sure that a field ends up // wehere it needs to be... well we dont... a field can end up in any processor. // so how should it actually look like then... well as follows: // since the fields are stored as follows: A,B,C,D we know A ends up in processor 0, B in 1, C in 2, D in 3 and so forth. // thus... processor 0 can determine length of A by looking at row[0], row[1], row[2], row[3], row[4], row[5], row[6]. // but how to know which count matches to who's field ? // is the length of row 5 for A or B or C or D ? we don't know do we ?! ;) // now we should be able to solve the problem... we know the bits belong to the first few fields... cool ! ;) =D // now we should be able to solve it easily... by only including a bit from the stream if the multiplier is set to 1 ;) :) // and now only thing left to do is shifting the bits into proper position and or-ing them together ! ;) Processor[0] := ((Stream[RowOffset[0]+0]*FieldRowMultiplier[0,0]) shl 0) or ((Stream[RowOffset[1]+0]*FieldRowMultiplier[0,1]) shl 1) or ((Stream[RowOffset[2]+0]*FieldRowMultiplier[0,2]) shl 2) or ((Stream[RowOffset[3]+0]*FieldRowMultiplier[0,3]) shl 3) or ((Stream[RowOffset[4]+0]*FieldRowMultiplier[0,4]) shl 4) or ((Stream[RowOffset[5]+0]*FieldRowMultiplier[0,5]) shl 5); Processor[1] := ((Stream[RowOffset[0]+1]*FieldRowMultiplier[1,0]) shl 0) or ((Stream[RowOffset[1]+1]*FieldRowMultiplier[1,1]) shl 1) or ((Stream[RowOffset[2]+1]*FieldRowMultiplier[1,2]) shl 2) or ((Stream[RowOffset[3]+1]*FieldRowMultiplier[1,3]) shl 3) or ((Stream[RowOffset[4]+1]*FieldRowMultiplier[1,4]) shl 4) or ((Stream[RowOffset[5]+1]*FieldRowMultiplier[1,5]) shl 5); Processor[2] := ((Stream[RowOffset[0]+2]*FieldRowMultiplier[2,0]) shl 0) or ((Stream[RowOffset[1]+2]*FieldRowMultiplier[2,1]) shl 1) or ((Stream[RowOffset[2]+2]*FieldRowMultiplier[2,2]) shl 2) or ((Stream[RowOffset[3]+2]*FieldRowMultiplier[2,3]) shl 3) or ((Stream[RowOffset[4]+2]*FieldRowMultiplier[2,4]) shl 4) or ((Stream[RowOffset[5]+2]*FieldRowMultiplier[2,5]) shl 5); Processor[3] := ((Stream[RowOffset[0]+3]*FieldRowMultiplier[3,0]) shl 0) or ((Stream[RowOffset[1]+3]*FieldRowMultiplier[3,1]) shl 1) or ((Stream[RowOffset[2]+3]*FieldRowMultiplier[3,2]) shl 2) or ((Stream[RowOffset[3]+3]*FieldRowMultiplier[3,3]) shl 3) or ((Stream[RowOffset[4]+3]*FieldRowMultiplier[3,4]) shl 4) or ((Stream[RowOffset[5]+3]*FieldRowMultiplier[3,5]) shl 5); // *** STILL TO DO (solved by extending array): ******************************** // *** ^^^ may have to look into potential out of range problem ^^^ **** // ********************************************************************* // for now it seems ok, also as long as stream array has +NumberOfProcessors scratch pad at end it may be ok ! ;) :) // one last problem might remain... the row offset may go out of range... // we could either use a scratch pad or solve this in another way. // I think it's best to leave it as as and perhaps make the stream a bit larger or omething let's see what happens. // print processor values. writeln( 'Processor[0]: ', Processor[0] ); writeln( 'Processor[1]: ', Processor[1] ); writeln( 'Processor[2]: ', Processor[2] ); writeln( 'Processor[3]: ', Processor[3] ); writeln; end; begin try Main; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; ReadLn; end. // *** End of Delphi Program *** // *** Begin of C/C++ Program *** // ParallelDecodingCVersion.cpp : Defines the entry point for the console application. // // Full C version 0.01 created on 23 september 2015 by Skybuck Flying =D #include "stdafx.h" // Begin of Dummy Decoder Example const int MaxProcessorCount = 4; int Constrain( int Para ) { if (Para < 0) Para = 0; if (Para >= 1) Para = 1; return Para; } int _tmain(int argc, _TCHAR* argv[]) { // information stream, input int Stream[21+(MaxProcessorCount-1)]; // add max processor count to create a safe "padding" for reading so no out of bounds/range check errors with arrays. // bits representing fields of data int a1,a2,a3,a4; int b1,b2,b3; int c1; int d1,d2,d3,d4,d5,d6; // output int RowIndex; int RowCount; int RowLength[6]; int RowOffset[6]; int FieldRowMultiplier[4][6]; int DataOffset; int FieldCount; int FieldLength[4]; int Processor[4]; // debug fields int FieldA; int FieldB; int FieldC; int FieldD; // input test 1 /* a1 = 1; a2 = 1; a3 = 1; a4 = 1; b1 = 1; b2 = 1; b3 = 1; c1 = 1; d1 = 1; d2 = 1; d3 = 1; d4 = 1; d5 = 1; d6 = 1; */ // input test 2 a1 = 1; a2 = 0; a3 = 0; a4 = 1; b1 = 1; b2 = 1; b3 = 0; c1 = 1; d1 = 1; d2 = 1; d3 = 0; d4 = 0; d5 = 1; d6 = 0; // compute input fields to compare it later with output fields FieldA = (a1) | (a2 << 1) | (a3 << 2) | (a4 << 3); FieldB = (b1) | (b2 << 1) | (b3 << 2); FieldC = (c1); FieldD = (d1) | (d2 << 1) | (d3 << 2) | (d4 << 3) | (d5 << 4) | (d6 << 5); // print field values printf( "FieldD: %d \n", FieldD ); printf( "FieldA: %d \n", FieldA ); printf( "FieldB: %d \n", FieldB ); printf( "FieldC: %d \n\n", FieldC ); // number of rows Stream[0] = 6; // row lengths Stream[1] = 4; Stream[2] = 3; Stream[3] = 3; Stream[4] = 2; Stream[5] = 1; Stream[6] = 1; // sorted information stream: // d1a1b1c1d2a2b2d3a3b3d4a4d5d6 // data bits Stream[7] = d1; Stream[8] = a1; Stream[9] = b1; Stream[10] = c1; Stream[11] = d2; Stream[12] = a2; Stream[13] = b2; Stream[14] = d3; Stream[15] = a3; Stream[16] = b3; Stream[17] = d4; Stream[18] = a4; Stream[19] = d5; Stream[20] = d6; // now the decoding algorithm: // determine number of rows RowCount = Stream[0]; // extract row lengths RowLength[0] = Stream[1]; RowLength[1] = Stream[2]; RowLength[2] = Stream[3]; RowLength[3] = Stream[4]; RowLength[4] = Stream[5]; RowLength[5] = Stream[6]; // determine field count FieldCount = RowLength[0]; // row[0] indicates number of fields. // I will help out a bit... by leaving this code in ! ;) seems somewhat obvious ;) // first determine data offset properly ! ;) :) 1 for the row count + // RowCount to skip over row lengths. DataOffset = 1 + RowCount; RowOffset[0] = DataOffset; RowOffset[1] = RowOffset[0] + RowLength[0]; RowOffset[2] = RowOffset[1] + RowLength[1]; RowOffset[3] = RowOffset[2] + RowLength[2]; RowOffset[4] = RowOffset[3] + RowLength[3]; RowOffset[5] = RowOffset[4] + RowLength[4]; // let's assume first field is largest so it always consumes all row information. // should be 0 if negative, should be zero if zero, should be 1 if positive so and will do the trick to constaint it. // the -0, -1, -2, -3 represents subtracting the processor number/identify from it... to allow parallel processing ! ;) // contraint is wrong... hahga unnt. FieldRowMultiplier[0][0] = Constrain(RowLength[0]-0); // shoudl be set to one if larger. FieldRowMultiplier[0][1] = Constrain(RowLength[1]-0); FieldRowMultiplier[0][2] = Constrain(RowLength[2]-0); FieldRowMultiplier[0][3] = Constrain(RowLength[3]-0); FieldRowMultiplier[0][4] = Constrain(RowLength[4]-0); FieldRowMultiplier[0][5] = Constrain(RowLength[5]-0); // now second field may consume less if there are not enough bits. FieldRowMultiplier[1][0] = Constrain(RowLength[0]-1); FieldRowMultiplier[1][1] = Constrain(RowLength[1]-1); FieldRowMultiplier[1][2] = Constrain(RowLength[2]-1); FieldRowMultiplier[1][3] = Constrain(RowLength[3]-1); FieldRowMultiplier[1][4] = Constrain(RowLength[4]-1); FieldRowMultiplier[1][5] = Constrain(RowLength[5]-1); // now third field may consume less if there are not enough bits. FieldRowMultiplier[2][0] = Constrain(RowLength[0]-2); FieldRowMultiplier[2][1] = Constrain(RowLength[1]-2); FieldRowMultiplier[2][2] = Constrain(RowLength[2]-2); FieldRowMultiplier[2][3] = Constrain(RowLength[3]-2); FieldRowMultiplier[2][4] = Constrain(RowLength[4]-2); FieldRowMultiplier[2][5] = Constrain(RowLength[5]-2); // now fourth field may consume less if there are not enough bits. FieldRowMultiplier[3][0] = Constrain(RowLength[0]-3); FieldRowMultiplier[3][1] = Constrain(RowLength[1]-3); FieldRowMultiplier[3][2] = Constrain(RowLength[2]-3); FieldRowMultiplier[3][3] = Constrain(RowLength[3]-3); FieldRowMultiplier[3][4] = Constrain(RowLength[4]-3); FieldRowMultiplier[3][5] = Constrain(RowLength[5]-3); // now compute field lengths // not necessary to multiply anything just add them up ! ;) =D FieldLength[0] = FieldRowMultiplier[0][0] + FieldRowMultiplier[0][1] + FieldRowMultiplier[0][2] + FieldRowMultiplier[0][3] + FieldRowMultiplier[0][4] + FieldRowMultiplier[0][5]; FieldLength[1] = FieldRowMultiplier[1][0] + FieldRowMultiplier[1][1] + FieldRowMultiplier[1][2] + FieldRowMultiplier[1][3] + FieldRowMultiplier[1][4] + FieldRowMultiplier[1][5]; FieldLength[2] = FieldRowMultiplier[2][0] + FieldRowMultiplier[2][1] + FieldRowMultiplier[2][2] + FieldRowMultiplier[2][3] + FieldRowMultiplier[2][4] + FieldRowMultiplier[2][5]; FieldLength[3] = FieldRowMultiplier[3][0] + FieldRowMultiplier[3][1] + FieldRowMultiplier[3][2] + FieldRowMultiplier[3][3] + FieldRowMultiplier[3][4] + FieldRowMultiplier[3][5]; // though the field multipliers could come in handy later to read the bits ! nice ! ;) =D // for each row the offset must be calculated this can be done serially or by all processors for themselfes at the same time: // row zero starts after the number of rows which is indicated by the first stream value =D // first determine data offset properly ! ;) :) 1 for the row count + RowCount to skip over row lengths. DataOffset = 1 + RowCount; RowOffset[0] = DataOffset; RowOffset[1] = RowOffset[0] + RowLength[0]; RowOffset[2] = RowOffset[1] + RowLength[1]; RowOffset[3] = RowOffset[2] + RowLength[2]; RowOffset[4] = RowOffset[3] + RowLength[3]; RowOffset[5] = RowOffset[4] + RowLength[4]; // now calculate and/ore detemrine length of each field // first determine number of fields // now that all row offsets are calculated it's possible to decode the stream into each processor, by each processor. // each processor knows it's own number/identitiy represented by the +0 +1 +2 +3 down below: // the general idea is: // row[] here is RowOffset[] /* Processor[0] := Stream[Row[0]+0]+Stream[Row[1]+0]+Stream[Row[2]+0]+Stream[Row[3]+0]+Stream[Row[4]+0]+Stream[Row[5]+0]; Processor[1] := Stream[Row[0]+1]+Stream[Row[1]+1]+Stream[Row[2]+1]+Stream[Row[3]+1]+Stream[Row[4]+1]+Stream[Row[5]+1]; Processor[2] := Stream[Row[0]+2]+Stream[Row[1]+2]+Stream[Row[2]+2]+Stream[Row[3]+2]+Stream[Row[4]+2]+Stream[Row[5]+2]; Processor[3] := Stream[Row[0]+3]+Stream[Row[1]+3]+Stream[Row[2]+3]+Stream[Row[3]+3]+Stream[Row[4]+3]+Stream[Row[5]+3]; */ // however a processor should only include the bits of a stream if it's within the field's length for that we need // to compute each field length and here we have an oops ! ;) :) cannot compute field length if multiple fields // per row. or can we ?! ;) :)perhaps we can... we know that fields have at least 1 bit because of row 0 // and we know which fields have 2 bits because of row 2 and so forth... and since all fields // are ditributed parallely... we don't actually need to know where their bits are.... cause they all packed lol... // we only need to know what max length is or something... though how can we dan be sure that a field ends up // wehere it needs to be... well we dont... a field can end up in any processor. // so how should it actually look like then... well as follows: // since the fields are stored as follows: A,B,C,D we know A ends up in processor 0, B in 1, C in 2, D in 3 and so forth. // thus... processor 0 can determine length of A by looking at row[0], row[1], row[2], row[3], row[4], row[5], row[6]. // but how to know which count matches to who's field ? // is the length of row 5 for A or B or C or D ? we don't know do we ?! ;) // now we should be able to solve the problem... we know the bits belong to the first few fields... cool ! ;) =D // now we should be able to solve it easily... by only including a bit from the stream if the multiplier is set to 1 ;) :) // and now only thing left to do is shifting the bits into proper position and or-ing them together ! ;) Processor[0] = ((Stream[RowOffset[0]+0]*FieldRowMultiplier[0][0]) << 0) | ((Stream[RowOffset[1]+0]*FieldRowMultiplier[0][1]) << 1) | ((Stream[RowOffset[2]+0]*FieldRowMultiplier[0][2]) << 2) | ((Stream[RowOffset[3]+0]*FieldRowMultiplier[0][3]) << 3) | ((Stream[RowOffset[4]+0]*FieldRowMultiplier[0][4]) << 4) | ((Stream[RowOffset[5]+0]*FieldRowMultiplier[0][5]) << 5); Processor[1] = ((Stream[RowOffset[0]+1]*FieldRowMultiplier[1][0]) << 0) | ((Stream[RowOffset[1]+1]*FieldRowMultiplier[1][1]) << 1) | ((Stream[RowOffset[2]+1]*FieldRowMultiplier[1][2]) << 2) | ((Stream[RowOffset[3]+1]*FieldRowMultiplier[1][3]) << 3) | ((Stream[RowOffset[4]+1]*FieldRowMultiplier[1][4]) << 4) | ((Stream[RowOffset[5]+1]*FieldRowMultiplier[1][5]) << 5); Processor[2] = ((Stream[RowOffset[0]+2]*FieldRowMultiplier[2][0]) << 0) | ((Stream[RowOffset[1]+2]*FieldRowMultiplier[2][1]) << 1) | ((Stream[RowOffset[2]+2]*FieldRowMultiplier[2][2]) << 2) | ((Stream[RowOffset[3]+2]*FieldRowMultiplier[2][3]) << 3) | ((Stream[RowOffset[4]+2]*FieldRowMultiplier[2][4]) << 4) | ((Stream[RowOffset[5]+2]*FieldRowMultiplier[2][5]) << 5); Processor[3] = ((Stream[RowOffset[0]+3]*FieldRowMultiplier[3][0]) << 0) | ((Stream[RowOffset[1]+3]*FieldRowMultiplier[3][1]) << 1) | ((Stream[RowOffset[2]+3]*FieldRowMultiplier[3][2]) << 2) | ((Stream[RowOffset[3]+3]*FieldRowMultiplier[3][3]) << 3) | ((Stream[RowOffset[4]+3]*FieldRowMultiplier[3][4]) << 4) | ((Stream[RowOffset[5]+3]*FieldRowMultiplier[3][5]) << 5); // *** STILL TO DO (solved by extending array): ******************************** // *** ^^^ may have to look into potential out of range problem ^^^ **** // solved by adding padding for reading ;) // ********************************************************************* // for now it seems ok, also as long as stream array has +NumberOfProcessors scratch pad at end it may be ok ! ;) :) // one last problem might remain... the row offset may go out of range... // we could either use a scratch pad|solve this in another way. // I think it's best to leave it as as and perhaps make the stream a bit larger or omething let's see what happens. // print processor values. printf( "Processor[0]: %d \n", Processor[0] ); printf( "Processor[1]: %d \n", Processor[1] ); printf( "Processor[2]: %d \n", Processor[2] ); printf( "Processor[3]: %d \n\n", Processor[3] ); return 0; } // *** Emd of C/C++ Program *** Bye, Skybuck. From __peter__ at web.de Tue Sep 29 03:24:26 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 29 Sep 2015 09:24:26 +0200 Subject: multiprocessing speedup References: Message-ID: Rita wrote: > I am using the multiprocessing with apply_async to do some work. Each task > takes a few seconds but I have several thousand tasks. I was wondering if > there is a more efficient method and especially when I plan to operate on > a > large memory arrays (numpy) > > Here is what I have now > > > import multiprocessing as mp > import random > > def f(x): > count=0 > for i in range(x): > x=random.random() > y=random.random() > if x*x + y*y<=1: > count+=1 > > return count > > def main(): > resultObj=[] > n=10000 > P=mp.Pool(2) > for arg in xrange(n): > resultObj.append(P.apply_async(f,(arg,))) > P.close() > P.join() > result = [ i.get() for i in resultObj ] > print sum(result)/(n) > > if __name__=="__main__": > main() This is much too early to worry about speed. First write a working version. Then measure to identify the bottlenecks. Then optimise the bottlenecks (if any) and only the bottlenecks. > 1) Does multiprocessing do a fork for each task? I don't think so. You can see the when you modify your script to return the process id (there will only be two). But the data has to be passed around. > 2) If so, I assume thats costly due to setup and teardown. Would this be > the case? I don't think so. > 3) I plan to pass large arrays to function,f, therefore is there a more > efficient method to achieve this? Where do these arrays come from? If they are coming from a file could you use separate scripts to operate on part(s) of the file(s)? Of course such considerations are moot if most of time is spent to process an array rather than pass it around. Which brings us back to the first and foremost point: This is much too early to worry about speed. From rosuav at gmail.com Tue Sep 29 04:01:05 2015 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 29 Sep 2015 18:01:05 +1000 Subject: Check if a given value is out of certain range In-Reply-To: References: Message-ID: On Tue, Sep 29, 2015 at 2:46 PM, Laxmikant Chitare wrote: > Hi, > > I know there is an elegant way to check if a given value is within certain > range. > Example - To check if x is between zero and ten, I can do 0 < x 10. > > Is there any similar elegant way to check if a value is out of certain > range? > Example - To check if x is either less than zero or greater than ten? > Right now I am using x < 0 or x > 10. You can simply negate the condition: not 0 <= x <= 10 ChrisA From gilad905 at gmail.com Tue Sep 29 05:20:00 2015 From: gilad905 at gmail.com (Gilad Mayani) Date: Tue, 29 Sep 2015 11:20:00 +0200 Subject: Issue: cannot successfully install Python 3 on Windows 7 Message-ID: Dear Python staff, I am trying to install the latest version of Python 3 on my machine, in which I already have Python 2.7.3 installed. I did this by downloading the installer from the 'Download Python 3.5.0' button from https://www.python.org/downloads/. BTW, the installer installs the 32-bit Python version. The installation seems to run smoothly, but when I try to then open Python (by running "py -3" from the command line or opening the Python 3 IDLE) I always get this message: > the program can't start because api-ms-win-crt-runtime-I1-1-0.dll is > missing from your computer. I have trying a few times via the installer to repair the installation, uninstall & re-install and restart my computer between the installations. I also ran Windows updates and tried installing with the Python 3.5.0 Windows x86-64 executable installer ( https://www.python.org/ftp/python/3.5.0/python-3.5.0-amd64.exe) instead, with the same results. My machine details are: OS Name Microsoft Windows 7 Home Premium Version 6.1.7601 Service Pack 1 Build 7601 System Type x64-based PC Processor Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz, 2001 Mhz, 4 Core(s), 8 Logical Processor(s) BIOS Version/Date Dell Inc. A02, 2/3/2011 SMBIOS Version 2.6 Do you know how this can be solved? Thanks a lot for your help! Gilad Mayani. -------------- next part -------------- An HTML attachment was scrubbed... URL: From plewto at gmail.com Tue Sep 29 05:27:23 2015 From: plewto at gmail.com (plewto at gmail.com) Date: Tue, 29 Sep 2015 02:27:23 -0700 (PDT) Subject: Question re class variable Message-ID: <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> I have a perplexing problem with Python 3 class variables. I wish to generate an unique ID each time an instance of GameClass is created. There are two versions of the __gen_id method with test run results for each listed below the code. Originally I used the version which is now commented out. When a new instance was created it created an ID by appending the value of __instance_counter to the class name, it then checked the contents of of __instatance_registrty to see if this ID was already in use. If so it incremented the counter until it found an unused ID. This version works exactly as I expected. Later I decided to get rid of __instance_registry and rely solely on the restricted access to __instance_counter and the fact that it is monotonically increasing to generate IDs. I wrote the second, simpler version of __gen_id to that end, but it doesn't work! No doubt I'm overlooking something very simple here but I'm not seeing it. Any help appreciated. class GameObject: # __instance_registry = {"":None} __instance_counter = 0 def __init__(self, name): self.__name = str(name) self.__id = self.__gen_id() # def __gen_id(self): # ty = self.__class__.__name__ # id = '' # while id in self.__instance_registry: # id = '%s_%d' % (ty, self.__instance_counter) # self.__instance_counter += 1 # self.__instance_registry[id] = self # return id def __gen_id(self): ty = self.__class__.__name__ id = '%s_%d' % (ty, self.__instance_counter) self.__instance_counter += 1 return id def __str__(self): return "name = '%s' id = '%s'" % (self.__name, self.__id) go1 = GameObject("GO1") go2 = GameObject("GO2") go3 = GameObject("GO3") print(go1) print(go2) print(go3) # Results with original __gen_id method # name = 'GO1' id = 'GameObject_0' # name = 'GO2' id = 'GameObject_1' # name = 'GO3' id = 'GameObject_2' # Results with new simpler __gen_id method, __instance_counter not being incremented # name = 'GO1' id = 'GameObject_0' # name = 'GO2' id = 'GameObject_0' # name = 'GO3' id = 'GameObject_0' From alister.nospam.ware at ntlworld.com Tue Sep 29 06:00:16 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Tue, 29 Sep 2015 10:00:16 +0000 (UTC) Subject: Question re class variable References: <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> Message-ID: On Tue, 29 Sep 2015 02:27:23 -0700, plewto wrote: > I have a perplexing problem with Python 3 class variables. I wish to > generate an unique ID each time an instance of GameClass is created. > There are two versions of the __gen_id method with test run results for > each listed below the code. > > Originally I used the version which is now commented out. When a new > instance was created it created an ID by appending the value of > __instance_counter to the class name, it then checked the contents of of > __instatance_registrty to see if this ID was already in use. If so it > incremented the counter until it found an unused ID. This version works > exactly as I expected. > > Later I decided to get rid of __instance_registry and rely solely on the > restricted access to __instance_counter and the fact that it is > monotonically increasing to generate IDs. I wrote the second, simpler > version of __gen_id to that end, but it doesn't work! No doubt I'm > overlooking something very simple here but I'm not seeing it. > > Any help appreciated. > > > class GameObject: > > # __instance_registry = {"":None} > __instance_counter = 0 > > def __init__(self, name): > self.__name = str(name) > self.__id = self.__gen_id() > > # def __gen_id(self): > # ty = self.__class__.__name__ > # id = '' > # while id in self.__instance_registry: > # id = '%s_%d' % (ty, self.__instance_counter) > # self.__instance_counter += 1 # > self.__instance_registry[id] = self # return id > > def __gen_id(self): > ty = self.__class__.__name__ > id = '%s_%d' % (ty, self.__instance_counter) > self.__instance_counter += 1 return id > > def __str__(self): > return "name = '%s' id = '%s'" % (self.__name, self.__id) > > > go1 = GameObject("GO1") > go2 = GameObject("GO2") > go3 = GameObject("GO3") > print(go1) > print(go2) > print(go3) > > > # Results with original __gen_id method # name = 'GO1' id = > 'GameObject_0' > # name = 'GO2' id = 'GameObject_1' > # name = 'GO3' id = 'GameObject_2' > > > # Results with new simpler __gen_id method, __instance_counter not being > incremented # name = 'GO1' id = 'GameObject_0' > # name = 'GO2' id = 'GameObject_0' > # name = 'GO3' id = 'GameObject_0' why reinvent the wheel? why not simply use pythons builtin id function? each new instance of an object is automatically assigned a unique ID -- I'm a soldier, not a diplomat. I can only tell the truth. -- Kirk, "Errand of Mercy", stardate 3198.9 From antoon.pardon at rece.vub.ac.be Tue Sep 29 06:40:09 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 29 Sep 2015 12:40:09 +0200 Subject: Question re class variable In-Reply-To: <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> References: <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> Message-ID: <560A6A89.8020907@rece.vub.ac.be> Op 29-09-15 om 11:27 schreef plewto at gmail.com: > I have a perplexing problem with Python 3 class variables. I wish to generate an unique ID each time an instance of GameClass is created. There are two versions of the __gen_id method with test run results for each listed below the code. The problem is that in python you can't change a class variable through an instance. The moment you try, you create an instance attribute. > class GameObject: > > # __instance_registry = {"":None} > __instance_counter = 0 > > def __init__(self, name): > self.__name = str(name) > self.__id = self.__gen_id() > > def __gen_id(self): > ty = self.__class__.__name__ > id = '%s_%d' % (ty, self.__instance_counter) > self.__instance_counter += 1 This last line doesn't work as expected. What happens is equivallent to the following. self.__instance_counter = self.__instance_counter + 1 But the self.__instance_counter are two different things here. On the right hand python finds that self has no __instance_counter attribute so it will fetch the value from the class. However on the left hand, python will create an attribute for self and assign the value to it. Python will not rebind the class variable. -- Antoon Pardon From jeanmichel at sequans.com Tue Sep 29 07:02:12 2015 From: jeanmichel at sequans.com (jmp) Date: Tue, 29 Sep 2015 13:02:12 +0200 Subject: Question re class variable In-Reply-To: <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> References: <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> Message-ID: On 09/29/2015 11:27 AM, plewto at gmail.com wrote: > I have a perplexing problem with Python 3 class variables. Your problem is that when assigning values to your class attribute, you are actually creating a instance attribute. class Foo: bar = "I'm a class attribute" def __init__(self): self.bar = "I'm an instance attribute" def foo(self): print self.bar print Foo.bar # this is how you set a class attribute from an instance Foo.bar = "I am still a class attribute" print Foo.bar Foo.foo() I'm an instance attribute I'm a class attribute I am still a class attribute What can be confusing is that assuming you never use the same name for a class an instance attribute (that would be bad code), you can access your class attribute from the instance: class Foo: bar = "I'm a class attribute" def foo(self): # python will look into the class scope if not found in the instance print self.bar # this is not an assignment so we're fine Foo.foo() I'm an class attribute As side note and unrelated topic, your are using name mangling (attribute starting with __), are you sure you need it ? You need a strong motive to use this feature otherwise you're making things difficult for yourself without any benefit. Finally here's how I'd code your id, to give some idea on alternative ways: class GameObject: @property def id(self): return id(self) #use the builtin id function print GameObject().id Cheers, JM From jeanmichel at sequans.com Tue Sep 29 07:11:15 2015 From: jeanmichel at sequans.com (jmp) Date: Tue, 29 Sep 2015 13:11:15 +0200 Subject: Question re class variable In-Reply-To: References: <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> Message-ID: On 09/29/2015 01:02 PM, jmp wrote: > class GameObject: > > @property > def id(self): > return id(self) #use the builtin id function > > print GameObject().id > > Cheers, > > JM I should add that until you don't serialize your object you're fine. If you need to serialize it, you may want to look at https://docs.python.org/3/library/uuid.html import uuid class GameObject: def __init__(self): self._id = None @property def id(self): if self._id is None: # make a UUID based on the host ID and current time self._id = uuid.uuid1() return self._id From as at sci.fi Tue Sep 29 07:17:35 2015 From: as at sci.fi (Anssi Saari) Date: Tue, 29 Sep 2015 14:17:35 +0300 Subject: Question re class variable References: <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> Message-ID: Antoon Pardon writes: > Op 29-09-15 om 11:27 schreef plewto at gmail.com: >> I have a perplexing problem with Python 3 class variables. I wish to >> generate an unique ID each time an instance of GameClass is >> created. There are two versions of the __gen_id method with test run >> results for each listed below the code. > > The problem is that in python you can't change a class variable through an instance. The moment you > try, you create an instance attribute. That much is clear but why does his other version of __gen_id() work (after a fashion)? It doesn't increment the class variable but the instances get an incremental id. The function was like this: def __gen_id(self): ty = self.__class__.__name__ id = '' while id in self.__instance_registry: id = '%s_%d' % (ty, self.__instance_counter) self.__instance_counter += 1 self.__instance_registry[id] = self return id Also, is there any problem with incrementing GameObject.__instance_counter from __gen_id()? I guess not? From lac at openend.se Tue Sep 29 07:42:50 2015 From: lac at openend.se (Laura Creighton) Date: Tue, 29 Sep 2015 13:42:50 +0200 Subject: Create a .lua fle from Python In-Reply-To: References: Message-ID: <201509291142.t8TBgohl011066@fido.openend.se> In a message of Mon, 28 Sep 2015 18:41:09 -0300, Ariel Arga?araz writes: >Hi, >This is my first post, I would like to know if a library that can help me >with this. > > >I want to parse a XML fle with Python and save the data into a Lua table >called for example "newTable", then I want to create a "table.lua" fle with >the "newTable" write on it. > > >for example: > >the XML fle: cities.xml > > > > BuenosAires > 30 > > > Seatle > 25 > > > > >And I want to create a cities_temp.lua file > >cities_temps ={ >["Buenos Aires"] = 30, >["Seatle"] = 25, >} > > >Is that posible to do with LUPA (https://pypi.python.org/pypi/lupa)?? In >the docs I read that you can create lua tables but I did not see if there >is a way to create a .lua file with that table. > > >I could do it with python writing to a file line per line but i want some >more elegant. > >Can anyone give some help? > >Thanks. > >-- >Ariel Arga?araz Lupa is a partial re-write of lunatic python. https://pypi.python.org/pypi/lunatic-python with docs here: http://labix.org/lunatic-python and maybe that can do what you want. But I don't know why you need to involve python at all. Lua has perfectly good xml parsers, indeed like python -- perhaps too many of them. Can't you just use lua? Laura From antoon.pardon at rece.vub.ac.be Tue Sep 29 08:02:34 2015 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 29 Sep 2015 14:02:34 +0200 Subject: Question re class variable In-Reply-To: References: <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> Message-ID: <560A7DDA.2030401@rece.vub.ac.be> Op 29-09-15 om 13:17 schreef Anssi Saari: > Antoon Pardon writes: > >> Op 29-09-15 om 11:27 schreef plewto at gmail.com: >>> I have a perplexing problem with Python 3 class variables. I wish to >>> generate an unique ID each time an instance of GameClass is >>> created. There are two versions of the __gen_id method with test run >>> results for each listed below the code. >> The problem is that in python you can't change a class variable through an instance. The moment you >> try, you create an instance attribute. > That much is clear but why does his other version of __gen_id() work > (after a fashion)? It doesn't increment the class variable but the > instances get an incremental id. > > The function was like this: > > def __gen_id(self): > ty = self.__class__.__name__ > id = '' > while id in self.__instance_registry: > id = '%s_%d' % (ty, self.__instance_counter) > self.__instance_counter += 1 > self.__instance_registry[id] = self > return id Because you check against the class variable __instance_registry. That variable isn't rebound, it is mutated, so it remains a class variable and can thus be used to check which id's are already in use. So you increment your counter until the corresponding id is not in the __instance_registry. -- Antoon Pardon. From steve at pearwood.info Tue Sep 29 08:06:13 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 29 Sep 2015 22:06:13 +1000 Subject: Question re class variable References: <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> Message-ID: <560a7eb7$0$1607$c3e8da3$5496439d@news.astraweb.com> On Tue, 29 Sep 2015 09:17 pm, Anssi Saari wrote: [...] >> The problem is that in python you can't change a class variable through >> an instance. The moment you try, you create an instance attribute. > > That much is clear but why does his other version of __gen_id() work > (after a fashion)? It doesn't increment the class variable but the > instances get an incremental id. > > The function was like this: > > def __gen_id(self): > ty = self.__class__.__name__ > id = '' > while id in self.__instance_registry: > id = '%s_%d' % (ty, self.__instance_counter) > self.__instance_counter += 1 > self.__instance_registry[id] = self > return id This works because it doesn't assign to self.__instance_registry itself, it assigns to an item within the existing self.__instance_registry. So the registry object (a dict?) gets modified in place, not re-bound or shadowed by an instance attribute of the same name. -- Steven From gvanem at yahoo.no Tue Sep 29 08:44:49 2015 From: gvanem at yahoo.no (Gisle Vanem) Date: Tue, 29 Sep 2015 14:44:49 +0200 Subject: Issue: cannot successfully install Python 3 on Windows 7 In-Reply-To: References: Message-ID: <560A87C1.10406@yahoo.no> Gilad Mayani wrote: > I always get this message: > > the program can't start because api-ms-win-crt-runtime-I1-1-0.dll is missing from your computer. Is that really an 'I' in there? The .dll should really be named: %SystemRoot%\system32\api-ms-win-crt-runtime-l1-1-0.dll with an lower-case 'l'. (This .dll is itself a forwarder .dll to ucrtbase.dll). -- --gv From michel.casabianca at gmail.com Tue Sep 29 08:53:01 2015 From: michel.casabianca at gmail.com (casa) Date: Tue, 29 Sep 2015 05:53:01 -0700 (PDT) Subject: [ANN] pythenv Message-ID: <22dcbda0-d63f-45c8-89ff-a10d905e4c2d@googlegroups.com> Pythenv runs a Python script creating a virtualenv on the fly. Requirements may be passed as a requirements file or embedded in the Python script in a dedicated comment: # requirements: foo==1.2.3, bar This project is on Github: https://github.com/c4s4/pythenv Enjoy! From oscar.j.benjamin at gmail.com Tue Sep 29 10:12:39 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 29 Sep 2015 14:12:39 +0000 Subject: multiprocessing speedup In-Reply-To: References: Message-ID: On Tue, 29 Sep 2015 at 02:22 Rita wrote: > I am using the multiprocessing with apply_async to do some work. Each task > takes a few seconds but I have several thousand tasks. I was wondering if > there is a more efficient method and especially when I plan to operate on a > large memory arrays (numpy) > > Here is what I have now > import multiprocessing as mp > import random > > def f(x): > count=0 > for i in range(x): > x=random.random() > y=random.random() > if x*x + y*y<=1: > count+=1 > > return count > I assume you're using the code shown as a toy example of playing with the multiprocessing module? If not then the function f can be made much more efficient. The problem is that while it's good that you have distilled your problem into a simple program for testing it's not really possible to find a more efficient way without finding the bottleneck which means looking at the full problem. -- Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From oscar.j.benjamin at gmail.com Tue Sep 29 10:33:27 2015 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 29 Sep 2015 14:33:27 +0000 Subject: Issue: cannot successfully install Python 3 on Windows 7 In-Reply-To: References: Message-ID: On Tue, 29 Sep 2015 at 10:22 Gilad Mayani wrote: > Dear Python staff, > > I am trying to install the latest version of Python 3 on my machine, in > which I already have Python 2.7.3 installed. > I did this by downloading the installer from the 'Download Python 3.5.0' > button from https://www.python.org/downloads/. > BTW, the installer installs the 32-bit Python version. > > The installation seems to run smoothly, but when I try to then open Python > (by running "py -3" from the command line or opening the Python 3 IDLE) > I always get this message: > >> the program can't start because api-ms-win-crt-runtime-I1-1-0.dll is >> missing from your computer. > > Do you know how this can be solved? > It seems there are some teething problems with Python 3.5 on Windows. What's happening here is probably a bug in Python 3.5. It would be great if you could report it to the issue tracker: bugs.python.org In the meantime I suspect that you will have better luck installing Python 3.4. -- Oscar -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Tue Sep 29 10:44:40 2015 From: gordon at panix.com (John Gordon) Date: Tue, 29 Sep 2015 14:44:40 +0000 (UTC) Subject: Question re class variable References: <3948d9cd-24b1-4a3b-8ed0-46bb60a8d738@googlegroups.com> Message-ID: In alister writes: > why not simply use pythons builtin id function? > each new instance of an object is automatically assigned a unique ID It's only guaranteed to be unique for objects that exist at the same time. If an object is created and destroyed and then another new object is created, the ID of those two objects can be the same. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From jeanmichel at sequans.com Tue Sep 29 12:32:15 2015 From: jeanmichel at sequans.com (jmp) Date: Tue, 29 Sep 2015 18:32:15 +0200 Subject: Create a .lua fle from Python In-Reply-To: References: Message-ID: On 09/28/2015 11:41 PM, Ariel Arga?araz wrote: > Hi, > This is my first post, I would like to know if a library that can help > me with this. > > > I want to parse a XML fle with Python and save the data into a Lua table > called for example "newTable", then I want to create a "table.lua" fle > with the "newTable" write on it. > And I want to create a cities_temp.lua file > > cities_temps ={ > ["Buenos Aires"] = 30, > ["Seatle"] = 25, > } > Can anyone give some help? > > Thanks. > > -- > Ariel Arga?araz Use an xml parser to fetch the data from the xml file and use a template engine to generate the lua code. for instance, using bs4 (beautifulsoup) for xml and jinja2 for the template engine: import bs4 import jinja2 xml = """ BuenosAires 30 Seatle 25 """ lua_template = """ cities_temps ={ {%- for city, temp in cities.iteritems() %} ["{{city}}"] = {{temp}}, {%- endfor %} }""" xmlp = bs4.BeautifulSoup(xml, 'xml') # from xml to python dictionary data = {city.find('name').string:city.find('temperature').string for city in xmlp.findAll('city')} # from python dictionary to lua print jinja2.Template(lua_template).render(cities=data) will yield (python 2.7): cities_temps ={ ["BuenosAires"] = 30, ["Seatle"] = 25, } Cheers, jm From rgaddi at technologyhighland.invalid Tue Sep 29 12:48:14 2015 From: rgaddi at technologyhighland.invalid (Rob Gaddi) Date: Tue, 29 Sep 2015 16:48:14 +0000 (UTC) Subject: Check if a given value is out of certain range References: Message-ID: On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: > Hi, > > I know there is an elegant way to check if a given value is within > certain range. > Example - To check if x is between zero and ten, I can do 0 < x 10. > > Is there any similar elegant way to check if a value is out of certain > range? > Example - To check if x is either less than zero or greater than ten? > Right now I am using x < 0 or x > 10. > > Regards, > Laxmikant not (0 <= x <= 10) -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From __peter__ at web.de Tue Sep 29 13:28:24 2015 From: __peter__ at web.de (Peter Otten) Date: Tue, 29 Sep 2015 19:28:24 +0200 Subject: Create a .lua fle from Python References: Message-ID: jmp wrote: > On 09/28/2015 11:41 PM, Ariel Arga?araz wrote: >> Hi, >> This is my first post, I would like to know if a library that can help >> me with this. >> >> >> I want to parse a XML fle with Python and save the data into a Lua table >> called for example "newTable", then I want to create a "table.lua" fle >> with the "newTable" write on it. > >> And I want to create a cities_temp.lua file >> >> cities_temps ={ >> ["Buenos Aires"] = 30, >> ["Seatle"] = 25, >> } >> Can anyone give some help? >> >> Thanks. >> >> -- >> Ariel Arga?araz > > Use an xml parser to fetch the data from the xml file and use a template > engine to generate the lua code. > > for instance, using bs4 (beautifulsoup) for xml and jinja2 for the > template engine: > > import bs4 > import jinja2 > > xml = """ > > BuenosAires > 30 > > > Seatle > 25 > > """ > > lua_template = """ > cities_temps ={ > {%- for city, temp in cities.iteritems() %} > ["{{city}}"] = {{temp}}, > {%- endfor %} > }""" > > xmlp = bs4.BeautifulSoup(xml, 'xml') > # from xml to python dictionary > data = {city.find('name').string:city.find('temperature').string for > city in xmlp.findAll('city')} > # from python dictionary to lua > print jinja2.Template(lua_template).render(cities=data) > > > will yield (python 2.7): > > cities_temps ={ > ["BuenosAires"] = 30, > ["Seatle"] = 25, > } Is Ariel's xml file user-supplied? If so, how does your suggestion prevent the resulting lua script from executing arbitrary code? From facundobatista at gmail.com Tue Sep 29 14:06:16 2015 From: facundobatista at gmail.com (Facundo Batista) Date: Tue, 29 Sep 2015 15:06:16 -0300 Subject: [ANN] pythenv In-Reply-To: <38be4fa0-ca14-48aa-9411-1c3a7facba82@googlegroups.com> References: <38be4fa0-ca14-48aa-9411-1c3a7facba82@googlegroups.com> Message-ID: On Tue, Sep 29, 2015 at 10:14 AM, wrote: > Pythenv runs a Python script creating a virtualenv on the fly. Requirements may be passed as a requirements file or embedded in the Python script in a dedicated comment: > > # requirements: foo==1.2.3, bar > > This project is on Github: > > https://github.com/c4s4/pythenv Hi Michel! You may be interested in fades: https://pypi.python.org/pypi/fades fades does something similar, but also support receivng the parameters one by one in comand line, or through a requirements.txt file, or in a comment in the script, or in the scripts docstring. It also supports running any installed python version, even ipython. And you're not forced to run a python script! you can open an interactive interpreter inside the virtualenv, or directly execute anything inside the virtualenv. Regards, -- . Facundo Blog: http://www.taniquetil.com.ar/plog/ PyAr: http://www.python.org/ar/ Twitter: @facundobatista From breamoreboy at yahoo.co.uk Tue Sep 29 16:32:26 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 29 Sep 2015 21:32:26 +0100 Subject: Check if a given value is out of certain range In-Reply-To: References: Message-ID: On 29/09/2015 17:48, Rob Gaddi wrote: > On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: > >> Hi, >> >> I know there is an elegant way to check if a given value is within >> certain range. >> Example - To check if x is between zero and ten, I can do 0 < x 10. >> >> Is there any similar elegant way to check if a value is out of certain >> range? >> Example - To check if x is either less than zero or greater than ten? >> Right now I am using x < 0 or x > 10. >> >> Regards, >> Laxmikant > > not (0 <= x <= 10) > Yuck. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From random832 at fastmail.com Tue Sep 29 17:04:32 2015 From: random832 at fastmail.com (Random832) Date: Tue, 29 Sep 2015 17:04:32 -0400 Subject: Check if a given value is out of certain range In-Reply-To: References: Message-ID: <1443560672.3996136.396949593.363A855B@webmail.messagingengine.com> On Tue, Sep 29, 2015, at 16:32, Mark Lawrence wrote: > On 29/09/2015 17:48, Rob Gaddi wrote: > > On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: > > > >> Hi, > >> > >> I know there is an elegant way to check if a given value is within > >> certain range. > >> Example - To check if x is between zero and ten, I can do 0 < x 10. > >> > >> Is there any similar elegant way to check if a value is out of certain > >> range? > >> Example - To check if x is either less than zero or greater than ten? > >> Right now I am using x < 0 or x > 10. > >> > >> Regards, > >> Laxmikant > > > > not (0 <= x <= 10) > > > > Yuck. How about x not in range(11)? From emile at fenx.com Tue Sep 29 17:07:23 2015 From: emile at fenx.com (Emile van Sebille) Date: Tue, 29 Sep 2015 14:07:23 -0700 Subject: Check if a given value is out of certain range In-Reply-To: <1443560672.3996136.396949593.363A855B@webmail.messagingengine.com> References: <1443560672.3996136.396949593.363A855B@webmail.messagingengine.com> Message-ID: On 9/29/2015 2:04 PM, Random832 wrote: > On Tue, Sep 29, 2015, at 16:32, Mark Lawrence wrote: >>> >>> not (0 <= x <= 10) >>> >> >> Yuck. > > How about x not in range(11)? x = 5.5 Emile From ian.g.kelly at gmail.com Tue Sep 29 17:07:42 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 29 Sep 2015 15:07:42 -0600 Subject: Check if a given value is out of certain range In-Reply-To: <1443560672.3996136.396949593.363A855B@webmail.messagingengine.com> References: <1443560672.3996136.396949593.363A855B@webmail.messagingengine.com> Message-ID: On Tue, Sep 29, 2015 at 3:04 PM, Random832 wrote: > How about x not in range(11)? That's fine as long as x is known to only take integral values. From TBarnett at primeinc.com Tue Sep 29 17:40:08 2015 From: TBarnett at primeinc.com (Tom Barnett) Date: Tue, 29 Sep 2015 21:40:08 +0000 Subject: Installing Python 3.5 fails Message-ID: <47623d544508444695a88cf1a7985fac@NTEX1.primeinc.com> I do have a fresh successful install of Visual Studio 2015 Redistributables installed. Then I reinstalled Python 3.5 and still now joy. What am I missing? Tom Tom Barnett Senior Systems Administrator Prime, inc. 2740 N. Mayfair Springfield, MO 65803 Ph. 417.866.0001 Fax 417.521.6863 * Before printing this e-mail, please verify it is necessary. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Picture (Device Independent Bitmap) 1.jpg Type: image/jpeg Size: 15466 bytes Desc: Picture (Device Independent Bitmap) 1.jpg URL: From denismfmcmahon at gmail.com Tue Sep 29 19:12:05 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 29 Sep 2015 23:12:05 +0000 (UTC) Subject: Check if a given value is out of certain range References: Message-ID: On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: > Is there any similar elegant way to check if a value is out of certain > range? What about: if not (0 < x < 10): -- Denis McMahon, denismfmcmahon at gmail.com From python.list at tim.thechases.com Tue Sep 29 19:44:33 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 29 Sep 2015 18:44:33 -0500 Subject: Check if a given value is out of certain range In-Reply-To: References: Message-ID: <20150929184433.5ee1bc8a@bigbox.christie.dr> On 2015-09-29 21:32, Mark Lawrence wrote: > On 29/09/2015 17:48, Rob Gaddi wrote: > >> Is there any similar elegant way to check if a value is out of > >> certain range? > >> Example - To check if x is either less than zero or greater than > >> ten? Right now I am using x < 0 or x > 10. > > > > not (0 <= x <= 10) > > Yuck. Not sure there's much "yuck" to be had there. It's succinct, easy to read, and correct. The only improvement might be if you have things to do in both cases, in which case remove the "not" and set the clauses accordingly: if 0 <= x <= 10: success_within_range(x) else: fail_out_of_bounds(x) -tkc From rmorgan466 at gmail.com Tue Sep 29 20:50:43 2015 From: rmorgan466 at gmail.com (Rita) Date: Tue, 29 Sep 2015 20:50:43 -0400 Subject: multiprocessing speedup In-Reply-To: References: Message-ID: Thanks for the responses. I will create another thread to supply a more realistic example. On Tue, Sep 29, 2015 at 10:12 AM, Oscar Benjamin wrote: > On Tue, 29 Sep 2015 at 02:22 Rita wrote: > >> I am using the multiprocessing with apply_async to do some work. Each >> task takes a few seconds but I have several thousand tasks. I was wondering >> if there is a more efficient method and especially when I plan to operate >> on a large memory arrays (numpy) >> > >> Here is what I have now >> > import multiprocessing as mp >> import random >> >> def f(x): >> count=0 >> for i in range(x): >> x=random.random() >> y=random.random() >> if x*x + y*y<=1: >> count+=1 >> >> return count >> > > I assume you're using the code shown as a toy example of playing with the > multiprocessing module? If not then the function f can be made much more > efficient. > > The problem is that while it's good that you have distilled your problem > into a simple program for testing it's not really possible to find a more > efficient way without finding the bottleneck which means looking at the > full problem. > > -- > Oscar > -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at pearwood.info Tue Sep 29 21:55:57 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 30 Sep 2015 11:55:57 +1000 Subject: Check if a given value is out of certain range References: <1443560672.3996136.396949593.363A855B@webmail.messagingengine.com> Message-ID: <560b412e$0$1616$c3e8da3$5496439d@news.astraweb.com> On Wed, 30 Sep 2015 07:07 am, Ian Kelly wrote: > On Tue, Sep 29, 2015 at 3:04 PM, Random832 wrote: >> How about x not in range(11)? > > That's fine as long as x is known to only take integral values. It's not fine. In Python 2, it's painfully slow and inefficient, both memory-wise and algorithmically: -1 in range(100000000) # test 0 <= -1 <= 100000000 This first creates a list of 100000000 integers, then compares each and every one of them against -1 before returning False. Using xrange instead at least avoids building the list first, but it still compares -1 against each value. Testing a numeric value within a certain range of values should be constant time and constant memory. It should be *fast*. Using range in Python 2 is none of those things. -- Steven From luisjosenovoa at gmail.com Tue Sep 29 21:58:19 2015 From: luisjosenovoa at gmail.com (LJ) Date: Tue, 29 Sep 2015 18:58:19 -0700 (PDT) Subject: pypy - Gurobi solver library Message-ID: Hi All, I use gurobipy to model a large scale optimization problem. Is there a way to use pypy with the gurobipy library? Has anyone done this? Thanks. From marfig at gmx.com Tue Sep 29 22:37:46 2015 From: marfig at gmx.com (Mario Figueiredo) Date: Wed, 30 Sep 2015 03:37:46 +0100 Subject: Linux Mint installation of Python 3.5 Message-ID: <560B4AFA.2040305@gmx.com> Hello everyone, Under Linux Mint it is not a good idea to just go ahead and replace the system installed Python versions and their packages. And yet I wish to both update the 3.4 modules and install Python 3.5. I understand that for the first I just need to use virtualenv. But how can I safely install Python 3.5 from sources into a Linux Mint box without damaging the OS? From rosuav at gmail.com Tue Sep 29 22:44:27 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Sep 2015 12:44:27 +1000 Subject: Linux Mint installation of Python 3.5 In-Reply-To: <560B4AFA.2040305@gmx.com> References: <560B4AFA.2040305@gmx.com> Message-ID: On Wed, Sep 30, 2015 at 12:37 PM, Mario Figueiredo wrote: > Under Linux Mint it is not a good idea to just go ahead and replace the > system installed Python versions and their packages. And yet I wish to > both update the 3.4 modules and install Python 3.5. I understand that > for the first I just need to use virtualenv. > > But how can I safely install Python 3.5 from sources into a Linux Mint > box without damaging the OS? The easiest way to install something from source is to use 'make altinstall' for the final step. That should install you a 'python3.5' binary without touching the 'python3' binary. That said, though, it's entirely possible that upgrading 'python3' from 3.4 to 3.5 won't actually break anything; it won't break any script that explicitly looks for python3.4, and there's not a huge amount of breakage. But to be on the safe side, use altinstall and explicitly ask for python3.5 any time you want it. Personally, I use the regular 'make install', but that's because I'm on Debian - the system Python is 2.7. ChrisA From marfig at gmx.com Tue Sep 29 23:00:24 2015 From: marfig at gmx.com (Mario Figueiredo) Date: Wed, 30 Sep 2015 04:00:24 +0100 Subject: Linux Mint installation of Python 3.5 In-Reply-To: References: <560B4AFA.2040305@gmx.com> Message-ID: <560B5048.50100@gmx.com> On 09/30/2015 03:44 AM, Chris Angelico wrote: > > The easiest way to install something from source is to use 'make > altinstall' for the final step. That should install you a 'python3.5' > binary without touching the 'python3' binary. That said, though, it's > entirely possible that upgrading 'python3' from 3.4 to 3.5 won't > actually break anything; it won't break any script that explicitly > looks for python3.4, and there's not a huge amount of breakage. But to > be on the safe side, use altinstall and explicitly ask for python3.5 > any time you want it. > Thank you Chris. That will set me on my path. > Personally, I use the regular 'make install', but that's because I'm > on Debian - the system Python is 2.7. Unfortunately Ubuntu based distros are going through a 2.x to 3.x transition period. Both Pythons are installed and are system dependencies. And their finicky dependency on Python really make these distros not very friendly for Python development. If I do end up successfully upgrading from 3.4 to 3.5, I will most likely forfeit my ability to upgrade the Mint version in the future without a full system installation. So the solution is to just maintain 3 different versions of python my machine. Ridiculous. From random832 at fastmail.com Tue Sep 29 23:08:51 2015 From: random832 at fastmail.com (Random832) Date: Tue, 29 Sep 2015 23:08:51 -0400 Subject: Check if a given value is out of certain range References: <1443560672.3996136.396949593.363A855B@webmail.messagingengine.com> <560b412e$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano writes: > It's not fine. In Python 2, >... > Testing a numeric value within a certain range of values should be constant > time and constant memory. It should be *fast*. Using range in Python 2 is > none of those things. I wasn't aware we were discussing Python 2. From zachary.ware+pylist at gmail.com Tue Sep 29 23:14:06 2015 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Tue, 29 Sep 2015 22:14:06 -0500 Subject: Linux Mint installation of Python 3.5 In-Reply-To: <560B5048.50100@gmx.com> References: <560B4AFA.2040305@gmx.com> <560B5048.50100@gmx.com> Message-ID: On Tue, Sep 29, 2015 at 10:00 PM, Mario Figueiredo wrote: > On 09/30/2015 03:44 AM, Chris Angelico wrote: >> >> The easiest way to install something from source is to use 'make >> altinstall' for the final step. That should install you a 'python3.5' >> binary without touching the 'python3' binary. That said, though, it's >> entirely possible that upgrading 'python3' from 3.4 to 3.5 won't >> actually break anything; it won't break any script that explicitly >> looks for python3.4, and there's not a huge amount of breakage. But to >> be on the safe side, use altinstall and explicitly ask for python3.5 >> any time you want it. >> > > Thank you Chris. That will set me on my path. > >> Personally, I use the regular 'make install', but that's because I'm >> on Debian - the system Python is 2.7. > > Unfortunately Ubuntu based distros are going through a 2.x to 3.x > transition period. Both Pythons are installed and are system dependencies. > > And their finicky dependency on Python really make these distros not > very friendly for Python development. If I do end up successfully > upgrading from 3.4 to 3.5, I will most likely forfeit my ability to > upgrade the Mint version in the future without a full system > installation. So the solution is to just maintain 3 different versions > of python my machine. Ridiculous. It should be no problem to just do `./configure && make profile_opt && make install`. The default prefix is /usr/local/; the system python's prefix is /usr/. Assuming /usr/local/bin is on your PATH before /usr/bin, 'python3' from your shell will be python3.5, but all system scripts should be using /usr/bin/python3 explicitly (if not, it's a bug; report it to Mint). Let the system take care of its own 3.4, you can ignore it and use 3.5. You won't be able to use apt-get to install packages for 3.5, but since you're using 3.5.0 less than a month after release, I assume you want more up-to-date packages anyway :). Just use pip for any global packages you want for 3.5, and both venv and pip for any packages you don't want to be global. -- Zach From steve at pearwood.info Tue Sep 29 23:14:40 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 30 Sep 2015 13:14:40 +1000 Subject: Check if a given value is out of certain range References: <1443560672.3996136.396949593.363A855B@webmail.messagingengine.com> <560b412e$0$1616$c3e8da3$5496439d@news.astraweb.com> Message-ID: <560b53a1$0$1585$c3e8da3$5496439d@news.astraweb.com> On Wed, 30 Sep 2015 01:08 pm, Random832 wrote: > Steven D'Aprano writes: >> It's not fine. In Python 2, >>... >> Testing a numeric value within a certain range of values should be >> constant time and constant memory. It should be *fast*. Using range in >> Python 2 is none of those things. > > I wasn't aware we were discussing Python 2. Was there something in the OP's question that suggested to you that we were only discussing Python 3? Python 2.7 is still the main version used by most people. -- Steven From rosuav at gmail.com Tue Sep 29 23:15:33 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Sep 2015 13:15:33 +1000 Subject: Linux Mint installation of Python 3.5 In-Reply-To: <560B5048.50100@gmx.com> References: <560B4AFA.2040305@gmx.com> <560B5048.50100@gmx.com> Message-ID: On Wed, Sep 30, 2015 at 1:00 PM, Mario Figueiredo wrote: >> Personally, I use the regular 'make install', but that's because I'm >> on Debian - the system Python is 2.7. > > Unfortunately Ubuntu based distros are going through a 2.x to 3.x > transition period. Both Pythons are installed and are system dependencies. > > And their finicky dependency on Python really make these distros not > very friendly for Python development. If I do end up successfully > upgrading from 3.4 to 3.5, I will most likely forfeit my ability to > upgrade the Mint version in the future without a full system > installation. So the solution is to just maintain 3 different versions > of python my machine. Ridiculous. Three different Python versions? Ehh, no big deal. rosuav at sikorsky:~$ python2 --version Python 2.7.9 rosuav at sikorsky:~$ python3.4 --version Python 3.4.2 rosuav at sikorsky:~$ python3.5 --version Python 3.5.0b1+ rosuav at sikorsky:~$ python3.6 --version Python 3.6.0a0 rosuav at sikorsky:~$ pypy --version Python 2.7.8 (2.4.0+dfsg-3, Dec 20 2014, 13:30:46) [PyPy 2.4.0 with GCC 4.9.2] rosuav at sikorsky:~$ jython --version "my" variable $jythonHome masks earlier declaration in same scope at /usr/bin/jython line 15. Jython 2.5.3 And Steven D'Aprano probably can beat that by an order of magnitude. Keep your multiple interpreters around; it doesn't hurt. Unless you're seriously bothered by disk space issues, the biggest cost is keeping track of which one you've installed some third-party package into. ChrisA From steve at pearwood.info Tue Sep 29 23:23:57 2015 From: steve at pearwood.info (Steven D'Aprano) Date: Wed, 30 Sep 2015 13:23:57 +1000 Subject: Linux Mint installation of Python 3.5 References: <560B4AFA.2040305@gmx.com> Message-ID: <560b55cf$0$1596$c3e8da3$5496439d@news.astraweb.com> On Wed, 30 Sep 2015 01:00 pm, Mario Figueiredo wrote: > So the solution is to just maintain 3 different versions > of python my machine. Ridiculous. Not at all. It's not like a Python install is that big -- Python 3.3 is only about 150MB. It's a little sad that Ubuntu isn't able to transition between 2 and 3 in one release, but that's their problem, not yours. You shouldn't be touching the system Python(s), you should leave that for Ubuntu to upgrade. I think that it is generally a good idea to keep your development Python separate from the system Python, even if they use the same version. That way, even if you accidentally break your development Python, the system Python will continue to work. -- Steven From rosuav at gmail.com Tue Sep 29 23:36:01 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Sep 2015 13:36:01 +1000 Subject: Linux Mint installation of Python 3.5 In-Reply-To: <560b55cf$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <560B4AFA.2040305@gmx.com> <560b55cf$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 30, 2015 at 1:23 PM, Steven D'Aprano wrote: > I think that it is generally a good idea to keep your development Python > separate from the system Python, even if they use the same version. That > way, even if you accidentally break your development Python, the system > Python will continue to work. What, you don't enjoy fixing a broken Python using no tool that itself requires Python? Where's the fun in a boring life?!? ChrisA From ian.g.kelly at gmail.com Wed Sep 30 01:54:03 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 29 Sep 2015 23:54:03 -0600 Subject: Check if a given value is out of certain range In-Reply-To: <560b53a1$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <1443560672.3996136.396949593.363A855B@webmail.messagingengine.com> <560b412e$0$1616$c3e8da3$5496439d@news.astraweb.com> <560b53a1$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 29, 2015 at 9:14 PM, Steven D'Aprano wrote: > On Wed, 30 Sep 2015 01:08 pm, Random832 wrote: > >> Steven D'Aprano writes: >>> It's not fine. In Python 2, >>>... >>> Testing a numeric value within a certain range of values should be >>> constant time and constant memory. It should be *fast*. Using range in >>> Python 2 is none of those things. >> >> I wasn't aware we were discussing Python 2. > > Was there something in the OP's question that suggested to you that we were > only discussing Python 3? > > Python 2.7 is still the main version used by most people. As far as I'm concerned, Python is Python 3. I'm aware that the check is inefficient in Python 2, but I tire of constantly pointing out Python 2 as the exception to everything. From otlucaDELETE at DELETEyahoo.it Wed Sep 30 01:57:22 2015 From: otlucaDELETE at DELETEyahoo.it (Luca Menegotto) Date: Wed, 30 Sep 2015 07:57:22 +0200 Subject: Check if a given value is out of certain range References: Message-ID: Il 29/09/2015 23:04, Random832 ha scritto: > How about x not in range(11)? > Remember: simpler is better. -- Ciao! Luca From lac at openend.se Wed Sep 30 01:59:47 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 30 Sep 2015 07:59:47 +0200 Subject: pypy - Gurobi solver library In-Reply-To: References: Message-ID: <201509300559.t8U5xmUn027053@fido.openend.se> In a message of Tue, 29 Sep 2015 18:58:19 -0700, LJ writes: >Hi All, > >I use gurobipy to model a large scale optimization problem. Is there a way to use pypy with the gurobipy library? Has anyone done this? > >Thanks. I don't think so. I think that gurobipy depends on having all of numpy working, and pypy isn't there yet. But you can ask this one on pypy-dev at python.org in case there is somebody there who has done such a thing. Laura From katewinslet626 at gmail.com Wed Sep 30 02:04:47 2015 From: katewinslet626 at gmail.com (shiva upreti) Date: Tue, 29 Sep 2015 23:04:47 -0700 (PDT) Subject: ConnectionError handling problem In-Reply-To: References: <550e9854-1247-4f6b-b9c7-7c8d7ea6ae37@googlegroups.com> Message-ID: On Friday, September 25, 2015 at 12:55:01 PM UTC+5:30, Cameron Simpson wrote: > On 24Sep2015 22:46, shiva upreti wrote: > >On Friday, September 25, 2015 at 10:55:45 AM UTC+5:30, Cameron Simpson wrote: > >> On 24Sep2015 20:57, shiva upreti wrote: > >> >Thank you Cameron. > >> >I think the problem with my code is that it just hangs without raising any > >> >exceptions. And as mentioned by Laura above that when I press CTRL+C, it > >> >just catches that exception and prints ConnectionError which is definitely > >> >a lie in this case as you mentioned. > > Ok. You original code says: > > try: > r=requests.post(url, data=query_args) > except: > print "Connection error" > > and presumably we think your code is hanging inside the requests.post call? You > should probably try to verify that, because if it is elsewhere you need to > figure out where (lots of print statements is a first start on that). > > I would open two terminals. Run your program until it hangs in one. > > While it is hung, examine the network status. I'll presume you're on a UNIX > system of some kind, probably Linux? If not it may be harder (or just require > someone other than me). > > If it is hung in the .post call, quite possibly it has an established connecion > to the target server - maybe that server is hanging. > > The shell command: > > netstat -rn | fgrep 172.16.68.6 | fgrep 8090 > > will show every connection to your server hosting the URL > "http://172.16.68.6:8090/login.xml". That will tell you if you have a > connection (if you are the only person doing the connecting from your machine). > > If you have the "lsof" program (possibly in /usr/sbin, so "/usr/sbin/lsof") you > can also examine the state of your hung Python program. This: > > lsof -p 12345 > > will report on the open files and network connections of the process with pid > 12345. Adjust to suit: you can find your program's pid ("process id") with the > "ps" command, or by backgrounding your program an issuing the "jobs" command, > which should show the process id more directly. > > Cheers, > Cameron Simpson Hi Cameron. Yes I use ubuntu 14.04. I will try what you suggested. But I cant understand one thing, for whatever reason the script is hanging, why does it resumes almost instantaneously when I press CTRL+C. Thanks. From lac at openend.se Wed Sep 30 04:12:59 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 30 Sep 2015 10:12:59 +0200 Subject: Installing Python 3.5 fails In-Reply-To: <47623d544508444695a88cf1a7985fac@NTEX1.primeinc.com> References: <47623d544508444695a88cf1a7985fac@NTEX1.primeinc.com> Message-ID: <201509300812.t8U8CxNV004455@fido.openend.se> In a message of Tue, 29 Sep 2015 21:40:08 -0000, Tom Barnett writes: > > > >I do have a fresh successful install of Visual Studio 2015 Redistributables installed. > >Then I reinstalled Python 3.5 and still now joy. > >What am I missing? > >Tom (It's another missing api-ms-win-crt-runtime-l1-1-0.dll) You are probably doing nothing wrong. 3.5 has a completely new installer. Are you on Vista by any chance? You may have this problem https://bugs.python.org/issue25223 and maybe installing the universal crt update mentioned there will help you. If not, open a separate issue in the tracker. Sorry about this. Laura From jeanmichel at sequans.com Wed Sep 30 05:21:07 2015 From: jeanmichel at sequans.com (jmp) Date: Wed, 30 Sep 2015 11:21:07 +0200 Subject: Create a .lua fle from Python In-Reply-To: References: Message-ID: On 09/29/2015 07:28 PM, Peter Otten wrote: > jmp wrote: >> import bs4 >> import jinja2 >> >> xml = """ >> >> BuenosAires >> 30 >> >> >> Seatle >> 25 >> >> """ >> >> lua_template = """ >> cities_temps ={ >> {%- for city, temp in cities.iteritems() %} >> ["{{city}}"] = {{temp}}, >> {%- endfor %} >> }""" >> >> xmlp = bs4.BeautifulSoup(xml, 'xml') >> # from xml to python dictionary >> data = {city.find('name').string:city.find('temperature').string for >> city in xmlp.findAll('city')} >> # from python dictionary to lua >> print jinja2.Template(lua_template).render(cities=data) >> >> >> will yield (python 2.7): >> >> cities_temps ={ >> ["BuenosAires"] = 30, >> ["Seatle"] = 25, >> } > > Is Ariel's xml file user-supplied? If so, how does your suggestion prevent > the resulting lua script from executing arbitrary code? It does not. Like it doesn't fulfill the millions of possible requirements the OP could have written but did not. What if the OP want a thread safe, super fast, multi core solution distributed on multiple remote hosts ? jm From alister.nospam.ware at ntlworld.com Wed Sep 30 05:41:51 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 30 Sep 2015 09:41:51 +0000 (UTC) Subject: Check if a given value is out of certain range References: Message-ID: On Tue, 29 Sep 2015 18:44:33 -0500, Tim Chase wrote: > On 2015-09-29 21:32, Mark Lawrence wrote: >> On 29/09/2015 17:48, Rob Gaddi wrote: >> >> Is there any similar elegant way to check if a value is out of >> >> certain range? >> >> Example - To check if x is either less than zero or greater than >> >> ten? Right now I am using x < 0 or x > 10. >> > >> > not (0 <= x <= 10) >> >> Yuck. > > Not sure there's much "yuck" to be had there. It's succinct, easy to > read, and correct. The only improvement might be if you have things to > do in both cases, in which case remove the "not" and set the clauses > accordingly: > > if 0 <= x <= 10: > success_within_range(x) > else: > fail_out_of_bounds(x) > > -tkc I would stick with the OP's current solution Readability Counts! -- BUFFERS=20 FILES=15 2nd down, 4th quarter, 5 yards to go! From sagarjo125 at gmail.com Wed Sep 30 08:36:40 2015 From: sagarjo125 at gmail.com (Sagar Joshi) Date: Wed, 30 Sep 2015 05:36:40 -0700 Subject: failure in installing Message-ID: hey, there is a failure installing python3.5.0 in my PC can u help -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Sep 30 08:52:38 2015 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Sep 2015 22:52:38 +1000 Subject: failure in installing In-Reply-To: References: Message-ID: On Wed, Sep 30, 2015 at 10:36 PM, Sagar Joshi wrote: > hey, there is a failure installing python3.5.0 in my PC can u help yes ChrisA PS. If my response wasn't helpful enough, it's because your question wasn't helpful enough. You'll need to give us a lot more information, such as your platform, what went wrong, etc. From PointedEars at web.de Wed Sep 30 09:16:06 2015 From: PointedEars at web.de (Thomas 'PointedEars' Lahn) Date: Wed, 30 Sep 2015 15:16:06 +0200 Subject: failure in installing References: Message-ID: <5311512.75zt12J0Aq@PointedEars.de> Sagar Joshi wrote: > hey, there is a failure installing python3.5.0 in my PC can u help -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail. From breamoreboy at yahoo.co.uk Wed Sep 30 09:45:59 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 30 Sep 2015 14:45:59 +0100 Subject: failure in installing In-Reply-To: References: Message-ID: On 30/09/2015 13:36, Sagar Joshi wrote: > hey, there is a failure installing python3.5.0 in my PC can u help > Not directly, as once again both my main and spare crystal balls are at the menders due to over use. However should you decide to tell us what OS version you've got, exactly what you tried to do and exactly what went wrong I'm sure that somebody can help, even if it is stating that it's a known problem and has all ready been reported on the bug tracker. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From invalid at invalid.invalid Wed Sep 30 10:11:52 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 30 Sep 2015 14:11:52 +0000 (UTC) Subject: failure in installing References: Message-ID: On 2015-09-30, Sagar Joshi wrote: > hey, there is a failure installing python3.5.0 in my PC can u help No. Or yes. It depends. -- Grant Edwards grant.b.edwards Yow! Somewhere in DOWNTOWN at BURBANK a prostitute is gmail.com OVERCOOKING a LAMB CHOP!! From pip7kids at gmail.com Wed Sep 30 11:25:40 2015 From: pip7kids at gmail.com (pip7kids at gmail.com) Date: Wed, 30 Sep 2015 08:25:40 -0700 (PDT) Subject: Oracle connect Message-ID: <5219a22f-c9e7-4206-8d5c-496678800fbe@googlegroups.com> Hi New to Python and just downloaded 3.5 Trying to connect to Oracle but failing - eg import cx_oracle connstr = 'userid/password@@99.999.9.99:PORT/SID' connection = cx_oracle.connect(connstr) cursor = connection.cursor() cursor.execute("SELECT * FROM MYTABLE WHERE ROWNUM <=100") cursor.close() connection.close() Getting error No module named 'cx_oracle' Any examples or should I use an earlier version of Python. Regards From larry.martell at gmail.com Wed Sep 30 11:34:50 2015 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 30 Sep 2015 11:34:50 -0400 Subject: Oracle connect In-Reply-To: <5219a22f-c9e7-4206-8d5c-496678800fbe@googlegroups.com> References: <5219a22f-c9e7-4206-8d5c-496678800fbe@googlegroups.com> Message-ID: On Wed, Sep 30, 2015 at 11:25 AM, wrote: > Hi > New to Python and just downloaded 3.5 > Trying to connect to Oracle but failing - eg > > import cx_oracle > connstr = 'userid/password@@99.999.9.99:PORT/SID' > connection = cx_oracle.connect(connstr) > cursor = connection.cursor() > cursor.execute("SELECT * FROM MYTABLE WHERE ROWNUM <=100") > cursor.close() > connection.close() > > Getting error No module named 'cx_oracle' Did you install cx_oracle? If not, do this: pip install cx_Oracle Also, there is a cx_oracle mailing list. From gordon at panix.com Wed Sep 30 11:42:59 2015 From: gordon at panix.com (John Gordon) Date: Wed, 30 Sep 2015 15:42:59 +0000 (UTC) Subject: Check if a given value is out of certain range References: Message-ID: In alister writes: > I would stick with the OP's current solution > Readability Counts! I agree. 'if x < 0 or x > 10' is perfectly fine. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From invalid at invalid.invalid Wed Sep 30 11:56:31 2015 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 30 Sep 2015 15:56:31 +0000 (UTC) Subject: Check if a given value is out of certain range References: Message-ID: On 2015-09-30, alister wrote: > On Tue, 29 Sep 2015 18:44:33 -0500, Tim Chase wrote: > >> On 2015-09-29 21:32, Mark Lawrence wrote: >>> On 29/09/2015 17:48, Rob Gaddi wrote: >>> >> Is there any similar elegant way to check if a value is out of >>> >> certain range? >>> >> Example - To check if x is either less than zero or greater than >>> >> ten? Right now I am using x < 0 or x > 10. >>> > >>> > not (0 <= x <= 10) >>> >>> Yuck. >> >> Not sure there's much "yuck" to be had there. It's succinct, easy to >> read, and correct. The only improvement might be if you have things to >> do in both cases, in which case remove the "not" and set the clauses >> accordingly: >> >> if 0 <= x <= 10: >> success_within_range(x) >> else: >> fail_out_of_bounds(x) >> >> -tkc > > I would stick with the OP's current solution > > Readability Counts! I'm baffled. If the condition we are trying to check for is when "x is not within a range of 0-10 inclusive" then this is as readable as it gets: not (0 <= x <= 10) (I) That's pretty much a literal, word-for-word translation of the requirement into code. Sure, you can can apply De Morgans theorom to transform that into (x < 0) or (x > 10) (II) That's just as correct, but now the code is one step removed from the requirement statement. IMO, (I) is _more_ readable than (II) -- Grant Edwards grant.b.edwards Yow! Boy, am I glad it's at only 1971... gmail.com From python at mrabarnett.plus.com Wed Sep 30 13:05:05 2015 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 30 Sep 2015 18:05:05 +0100 Subject: Linux Mint installation of Python 3.5 In-Reply-To: References: <560B4AFA.2040305@gmx.com> <560B5048.50100@gmx.com> Message-ID: <560C1641.1060003@mrabarnett.plus.com> On 2015-09-30 04:15, Chris Angelico wrote: > On Wed, Sep 30, 2015 at 1:00 PM, Mario Figueiredo wrote: >>> Personally, I use the regular 'make install', but that's because I'm >>> on Debian - the system Python is 2.7. >> >> Unfortunately Ubuntu based distros are going through a 2.x to 3.x >> transition period. Both Pythons are installed and are system dependencies. >> >> And their finicky dependency on Python really make these distros not >> very friendly for Python development. If I do end up successfully >> upgrading from 3.4 to 3.5, I will most likely forfeit my ability to >> upgrade the Mint version in the future without a full system >> installation. So the solution is to just maintain 3 different versions >> of python my machine. Ridiculous. > > Three different Python versions? Ehh, no big deal. > > rosuav at sikorsky:~$ python2 --version > Python 2.7.9 > rosuav at sikorsky:~$ python3.4 --version > Python 3.4.2 > rosuav at sikorsky:~$ python3.5 --version > Python 3.5.0b1+ > rosuav at sikorsky:~$ python3.6 --version > Python 3.6.0a0 > rosuav at sikorsky:~$ pypy --version > Python 2.7.8 (2.4.0+dfsg-3, Dec 20 2014, 13:30:46) > [PyPy 2.4.0 with GCC 4.9.2] > rosuav at sikorsky:~$ jython --version > "my" variable $jythonHome masks earlier declaration in same scope at > /usr/bin/jython line 15. > Jython 2.5.3 > > And Steven D'Aprano probably can beat that by an order of magnitude. > > Keep your multiple interpreters around; it doesn't hurt. Unless you're > seriously bothered by disk space issues, the biggest cost is keeping > track of which one you've installed some third-party package into. > Well, I have 16 of them! From gokoproject at gmail.com Wed Sep 30 13:30:30 2015 From: gokoproject at gmail.com (John Wong) Date: Wed, 30 Sep 2015 13:30:30 -0400 Subject: Linux Mint installation of Python 3.5 In-Reply-To: <560B4AFA.2040305@gmx.com> References: <560B4AFA.2040305@gmx.com> Message-ID: On Tue, Sep 29, 2015 at 10:37 PM, Mario Figueiredo wrote: > Hello everyone, > > Under Linux Mint it is not a good idea to just go ahead and replace the > system installed Python versions and their packages. And yet I wish to > both update the 3.4 modules and install Python 3.5. I understand that > for the first I just need to use virtualenv. > Late to the party but this goes for every system. Never a good idea to replace system files. There are tools out there to manage multiple versions of python, you can give those a try, otherwise I prefer sticking native solution. This may not be a Python discussion, but I don't think update-alterantives works for python right? I've used that for Java. Not that this actually applies for the usage parent is thinking.... -------------- next part -------------- An HTML attachment was scrubbed... URL: From rusirijayalath92 at gmail.com Wed Sep 30 13:36:13 2015 From: rusirijayalath92 at gmail.com (Rusiri Jayalath) Date: Wed, 30 Sep 2015 23:06:13 +0530 Subject: Error code 0x80070570 Message-ID: Error code 0x80070570 appears when installing python 3.5.0 (32-bit) setup for my windows 8.1 system. Please help me to solve this problem. -- Thank You. Best Regards, Rusiri D. Jayalath -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Wed Sep 30 13:57:31 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 30 Sep 2015 13:57:31 -0400 Subject: Error code 0x80070570 In-Reply-To: References: Message-ID: On Wed, Sep 30, 2015 at 1:36 PM, Rusiri Jayalath wrote: > Error code 0x80070570 appears when installing python 3.5.0 (32-bit) setup > for my windows 8.1 system. Please help me to solve this problem. > > -- > > Thank You. > > > > > > > > Best Regards, > > > > > > > > Rusiri D. Jayalath > > -- > https://mail.python.org/mailman/listinfo/python-list > > Microsoft seems to think its a disk problem, or a cd problem: http://answers.microsoft.com/en-us/windows/forum/windows_8-windows_install/gets-the-error-code-0x80070570-during-the/34908e67-35d3-4291-9008-d7db862c29ff -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at pacujo.net Wed Sep 30 14:06:02 2015 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 30 Sep 2015 21:06:02 +0300 Subject: Check if a given value is out of certain range References: Message-ID: <87si5v3hpx.fsf@elektro.pacujo.net> Grant Edwards : > not (0 <= x <= 10) (I) > [...] > (x < 0) or (x > 10) (II) > [...] > IMO, (I) is _more_ readable than (II) IMO, they're equally readable (except that you should drop the redundant parentheses from (II)). Marko From sohcahtoa82 at gmail.com Wed Sep 30 14:31:21 2015 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Wed, 30 Sep 2015 11:31:21 -0700 (PDT) Subject: Check if a given value is out of certain range In-Reply-To: References: Message-ID: On Tuesday, September 29, 2015 at 1:33:23 PM UTC-7, Mark Lawrence wrote: > On 29/09/2015 17:48, Rob Gaddi wrote: > > On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: > > > >> Hi, > >> > >> I know there is an elegant way to check if a given value is within > >> certain range. > >> Example - To check if x is between zero and ten, I can do 0 < x 10. > >> > >> Is there any similar elegant way to check if a value is out of certain > >> range? > >> Example - To check if x is either less than zero or greater than ten? > >> Right now I am using x < 0 or x > 10. > >> > >> Regards, > >> Laxmikant > > > > not (0 <= x <= 10) > > > > Yuck. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence What is so "yuck" about that? What would you do instead? It seems like the best solution to me. Easy to read, fast to execute. From bc at freeuk.com Wed Sep 30 14:32:22 2015 From: bc at freeuk.com (BartC) Date: Wed, 30 Sep 2015 19:32:22 +0100 Subject: Check if a given value is out of certain range In-Reply-To: References: Message-ID: <_UVOx.32452$nl4.10232@fx02.am4> On 29/09/2015 05:46, Laxmikant Chitare wrote: > Hi, > I know there is an elegant way to check if a given value is within > certain range. > Example - To check if x is between zero and ten, I can do 0 < x 10. That's not clear. Do you mean whether x is 1 to 9 inclusive? Because your contrary example below suggests you mean 0 to 10 inclusive. > Is there any similar elegant way to check if a value is out of certain > range? > Example - To check if x is either less than zero or greater than ten? > Right now I am using x < 0 or x > 10. You might try just defining a function to do it: def out_of_range(x,a,b): # use whatever code you like then use it as: if out_of_range(x,0,10): But it is necessary to define exactly what is meant by it (Python ranges seem to exclude the upper bound). So x<0 or x>10 might not be the most elegant, and x is evaluated twice, but it is the clearest. -- Bartc From massi_srb at msn.com Wed Sep 30 14:34:04 2015 From: massi_srb at msn.com (massi_srb at msn.com) Date: Wed, 30 Sep 2015 11:34:04 -0700 (PDT) Subject: Question about regular expression Message-ID: <811788b6-9955-4dcc-bf49-9647891d17ec@googlegroups.com> Hi everyone, firstly the description of my problem. I have a string in the following form: s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..." that is a string made up of groups in the form 'name' (letters only) plus possibly a tuple containing 1 or 2 integer values. Blanks can be placed between names and tuples or not, but they surely are placed beween two groups. I would like to process this string in order to get a dictionary like this: d = { "name1":(0, 0), "name2":(1, 0), "name3":(0, 0), "name4":(1, 4), "name5":(2, 0), } I guess this problem can be tackled with regular expressions, but I have no idea bout how to use them in this case (I'm not a regexp guy). Can anyone give me a hint? any possible different approach is absolutely welcome. Thanks in advance! From emile at fenx.com Wed Sep 30 14:50:12 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 30 Sep 2015 11:50:12 -0700 Subject: Question about regular expression In-Reply-To: <811788b6-9955-4dcc-bf49-9647891d17ec@googlegroups.com> References: <811788b6-9955-4dcc-bf49-9647891d17ec@googlegroups.com> Message-ID: On 9/30/2015 11:34 AM, massi_srb at msn.com wrote: > Hi everyone, > > firstly the description of my problem. I have a string in the following form: > > s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..." > > that is a string made up of groups in the form 'name' (letters only) plus possibly a tuple containing 1 or 2 integer values. Blanks can be placed between names and tuples or not, but they surely are placed beween two groups. I would like to process this string in order to get a dictionary like this: > > d = { > "name1":(0, 0), > "name2":(1, 0), > "name3":(0, 0), > "name4":(1, 4), > "name5":(2, 0), > } > > I guess this problem can be tackled with regular expressions, Stop there! :) I'd use string functions. If you can control the string output to drop the spaces and always output in namex(a,b)namey(c,d)... format, try starting with >>> "name1 name2(1) name3 name4(1,4) name5(2)".split() ['name1', 'name2(1)', 'name3', 'name4(1,4)', 'name5(2)'] then create the dict from the result. Emile From python.list at tim.thechases.com Wed Sep 30 15:20:15 2015 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 30 Sep 2015 14:20:15 -0500 Subject: Question about regular expression In-Reply-To: <811788b6-9955-4dcc-bf49-9647891d17ec@googlegroups.com> References: <811788b6-9955-4dcc-bf49-9647891d17ec@googlegroups.com> Message-ID: <20150930142015.4045c931@bigbox.christie.dr> On 2015-09-30 11:34, massi_srb at msn.com wrote: > firstly the description of my problem. I have a string in the > following form: > > s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..." > > that is a string made up of groups in the form 'name' (letters > only) plus possibly a tuple containing 1 or 2 integer values. > Blanks can be placed between names and tuples or not, but they > surely are placed beween two groups. I would like to process this > string in order to get a dictionary like this: > > d = { > "name1":(0, 0), > "name2":(1, 0), > "name3":(0, 0), > "name4":(1, 4), > "name5":(2, 0), > } > > I guess this problem can be tackled with regular expressions, b First out of the gate, I suggest you follow Emile's advice and try using string expressions. However, if you *want* to do it with regular expressions, you can. It's ugly and might be fragile, but ############################################################# import re s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..." r = re.compile(r""" \b # start at a word boundary (\w+) # capture the word \s* # optional whitespace (?: # start an optional grouping for things in the parens \( # a literal open-paren \s* # optional whitespace (\d+) # capture the number in those parens (?: # start a second optional grouping for the stuff after a comma \s* # optional whitespace , # a literal comma \s* # optional whitespace (\d+) # the second number )? # make the command and following number optional \) # a literal close-paren )? # make that stuff in parens optional """, re.X) d = {} for m in r.finditer(s): a, b, c = m.groups() d[a] = (int(b or 0), int(c or 0)) from pprint import pprint pprint(d) ############################################################# I'd stick with the commented version of the regexp if you were to use this anywhere so that others can follow what you're doing. -tkc From joel.goldstick at gmail.com Wed Sep 30 15:21:43 2015 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 30 Sep 2015 15:21:43 -0400 Subject: Question about regular expression In-Reply-To: References: <811788b6-9955-4dcc-bf49-9647891d17ec@googlegroups.com> Message-ID: On Wed, Sep 30, 2015 at 2:50 PM, Emile van Sebille wrote: > On 9/30/2015 11:34 AM, massi_srb at msn.com wrote: > >> Hi everyone, >> >> firstly the description of my problem. I have a string in the following >> form: >> >> s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..." >> >> that is a string made up of groups in the form 'name' (letters only) plus >> possibly a tuple containing 1 or 2 integer values. Blanks can be placed >> between names and tuples or not, but they surely are placed beween two >> groups. I would like to process this string in order to get a dictionary >> like this: >> >> d = { >> "name1":(0, 0), >> "name2":(1, 0), >> "name3":(0, 0), >> "name4":(1, 4), >> "name5":(2, 0), >> } >> >> I guess this problem can be tackled with regular expressions, >> > > Stop there! :) > > I'd use string functions. If you can control the string output to drop > the spaces and always output in namex(a,b)namey(c,d)... format, try > starting with > > >>> "name1 name2(1) name3 name4(1,4) name5(2)".split() > ['name1', 'name2(1)', 'name3', 'name4(1,4)', 'name5(2)'] > > then create the dict from the result. In your original string, splitting on spaces gives this: >>> s = "name1 name2(1) name3 name4 (1, 4) name5(2)" >>> s.split(' ') ['name1', 'name2(1)', 'name3', 'name4', '(1,', '4)', 'name5(2)'] >>> That might be useful to start. The space between the namex and (1,...) is problematic. If your data could be that way, perhaps, preprocess the string to remove space before '(', and the space between commas. >>> s = "name1 name2(1) name3 name4(1,4) name5(2)" >>> s.split(' ') ['name1', 'name2(1)', 'name3', 'name4(1,4)', 'name5(2)'] >>> >From here writing the dictionary shouldn't be too hard. I'm sure there is a better way as this does a couple of loops, but once you get it working, you can optimize if necessary. > > -- Joel Goldstick http://joelgoldstick.com/stats/birthdays -------------- next part -------------- An HTML attachment was scrubbed... URL: From eryksun at gmail.com Wed Sep 30 15:36:02 2015 From: eryksun at gmail.com (eryksun) Date: Wed, 30 Sep 2015 14:36:02 -0500 Subject: Error code 0x80070570 In-Reply-To: References: Message-ID: On 9/30/15, Rusiri Jayalath wrote: > Error code 0x80070570 appears when installing python 3.5.0 (32-bit) setup > for my windows 8.1 system. Please help me to solve this problem. 0x80070570 is ERROR_FILE_CORRUPT: the file or directory is corrupted and unreadable. It could be an intermittent problem with your internet connection when downloading the required packages. Try using the non-web installer that already includes most of them [1]. I haven't seen this particular error reported on the issue tracker, so you might want to submit a new issue. Include a zip of the installation logs for the most recent failed attempt. They're in your %TEMP% directory with names like "Python 3.5.0 (32-bit)_*.log". FYI, the severity/facility code 0x8007 determines that 0x0570 is a Win32 error code. See HRESULT [2] for an overview of how to decode HRESULT and NTSTATUS [3] codes. See Win32 Error Codes [4] or System Error Codes [5] for a list of Win32 errors. [1]: https://www.python.org/ftp/python/3.5.0/python-3.5.0.exe [2]: https://msdn.microsoft.com/en-us/library/cc231198 [3]: https://msdn.microsoft.com/en-us/library/cc231200 [4]: https://msdn.microsoft.com/en-us/library/cc231199 [5]: https://msdn.microsoft.com/en-us/library/ms681381 From alister.nospam.ware at ntlworld.com Wed Sep 30 16:19:31 2015 From: alister.nospam.ware at ntlworld.com (alister) Date: Wed, 30 Sep 2015 20:19:31 +0000 (UTC) Subject: Check if a given value is out of certain range References: <87si5v3hpx.fsf@elektro.pacujo.net> Message-ID: On Wed, 30 Sep 2015 21:06:02 +0300, Marko Rauhamaa wrote: > Grant Edwards : > >> not (0 <= x <= 10) (I) >> [...] >> (x < 0) or (x > 10) (II) >> [...] >> IMO, (I) is _more_ readable than (II) > > IMO, they're equally readable (except that you should drop the redundant > parentheses from (II)). > > > Marko both are correct the problem with 1 is the human brain is not particularity good with negatives*. to do not (some function) you first of all have to work out some function & then invert it, a computer does this without difficulty the human brain gets confused which is why I personally consider ii is more readable (YMMV especially if you are working with Boolean maths regularly) this example is relatively simple as things get more complex they become more error prone error. *as an example you brain cannot correctly process the following. Not (think of your left toe) you are now thinking about it aren't you? -- The UPS is on strike. From ian.g.kelly at gmail.com Wed Sep 30 16:46:48 2015 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 30 Sep 2015 14:46:48 -0600 Subject: Check if a given value is out of certain range In-Reply-To: References: <87si5v3hpx.fsf@elektro.pacujo.net> Message-ID: On Wed, Sep 30, 2015 at 2:19 PM, alister wrote: > On Wed, 30 Sep 2015 21:06:02 +0300, Marko Rauhamaa wrote: > >> Grant Edwards : >> >>> not (0 <= x <= 10) (I) >>> [...] >>> (x < 0) or (x > 10) (II) >>> [...] >>> IMO, (I) is _more_ readable than (II) >> >> IMO, they're equally readable (except that you should drop the redundant >> parentheses from (II)). >> >> >> Marko > > both are correct > the problem with 1 is the human brain is not particularity good with > negatives*. > to do not (some function) you first of all have to work out some function > & then invert it, a computer does this without difficulty the human brain > gets confused which is why I personally consider ii is more readable > (YMMV especially if you are working with Boolean maths regularly) this > example is relatively simple as things get more complex they become more > error prone error. To me, the negative of one condition (is x in this range) is more easily processable than the disjunction of two conditions that together compose the real, more easily understood condition (is x outside this range). I find it preferable to avoid nested conditions, not negated conditions, and (II) has more nesting than (I). Thought mirrors language. In English, we typically would say "x is not between 0 and 10", not "x is either less than 0 or greater than 10". > *as an example you brain cannot correctly process the following. > > Not (think of your left toe) > > you are now thinking about it aren't you? No, it made me think about thinking. I barely even registered the phrase "left toe", much less thought about that. In any case, that's more an issue of being unable to control what you're thinking about. If I instruct you, "don't raise your right hand", do you then automatically raise your right hand? From cs at zip.com.au Wed Sep 30 17:30:59 2015 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 1 Oct 2015 07:30:59 +1000 Subject: ConnectionError handling problem In-Reply-To: References: Message-ID: <20150930213059.GA6225@cskk.homeip.net> On 29Sep2015 23:04, shiva upreti wrote: >On Friday, September 25, 2015 at 12:55:01 PM UTC+5:30, Cameron Simpson wrote: >> Ok. You original code says: >> >> try: >> r=requests.post(url, data=query_args) >> except: >> print "Connection error" >> >> and presumably we think your code is hanging inside the requests.post call? You >> should probably try to verify that, because if it is elsewhere you need to >> figure out where (lots of print statements is a first start on that). >> I would open two terminals. Run your program until it hangs in one. [...various things to do to check _exactly_ where the hang is occurring...] > >Yes I use ubuntu 14.04. I will try what you suggested. But I cant understand >one thing, for whatever reason the script is hanging, why does it resumes >almost instantaneously when I press CTRL+C. Most likely the Ctrl-C interrupts whatever system call is hanging, causing it to return (failed, probably with errno EINTR). And the python program resumes because the OS system call has returned. Cheers, Cameron Simpson From lac at openend.se Wed Sep 30 17:56:02 2015 From: lac at openend.se (Laura Creighton) Date: Wed, 30 Sep 2015 23:56:02 +0200 Subject: ConnectionError handling problem In-Reply-To: <20150930213059.GA6225@cskk.homeip.net> References: <20150930213059.GA6225@cskk.homeip.net> Message-ID: <201509302156.t8ULu2rE000710@fido.openend.se> In a message of Thu, 01 Oct 2015 07:30:59 +1000, Cameron Simpson writes: >Most likely the Ctrl-C interrupts whatever system call is hanging, causing it >to return (failed, probably with errno EINTR). And the python program resumes >because the OS system call has returned. > >Cheers, >Cameron Simpson Shiva Upreti needs to post the current code, but last time I read it the problem was that control-C is a KeyboardInterrupt, which the program was catching, and then continuing the loop. Laura From breamoreboy at yahoo.co.uk Wed Sep 30 18:31:59 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 30 Sep 2015 23:31:59 +0100 Subject: Check if a given value is out of certain range In-Reply-To: References: Message-ID: On 30/09/2015 19:31, sohcahtoa82 at gmail.com wrote: > On Tuesday, September 29, 2015 at 1:33:23 PM UTC-7, Mark Lawrence wrote: >> On 29/09/2015 17:48, Rob Gaddi wrote: >>> On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote: >>> >>>> Hi, >>>> >>>> I know there is an elegant way to check if a given value is within >>>> certain range. >>>> Example - To check if x is between zero and ten, I can do 0 < x 10. >>>> >>>> Is there any similar elegant way to check if a value is out of certain >>>> range? >>>> Example - To check if x is either less than zero or greater than ten? >>>> Right now I am using x < 0 or x > 10. >>>> >>>> Regards, >>>> Laxmikant >>> >>> not (0 <= x <= 10) >>> >> >> Yuck. >> >> -- >> My fellow Pythonistas, ask not what our language can do for you, ask >> what you can do for our language. >> >> Mark Lawrence > > What is so "yuck" about that? What would you do instead? It seems like the best solution to me. Easy to read, fast to execute. > I have to parse those damn brackets and then figure out the inverted logic. Give me x < 0 or x > 10 any day of the week. When you're an old, senile git like me, readability counts :-) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From denismfmcmahon at gmail.com Wed Sep 30 18:33:35 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 30 Sep 2015 22:33:35 +0000 (UTC) Subject: Error code 0x80070570 References: Message-ID: On Wed, 30 Sep 2015 23:06:13 +0530, Rusiri Jayalath wrote: > Error code 0x80070570 appears when installing python 3.5.0 (32-bit) > setup for my windows 8.1 system. Please help me to solve this problem. This seems to be a windows error, not a python issue. Try google. -- Denis McMahon, denismfmcmahon at gmail.com From denismfmcmahon at gmail.com Wed Sep 30 19:30:47 2015 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 30 Sep 2015 23:30:47 +0000 (UTC) Subject: Question about regular expression References: <811788b6-9955-4dcc-bf49-9647891d17ec@googlegroups.com> Message-ID: On Wed, 30 Sep 2015 11:34:04 -0700, massi_srb wrote: > firstly the description of my problem. I have a string in the following > form: ..... The way I solved this was to: 1) replace all the punctuation in the string with spaces 2) split the string on space 3) process each thing in the list to test if it was a number or word 4a) add words to the dictionary as keys with value of a default list, or 4b) add numbers to the dictionary in the list at the appropriate position 5) convert the list values of the dictionary to tuples It seems to work on my test case: s = "fred jim(1) alice tom (1, 4) peter (2) andrew(3,4) janet( 7,6 ) james ( 7 ) mike ( 9 )" d = {'mike': (9, 0), 'janet': (7, 6), 'james': (7, 0), 'jim': (1, 0), 'andrew': (3, 4), 'alice': (0, 0), 'tom': (1, 4), 'peter': (2, 0), 'fred': (0, 0)} -- Denis McMahon, denismfmcmahon at gmail.com From emile at fenx.com Wed Sep 30 23:58:10 2015 From: emile at fenx.com (Emile van Sebille) Date: Wed, 30 Sep 2015 20:58:10 -0700 Subject: Question about regular expression In-Reply-To: <20150930142015.4045c931@bigbox.christie.dr> References: <811788b6-9955-4dcc-bf49-9647891d17ec@googlegroups.com> <20150930142015.4045c931@bigbox.christie.dr> Message-ID: On 9/30/2015 12:20 PM, Tim Chase wrote: > On 2015-09-30 11:34, massi_srb at msn.com wrote: >> I guess this problem can be tackled with regular expressions, b > ... However, if you *want* to do it with > regular expressions, you can. It's ugly and might be fragile, but > > ############################################################# > import re > s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..." > r = re.compile(r""" > \b # start at a word boundary > (\w+) # capture the word > \s* # optional whitespace > (?: # start an optional grouping for things in the parens > \( # a literal open-paren > \s* # optional whitespace > (\d+) # capture the number in those parens > (?: # start a second optional grouping for the stuff after a comma > \s* # optional whitespace > , # a literal comma > \s* # optional whitespace > (\d+) # the second number > )? # make the command and following number optional > \) # a literal close-paren > )? # make that stuff in parens optional > """, re.X) > d = {} > for m in r.finditer(s): > a, b, c = m.groups() > d[a] = (int(b or 0), int(c or 0)) > > from pprint import pprint > pprint(d) > ############################################################# :) > > I'd stick with the commented version of the regexp if you were to use > this anywhere so that others can follow what you're doing. ... and this is why I use python. That looks too much like a hex sector disk dump rot /x20. :) No-really-that's-sick-ly yr's, Emile