Re: Separating elements from a list according to preceding element

2006-03-05 Thread Alex Martelli
Gerard Flanagan <[EMAIL PROTECTED]> wrote: ... > a = [ '+', 'tag1', '+', 'tag2', '-', 'tag3', '+', 'tag4' ] > > import itertools > > b = list(itertools.islice(a,0,8,2)) > c = list(itertools.islice(a,1,8,2)) Much as I love itertools, this specific task would be best expressed ad b = a[::2] c

Re: django and mod_python

2006-03-05 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Hi, > > I read the mod_python documentation on the Django site but I'm getting > this error: > > EnvironmentError: Could not import DJANGO_SETTINGS_MODULE > 'accesshiphop.settings' (is it on sys.path?): No module named > accesshiphop.settings > > Here's my httpd.con

Re: Argument Precedence (possible bug?)

2006-03-05 Thread Terry Reedy
"vbgunz" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello all, > > I am just learning Python and have come across something I feel might > be a bug. I feel it is more likely that there in a bug in the communication process from the manual to you, on an admittedly somewhat con

Re: Cryptographically random numbers

2006-03-05 Thread Emile van Sebille
> def cran_rand(min,max): You're shadowing built-ins here. Not a problem, but something I'd generally avoid. >if(min>max): >x=max >max=min >min=x If the args were a,b you could say: maxarg,minarg = min(a,b),max(a,b) >range=round(log(max-min)/log(256)) more

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Gerard Flanagan
James Stroud wrote: > Gerard Flanagan wrote: > > Rob Cowie wrote: > > > >>I'm having a bit of trouble with this so any help would be gratefully > >>recieved... > >> > >>After splitting up a url I have a string of the form > >>'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be >

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Gerard Flanagan
Alex Martelli wrote: > Gerard Flanagan <[EMAIL PROTECTED]> wrote: > ... > > a = [ '+', 'tag1', '+', 'tag2', '-', 'tag3', '+', 'tag4' ] > > > > import itertools > > > > b = list(itertools.islice(a,0,8,2)) > > c = list(itertools.islice(a,1,8,2)) > > Much as I love itertools, this specific task wo

Re: Why I chose Python over Ruby

2006-03-05 Thread Schüle Daniel
Hi Alex [...] > The trick about distinguishing a name's exact nature based on whether > the compiler sees an assignment to that name in some part of code is > found in both languages, albeit in different ways. In Ruby, as you've > pointed out, it's the heuristic used to disambiguate local variabl

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Paul McGuire
"Rob Cowie" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm having a bit of trouble with this so any help would be gratefully > recieved... > > After splitting up a url I have a string of the form > 'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be > preceeded

Adding method at runtime - problem with self

2006-03-05 Thread marek . rocki
First of all, please don't flame me immediately. I did browse archives and didn't see any solution to my problem. Assume I want to add a method to an object at runtime. Yes, to an object, not a class - because changing a class would have global effects and I want to alter a particular object only.

Re: Adding method at runtime - problem with self

2006-03-05 Thread Schüle Daniel
[EMAIL PROTECTED] wrote: > First of all, please don't flame me immediately. I did browse archives > and didn't see any solution to my problem. > > Assume I want to add a method to an object at runtime. Yes, to an > object, not a class - because changing a class would have global > effects and I wa

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Bruno Desthuilliers
Gerard Flanagan a écrit : > Alex Martelli wrote: > >>Gerard Flanagan <[EMAIL PROTECTED]> wrote: >>... >> >>>a = [ '+', 'tag1', '+', 'tag2', '-', 'tag3', '+', 'tag4' ] >>> >>>import itertools >>> >>>b = list(itertools.islice(a,0,8,2)) >>>c = list(itertools.islice(a,1,8,2)) >> >>Much as I love i

Re: Why I chose Python over Ruby

2006-03-05 Thread Marcin Mielżyński
Francois wrote: > I discovered Python a few months ago and soon decided to invest time in > learning it well. While surfing the net for Python, I also saw the hype > over Ruby and tried to find out more about it, before I definitely > embarked on studying and practicing Python. I recently found two

