Re: Let My Terminal Go

2005-10-13 Thread Fredrik Lundh
Jorgen Grahn wrote: > > Done once, it's usually not unacceptable. > > In fact, I can't think of a scenario where it /would/ be unacceptable ;-) if you're stuck on a system that doesn't use copy-on-write ? -- http://mail.python.org/mailman/listinfo/python-list

Re: form filling XML

2005-10-13 Thread Fredrik Lundh
"George" <[EMAIL PROTECTED]> wrote: > How can I compare the text in the element tags with the elements > tags in filling and if they match replace the text within the elements > tags with the text in the matching element tag of fillin. > For example Since the text Monday in form matches the Elem

Re: 1-liner to iterate over infinite sequence of integers?

2005-10-13 Thread Fredrik Lundh
Neal Becker wrote: > I can do this with a generator: > > def integers(): > x = 1 > while (True): > yield x > x += 1 > > for i in integers(): > > Is there a more elegant/concise way? depends on your definition of "integers": xrange(sys.maxint) # 0-b

Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-13 Thread Fredrik Lundh
Rune Strand wrote: > I've read a lot of your comments the last years. Your friendliness > always strikes me. terseness != unfriendlyness -- http://mail.python.org/mailman/listinfo/python-list

Re: UI toolkits for Python

2005-10-13 Thread Fredrik Lundh
> > However, Tkinter not most people's favorite, because the widgets look > > crude, they don't resemble the native widgets of any popular platform, > > and the widget set is somewhat limited. (given that the web interface is the new black, that's not much of an argument. tkinter with the right s

Re: Setdefault bypasses __setitem__

2005-10-13 Thread Fredrik Lundh
Diez B. Roggisch wrote: > I rarely find things in python strange or named incorrectly, but this is > IMHO such a case - setdefault led me to think that using it would set a > default value to return for _future_ lookups of non-existant keys. That > semantics is known in e.g. ruby or java. > > I th

Re: ImportError: No module named dbm

2005-10-13 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > firstly i couldnt find the DBM module for python 2.3.5, trustix system and > i386 hardware platform. > so i downloaded gnu dbm for python 2.3.5 and i568( precisly, > python-gdbm-2.3.5-4tr.i586), simply assuming it could just work. > > but trying to install gives me the f

Re: Python's Performance

2005-10-14 Thread Fredrik Lundh
Paul Boddie wrote: > On the subject of other virtual machine implementations, I wonder what > happened to this one: > > http://effbot.org/zone/pytte.htm > > Fredrik? ;-) so much code, so little time... -- http://mail.python.org/mailman/listinfo/python-list

Re: getting the path in a cgi script

2005-10-14 Thread Fredrik Lundh
Kalle Anke wrote: > I know I've done this once before ... I think ... but now I can't figure out > how to do it > > I've set my web server to use an alias similar to this > >ScriptAlias /xx/ "/Library/WebServer/CGI-Executables/xxx.cgi/" > > which makes it possible for me to write > >http:/

Re: MD5 module Pythonicity

2005-10-14 Thread Fredrik Lundh
Leandro Lameiro wrote: > What's wrong in having a function like the one I said, that would > split files for you, feed md5.update and, when it is over, return the > digest? Calculating the digest sum for a file on disk, without doing anything else with that file, is a very small subset of everyth

Re: MD5 module Pythonicity

2005-10-14 Thread Fredrik Lundh
Fredrik Lundh wrote: > Forcing every digest module to add code to cater for just one of many > use cases is most likely a waste of time. here's the hash API specification, btw: http://www.python.org/peps/pep-0247.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem splitting a string

2005-10-15 Thread Fredrik Lundh
"SPE - Stani's Python Editor" wrote: > Use re.split, as this is the fastest and cleanest way. > However, iff you have to split a lot of strings, the best is: > > import re > delimiters = re.compile('_| ') > > def split(x): > return delimiters.split(x) or, shorter: import re split = re.

Re: how to improve simple python shell script (to compile list of files)

2005-10-15 Thread Fredrik Lundh
Jari Aalto wrote: > Please suggest comments how can I make this script to work > from bash. replace it with a call to the compileall module? $ python -mcompileall [directory...] ? $ python -mcompileall -h option -h not recognized usage: python compileall.py [-l] [-f] [-q] [-d d

Re: Perl-Python-a-Day: Sorting

2005-10-15 Thread Fredrik Lundh
Tim Roberts wrote: > >This entry is obsolete: it should mention the 'key' option of the > >standard sort method. > > It should mention it, but not necessarily recommend it. > > I haven't run the numbers in Python, but in Perl, the undecorated sort is > so well-optimized that the Schwartzian transf

Re: how to improve simple python shell script (to compile list offiles)

2005-10-15 Thread Fredrik Lundh
Jari Aalto wrote: > Thanks, but that will not work. The files are gathered from discrete > places really? so what is that "find" command doing in your code ? compile $(find path/to -type f -name "*.py") seems to me as if python -mcompileall path/to would do exactly what your script d

Re: Some set operators

2005-10-15 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Sometimes I suggest to add things to the language (like adding some set > methods to dicts), but I've seen that I tend to forget the meaning of > six set/frozenset operators: > > s & t s &= t > s | t s |= t > s ^ t s ^= t > > My suggestion is to remove them, and keep

Re: "Microsoft has never made a computer in its existence."

2005-10-16 Thread Fredrik Lundh
Steven D'Aprano wrote: > Microsoft has never made a computer in its existence. Not one. http://www.microsoft.com/xbox/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with creating a dict from list and range

2005-10-16 Thread Fredrik Lundh
Steve Holden wrote: > Question: what's the difference between > > dict((name, seq) for seq, name in enumerate(description)) > > (the improved version of my answer posted by Scott David Daniels) and > > dict(enumerate(description)) a missing def enumerate(x, enumerate=enumerate): # ov

Re: subtle side effect of generator/generator expression

2005-10-16 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I initially thought that generator/generator expression is cool (sort of > like the lazy evaluation in Haskell) until I notice this side effect. > > >>>a=(x for x in range(2)) > >>>list(a) > [1,2] > >>>list(a) > [] > > Would this make generator/generator expression's usa

Re: Comparing lists

2005-10-16 Thread Fredrik Lundh
Christian Stapfer wrote: > As to the value of complexity theory for creativity > in programming (even though you seem to believe that > a theoretical bent of mind can only serve to stifle > creativity), the story of the discovery of an efficient > string searching algorithm by D.E.Knuth provides a

Re: subtle side effect of generator/generator expression

2005-10-16 Thread Fredrik Lundh
Diez B. Roggisch wrote: > Files allow to seek, in addition to stream semantics. Some files. Not all files support seek operations. Some only support forward seek. -- http://mail.python.org/mailman/listinfo/python-list

Re: can a cut-down Python still be Python?

2005-10-17 Thread Fredrik Lundh
"The Eternal Squire" wrote: > Regardless of the technical difficulties involved (and I know they are > legion), I am considering developing a very limited subset of Python > fit to run on embedded systems using 80188 or 68332 microchips. My > main question regarding this is: even if I am succes

Re: graphic memory & animation

2005-10-17 Thread Fredrik Lundh
"Peres" wrote: > Slow means more than 20ms to erase the screen. After double buffering it > improved a lot , of course (16 ms) but I'll need a faster speed. are you measuring the time it takes to go from a populated screen to a blank screen? if so, you're probably seeing the screen refresh time

Re: reading hebrew text file

2005-10-17 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I have a hebrew text file, which I want to read in python > I don't know which encoding I need to use that's not a good start. but maybe it's one of these: http://sites.huji.ac.il/tex/hebtex_fontsrep.html ? > how I do that f = open(myfile) text = f.read

Re: bug in os.system?

2005-10-18 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > The following code fails (pythonbugtest.exe takes one parameter, a > string): > > import os > result = os.system('"pythonbugtest.exe" "test"') > assert(result == 0) > > The error message is: > > 'pythonbugtest.exe" "test' is not recognized as an internal or external > co

Re: Bloodhound.Exploit.49 trojan found in MIMEBase.pyc

2005-10-18 Thread Fredrik Lundh
Alex Hunsley wrote: > Symantec antivirus has apparently picked up a virus in my Python 2.4 > (under cygwin): > > Scan type: Scheduled Scan > Event: Threat Found! > Threat: Bloodhound.Exploit.49 > File: C:\cygwin\lib\python2.4\email\MIMEBase.pyc > Location: Quarantine > Action taken: Quarantin

Re: Tkinter or Python issue?

2005-10-19 Thread Fredrik Lundh
Eugene Druker wrote: > tkFont.Font(...) is a class instance, while you need font description. Font instances are font descriptors. >>> f = tkFont.Font(family="ariel", size=24, weight=tkFont.BOLD) >>> f >>> print f font10726496 > t.tag.config( 'TBU', font=('times', 12, 'bold

Re: "dynamical" importing

2005-10-19 Thread Fredrik Lundh
Joerg Schuster wrote: > I need to import modules from user defined paths. I.e. I want to do > something like: > > module_dir = sys.argv[1] > > my_path = os.path.join(module_dir, 'bin', 'my_module') > > from my_path import my_object > > Obviously, it doesn't work this way. How would it work? some

Re: "dynamical" importing

2005-10-19 Thread Fredrik Lundh
John Abel wrote: > def _importModule( moduleName ): > modName = __import__ ( moduleName ) > modComponents = moduleName.split( '.' ) > for indivComp in modComponents[ 1: ]: > modName = getattr( modName, indivComp ) > >return modName __import__ takes a module name, not an ar

Re: Converting 2bit hex representation to integer ?

2005-10-19 Thread Fredrik Lundh
Madhusudan Singh wrote: >> Can you give us an example. I don't know what two bit >> hex means (takes at least 4 bits to make a hex digit). > > Like 64(base 16)=100. > I am referring to 64 in the above. that's two digits, not two bits. >>> print int("64", 16) 100 >> Now I'm going to try

Re: Python variables are bound to types when used?

2005-10-19 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > So I want to define a method that takes a "boolean" in a module, eg. > > def getDBName(l2): > ... > > Now, in Python variables are bound to types when used, right? no. variables are bound to objects, and objects have types. > Eg. > x = 10 # makes it an INT no. that

Re: Extention Module/ list of chars-> string

2005-10-19 Thread Fredrik Lundh
"Tuvas" wrote: > I am currently writing an extention module that needs to recieve a list > of characters that might vary in size from 0 to 8. This is written as a > list of characters rather than a string because it's easier to > manipulate. However, when I pass this list of characters into the >

Re: Extention Woes

2005-10-19 Thread Fredrik Lundh
"Tuvas" wrote: > I am in the process of writing an extention module, and am coming up > with lots of problems. Perhaps someone could be of use. I keep getting > data that isn't what I'm sending the program. Let me give the line of C > code and Python Code and output to illistrate the problem. > >

Re: Yes, this is a python question, and a serious one at that (moving to Win XP)

2005-10-19 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Try 4NT (http://www.jpsoft.com). It is like cmd on steroids. I've > been using it for years and it is the *only* thing that makes powerful > batch files possible on Windows. why bother with "powerful batch files" when you can use a real programming language ? --

Re: Abstract Methods & Abstract Class

2005-10-20 Thread Fredrik Lundh
Andreas Kostyrka wrote: > > Do we have something like abstract methods & Abstract class. > > > > So that my class would just define the method. And the implementation > > would be defined by somebody else. > > class AbstractBase: > def method(self): > raise TypeError("abstract method c

Re: Extention Woes

2005-10-20 Thread Fredrik Lundh
"Tuvas" wrote: > Well, the point of declaring it as a char was to have it as an 8 bit > integer, as is requested later on in the program. since ParseTuple writes an integer to the address you pass in, that's likely to overwrite some random stuff on the stack. like- wise, passing in a character b

Re: best way to replace first word in string?

2005-10-20 Thread Fredrik Lundh
Micah Elliott wrote: > And the regex is comparatively slow, though I'm not confident this one > is optimally written: > > $ python -mtimeit -s'import re' ' > re.sub(r"^(\w*)", r"/\1/", "a b c")' > 1 loops, best of 3: 44.1 usec per loop the above has to look the pattern up in the

Re: reload fails if module not in sys.path

2005-10-20 Thread Fredrik Lundh
Lonnie Princehouse wrote: > Maybe it could fall back to module.__file__ if the module isn't found > in sys.path?? > ... or reload could just take an optional path parameter... > > Or perhaps I'm the only one who thinks this is silly: > > >>> my_module = imp.load_module(module_name, > >>> *imp.fin

Re: a simple question about the third index in slice

2005-10-20 Thread Fredrik Lundh
someone wrote: > I cannot quite understand when the third index is a negative > number,like this: > a = '0123456789' > a[1:10:2] I know the index step is 2, so it will collect items from > offset 1, 3, 5, 7, 9 > but when a negative number come,like: > a[1::-1] answer '10', and a[1:10:-1] only answ

Re: get a copy of a string leaving original intact

2005-10-21 Thread Fredrik Lundh
"Bell, Kevin" wrote: > I'm having trouble with something that seems like it should be simple. > > I need to copy a file, say "abc-1.tif" to another directory, but if it's > in there already, I need to transfer it named "abc-2.tif" but I'm going > about it all wrong. > > Here's what doesn't work: (

Re: Execute C code through Python

2005-10-21 Thread Fredrik Lundh
"Ernesto" wrote: > Thanks. Can anyone provide an example of using *subprocess* to run > helloWorld.C through the python interpreter. compile helloWorld, and run: import subprocess subprocess.call("helloWorld") (any special reason why you couldn't figure this out yourself, given the exa

Re: Compile C program -> .pyc file

2005-10-21 Thread Fredrik Lundh
"Ernesto" wrote: > Is there a way to compile a C program into a .pyc file that has the > same behavior as the compiled C program? unless you find a C->Python compiler, no. PYC files contain Python bytecode, C compilers usually generate native code for a given machine platform. -- http://m

Re: Compile C program -> .pyc file

2005-10-21 Thread Fredrik Lundh
Steve Holden wrote: > Here's a start: > > http://codespeak.net/pipermail/pypy-dev/2003q1/000198.html if anyone could turn ideas that only exist in Christian's brain into working systems, the world would look a lot different. -- http://mail.python.org/mailman/listinfo/python-list

Re: get a copy of a string leaving original intact

2005-10-22 Thread Fredrik Lundh
"Bell, Kevin" wrote: > I ended up slicing my string into a new one, rather than trying to have > a copy of the string to alter in one case, or leave intact in another > case. given that you cannot modify strings in place in Python, that comment probably doesn't match what your code really did...

Re: access dictionary with preferred order ?

2005-10-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I am wondering if there is a dictionary data type that allows me to > define the order of access when iterating it using items/keys etc. ? > > An example: > > a=dict(a=dict(), c=dict(), h=dict()) > prefer=['e','h', 'a'] > > for x in a.values: print x > > would give me >

Re: Help with language, dev tool selection

2005-10-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I have a flat text file, 3 records, each record has two columns, > the columns are tab separated. > > The file looks like this (approximately) > > Sarajevo 431104-133111 (when did they move sarajevo to italy?) > Mostar 441242-133421 > Zagreb 432322-134423 here's a

Re: Python variables are bound to types when used?

2005-10-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > > reset your brain: > > > > http://effbot.org/zone/python-objects.htm > > Neat link. > > Can you expand on this: > > > a type (returned by type(x)) > ... > > You cannot change the type. the page was written before the "type/class unification" in Python 2.2, at a tim

Re: find() method in ElementTree

2005-10-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > My questions: > 1) in the example above is there a subelement of doc with a tag > 'SampleDetails'? find only searches for direct subelements; SampleDetail is not a direct subelement to SampleRoot, since there's a SpecificInformation element in between. > 2) if so, what

Re: Syntax across languages

2005-10-23 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > - Information about the current line and file as Ruby: > __LINE__ __FILE__ > Instead of the python version: > inspect.stack()[0][2] inspect.stack()[0][1] (that's (mostly) CPython-dependent, and should be avoided) > - ~== for approximate FP equality str(a) == str(b) >

Re: Syntax across languages

2005-10-23 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > >if you can define the semantics, it's a few lines of code. if you're not > sure about the semantics, a built-in won't help you...< > > I think the language needs a fast built-in version of it. If something > is both inside Mathematica and Ruby, then probably it can be

Re: Syntax across languages

2005-10-23 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > >sure looks like four possible outcomes.< > > Right (but to me four explicit answers seem better than three answers > and an exception still). def cmp4(a, b): try: return cmp(a, b) except: return None -- http://mail.python.org/mailman/listi

Re: Syntax across languages

2005-10-23 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Thank you Fredrik Lundh for showing everybody that indeed lot of people > feel the need of such function in Python too. you seem to be missing the point: all those versions are highly optimized, and tuned for the specific use-cases. a generic flatten would be u

Re: Problem with subprocess.call and cp

2005-10-23 Thread Fredrik Lundh
Torsten Bronger wrote: > The following code > > from subprocess import call > call(['cp', 'subdir/*.jpg', 'othersubdir/']) > > yields > > cp: call of stat for "subdir/*.jpg" not possible: File or directory not found > > (This may not be the real error message since it's back-translated > from Germ

Re: Syntax across languages

2005-10-23 Thread Fredrik Lundh
"beza1e1" wrote: > It has is uses. I had some kind of parser and had a dict like this: > {case: function, ...} It had to be a dict, because i wanted to > dynamically add and remove cases. In some cases nothing had to be done. > To represent this in the dict a identity function is needed. in Pytho

Re: How to separate directory list and file list?

2005-10-23 Thread Fredrik Lundh
"Gonnasi" wrote: > With > >glob.glob("*") > > or > >os.listdir(cwd) > > I can get a combined file list with directory list, but I just wanna a > bare file list, no directory list. How to get it? use os.path.isfile on the result. for file in glob.glob("*"): if not os.path.isfile(file)

Re: Localized strftime()

2005-10-23 Thread Fredrik Lundh
Sebastjan Trepca wrote: > I'm trying to get a localized date format from strftime() but it seems > that is doesn't have any parameters for that or any information about > this issue in Python docs. > > For example I want to turn this: > 19 Oct, 2005 > to this(slovene language): > 19 Okt, 2005 you

Re: Syntax across languages

2005-10-24 Thread Fredrik Lundh
Tom Anderson wrote: > This is taken from the AI 754 standard, i take it? :) > > Seriously, that's horrible. Fredrik, you are a bad man, and run a bad > railway. > > However, looking at the page the OP cites, the only mention of that > operator i can find is in Dylan, and in Dylan, it's not

Re: New User

2005-10-24 Thread Fredrik Lundh
"thatchmatic" wrote: > I just downloaded and I think installed python. I am not sure if I > did cause it does'nt respond to the commands that the read me file > told me to use. Also can someone suggest a trial program I can maybe > write for fun? what happens when you type python at a com

Re: Setting a Limit to the Maximum Size of an Upload

2005-10-24 Thread Fredrik Lundh
"Joey C." wrote: > thefile = params["upfile.file"] > if os.path.getsize(thefile) <= conf["upmax"]: >print "File Size Okay." #Add Functions Later... > else: >print "File Too Large." #Here, too. > > CGItb reported the following error: > TypeError: coercing to Unicode: need string or

Re: Tricky Areas in Python

2005-10-24 Thread Fredrik Lundh
Steven D'Aprano wrote: > Those two are easy. However, and this is where I show > my hard-won ignorance, and admit that I don't see the > problem with the property examples: >> class Base(object) >> def getFoo(self): ... >> def setFoo(self): ... >> foo = property(getFoo

Re: ABOUT FIND

2005-10-24 Thread Fredrik Lundh
Shi Mu wrote: >I got confused by the following information from the help for "FIND": > find(s, *args) what "FIND" ? >>> help(str.find) Help on method_descriptor: find(...) S.find(sub [,start [,end]]) -> int Return the lowest index in S where substring sub is found, such that sub is

Re: Execute C code through Python

2005-10-24 Thread Fredrik Lundh
Ernesto wrote: >> > Thanks. Can anyone provide an example of using *subprocess* to run >> > helloWorld.C through the python interpreter. >> >> compile helloWorld, and run: >> >> import subprocess >> subprocess.call("helloWorld") >> >> (any special reason why you couldn't figure this out y

Re: importing pickle modlue execute the code twice ??

2005-10-24 Thread Fredrik Lundh
"ychaouche" wrote: > i am having a strange experience with the pickle module. I use > python2.4 and i really don't understand what is happening on ! > take a look at this : > > > import pickle > print "hello" > > > hello > hello > did you perhaps name your test program "pickle.py" ? --

Re: Extention String returning

2005-10-24 Thread Fredrik Lundh
"Tuvas" wrote: > I have been writing a program that is designed to return an 8 byte > string from C to Python. Occasionally one or more of these bytes will > be null, but the size of it will always be known. How can I write an > extention module that will return the correct bytes, and not just unt

Re: output from external commands

2005-10-24 Thread Fredrik Lundh
Terry Hancock wrote: > Note also that for those who count, "str(f)" is exactly as long > (in keystrokes) as "'%s'%f", making the "just" a matter of opinion. the % implementation still has to create an overallocated output buffer, parse the format string, call str() on the argument, verify the res

Re: grep

2005-10-25 Thread Fredrik Lundh
"marduk" wrote: >> What's the standard replacement for the obsolete grep module? > > AFAIK there never was a "grep" module. There does, however exist a > deprecated "regex" module: there was a "grep" module in 1.5.2 and earlier: http://effbot.org/librarybook/grep.htm but it was removed in

Re: pickle

2005-10-25 Thread Fredrik Lundh
Shi Mu wrote: > what does the following code mean? > > y = pickle.load(file("cnumber.pickle", "r")) open the file "cnumber.pickle" for reading, pass the file handle to the pickle.load function, and store the result in the "y" variable. > also, I can not understand "f" in pickle.dump(x, f) the s

Re: testing for modules?

2005-10-25 Thread Fredrik Lundh
Ed Hotchkiss wrote: > i have a generic script that is using several modules on windows and linux > boxes. i need to have the scripts test if a module is installed, and then if > not - then to install the module. can anyone give me a headsup on how to > test for a module, returning something to ind

Re: Setting a Limit to the Maximum Size of an Upload

2005-10-25 Thread Fredrik Lundh
"Joey C." wrote: > Here is a basic overview of the variables included there. > > params = cgi.FieldStorage() > I accidentally made a mistake when typing what the "thefile" variable > is. > thefile = params["upfile"].file > "upfile" is the CGI field that contains the file that I'm uploading. > As y

Re: Hi All - Newby

2005-10-25 Thread Fredrik Lundh
"Ask" wrote: > As an example, if I create a window, I've been unable to force it to be a > certain size, and put a > button (widget) at (say) 20,40 (x & y). Is window formatting possible? I'm pretty sure all GUI toolkits can do that, but the exact details depend on the library you're using. (

Re: Tricky Areas in Python

2005-10-25 Thread Fredrik Lundh
Alex Martelli wrote: > No, LC goes back a long way -- I think it was in 2.0 already, 2.1 for > sure. $ python1.5 -c "print [x for x in 'abc']" File "", line 1 print [x for x in 'abc'] ^ SyntaxError: invalid syntax $ python2.0 -c "print [x for x in 'abc']" ['a', 'b', 'c'] I w

Re: XML Tree Discovery (script, tool, __?)

2005-10-25 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > The output I was contemplating was a DOM "DNA" - that is the DOM > without the instances of the elements or their data, a bare tree, a > prototype tree based on what is in the document (rather than what is > legal to include in the document). > > Just enough data that fo

Re: Tricky Areas in Python

2005-10-25 Thread Fredrik Lundh
Alex Martelli wrote: >> my hard-won ignorance, and admit that I don't see the >> problem with the property examples: >> >> > class Sic: >> > def getFoo(self): ... >> > def setFoo(self): ... >> > foo = property(getFoo, setFoo) > > Sorry for skipping the 2nd argument to s

Re: how to use new AST goodies

2005-10-25 Thread Fredrik Lundh
Simon Burton wrote: > I'd like to experiment with this, does anyone know where to start ? with the "once there is" parts, probably (see below). > It seems that the parser module still produces the same junk as before. > So where do we find these nice high level AST objects ? here's a nice summa

Re: cell and row

2005-10-25 Thread Fredrik Lundh
Shi Mu wrote: >I can not understand the use of "cell" and "row" in the code: > > # convert the matrix to a 1D list > matrix = [[13,2,3,4,5],[0,10,6,0,0],[7,0,0,0,9]] > items = [cell for row in matrix for cell in row] > print items working through the Python tutorial might be a good idea. here's

Re: more than 100 capturing groups in a regex

2005-10-25 Thread Fredrik Lundh
Joerg Schuster wrote: > I just want to use more than 100 capturing groups. define "more" (101, 200, 1000, 10, ... ?) -- http://mail.python.org/mailman/listinfo/python-list

Re: Setting a Limit to the Maximum Size of an Upload

2005-10-25 Thread Fredrik Lundh
"Joey C." wrote: > I'm afraid on my interpreter, this works. > if os.path.getsize("C:\\Documents and Settings\\Joey\\Desktop\\file.txt") <= 1000: print "<= 1000." > > <= 1000. > > No problems there, as you can see. I'm not sure if you replied to my post, but what I tried to say is

Re: python gc performance in large apps

2005-10-25 Thread Fredrik Lundh
Robby Dermody wrote: > In the diagrams above, one can see the night-day separation clearly. At > night, the memory usage growth seemed to all but stop, but with the > increased call volume of the day, it started shooting off again. When I > first started gathering this data, I was hoping for a log

Re: Upgrading 2.4.1 to 2.4.2

2005-10-25 Thread Fredrik Lundh
Vincent Gulinao wrote: > Hi, I'm new to python and just upgraded python on my system from 2.3 to 2.4. > My platform is Linux-2.6.9-1.667smp-i686-with-redhat-3-Heidelberg. > > Is there any way to inherit (share?) all extensions and additional modules > the my 2.3 have? (of course, beside re-install

Re: Upgrading 2.4.1 to 2.4.2

2005-10-25 Thread Fredrik Lundh
>> Hi, I'm new to python and just upgraded python on my system from 2.3 to 2.4. >> My platform is Linux-2.6.9-1.667smp-i686-with-redhat-3-Heidelberg. >> >> Is there any way to inherit (share?) all extensions and additional modules >> the my 2.3 have? (of course, beside re-installing everything) > >

Re: overiding assignment in module

2005-10-25 Thread Fredrik Lundh
Viktor Marohnic wrote: > I would to do something like this. > > container = [] > > p1 = point() > l1 = line() > > and i would like to override = method of the module so that its puts > all objects into container. > how i can do something like that. you cannot, at least not as you've described the

Re: Tricky import question.

2005-10-25 Thread Fredrik Lundh
David Poundall wrote: > importedfiles = {} > for f in FileList > f2 = f.split('.')[0] # strip the .py, .pyc > __import__(f2) > s2 = f2+'.main()' # main is the top file in each import > c = compile(s2, '', 'eval') > importedfiles[f2] = eval(c) > > 'importedfiles' should hold an

Re: more than 100 capturing groups in a regex

2005-10-25 Thread Fredrik Lundh
Iain King wrote: > Anyway, back to the OP: in this specific case, the cap of 100 groups in > a RE seems random to me, so I think the rule applies. perhaps in the "indistinguishable from magic" sense. if you want to know why 100 is a reasonable and non-random choice, I suggest checking the RE doc

Re: XML Tree Discovery (script, tool, __?)

2005-10-26 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > just namespace + tag here's an ElementTree-based example: # http://effbot.org/tag/elementtree import elementtree.ElementTree as ET FILE = "example.xml" path = () path_map = {} for event, elem in ET.iterparse(FILE, events=("start", "end")):

Re: Weird import behavior

2005-10-26 Thread Fredrik Lundh
"Tommytrojan" wrote: > thanks for your quick reply. I guess I should have included the output. > I thought I was clear in the error description. > The problem is that I never assign to 'string'. I only reference it (as > the error message correctly states). If you comment out the import > statemen

Re: more than 100 capturing groups in a regex

2005-10-26 Thread Fredrik Lundh
Joerg Schuster wrote: > > if you want to know why 100 is a reasonable and non-random choice, I > > suggest checking the RE documentation for "99 groups" and the special > > meaning of group 0. > > I have read everything I found about Python regular expressions. But I > am not able to understand wh

Re: assignment to reference

2005-10-26 Thread Fredrik Lundh
Loris Caren wrote: > a = 'apple' > b = 'banana' > c = 'cabbage' > > How can I get something like:- > > for i in 'abc': > r = eval(i) > if r == 'cabbage': r = 'coconut' > > actually change the object referenced by r rather > than creating a new object temporarily referenced by it? if you n

Re: WinXP vs. Win98

2005-10-26 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I use Python 2.3.3 (Enthought edition) with wxPython and it is > installed on both WinXP and Win98. On Win98 machine I have the > following error: > File "C:\PYTHON23\lib\site-packages\freetype\font_lookup.py", line > 24, in ? > font_dirs.append(os.path.join(os.en

Re: Raw string fu

2005-10-26 Thread Fredrik Lundh
Joshua Ginsberg wrote: > >>> r'\' > File "", line 1 > r'\' > ^ > SyntaxError: EOL while scanning single-quoted string > >>> r'\\' > '' > > Does that seem wrong to anybody else? Shouldn't the first one be > syntactically correct? the "r" prefix doesn't change how string literals are parsed; it

Re: syntax question - if 1:print 'a';else:print 'b'

2005-10-26 Thread Fredrik Lundh
Gregory PiƱero wrote: > Any idea why I can't say: > > if 1:print 'a';else:print 'b' > > all in one line like that? because ";" can only be used to separate simple statements, not the different parts in a compound statement. see the grammar for details: http://docs.python.org/ref/grammar.txt

Re: Sorting with only a partial order definition

2005-10-27 Thread Fredrik Lundh
Bryan Olson wrote: > The usual tools to deal with partial orderings are directed acyclic graphs, > and "topological sorting". Try Googling the terms along with "Python". here's a rather powerful timbot implementation: http://mail.python.org/pipermail/python-list/1999-July/006625.html

Re: Missing modules '_ssl', 'ext.IsDOMString', 'ext.SplitQName'

2005-10-27 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > xml.sax._exceptions.SAXReaderNotAvailable: No parsers found http://starship.python.net/crew/theller/moin.cgi/Py2exeAndPyXML > I checked out what Ron suggested, but I've no files where the names > could clash with python modules. next time you get stuck, make sure to c

Re: time conversion

2005-10-27 Thread Fredrik Lundh
"flupke" wrote: > Is there an easy to convert following hour notation hh:mm > to decimals? > For instance 2 hours and 30 minutes as 2:30 to 2,50 > I don't really know where to search for this kind of conversion. you mean like >>> timestamp = "2:30" >>> hour, minute = timestamp.split(":")

Re: Scanning a file

2005-10-28 Thread Fredrik Lundh
Mike Meyer wrote: > Did you do timings on it vs. mmap? Having to copy the data multiple > times to deal with the overlap - thanks to strings being immutable - > would seem to be a lose, and makes me wonder how it could be faster > than mmap in general. if you use "mmap" to read large files sequen

Re: Scanning a file

2005-10-30 Thread Fredrik Lundh
Paul Watson wrote: > This is Cyngwin on Windows XP. using cygwin to analyze performance characteristics of portable API:s is a really lousy idea. here are corresponding figures from a real operating system: using a 16 MB file: $ time python2.4 scanmap.py real0m0.080s user0m

Re: parsing a tuple in embedded python

2005-10-30 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I am returning a tuple from my python method and am stuck trying to > figure out how to read it into a C array using PyArg_Parse. > My C Code: > int array[3]; > PyArg_Parse(return, "(iii)", &array); > > My Python Code: > mytuple = (1,2,3) > return mytuple > > That gives

Re: process and spinning slash

2005-10-30 Thread Fredrik Lundh
Alex Martelli wrote: > Have the spin function accept the pid argument and exit the loop if said > pid has terminated; to check the latter, e.g., os.kill(pid, 0) -- this > will raise an OSError if no process with that pid exists, so you can use > a try/except OSError: to catch that and break as app

Re: Need Python Pro for Help!! Plzz

2005-10-31 Thread Fredrik Lundh
Alex Hunsley wrote: > 2) Why should someone willing to help you enter into a private email > discussion? Newsgroups like this exist to help people looks like "Fan" wants to run his own group: http://groups.google.com/group/newtopython/about "There are no experts or PHD's, all are simple

Re: Tkinter problem

2005-10-31 Thread Fredrik Lundh
"dale cooper" wrote: > I've recently installed python2.4.2 on Fedora 4 (from downloaded > sources), but it appeared, that I can't use Tkinter module: > import Tkinter > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/local/lib/python2.4/lib-tk/Tkinter.py", line 38, i

Re: process and spinning slash

2005-10-31 Thread Fredrik Lundh
"benz" <[EMAIL PROTECTED]> wrote >I have rewrited my code as follow, but it still not working. > > import os, sys > > > pid = os.fork() > > if pid == 0: > os.execvp("du",("du","-shc","/usr/share")) > else: > while 1: >try: > os.kill(pid,0) > sys.stdout.write('running') > sys.s

<    1   2   3   4   5   6   7   8   9   10   >