List performance and CSV
Hello, I'm working on a simple project in Python that reads in two csv files and compares items in one file with items in another for matches. I read the files in using the csv module, adding each line into a list. Then I run the comparision on the lists. This works fine, but I'm curious about performance. Here's the main part of my code: ## file1 = open("CustomerList.csv") CustomerList = csv.reader(file1) Customers = [] #Read in the contents of the CSV file into memory for CustomerRecord in CustomerList: Customers.append(CustomerRecord) #not shown here: the second file CustomersToMatch #is loaded in a similar manner #loop through each record and find matches on column 2 #breaking out of inner loop when a match is found for loop1 in range(len(CustomersToMatch)): for loop2 in range(len(Customers)): if (CustomersToMatch[loop1][2] == Customers[loop2][2]) : CustomersToMatch[loop1][1] = Customers[loop2][1] break ## With this code, it takes roughly 10 minutes on a 2Ghz x86 box to compare two lists of 20,000 records. Is that good? Out of curiousity, I tried psyco and saw no difference. Is there a better Python synax to use? Thanks, -Stephan -- http://mail.python.org/mailman/listinfo/python-list
Python's CSV reader
I'm fairly new to python and am working on parsing some delimited text files. I noticed that there's a nice CSV reading/writing module included in the libraries. My data files however, are odd in that they are composed of lines with alternating formats. (Essentially the rows are a header record and a corresponding detail record on the next line. Each line type has a different number of fields.) Can the CSV module be coerced to read two line formats at once or am I better off using read and split? Thanks for your insight, Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's CSV reader
Thank you all for these interesting examples and methods! Supposing I want to use DictReader to bring in the CSV lines and tie them to field names, (again, with alternating lines having different fields), should I use two two DictReaders as in Christopher's example or is there a better way? -- Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's CSV reader
Andrew McLean wrote: > You are welcome. One point. I think there have been at least two > different interpretations of precisely what you task is. > > I had assumed that all the different "header" lines contained data for > the same fields in the same order, and similarly that all the "detail" > lines contained data for the same fields in the same order. Indeed, you are correct. Peter's version is interesting in its own right, but not precisely what I had in mind. However, from his example I saw what I was missing: I didn't realize that you could reassign the DictReader field names on the fly. Here is a rudimentary example of my working code and the data it can parse. - John|Smith Beef|Potatos|Dinner Roll|Ice Cream Susan|Jones Chicken|Peas|Biscuits|Cake Roger|Miller Pork|Salad|Muffin|Cookies - import csv HeaderFields = ["First Name", "Last Name"] DetailFields = ["Entree", "Side Dish", "Starch", "Desert"] reader = csv.DictReader(open("testdata.txt"), [], delimiter="|") while True: try: # Read next "header" line (if there isn't one then exit the loop) reader.fieldnames = HeaderFields header = reader.next() # Read the next "detail" line reader.fieldnames = DetailFields detail = reader.next() # Print the parsed data print '-' * 40 print "Header (%d fields): %s" % (len(header), header) print "Detail (%d fields): %s" % (len(detail), detail) except StopIteration: break Regards, -Stephan -- http://mail.python.org/mailman/listinfo/python-list
Interrupting execution of PyRun_SimpleScript()
Hi, Im am using PyRun_SimpleString() inside a BCB 5.0 GUI app on win32. All works fine. The PyRun_SimpleStript() runs a piece of python code which calls often a callback function to refresh my gui App so my Form still can react to user input. Now, I would like to implement a possibility to interrupt the execution. For this I have a button called "stop", and when the user executes it, I generate an exeption by calling: PyRun_SimpleString("raise KeyboardInterrupt\n"). I see in the window where I redirected stderr and stdout the exception, but the original code (a for loop) still continues to run. Does there somebody have some idea (in the Python FAQ i didnT find anything) Thanks Anton -- http://mail.python.org/mailman/listinfo/python-list
Problem installing pip
Good Morning, I've tried ten times to install pip with no success in windows 10 using python 64bit version. Is there a solution available? I'm looking forward hearing you soon. -- https://mail.python.org/mailman/listinfo/python-list
Re: A question on modification of a list via a function invocation
Op 2017-08-17, Rustom Mody schreef : > On Thursday, August 17, 2017 at 6:49:19 AM UTC+5:30, Mok-Kong Shen wrote: >> Am 17.08.2017 um 02:41 schrieb Steve D'Aprano: >> > By reference and by value are not the only two conventions. >> > >> > Perhaps if you go back to the 1950s you might be able to argue that >> > "reference" and "value" are the only two conventions, but >> > alternatives have existed for many decades, since *at least* 1960 >> > when Algol introduced "call by name". I'm a bit late to this discussion, but pelase allow me to add some (to me at least) fascinating history to this. In 1966, a very influential paper was published: P.J. Landin, "The Next 700 Programming Languages" See: https://www.cs.cmu.edu/~crary/819-f09/Landin66.pdf In this paper, Landin decribes a "family of unimplemented computing languages that is intended to span differences of application area by a unified framework". He calls this language (or family of languages) ISWIM. It is a language with Lisp-like semantics but "Algol-like" (i.e. infix) syntax, dynamically typed, and he introduces the novel idea to have "Indentation, used to indicate program structure." Sounds familiar to anybody? Yep, this is basically proto-Python. Anyway, then there is a later paper (from 1974) by G.D. Plotkin, "Call-by-name, call-by-value and the λ-calculus" (see http://www.sciencedirect.com/science/article/pii/0304397575900171 ). In this paper, Plotkin "examines the old question of the relationship between ISWIM and the λ-calculus, using the distinction between call-by-value and call-by-name." Yep, in 1974, what to call the calling convention of proto-Python was already an "old question". In this paper, Plotkin introduces the λV-calculus, the call-by-value lambda-calculus, to formalize what it is what ISWIM (and Python) are actually doing. This paper is, to the best of my knowledge, the closest thing to an "official" definition of what call-by-value actually means. Needless to say, according to the definition in Plotkin's paper, Python is "call-by-value". Stephan -- https://mail.python.org/mailman/listinfo/python-list
asyncio.gather cancellation behaviour
Hi all, I am a bit mystified about the rationale of the cancellation behaviour of asyncio.gather. Case 1: "If the outer Future is cancelled, all children (that have not completed yet) are also cancelled." Case 2: "If any child is cancelled, this is treated as if it raised CancelledError – the outer Future is not cancelled in this case. (THIS IS TO PREVENT THE CANCELLATION OF ONE CHILD TO CAUSE OTHER CHILDREN TO BE CANCELLED.)" [capitalization mine] Indeed I can observe this behavior. However, I would like to further understand the reasoning for not cancelling in case 2. Outside asyncio.gather, cancelling an "outer future" does NOT cancel the "inner future" on which the outer future is currently await-ing, while cancelling the "inner future" will raise a CancelledError which will cancel the outer future. Example: import asyncio f1 = asyncio.Future() async def make_f2(): await f1 f2 = asyncio.ensure_future(make_f2()) f2.cancel() # cancelling f1 instead will cancel BOTH f1 and f2 loop = asyncio.get_event_loop() try: loop.run_until_complete(f2) except asyncio.CancelledError: print("got CancelledError") print("f1 cancelled: ", f1.cancelled()) # prints False print("f2 cancelled: ", f2.cancelled()) # prints True So cancellation "normally" proceeds from inner future -> outer future. It seems somebody worked hard to reverse the direction in case of asyncio.gather. Why? Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Run Windows commands from Python console
Op 2017-09-06, Rick Johnson schreef : > One of the nice (current) features of Tkinter menus (that i > sometimes miss on my windows box!) is the ability to "tear- > off" a menu cascade and use it as a sort of "pseudo tool > bar". I was under the impression that Tk also supported tear-off menus under Windows (but not under macOS). However, many applications apparently explicitly suppress this functionality by doing Menu(..., tearoff=0) Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Best way to insert sorted in a list
Op 2017-09-08, logonve...@gmail.com schreef : > On Saturday, June 18, 2011 at 2:23:10 AM UTC+5:30, SherjilOzair wrote: >> There are basically two ways to go about this. >> One is, to append the new value, and then sort the list. >> Another is to traverse the list, and insert the new value at the >> appropriate position. >> >> The second one's complexity is O(N), while the first one's is O(N * >> log N). >> >> Still, the second one works much better, because C code is being used >> instead of pythons. Python uses the Timsort ( https://en.wikipedia.org/wiki/Timsort ) algorithm. Timsort is O(N) in the special case of a list of N elements where the first N-1 are already sorted and the last one is arbitrary. So appending the value and then calling sort() is in fact O(N) in Python (hence asymptotically optimal), and also practically fast since the sort() is implemented in C. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Using Python 2
Op 2017-09-08, Stefan Ram schreef : > OTOH, there are those killjoys who complain about > "too many parentheses" in programs written in the > "simple language". Which is clearly nonsense since it is easy to show that any working program in said simple language contains *precisely enough* parentheses. ;-) (Fortunate that I commented out the unbalanced closing parenthesis.) Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: The Incredible Growth of Python (stackoverflow.blog)
Op 2017-09-10, Chris Angelico schreef : > Want to make something iterable? Define __iter__. Want to make it > async-iterable (with "async for")? Define __aiter__. It's a bit clunky > if you want the same object to be iterable both ways, but I don't know > of any real-world situations where that's the case. Would we not eventually want a file object to deliver its lines asynchronously (with non-blocking reads under the hood) if iterated over with "async for", while preserving the current blocking behavior in the "for" case? Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: People choosing Python 3
Op 2017-09-10, Marko Rauhamaa schreef : > As an application developer, I can't make the customers depend on EPEL. > It's Python2 until the distro comes with Python3. Why not bundle the Python interpreter with your application? It seems to work for Windows developers... Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: People choosing Python 3
Op 2017-09-10, Marko Rauhamaa schreef : > Stephan Houben : >> >> Why not bundle the Python interpreter with your application? >> It seems to work for Windows developers... > > I've seen that done for Python and other technologies. It is an > expensive route to take. Also, it can be insecure. When vulnerabilities > are found, they are communicated to the maintainers of, say, Python. > When Python is fixed and released, the vulnerability is revealed, but > the version bundled with your product is still broken. You have to be > prepared perform an emergency release of your product and hope you don't > mess things up. To each his own, but this is not different from any other third-party package your application depends on. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Run Windows commands from Python console
Op 2017-09-10, Rick Johnson schreef : > It seems to me the best solution is for the TCL/Tk folks to > provide a configuration utility that stores user preferences > in the registry, or some other OS provided mechanism, as to > have these settings reset on every invocation of the > application would be inefficient from an enduser > perspective. You mean, like the existing .Xdefaults mechanism (yes Tk also supports that on Windows), and the "option" mechanism? https://www.tcl.tk/man/tcl8.6/TkCmd/option.htm Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: The Incredible Growth of Python (stackoverflow.blog)
Op 2017-09-10, Marko Rauhamaa schreef : > Stephan Houben : > >> Would we not eventually want a file object to deliver its lines >> asynchronously (with non-blocking reads under the hood) if >> iterated over with "async for", while preserving the current >> blocking behavior in the "for" case? > > I'm not exactly sure what your point is. I mean that I would imagine that 1. functionality as is today available in `aiofiles' would at some point be integrated into the standard library, and 2. that this might be done in such a way that there is no distinction anymore between a normal file object and an "aiofiles" file object, unlike today. > As for file objects supporting asynchronous iterators, I agree they > should. OK, that is essentially my point 2, above. > Linux is not quite ready for nonblocking file access yet (the > kernel developers are busy trying to make it happen). > > Note that you will not only need an async version of a file iterator but > also versions for the "open()" function, directory walking etc. open() already supports non-blocking mode (as does read() and write(), of course). readdir() is indeed currently always blocking. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: mutiprocessing gui
Op 2017-09-11, Antoon Pardon schreef : > When one wants to combine multithreading and gui programming > all sorts of issues arise. So I wonder how one might combine > multiprocessing with gui programming. > > gui libraries typically have some registration mechanisme, > where you can register a call back for when data is available > on a network connection. Could one write a wrapper so that > the multiprocessing.Queue or multiprocessing.Pipe could be > usable like that? Are you aware of Quamash? This allows you to combine a Qt GUI with asyncio-style code for, say, handing network connections. https://github.com/harvimt/quamash Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: array.array()'s memory shared with multiprocessing.Process()
Op 2017-09-12, gerlando.fala...@gmail.com schreef : > Notice however how I'd have to create those Arrays dynamically in the > producer thread. Would I then be able to pass them to the consumer by > putting a reference in a queue? Yes. > I wouldn't want them to be pickled at all in that case, of course. Essentially only an address pointing into a piece of shared memory is pickled and transmitted then. > Also, why do you say it only works on Unix? I couldn't find any > reference to such limitation in the documentation. There is no such limitation. It's supposed to work on all platforms (including Windows). Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: array.array()'s memory shared with multiprocessing.Process()
Op 2017-09-12, Thomas Jollans schreef : > I'm not sure actually. Maybe someone else here can help. I have a hunch > that on Windows the memory might not be shared in the same way that it > would on Linux/Unix, since Windows simply doesn't have the same process > forking capabilities as Unix. `multiprocessing` is not relying on the POSIX "inherit an anonymous mmap()" semantics to get a piece of memory shared across processes. 1. On Windows, it uses the Windows-specific functionality to associate a tagname with an mmap and open the specific mmap by tagname. 2. On Posix platforms, it creates a file which is opened and immediately unlink()-ed, and the file descriptor is communicated to the child process using a UNIX-domain socket. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Fw: Problems Installing Python36
Op 2017-09-12, Thomas Jollans schreef : > This isn't the first time I've someone with this issue here. It's > probably putting off plenty of potential new users who don't make as > much effort to find a solution. I can't say I understand the ins and > outs of installing things on Windows... is there anything that can be done? I just added issue 31427 on the Python bug tracker proposing adding this to the Windows FAQ. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: The Incredible Growth of Python (stackoverflow.blog)
Op 2017-09-12, Tim Golden schreef : > I agree. Except for the unusual case where someone's mistakenly chosen > to use, eg, Python 2.4 because they're using an old text book which > mentions it as the current version, most people are using the version > which suits them for one reason or another. If it is not clear from the original post that they are consciously using an old version, I will often try to politely suggest they use the latest version (i.e. "If there is no particular reason for you to use Python 1.5.2, may I suggest that you use 3.6 instead?"). The reason is that: * On many operating systems, just typing "python" will give you Python2.7 at best (e.g. macOS!). And the OP may not be aware that there are more recent versions. * In businesses, it is especially common to run on some RHEL version $ANCIENT; not so long ago I had a machine where typing "python" presented me with Python 2.3! I agree that *badgering* them about it (as opposed to suggesting it *once*) is a bad idea. > And, if I may put my 2.5p-worth in here, they're probably using the > operating system which suits them. (Maybe because their employer has > said so, or because they're familiar or whatever). So saying, as people > occasionally do, "Upgrade to Linux", even with half-a-wink, is not > really that funny or helpful. It's not really the same, though. Changing the OS is a big undertaking and affects all their programs, just installing version 3.6 of Python as a private user shouldn't affect anything else. You can install python in your home directory on your ancient RHEL box and leave the system Python happily at 2.3. I nowadays typically never bother with the system Python for my own development and just install a recent version of my choice locally. It saves a lot of headaches. The system Python is there to run system programs. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Python dress
Op 2017-09-12, Jona Azizaj schreef : > It looks very nice, thanks for sharing :) print(insertionSort) It's even Python3-compliant! Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?"
Op 2017-09-19, Steven D'Aprano schreef : > There is a significant chunk of the Python community for whom "just pip > install it" is not easy, legal or even possible. For them, if its not in > the standard library, it might as well not even exist. But numpy *is* in the standard library, provided you download the correct version of Python, namely the one from: https://python-xy.github.io/ Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Fw: Problems Installing Python36
Op 2017-09-20, Irmen de Jong schreef : > The only thing I can think of is that it asks windows update to > install said KB update but that it depends on something else that > isn't installed or that the user running the installation doesn't have > the rights to install windows updates. (I suspect something will be > logged in the event viewer somewhere...?) Yeah, I suppose something like that. Presumably you can lock down Windows in some way that it won't install the KB, but that is clearly not the factory default. > Or that it doesn't attempt to download it at all and that we are > misinformed :P :-( > Btw, I personally never had any issues installing Python on Windows. I was vaguely tempted to offer the Mingw-w64 (GCC) Python as an alternative, since it doesn't rely on any optionally-installed Microsoft DLLs and so avoids this issue. But I suppose that is not really the newbie-friendly solution the OP was looking for... Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Even Older Man Yells at Whippersnappers
Op 2017-09-21, Thomas Jollans schreef : > On 2017-09-19 20:21, Stefan Ram wrote: >> I do not use UTF-8 >> > > Why on earth not?! Even *More* Older Man Yells at UTF-8? -- https://mail.python.org/mailman/listinfo/python-list
Re: Assertions
Op 2017-09-22, Thomas Jollans schreef : > Just to make the implication explicit: > >>>> from math import nan >>>> nan is nan > True >>>> nan == nan > False >>>> nan != nan > True >>>> To add to the fun: >>> nan is nan True Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Fw: Problems Installing Python36
Op 2017-09-22, Irmen de Jong schreef : > On 09/22/2017 08:34 PM, Stephan Houben wrote: > >> I was vaguely tempted to offer the Mingw-w64 (GCC) Python as an >> alternative, since it doesn't rely on any optionally-installed Microsoft >> DLLs and so avoids this issue. But I suppose that is not really the >> newbie-friendly solution the OP was looking for... > > Mingw? Perhaps better to choose Anaconda/Miniconda instead if you go for > an alternative implementation... Anaconda is still based on MSVC and so still relies on the MSVC C library. If installing the MSVC C linrary is the problem, then I don't think Anaconda solves that. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: How to share class relationship representations?
Op 2017-09-22, Pavol Lisy schreef : > On 9/19/17, leam hall wrote: >> I'm working on designing the classes, sub-classes, and relationships in my >> code. What is a good visual way to represent it so it can be stored in git >> and shared on the list without large images or attachments? >> >> Thanks! >> >> Leam > > https://stackoverflow.com/questions/29586520/can-one-get-hierarchical-graphs-from-networkx-with-python-3#29597209 For direct inclusion in source code, what about plain text with Unicode box drawing characters? ┏━━┓ ┃object┃ ┗━━━┳━━┛ ┃ ┏━━┻━━┓ ┃float┃ ┗━┛ Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] beginning to code
Op 2017-09-23, Rick Johnson schreef : > These pissing contests over how values are passed in Python > are totally irrelevant. What does it matter? Nothing will be > gained or lost by arguing over which is true, or not. Unless > the distinction is preventing you from doing something that > you'd like to do, or unless you want to argue that one > "value passing method" would bring X, Y or Z benefits over > the other, what does it matter? Amen. For what it's worth, this discussion lead me to do a bit of historical research into how these terminologies came to be (also to see if there is some sort of "official" definition of what they actually mean). The earliest to which I can trace the discussion is on the context of the definition of the Algol programming language. Algol had both "call by value" and "call by name". Then the whole "call by XXX" terminology took off and people started talking about "call by copy in/out" and whatever. The "call by reference" terminology was introduced to describe what Fortran had been doing all along. The CLU people (primary Barbara Liskov) introduced "call by object sharing", to describe what CLU did. This matches pretty well what Python does, and what Java does, and what basically every programming language invented in the last 25 years does. Now, as I said, what Java and what CLU do is pretty similar, but in the Java community this very same thing is called "call by value". As far as I can follow, this is for the following reason: * The Algol report invented "call by value" and "call by name" and was very influential. * In particular, the Report on the Scheme language was heavily influenced by the Algol report. In the Scheme report, Scheme is described as being "call by value", again probably because of influence of the Algol report, and Scheme is definitely NOT "call by name". Note that in our terminology, Scheme should properly be called "call by object [sharing]". * Guy Steele, who was involved in the Scheme standard, then went on to work on the Java language definition. So Java got its terminology from the Algol->Scheme->Java route. Python got it from CLU. As an aside, in the academic literature, "call by value" is almost always contrasted with "call by name" (nobody seems to have ever published a paper discussing "call by reference"). Typically, this comparison is done in calculi which even lack assignment so that the difference between call by value and call by reference would be unobservable anyway. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Calling methods without objects?
Op 2017-09-25, Stefan Ram schreef : > So, is there some mechanism in Python that can bind a method > to an object so that the caller does not have to specify the > object in the call? > > If so, how is this mechanism called? > Others have already explained the details how functions become bound methods, but I would just point out that it is an instance of a piece of very general functionality: the descriptor protocol. https://docs.python.org/3.6/howto/descriptor.html With this, you can create your own objects which do some arbitrary special thing when accesses on an instance. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Parentheses (as after "print")
Op 2017-09-26, Stefan Ram schreef : > What happened? I woke up today in parens mood. So I typed: > > import( operator ) > > Python told me that I should type: > > import operator > > . Fine, Python conditioned me to omit the parens. > So now I was in noparens mood. So I typed: > > help operator > > . Oops! The explanation is of course that `import` is a syntactic keyword and `help` is an ordinary function. But if you want to be lazy, you can use the `ipython` interpreter (https://ipython.org) with the %autocall feature... $ ipython Python 3.6.2 (default, Aug 3 2017, 16:08:52) Type 'copyright', 'credits' or 'license' for more information IPython 6.2.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: %autocall Automatic calling is: Smart In [2]: help help Help on _Helper in module _sitebuiltins object: class _Helper(builtins.object) Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Op 2017-09-27, Robert L. schreef : > (sequence-fold + 0 #(2 3 4)) > ===> > 9 > > In Python? >>> sum([2, 3, 4]) 9 -- https://mail.python.org/mailman/listinfo/python-list
Re: LOOP with fixed final index value
Op 2017-09-27, Robert L. schreef : >> > (defun myloop (initial final increment) >> > (loop for i = initial then (+ i increment) >> > while (< i final) >> > do (print i) >> > finally (let ((i final)) (print i >> > > In Python? myloop = lambda *args: print("{}{}".format("".join(map("{}\n".format, range(*args))), args[1])) Of course. -- https://mail.python.org/mailman/listinfo/python-list
Re: merits of Lisp vs Python
Op 2017-09-30, Marko Rauhamaa schreef : > Robert L. is only trolling. He uses fake technical comments to spread > white supremacy in his signatures. My apologies. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: newb question about @property
Op 2017-10-01, Bill schreef : > I watched an example on YouTube where someone wrote a simple descriptor > ("@Time_it) to output the amount of time that it took ordinary functions > to complete.To be honest, I AM interested in descriptors. Are you sure you are not confusing deSCRIPTtors and deCORAtors here? @Time_it is decorator syntax. Despite the similarity in the words, there are totally different things. Descriptors are objects with __get__, and optionally __set__ and __delete__ methods (i.e. they implement the descriptor protocols). Decorators aren't really an official type, but loosely speaking these are any functions which can be applied meaningfully with a single function or class as argument. Some very mundane functions can be (ab)used as decorators. In [1]: @repr ...: def hello(): ...: pass ...: In [2]: hello Out[2]: '' Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: newb question about @property
Op 2017-10-01, Bill schreef : > Steve D'Aprano wrote: >> >> [1] Technically, the interpreter knows nothing about properties. What >> it cares about is *descriptors*. Properties are just one kind of >> descriptor, as are methods. But I'm intentionally not talking about >> the gory details of descriptors. Feel free to ask if you care, but >> honestly, you don't need to care unless you are writing your own >> descriptor class. >> > I found the following page to be a very easily accessible discussion > about descriptors (it represents the state of my knowledge about > descriptors). You got more? : ) > > https://www.programiz.com/python-programming/decorator I found the page to be a discussion about decorators (unsurprisingly given the URL) and not containing the word "descriptor" at all... Note that the remark from Steve is on the topic of descriptors. I suppose the first advice to anybody wanting to learn about either descriptors or decorators is to not confuse them with the other thing. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: How to determine lowest version of Python 3 to run?
Op 2017-10-05, Ben Finney schreef : > Christopher Reimer writes: > >> How do I determine the lowest version of Python to [declare that my >> code supports]? > > You can determine that by installing all the Python versions you want to > try, and running your code's unit test suite on each of them. An easy way to get a bunch of different Python versions is to just pull the various Docker containers for them. https://hub.docker.com/r/_/python/ Then run your unit tests in each of them. Note that Python 3.3 support officially ended on 2017-09-29, so at the moment I wouldn't bother to support anything lower than 3.4. That means testing 3.4, 3.5 and 3.6 (and 3.7 prerelease if you want to be thorough). Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Multithreaded compression/decompression library with python bindings?
Op 2017-10-04, Paul Moore schreef : > On 4 October 2017 at 16:08, Steve D'Aprano wrote: >> On Wed, 4 Oct 2017 08:19 pm, Thomas Nyberg wrote: >> >>> Hello, >>> >>> I was wondering if anyone here knew of any python libraries with >>> interfaces similar to the bzip2 module which is also multithreaded in >>> (de)compression? Something along the lines of (say) the pbip2 program >>> but with bindings for python? In a pinch: with open("myoutfile.gz", "wb") as f: sp = subprocess.Popen(("gzip",), stdin=subprocess.PIPE, stdout=f) sp.stdin.write(b"Hello, world\n") sp.stdin.close() Does compression in a separate process ;-) Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Multithreaded compression/decompression library with python bindings?
Op 2017-10-05, Thomas Nyberg schreef : > Btw if anyone knows a better way to handle this sort of thing, I'm all > ears. Given my current implementation I could use any compression that > works with stdin/stdout as long as I could sort out the waiting on the > subprocess. In fact, bzip2 is probably more than I need...I've half used > it out of habit rather than anything else. lzma ("xv" format) compression is generally both better and faster than bzip2. So that gives you already some advantage. Moreover, the Python lzma docs say: "When opening a file for reading, the input file may be the concatenation of multiple separate compressed streams. These are transparently decoded as a single logical stream." This seems to open the possibility to simply divide your input into, say, 100 MB blocks, compress each of them in a separate thread/process and then concatenate them. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: How to determine lowest version of Python 3 to run?
Op 2017-10-06, Christopher Reimer schreef : > So I got tox and tox-docker installed. When I went to install Docker > for Windows, it wouldn't work because Hyper-V wasn't available on > Windows 10 Home. After paying Microsoft $99 for the privilege, I got > Windows 10 Pro installed and Docker started working. I've read that > all the cool programming kids are using Docker these days. I certainly > hope it was worth the cost. O_o You could have just used a Linux VM in Virtualbox for $0, and run Docker in that. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Installing tkinter on FreeBSD
Op 2017-10-23, Thomas Jollans schreef : > On 24/10/17 00:16, Dick Holmes wrote: >> I am trying to use tkinter on a FreeBSD system but the installed >> versions of Python (2.7 and 3.6) don't have thinter configured. I tried >> to download the source (no binaries available for FreeBSD). What version of FreeBSD is that? On 11.1 I get: $ pkg search tkinter py27-tkinter-2.7.14_6 Python bindings to the Tk widget set (Python 2.7) py34-tkinter-3.4.7_6 Python bindings to the Tk widget set (Python 3.4) py35-tkinter-3.5.4_6 Python bindings to the Tk widget set (Python 3.5) py36-tkinter-3.6.2_6 Python bindings to the Tk widget set (Python 3.6) pypy-tkinter-5.8.0 PyPy bindings to the Tk widget set and for sure installing py36-tkinter-3.6.2_6 works fine. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Windows alternative: multiprocessing.connection.wait on Pipe, Tkinter File Handlers
Op 2017-10-23, Thomas Jollans schreef : > You might wait in a thread > and somehow (no idea what the best way to do this is in tkinter) pass a > message to the GUI thread when it's done. AFAIK, this is a real problem in Tkinter on Windows. On Posix you can use the self-pipe trick. But on Windows, Tkinter cannot wait on a pipe. I see two solutions (well, three, really): 1. Use a different toolkit, e.g. PyQt has explicit support for notifying the GUI thread from another thread. 2. Use Cygwin-based Python. If this is an option, the Cygwin people did already all the heavy lifting for providing Posix-like select() semantics. 3. Regular polling. This has been rejected by the OP, but in my experience can produce reasonable results when done "properly", i.e. use the Tkinter "after" method with a reasonable time interval (in the past I have used a strategy of starting with 10 ms and then, on no event, slowly back off to polling every 200ms). It is by far the simplest solution, and AFAIK the only one which will work with the standard Python distribution + Tkinter. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: doubling the number of tests, but not taking twice as long
Op 2018-07-16, Larry Martell schreef : > I had some code that did this: > > meas_regex = '_M\d+_' > meas_re = re.compile(meas_regex) > > if meas_re.search(filename): > stuff1() > else: > stuff2() > > I then had to change it to this: > > if meas_re.search(filename): > if 'MeasDisplay' in filename: > stuff1a() > else: > stuff1() > else: > if 'PatternFov' in filename: > stuff2a() >else: > stuff2() > > This code needs to process many tens of 1000's of files, and it runs > often, so it needs to run very fast. Needless to say, my change has > made it take 2x as long. It's not at all obvious to me. Did you actually measure it? Seems to depend strongly on what stuff1a and stuff2a are doing. > Can anyone see a way to improve that? Use multiprocessing.Pool to exploit multiple CPUs? Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Can pip install packages for all users (on a Linux system)?
Op 2018-07-24, John Ladasky schreef : > I believe that I now have tensorflow 1.8 installed twice on my system, > once for each user. If anyone can share how to convince pip to behave > like Synaptic, I would appreciate it. Thanks. I would recommend against using pip to install packages into the system Python. The reason is that you may get into a conflict with the package manager. You can try to be careful and not install tensorflow using Synaptic, but once you install some other package which happens to depend on tensorflow, you will start getting package manager conflicts. An alternative is to install Python yourself (from source, without the package manager) in, say, /opt/python. You are then in splendid isolation from the package manager and can install any version of Python and tensorflow you desire. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Checking whether type is None
Op 2018-07-24, Chris Angelico schreef : > On Wed, Jul 25, 2018 at 9:18 AM, Rob Gaddi > wrote: >> On 07/24/2018 01:07 PM, Chris Angelico wrote: >> I suppose one valid usage would be this sort of thing: >> >> fn = { >> int: dispatchInt, >> str: dispatchStr, >> list: dispatchList, >> type(None): dispatchNone >> }[type(x)] >> fn(x) >> > > True, but that would be useful only in a very few situations, where > you guarantee that you'll never get any subclasses. So if you're > walking something that was decoded from JSON, and you know for certain > that you'll only ever get those types (add float to the list and it's > basically covered), then yes, you might do this; and then I would say > that using "type(None)" is the correct spelling of it. This is actual code I have: @singledispatch def as_color(color): """Convert object to QColor.""" return QtGui.QColor(color) as_color.register(type(None), lambda x: QtGui.QColor(0, 0, 0, 0)) Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Checking whether type is None
Op 2018-07-25, Ian Kelly schreef : > Is there a reason for using singledispatch here rather than a simpler and > more readable "if color is None" check? Yes, the other 20 cases I didn't show. And extensibility. Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Using Python on a fork-less POSIX-like OS
Op 2018-07-29, Terry Reedy schreef : > multiprocessing module uses 'spawn' rather than 'fork' on Windows and it > has an option to use 'spawn' even on *nix. I presume the latter refers > to posix_spawn. You might want to check the multiprocessing code to see > what *it* is doing 'under the covers'. Actually, the only place posix_spawn is currently used in Python is in some experimental and currently-disabled code in the posix module. `spawn' in multiprocessing only refers to a fork/exec combination (on Posix, at least), as opposed to `fork' which only does a fork. Note that posix_spawn cannot provide full subprocess functionality (obviously preexec_fn, but also not start_new_session). So it's a hard sell to add a posix_spawn special case there, since a generic fork/exec would need to be maintained anyway. (The same reason is also why most shells such as bash, zsh, don't bother with posix_spawn.) Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: os.system vs subrocess.call
> On 28. Nov 2019, at 12:05, Ulrich Goebel wrote: > > Hi, > > I have to call commands from inside a python skript. These commands are in > fact other python scripts. So I made > >os.system('\.Test.py') > > That works. > > Now I tried to use > >supprocess.call(['.\', 'test.py']) [ins] In [1]: from os import system [ins] In [2]: system('./test.py') hallo world Out[2]: 0 [ins] In [3]: from subprocess import call [ins] In [4]: call('./test.py') hallo world Out[4]: 0 In the first call you call ’.Test.py’ In the second call you call ’test.py’ “supprocess” doesn’t exist How about subprocess.call(‘\.Test.py’) Or subprocess.call([‘\.Test.py’]) Whereas the later makes more sense if you want to pass arguments to Test.py Greetings Stephan -- https://mail.python.org/mailman/listinfo/python-list
Re: Sandboxing eval() (was: Calculator)
> On 19. Jan 2020, at 19:35, mus...@posteo.org wrote: > > Is it actually possible to build a "sandbox" around eval, permitting it > only to do some arithmetic and use some math functions, but no > filesystem acces or module imports? > > I have an application that loads calculation recipes (a few lines of > variable assignments and arithmetic) from a database. > > exec(string, globals, locals) > > with locals containing the input variables, and globals has a > __builtin__ object with a few math functions. It works, but is it safe? https://github.com/danthedeckie/simpleeval Might be a good starting point. Greetings Stephan -- https://mail.python.org/mailman/listinfo/python-list
dynamic import of dynamically created modules failes
Hello, background: - a daemon creates package p1 (e.g. directory with __init__.py-file) and in p1 a module m1 is created. - Then the daemon wants to import from m1, which functions (so far all the time). - Then a module m2 is created in p1 and the daemon wants to import from m2 which fails (most of the time but *not* always) with ModuleNotFoundError. See the little test script at the end which reproduces the problem. The very strange thing for me is, that the import of m2 in the test script sometimes works. I wonder if there is some package-content-caching. And if so how to prevent or re-trigger it. (neither a reload of p1 nor a deletion of p1 from sys.modules does the trick) -test-script--- """ (python --version: Python 3.8.2) Dynamic import of dynamically created modules right after creation. """ from shutil import rmtree from os import path, chdir, mkdir, listdir from importlib import import_module, reload import sys # for test-package creation P1 = 'p1' INIT = '__init__.py' INIT_CONTENT = """\ # -*- coding: utf-8 -*- """ # for first test-module creation M1 = 'm1' M1_CONTENT = """\ # -*- coding: utf-8 -*- answer = 42 """ # for second test-module creation M2 = 'm2' M2_CONTENT = """\ # -*- coding: utf-8 -*- hello = 'world' """ chdir(path.dirname(__file__)) # make sure we are in the right directory if path.isdir(P1): rmtree(P1) # always start off under the same conditions mkdir(P1) # create test-package and first test-module with open(path.join(P1, INIT), 'w') as f: f.write(INIT_CONTENT) with open(path.join(P1, M1+'.py'), 'w') as f: f.write(M1_CONTENT) # import from the just created module; this worked always so far from p1.m1 import answer print(f'{answer=}') with open(path.join(P1, M2+'.py'), 'w') as f: f.write(M2_CONTENT) # create the second test-module # check current directory, file and module structure print('wd-content:', ', '.join(listdir())) print('p1-content:', ', '.join(listdir(P1))) print('p1-modlues:', ', '.join([m for m in sys.modules if m.startswith('p1')])) # reload(sys.modules['p1']) # neither a reload # del sys.modules['p1'] # nor a deletion of p1 does the trick # here it most of the time fails (but NOT all the time) # so far if it fails it fails in all three variants # so far if it works the 'from ...'-import works already try: from p1.m2 import hello except ModuleNotFoundError: try: hello = getattr(import_module('p1.m2'), 'hello') except ModuleNotFoundError: try: hello = getattr(__import__('p1.m2', fromlist=[None]), 'hello') except ModuleNotFoundError: raise else: print("__import__-import worked") else: print("import_module-import worked") else: print("'from ... '-import worked") print(f'{hello=}') -- https://mail.python.org/mailman/listinfo/python-list
Re: dynamic import of dynamically created modules failes
On 3/31/20 9:01 PM, Pieter van Oostrum wrote: "Dieter Maurer" writes: Stephan Lukits wrote at 2020-3-31 17:44 +0300: background: - a daemon creates package p1 (e.g. directory with __init__.py-file) and in p1 a module m1 is created. - Then the daemon wants to import from m1, which functions (so far all the time). - Then a module m2 is created in p1 and the daemon wants to import from m2 which fails (most of the time but *not* always) with ModuleNotFoundError. See the little test script at the end which reproduces the problem. ... I remember a similar report (some time ago). There, caching has been responsible. I have forgotten how to invalidate the caches. But, you could try logic found in `importlib._bootstrap_external.PathFinder.invalidate_caches`. The first import creates a file __pycache__ in the directory p1. To remove it use rmtree(path.join(P1,'__pycache__')) Then the second import will succeed. Thank you, but the behavior doesn't change. I added rmtree(path.join(P1, '__pycache__')) Before the import: try: from p1.m2 import hello and still get (please note that there isn't a __pycache__ directory anymore): answer=42 wd-content: __init__.py, p1 p1-content: __init__.py, __pycache__, m1.py, m2.py p1-modlues: p1, p1.m1 p1-content after rmtree: __init__.py, m1.py, m2.py Traceback (most recent call last): File "dynamic_modules/__init__.py", line 68, in from p1.m2 import hello ModuleNotFoundError: No module named 'p1.m2' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "dynamic_modules/__init__.py", line 71, in hello = getattr(import_module('p1.m2'), 'hello') File "/home/goedel/.pyenv/versions/3.8.2/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 973, in _find_and_load_unlocked ModuleNotFoundError: No module named 'p1.m2' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "dynamic_modules/__init__.py", line 74, in hello = getattr(__import__('p1.m2', fromlist=[None]), 'hello') ModuleNotFoundError: No module named 'p1.m2' -- https://mail.python.org/mailman/listinfo/python-list
[Solved] Re: dynamic import of dynamically created modules failes
On 3/31/20 8:00 PM, Dieter Maurer wrote: Stephan Lukits wrote at 2020-3-31 17:44 +0300: background: - a daemon creates package p1 (e.g. directory with __init__.py-file) and in p1 a module m1 is created. - Then the daemon wants to import from m1, which functions (so far all the time). - Then a module m2 is created in p1 and the daemon wants to import from m2 which fails (most of the time but *not* always) with ModuleNotFoundError. See the little test script at the end which reproduces the problem. ... I remember a similar report (some time ago). There, caching has been responsible. I have forgotten how to invalidate the caches. But, you could try logic found in `importlib._bootstrap_external.PathFinder.invalidate_caches`. Yes, removing the entry for p1 from 'sys.path_importer_cache' seems to solve the problem. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Typing modules
> On 20 Jul 2020, at 16:31, Jonathan Gossage wrote: > > I have the following code and I would like to type the variable *contents*: > > contents: something = importlib._import_module(name) > > > I have been unable to find out what *something* should be. types.ModuleType > > -- > Jonathan Gossage > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 30)
On Tue, 04 Jan 2005 05:43:32 -0800, michele.simionato wrote: > Holger: > >> FWIW, i added the recipe back to the online cookbook. It's not > perfectly >> formatted but still useful, i hope. > >> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/361742 > > Uhm... on my system I get: > german_ae = unicode('\xc3\xa4', 'utf8') print german_ae # dunno if it will appear right on Google groups > ä > german_ae.decode('latin1') > Traceback (most recent call last): > File "", line 1, in ? > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in > position 0: ordinal not in range(128) > ?? What's wrong? I'd rather use german_ae.encode('latin1') ^^ which returns '\xe4'. > > Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Problem with threads
Hi all, I've got a problem with stopping python-threads. I'm starting a thread with twisteds reactor.deferToThread which start a methodcall in a seperate thread. In this thread a swig-wrapped c++ module is running. Now I want to stop the running thread from the main thread or another one, and have no idea how to do it. I hope it has become clear what I want to do, if not feel free to ask. I'm running python 2.4 Thanks in advance, Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: python and ajax
On Mon, 29 Aug 2005 12:04:46 -0700, Steve Young wrote: > Hi, I was wondering if anybody knew of any good > tutorial/example of AJAX/xmlhttprequest in python. > Thanks. > > -Steve As all the others have said already, AJAX has nothing to do with python, but everything with JavaScript. You might want to check out MochiKit (http://mochikit.com), a lightweight JavaScript library written by Bob Ippolito. Bob did a very good job in turning programming JS into a more python like experience. - stephan -- http://mail.python.org/mailman/listinfo/python-list
curious about slice behaviour
I just found out by accident, that slice indices can be larger than the length of the object. For example >>> 'test'[:50] 'test' >>> 'test'[40:50] '' I'd rather expected to be confronted with an IndexError. (This is actually described in http://docs.python.org/lib/typesseq.html, so my expectation was wrong :)) Does anybody know, why this is preferred to just raising an error? -- http://mail.python.org/mailman/listinfo/python-list
Re: curious about slice behaviour
On Mon, 05 Sep 2005 14:26:14 -0400, Terry Reedy wrote: > > "Stephan Diehl" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >>I just found out by accident, that slice indices can be larger than >> the length of the object. For example >>>>> 'test'[:50] >> 'test' [...] >> Does anybody know, why this is preferred to just raising an error? > > Slicing was intentially designed to always give an answer (given int > coords) and never say 'can't answer' (whether by exception or a None > return). This avoids having to call len() when you don't care and avoids > having to use try:...except:... or conditionalize the code when it is not > needed. For instance c=s[0:1] is equivalent to > > c=s[0:min(1,len(s))] # if slice had to be exact, or > > c = s and s[0] or '' # or > > if s: > c = s[0] > else: > c = '' # or > > try: > c = s[0] > except IndexError: > c = '' > > People occasionally post buggy code which simply needs s[0] changed to > s[0:1]. > > The form s[i:], which I am sure you agree is useful, is effectively > equivalent to eithers[i:len(s)] or s[i:]. The latter view > generalizes to iterables without a knowable length. I do think that this is useful and can save some lines of code. Just never expected this. > > Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Python CGI and Firefox vs IE
On Wed, 07 Sep 2005 10:50:15 -0700, Jason wrote: > Hey y'all, this falls under the murky realm of HTML, CGI and > Python...and IE. > > Python 2.4, using CGI to process a form. > > Basically I've got 3 buttons. Here's the HTML code: > > > All > Servers > type='submit'>WKPEA1 > type='submit'>WKNHA2 > > > > And the code that's messing things up: > No, here you are wrong. IE doesn't work as expected with buttons. See http://www.solanosystems.com/blog/archives/2005/04/12/the-submit-button-problem/ This has nothing to do with Python. --- Stephan > jason -- http://mail.python.org/mailman/listinfo/python-list
Re: Alternatives to Stackless Python?
On Tue, 20 Sep 2005 08:50:44 -0700, [EMAIL PROTECTED] wrote: > After recently getting excited about the possibilities that stackless > python has to offer > (http://harkal.sylphis3d.com/2005/08/10/multithreaded-game-scripting-with-stackless-python/) > and then discovering that the most recent version of stackless > available on stackless.com was for python 2.2 I am wondering if > Stackless is dead/declining and if so, are there any viable > alternatives that exist today? Well, it's not dead and the last recent version is for python 2.3 The developer of stackless, Christian Tismer, is one of the main developers of the PyPy project. (http://codespeak.net/pypy) For this reason, there is an extremely good chance that the ideas behind stackless will survive :-) . Visit www.stackless.com for further info. --- Stephan -- http://mail.python.org/mailman/listinfo/python-list
Imported or executed?
Hi All, I've written a Python replacement of fixbb, as shell/awk script that will create tightly fitting bounding boxes for PostScript files. Most of the functionality is encapsulated in a small function called fixbb(filename). I'm importing this into other code via 'import'. A few lines of code for command line handling make the module into a freestanding program. For simplicity and ease of maintenance, I would rather keep library and program as a single file. However, the command line code is also executed when the module is imported, not only when the stand-alone program is executed. That is not, of course, intended (or working). Is there a (portable, standard) way for the program/module to find out if it is imported or executed stand-alone? You can find the code at http://www.eprover.org/SOFTWARE/utilities.html Bye, Stephan -- -- It can be done! - Please email me as [EMAIL PROTECTED] (Stephan Schulz) -- http://mail.python.org/mailman/listinfo/python-list
Re: Imported or executed?
In article <[EMAIL PROTECTED]>, Fredrik Lundh wrote: >Stephan Schulz wrote: > >> Is there a (portable, standard) way for the program/module to find out >> if it is imported or executed stand-alone? > >if a module is executed, it's name is set to "__main__". see: [...] It works. Thanks! Bye, Stephan -- -- It can be done! ----- Please email me as [EMAIL PROTECTED] (Stephan Schulz) -- http://mail.python.org/mailman/listinfo/python-list
Wing IDE 2.0.2 Released
Hi, I'm happy to announce the release of Wing IDE 2.0.2. This is a free upgrade for Wing IDE 2.0 users. The release can be downloaded from: http://wingware.com/downloads Wing IDE provides powerful debugging, editing, code intelligence, and search capabilities that reduce development and debugging time, cut down on coding errors, and make it easier to understand and navigate Python code. Highlights of this release include: * Easier to use Zope and Plone integration http://wingware.com/doc/howtos/zope * Extension of the IDE with Python scripts (Wing Pro only) http://wingware.com/doc/scripting * CVS revision control system integration (Wing Pro only) http://localhost/doc/edit/revision-control * Reorganized and expanded Project and File properties * Ability to view and change text file encodings * Per-project line ending and indentation policies * Option to auto-add new files to projects * Text input methods for non-european languages * Wing IDE Personal now includes the Indentation tool * Over 70 other improvements and bug fixes New features in Wing IDE 2.0 since the last 1.1 release include a redesigned customizable user interface, call tips, syntax error indicators, editor tabs and splits, multi-file wildcard and regular expression searching, integrated documentation and tutorial, German localization, and Unicode support. This release is available for Windows, Linux, and Mac OS X, and can be compiled from sources on *BSD, Solaris, and other Posix operating systems. A complete list of changes is available here: http://wingware.com/pub/wingide/2.0.2/CHANGELOG.txt For more information see: Product Info: http://wingware.com/products Sales: http://wingware.com/store/purchase Upgrades: http://wingware.com/store/upgrade Sincerely, Stephan Deibel -- Wingware Wing IDE for Python Advancing Software Development www.wingware.com -- http://mail.python.org/mailman/listinfo/python-list
Re: variable arguments question
On Tue, 15 Mar 2005 03:48:40 -0400, vegetax wrote: > if i have a dictionary: > d = {'a':2,'b':3 } > l = (1,2) > > how can i pass it to a generic function that takes variable keywords as > arguments? same thing with variable arguments, i need to pass a list of > arguments to the function > > def asd(**kw): print kw > def efg(*arg): print arg > > asd(d) > doesnt work > asd(kw = d) > doesnt work but asd(**d) > > efg(l) > doesnt work and efg(*l) will work. > > i need to pass those as a dictionary and a list,since i dont know ahead of > time if which items would have d and l -- http://mail.python.org/mailman/listinfo/python-list
ANN: Wing IDE 2.0.1 released
Hi, I'm happy to announce version 2.0.1 Wing IDE, an advanced integrated development environment for Python. This is a free upgrade for Wing IDE 2.0 users. It can be downloaded from: http://wingware.com/downloads Highlights of this release include: * Support for Python 2.4 * Optimized debugger * Searchable documentation * Expanded auto-completion preferences * Easier to customize key bindings * Remembers window layout even when no project is open * Zope instance directory support * Various bug fixes New features in Wing IDE 2.0 since the last 1.1 release include a redesigned customizable user interface, call tips, syntax error indicators, editor tabs and splits, multi-file wildcard and regular expression searching, integrated documentation and tutorial, German localization, and Unicode support. This release is available for Windows, Linux, and Mac OS X, and can be compiled from sources on FreeBSD, Solaris, and other Posix operating systems. A complete list of changes is available here: http://wingware.com/pub/wingide/2.0.1/CHANGELOG.txt For more information see: Product Info: http://wingware.com/products Sales: http://wingware.com/store/purchase Upgrades: http://wingware.com/store/upgrade Sincerely, Stephan Deibel -- Wingware Wing IDE for Python Advancing Software Development www.wingware.com -- http://mail.python.org/mailman/listinfo/python-list
ANN: PSF Licensing FAQ
Hi, The Python Software Foundation (PSF) board recently wrote up a licensing FAQ that we hope will help to clear up some of the confusion that has surrounded the PSF License. There are quite a few projects out there (on Source Forge and otherwise) that misuse this license in ways potentially detrimental to those projects. If you are the author or maintainer of a project that uses the PSF License, please read this: http://www.python.org/cgi-bin/moinmoin/PythonSoftwareFoundationLicenseFaq In short: The PSF License was originally developed specifically and only for Python itself (and its standard library). It can be reused but not verbatim without modifying the copyright and product name in the license. Also, the entire "license stack" that comes with Python is irrelevant to 3rd party projects and should not be reproduced outside of Python. The above document also covers contribution of code to the PSF, which is only an issue if your code will become part of the Python distribution. The contribution process is still being set up, so this part of the document is subject to change. Please cc me on any replies, as I can't currently keep up with CLP. Thanks! Stephan Deibel Chairman of the Board Python Software Foundation http://python.org/psf -- http://mail.python.org/mailman/listinfo/python-list
Please Donate to the PSF
Hi, As the holiday season ends and a new year approaches, I would like to take this opportunity to thank everyone that donated to the Python Software Foundation (PSF) in the past. Everyone's support is greatly appreciated. We now have well over 400 donors, many of whom donate regularly: http://www.python.org/psf/donations.html We also have 15 sponsor members that contribute annually to the PSF: http://www.python.org/psf/ Because of our donors and sponsors, the PSF was able to issue its first grants solicitation in 2004. This was very successful, with many more quality submissions than we could fund. Several grants have been approved for completion in 2005. With these and future grants, we intend to continue improving Python. The PSF also manages the intellectual property rights behind Python and runs the PyCon developers conference annually: http://www.python.org/pycon/ Please consider donating in order to support Python and the PSF. We are currently accepting donations via check or PayPal, and will soon begin accepting credit cards directly. Donations can be made starting here: http://www.python.org/psf/donations.html The PSF is a registered 501(c)(3) charity so donations are tax-deductible for US tax payers. There is still time to make a donation that can be deducted in the 2004 tax year. If you would like to learn more about the PSF, please visit: http://www.python.org/psf/ Happy New Year! Sincerely, Stephan Deibel Chairman of the Board Python Software Foundation http://python.org/psf -- http://mail.python.org/mailman/listinfo/python-list
PSF donations update
Hi, Just wanted to follow up on my earlier message requesting donations to the Python Software Foundation. The PSF has now announced the projects we are funding in our first round of grants: http://www.python.org/psf/grants/ We received many other quality grant proposals that could not be funded due to the relatively small size of our budget ($40K this year). I hope we'll be able to raise substantially more money in the coming year to allow us to fund more projects in the next cycle. There are something like 750,000 Python users in the world -- imagine what we could do with just $10 from each! Also new since my previous email: Credit card donations are now (finally) working properly. We can also still accept PayPal and mailed checks. The PSF is a registered non-profit and donations are tax-deductible in the USA. To donate, please go to: http://www.python.org/psf/donations.html I hope you will consider including the PSF in your year-end giving. In addition to funding grants, your donation will help the PSF to run PyCon annually (http://www.python.org/pycon) and to protect the intellectual property rights behind Python. Thanks very much, and Happy New Year! Stephan Deibel Chairman of the Board Python Software Foundation http://python.org/psf -- http://mail.python.org/mailman/listinfo/python-list
Wanted: New Python Success Stories
Hi, O'Reilly Associates is going to be printing volume III of the Python Success Stories series in June and I'm looking for submissions of new stories. The stories have been quite valuable for people introducing Python to new users and companies. The deadline for me to receive stories for editing is May 1st and the deadline for the final edited, approved story going to O'Reilly is June 1st. The existing stories are online here: http://pythonology.org/success There's more info about writing one here: http://pythonology.org/successguide The biggest hurdle is usually getting approval from the company to write about Python. It may require some educating about open source to get past rules against endorsing commercial products (which Python obviously isn't). If you have any questions, please let me know. Thanks, Stephan Deibel Pythonology.com -- http://mail.python.org/mailman/listinfo/python-list
ANN: Wing IDE 4.1.12 released
Hi, Wingware has released version 4.1.12 of Wing IDE, our integrated development environment designed specifically for the Python programming language. Wing IDE provides a professional quality code editor with vi, emacs, and other key bindings, auto-completion, call tips, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. For details see http://wingware.com/ This minor release includes: * Support for Python 2.6 and 2.7 running on cygwin * List SHA1 hashes on the downloads page * Show perspectives key bindings in Load Perspective sub-menu * Fix several color-related regressions * Fix extract refactoring when toplevel source is indented * Return focus to editor after refactoring operations * 6 other bug fixes and minor improvements For a complete change log see http://wingware.com/pub/wingide/4.1.12/CHANGELOG.txt Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature matrix: http://wingware.com/wingide/features More information: http://wingware.com/ Sales: http://wingware.com/store/purchase Upgrades: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at sa...@wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE Advancing Software Development www.wingware.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Behavior on non definded name in Cheetah
Paolo Pantaleo wrote: > [I hope I am posting to the right place] > > I have a cheetah template something like this: > > x is: $x > y is: $y > z is: $z > > [Actually more complicated] > > If for example $y is not defined I get an exception and the parsing > of the template stops. Is there any way to substitute $y with an emty > string and making cheeta going on with parsing? > > Thnx > PAolo > http://cheetahtemplate.org/docs/users_guide_html_multipage/language.namemapper.missing.html -- http://mail.python.org/mailman/listinfo/python-list
Re: #!/usr/bin/python or #!/usr/bin/env python?
> Always prefer to use env over a hardcoded path, because that hardcoded > path will invariably be wrong. (Yes, for those about to nitpick, it's > conceivable that env might be somewhere other than /usr/bin. However, > that is very rare and results in a no-win situations regardless of the > issue of where Python is installed.) Don't yell at me for bringing in another language, but I really like the trick, Tcl does: >#!/bin/sh ># The next line starts Tcl \ >exec tclsh "$0" "$@" This works by the somewhat weird feature of Tcl, that allows comments to be continued in the next line with "\" at the end of the comment-line. It looks unfamiliar, but has several advantages, I think. First it's really VERY unlikely, that there is no /bin/sh (while I found systems with different places for env), and you can add some other features at or before the actual call of the interpreter, i.e. finding the right or preferred version... - This way I coded a complete software-installer, that runs either as a Tcl/Tk-Script with GUI, or as bash-script, when no Tcl is available. - I really would like to have something like that for python, but I did not find a way to achieve that, yet. Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: #!/usr/bin/python or #!/usr/bin/env python?
Michał Bartoszkiewicz wrote: > #!/bin/sh > """exec" python "$0" "$@""" Wow, cool... I like that! Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: #!/usr/bin/python or #!/usr/bin/env python?
Erik Max Francis wrote: >>> #!/bin/sh >>> """exec" python "$0" "$@""" >> >> Wow, cool... I like that! > > Only someone genuinely fond of the Tcl hack could ... True, I admit, I'm a Tcl-Addict... But I really love Python too for many reasons. But I miss features and tricks in both languages that I have in the other... Interleaving the script-language with shell-scripting was one of them. So I'm a little bit happier with Python now... ;-) Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: #!/usr/bin/python or #!/usr/bin/env python?
ZeD wrote: > print "Hello, world" > $ file test.py > test.py: Bourne shell script text executable Yes, the same happens with all Tcl-Scripts. I like to see this as a bug in "file", not in the scripting... Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: #!/usr/bin/python or #!/usr/bin/env python?
Tobias Brox wrote: > This is very off-topic, Sorry for starting that... > but if it's fairly common to begin tcl-scripts > as a /bin/sh-file with "exec tcl" at one of the first lines, I think > "file" ought to be able to recognize it. > > """exec" python is clearly an obscure hack not used by many, so I > don't see why "file" should ever recognize that :-) That's what I meant. It is okay for a Python-script not to be recognized by "file" that way, it is enough that I can do it, if I need to. But file should recognize this for Tcl, because it is common there. And if it needs to work for Tcl only, one can construct a simple mechanism for "file" to check this. Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: #!/usr/bin/python or #!/usr/bin/env python?
Erik Max Francis wrote: > The problem is that there are endless ways to do that, and figuring out > all the cases makes `file` an sh interpreter, not the magic number > detector it's supposed to be. It makes it into a pattern-matcher, not an interpreter. But that it is already. But right, there are endless ways to do that, but only one or a very small subset is common. The way I cited is the way mentioned in the Tclsh-manpage, so it can be (not must, but can) as the standard-header of a Tcl-Script on Unix-like systems. Even if the construct sometimes differs a little bit, "file" should be able to identify, since the manpage of "file" says, that it is not a pure magic-number-detector. The first part explains how the magic-number-thing works and then what is done, when that fails: "If a file does not match any of the entries in the magic file, it is examined to see if it seems to be a text file. [...] Once file has determined the character set used in a text-type file, it will attempt to determine in what language the file is written. The language tests look for particular strings (cf names.h) that can appear anywhere in the first few blocks of a file. For example, the keyword .br indicates that the file is most likely a troff(1) input file, just as the keyword struct indicates a C program. These tests are less reliable than the previous two groups, so they are performed last." This is not the most reliable way, as the man-page says, but it should work: if in the first some blocks you can find a statement with a continued comment-line and the exec-trick, "file" can at least guess, that it is a Tcl-file. So this would be a valid method to detect that files type, because a troff-file is a troff file, even when there is no .br in the first few blocks, but "file" tries to identify it anyway. "file" is not meant to be to ignore troff files, just because they are sometimes hard to detect. The same applies to Tcl-files, I think. Not perfectly reliable, but worth a try, since it is, according to the Tclsh-manpage, the common header-pattern for a Tcl-script. So "file" can not be perfect and reliable in every case, but it should try to take a good guess. If you do not care about the Tcl-headers (and why should you, this is comp.lang.python... ;-), you are right with your reasoning. But if you accept, that file can not be perfect anyway and want it to be as good as possible, then it is some kind of bug or missing feature in "file" that it recognizes (or tries to) some morphing file formats but not another (which is fairly wide spread, even if Tcl is not a modern buzz-word-language these days). Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Dr. Dobb's Python-URL! - weekly Python news and links (Oct 10)
Cameron Laird wrote: > goon summarizes WSGI resources: > http://groups.google.com/group/comp.lang.python/msg/f7d67bc039748792 > THE wsgi resource at the moment is http://wsgi.org . (sorry, I've missed the original thread) Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Where is Python in the scheme of things?
Magnus Lycka wrote: ... > I'd suggest that the OP look at the Wikipedia page in Unix > Philosophy. Read about Gancarz tenets, and replace shell scripts > with Python. (Of course, Python offers more elaborate communication > than pipes.) I'd also the link to Joel Spolsky's Biculturalism > article, and read that. I fully agree with your posting. I (and I think many people) feel the same way about commandline and GUI interfaces. Commandline is the way my brain works... But what I really wanted to say: a very good reading about the different types of thinking and culture when comparing commandline and GUI and other important cultural phenomena using either the "commandline"- or the GUI-philosophy (e.g. DisneyWorld vs. "the real things") is "In the beginning was the commandline" from Neal Stephenson. Everybody, who is interested in the comparison of these different types of thinking and (how Stephenson says) cultures, find a very good essay about it in this small book. Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Tracing the execution of scripts?
"Michael B. Trausch" <"mike$#at^&nospam!%trauschus"> wrote: > Basically, is there something that will log every line of Python code > executed, in its order of execution, to a text file so that I can see > what is (or isn't) happening that I am expecting? Python itself can do this for you. A __VERY__ simple approach: |def myCallTrace (frame, event, arg): | tracefile.write('localTrace\n frame: '+str(frame)+'\n event: |'+str(event)+'\n arg: '+str(arg)+'\n') | tracefile.write(''+str(inspect.getframeinfo(frame))+'\n') | |def myTrace (frame, event, arg): | tracefile.write('globalTrace\n frame: '+str(frame)+'\n event: |'+str(event)+'\n arg: '+str(arg)+'\n') | if event == 'call': |return myCallTrace | |import inspect |import sys | |sys.settrace(myTrace) |tracefile = file('trace.txt', 'w') Insert this in you program and you get a trace of every line of Python-Code executed in the file trace.txt. You must read the documentation of the module inspect and of sys.settrace() to understand, what happens and what it means. Additionally, if it should work with threads, you must take care that every thread gets its own output file. But as a first step to get a trace of execution, this should do it. HTH, Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Searching for a module to generate GUI events
Hello I'm searching for a Python Module which is able to generate GUI events on different platforms (at least X11 and Windows, MacOSX would be nice), but without being a GUI toolkit itself. So PyTk is not a choice, because I need to use it, to control GUIs of other Programs. I want to generate Mouse events (move, click etc.) and keyboard events and inject them directly into the event-queue of the underlying window system. Does somebody know such a module or do I have to utilize platform specific tools from within Python? Regards and Thanks Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Cactching Stdout
Dennis Lee Bieber wrote: >> popen...is this what I need? How can I use them? It is very important >> for me that I could take the output in real-time. >> Thanks for the help! >> Massi > > That's going to be difficult... popen and pipes work when one > process starts another INDEPENDENT process. I'm not sure, if it fits the problem, but just a few days ago I had the problem to catch the stdout and stderr of a module to process it before writing it to the console. What I did was basically this: --- import sys import StringIO # save the original streams _stdout_ = sys.stdout _stderr_ = sys.stderr # create StringIO string buffers to replace streams sys.stdout = StringIO.StringIO() sys.stderr = StringIO.StringIO() # Now print something, this goes to the string buffers instead of console print "Hello World to stdout" sys.stderr.write("Hello World to stderr\n") # Now process the contents of the buffers... ... # ...and print them to the real console afterwards _stdout_.write(sys.stdout) _stderr_.write(sys.stderr) # Clean up the string buffers for the next IO sys.stdout.truncate(0) sys.stderr.truncate(0) --- Of course you should put all that into defs and create own write/print functions to encapsulate the whole buffering/processing/cleanup. This works great for scripting, but I'm pretty sure, that it does not work for C Libraries in Python. But I do not know, how Python handles its streams internally, so it might be worth a try. Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Searching for a module to generate GUI events
utabintarbo wrote: > http://pywinauto.pbwiki.com/ for Win32 Thanks for the hint, looks usable. But it seems, there's nothing for X11 and MacOSX. I didn't thought, that the problem would be so unusual... Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Searching for a module to generate GUI events
Paul Boddie wrote: > Searching for "Python GUI testing" on Google gave this as the first > result: Thank you very much, this looks very promissing to me. Seems to be a very usefull skill, if one is able to type the right words at the google prompt. Think, I should learn that some day... ;-) Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Secure Python
Fredrik Tolf wrote: > If this doesn't work, might there be some other way to run untrusted > code that I haven't thought of (apart from using O/S-specific stuff like > SECCOMD, of course). There was a module called rexec which tries to give you a restricted environment for executing code. But it seems, that it is not maintained anymore, because there were too much problems with it. It seems, that it is very complicated to get a restricted execution environment without losing too much of Pythons functionality. One question is, what you want to achieve. As another posting in this thread mentioned, you can't get around of denial of service attacks, even in restricted or trusted environments. So I assume, that what you want is something like a sandbox, where specific file actions (deleting files, access to specific part of the FS at all) and some other things can be restricted or forbidden. I think, this should be possible, even for some DOS-Attacks (e.g. restricting the amount of memory that can be used by the script, or the max stack size, depth of recursion limits etc.), but it is a hard job to find all places, where code can break out of your sandbox. For a full load of bad examples, simply have a look at JavaScript... For a IMHO really good implementation of the sandbox idea, have a look at the "safe interp" in Tcl. A short description (and by no mean complete) of the safe interp is to run a second and completely independent interpreter with all possibly dangerous commands completely removed and a one-way-channel to inject commands and scripts into its evaluation loop from the trusted interpreter. Depending on how much faith you have into the untrusted script, you can selectively allow additional commands in the safe interp or map common commands to other restricted or monitored versions of them, which you implemented yourself inside your trusted environment. I do not know, how complex it would be to do this in Python (since Tcl may look a little old fashioned to some people but has some unique features that helps especially with this kind of problem, such as having no keywords, which makes it possible to change the semantics of even the most basic constructs in the language from the scripting level), but I think it would be a really useful feature for Python to have a sandbox mechanism to run untrusted code. Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Secure Python
timmy <"timothy at open-networks.net"> wrote: This sub-thread starts to become a flame-war, isn't it? Calm down, both of you... No need to fight, when only some ideas for a technical question are requested. > as posted before, linux kernel limit. > > then you and your users can go as crazy as you want and you won't take > out your system. The problem with linux kernel limits are, that they won't work really good on MacOSX and Windows... OTOH the idea is the right one, but the effect can be achieved inside of Python. Since Python does byte compile the code and the interpreter evaluates each byte code token in one evaluation step. The interpreter could be extended for such usecases to count and limit the number of evaluation steps allowed for untrusted script or methods in untrusted script as well as to limit the recursion depth or memory to be allocated. All those limits are managed by the interpreter for script code and hence can be limited for untrusted code by the interpreter. This also does not really make DoS impossible (what about C extensions? - maybe restricting "import"?). - As I said before in this thread, making a sandbox really secure is a hard job, and may need some serious changes in the Python interpreter, but AFAIK from Tcl, it is possible - and would be nice to have. Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Secure Python
timmy <"timothy at open-networks.net"> wrote: >> count and limit the number of evaluation steps allowed for untrusted >> script or methods in untrusted script as well as to limit the recursion >> depth or memory to be allocated. > > idunno sounds like a lot of trouble to engineer a solution that has > already got a solution. all win NT systems have resource managment and i > imagine OS X would as well?? Sounds very likely, but does not solve the problem. With resource management on the OS level you can indeed set some important limits for untrusted scripts, but there are at least two drawbacks, which come to my mind (and maybe more, that I'm not aware of): 1. OS level can always only implement the lowest common denominator of all OS resource managements to be platform independent, which is a strong requirement, IMO. 2. If you want to exec a untrusted script from inside a trusted interpreter giving it a sandbox, then the sandbox has the same OS level restrictions as the first interpreter (except when started in a separate process, which makes communication between trusted and untrusted parts much more complicated). Also you can't have such a fine grained control over the untrusted execution environment at the OS level, e.g. limiting the recursion depth, which is a very important limit for secure interpreters. Limiting the stack on the OS level is for example no solution for this, because the byte code may behave completely different on the stack (and regarding hidden internal recursion) as what the toplevel Python code does (does anyone understand, what I'm talking about... - I think I just reached the recurion limit of my english capabilities), which means that you can't set deterministic restrictions for untrusted code in a platform independent manner at the OS level. - Managing all this in the interpreter would solve the problem, at the cost of implementing lots of resource management code. A good sandbox seems to be a real adventure with few survivors, as can be seen in the JavaScript-world. Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Secure Python
Paul Boddie wrote: >> implement the lowest common denominator of all OS resource managements to >> be platform independent, which is a strong requirement, IMO. > > I think I understand what you intend to say here: that some kind of > Python sandbox relying on operating system facilities can only depend > on facilities implemented in all of the most interesting operating > systems (which I once referred to as "the big three", accompanied by > howls of protest/derision Oberon, Plan 9 and AmigaOS...? ;-) > ). Yet just as people like to say that > choosing a language is all about "choosing the right tool for the job", > shouldn't the choice of operating system be significant as well? Yes, it should. But it isn't most times, I think. Often you have the situation to run a certain app e.g. on a OS that you can't simply exchange to your needs, for example the game server you mentioned, if this should run on an external host which is not maintained by you. Personally I would always prefer an OS independent solution, because it makes you more flexible. Some OS may be a good choice at a given time, but after you app has grown up, you may come to the decision to change the OS for some reason, but can't because you app depends on some of its specific features. Especially for apps written in a scripting language I would try to avoid that. > If > you're running a "Try Python" Web site, as some people were doing a few > months ago, isn't it important to choose the right operating system as > part of the right complete environment, instead of having the > theoretical possibility of running it on something like RISC OS, yet > having someone take your site down within seconds anyway? I don't know > whether it's the same people who like to promote "how well Python plays > with everything else" who also demand totally cross-platform solutions > ("if it doesn't work on Windows, we won't do it"), but if so, I'd be > interested in how they manage to reconcile these views. I'm afraid, we can't have a perfect world... But as I stated in another posting before, I think it is possible, to get a secure execution environment in a platform independent manner. The Tcl people did it and since I made myself already very unpopular at c.l.tcl by requesting some of Pythons goods for Tcl, I can do the same here by requesting some of Tcls good inventions for Python... ;-) > The emergence of virtualisation as a commodity technology would suggest > that sandboxing language runtimes isn't as fashionable as it was ten > years ago. Virtual environments are a good choice for some of the tasks that were done with sandboxes in the past. But I'm afraid, that they are too huge for many problems. Imagine running an instance of a virtual machine on a mobile phone, or needing to execute some hundreds of them in parallel on a game server (or CGI) which itself runs on a virtual host at your webhoster, and of course none of them should be able to kill it's neighbours, so all of them need their own VM... phiu, that would need a really big iron. So the the idea of VMs _is_ a good one for certain situations, but the need for secure execution environments inside an interpreter remains. Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Secure Python
Hendrik van Rooyen wrote: > I seem to recall previous discussion on this group about a thing called > the bastion module, > and that it was deprecated. Not sure if it has any relevance. Never heard about it, maybe it's worth a look for the OP. Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Registry of Methods via Decorators
bayerj schrieb: > I want to make a registry of methods of a class during creation. My > attempt was this > > """ classdecorators.py > > Author: Justin Bayer > Creation Date: 2006-06-22 > Copyright (c) 2006 Chess Pattern Soft, > All rights reserved. """ > > class decorated(object): > > methods = [] > > @classmethod > def collect_methods(cls, method): > cls.methods.append(method.__name__) > return method > > class dec2(decorated): > > @collect_methods > def first_func(self): > pass > > @collect_methods > def second_func(self): > pass replace '@collect_methods' with '@decorated.collect_methods' and this will do what you want. But keep in mind, that the 'methods' list in decorated will be used for all derived classes. -- http://mail.python.org/mailman/listinfo/python-list
Re: print shell output in a file
f = file('output.txt','w') print >>f, '%-30s | %-12d | %-12d |%-12d ' % (typename, size / count, count, size) f.close() > hello, > > one more question i will have! > > now i have written a little programm, which delivers me an output on the > shell! > > > here is the print command, which delivers me the following output (see > below) on the shell: > > > print '%-30s | %-12d | %-12d |%-12d ' % (typename, > size / count, > count, > size) > > > > --NAME-|Groesse(Byte)-|Anzahl|-Gesamtgroesse > (Byte)-| > > -- > ADD_REAL_N6| 4| 1|4 > AND_BOOL_N10 | 4| 1|4 > AND_BOOL_N12 | 4| 1|4 > > > > Is there a way to put this output in an file?!?! i searched about 2h for > this, but i couldn`t find an answer! > > thnks, juergen > -- http://mail.python.org/mailman/listinfo/python-list
Re: XMLLIB
Gnosis (http://gnosis.cx/download/) is able to do this if you mean something like pickling, but with an XML-like ouput. -- http://mail.python.org/mailman/listinfo/python-list
Re: Issues with Installer written in Python for Linux
[EMAIL PROTECTED] wrote: > I am undertaking writing an installer for a software package using > Python. It is exclusively for Linux. Because this is an installer and > has to run on numerous Linux distros, it is presenting some unique > challenges. I had the same problem to solve as you, and I hope, my answer is not too offtopic to you, since I wrote the solution in Tcl/Tk. I needed the installer to work in text-mode, if no X is available and with a GUI, if X can be used. The Installer works in both modes. It is not very fancy, but allows to run additional scripts after installation, shows some info and License-Agreement, Logo and so on. The "trick" was to pack all in a single script, that first runs as a shell script, checks if Tcl is available at all (for you python), the starting up Tcl, feeding it the same file as a Tcl-Script, then checking inside of Tcl, if Tk can be loaded (for you TkInter, which is the same thing) and if so, run the GUI, otherwise run in a text-mode, which I implemented using only basic shell-commands (cat, md5sum for validity-check, bzip2, but gzip would also work, and sed, the other commands are bash-builtins) so they should be on every distro. But that part possibly can better also be implemented in python or Tcl. - If you are interested, how it works and think, it would help you, tell me. You can look at the installer at www.mevislab.de -> Downloads, take one of the Linux-Installers. If you want, I can also give you the scripts, that create such a installer. They are a little bit confused written, since they had to be finished yesterday, as ever (and laying around since, annoying me, when I look at the code). But may be they help or at least inspire you, doing the same thing but better. Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to run an external program
Brant Sears wrote: > Any ideas on what I might do to troubleshoot this? As other stated out, you are using the wrong module. Try: >>> import os >>> p=os.popen('dir') >>> for l in p: ... print l ... --- OUTPUT OF DIR HERE --- >>> p.close() The return value of close is the return value of the command run. If you need to read stdout and stderr of your command or write to its stdin, use popen2, popen3, popen4 from the os-module. Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Making sure script only runs once instance at a time.
Hari Sekhon wrote: > I have written a script and I would like to ensure that the script is > never run more than once at any given time. > > What is the best way of testing and exiting if there is another version > of this script running somewhere on this machine? > > I guess what I'm asking is how to handle system processes the way I can > in shell. I am running this on linux. Although the other solution suggested seems to be more general (I have not read the code, only the info in the header), the following may be sufficient for what you want, and can be used as code inside of your script. It searches /proc/ for another process that is a script interpreted by python and has the same name as your script. So it can fail, if there is another python script running with the same name, but which is not identical to your script. OTOH it's a very short and simple test: - #!/bin/env python import os.path import linecache pid=os.getpid() script=linecache.getline(os.path.join('/proc', str(pid), 'cmdline'), 1).split('\0')[0:2] for pid in filter(lambda x: x.isdigit() and x != str(pid), os.listdir('/proc')): other=linecache.getline(os.path.join('/proc', str(pid), 'cmdline'), 1).split('\0')[0:2] if script[0] == other[0] and os.path.basename(script[-1]) == os.path.basename(other[-1]): raise "already running!" - HTH Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Secure Python
Steve Holden wrote: > Anyone with an interest in secure Python should take a look at what > Brett Cannon is doing in his postgraduate work. There have been some > discussions on the python-dev list. Can you some links to his work, the discussions or some other starting point? Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Ruby/Python/REXX as a MUCK scripting language
Tony Belding wrote: > Is this practical? I'm thinking of Ruby or Python for this, if they > can meet the requirements. Python had a sandbox module, but is was discarded because of security problems. If you want it working on MacOS, you may also have a look at Tcl, which has a long tradition on MacOS and it comes with a very good implemented and fully customizable sandbox. For a starting point, if Tcl sandbox meets your requirements, have a look here: Safe Tcl Overview: http://www.tcl.tk/software/plugin/safetcl.html Docs about the specific Tcl commands, to create safe interpreters: http://www.tcl.tk/man/tcl8.4/TclCmd/interp.htm (See in the lower third of the page at "Safe Interpreters") http://www.tcl.tk/man/tcl8.4/TclCmd/safe.htm Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding standards without control?
Soni Bergraj wrote: > editormt wrote: >> A majority of the participating organisations have coding standards... >> and a majority does not control them ;o) What is the situation at your >> location? Does this lack of control really hurt? > > """A Foolish Consistency is the Hobgoblin of Little Minds""" > > from: http://www.python.org/dev/peps/pep-0008/ > > Python makes coding standards obsolete;) No, it does not. If you have a team of, say, 50 programmers, everyone following his own mind-to-ascii-mapping, you are very soon in a situation, where code is completely unmaintainable. But Python has the advantage, that your coding standards can concentrate on the important things and skip most of the formatting rules, that are often part of other languages coding standards. To the control part: this is where Python comes in for general coding standards. Many rules of coding standards can be tested automatically and Python is a good choice for text processing and checking source code against the rules of a coding standard. I wrote a Python package for a subset of our coding standards and that is a very useful tool to check some 100k files. Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Re: What am I supposed to do with an egg?!
Sebastian 'lunar' Wiesner wrote: > Morpheus <[EMAIL PROTECTED]> wrote > >> So, what am I supposed to do here now? > > That's easy: Breed it... Since two days I'm fighting with myself not to make this joke. Thanks for relieving me... Regards Stephan -- http://mail.python.org/mailman/listinfo/python-list
Wing IDE 3.0 beta2 released
Hi, I'm happy to announce the release of Wing IDE 3.0 beta 2. It is available from http://wingware.com/wingide/beta Changes since the previous beta release include: * Stackless Python 2.4 and 2.5 are now supported * Python 2.5 for 64-bit Windows is now supported * Fixed Zope WingDBG so it will connect back to IDE * Improved auto-completion coverage for imports and end cases * Up to 10% speed-up when running in debugger * Fixed many other bugs, particularly source browser, OS commands, testing tool, and source assistant (*) In addition, we have introduced Wing IDE 101, a free scaled back version of Wing IDE designed for teaching introductory programming courses. The CHANGELOG.txt file in the installation provides additional details. The major new features introduced in Wing 3.0 are: * Multi-threaded debugger * Debug value tooltips in editor, debug probe, and interactive shell * Autocompletion in debug probe and interactive shell * Automatically updating project directories * Testing tool, currently supporting unittest derived tests (*) * OS Commands tool for executing and interacting with external commands (*) * Rewritten indentation analysis and conversion (*) * Introduction of Wing IDE 101, a free edition for beginning programmers * Available as a .deb package for Debian and Ubuntu * Support for Stackless Python * Support for 64 bit Python on Windows and Linux (*)'d items are available in Wing IDE Professional only. System requirements are Windows 2000 or later, OS X 10.3.9 or later for PPC or Intel (requires X11 Server), or a recent Linux system (either 32 or 64 bit). Compatibility Notes --- The file pattern in the Testing tab of Project Properties will need to be re-entered if the project was saved with one of the 3.0 alpha releases. Reporting Bugs -- Please report bugs using the Submit Bug Report item in the Help menu or by emailing support at wingware dot com. This is beta quality software that installs side-by-side with Wing 2.x or 1.x. We advise you to make frequent backups of your work when using any pre-release version of Wing IDE. Upgrading - To upgrade a 2.x license or purchase a new 3.x license: Upgradehttps://wingware.com/store/upgrade Purchase https://wingware.com/store/purchase Any 2.x license sold after May 2nd 2006 is free to upgrade; others cost 1/2 the normal price to upgrade. If you are not ready to upgrade, feel free to keep using a series of trial licenses. There will be no limit on the number of trials until 3.0 final is out. Thanks! The Wingware Team Wingware | Python IDE Advancing Software Development www.wingware.com -- http://mail.python.org/mailman/listinfo/python-list