Opening files without closing them

2006-03-05 Thread Sandra-24
I was reading over some python code recently, and I saw something like this: contents = open(file).read() And of course you can also do: open(file, "w").write(obj) Why do they no close the files? Is this sloppy programming or is the file automatically closed when the reference is destroyed (aft

Re: Opening files without closing them

2006-03-05 Thread Marcin Mielżyński
Sandra-24 wrote: > I was reading over some python code recently, and I saw something like > this: > > contents = open(file).read() > > And of course you can also do: > > open(file, "w").write(obj) > > Why do they no close the files? Is this sloppy programming or is the > file automatically clos

Re: Opening files without closing them

2006-03-05 Thread Robert Kern
Sandra-24 wrote: > I was reading over some python code recently, and I saw something like > this: > > contents = open(file).read() > > And of course you can also do: > > open(file, "w").write(obj) > > Why do they no close the files? Is this sloppy programming or is the > file automatically clos

Re: Adding method at runtime - problem with self

2006-03-05 Thread Jay Parlar
On Mar 5, 2006, at 2:30 PM, Marek wrote: > Assume I want to add a method to an object at runtime. Yes, to an > object, not a class - because changing a class would have global > effects and I want to alter a particular object only. The following > approach fails: > > class kla: > x = 1 > > de

Re: Opening files without closing them

2006-03-05 Thread Marcin Mielżyński
Marcin Mielżyński wrote: > Sandra-24 wrote: >> I was reading over some python code recently, and I saw something like >> this: >> >> contents = open(file).read() >> >> And of course you can also do: >> >> open(file, "w").write(obj) >> >> Why do they no close the files? Is this sloppy programming or

Re: The old round off problem?

2006-03-05 Thread David Treadwell
On Mar 5, 2006, at 1:01 AM, sam wrote:David Treadwell wrote: exp(x) is implemented by:1.  reducing x into the range |r| <=  0.5 * ln(2), such that x = k *ln(2) + r2.  approximating exp(r) with a fifth-order polynomial,3.  re-scaling by multiplying by 2^k: exp(x) = 2^k * exp(r)sinh(x) is mathematica

Re: Write a GUI for a python script?

2006-03-05 Thread Bill Maxwell
On Sat, 4 Mar 2006 13:08:35 -0500, "Peter Decker" <[EMAIL PROTECTED]> wrote: >On 3/4/06, Bill Maxwell <[EMAIL PROTECTED]> wrote: > >> Dabo does look really nice, but seems like it has a ways to go yet. >> >> I downloaded it a couple of weeks ago, and the very first thing I wanted >> to do doesn't

Re: Opening files without closing them

2006-03-05 Thread Bruno Desthuilliers
Sandra-24 a écrit : > I was reading over some python code recently, and I saw something like > this: > > contents = open(file).read() > > And of course you can also do: > > open(file, "w").write(obj) > > Why do they no close the files? Is this sloppy programming or is the > file automatically c

Re: Package organization: where to put 'common' modules?

2006-03-05 Thread fortepianissimo
Hm this doesn't work. Say I have the following directory structure: A |--- util ||--- foo.py | |--- B |--- bar.py And bar.py has this line from util import foo I then run python B/bar.py in directory A. Still got error ImportError: No module named util A check of sys.path in bar

Re: Python advocacy in scientific computation

2006-03-05 Thread sturlamolden
Dennis Lee Bieber wrote: > > 1. Can python do "pass by reference"? Are datastructures represented by > > references as in Java (I don't know yet). > > > Everything in Python is a reference to an object. I think the > question you want is more on the lines of: Can I change an object that > ha

Re: Cryptographically random numbers

2006-03-05 Thread Tuvas
Good idea about the max and min values. Yes, urandom is os.urandom. s2num('blah') will convert the phrase blah to ascii, and treat them as if they were a big function. Anyone else whose still interested, I found another small bug, but it was in the modular (Again). It won't do much, but... I did

Re: Separating elements from a list according to preceding element

2006-03-05 Thread Michael Spencer
Rob Cowie wrote: > I'm having a bit of trouble with this so any help would be gratefully > recieved... > > After splitting up a url I have a string of the form > 'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag will only be > preceeded by an operator if it is a '-', if it is preceded by n

Re: Python advocacy in scientific computation

2006-03-05 Thread Evan Monroig
> First there are a few things I don't like: Hi, I will respond to things that others haven't responded yet > 2. How good is matplotlib/pylab? I tried to install it but only get > error messages so I haven't tested it. But plotting capabilities is > really major issue. I don't know because I hav

Re: Adding method at runtime - problem with self

2006-03-05 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > First of all, please don't flame me immediately. Granted - we'll do it later then !-) > I did browse archives > and didn't see any solution to my problem. > > Assume I want to add a method to an object at runtime. Yes, to an > object, not a class - because changing

Re: Package organization: where to put 'common' modules?

2006-03-05 Thread Kent Johnson
fortepianissimo wrote: > Hm this doesn't work. Say I have the following directory structure: > A > |--- util > ||--- foo.py > | > |--- B > |--- bar.py > > And bar.py has this line > > from util import foo > > I then run > > python B/bar.py > > in directory A. Still got er

Re: Opening files without closing them

2006-03-05 Thread Erik Max Francis
Robert Kern wrote: >> I usually use: >> >> try: >> f = open(file) >> contents = f.read() >> finally: >> f.close() >> >> But now I am wondering if that is the same thing. Which method would >> you rather use? Why? > > Just keep doing what you are doing, please. Note quite. The assignment

Re: Opening files without closing them

2006-03-05 Thread Robert Kern
Erik Max Francis wrote: > Robert Kern wrote: > >>>I usually use: >>> >>>try: >>> f = open(file) >>> contents = f.read() >>>finally: >>> f.close() >>> >>>But now I am wondering if that is the same thing. Which method would >>>you rather use? Why? >> >>Just keep doing what you are doing, please.

Re: Why I chose Python over Ruby

2006-03-05 Thread Xavier Morel
I'll just play the devil's advocate here Francois wrote: > 1) In Ruby there is a risk of "Variable/Method Ambiguity" when calling > a method with no parameters without using () : > Yes, but that's in my opinion a programmer error, not necessarily a language error. > 2) Ruby does not have true f

