Re: deploying big python applications
AndyL wrote: Hi, let me describe how I do that today. There is standard python taken from python.org installed in a c:\python23 with at least dozen different additional python packages (e.g. SOAPpy, Twisted, wx, many smaller ones etc) included. Also python23.dll moved from c:\windows to c:\python23. This is zipped and available as over 100MB file to anyone to manually unzip on his/her PC. This is a one time step. On top of that there is 30K lines of code with over 100 .py files application laid out within a directory tree. Very specific for the domain, typical application. This again is zipped and available to anyone as much smaller file to unzip and use. This step is per software releases. There is one obvious drawback - I can not separate python from standard libraries easily. True, python releases on windows are forward incompatible with C extensions, so don't even think about that. I'm not even talking about big pure python packages that could probably break because of small subtle changes in python API between releases. So when upgrade to 2.4 comes, I need to reinstall all the packages. Yes, but how much time it will *actually* take? I bet it's 1 hour. Seriously, why don't you *time* it with a stopwatch? And then compare that time to the time needed to debug the new release. In order to address that as well as the Linux port I project following structure: -default python.org installation or one time step on Windows -set of platform dependent libraries in directory A -set of platform independent libraries in directory B -application in directory C I would suggest the same structure I described for deploying over LAN: http://groups.google.com/group/comp.lang.python/msg/2482a93eb7115cb6?hl=en; The only problem is that exemaker cannot find python relative to itself, you will have to mash exemaker, python and application launcher in one directory. So the layout is like this: app/ engine/ -- directory with your actual application app.exe -- renamed exemaker.exe app.py -- dispatching module, see below python.exe python24.dll lib -- python stdlib, etc === app.py === from engine import real_application This way file engine/real_application.py is platform independant. On Linux/Unix shell script is an equivalent of exemaker. Or C program like exemaker, but you will have to compile it for all platforms. -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
We seem to have strayed a long way from Voltaire's I do not agree with what you say, but I will defend to the death your right to say it. Not at all. My problem with Xah Lee is that he is abusing the Usenet as a personal BLOG. He has a web site to post these articles and he can certainly put up a discussion board there if he wants a vigorous discussion of his ideas. It's worse. He does not even respond to questions directly posed to him in the thread of his articles. Just imagine if every blogger on the Internet started using Usenet instead and cross-posting at that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Conversion of perl based regex to python method
Andrew Robert wrote: Wanted: perl -ple 's/([^\w\s])/sprintf(%%%2X, ord $1)/ge' somefile.txt Got: # Evaluate captured character as hex def ret_hex(ch): return chr((ord(ch) + 1) % ) Make it compile at least before posting :-) # Evaluate the value of whatever was matched def eval_match(match): return ret_hex(match.group(0)) # open file file = open(r'm:\mq\mq\scripts\testme.txt','r') # Read each line, pass any matches on line to function for line in file.readlines(): re.sub('[^\w\s]',eval_match, line) for line in file: ... without readlines() is better because it doesn't read the whole file into memory first. If you want to read data from files passed as commandline args or from stdin you can use fileinput.input(): import re import sys import fileinput def replace(match): return %%%2X % ord(match.group(0)) for line in fileinput.input(): sys.stdout.write(re.sub([^\w\s], replace, line)) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: determining available space for Float32, for instance
David Socha wrote: Robert Kern wrote: However, keeping track of the sizes of your arrays and the size of your datatypes may be a bit much to ask. Exactly. Building a duplicate mechanism for tracking this informaiton would be a sad solution. Surely Python has access to the amount of memory being used by the different data types. How can I get to that information? I meant that you shouldn't bother doing any of this manually at all. *Using* such a mechanism is going to be a sad solution much less building a duplicate one. Instead, use a persistent data store like PyTables or possibly an SQL database (but I do recommend PyTables for your use-case). For numpy arrays, I showed you how to calculate the memory footprint (modulo the bytes for the actual Python structure itself that contains the metadata, but that's tiny compared to the actual array). I think there's a more general function that tries to guess the number of bytes used, but it's not terribly reliable, and I don't recommend its use. For example, how does one measure the memory footprint of a Python list? Do you count the memory footprint of each of the items? What if the items are repeated or shared between other objects? [snip] numpy (definitely not Numeric) does have a feature called record arrays which will allow you to deal with your agents much more conveniently: http://www.scipy.org/RecordArrays Also, you will certainly want to look at using PyTables to store and access your data. With PyTables you can leave all of your data on disk and access arbitrary parts of it in a relatively clean fashion without doing the fiddly work of swapping chunks of memory from disk and back again: http://www.pytables.org/moin Do RecordArrays and PyTables work well together? Yes. Currently, PyTables uses numarray's implementation of record arrays to represent HDF5 tables (which are essentially equivalent in structure to record arrays). It can interact with numpy record arrays just fine. Eventually, PyTables will be using numpy and numpy only. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: How does a generator object refer to itself?
Why don't you use a class ? class MyGen(object): def __iter__(self): for i in range(2): yield I know who I am %s % self gen_obj = MyGen() for x in gen_obj: print x For language lawyers: strictly speaking gen_obj is not a generator object (since it is restartable) but it may work for you anyway. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to handle exceptions with try/finally
I wonder where the else goes in try..except..finally... -- http://mail.python.org/mailman/listinfo/python-list
Re: NEWB: how to convert a string to dict (dictionary)
manstey wrote: Thanks. I didn't know eval could do that. But why do many posts say they want a solution that doesn't use eval? Because it is a sledgehammer: capable of driving in nails or breaking rocks. Most times people say 'I want to use eval' they are using it to drive nails and something like 'getattr' would be more appropriate. If you have a string which could have come from an untrusted source it can be dangerous. Quite easily you can construct strings which will execute arbitrary Python code. e.g. If you are running an application on a web server and part or all of the string has come from another system (which you don't necessarily trust), then using eval could potentially do anything. Don't give people you don't know a sledgehammer to use on your code. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to change sys.path?
also se topic named 'problem(s) with import from parent dir: from ../brave.py import sir_robin ' I use this every day now: sys.path.append(../../py_scripts) best wishes, Per -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
Mitch [EMAIL PROTECTED] writes: John Bokma wrote: Mitch [EMAIL PROTECTED] wrote: John Bokma wrote: [...] You're mistaken. All you need to do is report it. After some time Xah will either walk in line with the rest of the world, or has found somewhere else to yell. As long as it's not my back garden and not around 4AM, I am ok with it. Walk in line with the rest of the world? Pah. This is no-ones back garden. Funny how people who always think they can change Usenet have no clue about what Usenet is and how it works in the first place. Who said anything about changing it? I like it just the way it is. Usenet is just that, each server participating can be thought of as being the back yard of the news master. Sure, each server has terms and conditions that apply, doesn't mean you should be able to ban people from speaking just because you don't like what they say. My point is that this isn't *your* back garden, it isn't *my* back garden. It isn't something I own, and it *IS* something I can filter and/or ignore. Someone shouting in your back garden is a whole different ball game where your desires prevail. Not here. You know what you are getting into when you sign in, and it is your responsibility to deal with those you don't agree with personally. I understand you consider his writings spam, and so can see why you have reported him. All I'm saying is that as long as the articles are remotely on topic, I believe he has a right to post his opinions here. If you have no clue about how Usenet works, first read up a bit. What a Usenet server is, a feed, and how Usenet is distributed. And then come back if you finally have something to say that you can back up. Thankfully I'm aware enough of all the above that I don't feel the need. As these are all opinions, I don't see any need to back up any of it. Personally, I think this is getting a bit out of hand. Originally, John and others suggested reporting Xah to his ISP for spamming multiple groups. There was never any suggestion I have seen (except from Xah himself) that the objective was to gag his contraversial thoughts/comments/ideas. I have no problem with him posting comments which are relevant to the group he posts to. However, I do object to anyone who has the arrogance to believe their opinions are so important they should be posted to any remotely related group they can think of. I don't agree with nearly 99% of what Xah says - he often raises a well known issue (i've not seen anything original yet), outlines it reasonably well, but then proposes solutions which strike me as being very poorly considered or narrow of thought. He also tends to look at something for a couple of days and then rubbish it with a tone of authority and experience he obviously hasn't yet obtained. However, he has just as much right to do so as anyone else and therefore, its not because of his content he should be reported - its because of his irresponsability in how he distributes it. I also seem to remember a page on his website from a couple of years back in which he admits enjoying trolling and starting flame wars - but I can't find it now, so maybe I'm mistaken. However, I suspect this is the main motivation for his posts rather than a genuine desire to solve problems he perceives. At any rate, its not like he hasn't been told his constant behavior of mass cross posting was considered bad form - he has been told many many times and just ignores it. If someone wrote up there essays and got them printed on millions of leaflets which they then dumped all over the place, would you be outraged when they were fined for littering and claim their right to free speech was being gagged? Of course not. This is the same. I think most would have no problem with Xah posting if he did it in a responsible manner. Note that normally I try to remove all the cross posted groups in replies to Xah's thread, but this time, I'm leaving them as I feel the nature of this thread warrants it. If you disagree, please don't hesitate to report me to my ISP as I'm more than willing to defend my decision. If I lose, there not an ISP I'd want to stay with anyway! Tim -- tcross (at) rapttech dot com dot au -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
Mitch wrote: Sure, each server has terms and conditions that apply, doesn't mean you should be able to ban people from speaking just because you don't like what they say. You are a silly person. BugBear -- http://mail.python.org/mailman/listinfo/python-list
Re: Scipy: vectorized function does not take scalars as arguments
I have installed numpy-0.9.6 I haven't tried 0.9.8. -- http://mail.python.org/mailman/listinfo/python-list
wincerapi
Does anyone have a copy of the wincerapi module.It appears not to be in the win32 extensions anymore, and I've googled lots but not found it available anywhere. Thanks -- Tim Williams -- http://mail.python.org/mailman/listinfo/python-list
regex in python
I'm trying to compile a perfectly valid regex, but get the error message: r = re.compile(r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*') Traceback (most recent call last): File stdin, line 1, in ? File /usr/lib/python2.3/sre.py, line 179, in compile return _compile(pattern, flags) File /usr/lib/python2.3/sre.py, line 230, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat What does this mean? I know that the regex ([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.* is valid because i'm able to use it in Regex Coach. But is Python's regex syntax different that an ordinary syntax? By the way, i'm using it to normalise strings like: London|country/uk/region/europe/geocoord/32.3244,42,1221244 to: London|country/uk/region/europe/geocoord/32.32,42,12 By using \1\2\4 as replace. I'm open for other suggestions to achieve this! -Gisle- -- http://mail.python.org/mailman/listinfo/python-list
Qrcode and python
Title: Qrcode and python Iam loooking for some information on qrcode module for python (making qrcode in python qrcode is a special kind of barcode) Or i only found japanese documentation If someone have english or french documentation i twill be nice Regards Bussiere I have some problems with this email and i dunnow if my old post ive been sent, if so excuse me -- http://mail.python.org/mailman/listinfo/python-list
Re: Modify one character in a string
mp wrote: X-No-Archive How do I go about modifying one character in a string elegantly? In other words, I want a function that will change '' to 'aaza', given the index 2 of the character in the string. Also, how do I do this when dealing with a file ; which file mode should I use and what function should I use to modify a single character once in that file mode? Thanks MP Technically you can't - strings are immutable. If you use the StringIO module then you can use a common approach between 'strings' in memory, and files, using seek and write. All the best, Keir. -- http://mail.python.org/mailman/listinfo/python-list
[no subject]
hello together !!! I would like to know if it is available the com component for wmeditor in python language? This program is called windows media file editor, lets users to create marks into a movie and belongs to installation packet of windows encoder. thank you --oOo-oOo-- Servicio de acceso ó correo electrónico vía web da Universidade de Vigo Servicio de acceso al correo electrónico vía web de la Universidad de Vigo Servicios Informáticos [ http://si.uvigo.es ] Universidade de Vigo [ http://www.uvigo.es ] URL: https://correoweb.uvigo.es -- http://mail.python.org/mailman/listinfo/python-list
Final_Call_SummerSchool2006
REGISTER NOW FOR PATTERN RECOGNITION EVENTS THIS SUMMER, 2006 Early Registration Deadline for ISSPR is 25 MAY, 2006 ___ 4TH INTERNATIONAL SUMMER SCHOOL ON PATTERN RECOGNITION (ISSPR, 2006) 23-28 JULY, UK http://www.PatternRecognitionSchool.com NEW...EXTENDED Early Bird Deadline for Registration. New Deadline 25th May 2006! and payments can be made Online CALL FOR PARTICIPATION The 4th International Summer School on Pattern Recognition will be organised at the University of Plymouth, UK (23-28 July, 2006). The school programme is listed below. Please pass on this email to your interested colleagues and students. This is a great summer school which I would recommend for everyone to attend. DEADLINE: Register BEFORE 25 MAY, 2006 through the website to get a discount on the fee. Limited seats left! Speakers at the Summer School (ISSPR'2006) Dr. Sam Roberts Mathworks, UK (Introduction to Matlab) Prof. Wojtek Krzanowski University of Exeter, UK (Multivariate Statistics: Data Description) Dr. Mike Tipping, Microsoft Research, UK (Bayesian Pattern Recognition: Principles and Practice) Prof. Chris Bishop, Microsoft Research, UK (Latent Variables, Mixture Models and EM) Dr. Richard Everson, University of Exeter, UK (Dimensionality Reduction) Dr. Peter Tino University of Birmingham, UK (Probabilistic framework for model-based topographic map formation) Prof. Chris Williams, University of Edinburgh, UK (Neural Networks and Kernel Machines) Dr. Colin Campbell, University of Bristol, UK (Support Vector Machines and Kernel Methods: An Introduction and Review) Prof. John Shawe- Taylor, University of Southampton, UK (Kernel Based Methods) Dr. Steve Gunn, University of Southampton, UK (Matlab for Support Vector Machines) Prof. Mahesan Niranjan, University of Sheffield, UK (Classifier Performance Particle Filters for Tracking and Sequential Problems) Dr. Andrew Webb Qinetiq, UK (Decision TreesData Clustering) Prof. Xin Yao, University of Birmingham, UK (A Gentle Introduction to Evolutionary Computation; ATutorial on Evolutionary Multi-objective Optimisation) Dr. Richard Deardon, University of Birmingham, UK (Sequential Decision Making; Markov Chains Monte Carlo Methods) Dr. Jeremy Wyatt, University of Birmingham, UK (An Introduction to Reinforcement Learning) Dr. Ludmila Kuncheva, University of Wales, UK (Classifier Combination) Prof. Joseph Kittler, University of Surrey, UK (Feature Selection and Extraction) Prof. Sameer Singh, Loughborough University, UK (Multiresolution Pattern Recognition) Prof. Susan Craw, Robert Gordon University, UK (Case Based Reasoning) SUPPORTED BY: Microsoft, Springer, British Computer Society, and Mathworks. ___ IEEE CVPR CONFERENCE www.CVPR.org/2006 17-22 June, 2006 Registration Deadline is now 2nd of June, 2006 ___ 18th INTERNATIONAL CONFERENCE ON PATTERN RECOGNITION www.comp.hkbu.edu.hk/~icpr06 August 20-24, 2006 Early Bird Registration: 31 May, 2006 __ Please see the event websites to get FULL information. Compiled by: Dr. Heather Mclleland -- http://mail.python.org/mailman/listinfo/python-list
access to TimesTen using python
is there any module to access TimesTen in-memory database using python? -- http://mail.python.org/mailman/listinfo/python-list
pc 2 mobile via bluetooth
hello :)could some1 help me plzzz is there a python script to connect my windows pc with my s60 mobile via bluetooth on both so i could send text files from my pc and recivee them on my phonethank u so much . . How low will we go? Check out Yahoo! Messengers low PC-to-Phone call rates.-- http://mail.python.org/mailman/listinfo/python-list
Two idle questions
I've asked these questions on idle-dev with no answer. 1. How can code tell whether it is being run from Idle's debugger? 2. How can code being run from Idle's debugger simulate a breakpoint, such as pdb.set_trace() does? Yes, pdb.set_trace() does work, but I want to enable idle's debugging console and get all of Idle's nice debugging features. Thanks. Edward P.S. I've studied Idle's debugger code for several hours and the answers are not exactly jumping out at me :-) Perhaps it would be good to create wrapper functions (no idea where) to make these tasks easier. Or maybe they already exist? EKR Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-list
a good explanation
hi my friend has written a loop like this cnt = 0 files = [a,b,c,d] while cnt len(files) : do_something(files[cnt]) i told him using for fi in files: do_something(fi) is better, because the while loop method makes another call to len..which is slower.. am i partly right? or is there a better explanation for using the for method.? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Request for comments on python distributed technologies
Carl J. Van Arsdall [EMAIL PROTECTED] (CJVA) wrote: CJVA Hey everyone, another question for the list. In particular i'm CJVA looking for comments on some of the distributed technologies CJVA supported in python. Specifically, I'm looking at XML-RPC, RPyC, CJVA CORBA, and Twisted. Although it doesn't cover exactly the technologies mentioned above the following article may be interesting for you: Python Web services developer: Messaging technologies compared http://www.ibm.com/developerworks/library/ws-pyth9/ -- Piet van Oostrum [EMAIL PROTECTED] URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: regex in python
r = re.compile(r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*') ... sre_constants.error: nothing to repeat The error gives something away (like any good error message should) You're attempting to repeat something that may not exist. In this case, it's the last question-mark. The item before it (\d*) could be empty, and thus have nothing to repeat. Simply removing the question-mark in question, making it r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*).*' has the same effect as desired (AFAIU) without the error. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Bind an instance of a base to a subclass - can this be done?
Le Jeudi 25 Mai 2006 01:10, vous avez écrit : The ratio of two durations has no meaning??? Oh, sorry, sure it has, I wanted to say it has no meaning in timedelta provided arithmetic. It's a ratio (no dimension) not a duration. In that sense the expected result should be a float, and the proposed operator will break the timedelta's arithmetic consistence. t, u, v - timedeltas t+u # valid t / u # valid t / u + v # invalid while all terms are valids It's a big design flaw and I think it's the full answer to the original question. Le Jeudi 25 Mai 2006 02:26, Robert Kern a écrit : what you want is : num_weeks = time_diff.days / 7 or num_weeks = (time_diff / 7).days Uh, no. Besides the integer division problem in your first line, keep in mind that the .days attribute does not give you the time interval measured in days. It gives you the number of *whole* days in the interval. The first method will be incorrect if time_diff is not an even multiple of 1 day. The latter will be incorrect if time_diff is not an even multiple of 7 days. In fact i was computing the exact number of whole weeks in the delta. In respect of that both expression are perfectly correct, but the second one isn't clear IMO (why this days attribute should give me the number of weeks ?). This said it's not hard to figure out the correct expression of the decimal value of weeks in deltas (discarding the microseconds which are not relevant) : num_weeks = (time_diff.days * 24* 3600 + time_diff.seconds) / (7.*24*3600) If I need to do much of these in a piece of code I would probably define some helper functions like this : def tomicroseconds(td) : return td.days * 24* 3600 * 10**6 + td.seconds * 10 ** 6 + td.microseconds def toseconds(td) : return float(tomicroseonds(td)) / 10 ** 6 tominute, tohours, todays, toweeks, etc... and use float and int / and % operators. This is an easy and clean implementation IMHO. -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 -- http://mail.python.org/mailman/listinfo/python-list
Re: regex in python
In article [EMAIL PROTECTED], gisleyt [EMAIL PROTECTED] wrote: I'm trying to compile a perfectly valid regex, but get the error message: r = re.compile(r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*') Traceback (most recent call last): File stdin, line 1, in ? File /usr/lib/python2.3/sre.py, line 179, in compile return _compile(pattern, flags) File /usr/lib/python2.3/sre.py, line 230, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat What does this mean? I know that the regex ([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.* is valid because i'm able to use it in Regex Coach. But is Python's regex syntax different that an ordinary syntax? Your problem lies right near the end: import re r = re.compile(r'(\d*)?') Traceback (most recent call last): File stdin, line 1, in ? File /usr/local/lib/python2.4/sre.py, line 180, in compile return _compile(pattern, flags) File /usr/local/lib/python2.4/sre.py, line 227, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat Since the term \d* can be matched by the empty string, what would it mean to ask for 0 or 1 copies of the empty string? How is that different from 17 copies of the empty string. So: r = re.compile(r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*).*') will be accepted. By the way, i'm using it to normalise strings like: London|country/uk/region/europe/geocoord/32.3244,42,1221244 to: London|country/uk/region/europe/geocoord/32.32,42,12 By using \1\2\4 as replace. I'm open for other suggestions to achieve this! But you're looking for a string followed by two floats and your sample input is a string, a float, an integer, a comma and another integer. If you actually mean the input is London|country/uk/region/europe/geocoord/32.3244,42.1221244 and you want to convert it to: London|country/uk/region/europe/geocoord/32.32,42.12 then the above regex will work -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why can't timedeltas be divided?
oups ididn't post it to the good thread :) Le Jeudi 25 Mai 2006 01:10, vous avez écrit : The ratio of two durations has no meaning??? Oh, sorry, sure it has, I wanted to say it has no meaning in timedelta provided arithmetic. It's a ratio (no dimension) not a duration. In that sense the expected result should be a float, and the proposed operator will break the timedelta's arithmetic consistence. t, u, v - timedeltas t+u # valid t / u # valid t / u + v # invalid while all terms are valids It's a big design flaw and I think it's the full answer to the original question. Le Jeudi 25 Mai 2006 02:26, Robert Kern a écrit : what you want is : num_weeks = time_diff.days / 7 or num_weeks = (time_diff / 7).days Uh, no. Besides the integer division problem in your first line, keep in mind that the .days attribute does not give you the time interval measured in days. It gives you the number of *whole* days in the interval. The first method will be incorrect if time_diff is not an even multiple of 1 day. The latter will be incorrect if time_diff is not an even multiple of 7 days. In fact i was computing the exact number of whole weeks in the delta. In respect of that both expression are perfectly correct, but the second one isn't clear IMO (why this days attribute should give me the number of weeks ?). This said it's not hard to figure out the correct expression of the decimal value of weeks in deltas (discarding the microseconds which are not relevant) : num_weeks = (time_diff.days * 24* 3600 + time_diff.seconds) / (7.*24*3600) If I need to do much of these in a piece of code I would probably define some helper functions like this : def tomicroseconds(td) : return td.days * 24* 3600 * 10**6 + td.seconds * 10 ** 6 + td.microseconds def toseconds(td) : return float(tomicroseonds(td)) / 10 ** 6 tominute, tohours, todays, toweeks, etc... and use float and int / and % operators. This is an easy and clean implementation IMHO. -- _ Maric Michaud _ Aristote - www.aristote.info 3 place des tapis 69004 Lyon Tel: +33 426 880 097 -- http://mail.python.org/mailman/listinfo/python-list
RE: how to change sys.path?
Is there something like a .pythoninitrc which can run whenever we start Python that can load a file with many sys.path.append(), etc? If not is there some way to modify the Python shell constructor and destructor? Thanks in advance: Michael yanowitz -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of per9000 Sent: Thursday, May 25, 2006 4:07 AM To: python-list@python.org Subject: Re: how to change sys.path? also se topic named 'problem(s) with import from parent dir: from ../brave.py import sir_robin ' I use this every day now: sys.path.append(../../py_scripts) best wishes, Per -- http://mail.python.org/mailman/listinfo/python-list
webbrowser module bug on os x?
hi it seems to me like the webbrowser command webbrowser.open('http://www...', new=0) does not work as advertised: all the urls open in seperate windows regardless of the default browser (safari, firefox, mozilla). i do not have this problem on windows... can anyone help? thank you in advance. robin -- http://mail.python.org/mailman/listinfo/python-list
Re: regex in python
On 25/05/2006 7:58 PM, gisleyt wrote: I'm trying to compile a perfectly valid regex, but get the error message: r = re.compile(r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*') Traceback (most recent call last): File stdin, line 1, in ? File /usr/lib/python2.3/sre.py, line 179, in compile return _compile(pattern, flags) File /usr/lib/python2.3/sre.py, line 230, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat What does this mean? I know that the regex ([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.* is valid because i'm able to use it in Regex Coach. Say what??? From the Regex Coach website: (1) can be used to experiment with (Perl-compatible) regular expressions (2) PCRE (which is used by projects like Python -- once upon a time, way back in the dream-time, when the world was young, ... The problem is this little snippet near the end of your regex: re.compile(r'(\d*)?') Traceback (most recent call last): File stdin, line 1, in ? File C:\Python24\lib\sre.py, line 180, in compile return _compile(pattern, flags) File C:\Python24\lib\sre.py, line 227, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat The message is a little cryptic, should be something like a repeat operator has an operand which may match nothing. In other words, you have said X? (optional occurrence of X) *BUT* X can already match a zero-length string. X in this case is (\d*) This is a theoretically valid regex, but it's equivalent to just plain X, and leaves the reader (and the re implementors, obviously) wondering whether you (a) have made a typo (b) are a member of the re implementation quality assurance inspectorate or (c) just plain confused :-) BTW, reading your regex was making my eyes bleed, so I did this to find out which piece was the problem: import re pat0 = r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*' pat1 = r'([^\d]*)' pat2 = r'(\d{1,3}\.\d{0,2})?' pat3 =r'(\d*)' pat4 = r'(\,\d{1,3}\.\d{0,2})?' pat5 = r'(\d*)?.*' for k, pat in enumerate([pat1, pat2, pat3, pat4, pat5]): print k+1 re.compile(pat) But is Python's regex syntax different that an ordinary syntax? Python aims to lift itself above the ordinary :-) By the way, i'm using it to normalise strings like: London|country/uk/region/europe/geocoord/32.3244,42,1221244 to: London|country/uk/region/europe/geocoord/32.32,42,12 By using \1\2\4 as replace. I'm open for other suggestions to achieve this! Well, you are just about on the right track. You need to avoid the eye-bleed (by using VERBOSE patterns) and having test data that doesn't have typos in it, and more test data. You may like to roll your own test harness, in *Python*, for *Python* regexes, like the following: C:\junktype re_demo.py import re tests = [ [AA222.22333,444.44555FF, AA222.22,444.44], [foo/geocoord/32.3244,42.1221244, foo/geocoord/32.32,42.12], # what you meant [foo/geocoord/32.3244,42,1221244, foo/geocoord/32.32,42,12], # what you posted ] pat0 = r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*' patx = r ([^\d]*) # Grp 1: zero/more non-digits (\d{1,3}\.\d{0,2})?# Grp 2: 1-3 digits, a dot, 0-2 digits (optional) (\d*) # Grp 3: zero/more digits (\,\d{1,3}\.\d{0,2})? # Grp 4: like grp 2 with comma in front (optional) (\d*) # Grp 5: zero/more digits (.*) # Grp 6: any old rubbish rx = re.compile(patx, re.VERBOSE) for testin, expected in tests: print \ntestin:, testin mobj = rx.match(testin) if not mobj: print no match continue for k, grp in enumerate(mobj.groups()): print Group %d matched %r % (k+1, grp) actual = rx.sub(r\1\2\4, testin) print expected: %r; actual: %r; same: %r % (expected, actual, expected == actual) C:\junkre_demo.py testin: AA222.22333,444.44555FF Group 1 matched 'AA' Group 2 matched '222.22' Group 3 matched '333' Group 4 matched ',444.44' Group 5 matched '555' Group 6 matched 'FF' expected: 'AA222.22,444.44'; actual: 'AA222.22,444.44'; same: True testin: foo/geocoord/32.3244,42.1221244 Group 1 matched 'foo/geocoord/' Group 2 matched '32.32' Group 3 matched '44' Group 4 matched ',42.12' Group 5 matched '21244' Group 6 matched '' expected: 'foo/geocoord/32.32,42.12'; actual: 'foo/geocoord/32.32,42.12'; same: True testin: foo/geocoord/32.3244,42,1221244 Group 1 matched 'foo/geocoord/' Group 2 matched '32.32' Group 3 matched '44' Group 4 matched None Group 5 matched '' Group 6 matched ',42,1221244' Traceback (most recent call last): File C:\junk\re_demo.py, line 28, in ? actual = rx.sub(r\1\2\4, testin) File C:\Python24\lib\sre.py, line
Re: a good explanation
I guess that your version is faster, although the difference would be negligible in this small example. The for loop is probably optimized for speed under the hood (it is written in C), while the 'while' loop is performed in python, which is much slower. Much more important than the speed difference is the clarity: your version is the accepted practice in the python world, so people will understand it immediately. It also saves two lines of code. And most of all, it prevents you from making mistakes: your friend, for example, has forgotten to increase cnt, so he created an infinite loop! Bas -- http://mail.python.org/mailman/listinfo/python-list
Re: a good explanation
[EMAIL PROTECTED] schrieb: hi my friend has written a loop like this cnt = 0 files = [a,b,c,d] while cnt len(files) : do_something(files[cnt]) i told him using for fi in files: do_something(fi) is better, because the while loop method makes another call to len..which is slower.. am i partly right? or is there a better explanation for using the for method.? Several good reasons: - his loop won't terminate, as he (or you trying to copy his efforts) forgot to increment cnt - he needs additional statements state. The more you have of this, the likelier you make errors. he could for example write = len(files) - the whole loop is noisier to the eye, makes it harder to grasp what it's all about It seems that your friend comes from a language like C or JAVA (pre 1.5) where the for loop was basically what his while loop above is: one initializer, one condition test, one last statement, mostly incrementing the counter. Python's for is build around the concept of an iterable. Which lists, tuples, strings and many other things are - and thus the last, and possibly strongest reason is: its not idiomatic Python, he tries top shoehorn python into some schemes he's used from other languages. Don't do that, accept Python it's ways for a better life :) Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: a good explanation
On 25/05/2006 9:27 PM, [EMAIL PROTECTED] wrote: hi my friend has written a loop like this cnt = 0 files = [a,b,c,d] while cnt len(files) : do_something(files[cnt]) i told him using for fi in files: do_something(fi) is better, because the while loop method makes another call to len..which is slower.. am i partly right? or is there a better explanation for using the for method.? You are partially right. More reasons: (1) It's more elegant; you don't have the cnt if you don't need it, there's no extraneous evaluation of len(files). (2) You don't get the chance to omit cnt += 1, like your friend did (ROTFLMAO). Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: a good explanation
wow!...thanks for both replies..and yes you are right, he comes from a world of C and java...i have successfully brainwashed him to try out coding in python...haha. So he has written his first program in python and i have roughly toook a glance at it and saw what he did.. i pointed out his mistakes but couldn't convince him otherwise. Anyway , i am going to show him your replies.. thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
In article [EMAIL PROTECTED], Tim X [EMAIL PROTECTED] wrote: I also seem to remember a page on his website from a couple of years back in which he admits enjoying trolling and starting flame wars - but I can't find it now, so maybe I'm mistaken. http://web.archive.org/web/20050204172641/www.xahlee.org/Netiquette_dir/troll.html big -- Everything you love, everything meaningful with depth and history, all passionate authentic experiences will be appropriated, mishandled, watered down, cheapened, repackaged, marketed and sold to the people you hate. Mr Jalopy quoting Hooptyrides (on jalopyjunktown.com) -- http://mail.python.org/mailman/listinfo/python-list
Re: Bind an instance of a base to a subclass - can this be done?
In article [EMAIL PROTECTED], Diez B. Roggisch [EMAIL PROTECTED] wrote: Lou Pecora schrieb: [cut] Then do something like (I know this isn't right, I'm just trying to convey the idea of what I would like) mf=myfile() mf=open(Afile,r) Possible in some way? Thanks in advance for any clues. Nope, not in that way. But you might consider writing a proxy/wrapper for an object. That looks like this (rouch sketch from head): class FileWrapper(object): def __init__(self, f): self._f = f def __getattr__(self, name): return getattr(self._f, name) def myreadline(self): Then you do f = FileWrapper(open(name, mode)) Diez Interesting. I have to think about this to understand if it is a solution I can use. But, thank you for a very different angle on this. -- Lou Pecora (my views are my own) REMOVE THIS to email me. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to change sys.path?
Michael Yanowitz wrote: Is there something like a .pythoninitrc which can run whenever we start Python that can load a file with many sys.path.append(), etc? If not is there some way to modify the Python shell constructor and destructor? Thanks in advance: Michael yanowitz Yes, there is the user module: http://docs.python.org/lib/module-user.html which you have to explicitly import and which will look for .pythonrc.py file in user's home directory and execute it. The other option is a sitecustomize module, which should be put somewhere on the initial search path. It will be imported automatically during the interpreter initialization. See: http://docs.python.org/lib/module-site.html for details. Ziga -- http://mail.python.org/mailman/listinfo/python-list
Re: Bind an instance of a base to a subclass - can this be done?
In article [EMAIL PROTECTED], Maric Michaud [EMAIL PROTECTED] wrote: Le Mercredi 24 Mai 2006 22:04, Diez B. Roggisch a écrit : Nope, not in that way. But you might consider writing a proxy/wrapper for an object. That looks like this (rouch sketch from head): class FileWrapper(object): def init (self, f): self. f = f def getattr (self, name): return getattr(self. f, name) def myreadline(self): Why use a proxy when you can just inherit from the builtin file object ? class myFile(file) : def myreadline(self) : print 'yo' In [20]: myFile('frwiki-20060511-abstract.xml') Out[20]: open file 'frwiki-20060511-abstract.xml', mode 'r' at 0xa78cc1e4 In [21]: myFile('frwiki-20060511-abstract.xml').myreadline() yo In [22]: BINGO! This is exactly what I want. I didn't realize that I could open using file itself instead of open. I did find this in another section of Python in a Nutshell thanks to your suggestion. Thank you. And thanks to all who answered. -- Lou Pecora (my views are my own) REMOVE THIS to email me. -- http://mail.python.org/mailman/listinfo/python-list
Re: IronPython 1.0 Beta 7 Released
Can you recommend a book or a link for a person learning Python on Windows who does not yet know C# or .NET? Thanks, rick -- http://mail.python.org/mailman/listinfo/python-list
how to clear up a List in python?
I have new a list , when it hava large number of values, I wonna to delete all the values in it,how to do? And, if a list have 801 values, I want to get its values index from 300 to 400, could use list1[300:400],are right me? -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding Upper-case characters in regexps, unicode friendly.
[EMAIL PROTECTED] wrote: I'm trying to make a unicode friendly regexp to grab sentences reasonably reliably for as many unicode languages as possible, focusing on european languages first, hence it'd be useful to be able to refer to any uppercase unicode character instead of just the typical [A-Z], which doesn't include, for example É. Is there a way to do this, or do I have to stick with using the isupper method of the string class? See http://tinyurl.com/7jqgt Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use matplotlib contour()?
On 2006-05-24, Robert Kern [EMAIL PROTECTED] wrote: Yes, unfortunately, much of the documentation was written by people who were very familiar with the Matlab interfaces that these functions are emulating. Since I've never used matlab, I'm a bit clueless. For example one parameter is specied as an array. No clue as to how many dimensions or what the axis are. In another place it says the X,Y parameters specify the (x,y) coordinates of a surface. _How_ do they specify the surface? Are they just equal length lists of x and y coordinates that specify len(X) points. Or do they specify a len(X) x len(Y) grid of points? Why would my Z values be a 2D array? contour() only does contouring on gridded data. That's what I was beginning to suspect. What confused me was that if it required gridded data, I expected the input parameters to specify a grid (e.g. for a 5x7 grid, the X parameter would be a vector of 5 values, and the Y parameter would be a vector of 7 values) rather than just lie on a grid. If you want to handle scattered datapoints, you will have to do some interpolation. http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data Thanks, that looks like exactly what I need. My next step was actually going to be to use the Delaunay triangulation module to interpolate the data onto a much finer grid. So X, Y, and Z are all 2-D arrays laid out corresponding to the grid that you have sampled. I thought the contour_demo.py example was reasonably clear on this, but if you didn't get it to run, then I can see why you wouldn't have read it. I did delete some code that was attempting to label the graph, and then it ran. The examples do use gridded data, but when I changed them to non-gridded data, it seemed to run fine. Talking about this on matplotlib-users will probably get these problems fixed faster: https://lists.sourceforge.net/lists/listinfo/matplotlib-users After I got the demos to run, it became apparent that the contour functions don't do what I want anyway, so it's all moot at this point. -- Grant Edwards grante Yow! YOW!! Now I at understand advanced visi.comMICROBIOLOGY and th' new TAX REFORM laws!! -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Help] os listdir access denied when run as a service
On Thu, 25 May 2006, Thomas Thomas wrote: I am trying to access a mapped network drive folder. everything works fine normally. But when i run the application as service I am getting the error The error is on the line: for filename in os.listdir(folder):#line 25 and I have to assume that the bad call here is to os.listdir(). What's the particular input that's being sent to os.listdir() at the point of failure? As far as I can tell, the error message: Traceback (most recent call last): File docBoxApp.py, line 129, in ? File core\PollFiles.pyc, line 332, in doPoll File core\PollFiles.pyc, line 47, in createFileList File core\PollFiles.pyc, line 25, in addFolderFiles WindowsError: [Errno 5] Access is denied:'G:\\DT Hot Folder test/*.*' suggests that 'G:\\DT Hot Folder test/*.*' might be the folder being passed. If so, that could be the problem, since os.listdir takes the name of a directory: it does not take a file glob. Can you check to see what 'folder' is being passed into your program in the context of a file service? The problem may simply be bad input. We can check early on this by programming a bit defensively, mandating that on entry to addFolderFiles that 'folder' must be an existing directory: def addFolderFiles(folder, filelist=[]): assert os.path.isdir(folder) ... in which case, if we get past the assertion, we'll be able to at least know that we're getting in semi-good input. One other note: it is not recommended that we use a list as a default parameter value. That value will be shared among all calls to addFolderFiles, so we will see side effects. See the Important Warning in: http://docs.python.org/tut/node6.html#SECTION00671 -- http://mail.python.org/mailman/listinfo/python-list
tkFileDialog.Open to select a large number of files
Hi. I've noticed that when i select a large number of files ( 400) using tkFileDialog.Open i get an empty list. Does anyone knows the limits of that interface regarding the maximum number of files that can be selected, or the maximum length of the resulting list? Does anyone have any work around? thx. alex. -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
Larry Elmore wrote: No shit. Lately it seems that for every spam post of Xah's, there's at three or more by John *to all the same newsgroups* bitching about Xah's use of bandwidth. Pot, meet kettle. I'm killfiling Xah for being a useless twit and killfiling John for being a prick about it. There is a person on USENET, particularly in hr. hierarchy that posts under three different accounts. Sometimes he argues with himself, and sometimes event supports himself :-) Maybe we have the similar case here. DG -- http://mail.python.org/mailman/listinfo/python-list
regex/lambda black magic
Hi everyone, I have two test scripts, an encoder and a decoder. The encoder, listed below, works perfectly. import re,sys output = open(r'e:\pycode\out_test.txt','wb') for line in open(r'e:\pycode\sigh.txt','rb') : output.write( re.sub(r'([^\w\s])', lambda s: '%%%2X' % ord(s.group()), line)) The decoder, well, I have hopes. import re,sys output = open(r'e:\pycode\new_test.txt','wb') for line in open(r'e:\pycode\out_test.txt','rb') : output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(), 16)) % ord(s.group()), line)) The decoder generates the following traceback: Traceback (most recent call last): File E:\pycode\sample_decode_file_specials_from_hex.py, line 9, in ? output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(), 16)) % ord(s.group()), line)) File C:\Python24\lib\sre.py, line 142, in sub return _compile(pattern, 0).sub(repl, string, count) File E:\pycode\sample_decode_file_specials_from_hex.py, line 9, in lambda output.write( re.sub(r'([^\w\s])', lambda s: chr(int(s.group(), 16)) % ord(s.group()), line)) ValueError: invalid literal for int(): % Does anyone see what I am doing wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: Modify one character in a string
mp [EMAIL PROTECTED] wrote: X-No-Archive How do I go about modifying one character in a string elegantly? In other words, I want a function that will change '' to 'aaza', given the index 2 of the character in the string. Strings are immutable, so you can't change a string. The best you can do is create a new string from the old one. Something like: old = '' new = old[:2] + 'z' + old[3:] print new aaza or a few variations on that theme. Also, how do I do this when dealing with a file ; which file mode should I use and what function should I use to modify a single character once in that file mode? This is a much more complicated question, because it depends on the details of the operating system you're using. On Unix, you can seek to a specific place in a file, write a single character, seek to EOF, and you've done an in-place single character edit of the file. I don't know if that works on other OS's or not. -- http://mail.python.org/mailman/listinfo/python-list
Re: wincerapi
I know this isn't helpful at all, but now I'm curious. What's wincer? -- http://mail.python.org/mailman/listinfo/python-list
Re: wincerapi
On 25 May 2006 07:06:02 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I know this isn't helpful at all, but now I'm curious. What's wincer? Its a module which provides an interface to the win32 CE Remote API :) -- http://mail.python.org/mailman/listinfo/python-list
Re: how to clear up a List in python?
I have new a list , when it hava large number of values, I wonna to delete all the values in it,how to do? something like this will probably help. x = [1,2,3,4,5,6,7,8,9] y = x list([x.pop() for z in xrange(len(x))]) print x, y # [] [] And, if a list have 801 values, I want to get its values index from 300 to 400, could use list1[300:400],are right me? 300 will be included in your slice whereas the 400th index will be excluded. you will ultimately have 99 items in your slice. if you want values from index 300 to 400 you'll need to say [300:401]. the first index is included. the last index is excluded. good luck! -- http://mail.python.org/mailman/listinfo/python-list
Re: IronPython 1.0 Beta 7 Released
Ravi Teja wrote: Also, IronPython cannot access CPython libraries. So it cannot be used as a drop-in replacement for CPython in most non-trivial apps. Python for .NET however allows you to both use both CPython and .NET libraries. It will be able to access the standard libraries, as long as they are rewriten in a .NET language. People are doing it already, it's just a matter of time... -- http://mail.python.org/mailman/listinfo/python-list
Re: Bind an instance of a base to a subclass - can this be done?
I came up with this solution for subclassing the file object and making some easy I/O functions (much thanks to Maric Michaud for pointing me in the right direction). My goal was to make I/O of variables easy and in a form that I could easily visually examine the file (which I often need to do). The code also keeps it very clear as to what is being read in or out in a single function call. The class (inherited from file) in file ezfile.py: # File subclass from file for EZ I/O === class ezfile(file): # Write items to file -- # converts items list to string first using repr fcn. def printline(_, ls): sls=repr(ls) _.writelines(sls) # Scan line from file return items # converts scanned string to list first using eval fcn. def scanline(_,): sls=_.readline() return eval(sls) An example in a Python session: from ezfile import * # Define some variables x=2.334 i= 7 str='Some stuff here' # Open a file and output the variables to it ff=ezfile('junk','w') ff.printline([x,i,str]) ff.close() # Open the same file and read the values back in to other variables f2=ezfile('junk','r') y,j,thestr=f2.scanline() print y,j,thestr 2.334 7 Some stuff here f2.close() The file content looks like this: [2.3341, 7, 'Some stuff here'] easy to see what is saved to the file. It works! Thanks, again. Comments welcome. -- Lou Pecora (my views are my own) REMOVE THIS to email me. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to clear up a List in python?
python wrote: I have new a list , when it hava large number of values, I wonna to delete all the values in it,how to do? And, if a list have 801 values, I want to get its values index from 300 to 400, could use list1[300:400],are right me? del list1[:] del list1[:-1000] # keep max. last 1000 appended items in the list list1[:]=replace_list ... -robert -- http://mail.python.org/mailman/listinfo/python-list
Re: how to change sys.path?
Dennis Lee Bieber wrote: On Wed, 24 May 2006 17:24:08 GMT, John Salerno [EMAIL PROTECTED] declaimed the following in comp.lang.python: Dennis Lee Bieber wrote: I may have gotten slightly confused That's my job. :) Okay: You have gotten me slightly confused G Your job is to pay no attention to me and my blathering. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: how to normalize indentation sources
John Machin wrote: remove empty lines at the end of files. Also ensure the last line ends with a newline. don't those two things conflict with one another? or is the newline added after empty lines are removed? -- http://mail.python.org/mailman/listinfo/python-list
Re: regex/lambda black magic
Andrew Robert [EMAIL PROTECTED] wrote: ValueError: invalid literal for int(): % Does anyone see what I am doing wrong? Try getting rid of the lamba, it might make things clearer and it simplifies debugging. Something like(this is just a sketch): def callback(match): print match.group() return chr(int(match.group(),16)) % ord(match.group()) output.write(re.sub('r([^\w\s])', callback, line) It looks like your match.group is a '%' character: int('%', 16) Traceback (most recent call last): File pyshell#108, line 1, in ? int('%', 16) ValueError: invalid literal for int(): % max -- http://mail.python.org/mailman/listinfo/python-list
Re: how to normalize indentation sources
[John Machin, quoting reindent.py docs] remove empty lines at the end of files. Also ensure the last line ends with a newline. [John Salerno] don't those two things conflict with one another? No. This is the repr of a file with (3) empty lines at the end: a file\n\n \n \t\n reindent.py changes that to: a file\n This is the repr of a file with no newline at the end: a file reindent.py changes that to: a file\n or is the newline added after empty lines are removed? False dichotomy ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
Draen Gemic wrote: Larry Elmore wrote: No shit. Lately it seems that for every spam post of Xah's, there's at three or more by John *to all the same newsgroups* bitching about Xah's use of bandwidth. Pot, meet kettle. I'm killfiling Xah for being a useless twit and killfiling John for being a prick about it. There is a person on USENET, particularly in hr. hierarchy that posts under three different accounts. Sometimes he argues with himself, and sometimes event supports himself :-) Sounds like me. In rare moments I believe that I'm not alone on usenet but there are other people as well. I wanted to go to the doctor because I believed I had a multiple personality but than I discovered that the doctor was me too. Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: a good explanation
mik3 [EMAIL PROTECTED] wrote: So he has written his first program in python and i have roughly toook a glance at it and saw what he did.. i pointed out his mistakes but couldn't convince him otherwise. Anyway , i am going to show him your replies.. You might want to show him this too...if you happen to need cnt in the loop, this is what you write files = [a,b,c,d] for cnt, fi in enumerate(files): do_something(cnt, fi) -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: how to clear up a List in python?
del list1[:] thank you for that reply. I never thought of [:] cause to be me I thought it would immediately make a copy of the list or if anything that it would delete a copy so I never played with it. nice :) del list1[:-1000] # keep max. last 1000 appended items in the list list1[:]=replace_list very much thanks for the tips. they're great! -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to handle exceptions with try/finally
Zameer wrote: I wonder where the else goes in try..except..finally... try / except / else / finally See the PEP: http://www.python.org/dev/peps/pep-0341/ Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: how to clear up a List in python?
And, if a list have 801 values, I want to get its values index from 300 to 400, could use list1[300:400],are right me? 300 will be included in your slice whereas the 400th index will be excluded. you will ultimately have 99 items in your slice. No, he'll have 100 items in the slice... 300, 301,... 399 that's 100 items. -- damjan -- http://mail.python.org/mailman/listinfo/python-list
script vs inneractive
I am a little confused because I write most of my programs in a script editor but not all the code executes unless I run it from the inneractive shell. Am I doing something wrong? A good example is return 1 in a script returns nothing where as in the inneractive shell it will return 1 or true. -- http://mail.python.org/mailman/listinfo/python-list
Re: Telnet linebreaks
*bump* :)On 5/24/06, Patrick M. Nielsen [EMAIL PROTECTED] wrote: Oh, and, apologies for the inpythonic nature of this issue.On 5/24/06, Patrick M. Nielsen [EMAIL PROTECTED] wrote:Hey guys.I have begun playing with the Simple MUD server example from the Stackless website ( http://www.stackless.com/Members/rmtew/code/mud.py ) and it's all good so far, however, I've come to notice something that I remember from backin the days (some old mud code), but I don't remember what I did to fix it.While the MUD reads lines from Telnet clients just fine, clients such as Gmud are practically ignored, probably because Gmud doesn't send Telnet-valid data ('\x08'?).However, a MUD that is not accessible to one such client or others isn't much good, so I'd appreciatesome help in pinpointing the problem. These are the code blocks that need modification (I believe) def read(self): # TELNET ret = self.readChannel.receive() if self.echo: if ret == '\x08': self.send(ret+ ) self.send(ret) return ret def readline(self): # TELNET buf = self.readBuffer while True: if buf.find('\r\n') -1: # MUD clients that aren't using the telnet protocol i = buf.index('\r\n') # need to be able to do stuff. ret = buf[:i+2] self.readBuffer = buf[i+2:] while '\x08' in ret: i = ret.index('\x08') if i == 0: ret = ret[1:] else: ret = ret[:i-1]+ret[i+1:] return ret buf += self.read()I'm suspecting that Gmud doesn't send '\x08', since from looking at some old DIKU code,I see that the if '\n' || '\r' are there as well, but there is no check for '\x08'. If this is indeedthe cause of my problem, how would I go about doing it? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to normalize indentation sources
Tim Peters wrote: [John Machin, quoting reindent.py docs] remove empty lines at the end of files. Also ensure the last line ends with a newline. [John Salerno] don't those two things conflict with one another? No. This is the repr of a file with (3) empty lines at the end: a file\n\n \n \t\n reindent.py changes that to: a file\n This is the repr of a file with no newline at the end: a file reindent.py changes that to: a file\n or is the newline added after empty lines are removed? False dichotomy ;-) So the line below the last line of the file isn't actually considered an empty line, even though you can move the cursor to it in a text editor? If you have a file that has one line and it ends with a newline, at least in my text editor the cursor then moves down to the next line, but is this just a detail of the way the editor itself works, and nothing to do with the file? (i.e., there is really only one line in the file, not two?) -- http://mail.python.org/mailman/listinfo/python-list
Re: regex/lambda black magic
Max Erickson wrote: snip /snip Try getting rid of the lamba, it might make things clearer and it simplifies debugging. Something like(this is just a sketch): max Yeah.. trying to keep everything on one line is becoming something of a problem. To make this easier, I followed something from another poster and came up with this. import re,base64 # Evaluate captured character as hex def ret_hex(value): return base64.b16encode(value) def ret_ascii(value): return base64.b16decode(value) # Evaluate the value of whatever was matched def eval_match(match): return ret_ascii(match.group(0)) # Evaluate the value of whatever was matched # def eval_match(match): # return ret_hex(match.group(0)) out=open(r'e:\pycode\sigh.new2','wb') # Read each line, pass any matches on line to function for # line in file.readlines(): for line in open(r'e:\pycode\sigh.new','rb'): print (re.sub('[^\w\s]',eval_match, line)) The char to hex pass works but omits the leading % at the start of each hex value. ie. 22 instead of %22 The hex to char pass does not appear to work at all. No error is generated. It just appears to be ignored. -- http://mail.python.org/mailman/listinfo/python-list
Re: Web frameworks and credit cards
TrustCommerce (www.trustcommerce.com) has an easy to use Python interface (they other interfaces as well) that I've used on a large Zope project recently. -Larry Bates Ed Leafe wrote: I may have an opportunity to develop an online ordering system for a client, and will have the ability to develop using any tool I choose. Given the fact that there are more web frameworks in Python than keywords ;-) , what I need to know is any experience anyone out there has had integrating credit card processing with the various Python web frameworks. Until now, my only practical experience is with Zope 2.x, but I'm open to any and all alternatives, so long as it's Python! -- Ed Leafe -- http://leafe.com -- http://dabodev.com -- http://mail.python.org/mailman/listinfo/python-list
Re: os listdir access denied when run as a service
Thomas Thomas wrote: Hi All, I am trying to access a mapped network drive folder. everything works fine normally. But when i run the application as service I am getting the error Traceback (most recent call last): File docBoxApp.py, line 129, in ? File core\PollFiles.pyc, line 332, in doPoll File core\PollFiles.pyc, line 47, in createFileList File core\PollFiles.pyc, line 25, in addFolderFiles WindowsError: [Errno 5] Access is denied: 'G:\\DT Hot Folder test/*.*' below is my code def addFolderFiles(folder,filelist=[]): logger=ServerInterface.getErrorLogger() folder = folder.encode('ascii') #convert path to ascii for File Method for filename in os.listdir(folder):#line 25 file=os.path.join(folder,filename) logger.error(loop file :+file); if os.path.isfile(file): logger.error(is file :+file); if ((not (file.find(.tmp)=0)) and (not (file.find(~)=0))): filelist.append(file) elif os.path.isdir(file): logger.error(file is a directory :+file); addFolderFiles(file,filelist) def createFileList(files,folders,filelist=[]): logger=ServerInterface.getErrorLogger() for file in files: file = file.encode('ascii') #convert path to ascii for File Method if os.path.isfile(file): if ((not (file.find(.tmp)=0)) and (not (file.find(~)=0))): filelist.append(file) for folder in folders: logger.error(got a folder :+folder); logger.error(it was in the list :+folders.__str__()); addFolderFiles(folder,filelist) return (1,filelist) anything I can do about this.. - Thomas Thomas Remember that services run under a different context than the foreground login. You can configure services to run under a user context by editing that info in the service control panel applet under the Log On tab at the top. The default is to run the service under Local System account which probably doesn't have any mapped drives. -Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
Re: how to clear up a List in python?
No, he'll have 100 items in the slice... 300, 301,... 399 that's 100 items. you're right, sorry. [300:400] would return 100 items but the item at index 400 would not return. I suggested if he wanted it to try [300:401] as the last slice index is excluded from the return. Thanks for that :) -- http://mail.python.org/mailman/listinfo/python-list
Re: script vs inneractive
the interactive shell will immediatly show the result of an expression without you having to explicitly print the result. In all text editor, you will have to print the result if you wish to see it. -- http://mail.python.org/mailman/listinfo/python-list
Re: regex/lambda black magic
Andrew Robert [EMAIL PROTECTED] wrote: import re,base64 # Evaluate captured character as hex def ret_hex(value): return base64.b16encode(value) def ret_ascii(value): return base64.b16decode(value) Note that you can just do this: from base64 import b16encode,b16decode and use them directly, or ret_hex=base64.b16encode ret_ascii=base64.b16decode if you want different names. As far as the rest of your problem goes, I only see one pass being made, is the code you posted the code you are running? Also, is there some reason that base64.b16encode should be returning a string that starts with a '%'? All I would expect is: base64.b16decode(base64.b16encode(input))==input other than that I have no idea about the expected behavior. max -- http://mail.python.org/mailman/listinfo/python-list
Re: Modify one character in a string
mp wrote: X-No-Archive How do I go about modifying one character in a string elegantly? In other words, I want a function that will change '' to 'aaza', given the index 2 of the character in the string. Also, how do I do this when dealing with a file ; which file mode should I use and what function should I use to modify a single character once in that file mode? Thanks MP IMHO the most elegant method is something like: def switchchar(srcstring, position, character): b=list(srcstring) b[2]=character return ''.join(b) You should open file in binary 'b' mode. Use .seek() method to seek to the character you want to replace. use .write() method to write one character. -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: logging
Baurzhan Ismagulov wrote: Thanks for the idea! I think this should work for the example I sent. However, I have more than one module, and I want to log only l01. How can I do that? I don't know what your logger hierarchy looks like: you could perhaps log to child loggers of l01 (l01.XXX), or set all other loggers you use to have a CRITICAL level, or filter them using a filter which filters out everything. Regards, Vinay -- http://mail.python.org/mailman/listinfo/python-list
Re: script vs inneractive
Dennis Lee Bieber wrote: If that return 1 is the last line in the program, at the most it will be treated as a return code to the OS signaling that the program succeeded or failed. I'm not really sure how Python handles a return from main program. It's a syntax error. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: access to TimesTen using python
gunsupancar wrote: is there any module to access TimesTen in-memory database using python? I didn't find native one, but TimesTen has ODBC interface that you could use. http://www.compwisdom.com/topics/ODBC -- http://mail.python.org/mailman/listinfo/python-list
Re: Modify one character in a string
Larry Bates [EMAIL PROTECTED] writes: IMHO the most elegant method is something like: def switchchar(srcstring, position, character): b=list(srcstring) b[2]=character return ''.join(b) If the strings or large or you're doing it a lot, the array module is likely more efficient. -- http://mail.python.org/mailman/listinfo/python-list
Re: No handlers could be found for logger xxx ?
robert wrote: some packages like paramiko use the logging. I get this messages: No handlers could be found for logger xxx on stderr Why is un-initialized logging allowed to chatter at all? You could invoke logging.basicConfig with a level of CRITICAL. This will generally filter out logging messages. Un-initialized logging chatters because in development environments, it's useful to be able to spot misconfigured loggers. For production use, set logging.raiseExceptions to 0 and logging should then be quiet. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
list comprehensions put non-names into namespaces!
List comprehensions appear to store their temporary result in a variable named _[1] (or presumably _[2], _[3] etc for nested comprehensions) In other words, there are variables being put into the namespace with illegal names (names can't contain brackets). Can't someone come up with a better hack than this? How about using _1, _2, etc, or actually making _ a list of lists and using the real first, second, third elements? This is an unexpected wrench in the works for people trying to implement custom global namespaces. Illustration: class custom_namespace(dict): def __getitem__(self, i): print GET, i return dict.__getitem__(self, i) eval([x for x in range(10)], custom_namespace()) -- http://mail.python.org/mailman/listinfo/python-list
Anyone compiling Python 2.3 on an SCO OpenServer 5 box?
If anyone is successfully compiling Pyton 2.3 on an SCO OpenServer 5 box, I'd appreciate hearing from you on how you managed to do it. So far, I'm unable to get a python that doesn't coredump. -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
Dra¾en Gemiæ [EMAIL PROTECTED] wrote: There is a person on USENET, particularly in hr. hierarchy that posts under three different accounts. Sometimes he argues with himself, and sometimes event supports himself :-) Maybe we have the similar case here. Wouldn't amaze me if some of the buddies of Xah are actually Xah sitting in some Internet cafe, enjoying this troll fest, and already thinking up the next one. -- John Bokma Freelance software developer Experienced Perl programmer: http://castleamber.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: NEWB: how to convert a string to dict (dictionary)
In article [EMAIL PROTECTED], manstey [EMAIL PROTECTED] wrote: Thanks. I didn't know eval could do that. But why do many posts say they want a solution that doesn't use eval? Because it is a security risk! eval(os.system('rm -rf /')) -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ I saw `cout' being shifted Hello world times to the left and stopped right there. --Steve Gonedes -- http://mail.python.org/mailman/listinfo/python-list
Re: IronPython 1.0 Beta 7 Released
Ravi Teja wrote: Also, IronPython cannot access CPython libraries. So it cannot be used as a drop-in replacement for CPython in most non-trivial apps. Python for .NET however allows you to both use both CPython and .NET libraries. It will be able to access the standard libraries, as long as they are writen in pure python, otherwise they should be rewriten in a .NET language. People are doing it already, it's just a matter of time... -- http://mail.python.org/mailman/listinfo/python-list
sybase open client 15_0
I have compiled and installed sybase-.037 , the module to add sybase to python. However, when I try to use it I get Import error: /usr/local/lib/python2.3/site-packages/sybasect.so undefined symbol: cs_dt_info I've seen some posts on the internet with other people having this issue. But nothing they've suggested has resolved this issue. Maybe python just needs to be installed again or upgraded to support sybase Open Client. Thanks, ~DjK -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Programming Books?
In article [EMAIL PROTECTED], Rony Steelandt [EMAIL PROTECTED] wrote: 1.Python for Dummies Maruch Stef;Maruch Aahz - Hungry Minds Inc,U.S. - 408 pages - 08 2006 Possibly September if we get behind, but since Neal Norwitz is trying to accelerate the release of 2.5, that's not too likely. (This should be the first 2.5-specific book out.) 2.Programming Python Lutz Mark - O Reilly - 1256 pages - 07 2006 3.Core Python Programming Chun Wesley J - Peachpit Press - 07 2006 5.Python Essential Reference Beazley David - Sams - 03 2006 8.Python Scripting for Computational Science Langtangen Hans P. - Springer-Verlag Berlin and Heidelberg GmbH Co. K - 750 pages - 12 2005 9.WxPython in Action Rappin Noel;Dunn Robin - O Reilly USA - 12 2005 Not sure why you suggested these books, they don't appear to be aimed at beginning programmers. -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ I saw `cout' being shifted Hello world times to the left and stopped right there. --Steve Gonedes -- http://mail.python.org/mailman/listinfo/python-list
Re: sybase open client 15_0
I'm running SLES 9.3 on Tyan with 2 single core 64-bit Opteron 8 GB of memory and SWAP. OCS-15_0 sybperl-2.18 python 2.3.5 Dan [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have compiled and installed sybase-.037 , the module to add sybase to python. However, when I try to use it I get Import error: /usr/local/lib/python2.3/site-packages/sybasect.so undefined symbol: cs_dt_info I've seen some posts on the internet with other people having this issue. But nothing they've suggested has resolved this issue. Maybe python just needs to be installed again or upgraded to support sybase Open Client. Thanks, ~DjK -- http://mail.python.org/mailman/listinfo/python-list
Distutils -- specifying compiled output name
I am using distutils to comiple/install a c extension created with SWIG. However I need to be able to specify the output filename from gcc. I tried doing this with the extra_compile_args and extra_link_args by setting them equal to -o MyOutputName.so but that didn't work. Can someone show me how to specify the output name? Thanks, Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
John Bokma [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Dra¾en Gemiæ [EMAIL PROTECTED] wrote: There is a person on USENET, particularly in hr. hierarchy that posts under three different accounts. Sometimes he argues with himself, and sometimes event supports himself :-) Maybe we have the similar case here. Wouldn't amaze me if some of the buddies of Xah are actually Xah sitting in some Internet cafe, enjoying this troll fest, and already thinking up the next one. That's right, we're all Xah, you're the only other one here. After you kill Navarth, will it be nothing but gruff and deedle with a little wobbly to fill in the chinks? -- Geoff -- http://mail.python.org/mailman/listinfo/python-list
Re: regex/lambda black magic
Hi Everyone, Thanks for all of your patience on this. I finally got it to work. Here is the completed test code showing what is going on. Not cleaned up yet but it works for proof-of-concept purposes. #!/usr/bin/python import re,base64 # Evaluate captured character as hex def ret_hex(value): return '%'+base64.b16encode(value) # Evaluate the value of whatever was matched def enc_hex_match(match): return ret_hex(match.group(0)) def ret_ascii(value): return base64.b16decode(value) # Evaluate the value of whatever was matched def enc_ascii_match(match): arg=match.group() #remove the artifically inserted % sign arg=arg[1:] # decode the result return ret_ascii(arg) def file_encoder(): # Read each line, pass any matches on line to function for # line in file.readlines(): output=open(r'e:\pycode\sigh.new','wb') for line in open(r'e:\pycode\sigh.txt','rb'): output.write( (re.sub('[^\w\s]',enc_hex_match, line)) ) output.close() def file_decoder(): # Read each line, pass any matches on line to function for # line in file.readlines(): output=open(r'e:\pycode\sigh.new2','wb') for line in open(r'e:\pycode\sigh.new','rb'): output.write(re.sub('%[0-9A-F][0-9A-F]',enc_ascii_match, line)) output.close() file_encoder() file_decoder() -- http://mail.python.org/mailman/listinfo/python-list
Re: Request for comments on python distributed technologies
Piet Python Web services developer: Messaging technologies compared Piet http://www.ibm.com/developerworks/library/ws-pyth9/ Note a couple things. One, the article is four years old. You can't assume the various technologies have remained static since then. Two, the authors apparently didn't use sgmlop (at least it's not mentioned) to boost the decode performance of XML-RPC. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
Geoffrey Summerhayes [EMAIL PROTECTED] wrote: After you kill Navarth, will it be nothing but gruff and deedle with a little wobbly to fill in the chinks? Comparing Navarth with Xah is a huge insult to Jack Vance. You should be ashamed of yourself for even thinking about it, let alone write it down. -- John Bokma Freelance software developer Experienced Perl programmer: http://castleamber.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Telnet linebreaks
On 5/24/06, Patrick M. Nielsen [EMAIL PROTECTED] wrote: Hey guys. I have begun playing with the Simple MUD server example from the Stackless website ( http://www.stackless.com/Members/rmtew/code/mud.py ) and it's all good so far, however, I've come to notice something that I remember from back in the days (some old mud code), but I don't remember what I did to fix it. While the MUD reads lines from Telnet clients just fine, clients such as Gmud are practically ignored, probably because Gmud doesn't send Telnet-valid data ('\x08'?). \x08 is \b is backspace. Servers support this character so that clients that don't actually delete the previous input character when you hit backspace will work as the user expects. Gmud doesn't send it because Gmud has a GUI input area and actually deletes characters when you hit backspace. However, a MUD that is not accessible to one such client or others isn't much good, so I'd appreciate some help in pinpointing the problem. I don't think you've correctly identified the root cause of the problem. These are the code blocks that need modification (I believe) def read(self): # TELNET ret = self.readChannel.receive() if self.echo: if ret == '\x08': self.send(ret+ ) Here the server takes extra pains to actually erase the deleted character that the client sent. self.send(ret) return ret def readline(self): # TELNET buf = self.readBuffer while True: if buf.find('\r\n') -1: # MUD clients that aren't using the telnet protocol i = buf.index('\r\n') # need to be able to do stuff. ret = buf[:i+2] self.readBuffer = buf[i+2:] while '\x08' in ret: i = ret.index('\x08') if i == 0: ret = ret[1:] else: ret = ret[:i-1]+ret[i+1:] return ret And here it deletes it from the input which it is actually processing, so that a user who types wield sq\bword will wield their sword instead of being told they don't have a sq\bword to wield (which will probably be rendered as sword on their terminal, which would be pretty confusing). buf += self.read() I'm suspecting that Gmud doesn't send '\x08', since from looking at some old DIKU code, I see that the if '\n' || '\r' are there as well, but there is no check for '\x08'. If this is indeed the cause of my problem, how would I go about doing it? It sounds to me as though the cause of the problem lies elsewhere. Twisted includes a rather complete telnet implementation (as well as an SSH implementation and a VT102 implementation). You may want to take a look at it, either to use for your server, or at least to see the correct way to gather input from your clients. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: how to clear up a List in python?
vbgunz wrote: I have new a list , when it hava large number of values, I wonna to delete all the values in it,how to do? something like this will probably help. x = [1,2,3,4,5,6,7,8,9] y = x list([x.pop() for z in xrange(len(x))]) print x, y # [] [] if you don't know how to do things, you don't need to post. if you know why this is about the dumbest way to do what you're doing, and you're posted this on purpose, you really need to grow up. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: list comprehensions put non-names into namespaces!
Lonnie List comprehensions appear to store their temporary result in a Lonnie variable named _[1] (or presumably _[2], _[3] etc for Lonnie nested comprehensions) Known issue. Fixed in generator comprehensions. Dunno about plans to fix it in list comprehensions. I believe at some point in the future they may just go away or become syntactic sugar for a gen comp wrapped in a list() call. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: how to normalize indentation sources
On 26/05/2006 2:38 AM, John Salerno wrote: [snip] So the line below the last line of the file isn't actually considered an empty line, even though you can move the cursor to it in a text editor? That line doesn't exist in a file *until* you (a) type something into the editor and (b) save the revised contents back to disk. If you have a file that has one line and it ends with a newline, at least in my text editor the cursor then moves down to the next line, but is this just a detail of the way the editor itself works, and nothing to do with the file? (i.e., there is really only one line in the file, not two?) Please consider, if the answer to your question were no, how could anyone add lines to a file using such an editor. Why you don't fire up your Python and try something for yourself, like: print repr(open(my_one_line_file.txt.read())) ? -- http://mail.python.org/mailman/listinfo/python-list
Secure Pickle-like module
Hi all, I'm currently working on a secure Pickle-like module, Cerealizer, http://home.gna.org/oomadness/en/cerealizer/index.html Cerealizer has a pickle-like interface (load, dump, __getstate__, __setstate__,...), however it requires to register the class you want to cerealize, by calling cerealizer.register(YourClass). Cerealizer doesn't import other modules (contrary to pickle), and the only methods it may call are YourClass.__new__, YourClass.__getstate__ and YourClass.__setstate__ (Cerealizer keeps it own reference to these three method, so as YourCall.__setstate__ = cracked_method is harmless). Thus, as long as __new__, __getstate__ and __setstate__ are not dangerous, Cerealizer should be secure. The performance are quite good and, with Psyco, it is about as fast as cPickle. However, Cerealizer is written in less than 300 lines of pure-Python code. I would appreciate any comments, especially if there are some security gurus here :-) Jiba -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
Xah Lee wrote: I'm sorry to trouble everyone. But as you might know, due to my controversial writings and style, recently John Bokma lobbied people to complaint to my web hosting provider. After exchanging a few emails, my web hosting provider sent me a 30-day account cancellation notice last Friday. I'm probably stupid for contributing in this flame fest, but here goes. The reason that I consider Xah a troll and net abuser has little to do with cross-posting (which is still bad) or the length of his messages (he really should post them on his website and provide a summary and a link). My main problem is that he unloads his crap and then runs away. He doesn't participate in any discussion after that. This shows that he has no actual interest in discussion of the issues just in using Usenet as a form of publishing. The mention of free speech was raised. But the fact is that Usenet is not free (as in beer). We all pay for it. Your ISP has to pay for a server, the space for the messages, the bandwidth to download the messages, and the bandwidth to send them to your news reader. In reality the cost is shared among all of us. Therefore you do not have the right to do what you want with Usenet. You have a responsibility to use Usenet in a way that benefits the group as a whole (e.g. asking interesting questions that educate others). -- Dale King -- http://mail.python.org/mailman/listinfo/python-list
Re: Secure Pickle-like module
On 25 May 2006 13:22:21 -0700, [EMAIL PROTECTED] wrote: Hi all, I'm currently working on a secure Pickle-like module, Cerealizer, http://home.gna.org/oomadness/en/cerealizer/index.html Cerealizer has a pickle-like interface (load, dump, __getstate__, __setstate__,...), however it requires to register the class you want to cerealize, by calling cerealizer.register(YourClass). Cerealizer doesn't import other modules (contrary to pickle), and the only methods it may call are YourClass.__new__, YourClass.__getstate__ and YourClass.__setstate__ (Cerealizer keeps it own reference to these three method, so as YourCall.__setstate__ = cracked_method is harmless). Thus, as long as __new__, __getstate__ and __setstate__ are not dangerous, Cerealizer should be secure. The performance are quite good and, with Psyco, it is about as fast as cPickle. However, Cerealizer is written in less than 300 lines of pure-Python code. I would appreciate any comments, especially if there are some security gurus here :-) There are a couple factual inaccuracies on the site that I'd like to clear up first: Trivial benchmarks put cerealizer and banana/jelly on the same level as far as performance goes: $ python -m timeit -s 'from cereal import dumps; L = [Hello, , (w, o, r, l, d, .)]' 'dumps(L)' 1 loops, best of 3: 84.1 usec per loop $ python -m timeit -s 'from twisted.spread import banana, jelly; dumps = lambda o: banana.encode(jelly.jelly(o)); L = [Hello, , (w, o, r, l, d, .)]' 'dumps(L)' 1 loops, best of 3: 89.7 usec per loop This is with cBanana though, which has to be explicitly enabled and, of course, is written in C. So Cerealizer looks like it has the potential to do pretty well, performance-wise. Similar benchmarks show jelly/banana actually produces shorter encoded forms: len(banana.encode(jelly.jelly(( 9 len(cereal.dumps(())) 21 len(banana.encode(jelly.jelly([Hello, , (w, o, r, l, d, .)]))) 45 len(cereal.dumps([Hello, , (w, o, r, l, d, .)])) 67 I think the mistake you may have made was thinking that repr(jelly()) is the final output form, when really it's banana.encode(jelly()). You talked about _Tuple and _Dereference on the website as well. These are internal implementation details. They don't show up in the final decoded output at all: from twisted.spread import jelly output = jelly.unjelly(jelly.jelly([()] * 2)) output [(), ()] output[0] is output[1] True type(output[0]) is tuple True jelly also supports extension types, by way of setUnjellyableForClass and similar functions. As far as security goes, no obvious problems jump out at me, either from the API for from skimming the code. I think early-binding __new__, __getstate__, and __setstate__ may be going further than is necessary. If someone can find code to set attributes on classes in your process space, they can probably already do anything they want to your program and don't need to exploit security problems in your serializer. On the other hand, early-binding may lead to confusing bugs, albeit only in nasty cases where people are expecting changes they make to class objects to have an effect on every part of the system. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
Robert Boyd wrote: On 24 May 2006 08:29:57 -0700, Rune Strand [EMAIL PROTECTED] wrote: I can just declare my support. Reading Mr. Bokmas comments below [*] certainly makes my suport stronger. I sent an email in support of Xah, which I wouldn't have bothered to do had I not read the rapid-fire posts from Bokma which were abusive, insulting, and arrogant. Xah's posts often make me roll my eyes, or I skip them, but sometimes (and more so lately) they have been intriguing and foster thought-provoking replies. I'd prefer debate and discussion be fostered, rather than squelched. But what does this clueless sock-puppet know? ;) I too wrote to XL's hosting company pointing out that while he might be an irritant he wasn't particularly abusive. Bokma, on the other hand, can be. I don't like either of them much, but at least Xah Lee insults everyone while Bokma appears to resort to ad hominem attacks frequently. -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Love me, love my blog http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Problem with itertools.groupby.
What am I doing wrong here? import operator import itertools vals = [(1, 11), (2, 12), (3, 13), (4, 14), (5, 15), ... (1, 16), (2, 17), (3, 18), (4, 19), (5, 20)] for k, g in itertools.groupby(iter(vals), operator.itemgetter(0)): ... print k, [i for i in g] ... 1 [(1, 11)] 2 [(2, 12)] 3 [(3, 13)] 4 [(4, 14)] 5 [(5, 15)] 1 [(1, 16)] 2 [(2, 17)] 3 [(3, 18)] 4 [(4, 19)] 5 [(5, 20)] What I want is tuples starting with identical numbers to be grouped. I cannot figure out why this is not working. If anyone has any insights, I would appreciate it. - Alex Ross -- http://mail.python.org/mailman/listinfo/python-list
Re: regex/lambda black magic
On 26/05/2006 4:33 AM, Andrew Robert wrote: Hi Everyone, Thanks for all of your patience on this. I finally got it to work. Here is the completed test code showing what is going on. Consider doing what you should have done at the start: state what you are trying to achieve. Not very many people have the patience that Max showing ploughing through code that was both fugly and broken in order to determine what it should have been doing. What is the motivation for encoding characters like ,./;':[EMAIL PROTECTED]*()-+=[]\{}| Not cleaned up yet but it works for proof-of-concept purposes. #!/usr/bin/python import re,base64 # Evaluate captured character as hex def ret_hex(value): return '%'+base64.b16encode(value) This is IMHO rather pointless and obfuscatory, calling a function in a module when it can be done by a standard language feature. Why did you change it from the original %%%2X % value (which would have been better IMHO done as %%%02X % value)? # Evaluate the value of whatever was matched def enc_hex_match(match): return ret_hex(match.group(0)) Why a second level of function call? def ret_ascii(value): return base64.b16decode(value) See above. # Evaluate the value of whatever was matched def enc_ascii_match(match): arg=match.group() #remove the artifically inserted % sign Don't bother, just ignore it. return int(match()[1:], 16) arg=arg[1:] # decode the result return ret_ascii(arg) def file_encoder(): # Read each line, pass any matches on line to function for # line in file.readlines(): output=open(r'e:\pycode\sigh.new','wb') for line in open(r'e:\pycode\sigh.txt','rb'): output.write( (re.sub('[^\w\s]',enc_hex_match, line)) ) output.close() Why are you opening the file with rb but then reading it a line at a time? For a binary file, the whole file may be one line; it would be safer to read() blocks of say 8Kb. For a text file, the only point of the binary mode might be to avoid any sort of problem caused by OS-dependant definitions of newline i.e. CRLF vs LF. I note that as \r and \n are whitespace, you are not encoding them as %0D and %0A; is this deliberate? def file_decoder(): # Read each line, pass any matches on line to function for # line in file.readlines(): output=open(r'e:\pycode\sigh.new2','wb') for line in open(r'e:\pycode\sigh.new','rb'): output.write(re.sub('%[0-9A-F][0-9A-F]',enc_ascii_match, line)) output.close() file_encoder() file_decoder() -- http://mail.python.org/mailman/listinfo/python-list
Go help the perl list instead Fredrik Lundh
Fredrik Lundh wrote: vbgunz wrote: I have new a list , when it hava large number of values, I wonna to delete all the values in it,how to do? something like this will probably help. x = [1,2,3,4,5,6,7,8,9] y = x list([x.pop() for z in xrange(len(x))]) print x, y # [] [] if you don't know how to do things, you don't need to post. if you know why this is about the dumbest way to do what you're doing, and you're posted this on purpose, you really need to grow up. /F He already posted before your post that he made a mistake. You obviously ignored that and invented some argument that he posted with malicious intentions. That better describes most of your thousands of annoying posts. -- http://mail.python.org/mailman/listinfo/python-list