Re: Compile python code into a dll
Thank you all for your help. I'm going to try Cython. Regards Rolf On 10/09/12 14:15, Rolf Wester wrote: Hi, I have Python code that I would like to compile into a dll (I have to deliver a C/C++ callable dll and I don't want to reimpelement the Python code in C/C++). It's not for extending Python but I want to call the Python functions and classes from C/C++. It's more like extending C/C++ with Python. I would be very appreciative for any help. Thank you in advance Regards Rolf -- http://mail.python.org/mailman/listinfo/python-list
Re: python CAD libraries?
https://www.google.com/search?q=python+cad+3d+examples&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a First listing looks good, might look later on at it myself: http://www.pythonocc.org/ -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py
On 11/09/2012 04:46, Steven D'Aprano wrote: > On Mon, 10 Sep 2012 15:22:05 -0700, ruck wrote: > >> On Monday, September 10, 2012 1:16:13 PM UTC-7, Steven D'Aprano wrote: > [...] >>> That's not so much a workaround as the officially supported API for >>> dealing with the situation you are in. Why don't you just prepend a >>> '?' to paths like they tell you to? >> >> Good idea, but the first thing os.walk() does is a listdir(), and >> os.listdir() does not like the r'\\?\' prefix. In other words, >> os.walk(r'\\?\C:Users\john\Desktop\sandbox\goo') does not work. > > Now that sounds like a bug to me. If Microsoft officially support > leading ? in file names, then so should Python on Windows. And so it does, but you'll notice from the MSDN docs that the \\? syntax must be supplied as a Unicode string, which os.listdir will do if you pass it a Python unicode object and not otherwise: import os os.listdir(u"?\\c:\\users") # and consequently for p, ds, fs in os.walk(u"?\\c:\\users"): print p TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Compile python code into a dll
Also, and sometimes google does kind of fail you, but straight from your question, I just type in this section of what you wrote: 'Python code that I would like to compile into a dll' Yours comes up as well within that search,but so do quite a few others related to it. > > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -- http://mail.python.org/mailman/listinfo/python-list
Re: python CAD libraries?
And just a little more for you from: http://wiki.python.org/moin/Applications#A3D_CAD.2FCAM This looked interesting: http://free-cad.sourceforge.net/ > > but I have to get to a few other things, so I hope this helps. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -- http://mail.python.org/mailman/listinfo/python-list
Re: python CAD libraries?
Blender is definitely the most popular open-source CAD software; it has even forked its own version of Python to make things run neatly :P On Tue, Sep 11, 2012 at 5:33 PM, Dwight Hutto wrote: > And just a little more for you from: > > http://wiki.python.org/moin/Applications#A3D_CAD.2FCAM > > This looked interesting: > http://free-cad.sourceforge.net/ >> >> > but I have to get to a few other things, so I hope this helps. > > > > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: python CAD libraries?
On Tue, Sep 11, 2012 at 3:36 AM, Alec Taylor wrote: > Blender is definitely the most popular open-source CAD software; it > has even forked its own version of Python to make things run neatly :P > I heard that they were going to change a few things a while back with the Python API(especially the switch to 3.0 in blender 2.5), but thought they were still using regular 3.x. I've been using the 2.49b, and just started using 2.6.2 when I upgraded my Ubuntu to 12.04. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -- http://mail.python.org/mailman/listinfo/python-list
Re: python CAD libraries?
> Blender is definitely the most popular open-source CAD software; it >> has even forked its own version of Python to make things run neatly :P >> > > Plus it never hurts to look around at some of the other interfaces,some of which might have just altered Blender, or something else, just to see which is more user friendly for the individual. But I am a huge Blender fan, so I'll probably not be changing that anytime soon. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: where's the new python gone?
c.c Description: Binary data Op 10 Sep 2012, om 22:53 heeft William R. Wing (Bill Wing) het volgende geschreven: > On Sep 10, 2012, at 11:17 AM, Bob Aalsma wrote: > >> Well, Bill, better late than never - thanks for stepping in. >> You are right, my problems are not yet solved ;) > > As Hans pointed out, you are looking for python, not Python (the frameworks > are named Python, the executable is python). Sorry about that. > > To eliminate the output from TimeMachine (assuming it is using an external > drive or a TimeCapsule), add one more option to the find command: > > $ sudo find -x / -name python -print (or follow his directions for piping to > a file). > > The -x option prevents find from descending into a volume with a different > device number from the one you started on. > > -Bill > -- http://mail.python.org/mailman/listinfo/python-list
Re: submit jobs on multi-core
On 09/11/2012 07:53 AM, Laszlo Nagy wrote: > On 2012-09-11 06:16, Dhananjay wrote: >> Dear all, >> >> I have a python script in which I have a list of files to input one by >> one and for each file I get a number as an output. >> I used for loop to submit the file to script. >> My script uses one file at a time and returns the output. >> >> My computers has 8 cores. >> Is there any way that I could submit 8 jobs at a time and get all the >> output faster ? >> In other words, how can I modify my script so that I could submit 8 >> jobs together on 8 different processors ? >> >> I am bit new to this stuff, please suggest me some directions. > You should first look at the multiprocessing module. It is part of the > standard library. > > http://docs.python.org/library/multiprocessing.html > > Did anybody tried this on a cluster? -- http://mail.python.org/mailman/listinfo/python-list
Re: submit jobs on multi-core
http://celeryproject.org/ Don't eat it all at once On Tue, Sep 11, 2012 at 2:16 PM, Dhananjay wrote: > Dear all, > > I have a python script in which I have a list of files to input one by one > and for each file I get a number as an output. > I used for loop to submit the file to script. > My script uses one file at a time and returns the output. > > My computers has 8 cores. > Is there any way that I could submit 8 jobs at a time and get all the output > faster ? > In other words, how can I modify my script so that I could submit 8 jobs > together on 8 different processors ? > > I am bit new to this stuff, please suggest me some directions. > > Thank you. > > -- Joshi > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
Steven D'Aprano wrote: > But for the record, in principle string comparisons *could* be the > bottleneck. Example: you have 1 strings, which are each created > once and stored in a list. Then you iterate over the list, comparing > every string against every other string. And due to some weird vagary > of the data, the strings are nearly all equal. > > (Why would you do this? I don't know, maybe it's a programmers' > challenge found on the Internet, make up your own scenario...) > > Total number of strings created: 1. > Total number of strings compared: 1. which is exactly what I meant by doing a lot of comparisons (1) on the same string. Perhaps if I'd phrased it more as "you have to be doing many more comparisons than string creation operations" it would have been clearer what I meant. > The overhead of creating the strings is trivial compared to the > overhead of comparing them, and since each string is only created once > anyway, interning them is just a waste of time. No, you created 10k strings many of which are equal and then did 10k comparisons on each most of which found 'yes' they are equal. Interning them would have reduced all the 'true' comparisons to an identity check at the cost of 1 hash and 1 full comparison per string. >> so at the expense of a single dictionary >> insertion when the string is created you can get guaranteed O(1) on >> all the comparisons. > > What interning buys you is that "s == t" is an O(1) pointer compare if > they are equal. But if s and t differ in the last character, __eq__ > will still inspect every character. There is no way to tell Python > "all strings are interned, if s is not t then s != t as well". Right if the strings differ only in the last character, but the rest of this thread has been about how, for random strings, the not-equal case is O(1) as well. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
Oscar Benjamin wrote: >> What interning buys you is that "s == t" is an O(1) pointer compare >> if they are equal. But if s and t differ in the last character, >> __eq__ will still inspect every character. There is no way to tell >> Python "all strings are interned, if s is not t then s != t as well". >> > > I thought that if *both* strings were interned then a pointer > comparison could decide if they were unequal without needing to check > the characters. > > Have I misunderstood how intern() works? > I don't think you've misunderstood how it work, but so far as I can see the code doesn't attempt to short circuit the "not equal but interned" case. The comparison code doesn't look at interning at all, it only looks for identity as a shortcut. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 11 September 2012 10:51, Duncan Booth wrote: > Oscar Benjamin wrote: > > >> What interning buys you is that "s == t" is an O(1) pointer compare > >> if they are equal. But if s and t differ in the last character, > >> __eq__ will still inspect every character. There is no way to tell > >> Python "all strings are interned, if s is not t then s != t as well". > >> > > > > I thought that if *both* strings were interned then a pointer > > comparison could decide if they were unequal without needing to check > > the characters. > > > > Have I misunderstood how intern() works? > > > > I don't think you've misunderstood how it work, but so far as I can see the > code doesn't attempt to short circuit the "not equal but interned" case. > The comparison code doesn't look at interning at all, it only looks for > identity as a shortcut. It also doesn't seem to check if the hash values have been set. I guess the cached hash value is only used in contexts where the hash is explicitly desired. That makes two optimisations that can bring worst case string comparison down to O(1) in many contexts that are available to cpython but unused. But then if full string comparison is already on average O(1) then the cost of checking the interned and hash flags for every string comparison would outweigh the benefits of avoiding the rare worst case O(N) comparisons. Oscar -- http://mail.python.org/mailman/listinfo/python-list
Re: simple client data base
Mark R Rivet wrote: > Thomas 'PointedEars' Lahn wrote: >> Mark R Rivet wrote: >>> Hello all, I am learning to program in python. I have a need to make a >>> program that can store, retrieve, add, and delete client data such as >>> name, address, social, telephone number and similar information. This >>> would be a small client database for my wife who has a home accounting >>> business. >>> >>> I have been reading about lists, tuples, and dictionary data >>> structures in python and I am confused as to which would be more >>> appropriate for a simple database. >> >> […] >> However, if you want your program to manipulate the data *persistently*. >> as it will probably be needed for business, you will need to also store >> it somewhere else than in the volatile memory in which these data >> structures are usually stored. The most simple way would be to store and >> parse the string representation of the objects. >> >> Production-quality implementations of those and other concepts already >> exist, of course, but using something finished and polished does not >> provide as much learning experience. > > Now this is the kind of answer I was hoping for. This gives me food > for thought. Now I have some Ideas of how to appproach this thing. I > know that there are solutions to this problem already but I need to do > my own before I can really use anything better. Thanks for the help. I > fully intend to go with a real realational database, but not now. My > version 1 will be a console interface and dictionaries, lists and > pickling. Version 2 will be with a GUI written in tkinter, and better > and better. I just want to learn how to lay the bricks before I start > using prefab walls. You are welcome. However, I have to concur with the others that in terms of efficiency and reliability, which leads to household peace, you are better off starting with a prepackaged solution instead. You can keep developing your Python-powered database as a pet project for the time being. Your wife will be even more impressed if at one day you can tell her that you wrote completely customizable software that works the same or even better than the one she has been getting used to :) Even if not, you will have learned much about Python and related concepts along the way. Keep in mind, then, that you probably also need a graphical user interface. Please trim your quotes to the relevant minimum next time. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyPyODBC 0.8.4 released with improved compatibility to pyodbc
PyPyODBC - A Pure Python ctypes ODBC module Features -Pure Python, compatible with IronPython and PyPy (tested on Win32) -Almost totally same usage as pyodbc You can simply try pypyodbc in your existing pyodbc powered script with the following changes: #import pyodbc <-- The original pyodbc importing line import pypyodbc as pyodbc # Let pypyodbc "pretend" the pyodbc pyodbc.connect(...)# pypyodbc is now doing pyodbc's job with same APIs! History Version 0.8.4 Sep 9 2012 Improved compatibility with pyodbc; Many underlying bug fixes; Version 0.8.3 Sep 1 2012 sql_longvarchar handling fix; performance optimization; Version 0.8.2 Aug 27 2012 Differentiate sql_varchar and sql_longvarchar; Initial support for SQLAlchemy; Version 0.8.1 Aug 26 2012 Fixed the long type parameter issue; Added support for IronPython; Version 0.8 Aug 25 2012 Added getinfo method; Version 0.7 Jul 28 2012 Fixed nchar/ntext/nvarchar string truncat problem ; Version 0.6 Jul 4 2012 Added Cursor.commit() and Cursor.rollback(); Added readonly keyword to connect; Version 0.5 Jun 23 2012 Initial release; -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: where's the new python gone?
On Sep 11, 2012, at 3:52 AM, Bob Aalsma wrote: > > Op 10 Sep 2012, om 22:53 heeft William R. Wing (Bill Wing) het volgende > geschreven: > >> On Sep 10, 2012, at 11:17 AM, Bob Aalsma wrote: >> >>> Well, Bill, better late than never - thanks for stepping in. >>> You are right, my problems are not yet solved ;) >> >> As Hans pointed out, you are looking for python, not Python (the frameworks >> are named Python, the executable is python). Sorry about that. >> >> To eliminate the output from TimeMachine (assuming it is using an external >> drive or a TimeCapsule), add one more option to the find command: >> >> $ sudo find -x / -name python -print (or follow his directions for piping >> to a file). >> >> The -x option prevents find from descending into a volume with a different >> device number from the one you started on. >> >> -Bill >> > > -- > http://mail.python.org/mailman/listinfo/python-list Well, clearly, the only copies of python 2.7 on your system are from Apple (in System/Library and associated with Xcode). So, either the one you downloaded overwrote one of them, or the install failed and you didn't notice the error go zooming by in a listing. Can you run the install procedure again and capture the output? -Bill -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: where's the new python gone?
On Sep 11, 2012, at 9:12 AM, Bob Aalsma wrote: > Hmm, this feels embarrassing but the good news is that, on seeing the errors, > I remember using a "sudo" with the make install and only later finding out > that I shouldn't have. > > Last login: Tue Sep 11 09:46:11 on ttys000 > macpro1:~ debaas$ pwd > /Users/debaas > macpro1:~ debaas$ ls > Desktop Documents Downloads Library Movies > Music PicturesPublic Sites > macpro1:~ debaas$ cd Desktop/ > macpro1:Desktop debaas$ cd Python-2.7.3/ > macpro1:Python-2.7.3 debaas$ ls /usr/local > apache2 bin clamXav include lib libexec share > macpro1:Python-2.7.3 debaas$ make install > /usr/bin/install -c python.exe /usr/local/bin/python2.7 > install: /usr/local/bin/python2.7: Permission denied > make: *** [altbininstall] Error 71 > > So how to proceed here? > > -Bob As others have commented, please don't top-post. The script from which you've captured a fragment of output above isn't going to work on a Mac without rewriting. (Your Mac isn't going to like python.exe for example.) As to proceeding, in all honesty, the simplest thing to do is go here: http://www.python.org/download/ Look down the page to the link for Python 2.7.3 Mac OS X 64-bit/32-bit x86-64/i386 Installer (for Mac OS X 10.6 and 10.7 [2]) and grab it. That will hand you a completely prebuilt 2.7.3 (latest) along with an installer that will put it in /Library/Frameworks where it belongs and will even edit your .profile. Good luck, Bill -- http://mail.python.org/mailman/listinfo/python-list
Re: python CAD libraries?
On Monday, September 10, 2012 11:10:55 PM UTC+2, Jayden wrote: > Are there any python CAD libraries that can > > > > (1) build simple 3D primitives solids such as spheres, cylinders and so on > > (2) perform bool operations on 3D solids > > (3) better if it has some transformations such has scaling, sweeping, and > lofting > > > > Please recommend some good ones for me? Thanks a lot!! Hi Jayden, In my opinion, the best you can get is OpenCascade (OCC) (www.opencascade.org) in combination with the python bindings (www.pythonocc.org). OCC is a hugh C++ CAD library. It not only deals with the simple geometric stuff, but it can be used to build CAD programs similar to SolidEdge or SolidWorks. It does however come with quite a steep learning curve. When using PythonOCC, the learning curve becomes a little less steep. Also note that in my opinion, Blender cannot be considered as a CAD environment. Ofcourse it is very powerful, but I think it is more targeted towards animation and visually pleasing applications, not mechanical engineering. Regards, Marco -- http://mail.python.org/mailman/listinfo/python-list
Unable to compile Python 2.7.3 in Cygwin
Hi, I'm trying to compile Python in Cygwin, with little luck. I've posted the ugliness in this link. Thoughts? http://bin.cakephp.org/view/176472400 -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: where's the new python gone?
Hmm, this feels embarrassing but the good news is that, on seeing the errors, I remember using a "sudo" with the make install and only later finding out that I shouldn't have. Last login: Tue Sep 11 09:46:11 on ttys000 macpro1:~ debaas$ pwd /Users/debaas macpro1:~ debaas$ ls Desktop Documents Downloads Library Movies Music PicturesPublic Sites macpro1:~ debaas$ cd Desktop/ macpro1:Desktop debaas$ cd Python-2.7.3/ macpro1:Python-2.7.3 debaas$ ls /usr/local apache2 bin clamXav include lib libexec share macpro1:Python-2.7.3 debaas$ make install /usr/bin/install -c python.exe /usr/local/bin/python2.7 install: /usr/local/bin/python2.7: Permission denied make: *** [altbininstall] Error 71 So how to proceed here? -Bob Op 11 Sep 2012, om 14:26 heeft William R. Wing (Bill Wing) het volgende geschreven: > On Sep 11, 2012, at 3:52 AM, Bob Aalsma wrote: > >> >> Op 10 Sep 2012, om 22:53 heeft William R. Wing (Bill Wing) het volgende >> geschreven: >> >>> On Sep 10, 2012, at 11:17 AM, Bob Aalsma >>> wrote: >>> Well, Bill, better late than never - thanks for stepping in. You are right, my problems are not yet solved ;) >>> >>> As Hans pointed out, you are looking for python, not Python (the frameworks >>> are named Python, the executable is python). Sorry about that. >>> >>> To eliminate the output from TimeMachine (assuming it is using an external >>> drive or a TimeCapsule), add one more option to the find command: >>> >>> $ sudo find -x / -name python -print (or follow his directions for piping >>> to a file). >>> >>> The -x option prevents find from descending into a volume with a different >>> device number from the one you started on. >>> >>> -Bill >>> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > Well, clearly, the only copies of python 2.7 on your system are from Apple > (in System/Library and associated with Xcode). > So, either the one you downloaded overwrote one of them, or the install > failed and you didn't notice the error go zooming by in a listing. > > Can you run the install procedure again and capture the output? > > -Bill -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: where's the new python gone?
On 11 Sep 2012, at 15:31, William R. Wing (Bill Wing) wrote: > On Sep 11, 2012, at 9:12 AM, Bob Aalsma wrote: > >> Hmm, this feels embarrassing but the good news is that, on seeing the >> errors, I remember using a "sudo" with the make install and only later >> finding out that I shouldn't have. >> >> Last login: Tue Sep 11 09:46:11 on ttys000 >> macpro1:~ debaas$ pwd >> /Users/debaas >> macpro1:~ debaas$ ls >> Desktop Documents Downloads Library Movies >> Music PicturesPublic Sites >> macpro1:~ debaas$ cd Desktop/ >> macpro1:Desktop debaas$ cd Python-2.7.3/ >> macpro1:Python-2.7.3 debaas$ ls /usr/local >> apache2 bin clamXav include lib libexec share >> macpro1:Python-2.7.3 debaas$ make install >> /usr/bin/install -c python.exe /usr/local/bin/python2.7 >> install: /usr/local/bin/python2.7: Permission denied >> make: *** [altbininstall] Error 71 >> >> So how to proceed here? >> >> -Bob > > As others have commented, please don't top-post. > > The script from which you've captured a fragment of output above isn't going > to work on a Mac without rewriting. (Your Mac isn't going to like python.exe > for example.) > > As to proceeding, in all honesty, the simplest thing to do is go here: > > http://www.python.org/download/ > > Look down the page to the link for Python 2.7.3 Mac OS X 64-bit/32-bit > x86-64/i386 Installer (for Mac OS X 10.6 and 10.7 [2]) and grab it. That > will hand you a completely prebuilt 2.7.3 (latest) along with an installer > that will put it in /Library/Frameworks where it belongs and will even edit > your .profile. > > Good luck, > Bill Sorry about top-posting. And it worked! Thank you for teaching! Regards, Bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing strings from the back?
On 9/11/2012 6:40 AM, Oscar Benjamin wrote: On 11 September 2012 10:51, Duncan Booth mailto:[email protected]>> wrote: Oscar Benjamin mailto:[email protected]>> wrote: >> What interning buys you is that "s == t" is an O(1) pointer compare >> if they are equal. But if s and t differ in the last character, >> __eq__ will still inspect every character. There is no way to tell >> Python "all strings are interned, if s is not t then s != t as well". >> > > I thought that if *both* strings were interned then a pointer > comparison could decide if they were unequal without needing to check > the characters. > > Have I misunderstood how intern() works? > I don't think you've misunderstood how it work, but so far as I can see the code doesn't attempt to short circuit the "not equal but interned" case. The comparison code doesn't look at interning at all, it only looks for identity as a shortcut. It also doesn't seem to check if the hash values have been set. I guess the cached hash value is only used in contexts where the hash is explicitly desired.- I believe the internal use of interning and hash comparison has varied from release to release. However, the main use of string comparison is for dict keys, especially the internal dicts for namespaces and attributes. Since the dict lookup code needs hash values anyway, to find slots with possible conflicts, I am sure it does not use the generic comparison operators but starts with hash comparisons. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing ISO date/time strings - where did the parser go?
Roy Smith writes: > In article , > Chris Angelico wrote: > > What is it that takes up forty pages [for the ISO 8601 > > specification]? RFC 2822 describes a date/time stamp in about two > > pages. In fact, the whole RFC describes the Internet Message Format > > in not much more than 40 pages. Is ISO-language just bloated? > > > > *boggle* > > You can find a copy at http://dotat.at/tmp/ISO_8601-2004_E.pdf In brief: ISO 8601 doesn't have the luxury of a single timestamp format. It also must define its terms from a rather more fundamental starting point than RFC 5822 can assume. There's some bloat (5 of the 40 pages don't even show up in the table of contents), but much of the content of the ISO 8601 standard is required, to cover the ground intended in the level of detail intended. Scope This International Standard is applicable whenever representation of dates in the Gregorian calendar, times in the 24-hour timekeeping system, time intervals and recurring time intervals or of the formats of these representations are included in information interchange. It includes * calendar dates expressed in terms of calendar year, calendar month and calendar day of the month; * ordinal dates expressed in terms of calendar year and calendar day of the year; * week dates expressed in terms of calendar year, calendar week number and calendar day of the week; * local time based upon the 24-hour timekeeping system; * Coordinated Universal Time of day; * local time and the difference from Coordinated Universal Time; * combination of date and time of day; * time intervals; * recurring time intervals. -- \ “First things first, but not necessarily in that order.” —The | `\ Doctor, _Doctor Who_ | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: a python license problem?
Jayden writes: > Python is under GPL compatible. If I develop a python code If you write new code, without deriving your work from the code of Python itself, then the license of the Python code cannot affect what you many do with what you wrote – because the copyright on Python does not affect works not derived from it. Despite the wishes of copyright maximalists (and the PSF are not copyright maximalists, to my knowledge), there are still limits to the scope of copyright. > If python is under GPL, is the answer different? Thanks a lot!! Python is not under GPL. But unless you are deriving a work from Python and distributing the result, that doesn't alter the answer. -- \ “I wish there was a knob on the TV to turn up the intelligence. | `\ There's a knob called ‘brightness’ but it doesn't work.” | _o__) —Eugene P. Gallagher | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Which Version of Python?
I have a lot of programming experience in many different languages and now I want to learn Python. Which version do you suggest I download, Python 2.x or Python 3.x ? Also why should I prefer one over the other? Right now I am thinkng Python 3.x as it has been out since 2008, but I have some concerns about backward compatibility with older packages that I might want to use. Thanks for your ideas and help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Version of Python?
Having recently looked for the same answer myself, consensus seems to be that you should work with 3.x unless you know you need something that is still 2.x specific. For me, that 2.x specific item was OpenStack. On Tue, Sep 11, 2012 at 12:49 PM, Charles Hottel wrote: > I have a lot of programming experience in many different languages and now > I want to learn Python. Which version do you suggest I download, Python > 2.x > or Python 3.x ? Also why should I prefer one over the other? > > Right now I am thinkng Python 3.x as it has been out since 2008, but I have > some concerns about backward compatibility with older packages that I might > want to use. > > Thanks for your ideas and help. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Version of Python?
On 11/09/2012 17:49, Charles Hottel wrote: I have a lot of programming experience in many different languages and now I want to learn Python. Which version do you suggest I download, Python 2.x or Python 3.x ? Also why should I prefer one over the other? Right now I am thinkng Python 3.x as it has been out since 2008, but I have some concerns about backward compatibility with older packages that I might want to use. Thanks for your ideas and help. My own preference is for Python 3.x. Python 2.x is ending at 2.7. As you said, some older packages may still be using 2.x, but there's not that much difference between 3.x and 2.x, so you should be able to switch from one to the other one very easily. -- http://mail.python.org/mailman/listinfo/python-list
Re: a python license problem?
On 9/11/2012 12:03 PM, Ben Finney wrote: Jayden writes: Python is under GPL compatible. If I develop a python code If you write new code, without deriving your work from the code of Python itself, then the license of the Python code cannot affect what you many do with what you wrote – because the copyright on Python does not affect works not derived from it. Despite the wishes of copyright maximalists (and the PSF are not copyright maximalists, to my knowledge), there are still limits to the scope of copyright. If by 'copyright maximalists' you mean the authors of translation programs that claim copyright to translations, then they are really 'copyright grabbers' in that they are denying copyright to original authors of the codes translated. The usual basis for the grab is that the translated code must run with a runtime component from the translator. The runtime may or may not be physically bundled with the translated code, just as Python code can run with either a separately installed python or a bundled python, as in freeze or py2exe. The PSF explicitly says that distribution of such bundles is allowed for CPython as long as one summarized what one is doing. (See terms 2 and 3.) If python is under GPL, is the answer different? Thanks a lot!! Python is not under GPL. But unless you are deriving a work from Python and distributing the result, that doesn't alter the answer. To be really clear, the 'Python license' is the license for the Python x.y.z software and documentation distributed by the Python Software Foundation. Other implementations have their own copyright and licenses. Code is copyrighted and licensed by the author or assignee. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: submit jobs on multi-core
There is parallel python as well http://www.parallelpython.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: submit jobs on multi-core
On Mon, Sep 10, 2012 at 11:53 PM, Laszlo Nagy wrote: > On 2012-09-11 06:16, Dhananjay wrote: >> >> Dear all, >> >> I have a python script in which I have a list of files to input one by one >> and for each file I get a number as an output. >> I used for loop to submit the file to script. >> My script uses one file at a time and returns the output. >> >> My computers has 8 cores. >> Is there any way that I could submit 8 jobs at a time and get all the >> output faster ? >> In other words, how can I modify my script so that I could submit 8 jobs >> together on 8 different processors ? >> >> I am bit new to this stuff, please suggest me some directions. > > You should first look at the multiprocessing module. It is part of the > standard library. > > http://docs.python.org/library/multiprocessing.html Or if Python 3.2 is an option, the concurrent.futures module would be very well suited for this task. -- http://mail.python.org/mailman/listinfo/python-list
Single leading dash in member variable names?
All Python noob here. Trying to understand a particular syntax: class stuff: def __init__(self): self._bongo = "BongoWorld" --- What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Single leading dash in member variable names?
On Tue, Sep 11, 2012 at 12:45 PM, wrote: > All > > Python noob here. Trying to understand a particular syntax: > > class stuff: > def __init__(self): > self._bongo = "BongoWorld" > > --- > > What is the significance of the leading underscore in "self._bongo"? I've > seen this a few times and, after looking through PEP 8, I didn't see anything > relevant, but I could have missed it. Single leading underscore is a convention indicating that the name should be considered private and not used externally. It's a softer version of the double leading underscore that means basically the same thing but has syntactic significance. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py
On Tuesday, September 11, 2012 12:21:24 AM UTC-7, Tim Golden wrote:
> And so it does, but you'll notice from the MSDN docs that the \\?
> syntax must be supplied as a Unicode string, which os.listdir
> will do if you pass it a Python unicode object and not otherwise:
I was saying os.listdir doesn't like the r'\\?\' prefix.
But Tim corrects me -- so yes, Steven's earler suggestion "Why don't you just
prepend a '?' to paths like they tell you to?" does work, when I supply it in
unicode.
Good:
>>> os.listdir(u'?\\C:\\Users\\john\\Desktop\\sandbox\\goo')
[u'voo...']
Bad:
>>> os.listdir('?\\C:\\Users\\john\\Desktop\\sandbox\\goo')
Traceback (most recent call last):
File "", line 1, in
os.listdir('?\\C:\\Users\\john\\Desktop\\sandbox\\goo')
WindowsError: [Error 123] The filename, directory name, or volume label
syntax is incorrect: '?\\C:\\Users\\john\\Desktop\\sandbox\\goo/*.*'
Thanks to both of you for taking the time to teach.
BTW, when I posted the original, I was trying to supply my own customized
ntpath module, and I was really puzzled as to why it wasn't getting picked up!
According to sys.path I expected my custom ntpath.py to be chosen, instead of
the standard Lib/ntpath.py.
Now I guess I understand why. I moved Lib/ntpath.* out of the way, and learned
that during initialization, Python is importing "site" module, which is
importing "os" which is importing "ntpath" -- before my dir is added to
sys.path. So later when I import os, it and ntpath have already been imported,
so Python doesn't attempt a fresh import.
To get my custom ntpath.py honored, need to RELOAD, like:
import os
import ntpath
reload(ntpath)
print 'os.walk(\'goo\') with isdir override in custom ntpath'
for root, dirs, files in os.walk('goo'):
print root, dirs, files
where the diff betw standard ntpath.py and my ntpath.py are:
14c14,19
< from genericpath import *
---
> from genericpath import *
>
> def isdir(s):
> return genericpath.isdir('?\\' + abspath(s + '\\'))
> def isfile(s):
> return genericpath.isfile('?\\' + abspath(s + '\\'))
I'm not sure how I could have known that ntpath was already imported, since *I*
didn't import it, but that was the key to my confusion.
Thanks again for the help.
John
--
http://mail.python.org/mailman/listinfo/python-list
Re: Single leading dash in member variable names?
On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: > On Tue, Sep 11, 2012 at 12:45 PM, I wrote: > > > All > > > > > > Python noob here. Trying to understand a particular syntax: > > > > > > class stuff: > > > def __init__(self): > > > self._bongo = "BongoWorld" > > > > > > --- > > > > > > What is the significance of the leading underscore in "self._bongo"? I've > > seen this a few times and, after looking through PEP 8, I didn't see > > anything relevant, but I could have missed it. > > > > Single leading underscore is a convention indicating that the name > > should be considered private and not used externally. It's a softer > > version of the double leading underscore that means basically the same > > thing but has syntactic significance. Thank you! PEP 8 says this is bad form. What do you think? -- http://mail.python.org/mailman/listinfo/python-list
Re: submit jobs on multi-core
On 2012-09-11, Dhananjay wrote: > --===0316394162== > Content-Type: multipart/alternative; boundary=20cf30776bd309ffd004c96557e2 > > --20cf30776bd309ffd004c96557e2 > Content-Type: text/plain; charset=ISO-8859-1 > > Dear all, > > I have a python script in which I have a list of files to input one by one > and for each file I get a number as an output. > I used for loop to submit the file to script. > My script uses one file at a time and returns the output. > > My computers has 8 cores. > Is there any way that I could submit 8 jobs at a time and get all the > output faster ? > In other words, how can I modify my script so that I could submit 8 jobs > together on 8 different processors ? > > I am bit new to this stuff, please suggest me some directions. > > Thank you. The simplest way I've found to do this is to use something like GNU parallel. I don't know if there's a Windows equivalent but it works well for me on linux and you can use it for any program (not just python scripts). >From the wikipedia page: http://en.wikipedia.org/wiki/GNU_parallel """ The most common usage is to replace the shell loop, for example (for x in `cat list` ; do do_something $x done) | process_output to the form of cat list | parallel do_something | process_output """ Note that there are two basic types of parallel execution depending on whether or not your parallel processes need to communicate with one another. I'm assuming that you really just want to run independent jobs simultaneously. Otherwise the other suggestions may be more relevant. Oscar -- http://mail.python.org/mailman/listinfo/python-list
Re: Single leading dash in member variable names?
On Tue, Sep 11, 2012 at 2:53 PM, wrote: > On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: >> Single leading underscore is a convention indicating that the name >> should be considered private and not used externally. It's a softer >> version of the double leading underscore that means basically the same >> thing but has syntactic significance. > > Thank you! > > PEP 8 says this is bad form. What do you think? Where are you seeing that? It says: Use one leading underscore only for non-public methods and instance > variables. > > To avoid name clashes with subclasses, use two leading underscores to > invoke Python's name mangling rules. > > ... Generally, double leading underscores should be used only to avoid > name conflicts with attributes in classes designed to be subclassed. > So a single leading underscore is the preferred style for non-public methods and attributes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Single leading dash in member variable names?
On 9/11/2012 4:53 PM, [email protected] wrote: What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. Single leading underscore is a convention indicating that the name should be considered private and not used externally. It's a softer version of the double leading underscore that means basically the same thing but has syntactic significance. PEP 8 says this is bad form. What do you think? Please quote the specific statement you want commented. The stdlib routinely uses _names for internal implementation objects. __ugh is perhaps never used. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
How to send email programmatically from a gmail email a/c when port 587(smtp) is blocked
Hi c.l.p peeps
I am stuck with an issue, so am coming to the Pythonista deltaforce who rescue
me everytime :)
I am trying to send out email programmatically, from a gmail a/c, using
smtplib, using the following chunk of code (b/w [ & ] below)
[
import smtplib
from email.mime.text import MIMEText
#uname, pwd are username & password of gmail a/c i am trying to send from
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls() # get response(220, '2.0.0 Ready to start TLS')
server.login(uname,pwd) # get response(235, '2.7.0 Accepted')
toaddrs = ['[email protected]', '[email protected]' ] # list of To email addresses
msg = MIMEText('email body')
msg['Subject'] = 'email subject'
server.sendmail(fromaddr, toaddrs, msg.as_string())
]
The code above works perfectly fine on my local machine, but fails on the
production server at the university where i work( all ports other than port 80
are blocked) :(
So , when i try to run the 2 py statements (in bold below) on a python prompt
from the production server, which has port 587 blocked, i get the following
error
{
>>> import smtplib
>>> server = smtplib.SMTP('smtp.gmail.com:587')
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.6/smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.6/smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.6/smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "/usr/lib/python2.6/socket.py", line 514, in create_connection
raise error, msg
socket.error: [Errno 101] Network is unreachable
}
1. How can i overcome this ?
A friend suggested , that i could use something called smtp relay, which would
solve my problem, but would be time-consuming & a pain to set up.
I did some cursory googling & searching on stackoverflow but could not find any
good, well explained results.
I dont know anything about SMTP.
Anybody has any recommendations on a good explanation on smtp relay & how to
set it up for sending email from a gmail a/c using a python script ?
2. Also, is there a more elegant/cleaner/graceful solution to my problem than
using an smtp relay ?
Any & all explanations/links/code
snippets/thoughts/ideas/suggestions/feedback/comments/wisdom of the c.l.p
community would be greatly appreciated.
Thanks a ton
cheers
ashish
email :
ashish.makani
domain:gmail.com
p.s. some more context so people dont presume we are spammers :)
These emails are automated diagnostic emails sent to a group of a few of us
admins, so we get notified when a python heartbeat script, detects a failure in
things like n/w connectivity, router status, etc.
All of us dont use university email, we use gmail .
“The only way to do great work is to love what you do. If you haven’t found it
yet, keep looking. Don’t settle. As with all matters of the heart, you’ll know
when you find it.” - Steve Jobs (1955 - 2011)
--
http://mail.python.org/mailman/listinfo/python-list
Re: Single leading dash in member variable names?
On 09/11/2012 01:53 PM, [email protected] wrote: On Tuesday, September 11, 2012 2:06:45 PM UTC-5, Ian wrote: On Tue, Sep 11, 2012 at 12:45 PM, I wrote: What is the significance of the leading underscore in "self._bongo"? I've seen this a few times and, after looking through PEP 8, I didn't see anything relevant, but I could have missed it. Single leading underscore is a convention indicating that the name should be considered private and not used externally. It's a softer version of the double leading underscore that means basically the same thing but has syntactic significance. Thank you! PEP 8 says this is bad form. What do you think? Where does it say that? -- Erik Max Francis && [email protected] && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Jabber erikmaxfrancis I will always remember / This moment -- Sade -- http://mail.python.org/mailman/listinfo/python-list
Double sided double underscored variable names
Were I to make a language to compile to Python, it is highly likely I would need to use hidden variable names to work constructs that Python alone does not have. This is the situation I face. If I were to use internal double-underscored names of the form __BS_* internalname*__, would the compiled code be able to assume that no-one had overwritten these variables and never will, even through modification of, say, locals(). I ask because Python's docs seem to specify that double sided double underscored names are strictly for Python and its special names. In other words, is not using __these_names__ in Python code rule or heavy convention. __BS__ is used because the name of the language is BluntSharp. Do not expect the language to ever be useful or widespread; I am doing this mostly for fun. An alternative is modifying the AST (as I am really compiling to Python's AST) to have the variables with names such as "+BS_internalname", but that seems like it might break a lot. I also doubt that it is good convention. -- http://mail.python.org/mailman/listinfo/python-list
Re: Double sided double underscored variable names
On Wed, Sep 12, 2012 at 8:09 AM, Joshua Landau wrote: > If I were to use internal double-underscored names of the form > __BS_internalname__, would the compiled code be able to assume that no-one > had overwritten these variables and never will, even through modification > of, say, locals(). I ask because Python's docs seem to specify that double > sided double underscored names are strictly for Python and its special > names. Interesting. If you're compiling your code to Python, you may be able to, if necessary, adorn a user's variable name(s). I'd be inclined to use a single underscore notation like _BS_internalname_ and then, in the event of a collision (which would be incredibly unlikely unless someone's fiddling), rename the offending variable to _BS_BS_something_ - which of course you'd never yourself use. Would that serve? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: How to send email programmatically from a gmail email a/c when port 587(smtp) is blocked
On 11/09/2012 22:51, ashish makani wrote: Hi c.l.p peeps I am stuck with an issue, so am coming to the Pythonista deltaforce who rescue me everytime :) [big snip] I say old chap, it's simply not cricket to ask a question like this some 32 minutes after asking the same question on the tutor mailing list. -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Double sided double underscored variable names
On 11 September 2012 23:22, Chris Angelico wrote: > On Wed, Sep 12, 2012 at 8:09 AM, Joshua Landau > wrote: > > If I were to use internal double-underscored names of the form > > __BS_internalname__, would the compiled code be able to assume that > no-one > > had overwritten these variables and never will, even through modification > > of, say, locals(). I ask because Python's docs seem to specify that > double > > sided double underscored names are strictly for Python and its special > > names. > > Interesting. If you're compiling your code to Python, you may be able > to, if necessary, adorn a user's variable name(s). I'd be inclined to > use a single underscore notation like _BS_internalname_ and then, in > the event of a collision (which would be incredibly unlikely unless > someone's fiddling), rename the offending variable to > _BS_BS_something_ - which of course you'd never yourself use. Would > that serve? > Well, the problem is that a lot of collisions aren't predictable. "locals()['foo'] = 2", for example. If it weren't for Python's annoying flexibility* I would definitely do something very close to what you suggest. Remember that "locals()" isn't Python's only introspection tool. How about "from foo import *"? I could just make the claim "You use non-explicitly declared names and you pay the price", but that seems... less nice. *Being "annoying" is how I'm pretty sure I can get inline function definitions working, though, so I shouldn't give it too much rap... -- http://mail.python.org/mailman/listinfo/python-list
Re: Double sided double underscored variable names
On Wed, Sep 12, 2012 at 8:48 AM, Joshua Landau wrote: > Well, the problem is that a lot of collisions aren't predictable. > "locals()['foo'] = 2", for example. If it weren't for Python's annoying > flexibility* I would definitely do something very close to what you suggest. > Remember that "locals()" isn't Python's only introspection tool. How about > "from foo import *"? You're not supposed to mutate locals(), but I suppose globals() works the same way. Inline functions? I like this idea. I tend to want them in pretty much any language I write in. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py
On Wed, Sep 12, 2012 at 5:13 AM, ruck wrote: > I'm not sure how I could have known that ntpath was already imported, since > *I* didn't import it, but that was the key to my confusion. One way to find out is to peek at the cache. >>> import sys >>> sys.modules There are quite a few of them in the 3.2 interactive that I just tried this in. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py
On 09/11/2012 03:13 PM, ruck wrote: > > > I'm not sure how I could have known that ntpath was already imported, since > *I* didn't import it, but that was the key to my confusion. > import sys print sys.modules -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Version of Python?
"Charles Hottel" writes: > I have a lot of programming experience in many different languages and now > I want to learn Python. Good for you, and welcome! > Which version do you suggest I download, Python 2.x or Python 3.x ? > Also why should I prefer one over the other? This question is a good one. It is common enough that the home page http://www.python.org/> has a link to the community's answer/discussion at http://wiki.python.org/moin/Python2orPython3>. > Right now I am thinkng Python 3.x as it has been out since 2008, but I > have some concerns about backward compatibility with older packages > that I might want to use. The fact that Python 3 has been out for a number of years is important, as is the fact that the Python developers and the community of third-party library developers have worked quite hard to make it feasible to work in Python 3. More important, from the perspective of a newcomer, is that Python 2 is essentially in maintenance-only mode, receiving only bug fixes. All larger improvements are only going into Python 3. The set of third-party libraries which are not ready for Python 3 still has some significant members, and will certainly never be zero. But that set has shrunk significantly in the many years that Python 3 has been active. At this stage, I would advise any person wanting to learn Python qua Python (i.e. without considering the wrinkles of some specific task) to focus on Python 3. If you need to learn older versions, that need will present itself and you can learn the legacy quirks then; for now, learn Python the way it is intended to be by going for Python 3. -- \ “A lie can be told in a few words. Debunking that lie can take | `\ pages. That is why my book… is five hundred pages long.” —Chris | _o__)Rodda, 2011-05-05 | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Version of Python?
If your desire is to "learn" Python then I would stick to 2.7 My reasoning would be that there are still a significant number of packages that have not been ported to 3.x (and may never be ported). Not having looked at the changes in 3.x (so don't flame me! :-)), it would seem that anything you "learn" in 2.7 would be easily transferred "up" when and if you feel the need to go to 3.x, but in the meantime enjoy the better support of a greater range of packages that are still only 2.x compatible! i.e. learning (and using) features of 3.x could make it difficult to go "down" when/if you decide you really need to use a library that hasn't (and may never!) be ported to 3.x. For example, Graysons book on Python GUI programming is still one of the better Python GUI books (although very old now!) and it would steer you towards using the Pmw library - which may never be ported to 3.x. If you decide to use wxPython for your GUI work then I see that has support for 2.x only also. So in this case, staying with the lower common denominator might be the better choice. -- http://mail.python.org/mailman/listinfo/python-list
Re: Standard Asynchronous Python
Thanks for the second round of responses. I think this gives me some focus - concentrate on the API, talk to the framework developers, and start redrafting the PEP sooner rather than later. Thanks! Dustin -- http://mail.python.org/mailman/listinfo/python-list
Re: Double sided double underscored variable names
Sorry for breaking threading, but Joshua's post does not show up on my
usenet provider.
On Wed, 12 Sep 2012 08:22:17 +1000, Chris Angelico wrote:
> On Wed, Sep 12, 2012 at 8:09 AM, Joshua Landau
> wrote:
>>
>> If I were to use internal double-underscored names of the form
>> __BS_internalname__, would the compiled code be able to assume that
>> no-one had overwritten these variables and never will,
Certainly not. It is virtually never possible to make that assumption in
Python. Nearly everything can be shadowed at runtime.
(One exception is local variables of a function, which can only be seen
from inside that function. But you don't need to wrap local variable
names in underscores to treat them as local.)
Dunder ("Double leading and trailing UNDERscore") names are normal names
subject to the same rules as anything else in Python (with one
exception), which means you can modify them in all sorts of ways at
runtime:
py> _int = int
py> class MyInt(_int):
... def __add__(self, other):
... return 42
...
py> int = MyInt
py> a = int("1")
py> a + 1
42
py> type(a).__add__ = lambda self, other: 23
py> a + 1
23
The one exception how dunder names are treated specially is that Python
uses a short-cut for name-lookup which means you cannot override them on
a per-instance basis like normal other attribute names.
>> even through modification of, say, locals().
Modifying locals() is an implementation detail which may not be supported.
>> I ask because Python's docs seem to
>> specify that double sided double underscored names are strictly for
>> Python and its special names.
Dunder names are reserved for use by Python's built-ins and syntax, that
is all.
> Interesting. If you're compiling your code to Python, you may be able
> to, if necessary, adorn a user's variable name(s). I'd be inclined to
> use a single underscore notation like _BS_internalname_ and then, in the
> event of a collision (which would be incredibly unlikely unless
> someone's fiddling), rename the offending variable to _BS_BS_something_
> - which of course you'd never yourself use. Would that serve?
This seems to be a mere extension of the name-mangling that occurs with
leading-only double-underscore attributes like self.__spam. This can be a
right PITA at times, and offers so little protection that it isn't
worthwhile. __names only protect against *accidental* name collisions,
and not all of those.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Re: Which Version of Python?
On 2012.09.11 19:17, Peter wrote: > If your desire is to "learn" Python then I would stick to 2.7 > > My reasoning would be that there are still a significant number of packages > that have not been ported to 3.x (and may never be ported). This is true, but the /potential/ for the need for one of these packages is not a good reason to learn from a branch that will never get any new features. If there is indeed a compelling reason to stay with the older version, then it is a worthwhile tradeoff. Otherwise, it is just silly. > Not having looked at the changes in 3.x (so don't flame me! :-)) That would be a good reason /to/ flame you. ;) > , it would seem that anything you "learn" in 2.7 would be easily transferred > "up" when and if you feel the need to go to 3.x, 3.x is not a simple superset of 2.7 - there are certain limitations and ways of doing things in 2.x that don't apply to 3.x. A new programmer should learn, for example, handling Unicode properly (which is strongly encouraged in 3.x) and then learn how to deal with less-than-ideal implementations (like 2.x) rather than learn how to do it sloppily and then be frustrated when 3.x wants them to do it correctly. Backward compatibility was not broken for trivial reasons. > i.e. learning (and using) features of 3.x could make it difficult to go "down" The official documentation does point out things that have been added/changed both overall in the "What's New" page and specifically in each module's documentation. > when/if you decide you really need to use a library that hasn't (and may > never!) be ported to 3.x. I don't think it's a good idea to encourage people (especially newbies) to stick with packages that won't get updated. I'm not saying that a package that isn't planned to be 3.x compatible will necessarily be unmaintained, but being unmaintained is the reason many packages will not be made 3.x compatible. In any case, packages that aren't getting support for 3.x will likely be replaced with better alternatives, especially once people start flocking en masse to 3.x (I'm no expert, but my guess is that this will happen once Django and Twisted support 3.x). If 3.0 had come out a month ago, I would see value in learning 2.x, but it's been nearly 4 years. -- CPython 3.3.0b1 | Windows NT 6.1.7601.17803 -- http://mail.python.org/mailman/listinfo/python-list
Re: Double sided double underscored variable names
And again, Joshua's original post is not available from my provider. Joshua, I suspect that something about your post is being seen as spam and dropped by at least some providers. On Wed, 12 Sep 2012 08:52:10 +1000, Chris Angelico wrote: > On Wed, Sep 12, 2012 at 8:48 AM, Joshua Landau > wrote: >> >> Well, the problem is that a lot of collisions aren't predictable. >> "locals()['foo'] = 2", for example. If it weren't for Python's annoying >> flexibility* I can't see your footnote there, so you may have already covered this, but for the record, what you call Python's "annoying flexibility" is fundamental to Python's programming model and done so for good reasons. The ability to shadow built-ins is, at times, incredibly useful rather than annoying. The world is full of bondage and domination languages that strongly restrict what you can do. Python doesn't need to be another one of them. Python's optimizing compiler, PyPy, is able to optimize code very well without such restrictions. >> I would definitely do something very close to what you >> suggest. Remember that "locals()" isn't Python's only introspection >> tool. How about "from foo import *"? I wouldn't call "import *" an introspection tool. At least, no more so than print. > You're not supposed to mutate locals(), It's not so much you're not allowed to do it, but that the result of making changes to locals() inside a function is implementation dependent: CPython 2: writing to the dict returned by locals() will work, but the changes will not be reflected in the actual local variables, except under very restricted circumstances; CPython 3: those restricted circumstances that allowed writes to locals() to modify local variables are now SyntaxErrors; Stackless: presumably the exact same behaviour as CPython (since Stackless is a fork, not a re-implementation); Jython: the same as CPython; IronPython: writes to locals() will modify the corresponding local variable. Outside of a function, locals() returns globals() and writes will always modify the global variable (this is a language guarantee). > but I suppose globals() works the same way. > > Inline functions? I like this idea. I tend to want them in pretty much > any language I write in. What do you mean by in-line functions? If you mean what you literally say, I would answer that Python has that with lambda. But I guess you probably mean something more like macros. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Double sided double underscored variable names
On 12 September 2012 01:51, Steven D'Aprano < [email protected]> wrote: > Sorry for breaking threading, but Joshua's post does not show up on my > usenet provider. > That may explain why I keep getting ignored -.- I thought it was something I said :P I'm just using EMail through GMail, posting to [email protected]. If that is the wrong way, I would love to know what I should be doing. > On Wed, 12 Sep 2012 08:22:17 +1000, Chris Angelico wrote: > > > On Wed, Sep 12, 2012 at 8:09 AM, Joshua Landau > > wrote: > >> > >> If I were to use internal double-underscored names of the form > >> __BS_internalname__, would the compiled code be able to assume that > >> no-one had overwritten these variables and never will, > > Certainly not. It is virtually never possible to make that assumption in > Python. Nearly everything can be shadowed at runtime. > > (One exception is local variables of a function, which can only be seen > from inside that function. But you don't need to wrap local variable > names in underscores to treat them as local.) > > Dunder ("Double leading and trailing UNDERscore") names are normal names > subject to the same rules as anything else in Python (with one > exception), which means you can modify them in all sorts of ways at > runtime: > > py> _int = int > py> class MyInt(_int): > ... def __add__(self, other): > ... return 42 > ... > py> int = MyInt > py> a = int("1") > py> a + 1 > 42 > py> type(a).__add__ = lambda self, other: 23 > py> a + 1 > 23 > Fair play. > The one exception how dunder names are treated specially is that Python > uses a short-cut for name-lookup which means you cannot override them on > a per-instance basis like normal other attribute names. > > >> even through modification of, say, locals(). > > Modifying locals() is an implementation detail which may not be supported. Nice to know. > >> I ask because Python's docs seem to > >> specify that double sided double underscored names are strictly for > >> Python and its special names. > > Dunder names are reserved for use by Python's built-ins and syntax, that > is all. The idea is that if they were reserved then nobody should ever use them. They may be able to, yes, but if you are not meant to make any up, and __BS_internalname__ isn't a Python-reserved name, then maybe I could claim that it's safe territory. > > Interesting. If you're compiling your code to Python, you may be able > > to, if necessary, adorn a user's variable name(s). I'd be inclined to > > use a single underscore notation like _BS_internalname_ and then, in the > > event of a collision (which would be incredibly unlikely unless > > someone's fiddling), rename the offending variable to _BS_BS_something_ > > - which of course you'd never yourself use. Would that serve? > > This seems to be a mere extension of the name-mangling that occurs with > leading-only double-underscore attributes like self.__spam. This can be a > right PITA at times, and offers so little protection that it isn't > worthwhile. __names only protect against *accidental* name collisions, > and not all of those. I disagree. Not with your opinion on self.__spam, but on its equivalence to the the mentioned idea. I have never used (due to absence of need) double leading underscored names, but name mangling is a rigidly different concept to simply naming a variable differently to another. As I can introspect my own compiled code* (gasp!) I can check for any direct name clashes. Python does not do the same with mangling, I believe. It's not like I don't have options. I could always say that inexplicit names have to be careful not to start with "_BS_" and then deal nicely with the explicit ones as said above. But then, people aren't going to be prepending "_BS_" explicitly unless they want to 'break' the code. If /you/ wanted to use a programming language that compiled to Python, would you mind _BS_internalname_ variables littered around the place, and would you prefer if they avoided as many conflicts as they can? I could always make explicit conflicts a warning rather than avoid them. I'm not sure what the practical choice is. * When it's done, of course -- http://mail.python.org/mailman/listinfo/python-list
Re: Double sided double underscored variable names
On 12 September 2012 02:14, Steven D'Aprano < [email protected]> wrote: > And again, Joshua's original post is not available from my provider. > Joshua, I suspect that something about your post is being seen as spam > and dropped by at least some providers. > I am sorry to ask this, but in the meantime can someone who isn't spam-filtered repost my messages? I'll give them a cookie! To repeat my previous post, I'm using GMail and posting to [email protected]. If that is what I'm meant to be doing, I'll try another email address. > On Wed, 12 Sep 2012 08:52:10 +1000, Chris Angelico wrote: > > > On Wed, Sep 12, 2012 at 8:48 AM, Joshua Landau > > wrote: > >> > >> Well, the problem is that a lot of collisions aren't predictable. > >> "locals()['foo'] = 2", for example. If it weren't for Python's annoying > >> flexibility* > > I can't see your footnote there, so you may have already covered this, > but for the record, what you call Python's "annoying flexibility" is > fundamental to Python's programming model and done so for good reasons. > The ability to shadow built-ins is, at times, incredibly useful rather > than annoying. > > The world is full of bondage and domination languages that strongly > restrict what you can do. Python doesn't need to be another one of them. > Python's optimizing compiler, PyPy, is able to optimize code very well > without such restrictions. I agree :P. The footnote should portray that I said that in jest. > >> I would definitely do something very close to what you > >> suggest. Remember that "locals()" isn't Python's only introspection > >> tool. How about "from foo import *"? > > I wouldn't call "import *" an introspection tool. At least, no more so > than print. Yeah, I meant "things that can change the current scope without explicitly naming the changes". "print" doesn't do that, but you are correct in what you say. > but I suppose globals() works the same way. > > > > Inline functions? I like this idea. I tend to want them in pretty much > > any language I write in. > > What do you mean by in-line functions? If you mean what you literally > say, I would answer that Python has that with lambda. > > But I guess you probably mean something more like macros. No, just multi-line lambda. Macros, if my knowledge of lower-level languages is valid, would be sorta' silly in Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: python CAD libraries?
On Tuesday, September 11, 2012 9:42:56 AM UTC-4, Marco Nawijn wrote: > On Monday, September 10, 2012 11:10:55 PM UTC+2, Jayden wrote: > > > Are there any python CAD libraries that can > > > > > > > > > > > > (1) build simple 3D primitives solids such as spheres, cylinders and so on > > > > > > (2) perform bool operations on 3D solids > > > > > > (3) better if it has some transformations such has scaling, sweeping, and > > lofting > > > > > > > > > > > > Please recommend some good ones for me? Thanks a lot!! > > > > Hi Jayden, > > > > In my opinion, the best you can get is OpenCascade (OCC) > (www.opencascade.org) in combination with the python bindings > (www.pythonocc.org). OCC is a hugh C++ CAD library. It not only deals with > the simple geometric stuff, but it can be used to build CAD programs similar > to SolidEdge or SolidWorks. It does however come with quite a steep learning > curve. When using PythonOCC, the learning curve becomes a little less steep. > > > > Also note that in my opinion, Blender cannot be considered as a CAD > environment. Ofcourse it is very powerful, but I think it is more targeted > towards animation and visually pleasing applications, not mechanical > engineering. > > > > Regards, > > > > Marco Hi, Marco, Thank you so much! This is what I exactly want. But I am a little concerned about its steep learning curve. Is it really hard to learn pythonOCC? Averagely, how long does it take to begin to program some practical code? Do you have any good advice for me to learn it? I deeply appreciate your kind help!! Best regards, Jayden -- http://mail.python.org/mailman/listinfo/python-list
Re: Double sided double underscored variable names
This is an email address linked to my GMail account. If this works better, tell me and I'll switch. It's still sending through GMail though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Version of Python?
On Tue, 11 Sep 2012 17:17:14 -0700, Peter wrote: > If your desire is to "learn" Python then I would stick to 2.7 > > My reasoning would be that there are still a significant number of > packages that have not been ported to 3.x (and may never be ported). But if all you want is to learn Python, then those packages are irrelevant. If I want to learn to write Python code, why should I care about SomePackage, regardless of whether it supports Python 3.x or 2.x or even 1.x? As a beginner to the language, I don't even know it exists, and chances are I'm never going to use it. (I was happily using Python using only the standard library for about seven years before I installed my first third-party library.) You may not have intended it this way, but the argument "stick to Python 2, because packages!" is a typical troll response. It might have been a reasonable response six years ago, when there weren't many (or even any) major packages that supported Python 3, but now many major packages do and most of those that don't are in the process of doing so. Now the choice is, paradoxically, much harder because library support is much more split: some libraries support 2.x, some 3.x, and some both. Of course, if you *need* to use SomePackage which only supports Python 2 or 3, then that will drive your decision to learn Python 2 or 3. But consider: (1) If a package only supports Python 2 now, and *has no plans* to support Python 3, I would consider that package more or less a dead end and be reluctant to start a new project with it unless I had no other choice at all. (Seriously guys, if you're the developer of a project that only supports 2.x and you aren't at least *thinking about* supporting 3.x, your project is going to be irrelevant to the wider world soon.) (2) The syntax differences between Python 2 and 3 are very minor. By the time you are proficient in one, you will be *easily* be able to jump to the other. > Not having looked at the changes in 3.x (so don't flame me! :-)), it > would seem that anything you "learn" in 2.7 would be easily transferred > "up" when and if you feel the need to go to 3.x, It goes both ways. But frankly, whenever I drop down from 3.x code to 2.x code, I get really annoyed that there's a lot of excellent stuff I cannot use. > but in the meantime > enjoy the better support of a greater range of packages that are still > only 2.x compatible! That's true. But the range of 3.x compatible third party libraries is very impressive: it includes numpy and scipy, CherryPy, parts of zope (but not yet all of it), pyparsing, an unofficial port of nltk, py2exe, and many more. Others, like django, have committed to support 3.x as soon as they can drop support for 2.4 or 2.5. See also: http://python3wos.appspot.com/ PyPy is now in the process of supporting Python 3. Within a few years, Python 3 will be the standard. > i.e. learning (and using) features of 3.x could > make it difficult to go "down" when/if you decide you really need to use > a library that hasn't (and may never!) be ported to 3.x. Any package that is not ported to 3.x will eventually be as obsolete and irrelevant as packages that only support Python 1.5. Python 2.7 will have an extended support period, but that won't last forever. My estimate is that we're past the half-way mark: in another four years, the question of "2.x or 3.x" will be irrelevant, people will be asking "I want to use library foo, but it only supports 2.7, what should I do?", and in eight years, people won't even ask that, they'll just ignore library foo as abandoned. > So in this case, staying with the lower common denominator might be the > better choice. Everyone has to make that choice for themselves, based on what libraries they intend to use. For those who don't intend to use any libraries at all, I think the answer is simple: Learn the version of Python that comes installed on your computer, or if you have to install it yourself, learn Python 3. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Version of Python?
On Wed, 12 Sep 2012 02:11:22 +, Steven D'Aprano wrote: > On Tue, 11 Sep 2012 17:17:14 -0700, Peter wrote: > >> If your desire is to "learn" Python then I would stick to 2.7 >> >> My reasoning would be that there are still a significant number of >> packages that have not been ported to 3.x (and may never be ported). > > But if all you want is to learn Python, then those packages are > irrelevant. If I want to learn to write Python code, why should I care > about SomePackage, regardless of whether it supports Python 3.x or 2.x > or even 1.x? As a beginner to the language, I don't even know it exists, > and chances are I'm never going to use it. > > (I was happily using Python using only the standard library for about > seven years before I installed my first third-party library.) > > You may not have intended it this way, but the argument "stick to Python > 2, because packages!" is a typical troll response. It might have been a > reasonable response six years ago, when there weren't many (or even any) > major packages that supported Python 3, Hardly surprising given that Python 3 came out four years ago. Sorry, brain-fart. I meant four years ago. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
generators as decorators simple issue
I'm trying to call SetName on an object to prevent me from ever having to call it explictly again on that object. Best explained by example. def setname(cls): '''this is the proposed generator to call SetName on the object''' try: cls.SetName(cls.__name__) finally: yield cls class Trial: '''class to demonstrate with''' def SetName(self, name): print 1, 1 @setname class Test(Trial): '''i want SetName to be called by using setname as a decorator''' def __init__(self): print 'Yay! or Invalid.' if __name__ == '__main__': test = Test() How can i fix this? This is my exact error: python decors2.py Traceback (most recent call last): File "decors2.py", line 23, in test = Test() TypeError: 'generator' object is not callable -- http://mail.python.org/mailman/listinfo/python-list
Re: generators as decorators simple issue
On Wednesday, 12 September 2012 07:58:10 UTC+5:30, pyjoshsys wrote: > I'm trying to call SetName on an object to prevent me from ever having to > call it explictly again on that object. Best explained by example. > [snip] In your decorator, you are using `yield cls` - it should be `return cls` 99.99% of the time. -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Version of Python?
On Tuesday, 11 September 2012 22:19:08 UTC+5:30, Charles Hottel wrote: > I have a lot of programming experience in many different languages and now > > I want to learn Python. Which version do you suggest I download, Python 2.x > > or Python 3.x ? Also why should I prefer one over the other? > > > > Right now I am thinkng Python 3.x as it has been out since 2008, but I have > > some concerns about backward compatibility with older packages that I might > > want to use. > > > > Thanks for your ideas and help. Use Python 3 because most packages support Python 3. Python 2.7 has many features that Python 3 has so it will require minimal effort to write Python 2.x code. -- http://mail.python.org/mailman/listinfo/python-list
Re: python CAD libraries?
On Tuesday, 11 September 2012 02:40:55 UTC+5:30, Jayden wrote: > Are there any python CAD libraries that can > > > > (1) build simple 3D primitives solids such as spheres, cylinders and so on > > (2) perform bool operations on 3D solids > > (3) better if it has some transformations such has scaling, sweeping, and > lofting > > > > Please recommend some good ones for me? Thanks a lot!! You could use Blender. It has support for Python 3 (I don't know whether it has support for Python 2) -- http://mail.python.org/mailman/listinfo/python-list
Re: python CAD libraries?
Hi, Marco, > > Thank you so much! This is what I exactly want. But I am a little > concerned about its steep learning curve. Is it really hard to learn > pythonOCC? Averagely, how long does it take to begin to program some > practical code? Do you have any good advice for me to learn it? I deeply > appreciate your kind help!! > > Best regards, > > Jayden > -- > http://mail.python.org/mailman/listinfo/python-list > Hey Jayden, You gotta learn to use the google searches buddy, although sometimes a good conversation can help: I found this under search term 'pythonOCC example code' http://code.google.com/p/pythonocc-examples/ and a converted pdf manual from quickview. You can download the pdf by typing in the above search term, and going straight to the main link: https://docs.google.com/viewer?a=v&q=cache:iu53RJFs1XEJ:https://pythonocc.googlecode.com/svn-history/r999/trunk/doc/tutorials/geometry_modeling_and_visualization/LATEX_src/VisualizationOfGeometryWithUtilisingpythonOCC.pdf+&hl=en&gl=us&pid=bl&srcid=ADGEESgHGUGqRqXy6Z9MKCgIIh19JfY9_BYl_xw5tQODTx1N8Hqb3CPU_oruG2LKpNhbfnrEgKEvLTyJHvfOymsHcNSMAQ7WoAa_SW-Bdg33WKVmtoD7dvEtajyqv4KMQuMLgv-NT_om&sig=AHIEtbSGCtWIUBBiFSsELS1AregIpXUVjA&pli=1 -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Version of Python?
I try to usually use several versions to know the difference. You never
know when a package might come along, and you want to try it out, and then
version becomes compatibility.
Alternatively, a client might come along and insist that a particular
version be used.
Do a little quick research on the differences, and try them out. You might
want to know a few things like from __future__ import x for the 2's or
print 'this' become print('this') in later ones, etc.
--
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
--
http://mail.python.org/mailman/listinfo/python-list
pythonOCC examples doesn't work?
I installed (1) pythonxy2.7.2.3 (with python2.7) and (2) pythonOCC-0.5-all-in-one.win32.py26 on windows 7 64 bit computer. I try run pythonOCC examples in its example folder, such as the helloworld.py and got errors as follows: ImportantError: DLL load failed: The specified module could not be found. The error come from the line of code: from OCC.BrepPrimAPI import * -- http://mail.python.org/mailman/listinfo/python-list
pythonOCC examples doesn't work?
I installed (1) pythonxy2.7.2.3 (with python2.7) and (2) pythonOCC-0.5-all-in-one.win32.py26 on windows 7 64 bit computer. I try run pythonOCC examples in its example folder, such as the helloworld.py and got errors as follows: ImportantError: DLL load failed: The specified module could not be found. The error come from the line of code: from OCC.BrepPrimAPI import * How to fix the error? Thanks a lot!! -- http://mail.python.org/mailman/listinfo/python-list
Re: pythonOCC examples doesn't work?
On Tue, Sep 11, 2012 at 11:58 PM, Jayden wrote: > I installed > (1) pythonxy2.7.2.3 (with python2.7) and > (2) pythonOCC-0.5-all-in-one.win32.py26 > on windows 7 64 bit computer. > > I try run pythonOCC examples in its example folder, such as the > helloworld.py and got errors as follows: > > ImportantError: DLL load failed: The specified module could not be > found. > > The error come from the line of code: > > from OCC.BrepPrimAPI import * > > Not sure if this would fix it(had kind of a similar problem I think a > while back, I have the AMD WOW 64, but you might want to install the 2.7_64 > version of Python, and if that doesn't work, come back with the results. > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -- http://mail.python.org/mailman/listinfo/python-list
Re: Double sided double underscored variable names
On Wed, Sep 12, 2012 at 11:38 AM, Joshua Landau wrote: > On 12 September 2012 02:14, Steven D'Aprano > wrote: >> >> And again, Joshua's original post is not available from my provider. >> Joshua, I suspect that something about your post is being seen as spam >> and dropped by at least some providers. > > I am sorry to ask this, but in the meantime can someone who isn't > spam-filtered repost my messages? I'll give them a cookie! > To repeat my previous post, I'm using GMail and posting to > [email protected]. If that is what I'm meant to be doing, I'll try > another email address. Mailing to python-list@python from Gmail is exactly what I do, and far as I know, none of my posts are getting lost. But then, I'm seeing all your posts, too, so maybe I just don't know when my posts don't go through. >> On Wed, 12 Sep 2012 08:52:10 +1000, Chris Angelico wrote: >> >> > Inline functions? I like this idea. I tend to want them in pretty much >> > any language I write in. >> >> What do you mean by in-line functions? If you mean what you literally >> say, I would answer that Python has that with lambda. >> >> But I guess you probably mean something more like macros. > > No, just multi-line lambda. Macros, if my knowledge of lower-level languages > is valid, would be sorta' silly in Python. Ah, okay. I was thinking more along the lines of what you call macros, but in the C++ sense of inline functions. In C, macros are handled at precompilation stage, and are dangerous. Classic example: #define squared(x) x*x x_squared = squared(6+7) So your macros end up littered with parentheses, and it still doesn't solve anything, as the argument still gets evaluated twice. (A problem if it has side effects - eg if it's a function call.) What I'm thinking of, though, is like C++ functions. You can put the 'inline' keyword onto any function, and the compiler will do its best to inline it (in fact, a good optimizing compiler will inline things regardless, but that's a separate point). I can write: inline int squared(int x) {return x*x;} and C++ will add no function overhead, but will still do all the proper evaluation order etc. Of course, C++ doesn't allow monkeypatching, so you'll never have semantic differences from inlining. It's just a performance question. But I use inline functions like constants - for instance, I could create a function that converts a database ID into an internal reference number, and I can change the definition of that function in one place and have it apply everywhere, just like if I wanted to change the definition of math.PI to 3.142857 for fun one day. Of course I can use a normal (out-of-line) function for this, but that has overhead in most languages. Hence, wanting inline functions. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: pythonOCC examples doesn't work?
I came up with this thread: http://techblog.ironfroggy.com/2007/01/python-on-windows-and-path.html But you might want to go to the pywin list for this one. http://mail.python.org/mailman/listinfo/python-win32 It says win32, but they should be able to help either way. > -- > Best Regards, > David Hutto > *CEO:* *http://www.hitwebdevelopment.com* > > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -- http://mail.python.org/mailman/listinfo/python-list
Re: generators as decorators simple issue
On Sep 12, 12:28 pm, [email protected] wrote: > def setname(cls): > '''this is the proposed generator to call SetName on the object''' > try: > cls.SetName(cls.__name__) > finally: > yield cls A generator is (basically) a callable that acts like an iterator. You'd use a generator if you wanted to loop with for or a list comprehension across the output of the generator: for foo in setname(Test) A decorator is a callable that takes another callable as an argument, either modifying it or returning a wrapped version of it: Test = setname(Test) You don't want to iterate over anything, so you should change `yield` to `return`. -- http://mail.python.org/mailman/listinfo/python-list
Re: pythonOCC examples doesn't work?
On Wednesday, September 12, 2012 6:02:14 AM UTC+2, Jayden wrote: > I installed > > (1) pythonxy2.7.2.3 (with python2.7) and > > (2) pythonOCC-0.5-all-in-one.win32.py26 > > on windows 7 64 bit computer. > > > > I try run pythonOCC examples in its example folder, such as the helloworld.py > and got errors as follows: > > > > ImportantError: DLL load failed: The specified module could not be found. > > > > The error come from the line of code: > > > > from OCC.BrepPrimAPI import * > > > > How to fix the error? Thanks a lot!! Hi Jayden, It has been some time ago that I used PythonOCC and I used it on Linux, so I cannot be of much help here. It sounds like you have to tell Windows where to look for the installed libraries (environment variables?). Anyhow, I recommend to post the question to the PythonOCC mailinglist. They are quite responsive. One last suggestion. OCC itself comes with a small utility called DRAWEXE. It is a tcl/tk program that can be used to play around with a lot of the functionality provided by OCC. Good luck! Marco -- http://mail.python.org/mailman/listinfo/python-list
Re: Single leading dash in member variable names?
Not to jump in with another question(this seems somewhat relevant to the conversation, maybe not), but is this similar to a private,public, or protected class similar to the C type langs? -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -- http://mail.python.org/mailman/listinfo/python-list
Re: generators as decorators simple issue
Am 12.09.2012 04:28 schrieb [email protected]: I'm trying to call SetName on an object to prevent me from ever having to call it explictly again on that object. Best explained by example. def setname(cls): '''this is the proposed generator to call SetName on the object''' try: cls.SetName(cls.__name__) finally: yield cls class Trial: '''class to demonstrate with''' def SetName(self, name): print 1, 1 @setname class Test(Trial): '''i want SetName to be called by using setname as a decorator''' def __init__(self): print 'Yay! or Invalid.' if __name__ == '__main__': test = Test() How can i fix this? I am not sure what exactly you want to achieve, but I see 2 problems here: 1. Your setname operates on a class, but your SetName() is an instance function. 2. I don't really understand the try...finally yield stuff. As others already said, you probably just want to return. I don't see what a generator would be useful for here... def setname(cls): '''this is the proposed generator to call SetName on the object''' try: cls.SetName(cls.__name__) finally: return cls and class Trial(object): '''class to demonstrate with''' @classmethod def SetName(cls, name): print 1, 1 should solve your problems. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py
Am 11.09.2012 05:46 schrieb Steven D'Aprano:
Good for you. (Sorry, that comes across as more condescending than it is
intended as.) Monkey-patching often gets used for quick scripts and tiny
pieces of code because it works.
Just beware that if you extend that technique to larger bodies of code,
say when using a large framework, or multiple libraries, your experience
may not be quite so good. Especially if *they* are monkey-patching too,
as some very large frameworks sometimes do. (Or so I am lead to believe.)
This sonds like a good use case for a context manager, like the one in
decimal.Context.get_manager().
First shot:
@contextlib.contextmanager
def changed_os_path(**k):
old = {}
try:
for i in k.items():
old[i] = getattr(os.path, i)
setattr(os.path, i, k[i])
yield None
finally:
for i in k.items():
setattr(os.path, i, old[i])
and so for your code you can use
print 'os.walk(\'goo\') with modified isdir()'
with changed_os_path(isdir=my_isdir):
for root, dirs, files in os.walk('goo'):
print root, dirs, files
so the change is only effective as long as you are in the relevant code
part and is reverted as soon as you leave it.
Thomas
--
http://mail.python.org/mailman/listinfo/python-list
Re: Which Version of Python?
On 11/09/2012 17:49, Charles Hottel wrote: I have a lot of programming experience in many different languages and now I want to learn Python. Which version do you suggest I download, Python 2.x or Python 3.x ? Also why should I prefer one over the other? Right now I am thinkng Python 3.x as it has been out since 2008, but I have some concerns about backward compatibility with older packages that I might want to use. Thanks for your ideas and help. Perhaps this will sway you http://docs.python.org/dev/whatsnew/3.3.html There is no longer an equivalent document for the Python 1.x or 2.x series of releases. -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: pythonOCC examples doesn't work?
On 12/09/2012 05:02, Jayden wrote: I installed (1) pythonxy2.7.2.3 (with python2.7) and (2) pythonOCC-0.5-all-in-one.win32.py26 Can you safely mix these? on windows 7 64 bit computer. I try run pythonOCC examples in its example folder, such as the helloworld.py and got errors as follows: ImportantError: DLL load failed: The specified module could not be found. The error come from the line of code: from OCC.BrepPrimAPI import * How to fix the error? Thanks a lot!! See above, I hope, I don't actually know :) -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