Re: Why I chose Python over Ruby

2006-03-05 Thread Terry Reedy
"Schüle Daniel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> block (Python forbids the rebinding of variables coming from an >> enclosing but non-global scope, to avoid facing this issue). > > I am not sure what you mean here > can you elaborate on this please > > >>> def a(): >

Re: Write a GUI for a python script?

2006-03-05 Thread Peter Decker
On 3/5/06, Bill Maxwell <[EMAIL PROTECTED]> wrote: > Thanks for the info. Knowing that, I was able to create a simple app in > the Dabo Designer that contains a Notebook. > > But, I'm having a heck of a time finding any documentation at all on > Dabo. I looked all thru the website(s), and have c

Re: Package organization: where to put 'common' modules?

2006-03-05 Thread Paul Boddie
fortepianissimo wrote: > Hm this doesn't work. Say I have the following directory structure: > > A > |--- util > ||--- foo.py > | > |--- B > |--- bar.py > > > And bar.py has this line > > from util import foo This would only work with A in sys.path/PYTHONPATH. However... > I then run > >

Re: Opening files without closing them

2006-03-05 Thread Steven Bethard
Sandra-24 wrote: > I was reading over some python code recently, and I saw something like > this: > > contents = open(file).read() > > And of course you can also do: > > open(file, "w").write(obj) > > Why do they no close the files? Is this sloppy programming or is the > file automatically clos

Re: Python advocacy in scientific computation

2006-03-05 Thread Alex Martelli
Robert Kern <[EMAIL PROTECTED]> wrote: ... > > just a toy. And as Matlab's run-time does reference counting insted of > > proper garbage collection, any datastructure more complex than arrays > > are sure to leak memory (I believe Python also suffered from this as > > some point). > > Python st

Re: Why I chose Python over Ruby

