Re: Problem using pip
On Tue, Jan 14, 2020 at 2:18 AM proplayer raj wrote: > > dear team > I have encountered a problem while using pip , that it did not allowed to > install webbrowsing and OS module it show the error that it does not found > any matching distributor and does not fount the version which can fulfill > the requirement. Can you be specific about which modules you are trying to install? I don't see any sign of a python package called 'webbrowsing' anywhere on the internet, for instance. Are you possibly looking for the 'webbrowser' module? If so, it's not installed via pip, it's part of the python standard library (see docs here: https://docs.python.org/3/library/webbrowser.html). There's also an 'os' module in the standard library (https://docs.python.org/3/library/os.html). Are those the modules you were looking for? -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Console Menu
On Tue, Jul 31, 2018 at 12:31 PM juraj.papic--- via Python-list wrote: > I will check the links thanks for that tips, is there any page where I can > see more examples? I like Doug Hellmann's Python Module of the Week site for in-depth looks at particular modules (including subprocess). If you're using python 3, the subprocess module's page is here: https://pymotw.com/3/subprocess/. >From your sample code, you may still be using python 2. If so, the PyMOTW page for that version is here: https://pymotw.com/2/subprocess/. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Missing python36.dll
On Mon, Mar 19, 2018 at 5:07 PM, MRABwrote: > You didn't say which installer you used. > It might also be helpful to know: Did you install python for "Just Me" or "All Users" in the installer? Does the user you're logged in as have enough authority to install for All Users if that's what you picked? What OS are you using? Since you're asking about DLLs, it's obviously some flavor of Windows, but you don't say which one. Did you notice any errors messages or log files generated by the installer? -- https://mail.python.org/mailman/listinfo/python-list
Re: Can't Uninstall !
On Tue, Feb 13, 2018 at 10:30 AM, Pedro Crescenciowrote: 3. How did you try to uninstall it? > Using Windows standard uninstall procedure > https://www.windowscentral.com/how-to-uninstall-apps-windows-10 > That page describes two different ways of uninstalling programs (from the start screen, or from the Apps & Features control panel). I don't know if it matters, but it might help someone to know which one you used. > 4. What messages did you get when you tried to uninstall it? > The message says : "Uninstalled". But I still have the icon over the App > list. > You say you have "the" icon. What icon is that? A normal python install should have a bunch of different stuff on the start menu -- on the Windows 7 installation I have in front of me, I have a "Python 3.6" folder, with four different links nested inside - "IDLE (Python 3.6 32-bit)", "Python 3.6 (32-bit)", "Python 3.6 Manuals (32-bit)", and "Python 3.6 Module Docs (32-bit)". What do you have? When you installed python, do you remember if you installed it for "All Users" or "Just Me"? -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: replacing `else` with `then` in `for` and `try`
On Wed, Nov 1, 2017 at 5:12 PM, Alexey Muranovwrote: > what do you think about the idea of replacing "`else`" with "`then`" in > the contexts of `for` and `try`? > I wish the core python developers had done it 20 years ago. Given that python is a relatively mature language at this point, I don't expect that it will ever change. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Finding keyword arguments in the documentation
On Tue, Sep 26, 2017 at 12:32 PM, Peter Otten <__pete...@web.de> wrote: > Newer Python versions will show > > Help on built-in function sin in module math: > > sin(x, /) > Return the sine of x (measured in radians). > > > where the arguments before the slash are positional-only: What version of python do you need to see that output from help? I'm not seeing it in 3.6.1 on windows: Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import math >>> help (math.sin) Help on built-in function sin in module math: sin(...) sin(x) Return the sine of x (measured in radians). >>> -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] beginning to code
On Tue, Sep 19, 2017 at 8:26 PM, Rick Johnsonwrote: > In the spirit of my last comment, i was going to say: "Or if > `x` does not support rich comparisons", but alas, it seems that > _all_ objects in Python support rich comparisons, even when > it doesn't make sense to! o_O For example: > > >>> False > 1 > False > >>> dir > 1 > True > >>> isinstance < 100 > False > >>> "" >= 10 > True > >>> (1,) <= 500 > False Rick, I'm pretty sure you already know that you're being deceptive here. If anyone else comes across this and doesn't already realize it, note that Rick is complaining about behavior that changed almost a decade ago (with the release of Python 3.0). Here's what a modern python does with those same statements: Python 3.5.2 (default, Aug 18 2017, 17:48:00) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> False > 1 False >>> dir > 1 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: builtin_function_or_method() > int() >>> isinstance < 100 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: builtin_function_or_method() < int() >>> "" >= 10 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: str() >= int() >>> (1,) <= 500 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: tuple() <= int() >>> -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: If you are running 32-bit 3.6 on Windows, please test this
On Wed, Aug 30, 2017 at 1:48 PM, MRABwrote: > > On 2017-08-30 18:35, Terry Reedy wrote: >> >> https://stackoverflow.com/questions/45965545/math-sqrt-domain-error-when-square-rooting-a-positive-number >> >> reports the following: >> - >> Microsoft Windows [Version 10.0.16251.1002] >> (c) 2017 Microsoft Corporation. All rights reserved. >> >> C:\Users\Adam>python >> Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit >> (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import math >> >>> math.sqrt(1.3) >> Traceback (most recent call last): >>File "", line 1, in >> ValueError: math domain error >> >>> >> >> I upgraded from version 3.6.1 to 3.6.2 to try to resolve the issue and >> restarted my computer but it is still occurring. Some numbers are >> working (1.2, 1.4) and some others are also not working (1.128). >> >> >> Neither installed 64 bit 3.6.2 nor my repository 3.6 32-bit debug build >> reproduce this. If anyone has the python.org 32bit 3.6.1/2 releases >> installed on Windows, please test and report. >> > Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import math > >>> math.sqrt(1.3) > 1.140175425099138 > >>> > > This is on 64-bit Windows 10. > -- > https://mail.python.org/mailman/listinfo/python-list This all seems to work fine with python 3.6.1 on Windows 7 (64-bit OS, 32-bit python). Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import math >>> math.sqrt(1.3) 1.140175425099138 >>> -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: how to write add frequency in particular file by reading a csv file and then making a new file of multiple csv file by adding frequency
On Fri, Jun 23, 2017 at 4:07 PM, Mark Byrnewrote: > Possible fix is to replace this: > > count = frequency.get(word,0) > count1 = frequency.get(word1,0) > if word1 == word: > frequency[word] = count + count1 > else: > frequency[word] = count > > with this: > > if word1 == word: > if word in frequency: > frequency[word] += 1 > else: > frequency[word] = 1 > Have you considered replacing your frequency dict with a defaultdict(int)? That way you could boil the whole thing down to: from collections import defaultdict frequency = defaultdict(int) ... ... if word1 == word: frequency[word] += 1 The defaultdict takes care of the special case for you. If the value is missing, it's defaulted to 0. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Two variable dictionary comprehension
On Mon, Apr 3, 2017 at 5:50 PM, Deborah Swansonwrote: > Ah, but did you actually try to use the proposed solutions on the two > stackoverflow pages? It's been several weeks now, but I did, and neither > of those two examples fit my situation, which is why I ended up writing > my own, and unsatisfactorily at that. Well, that first Stack Overflow link has the following as the first part of the highest scored answer: In Python 2.6 and earlier, the dict constructor can receive an iterable of key/value pairs: d = dict((key, value) for (key, value) in iterable) From Python 2.7 and 3 onwards, you can just use the dict comprehension syntax directly: d = {key: value for (key, value) in iterable} Isn't that second form the exact thing you were looking for, back in your first post? > I'm sorry you think the current edition of Google does such a fine job. > Has it really been that many years ago that the results Google returned > from a properly formatted boolean search were really useful? I'd > imagine that the old Google would have returned a good 10 pages or more > (probably a lot more) of urls containing the phrase "dict comprehension" > or "dictionary comprehension". in which you'd find a rich variety of > specific situations to glean through. (You wouldn't have needed to > include "python" in the search phrase, since no other programming > language that I know of, or other English usage for that matter, has > dict comprehensions.) Is this not your experience today? I just browsed through the first 5 pages of search results for the phrase "dict comprehension" (without the quotes), and the results seem to be pretty on point. It's mostly results talking about python dict comprehensions, general python pages talking about all sorts of comprehensions (dict, list, and set), and as you get deeper into the result pages, you start to see some entries for the word "comprehension" in dictionaries too, which seems like a reasonable thing to end up mixed in with the desired results. It goes on in that vein out to page 11 or so, at which point things seem to devolve a bit. I'd be totally sympathetic with your plight if you didn't know the key phrase 'dict comprehension' to find all of that information. I'm just not seeing the poor results you seem to be getting from Google once you know the term. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Two variable dictionary comprehension
On Mon, Apr 3, 2017 at 10:30 AM, Deborah Swansonwrote: > Regular updates as the docs are updated would be a good idea too. It's > obvious that today's Google isn't up to it, although it occurs to me > that I haven't tried Google's site search on python.org. So, when you search google for the phrase "dict comprehension" or "dictionary comprehension", nothing useful comes up for you? When I search either of those phrases, I get lots of useful results, all of which spell out how to do what you were originally asking about. I know Google search results are skewed by past usage, but I'm surprised that you didn't find anything useful in the first couple of search results. When I do a search for 'dict comprehension' I get a boxed result linking to PEP 274 as the first hit, then two Stack Overflow questions, both of which demonstrate how to do dictionary comprehensions. Following that is another link to PEP 274, a link to the Python docs on data structures (which does talk about dict comprehensions, but it's way down on the page), and then links to a bunch of tutorials. If you had to judge based on my search results, Google does a fine job of answering python questions, at least when you already know the key phrase to look for. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: how to evaluate a ast tree and change Add to Multiply ?
On Wed, Oct 12, 2016 at 5:55 AM, meInvent bbirdwrote: > i just expect to > rewrite + become multiply > by edit the example in the link provided This seems to work. You need to define visit_BinOp instead of visit_Num (since you want to mess with the binary operations, not the numbers). Then,in visit_BinOp, we just replace the ast.Add node with an ast.Mult node. import ast class ChangeAddToMultiply(ast.NodeTransformer): """Wraps all integers in a call to Integer()""" def visit_BinOp(self, node): if isinstance(node.op, ast.Add): node.op = ast.Mult() return node code = 'print(2+5)' tree = ast.parse(code) tree = ChangeAddToMultiply().visit(tree) ast.fix_missing_locations(tree) co = compile(tree, '', "exec") exec(code) exec(co) -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Why don't we call the for loop what it really is, a foreach loop?
On Tue, Sep 13, 2016 at 4:57 PM,wrote: > It would help newbies and prevent confusion. Are you asking why Guido didn't call it foreach back in 1989, or why the core developers don't change it now, 27 years later? I can't speak for the historical perspective, but I'm sure there's basically no chance that it will be changed now. It would be a totally backwards incompatible change, invalidate every tutorial and bit of python documentation that's been written over the last three decades, and break pretty much every python program that works today. In exchange, you get newbies who are a slightly less confused about for loops. That tradeoff isn't worth it. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Text input with keyboard, via input methods
On Thu, Mar 10, 2016 at 5:51 AM, Marko Rauhamaawrote: > I don't have an answer. I have requirements, though: > > * I should be able to get the character by knowing its glyph (shape). > > * It should be very low-level and work system-wide, preferably over the >network (I'm typing this over the network). This probably doesn't meet all your needs, but there are web services that get you to draw an approximation of a glyph, then present you with some possible unicode characters to match. I thought there were a couple of these sites, but on a quick search, I only find one for unicode glyphs: http://shapecatcher.com/ and another one for TeX codes: http://detexify.kirelabs.org/classify.html -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Need Help w. Getting the Eclipse Python Add-On.
On Fri, Jul 17, 2015 at 2:22 PM, Steve Burrus steveburru...@gmail.com wrote: I Need immediate Help w. Getting the Eclipse Python Add-On. I looked all around the Eclipse website to try to get this but didn't see the add-on for this. Can someone please help me to find it? Thanx. I think you're looking for PyDev: http://www.pydev.org/ -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: What means -?
On Tue, Apr 28, 2015 at 1:18 PM, stehlam...@arcor.de wrote: in the Python Language Specification, I've found the delimiter - (cf. https://docs.python.org/3/reference/lexical_analysis.html#delimiters, last entry in the table´s second line). Could you please describe the effects of this delimiter? I read nothing about - by now. In addition, help(-) didn´t work. It's part of the syntax for function annotations. See here in the reference manual: https://docs.python.org/3/reference/compound_stmts.html#index-23 and/or refer to PEP 3107 for more background: https://www.python.org/dev/peps/pep-3107/ If you're interested, PEP 484 (https://www.python.org/dev/peps/pep-0484/) is attempting to chart out the future uses of function annotation for doing type checking in external tools (keep in mind that PEP 484 isn't final yet, nor has it been accepted, my impression is that it's still a work in progress). -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Anyone used snap.py for drawing a graph?
On Sun, Apr 12, 2015 at 10:29 PM, Pippo adm2303.2...@gmail.com wrote: Any guide on this? http://snap.stanford.edu/snappy/#download Sure. http://snap.stanford.edu/snappy/#docs -- https://mail.python.org/mailman/listinfo/python-list
Re: Automation of Windows app?
On Fri, Mar 20, 2015 at 2:10 PM, Grant Edwards invalid@invalid.invalid wrote: I need to automate operation of a Windows application. I've used Sikuli (http://www.sikuli.org/) for similar things in the past. It's an automation framework built on Jython, and it worked great for what I needed at the time. I think AutoHotKey is also widely used for automating windows GUI apps, but it's not related to python at all. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: html page mail link to webmail program
On Tue, Nov 11, 2014 at 8:04 PM, Ethan Furman et...@stoneleaf.us wrote: My wife (using a Win7 machine) will be on a web page that has a link to mail somebody. She clicks on it, and it opens the currently installed but unused Thunderbird. As others have mentioned, this is more a question of configuring your browser than anything involving python. That said, those links on a web page that open an email window are called mailto links. A google search for open mailto links in gmail (without the quotes) gets a bunch of general information, and if you add your wife's browser of choice to the search terms, you should get some explicit instructions for setting everything up properly. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: NumPy, SciPy, Python 3X Installation/compatibility issues
On Tue, Sep 23, 2014 at 1:54 PM, SK shagunkh...@gmail.com wrote: Hi EK, Did you figure out questions 1, 2 and 3? SciPy (0.14.0) on installation asks me for Python 2.7. First day on Python here, I am really struggling :/ Thanks, SK Did you download the SciPy installer for python 3.3? I see it listed for download on the sourceforge site here: http://sourceforge.net/projects/scipy/files/scipy/0.14.0/scipy-0.14.0-win32-superpack-python3.3.exe/download There are also versions for python 3.4, 3.2, 2.7 and 2.6, so you have to make sure you get the one that matches the version of python you're using. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: .Net Like Gui Builder for Python?
On Fri, Jul 25, 2014 at 10:55 AM, Orochi kartikjagdal...@gmail.com wrote: So,Is there any Gui App builder like Visual Studio or having features like Visual Studio for Python. I'm not aware of anything with the same level of functionality as Visual Studio's GUI building tools. Glade is the closest I've seen, and as you mentioned, it's not as interactive and integrated into an IDE as Visual Studio is. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about Pass-by-object-reference?
On Tue, Jul 22, 2014 at 6:17 PM, fl rxjw...@gmail.com wrote: Thanks for your example. I do not find the explanation of [:] on line. Could you explain it to me, or where can I find it on line? It's pretty hard to find if you don't already know what's going on. First, you need to know that mylst[i:j] refers to a slice of the list mylist. Specifically, the items from the list starting with the item at index i, up to but not including the item at index j. If you leave the i off (e.g., mylist[:j]) that's a slice from the start of the list up to (but not including) the j-th item. If you leave the end position off, (e.g., mylist[i:]), that gets you the i-th item to the end (including the last item). If you leave off both indexes from the slice, you get back the entire contents of the list. So that's what mylist[:] means. Then you need to know that you can assign to the slice and it will replace the old elements from the slice with the new ones. You can see that defined here, in the docs (second item in the table under 4.6.3. Mutable Sequence Types): https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types So, when you so mylist[:] = [0,1] you're taking all of the contents of the existing list, and replacing them with the contents of the list [0,1]. That changes the existing list, it doesn't just assign a new list to the name mylist. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Error while calling round() from future.builtins
On Sat, May 10, 2014 at 7:39 AM, Preethi preethid...@gmail.com wrote: future==0.9.0 It looks like that library is out of date. The current version looks to be 0.12.0, and it also looks like this bug was fixed in the 0.12.0 release. I'd upgrade your version if at all possible. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: The “does Python have variables?” debate
On Wed, May 7, 2014 at 2:18 AM, Marko Rauhamaa ma...@pacujo.net wrote: Ned Batchelder n...@nedbatchelder.com: Why is variable sacrosanct and can only be used to describe C semantics, but we're OK reusing class, int, and function? The Python language specification calls them variables; the terminology discussion should end there. Personally, I found the idea that a python variable is a name + value pairing to be useful when learning the language, especially when I was struggling with the calling semantics (that is, the differences between call-by-value, call-by-reference, and call-by-object). I think it's rather silly for someone to insist that python doesn't have variables. On the other hand, I think it can be useful to point out that python variable aren't like C variables, and that thinking of python variables as having two parts -- names and values -- really can help people who are struggling to learn the language. I know it certainly helped me. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Joining centos 6.5 member Domain Controller to an existing Windows Domain
On Mon, May 5, 2014 at 11:18 AM, Joshua Knights christcade...@yahoo.com.dmarc.invalid wrote: Here is my Issue and I think it may be a python path bug? It's not a bug in Python. It looks to me like a configuration problem. I'm going to assume you have a good reason for bypassing your OS's package management system. In general, this is a bad idea, but since this isn't a linux administration list, I'll leave it at that. Then I downloaded Samba with the following command: git clone git://git.samba.org/samba.git samba-master Then I installed the additional openldap-devel Library then I did the ./configure --enable-debug --enable-selftest then initiated the make command So you configured it, and built it, but did not install it, right? You didn't do a make install or make altinstall? Installing would presumably have put the files in the right place for them to be picked up by python. Since you just built samba without installing it, it looks like you have to point python to the right place. When I do a find / - name samba.netcmd.main It pulls up: NOTHING!! Right, that's not surprising. samba.netcmd.main is a python package, not a module, so it won't be named samba.netcmd.main.py or whatever you were thinking. If I pull up : find / -name netcmd I get: /root/samba-master/python/samba/netcmd /root/samba-master/bin/python/samba/netcmd /root/samba-master/bin/default/python/samba/netcmd In my research somebody said: to export the PYTHONPATH and to change it to the correct path of the netcmd command. You'll want to add the directory up to the /python bit. I'm not sure which one of those three is really the right location for the module you're looking for, but I would start by trying '/root/samba-master/bin/python'. From there, python should be able to find the samba package. if I wanted to fix it permanently then to update my bash.rc file. In other words Tell my samba tool where to look, and this look is only temporary till I close my terminal. Placing the command in the bash.rc file will run this script every time I open my terminal. Well, I tried all 3 and none of them worked. This is not a good way to leave your system. It's okay if you're just testing the new samba build, but you really ought to install the software, not just run it out of the build directory. Best of all would be to install a version that's actually been packaged up for your OS using the CentOS packaging system. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Reference
On Mon, Mar 3, 2014 at 11:52 PM, Steven D'Aprano st...@pearwood.info wrote: If your intention is to treat None as a singleton sentinel, not as a value, then you ought to use is to signal that intention, rather than using == even if you know that there won't be any false positives. In all of the years I've been on this list, I don't think I've seen more than one or two cases of someone deliberately treating None as a singleton sentinel. In most cases, they're either checking the return value from a function or using it as a default argument to a function to force some default behavior when no parameter is passed. I'm pretty sure you're going to say that the latter use is exactly where you should us 'is' instead of '=='. Respectfully, I disagree. For a beginning python user, identity checking is an attractive nuisance. The only time most beginners should use it is when comparing to None. But, as soon as they are taught that there are two comparison operators, I start to see 'is' cropping up in more and more places where they ought to use '=='. And the problem is that sometimes it works for them, and sometimes it doesn't. Sure, students eventually need to understand the difference between identity and equality. My problem is that by enshrining in python custom that the only correct way to compare to None is with 'is', we have to explain that concept way early in the teaching process. I can't count the number of times that a thread has completely derailed into identity vs equality, then into interning of strings and small integers, and suddenly the thread is 40 messages long, and no one has actually talked about the code that was originally posted beyond that issue. In approximately zero cases, have I seen code where 'is' versus '==' actually made any difference, except where the 'is' is wrong. I've also never seen the supposedly ever-present boogie man of an object that mistakenly compares equal to None, much less seen that object passed to functions with None-based sentinels. I feel like 'is' is an operator that ought to be saved for an advanced course. Out of curiosity, do you think we should be doing truth checking with 'is'? True and False are singletons, and it seems to me that the justification for idenity versus equality should be just as strong there, but I don't think I've ever seen anyone even suggest that. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Reference
On Mon, Mar 3, 2014 at 4:51 PM, Tim Chase python.l...@tim.thechases.com wrote: There are a couple use-cases I've encountered where is matters: 1) the most popular: if foo is None: do_stuff() I know this is the one that always comes up, but honestly, I feel like is doesn't matter here. That code would be just as correct if it was written as: if foo == None: do_stuff() The only time it would give you a different result from the is version is if foo was bound to an object that returned True when compared with None. And if that were the case, I'm still not convinced that you can tell from looking at those two lines of code which one is buggy, except for the fact that there has been 20 years of custom saying that comparing to None with equality is wrong. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: posting code snippets
On Thu, Feb 27, 2014 at 7:13 AM, Mark H. Harris harrismh...@gmail.com wrote: hi folks, Its been too long... can't remember... are there rules here about posting code snippets, or length considerations, and so forth? Chris' advice about just posting your code inline with your message is good. If the problem is that you think your code is too long to post inline, you're probably right. That means it's probably also too long for people to give it much attention. If you really want people to help figure out what is going on with code you don't understand, the best thing to do is to post a Short, Self Contained, Correct Example (http://www.sscce.org/). That means cutting the code down to the bare minimum required to demonstrate your issue. Many times, the very act of cutting the code down to a digestible chunk will show you the problem without posting. And if you still don't understand what's going on, you're much more likely to get help when you present a problem that can be read in a single screenful or so of code. A related question, is there a python repository for uploading py files, patches, suggestions, etc? Assuming this goes beyond posting code for people on the list to look at, yes, there are lots of places to post python code. For short bits, Activestate has a repository of python recipes: http://code.activestate.com/recipes/langs/python/ For publishing full modules and packages, there's the python package index: https://pypi.python.org/pypi Patches, bugs and feature requests for the python language itself belong here: http://bugs.python.org/ attached to an appropriate tracker issue. Feature requests should probably be raised on the python-ideas mailing list (https://mail.python.org/mailman/listinfo/python-ideas) before opening an issue on the bug tracker. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Win32 Write RAW Physical Disk Python 3.3.2
On Wed, Feb 19, 2014 at 7:42 AM, khanta kha...@gmail.com wrote: Hello, I am trying to write to the raw physical disk on Windows 8.1 but I get an error: PermissionError: [Errno 13] Permission denied: '.\\PHYSICALDRIVE2' Is there a volume mounted from the drive at the time you're attempting to write to the physical device? According to some MSDN documentation (http://msdn.microsoft.com/en-us/library/aa365747%28VS.85%29.aspx ), it doesn't look like you can write to a physical device if the sectors you're attempting to write are mounted at the time. There appear to be a lot of caveats. Take a look at the section of that page starting with If you write directly to a volume that has a mounted file system, you must first obtain exclusive access to the volume. for lots of details. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Simple Object assignment giving me errors
On Wed, Feb 12, 2014 at 4:42 PM, Nir nircher...@gmail.com wrote: If this makes sense to you, great. I am trying to break it down so that I can make sense of it. As you mentioned self[name] = filename doesn't work unless I built a class to handle it. I guess my question then, is how is the class handling it in this code? If you can show me by stripping it down to the bare minimum or write an example that would be awesome. This example works because the UserDict object being used in this code was built to handle it. The UserDict class in the standard library does a lot more than the little snippet you had in your original code. Your original code would work if you did the same thing, like this: from collections import UserDict class FileInfo(UserDict): def __init__(self, filename=None): UserDict.__init__(self) self[name] = filename jeez = FileInfo(yo) (If you're using Python 2, then the first line should be from UserDict import UserDict instead). You can take a look at the source code for the userDict class here: http://hg.python.org/cpython/file/3.3/Lib/collections/__init__.py#l862 . In that class, the code responsible for handling the bracketed name lookup (i.e., self[name]), is in the __getitem__ and __setitem__ methods (and peripherally in __delitem__, __len__ and __contains__) -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: [OT] Usage of U+00B6 PILCROW SIGN (was: generator slides review and Python doc (+/- text bug))
On Tue, Feb 4, 2014 at 1:51 AM, wxjmfa...@gmail.com wrote: I got it. If I'm visiting a page like this: http://docs.python.org/3/tutorial/index.html#the-python-tutorial 1) To read the page, I'm scrolling down. 2) When I have finished to read the page, I scroll up (or scroll back/up) to the top of the page until I see this feature and the title. 3) I click on this feature. 4) The title, already visible, moves, let's say, 2cm higher. ...? Those links aren't for navigation. They're so you can discover anchor links in the page and pass them to someone else. For instance, if I want to point someone to the section of the tutorial that talks about reading and writing files, I could just give them this link: http://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files, instead of pointing them to the main page and instructing them to scroll down until they see Section 7.2 I was able to discover that link by opening the page, highlighting the section header with my mouse, then clicking the pilcrow. That gives me the anchor link to that section header. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to make a tkinter GUI work on top of a CUI program?
On Fri, Jan 3, 2014 at 9:44 PM, Beinan Li li.bei...@gmail.com wrote: But some console programs have their own shell or ncurse-like CUI, such as cscope. So I figured that I need to first subprocess.popen a bidirectional pipe and send command through stdin and get results from stdout and stderr. But in such a case I found that communicate('cmd') will freeze. Right. communicate() waits for the subprocess to end, and the subprocess is still waiting for you to do something. Instead, you'll need to read() and write() to the subprocess' stdin and stdout attributes, probably something like this (untested): def OnClickBtn(self, event): print('OnClickBtn') self.subProc.stdin.write('symbolName\n') print(self.subProc.stdout.read()) It looks like cscope has both a screen-oriented mode and a line-based mode. When you're working with a subprocess like this, you're going to want to be in the line-based mode, so you'll probably want to add -l or -L to your command line. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Copy a file like unix cp -a --reflink
On Wed, Dec 18, 2013 at 1:37 PM, Paulo da Silva p_s_d_a_s_i_l_...@netcabo.pt wrote: Hi! Is there a way to copy a file the same as Unix command: cp -a --reflink src dest without invoking a shell command? I started to dig through the cp man page to see what that did, then gave up when each option expanded out to several more. i.e., -a, --archive same as -dR --preserve=all leads to looking up -d -R and --preserve, etc. To me, it's just not worth it to spend more time researching your question than you spent writing the email asking it. If you don't get the answers you're looking for, you might try asking again, specifying the exact behavior you'd like to achieve. PS: That isn't really meant as any kind of complaint about your question. It's consise, easy to read, and gets right to the point. It just assumes a lot of background knowledge. If someone else happens to already know all of that background, they may be able to help right off. If not, they may be interested enough to do the research to figure it all out and then help. You just may be able to prompt more people to help by cutting down on the amount of work it would take them to do so. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: how to develop code using a mix of an existing python-program and console-commands
On Wed, Dec 18, 2013 at 3:17 PM, Jean Dubois jeandubois...@gmail.com wrote: I have a python-program which I want to perform its task first, then switch to the python console to experiment with further commands, using what was already defined in the python-program. I want this as an alternative for what I do now (but which is not very efficient): I start the python-console and then manually copy-paste line per line from the program in the console, then try out possible continuation commands, if however something goes wrong I have to redo the whole process. On the command line, python itself can take command line options, including one that does exactly what you're looking for. python -i script.py That command will run script.py to its end, then drop you into the interactive interpreter with the environment intact from running the script. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is there no natural syntax for accessing attributes with names not being valid identifiers?
On Wed, Dec 4, 2013 at 3:35 PM, Piotr Dobrogost p...@google-groups-2013.dobrogost.net wrote: Right. If there's already a way to have attributes with these non-standard names (which is a good thing) then for uniformity with dot access to attributes with standard names there should be a variant of dot access allowing to access these non-standard named attributes, too. Given the follow code, what do you think should print? class My_Class(object): pass bar = 1 my_object = My_Class() setattr(my_object, 'foo', 10) setattr(my_object, 'bar', 100) setattr(my_object, 'foo-bar', 1000) print(my_object.foo-bar) Today (in python 3.3), it prints 9, because my_object.foo is 10, the local variable bar is equal to 1, and 10 minus 1 is 9.. Under your new proposal, it would print 1000, right? Is there any way for your proposal to be backwards compatible? -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: Python GUI?
On Wed, Sep 11, 2013 at 4:55 PM, eamonn...@gmail.com wrote: Have you got anything to say on what one I should be using(excluding PyQT because it has a DD designer :( )? Is Tkinter really dead? Should I stick with wxPython? If that's a reason for excluding a GUI toolkit, you're in trouble. Drag and drop layout tools exist for all of your proposed systems. -- Jerry -- https://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen instance hangs
On Fri, Aug 30, 2013 at 11:32 AM, Tim Johnson t...@akwebsoft.com wrote: The objective is to display all output, but to also separate error messages from normal output. I still think you want to use communicate(). Like this: p = subprocess.Popen(args,stderr=subprocess.PIPE,stdout=subprocess.PIPE) output, err = p.communicate() That's it. No need for a loop, or manually handling the fact that stderr and/or stdout could end up with a full buffer and start to block. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: PEPs should be included with the documentation download
On Wed, Aug 21, 2013 at 1:55 PM, random...@fastmail.us wrote: I think, though, that if there's any useful information that can be obtained by reading accepted PEPs but not the documentation, or if things are explained less clearly than in the PEPs, that's a bug in the documentation, and should be remedied by adding to the documentation. Personally, the only PEPs I've used as reference material as PEP 8 (the Python Style Guide), and PEP 249 (the Python Database API Specification v2.0). If I recall correctly, one of the database adapters I used basically said that they were PEP 249 compliant, and didn't have much documentation beyond that. It seems to me that adding the PEPs to the compiled documentation would be a good thing. They are at least as useful as the Language Reference or the Embedding and Extending Python sections that are already included. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGLet, 2to3...?
On Thu, Jul 25, 2013 at 7:49 PM, John Ladasky john_lada...@sbcglobal.net wrote: === john@john:~/Desktop/pyglet-1.2alpha1$ sudo python3 setup.py install [sudo] password for john: running install running build running build_py running install_lib running install_egg_info Removing /usr/local/lib/python3.3/dist-packages/pyglet-1.2alpha1.egg-info Writing /usr/local/lib/python3.3/dist-packages/pyglet-1.2alpha1.egg-info Pyglet was installed to /usr/local/lib/python3.3/dist-packages ... john@john:~/Desktop/pyglet-1.2alpha1$ python3 Python 3.3.1 (default, Apr 17 2013, 22:30:32) [GCC 4.7.3] on linux Type help, copyright, credits or license for more information. import pyglet Traceback (most recent call last): File stdin, line 1, in module File ./pyglet/__init__.py, line 276 print '[%d] %s%s %s' % (thread, indent, name, location) ^ SyntaxError: invalid syntax ... But here, the error message is talking about ./pyglet/__init__.py. I think you're accidentally importing the pyglet package from the local directory instead of from the proper location in dist-packages. Try changing back to your home directory and trying this again. I think you're picking up the code from ~/Desktop/pyglet-1.2alpha1/pyglet instead of from /usr/local/lib/python3.3/dist-packages. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Geo Location extracted from visitors ip address
On Fri, Jul 5, 2013 at 3:08 PM, Νίκος Gr33k ni...@superhost.gr wrote: Is there a way to extract out of some environmental variable the Geo location of the user being the city the user visits out website from? Perhaps by utilizing his originated ip address? No, you'd need to take the originating IP address and look it up in a geolocation database or submit it to a geolocation service and get the response back from them. It's not stored in any environment variables. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: detect key conflict in a JSON file
On Wed, May 29, 2013 at 1:10 PM, Chris Rebert c...@rebertia.com wrote: On Wed, May 29, 2013 at 4:16 AM, Jabba Laci jabba.l...@gmail.com wrote: I have a growing JSON file that I edit manually and it might happen that I repeat a key. If this happens, I would like to get notified. Currently the value of the second key silently overwrites the value of the first. You can pass an appropriate object_pairs_hook function to json.load(): http://docs.python.org/2/library/json.html#repeated-names-within-an-object http://docs.python.org/2/library/json.html#json.load That makes it pretty easy to provide any validation you might like to your JSON data. Here's a quick example that raises ValueError on duplicate keys, since the docs didn't have any examples. Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win32 s = '{x: 1, x: 2, x: 3}' def json_checker(seq): d = {} for key, value in seq: if key in d: raise ValueError(Duplicate key %r in json document % key) else: d[key]=value return d json.loads(s, object_pairs_hook=json_checker) Traceback (most recent call last): File pyshell#31, line 1, in module json.loads(s, object_pairs_hook=checker) File C:\Python32\lib\json\__init__.py, line 320, in loads return cls(**kw).decode(s) File C:\Python32\lib\json\decoder.py, line 351, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File C:\Python32\lib\json\decoder.py, line 367, in raw_decode obj, end = self.scan_once(s, idx) File pyshell#30, line 5, in json_checker raise ValueError(Duplicate key %r in json document % key) ValueError: Duplicate key 'x' in json document -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 378: Format Specifier for Thousands Separator
On Thu, May 23, 2013 at 6:20 PM, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: Can str.format() do the following? f = '%d %d %d' v = '1,2,3' print f % eval(v) Sure: Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win32 f = {} {} {} v = 1,2,3 print(f.format(*eval(v))) 1 2 3 The * unpacks the tuple returned from eval(), so that you get 3 separate parameters passed to format(), instead of the single tuple. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: python backup script
On Mon, May 6, 2013 at 3:01 PM, MMZ programmer.toro...@gmail.com wrote: I am trying to backup database on CentOS linux server,I'm getting error when running the following script. anyone can help? Traceback (most recent call last): File ./backup.py, line 8, in ? username = config.get('client', 'mmz') File /usr/lib/python2.4/ConfigParser.py, line 511, in get raise NoSectionError(section) I've never used ConfigParser, but that error message looks pretty simple to interpret. You've set up a ConfigParser object, told it to read in ~/my.cnf, the asked for the value of section 'client', option 'mmz'. The error indicates that your config files doesn't have a section named 'client'. What is the content of your ~/my.cnf file? -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: import in Python3.3
On Mon, Mar 25, 2013 at 11:49 PM, rocky ro...@gnu.org wrote: On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote: I have a package name collections and inside of my package I want to I find this kind of thing sad: it feels to me that programmers are working around somewhat arbitrary and changing restrictions. Rather than avoid names like collections, why not try to address the underlying problem? There isn't an ambiguity here in my view: the fullname is mypackage.collections You've said a couple of times now that the original author has a package named mypackage with a module collections in it. As far as I can tell, that's untrue. The original post claims to have a package named collections, which is colliding with the builtin module of the same name. As far as I can tell, all of your suggestions about using your pyimport-relative tool aren't helpful unless the author re-names his package from collections to mypackage and then moves all of their code into a collections module inside mypackage, right? -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Maximum Likelihood Estimation
On Fri, Feb 1, 2013 at 1:59 PM, Michael Torrie torr...@gmail.com wrote: Most people on this list consider 8 dihedral to be a badly programmed bot. For what it's worth, I think it's a very cleverly programmed bot. It usually makes just enough sense for me to wonder if there really is a human being behind the keyboard. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Else statement executing when it shouldnt
On Wed, Jan 23, 2013 at 8:35 AM, Jussi Piitulainen jpiit...@ling.helsinki.fi wrote: The feature isn't bad, it's just very, very badly named. I believe it would read better - much better - if it was for/then and while/then instead of for/else and while/else. That's always been my opinion too. I'd remember how the construct worked if it was for/then (and while/then). Since seeing for/else always makes my brain lock up for a few seconds when I'm reading code, I don't bother using it. Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Python parser problem
On Wed, Dec 12, 2012 at 2:10 PM, RCU alex.e.s...@gmail.com wrote: With this occasion I would like to ask also what are the limits of the Python 2.x and 3.x parser. Where can I find what are the limits on the size/lines of the parsed script? The Python Language Reference is probably what you're looking for: http://docs.python.org/2/reference/index.html See, particularly, section 2 about lexical analysis and possibly section 9 for the grammar. The short answer though, is that python doesn't have any limits on the line length or the size of a script, other than that execution will obviously fail if you run out of memory while parsing or compiling the script. PEP 8 (http://www.python.org/dev/peps/pep-0008/) is the Python style guide, and it does have some recommendations about line length (http://www.python.org/dev/peps/pep-0008/#maximum-line-length). That document suggests a maximum length of 79 characters per line, and that's probably what PythonTidy was trying to accomplish by splitting your line. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with usbtmc-communication
On Tue, Dec 11, 2012 at 1:58 AM, Jean Dubois jeandubois...@gmail.com wrote: I found examples in the usbtmc kernel driver documentation (the examples there are given in C): http://www.home.agilent.com/upload/cmc_upload/All/usbtmc.htm?cc=BElc=dut Thanks for that link. I think it explains how the driver works pretty well. I haven't done any work with devices like this, but I see a few things in those docs that might help. In their example code, they open the device with: open(“/dev/usbtmc1”,O_RDWR); That's not exactly the same as what you've been doing. I would try opening the file this way in python: usb_device = open('/dev/usbtmc1', 'w+', buffering=0) That truncates the file after it opening it, and disables any buffering that might be going on. Then, I would try writing to the device with usb_device.write() and usb_device.read(). read() attempts to read to end-of-file, and based on the docs, the driver will work okay that way. Doing that, along with turning off buffering when you open the file, should eliminate any issues with the driver failing to emit newlines someplace. Personally, I would probably try playing with the device from python's interactive interpreter. I think that could shed a lot of light on the behavior you're seeing. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: string contains and special characters
On Tue, Oct 9, 2012 at 10:02 AM, loial jldunn2...@gmail.com wrote: I am trying to match a string that containing the and characters, using the string contains function, but it never seems to find the lines containing the string e.g if mystring.contains(TAG) : Do I need to escape the characters...and if so how? Strings don't have a contains() method. Assuming that mystring is actually a string, you should be getting a very specific error, telling you exactly what's wrong with your code (something like AttributeError: 'str' object has no attribute 'contains'). If that isn't what you're seeing, you'll need to provide the full and complete text of the error you are getting, and preferably enough of your code that we can reproduce the issue and help you solve it. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: get google scholar using python
On Mon, Oct 1, 2012 at 1:28 PM, রুদ্র ব্যাণার্জী bnrj.ru...@gmail.com wrote: So, If I manage to use the User-Agent as shown by you, will I still violating the google EULA? Very likely, yes. The overall Google Terms of Services (http://www.google.com/intl/en/policies/terms/) say Don’t misuse our Services. For example, don’t interfere with our Services or try to access them using a method other than the interface and the instructions that we provide. The only method that Google appears to allow for accessing Scholar is via the web interface, and they explicitly block web scraping through that interface, as you discovered. It's true that you can get around their block, but I believe that doing so violates the terms of service. Google does not appear to offer an API to access Scholar programatically, nor do I see a more specific EULA or TOS for the Scholar service beyond that general TOS document. That said, I am not a lawyer. If you want legal advice, you'll need to pay a lawyer for that advice. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Python source code easy to hack?
On Fri, Sep 28, 2012 at 10:18 AM, stu...@molden.no wrote: Python bytecode is not easier to hack than Java or .NET bytecodes. This is true, but both java and .net are also relatively easy to decompile. In general though, why does it matter? What are you trying to protect yourself against? If you're including secrets in your code like encryption keys or bank account numbers, there's no way to keep them out of the hands of a determined attacker that has access to your file, no matter what language it may be written in. If you must keep anyone from ever seeing how your code works, the only way to do that is to keep all the sensitive bits running on a machine that you control. Typically, you would do that by distributing a client portion of your application, and also running a web service. Then you can have your client connect to the web service, request that the sensitive calculations, or money transfer, or whatever, be done on the server, and just pass back the results. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: How to limit CPU usage in Python
On Thu, Sep 27, 2012 at 12:58 PM, Prasad, Ramit ramit.pra...@jpmorgan.com wrote: On *nix you should just set the appropriate nice-ness and then let the OS handle CPU scheduling. Not sure what you would do for Windows--I assume OS X is the same as *nix for this context. On windows, you can also set the priority of a process, though it's a little different from the *nix niceness level. See http://code.activestate.com/recipes/496767/ for a recipe using pywin32. I believe the psutil module handles this too, but I don't think it manages to abstract away the platform differences. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: How to apply the user's HTML environment in a Python programme?
On Fri, Sep 21, 2012 at 9:31 AM, BobAalsma overhaalsgang_24_...@me.com wrote: Thanks, Joel, yes, but as far as I'm aware these would all require the Python programme to have the user's username and password (or credentials), which I wanted to avoid. No matter what you do, your web service is going to have to authenticate with the remote web site. The details of that authentication are going to vary with each remote web site you want to connect to. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: How to limit CPU usage in Python
On Thu, Sep 20, 2012 at 11:12 AM, Rolando Cañer Roblejo rolando.ca...@cnic.edu.cu wrote: Hi all, Is it possible for me to put a limit in the amount of processor usage (% CPU) that my current python script is using? Is there any module useful for this task? I saw Resource module but I think it is not the module I am looking for. Some people recommend to use nice and cpulimit unix tools, but those are external to python and I prefer a python solution. I am working with Linux (Ubuntu 10.04). Maximum percentage of CPU used isn't normally something you control. The only way I know of to do it involves having another process monitor the thing you want to control and sending signals to stop and start it (e.g., http://cpulimit.sourceforge.net/). Typically, you instead want to control the priority (so that higher priority apps can easily take more CPU time). That's what nice is for (http://docs.python.org/library/os.html#os.nice). If you want to limit a process in the same way that ulimit does, then the resources module is what you want (http://docs.python.org/library/resource.html#resource.setrlimit). Is there a particular reason that you'd rather have your CPU sitting idle, rather than continuing with whatever code is waiting to be run? I'm having a hard time understanding what problem you might be having that some combination of setting the nice level and imposing resource limits won't handle. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
On Thu, Sep 6, 2012 at 11:07 AM, Helpful person rrl...@yahoo.com wrote: I am a complete novice to Python. I wish to access a dll that has been written to be compatible with C and VB6. I have been told that after running Python I should enter from ctypes import * which allows Python to recognize the dll structure. I have placed the dll into my active directory (if that's the correct word, one on my path) for simplification. I tried: import name.dll but this just gave me an error telling me that there was no such module. Can someone please help? You should start by reading the ctypes documentation, here: http://docs.python.org/library/ctypes.html . It has a lot of examples that ought to get you started. When you run into more specific problems, you're going to have to provide a lot more information before we can help you, including the specific documentation of the DLL you're trying to wrap, your platform, and python version. If you are not permitted to share those things, we may not be able to give you much help. Ctypes is very specific to the actual library you are accessing, and requires that you understand the requirements of the underlying DLL. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessing dll
On Thu, Sep 6, 2012 at 12:46 PM, Helpful person rrl...@yahoo.com wrote: The reference might help if I could get Python to recognize the dll as a module. That's never going to happen. It's a DLL, not a python module. I think the documentation lays that out pretty explicitly. Have you experimented with the very first bit of example code in the documentation? What do you get if you do the following at the interactive interpreter? from ctypes import * print windll.insert your dll name here, without the .dll extension -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Objects in Python
On Thu, Aug 23, 2012 at 4:59 AM, Jussi Piitulainen jpiit...@ling.helsinki.fi wrote: I don't get it either. To me the python-has-no-variables campaigners seem confused. As far as I can see, Python can be seen in terms of variables bound to (locations containing) values perfectly well, in a way that should be quite familiar to people who come from Java (or Lisp, Scheme like me). Personally, when I was learning python I found the idea of python having names and values (rather than variables and references) to clear up a lot of my misconceptions of the python object model. I think it's done the same for other people too, especially those who come from the C world, where a variable is a named and typed location in memory. Perhaps those that come from the Java and Lisp world don't find the name/value paradigm as helpful. Still, it seems silly to excoriate people on the list for trying to explain python fundamentals in several different ways. Sometimes explaining the same idea in different words helps people understand the concept better. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: writelines puzzle
On Wed, Aug 22, 2012 at 11:38 AM, William R. Wing (Bill Wing) w...@mac.com wrote: Much to my surprise, when I looked at the output file, it only contained 160 characters. Catting produces: StraylightPro:Logs wrw$ cat RTT_monitor.dat 2354[ 734716.72185185 734716.72233796 734716.72445602 ..., 734737.4440162 734737.45097222 734737.45766204][ 240.28.5 73.3 ..., 28.4 27.4 26.4] If that's the full output, then my guess is that x_dates and y_rtt are not actual python lists. I bet they are, in fact, numpy arrays and that the string representation of those arrays (what you're getting from str(x_dates), etc) include the '...' in the middle instead of the full contents. Am I close? -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: python 6 compilation failure on RHEL
On Tue, Aug 21, 2012 at 12:34 AM, John Nagle na...@animats.com wrote: After a thread of clueless replies, it's clear that nobody responding actually read the build log. Here's the problem: The very first reply, Emile's, pointed out that these were optional modules, and that python did, in fact build successfully. Failed to find the necessary bits to build these modules: bsddb185 dl imageop sunaudiodev What's wrong is that the Python 2.6 build script is looking for some antiquated packages that aren't in a current RHEL. Those need to be turned off. They don't need to be turned off. They can either be ignored (because they aren't needed, and did not cause the build to fail), or the development libraries for those pieces can be installed and python recompiled. The rest of the thread has been commenting on the OP's choice of python version and operating system. That's not exactly on topic, but the original question was answered in the very first response. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: ONLINE SERVER TO STORE AND RUN PYTHON SCRIPTS
On Sun, Aug 19, 2012 at 6:27 PM, coldfire amangill.coldf...@gmail.com wrote: Also I have no idea how to deploy a python script online. I have done that on my local PC using Apache server and cgi but it Works fine. Whats this all called? as far as I have searched its Web Framework but I dont wont to develop a website Just a Server which can run my scripts at specific time and send me email if an error occurs. I use Python And i am not getting any lead. If you want to host web pages, like your're doing on your local pc with Apache and cgi, then you need an account with a web server, and a way to deploy your scripts and other content. This is often known as a 'web hosting service'[1]. The exact capabilities and restrictions will vary from provider to provider. If you just want an alway-on, internet accessable place to store and run your python scripts, you may be interested in a 'shell account'[2], or if you need more control over the environment, a 'virtual private server'[3]. That may give you a few terms to google, and see what kind of service you need. 1 http://en.wikipedia.org/wiki/Shell_account 2 http://en.wikipedia.org/wiki/Web_host 3 http://en.wikipedia.org/wiki/Virtual_private_server -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Why doesn't Python remember the initial directory?
On Sun, Aug 19, 2012 at 9:57 PM, kj no.em...@please.post wrote: By now I have learned to expect that 99.99% of Python programmers will find that there's nothing wrong with behavior like the one described above, that it is in fact exactly As It Should Be, because, you see, since Python is the epitome of perfection, it follows inexorably that any flaw or shortcoming one may *perceive* in Python is only an *illusion*: the flaw or shortcoming is really in the benighted programmer, for having stupid ideas about programming (i.e. any idea that may entail that Python is not *gasp* perfect). Pardon my cynicism, but the general vibe from the replies I've gotten to my post (i.e. if Python ain't got it, it means you don't need it) is entirely in line with these expectations. Since you have no respect for the people you're writing to, why bother? I know I certainly have no desire to spend any time at all on your problem when you say things like that. Perhaps you're looking for for the argument clinic instead? http://www.youtube.com/watch?v=RDjCqjzbvJY -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I display unicode value stored in a string variable using ord()
On Fri, Aug 17, 2012 at 1:49 PM, wxjmfa...@gmail.com wrote: The character '…', Unicode name 'HORIZONTAL ELLIPSIS', is one of these characters existing in the cp1252, mac-roman coding schemes and not in iso-8859-1 (latin-1) and obviously not in ascii. It causes Py3.3 to work a few 100% slower than Py3.3 versions due to the flexible string representation (ascii/latin-1/ucs-2/ucs-4) (I found cases up to 1000%). '…'.encode('cp1252') b'\x85' '…'.encode('mac-roman') b'\xc9' '…'.encode('iso-8859-1') # latin-1 Traceback (most recent call last): File eta last command, line 1, in module UnicodeEncodeError: 'latin-1' codec can't encode character '\u2026' in position 0: ordinal not in range(256) If one could neglect this (typographically important) glyph, what to say about the characters of the European scripts (languages) present in cp1252 or in mac-roman but not in latin-1 (eg. the French script/language)? So... python should change the longstanding definition of the latin-1 character set? This isn't some sort of python limitation, it's just the reality of legacy encodings that actually exist in the real world. Very nice. Python 2 was built for ascii user, now Python 3 is *optimized* for, let say, ascii user! The future is bright for Python. French users are better served with Apple or MS products, simply because these corporates know you can not write French with iso-8859-1. PS When TeX moved from the ascii encoding to iso-8859-1 and the so called Cork encoding, they know this and provided all the complementary packages to circumvent this. It was in 199? (Python was not even born). Ditto for the foundries (Adobe, Linotype, ...) I don't understand what any of this has to do with Python. Just output your text in UTF-8 like any civilized person in the 21st century, and none of that is a problem at all. Python make that easy. It also makes it easy to interoperate with older encodings if you have to. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: print(....,file=sys.stderr) buffered?
On Mon, Aug 13, 2012 at 11:16 AM, Helmut Jarausch jarau...@skynet.be wrote: Now, when executing this, I always get +++ before calling foo --- after calling foo entering foo ... Can you give us a piece of code we can run that produces this output for you? You gave us an outline in your original post, but it would be useful to have a self contained example that you can say reliably produces the unexpected output for you. Also, what environment, OS, and exact python version is this? Is the code being run in an IDE of some sort? Does the behavior change if you call your code directly from the command line? -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: howto do a robust simple cross platform beep
On Fri, Jul 13, 2012 at 9:00 PM, Gelonida N gelon...@gmail.com wrote: I tried the simplest approach (just printing the BEL character '\a' chr(7) to the console. That's what I do when I want to send an audible alert to the user of a console based program. It's then up to the user's terminal to do whatever the user wants. Printing a BEL character has the added advantage that it plays nicely with programs that are run remotely (through ssh sessions and the like). Personally, I'm usually in a screen session, inside either an xterm or over an ssh link, and have visual bells turned on so I can see the alerts, even when they pop up in another screen. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: using identifiers before they are defined
On Tue, Jun 12, 2012 at 2:33 PM, Julio Sergio julioser...@gmail.com wrote: Suppose I have to define two functions, aa, and, bb that are designed to call each other: def aa(): ... ... a call of bb() somewhere in the body of aa ... def bb(): ... ... a call of aa() somewhere in the body of bb ... Whatever the order of definition of aa and bb the problem remains, one of the two identifiers is not known ... This works just fine in python, exactly as you've written it. What's the actual problem you're having? -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: English version for Mémento Python 3 (draft, readers needed)
On Wed, Jun 6, 2012 at 4:10 PM, Alec Ross a...@arlross.demon.co.uk wrote: FWIW, English idiomatic usage includes see overleaf, and see over, for the obverse side of a page/sheet, i.e, the following page; and see facing page, w/ the obvious meaning. For what it's worth, I've never seen either of those constructs (see overleaf and see over). Are they perhaps more common in a particular academic context, or possibly more common in places that use British English spellings rather than American English? Typically I've just seen see other side, or (very occasionally) see reverse and see obverse. Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: DateTime objectFormatting
On Wed, May 2, 2012 at 10:49 AM, Nikhil Verma varma.nikhi...@gmail.com wrote: What i am able to achieve with this class object to return is :- Gen GI Monday May 7 I want that the this class should return object like this :- Gen GI Monday AM, May 7 Pancreas Tuesday PM, May 8 Check the documentation for the strftime method: http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior That has a list of the various formatting directives that can be used to lay out your date and time as you wish. In this case, instead of %A %B %d, you probably want %A %p, %B %d. That is, Full Weekday Name, followed by the AM/PM marker, then a comma, then the Full Month Name and the day of month. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: syntax for code blocks
On Tue, May 1, 2012 at 1:07 PM, Kiuhnm kiuhnm03.4t.yahoo...@mail.python.org wrote: If you had read the module's docstring you would know that the public version uses Are you aware that you've never posted a link to your module, nor it's docstrings? Are you also aware that your module is essentially unfindable on google? Certainly nothing on the first two pages of google results for 'python codeblocks' jumps out at me as a python module of that name. Perhaps you would have better luck if you either post the actual code you want people to critique, or posted a link to that code. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: md5 check
On Wed, Apr 18, 2012 at 9:31 PM, contro opinion contropin...@gmail.com wrote: i have download file (gpg4win-2.1.0.exe from http://www.gpg4win.org/download.html) when i run : Type help, copyright, credits or license for import md5 f=open('c:\gpg4win-2.1.0.exe','r') print md5.new(f.read()).hexdigest() 'd41d8cd98f00b204e9800998ecf8427e' it is not = f619313cb42241d6837d20d24a814b81a1fe7f6d gpg4win-2.1.0.exe please see :gpg4win-2.1.0.exe from http://www.gpg4win.org/download.html why ? Probably because you opened the file in text mode, instead of binary mode. Try opening the file this way: f=open('c:\gpg4win-2.1.0.exe','rb') -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Script Works Locally But Not Remotely with SSH
On Sat, Apr 7, 2012 at 5:41 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: The WinXP machine would need to have X-client translator (something that redirects all the Windows native graphics into X protocol and ships it to the specified server machine). As I recall -- such are not cheap applications. X Servers for windows aren't expensive pieces of software anymore. XMing is quite good, and free. Cygwin also has an X server, but Cygwin always seems like too much of a hassle to me. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Script Works Locally But Not Remotely with SSH
On Tue, Mar 27, 2012 at 8:51 PM, goldtech goldt...@worldpost.com wrote: I have a WinXP PC running an SSH server and I have a Linux PC with an SSH client and logged into the XP seemingly OK. It's all on my personal LAN, the connection seems OK. I have a py file on the XP that I run via SSH from the Linux, it's: import webbrowser webbrowser.open('www.google.com') This runs OK started on the local XP PC, the browser Firefox opens and goes to the site, or it opens a tab to the site. But executing that same file via SSH does not open Firefox...doing it via SSH starts Firefox ( I see it begin in the process manager and I see web activity) but Firefox does not open it's window. Why the does the window not open when the script is started remotely? How are you running the ssh server on the windows machine? Is it a windows service? If so, what user does it run as, and is the service configured to be allowed to interact with the desktop? IIRC, by default most windows services run as a different user than you, and do not have permission to interact with your desktop session. You may be able to get the firefox window to pop up on the ssh server machine if you allow it to interact with the desktop, assuming that's what you're trying to do. Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Python simulate browser activity
On Thu, Mar 15, 2012 at 10:54 PM, Chris Rebert c...@rebertia.com wrote: On Thu, Mar 15, 2012 at 7:23 PM, choi2k rex.0...@gmail.com wrote: The application aims to simulate user activity including visit a website and perform some interactive actions (click on the menu, submit a form, redirect to another pages...etc) Did you look at Selenium? http://seleniumhq.org/ You might also be interested in Sikuli (http://sikuli.org/), which uses Jython to write scripts to automate other programs using screenshots. It's pretty neat if you need to automate a GUI that is otherwise difficult to deal with. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI for pickle read
On Tue, Feb 28, 2012 at 12:51 PM, Smiley 4321 ssmil...@gmail.com wrote: Can I have some thoughts about - building a GUI to display the results of the pickle read? A prototype code should be fine on Linux. It doesn't seem like it would be all that useful, though I may just be lacking in imagination. What would you do with such a thing? -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Just curious: why is /usr/bin/python not a symlink?
On Thu, Feb 23, 2012 at 2:11 PM, HoneyMonster someone@someplace.invalid wrote: $ cd /usr/bin $ ls -l python* -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python lrwxrwxrwx 1 root root 6 Oct 29 19:34 python2 - python -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python2.7 $ diff -s python python2.7 Files python and python2.7 are identical $ I'm just curious: Why two identical files rather than a symlink? It's not two files, it's a hardlink. You can confirm by running ls -li python* and comparing the inode numbers. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Just curious: why is /usr/bin/python not a symlink?
On Thu, Feb 23, 2012 at 2:34 PM, HoneyMonster someone@someplace.invalid wrote: On Thu, 23 Feb 2012 14:24:23 -0500, Jerry Hill wrote: It's not two files, it's a hardlink. You can confirm by running ls -li python* and comparing the inode numbers. You are spot on. Thank you, and sorry for my stupidity. I don't think you're stupid. It's hard to tell the difference between two separate files with the same file size and a hardlink. The biggest clue is the number 2 in the second column. If I recall correctly, for directories, that's the number of entries in the directory. For files, that number is the number of hardlinks referring to that file. Even with that, it's hard to tell what files are hardlinked together, and figuring it out by inode is a pain in the neck. Personally, I prefer symlinks, even if they introduce a small performance hit. Readability counts, even in the filesystem. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: package extension problem
On Sun, Feb 12, 2012 at 1:46 PM, Fabrizio Pollastri f.pollas...@inrim.itwrote: Hello, I wish to extend the functionality of an existing python package by creating a new package that redefines the relevant classes of the old package. Each new class inherits the equivalent old class and adds new methods. ... There is a way to solve this problem without redefining in the new package all the methods of the old package that return old classes? The general answer is no. If you want the methods of your subclass to behave differently, in any way, from the same methods in the superclass, then you must write new code that defines the behavior that you want. Sometimes people write their classes so they automatically play nicely when subclassed, and sometimes they don't. In general, it's impossible to always do the right thing when you don't know what particular behavior a subclass might need to override, so a lot of times people don't bother to write their classes to check for subclasses being passed in, etc. Since you haven't actually shown us any code, that's about all I can tell you. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: object aware of others
On Sun, Jan 29, 2012 at 1:47 AM, Lee lchapli...@gmail.com wrote: I was afraid that a list/set/dictionary and alike is the answer, but, anyway, thanks everybody. It doesn't seem too bad to keep track of the instances in the class object using weak references (http://docs.python.org/py3k/library/weakref.html). Here's an example that seems to do what you're asking using python 3.2, but it should be pretty similar in python 2: import weakref class A: _instances = set() def __init__(self): self.myname = 'IamA' print('This is A') self.__class__._instances.add(weakref.ref(self)) def foo(self): print(foo) def update(self): for ref in self.__class__._instances: obj = ref() if obj is not None: print(The only friends I've got are , ref, obj.myname) If you're creating lots of instances of A and deleting them, it would probably be worth removing the old weakrefs from the _instances set instead of just ignoring them when calling update(). -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: search google with python
On Wed, Jan 25, 2012 at 5:36 AM, Tracubik affdfsdfds...@b.com wrote: thanks a lot but it say it's deprecated, is there a replacement? Anyway it'll useful for me to study json, thanks :) I don't believe Google is particularly supportive of allowing third-parties (like us) to use their search infrastructure. All of the search-related APIs they used to provide are slowly going away and not being replaced, as far as I can tell. If you just need to search images (and not Google Image Search in particular), Bing's API appears to be supported and not about to go away. ( http://msdn.microsoft.com/en-us/library/dd900818.aspx ) You could, in theory, make requests to Google just like a web browser and parse the resulting HTML, but that tends to be fragile and prone to break. I believe it also violates Google's Terms of Service. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: windows and home path
On Tue, Jan 24, 2012 at 9:56 AM, Andrea Crotti andrea.crott...@gmail.com wrote: Window never stops to surprise me, I've been banging my head since yesterday and only now I now what is the problem. So suppose I have something like from os import path print path.expanduser('~') If I run it from cmd.exe I get /Users/user, doing the same in an emacs eshell buffer I get /Users/user/AppData/Roaming. What sense does it make?? Is there a way to get always the same variable from python somehow? The os.path.exanduser() docs ( http://docs.python.org/library/os.path.html#os.path.expanduser ) say that On Windows, HOME and USERPROFILE will be used if set, otherwise a combination of HOMEPATH and HOMEDRIVE will be used. An initial ~user is handled by stripping the last directory component from the created user path derived above. So, my guess is that emacs is mangling your HOME environment variable. That appears to be confirmed by the emacs documentation here: http://www.gnu.org/software/emacs/manual/html_node/emacs/General-Variables.html#General-Variables . At a guess, you do not have a system-wide HOME environment variable. When you launch python from the command line, it uses either your USERPROFILE setting, or is falling back to using HOMEDIRVE and HOMEPATH. When you launch emacs, it sees that HOME is not set, and emacs helpfully sets it for you, to whatever path it thinks is correct. That would explain why you see different answers in different environments. Does that explain the behavior you're seeing? -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: windows and home path
On Tue, Jan 24, 2012 at 11:05 AM, Jerry Hill malaclyp...@gmail.com wrote: So, my guess is that emacs is mangling your HOME environment variable. That appears to be confirmed by the emacs documentation here: http://www.gnu.org/software/emacs/manual/html_node/emacs/General-Variables.html#General-Variables I know, it's bad form to follow up to my own email, but here's a more concrete reference stating that emacs will set HOME when emacs starts: http://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html [Wherever Emacs finds your .emacs file], Emacs sets the value of the HOME environment variable to point to it, and it will use that location for other files and directories it normally creates in the user's home directory. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: windows and home path
On Tue, Jan 24, 2012 at 11:10 AM, Andrea Crotti andrea.crott...@gmail.com wrote: Ah yes thanks for the explanation, on Python 2.7 on Linux I don't see the same doc, it might have been updated later.. Anyway I just want to make sure that I get always the same path, not depending on the program. From a first look it seems that just using os.getenv('HOMEPATH') on windows might make the trick.. It would not do the trick on my windows XP workstation here. Your target environments may be different, of course. From a general command prompt (cmd.exe) on my work machine, here's what you would have to work with: HOMEDRIVE=H: HOMEPATH=\ HOMESHARE=\\server\share\userdirectory USERPROFILE=C:\Documents and Settings\username There is no HOME set here. So, what's the right home directory for me on this PC? Depending on your opinion of right you could end up with three different answers: H:\, \\server\share\userdirectory, or C:\Documents and Settings\username all seem like valid candidates to me. Just going by HOMEPATH isn't going to be helpful if I were to run your code though. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a serial stream too slowly
On Mon, Jan 23, 2012 at 4:48 PM, M.Pekala mcdpek...@gmail.com wrote: Hello, I am having some trouble with a serial stream on a project I am When one sensor is running my python script grabs the data just fine, removes the formatting, and throws it into a text control box. However when 3 or more sensors are running, I get output like the following: Sensor 1: 373 Sensor 2: 112$$M-160$G373 Sensor 3: 763$$A892$ I am fairly certain this means that my code is running too slow to catch all the '$' markers. Below is the snippet of code I believe is the cause of this problem... That doesn't sound right. Being too slow seems unlikely to produce the wrong data... def OnSerialRead(self, event): text = event.data self.sensorabuffer = self.sensorabuffer + text self.sensorbbuffer = self.sensorbbuffer + text self.sensorcbuffer = self.sensorcbuffer + text if sensoraenable: sensorresult = re.search(r'\$A.*\$.*', self.sensorabuffer ) Here, you search in sensorabuffer (which, by the way, would be much more readable to me as sensor_a_buffer, as recommended by the PEP 8 style guide). if sensorbenable: sensorresult = re.search(r'\$A.*\$.*', self.sensorbenable) here, you're not searching in the buffer, but in the enable flag. if sensorcenable: sensorresult = re.search(r'\$A.*\$.*', self.sensorcenable) And here too. Does that fix the problem? -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Please don't use setuptools, the rotten .egg install system.
On Wed, Jan 18, 2012 at 1:24 PM, John Nagle na...@animats.com wrote: Please don't use setuptools, the so-called easy installation system in your packages. It just makes things more complicated, adds dependencies, and needs too many weird options if things aren't exactly where it wants them. Since setuptools is non-standard, it has to be installed before installing other things. Please don't use any projects that are built with setuptools or easy installation systems. Problem solved. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Type object returned by the re.compile function
On Tue, Dec 27, 2011 at 4:56 PM, candide candide@free.invalid wrote: import re reo = re.compile('') reo.__class__ Traceback (most recent call last): File stdin, line 1, in module AttributeError: __class__ I'm not going to comment on what type is returned from the various functions in the re module, mostly because all I have installed locally is 2.6, and I'm not sure if anything has changed in 2.7 or 3.2. Instead, I will recommend a different tool for your toolbox. Take a look at the type() builtin function ( http://docs.python.org/library/functions.html#type ). Particularly, instead of inspecting reo.__class__ in your example above, you can print out type(reo). At a guess, those objects are missing the __class__ attribute, possibly because they are old style classes. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Upgraded Ubuntu - 11.10, Python - 2.7.2. Now psyco doesn't work?
On Tue, Dec 20, 2011 at 5:43 PM, John Ladasky lada...@my-deja.com wrote: I was running Ubuntu Linux 10.10, on which Python 2.6.6 was the standard distribution. I succeeded in doing an alternate install of Python 2.7.2, over Ubuntu 10.10. But I use so many packages in my code. Dealing with the package dependencies, and the intricacies of invoking the right version of Python at the command prompt, were making me dizzy. After a few hours of struggle, I just decided to upgrade my OS to Ubuntu 11.10, on which Python 2.7.2 is the standard distribution. I then installed numpy, scipy, and matplotlib, and confirmed that they work. I needed just one more package to try my code: psyco. According to the Synaptic Package Manager of Ubuntu 11.10, there is a supported version of psyco for this OS revision, python-psyco 1.6-2ubuntu1. I downloaded it. It installed. But an attempt to import psyco gives me an ImportError at the python prompt. From the psyco homepage ( http://psyco.sourceforge.net/ ) Python 2.7 is unsupported so far. Anyone interested in porting Psyco to it is welcome. I started the work in a branch but it needs finishing. That's the most recent news item on the home page, and it's dated July 16, 2010, about a year and a half ago. I don't think psyco supports python 2.7. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Python horks on WinXP path names
On Thu, Dec 8, 2011 at 3:16 PM, Eric einazaki...@yahoo.com wrote: I'm running Python 2.7 on WinXP (ActiveState community version) and when I try to do this: if __name__ == '__main__': root = Tkinter.Tk() root.withdraw() fileNames = tkFileDialog.askopenfilenames() root.destroy() print fileNames # windows filename gets for fileName in fileNames: print fileName file = open(fileName, 'r') for line in file.readlines(): print line.strip() I get this: C:\Documents and Settings\eric\Desktop\PythonShoppython picker.py {C:/Documents and Settings/eric/Desktop/PythonShop/cereal.py} { Traceback (most recent call last): File picker.py, line 31, in module file = open(fileName, 'r') IOError: [Errno 2] No such file or directory: u'{' That is, fileName is in a form that open() doesn't recognize. On a BSD box the code works fine. What's going on with the file name and how do I fix it? Try replacing your current print fileNames line with the follwing: print type(fileNames), repr(fileNames) The behavior you're seeing seems to indicate that fileNames is really a single filename (a single unicode string), rather than a list of file names (a list containing strings). I don't know why that would be, but it would be helpful to confirm that that is, indeed, the problem. I guess you should also double check that the version of the code you're running on windows does, in fact, call tkFileDialog.askopenfilenames() rather than tkFileDialog.askopenfilename() The two calls are just one letter different, but the first one is supposed to return a list, and the second one is supposed to just return a single string. -- http://mail.python.org/mailman/listinfo/python-list
Re: tracking variable value changes
On Thu, Dec 8, 2011 at 3:17 PM, Catherine Moroney catherine.m.moro...@jpl.nasa.gov wrote: Is there some way to rewrite the code above so the change of a from 1.0 to 100.0 is reflected in the dictionary. I would like to use simple datatypes such as floats, rather than numpy arrays or classes. No, there is not. You would need to use a mutable data type, and float is not mutable (neither are ints or strings). -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Py and SQL
On Wed, Nov 30, 2011 at 3:30 PM, Verde Denim tdl...@gmail.com wrote: dbCursor1.execute('select lpad(' ', 2*level) || c Privilege, Roles and Users from ( select null p, name c from system_privilege_map where name like upper(\'%enter_privliege%\') union select granted_role p, grantee c from dba_role_privs union select privilege p, grantee c from dba_sys_privs) start with p is null connect by p = prior c') I think this is your problem. Your string is delimited with single quotes on the outside ('), but you also have a mix of single and double quotes inside your string. If you were to assign this to a variable and print it out, you would probably see the problem right away. You have two options. First, you could flip the outer quotes to double quotes, then switch all of the quotes inside the string to single quotes (I think that will work fine in SQL). Second, you could use a triple-quoted string by switching the outer quotes to ''' or . Doing that would let you mix whatever kinds of quotes you like inside your string, like this (untested): sql = '''select lpad(' ', 2*level) || c Privilege, Roles and Users from ( select null p, name c from system_privilege_map where name like upper(\'%enter_privliege%\') union select granted_role p, grantee c from dba_role_privs union select privilege p, grantee c from dba_sys_privs) start with p is null connect by p = prior c''' dbCursor1.execute(sql) Once you do that, I think you will find that the enter_priviliege bit in your SQL isn't going to do what you want. I assume you're expecting that to automatically pop up some sort of dialog box asking the user to enter a value for that variable? That isn't going to happen in python. That's a function of the database IDE you use. You'll need to use python to ask the user for the privilege level, then substitute it into the sql yourself. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I submit an issue with Python 2.5.6?
2011/11/29 Toshiyuki Ogura m...@live.jp I found a problem with Python 2.5.6. ... Can I submit the issue at bugs.python.org? I think many people are still using Python 2.5 because of Google App Engine and fixing bugs with 2.5 is still helpful. I don't think they'll be accepted. Python 2.5 is not slated to receive any more releases, ever. Not even source-only security fixes. According to http://www.python.org/getit/releases/2.5.6/, This release is the final release of Python 2.5; under the current release policy, no security issues in Python 2.5 will be fixed anymore. Given that they're not even accepting security patches, I'm sure they won't accept non-security bugfixes either. If your goal is to get your patch accepted and deployed on google's app engine infrastructure, you could try getting a hold of someone at google, and asking if they accept patches directly, since there will be no further maintenance from the core python developers. I have no idea how difficult it would be to do that, or if there's any interest in accepting patches against python 2.5 at google. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: String splitting by spaces question
On Wed, Nov 23, 2011 at 12:10 PM, Massi massi_...@msn.com wrote: Hi everyone, I have to parse a string and splitting it by spaces. The problem is that the string can include substrings comprises by quotations which must mantain the spaces. What I need is to pass from a string like: This is an 'example string' to the following vector: [This, is, an, example string] Which is the best way to achieve this? This sounds a lot like the way a shell parses arguments on the command line. If that's your desire, python has a module in the standard library that will help, called shlex (http://docs.python.org/library/shlex.html). Particularly, shlex.split may do exactly what you want out of the box: Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 import shlex s = This is an 'example string' shlex.split(s) ['This', 'is', 'an', 'example string'] -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: How to mix-in __getattr__ after the fact?
On Fri, Oct 28, 2011 at 1:34 PM, dhyams dhy...@gmail.com wrote: If I call __getattr__ directly, as in bessie.__getattr__('foo'), it works as it should obviously; so the method is bound and ready to be called. But Python does not seem to want to call __getattr__ appropriately if I mix it in after the object is already created. Is there a workaround, or am I doing something wrongly? Python looks up special methods on the class, not the instance (see http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes). It seems like you ought to be able to delegate the special attribute access from the class to the instance somehow, but I couldn't figure out how to do it in a few minutes of fiddling at the interpreter. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading pen drive data
On Sat, Sep 3, 2011 at 12:21 PM, mukesh tiwari mukeshtiwari.ii...@gmail.com wrote: I am getting Traceback (most recent call last): File Mount.py, line 7, in module observer = QUDevMonitorObserver(monitor) NameError: name 'QUDevMonitorObserver' is not defined Could any one please tell me how to avoid this error . It looks to me like that should be pyudev.QUDevMonitorObserver, shouldn't it? -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: How to convert a list of strings into a list of variables
On Thu, Aug 18, 2011 at 11:19 AM, noydb jenn.du...@gmail.com wrote: I am being passed the list of strings. I have variables set up already pointing to files. I need to loop through each variable in the list and do things to the files. The list of strings will change each time, include up to 22 of the same strings each time. If you have a mapping of strings to values, you should just go ahead and store them in a dictionary. Then the lookup becomes simple: def foo(list_of_strings): mapping = { bar0: /var/log/bar0.log, bar1: /usr/local/bar/bar1.txt, bar2: /home/joe/logs/bar2.log, } for item in list_of_strings: filename = mapping[item] do_something(filename) (Untested) -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Determine what msvcrt.getch() is getting?
On Tue, Aug 16, 2011 at 5:43 PM, John Doe jdoe@usenetlove.invalid wrote: Whatever msvcrt.getch() is returning here in Windows, it's not within the 1-255 number range. How can I determine what it is returning? I would like to see whatever it is getting. Just print it. Like this: import msvcrt ch = msvcrt.getch() print (ch) for a bit more information, do this instead: import msvcrt ch = msvcrt.getch() print(type(ch), repr(ch), ord(ch)) -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Wait for a keypress before continuing?
On Tue, Aug 16, 2011 at 5:59 PM, John Doe jdoe@usenetlove.invalid wrote: No. I am running this from within Windows, all sorts of Windows. What does that mean? You seem very resistant to answering anyone's questions about your code. Is your code run from the command line, or does it have a GUI? If it has a GUI, what windowing toolkit are you using? If you have code that's not working, please, show us a short, run-able bit of sample code that demonstrates the problem you're experiencing. Describe the behavior you see, the behavior you expected instead, and the full text of any traceback you may be getting. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Only Bytecode, No .py Files
On Fri, Jul 29, 2011 at 8:51 AM, John Roth johnro...@gmail.com wrote: Sorry. I thought what you posted was from the OP. I guess I don't really expect someone to post a completely irrelevant trace in a thread started by someone who has a problem. I'm not sure why you would think that that post was by the original poster, or that it was irrelevant. It seems to me that it demonstrated exactly the behavior Eldon was complaining about as a normal part of the operation of lots of normal unix programs. Thomas even said that in the very first line of his post (after the quoted bit). -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: What is xrange?
On Fri, Jul 29, 2011 at 3:36 PM, Billy Mays no...@nohow.com wrote: Is xrange not a generator? I know it doesn't return a tuple or list, so what exactly is it? Y doesn't ever complete, but x does. x = (i for i in range(10)) y = xrange(10) xrange() does not return a generator. It returns an iterable xrange object. If you want the iterator derived from the iterable xrange object, you can get it like this: iterator = y.__iter__() See http://docs.python.org/library/functions.html#xrange for the definition of the xrange object. http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/ seems to cover the differences between iterables, iterators, and generators pretty well. Some more reading: http://docs.python.org/howto/functional.html http://www.python.org/dev/peps/pep-0255/ http://www.python.org/dev/peps/pep-0289/ -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I access IDLE in Win7
On Wed, Jul 27, 2011 at 5:26 PM, W. eWatson wolftra...@invalid.com wrote: .py=Python.File .pyw=Python.NoConFile Python.File=C:\Python25\python.exe %1 %* Python.File=C:\Python25\python.exe %1 %* Python.NoConFile=C:\Python25\pythonw.exe %1 %* That all looks good. I cannot copy from the cmd window. It ends with [errorno 13] Permission denied to c:||Users\\Wayne\\idlerc\\recent-files.lst' That sounds like the root of the problem, then. I'm assuming Wayne is your username, but I don't know why you wouldn't have permission to access something in your own user directory. Can you try deleting that file in the windows explorer? You could try messing with the permissions, but I doubt you care about a recent file list that sounds several months old. You might even try removing (or renaming) the whole C:\Users\Wayne\idlerc folder. Idle should re-build anything it needs if it's not there when you start up. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I access IDLE in Win7
On Wed, Jul 27, 2011 at 12:28 PM, W. eWatson wolftra...@invalid.com wrote: If I run cmd.exe and work my way down to .../idlelib, I find nothing but idle.bat. strange. Hidden? I can get into line mode by using python.exe. That is, I can type in print abc, and get a result. So, you don't have an idle.py or idle.pyw in C:\Python26\Lib\idlelib\ (or where ever you installed python)? If not, it sounds to me like your python installation is screwed up. I would re-install. Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I access IDLE in Win7
On Wed, Jul 27, 2011 at 3:34 PM, W. eWatson wolftra...@invalid.com wrote: On 7/27/2011 9:48 AM, Jerry Hill wrote: So, you don't have an idle.py or idle.pyw in C:\Python26\Lib\idlelib\ (or where ever you installed python)? If not, it sounds to me like your python installation is screwed up. I would re-install. Yes, I have both. Neither shows anything on the monitor when I double click them. Oh, I guess I misunderstood. Go ahead and open that cmd.exe window back up. Please run the following and report back the results. In the cmd.exe window run: assoc .py assoc .pyw ftype Python.File ftype Python.NoConFile Those four commands should show us how the python file associations are set up on your computer. Then, let's try to run idle and capture whatever error message is popping up. I don't think you've mentioned what version of python you have installed. The following is for 2.6, since that's what I have installed here, but it should work on any other version if you swap in your installation directory for the 2.6 one below. Still in your cmd.exe window, run the following: c:\Python26\python.exe C:\Python26\Lib\idlelib\idle.py If you get an exception, please copy and paste the details for us. If that works and opens idle, please try running this: C:\Python26\Lib\idlelib\idle.py Based on the behavior you've described so far, that ought to fail, and hopefully give some sort of message or exception for us to diagnose. PS: If you're just trying to get things working, and don't care what might be wrong, I would recommend just re-installing python. That ought to clean up all the file associations and set things up properly for you. That's likely the quickest way to just get things working. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list