2006-03-05 Thread Roy Smith
Xavier Morel <[EMAIL PROTECTED]> wrote: > Francois wrote: > > 1) In Ruby there is a risk of "Variable/Method Ambiguity" when calling > > a method with no parameters without using () : > > > Yes, but that's in my opinion a programmer error, not necessarily a > language error. In Python, you can

searching for the number of occurences of a string

2006-03-05 Thread M.N.A.Smadi
hi; say i have a text file with a string ( say '(XYZ)') and I want to find the number of line where this string has occured. What is the best way to do that? what about if that string was say a 0 with leading and trailing white spaces, would that be any different? thanks moe smadi -- http://m

Re: Package organization: where to put 'common' modules?

2006-03-05 Thread fortepianissimo
Interesting - Python seems to act differently under Windows then. Here I'm using Python 2.4 on Mac OS X. With all of the files, directories and command exactly like yours, it's still not working. One thing I noticed is that you have this 'C:\\WUTemp\\A' when you print sys.path in B/bar.py, but min

Re: searching for the number of occurences of a string

2006-03-05 Thread James Stroud
M.N.A.Smadi wrote: > hi; > say i have a text file with a string ( say '(XYZ)') and I want to find > the number of line where this string has occured. What is the best way > to do that? > > what about if that string was say a 0 with leading and trailing white > spaces, would that be any differen

Re: searching for the number of occurences of a string

2006-03-05 Thread James Stroud
M.N.A.Smadi wrote: > hi; > say i have a text file with a string ( say '(XYZ)') and I want to find > the number of line where this string has occured. What is the best way > to do that? > > what about if that string was say a 0 with leading and trailing white > spaces, would that be any differen

Re: searching for the number of occurences of a string

2006-03-05 Thread marek . rocki
> hi; > say i have a text file with a string ( say '(XYZ)') and I want to find > the number of line where this string has occured. What is the best way > to do that? I would suggest: # Read file contents lines = file('filename.txt').readlines() # Extract first line number containing 'XYZ' string

Re: Random Prime Generator/Modular Arithmetic

2006-03-05 Thread Bryan Olson
Tuvas wrote: [...] > Actually, I did another test, and realized that it was indeed a bug in > the code. Yikes. Oh well, thanks for the help in identifying it! > > An example that would be alot easier is this: > Mod(16,561).is_strong_pseudo_prime() > > True Hmmm...my M-R tester disagrees...

Re: Package organization: where to put 'common' modules?

2006-03-05 Thread fortepianissimo
Paul Boddie wrote: > fortepianissimo wrote: > > Hm this doesn't work. Say I have the following directory structure: > > > > A > > |--- util > > ||--- foo.py > > | > > |--- B > > |--- bar.py > > > > > > And bar.py has this line > > > > from util import foo > > This would only work with A in

Re: Package organization: where to put 'common' modules?

2006-03-05 Thread Kent Johnson
Paul Boddie wrote: > Yes, Python does this - it puts the directory of bar.py (B in this > case) in sys.path, but not the directory in which you're sitting when > you run the program from the shell (A in this case). This seems to be OS dependent. If I put 'print sys.path' at the start of site.py (

Re: Python advocacy in scientific computation

2006-03-05 Thread Steve Holden
sturlamolden wrote: > Robert Kern wrote: > > >>And you need to ask why Python is a better Matlab than Matlab? > > > > First there are a few things I don't like: > > 1. Intendation as a part of the syntax, really annoying. > Troll. You think this is going away because *you* don't like it? Am

Re: Question re client/server and blocking

2006-03-05 Thread Bryan Olson
Frank Millman wrote: [...] > There is a server component and a client component. All the business > logic is performed on the server. Oh, what a give-away. If the logic is in the server, then the client component should probably be the user's chosen web browser. > The client communicates with

Re: raw strings and \

2006-03-05 Thread Steve Holden
[EMAIL PROTECTED] wrote: > Hi, > > thanks for the reply. I was not aware of this in raw strings (and > frankly, don't like it... but who cares about that :-) ) > Healthy attitude! > When I needed embedded quotes in a raw string I went the triple quote > route: > > a = r'''check \' this''' > >

Re: Random Prime Generator/Modular Arithmetic

2006-03-05 Thread Tuvas
Ahh, I see, I missed doing the last step in my M-R test. Hmmm. Well, got that one fixed now, time for a new release I guess. Sigh. I do seem to be going through them rather quickly... -- http://mail.python.org/mailman/listinfo/python-list

Re: Random Prime Generator/Modular Arithmetic

2006-03-05 Thread Tuvas
Okay, now I get the correct number of 561 pseudoprimes, 5, so I can assume that it is indeed working right. Whew. Thanks for the help on that one. Now, I only wish I could change the answer to my last homework assignment... Oh well. -- http://mail.python.org/mailman/listinfo/python-list

Re: raw strings and \

2006-03-05 Thread plahey
>Alas, somebody will now quote Emerson at you, I fear;-). Let them come :-) I almost always see this (mis)quoted as: "consistency is the hobgoblin of little minds" which is not really what Emerson said. The full quote is: "A foolish consistency is the hobgoblin of little minds" I would say t

Re: Python advocacy in scientific computation

2006-03-05 Thread Michael Tobis
1) indentation: I claim that this is a trivial matter. Indentation is enforced, but if you want to end all your blocks with #end, feel free. Or write a preprocessor to go from your preferred block style to python's 2) self.something tedious to look at. Again, you can somewhat work around this i

Tix Note Book

2006-03-05 Thread anil . pundoor
hi am using Tix notebook and i have two frames in that. am adding some widgets in to both of the frames. now i want to delete all of the widgets in one of the frame. i dont want to delete the frame, but its childres. so how can i get the sub widgets within that frame. Thanks in advance Anil --

re.search

2006-03-05 Thread Rares Vernica
Hi, Isn't the following code supposed to return ('1994')? >>> re.search('(\d{4})?', '4 1994').groups() (None,) Thanks, Ray -- http://mail.python.org/mailman/listinfo/python-list

Re: re.search

2006-03-05 Thread James Stroud
Rares Vernica wrote: > Hi, > > Isn't the following code supposed to return ('1994')? > > >>> re.search('(\d{4})?', '4 1994').groups() > (None,) > > Thanks, > Ray The ? is allowing it to not match before it finds the 1994. Note: py> re.search('(\d{4})?', '1994 4').groups() ('1994',) James -

Re: re.search

2006-03-05 Thread Fredrik Lundh
Rares Vernica wrote: > Isn't the following code supposed to return ('1994')? > > >>> re.search('(\d{4})?', '4 1994').groups() > (None,) it's supposed to return the first thing that matches your pattern, which, in this case, is the empty string at the beginning of the target string. if you want

Popup menus without an associated window

2006-03-05 Thread Rich Churcher
Is there a way using any of the Python UI toolkits to generate popup menus outside the context of an application? For example, middle-clicking on the desktop shows a list of shortcuts to choose from. Pointers to source examples would be appreciated. -- Cheers, Rich. -- http://mail.python.org/m

setting PYTHONPATH

2006-03-05 Thread anushya beauty
Hi,    Anybody, please help me to set PYTHONPATH to import my modules?. Where is sy.path set?In some python groups site, to import the user modules, they explained to  create one __init__.py file in my module directory (this file should include __all__ variable, which refer to the modules

Re: Convert dictionary to HTTP POST

2006-03-05 Thread Laszlo Zsolt Nagy
>>The values of some inputs are encoded using html entities. >>How can I decode a string like "Bessy's cat" in "Bessy's cat"? >> >> > >this snippet might help: > >http://effbot.org/zone/re-sub.htm#strip-html > > Thank you, worked like a charm. :-) Laszlo -- http://mail.python.org/m

Re: Calculating md5 checksums.

2006-03-05 Thread Laszlo Zsolt Nagy
Rajesh Sathyamoorthy wrote: > I tried the script and had to get a hexdigest to get the value provided > > My test: > SimplyMEPIS-3.3.1-1.iso > checksum: 41a19060d3bb37bd596708ba77964491 > i got: 41a19060d3bb37bd596708ba77964491 > > Do people normally provide md5 checksum in a *hexadecimal string?

<    1   2