Re: Odd math related issue.

2008-07-21 Thread Fredrik Lundh
sahasranaman wrote: Use 2.0 / 3 * 100 to solve this. Why make things look bigger? you mean that a.0 / 3 * 100 works in your Python version? that's interesting. (maybe you should at least skim the the thread before you jump in?) -- http://mail.python.org/mailman/listinfo/python-list

Re: error

2008-07-21 Thread Fredrik Lundh
Anish Chapagain wrote: hi thank's i probably missed the b.pack() but it's till the window is not closed and error message of Windows Appear what does that error message say? -- http://mail.python.org/mailman/listinfo/python-list

Re: How to install simplejson on WinXP

2008-07-21 Thread Fredrik Lundh
lookon wrote: I am new to python and had difficulty in installing simplejson on WinXP...Could anyone help me? Thanks what did you try, and what happened when you tried that? -- http://mail.python.org/mailman/listinfo/python-list

Re: error

2008-07-21 Thread Fredrik Lundh
Anish Chapagain wrote: from Tkinter import * root=Tk() f=Frame(root,height=200,width=200) b=Button(f,text="quit",command=f.quit) f.pack() root.mainloop() -- from Tkinter import * import sys root=Tk() f=Frame(root,height=200,width=200) b=Button(f,t

Re: Odd math related issue.

2008-07-21 Thread Fredrik Lundh
Alexandru Palade wrote: However, you should be carefully because using an %i modifier for a what-should-be a float value truncates the value in a way you may not expect. What I mean is that if you have sent 2 out of 3 bytes, the math will be 200/3 which with the %i modifier will print 66, rathe

Re: simple question about dictionaries

2008-07-21 Thread Fredrik Lundh
Jeff wrote: throw KeyError('%s not found' % str(val)) "throw"? and shouldn't that be a ValueError? ;-) -- http://mail.python.org/mailman/listinfo/python-list

Re: simple question about dictionaries

2008-07-21 Thread Fredrik Lundh
skazhy wrote: hi, i am new to python, so i've a really simple question about dictionaries. if i have a dictionary and I make have an input after it (to input numbers) can i get the key of value that was in input? A dictionary contains (key, value) pairs, and is optimized for quickly finding t

Re: calling source command within python

2008-07-21 Thread Fredrik Lundh
Jie wrote: i'm having trouble executing os.system('source .bashrc') command within python, it always says that source not found and stuff. Any clue? like in $ python >>> import os >>> os.system("source .bashrc") sh: source not found and stuff 256 ? I get $ python

Re: trying to match a string

2008-07-21 Thread Fredrik Lundh
oj wrote: Fine, this works, although match instead of search blah blah blah as has already been mentioned. I still think searching for one invalid character is more elegant then trying to match the entire string, but that's just personal preference, I guess. The drawback is that it's a lot eas

Re: What is the role of python2.6 and C++?

2008-07-21 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: 2.6 is meant to be a continuation of the 2.x line of Python, to support a gradual move of larger projects over to the Python 3.x series. note that Python also has a tradition of releasing X.6 and (X+1).0 at the same time: http://mail.python.org/pipermail/python-anno

Re: Odd math related issue.

2008-07-21 Thread Fredrik Lundh
Robert Rawlins wrote: I’ve got what seems to me to be a totally illogical math issue here which I can’t figure out. Take a look at the following code: /self/.__logger.info(/"%i / %i"/ % (bytes_transferred, /self/.__sessions[path].total_bytes)) percentage = bytes_transferred

Re: regex doubts

2008-07-21 Thread Fredrik Lundh
Perhaps you could explain what you mean by "$ does the right thing". wtf is wrong with you? (I mean, you do know under what circumstances $ matches a newline character when used without modifiers, right? So why do you keep behaving like a reddit commenter?) -- http://mail.python.org/mai

Re: running a script with an input file

2008-07-21 Thread Fredrik Lundh
David Bikard wrote: I'd like to run a program so that it reads the input() or raw_input() statements from an input file instead of reading from keyboard. I'd also like it to write the print statements in an output file rather than on the screen. I'm on windows XP and when I run: > prog_nam

Re: Web Server

2008-07-21 Thread Fredrik Lundh
James Tanis wrote: there's also apache, of course, and a bunch of others, including several Python solutions (more or less pre-packaged). but the "open up" part still sounds a bit risky. maybe you could turn things around, and let the application "push" data to your server instead? Either

Re: Python Written in C?

2008-07-21 Thread Fredrik Lundh
Michael Torrie wrote: [EMAIL PROTECTED] wrote: I'm not dissing Python, here. Just noting that, if it is written in C, that throws a curve at me in trying to balance the value of learning Python vs. some other major language. Definitely one of the most non-sequitor statements I have ever hea

Re: regex doubts

2008-07-21 Thread Fredrik Lundh
John Machin wrote: '\n' is an "other character". so how does a user enter that character? Perhaps you could explain what you mean by "$ does the right thing". wtf is wrong with you? -- http://mail.python.org/mailman/listinfo/python-list

Re: Web Server

2008-07-20 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: Thanks, Fredrik - that definitely works. Now to get a little greedy - is there something along those lines that is a bit more secure (i.e. allows HTTPS, possibly with authentication)? Basically something that you would feel more comfortable opening up to the Internet..

Re: Passing keywords

2008-07-20 Thread Fredrik Lundh
Kless wrote: I could use the next but I don't think... --- def __check(self, **keywords): --- don't think what? if you keep using the same variables in all submethods you call from a method inside the class, why not make them attributes? otherwise, using the **

Re: Web Server

2008-07-20 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: As part of a Python app I wrote recently (for Windows), I would like to give the option of an HTTP (HTTPS if possible, but not necessary) front end, which would then call some existing python scripts. My question is - I know I can write a simple HTTP server in Python, b

Re: regex doubts

2008-07-20 Thread Fredrik Lundh
John Machin wrote: try "[LRM]+$" (an L or an R or an M, one or more times, all the way to the end of the string). Ummm ... with the default flag settings, shouldn't that be \Z instead of $ ? Why? The OP was reading input from a user; whether he gets a trailing newline or not depends on the

Re: Not entirely serious: recursive lambda?

2008-07-20 Thread Fredrik Lundh
Michael Tobis wrote: I realize that lambda is something of an orphan and was arguably a bad idea for anything besides obfuscation, but obfuscation is exactly my purpose here. Can a lambda call itself without giving itself a name? Google was not my friend on this one, and I suspect there is no an

Re: Rotating a cube

2008-07-20 Thread Fredrik Lundh
David Lyon wrote: But is the question about display graphics ? ie rotating a cube using a python framework ? With something like python and OpenGL ? or Python and PovRay... or perphaps python and imagemagick ? can you name one graphics framework that represents a cube as "x + 4*y + 16*z" ?

Re: XML Parsing: Expat Error

2008-07-19 Thread Fredrik Lundh
Gerth, William D wrote: Hey all, I’m simply trying to get my feet wet with XML parsing, and I tried to just do something simple with ElementTree, just throw the XML tags from a file into a list. The code is as follows (and may be wrong): ... xml.parsers.expat.ExpatError: no element found:

Re: regex doubts

2008-07-19 Thread Fredrik Lundh
Mr SZ wrote: I am taking a string as an input from the user and it should only contain the chars:L , M or R I tried the folllowing in kodos but they are still not perfect: [^A-K,^N-Q,^S-Z,^0-9] [L][M][R] [LRM]?L?[LRM]? etc but they do not exactly meet what I need. > For eg: LRLRLRLRLM is ok

Re: Fwd: Hello

2008-07-17 Thread Fredrik Lundh
> they have an official API, you know: > > http://developer.yahoo.com/search/boss/ and yes, there are other options too, including pYsearch which is available from their developer network: http://developer.yahoo.com/python/python-pysearch.html for more Python stuff from/for Yahoo, see

Re: Fwd: Hello

2008-07-17 Thread Fredrik Lundh
spandana g wrote: HTTPError: HTTP Error 999: Unable to process request at this time -- error 999 Previously i got the error which I have attached below when I use just urlopen . But now when I use this http request user_agent='Mozilla/3.0(compatible;MISE 5.5;Windows NT)' headers={'User-Agen

Re: Question about properties

2008-07-17 Thread Fredrik Lundh
Frank Millman wrote: > I thought that the main point of using property was to prevent direct > access to the attribute. Not "prevent access to" as much as "add behaviour to". Is this a valid comment, or does it come under the category of 'we are all adults here'? The latter. And the "__" do

Re: Getting a unknown word out of a list with no spaces

2008-07-17 Thread Fredrik Lundh
Alexnb wrote: "hello"[0] 'h' "hello"[0] == "<" False "hello"[0] == "h" True "hello".startswith("h") True really? That's just like C. I thought that it would fail because of the way lists work. Thanks! what way? the first three will fail if the string is empty. >>> ""[0] Tra

Re: Remove some characters from a string

2008-07-17 Thread Fredrik Lundh
Julien wrote: I can't seem to find the right regular expression to achieve what I want. I'd like to remove all characters from a string that are not numbers, letters or underscores. For example: magic_function('[EMAIL PROTECTED]') str: 'si_98udasgf' the easiest way is to replace the things

Re: Amazon: "Practical Django Projects" by James Bennett (June 2008)

2008-07-17 Thread Fredrik Lundh
Stefan Scholl wrote: And by the way: The quote was changed by deleting something on the same line: "June 2008 is a bit too early. Django isn't ready." vs. "Django isn't ready." Is this a language issue? That you meant to write "django 1.0 isn't done" (as in

Re: Amazon: "Practical Django Projects" by James Bennett (June 2008)

2008-07-17 Thread Fredrik Lundh
Stefan Scholl wrote: Django isn't ready. That's a remarkably ignorant statement. The 1.0 release will be in September. So? "1.0" will be done then, yes. In what way does that mean that Django itself isn't ready, in any sane sense of that word? (For bystanders, Django's 0.91 release in

Re: Rotating a cube

2008-07-17 Thread Fredrik Lundh
J-Burns wrote: Is there a built in Python function for this? for answering questions that have nothing to do with programming, and looks quite a bit like homework? don't think they've added that one yet. maybe you should look for a geometry newsgroup/forum? -- http://mail.python.org/mai

Re: Manually prompting garbage collection

2008-07-16 Thread Fredrik Lundh
Fredrik Lundh wrote: > Do these objects have direct references to a resource that you're > explicitly destroying from your C code? and yes, if this is the problem, the correct solution is to create an separate object type that's designed to manages the resource and act as a

Re: Manually prompting garbage collection

2008-07-16 Thread Fredrik Lundh
Kyle Lanclos wrote: The DECREF decrements the reference count, but does not immediately prompt garbage collection when the reference count drops to zero; that garbage collection does not appear to occur until I return from the particular C function I am in the middle of executing. Yeah, but wh

Re: Manually prompting garbage collection

2008-07-16 Thread Fredrik Lundh
Kyle Lanclos wrote: I want to modify the above sequence to manually prompt Python's garbage collection routine(s) to take over (performance is not an issue here), similar to the following: Py_XDECREF (some_callback); PyCollect_Garbage (); closeService (some_service); return; Is that possible?

Re: python doc in command line

2008-07-16 Thread Fredrik Lundh
Peng Yu wrote: Perl has a command line help perldoc. I'm wondering if python has a similar help command. it's built into the interpreter, and Python tells you how to use it when you start Python in interactive mode. $ python Python 2.5.1 Type "help", "copyright", "credits" or "license" for

Re: how to match whole word

2008-07-16 Thread Fredrik Lundh
John S wrote: > Not sure why you picked \A and \Z -- they are only useful if you are > using the re.M flag. Well, they're aliases for ^ and $ in "normal" mode, at least for strings that don't end with a newline. re.I is the same as re.IGNORECASE. More than one option may be OR'ed together. T

Re: For_loops hurt my brain.

2008-07-16 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: This script uses a simple for loop to zip some files. However I am repeating code that cries out for a nested loop. Cries out for a *function*, I'd say. My two lists of files_to_be_zipped (spare and seekfacts) are of > uneven length so I can't seem to decipher the "

Re: how to match whole word

2008-07-16 Thread Fredrik Lundh
Peng Yu wrote: I didn't read the docs and tried the following code. regex = re.compile(r"\A" + re.escape(old_str) + r"\Z", opts.ignore_case and re.I or 0) But I'm not sure why it is not working. as the documentation says, \A and \Z matches at the beginning/end of a *string*, not a word.

Re: Angle brackets in command-line arguments?

2008-07-16 Thread Fredrik Lundh
Keith Hughitt wrote: I am using someone else's script which expects input in the form of: ./script.py arg2 is a common notation for "replace with argument value", so it could be that they're just expecting you to type: ./script.py arg1 arg2 Alternatively, they meant ./scri

Re: Best Python packages?

2008-07-16 Thread Fredrik Lundh
Ben Sizer wrote: make my development a lot easier. Knowing what kind of development you do might help, of course. Some libraries are excellent in some contexts and suck badly in others... Looking at things that larger projects and distributions use can also be a good idea. For example, i

Re: Regular expression

2008-07-16 Thread Fredrik Lundh
Beema shafreen wrote: How do I write a regular expression for this kind of sequences >gi|158028609|gb|ABW08583.1| CG8385-PF, isoform F [Drosophila melanogaster] MGNVFANLFKGLFGKKEMRILMVGLDAAGKTTILYKLKLGEIVTTIPTIGFNVETVE line.split("|") ? it's a bit hard to come up with a working RE with only

Re: How to figure out if the platform is 32bit or 64bit?

2008-07-16 Thread Fredrik Lundh
Tim Golden wrote: This is included in the latest pywin32-211 as well: import win32process print win32process.IsWow64Process () on the other hand, "ctypes" is only an import away if you have a current Python... -- http://mail.python.org/mailman/listinfo/python-list

Re: How to figure out if the platform is 32bit or 64bit?

2008-07-16 Thread Fredrik Lundh
Ken Hartling wrote: > Thanks .. but I want to find out if the system is "running on 64bit" > even when the interpreter is a 32-bit build executable ("what python > was built on"). platform.architecture() and platform() in general > seems to only be looking at the build executable You can pass i

Re: bad recursion, still works

2008-07-16 Thread Fredrik Lundh
Jeff wrote: Is this avoidable by using a call to list() in the definition instead? No. Default values are *always* evaluated when, and only when, the "def" statement is executed; see: http://docs.python.org/ref/function.html Also note that "def" is an executable statement in Python, a

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-16 Thread Fredrik Lundh
Andreas Tawn wrote: I don't have experience of too many other languages, but in C++ (and I guess C)... That's invalid C (you cannot declare variables in the "for" statement itself, at least not in C89). And back in the old days, some C++ compilers did in fact leak declarations from "for" lo

Re: Get current class namespace.

2008-07-16 Thread Fredrik Lundh
Robert Rawlins wrote: What’s the simplest way to access a classes namespace from within itself. I want to use it in a custom __repr__() method so it prints the current namespace for the class like package.module.class. Name or namespace? You can access the class name from an instance via th

Re: isPrime works but UnBoundLocalError when mapping on list

2008-07-16 Thread Fredrik Lundh
Andreas Tawn wrote: I never knew that and I can't find reference to it in the docs. the for-in loop does ordinary assignments in the current scope: http://docs.python.org/ref/for.html "Each item in turn is assigned to the target list using the standard rules for assignments, and

Re: Testing for connection to a website

2008-07-16 Thread Fredrik Lundh
Alexnb wrote: e = '' try: ... except HTTPError, e: print e.code except URLError, e: print e.reason if e == '': print "good to go" footnote: here's a better way to test if an exception was raised or not: try: ... except HTTPError, e: print e.co

Re: Amazon: "Practical Django Projects" by James Bennett (June 2008)

2008-07-16 Thread Fredrik Lundh
Stefan Scholl wrote: Django isn't ready. That's a remarkably ignorant statement. -- http://mail.python.org/mailman/listinfo/python-list

Re: reading one byte from stdin

2008-07-16 Thread Fredrik Lundh
Mark McDuff wrote: I'm trying to read one byte from stdin, without the newline. If I try something like: >>> import os, sys >>> os.read(sys.stdin.fileno(),1) I can input a character, but then I have to press enter, which leaves a newline character in the stdin buffer and requires two keypre

Re: Is there any library that can extract titles from PDFs?

2008-07-16 Thread Fredrik Lundh
ZelluX wrote: I want to write a script which will rename PDFs according to their titles. I want to know if there is any library that can extract titles(the first line of the PDF) from PDFs. Mathieu Fenniak's PyPdf should be able to do this: http://pybrary.net/pyPdf/ (but note that "the f

Re: Is this correct behavior for default parameters?

2008-07-16 Thread Fredrik Lundh
Bruce Pearson wrote: The first call to test has the file_list empty but on the second call to test the file_list is no longer empty but contains the values appended in the first call. Is this correct behavior? I'm using python 2.5 yes: http://docs.python.org/ref/function.html "Def

Re: Is re.findall guaranteed to be "in order?"

2008-07-16 Thread Fredrik Lundh
Joshua Kugler wrote: Experimenting has shown me that re.findall() will return a list with the matches in the order it found them. "in the order it found them" doesn't really say much, does it? ;-) "findall" and "finditer" both scans the string from left to right, and will return matches in t

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Fredrik Lundh
Jerry Hill wrote: This is just plain untrue. If 'name is None' evaluates to true, then the variable 'name' is bound to the singleton value None. It has nothing to do with allocated memory or null pointers. All it means is that someplace along the line you did the equivalent of 'name = None' i

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Fredrik Lundh
Victor Noagbodji wrote: Well that's exactly why I'm asking. Since None returns False in if statements. Why do people use if name is not None: instead of simply writing if not name? Because they want to distinguish between None and other values that evaluate to False, of course. As the page I

Re: 'if name is not None:' v. 'if name:'

2008-07-15 Thread Fredrik Lundh
Victor Noagbodji wrote: what's the difference between these two statement? one checks if the given object is not None, the other checks if it's a true value: http://docs.python.org/ref/Booleans.html#Booleans > And which one should one use? depends on what you want to test for, of cour

Re: Logging in __del__()

2008-07-15 Thread Fredrik Lundh
Robert Rawlins wrote: I then get the following exception thrown when running my code: When the application is running, or when it is shutting down? Traceback (most recent call last): File "/usr/lib/python2.5/logging/handlers.py", line 73, in emit if self.shouldRollover(record): File

Re: why is "self" used in OO-Python?

2008-07-15 Thread Fredrik Lundh
ssecorp wrote: def append(self, item): self.stack.append(item) I can get to see the stack with var.stack but then why even implement append when I could do self.stack.append(x) etc. That way you could do away with OO completely. Umm. Even if you were to write that, self and stack

Re: SAX XML Parse Python error message

2008-07-15 Thread Fredrik Lundh
goldtech wrote: I would be grateful for support with the code I cited. It's not long and fairly standard. I'm sure my error(s) would be glaring to more experienced coders. I appreciated the "heads-up" about other options but I would be grateful for help getting this code to run. Thanks For com

Re: screencapture with PIL question

2008-07-15 Thread Fredrik Lundh
greg wrote: I am able to use the PIL module to capture a screen or specific window. My problem is when capturing a window (on windows XP) I can only capture the "visible" portion of the window. Is there any way to capture the entire window? specifically the scrolled portion of a window that i

Re: How to get an XML DOM while offline?

2008-04-06 Thread Fredrik Lundh
Stefan Behnel wrote: >> Is there a simpler way to read the iTunes XML? (It's merely a plist, >> so the format is much simpler than general XML.) > > Try lxml. Since version 2.0, its parsers will not access the network unless > you tell it to do so. > > http://codespeak.net/lxml which makes it t

Re: How to create an exe-file?

2008-04-06 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > a good thing about python is the portability though. but u cant make > an exe that can be used on mac too, ie one exe fpr both? you can create a portable python archive, but EXE files are windows only. > if i want to make an exe for mac, what do i need? see the second

Re: How to create an exe-file?

2008-04-06 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > how do you create exe-files of your python-code? > > is it different depending on what libraries, GUI-frameworks you use? > > i want to create an exe-file of a pythonscript that uses Tkinter. assuming windows only, you want: http://www.py2exe.org/ also see: http://

Re: Self in Interactive Interpreter

2008-04-06 Thread Fredrik Lundh
kj7ny wrote: > With some of my larger applications, it doesn't seem to work well to > try to run the whole thing in the interpreter. At least for me, I am > not a big IDE sort of programmer. I am much more comfortable in vim > and command line stuff. I suppose I should use the IDE more. you do

Re: When does a binary extension gets the file extension '.pyd' and when is it '.so'

2008-04-06 Thread Fredrik Lundh
Steve Holden wrote: >> for reference, here's what I get on Ubuntu 7.10, with the standard >> Python interpreter (2.5.1): >> >> $ python -c "import imp; print imp.get_suffixes()" >> [('.so', 'rb', 3), ('module.so', 'rb', 3), ('.py', 'U', 1), >> ('.pyc', 'rb', 2)] >> >> any Ubuntu gurus here that c

Re: TKinter, buttonwidget response problem(1) and all btns the same size(2)!

2008-04-05 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > i dont know, i used a piece of code i found which had a createwidgets- > method. isnt init a function, not a method btw(or it is the same > thing?) a method is a function defined inside a class statement, and which is designed to be called via an instance of that class

Re: When does a binary extension gets the file extension '.pyd' and when is it '.so'

2008-04-05 Thread Fredrik Lundh
Fredrik Lundh wrote: > and for the record, Python doesn't look for PYD files on any of the Unix > boxes I have convenient access to right now. what Ubuntu version are > you using, what Python version do you have, and what does > > $ python -c "import im

Re: TKinter, buttonwidget response problem(1) and all btns the same size(2)!

2008-04-05 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: >> def __init__(self): >> # ... >> button = Button(self, >> text='1', >> command=lambda n=1: self.display(n)) >> # ... >> >> def display(self, number): >> print number > > should this

Re: In Tkinter - having an input and an entry

2008-04-05 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Thanks it sorted out my 'StringVar' problem. > I now have another problem... > > Exception in Tkinter callback > Traceback (most recent call last): > File "D:\Python24\lib\lib-tk\Tkinter.py", line 1345, in __call__ > return self.func(*args) > TypeError: Insert() t

Re: TKinter, buttonwidget response problem(1) and all btns the same size(2)!

2008-04-05 Thread Fredrik Lundh
Francesco Bochicchio wrote: > It should be added here that in Python you have several ways get around > this Tkinter limitation and pass an user argument to the callback. Once > upon a time , back in Python 1.x, I used to do something like this: > > class CallIt: > def __init__(self, f, *a

Re: When does a binary extension gets the file extension '.pyd' and when is it '.so'

2008-04-05 Thread Fredrik Lundh
llothar wrote: > I don't think so. I asked a pretty simple question and as usual on > usenet nobody read the question did *you* read your own question? it took you three posts before you mentioned what you were trying to do, and four posts before you bothered to mention that you're seeing this

Re: When does a binary extension gets the file extension '.pyd' and when is it '.so'

2008-04-05 Thread Fredrik Lundh
Steve Holden wrote: > You display your ignorance here. The ".pyd" extension is used on Windows > as an alternative to ".dll", but both are recognized as shared > libraries. Personally I'm not really sure why they even chose to use > ".pyd", which is confusing to most Windows users. In UNIX/Linu

Re: In Tkinter - having an input and an entry

2008-04-05 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Traceback (most recent call last): > File "F:\Programming\python and database\access_db8.2.py", line 129, > in ? > Tkwindow() > File "F:\Programming\python and database\access_db8.2.py", line 88, > in Tkwindow > title = stringVar() > NameError: global name 's

Re: In Tkinter - having an input and an entry

2008-04-05 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I can fetch records but cannot insert records. > > def Insert(self, *row): > global cursor, title, author, pubdate using globals to pass arguments to a function/method is usually not a good idea. any reason you cannot pass them in as arguments? > sqlInsert =

Re: When does a binary extension gets the file extension '.pyd' and when is it '.so'

2008-04-05 Thread Fredrik Lundh
llothar wrote: > I ship an application that compiles an python interpreter and > extension on a remote system. > It also needs to copy this created items around. So if i use setup.py > to create an > extension i need to know the file name of the generated file. so why not just ask setup.py

Re: When does a binary extension gets the file extension '.pyd' and when is it '.so'

2008-04-05 Thread Fredrik Lundh
llothar wrote: > My question was: Why does setup.py generated sometimes a pyd and > sometimes a so file? setup.py picks an extension that happens to work on the platform you're running setup.py on. doing otherwise would be pretty pointless. -- http://mail.python.org/mailman/listinfo/python-

Re: Is there any way to say ignore case with "in"?

2008-04-04 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Is there any way in python to say > > if string1 in string2: > > > ignoring the case of string1 and string2? if string1.lower() in string2.lower(): ... (there's no case-insensitive version of the "in" operator in stock Python) -- http:

Re: Self in Interactive Interpreter

2008-04-04 Thread Fredrik Lundh
kj7ny wrote: > For years it has been a slight annoyance that every time I wanted to > test a snippet of code from a class by running it in the interactive > interpreter, I had to remove all of the self. instances from the > code. After I got it working correctly, I had to put all the self.'s > ba

Re: Tokenizer inconsistency wrt to new lines in comments

2008-04-04 Thread Fredrik Lundh
George Sakkis wrote: >> If it was a bug it has to violate a functional requirement. I can't >> see which one. > > Perhaps it's not a functional requirement but it came up as a real > problem on a source colorizer I use. I count on newlines generating > token.NEWLINE or tokenize.NL tokens in order

Re: When does a binary extension gets the file extension '.pyd' and when is it '.so'

2008-04-04 Thread Fredrik Lundh
llothar wrote: > On windows everything is '.pyd' but there seems to be two ways to get > this on unix? If you attempt to import the module "spam" on Windows, Python looks for "spam.dll" and "spam.pyd" (in addition to "spam.py/spam.pyw/spam.pyc" etc) On most Unix platforms, Python looks for "spa

Re: "Soup Strainer" for ElementSoup?

2008-03-30 Thread Fredrik Lundh
erikcw wrote: > I'm parsing real-world HTML with BeautifulSoup and XML with > cElementTree. > > I'm guessing that the only benefit to using ElementSoup is that I'll > have one less API to keep track of, right? Or are there memory > benefits in converting the Soup object to an ElementTree? It's

Re: regarding xml elements

2008-03-30 Thread Fredrik Lundh
Raj kumar wrote: > document.createElement("abc") > and i appeneded it by using append() method. > But how i can reflect this change to my xml file? write it out again: http://python.org/doc/current/lib/dom-objects.html -- http://mail.python.org/mailman/listinfo/python-list

Re: ElementTree.fromstring(unicode_html)

2008-01-27 Thread Fredrik Lundh
globophobe wrote: > In [1]: unicode_html = u'\u3055\u3080\u3044\uff0f\r\n\u3064\u3081\u305f > \u3044\r\n' > > I need to turn this into an elementtree, but some of the data is > japanese whereas the rest is html. This string contains a . where? is an element, not a character. "\r" and "\n" are

Re: python regex: misbehaviour with "\r" (0x0D) as Newline character in Unicode Mode

2008-01-27 Thread Fredrik Lundh
Arian Sanusi wrote: > concerning to unicode, "\n", "\r "and "\r\n" (0x000A, 0x000D and 0x000D+0x000A) should be threatened as newline character the link says that your application should treat them line terminators, not that they should all be equal to a new line character. to split on Unicode

Re: Memory errors with imaplib

2008-01-20 Thread Fredrik Lundh
Martey wrote: > I am trying to use imaplib to download messages, but I keep getting > memory errors when I try to download a large message (i.e. one with > attachments). Here is my test code (similar to the example in the > imaplib documentation): > /.../ > I am using Mac OS X 10.5 and Python 2

Re: Okay I got a question regarding Tkinter and Labels

2008-01-20 Thread Fredrik Lundh
Lamonte Harris wrote: > Okay I've created a script and basically when I loop through a folder it > is supposed to change the Label everytime it updates a file then again > it doesn't do nothing but shows the last file edited, whats the best way > to loop through files and display that file name

Re: Excess whitespace in my soup

2008-01-19 Thread Fredrik Lundh
John Machin wrote: > I'm happy enough with reassembling the second item. The problem is in > reliably and correctly collapsing the whitespace in each of the above > fiveelements. The standard Python idiom of u' '.join(text.split()) > won't work because the text is Unicode and u'\xa0' is whitesp

Re: Bug in __init__?

2008-01-18 Thread Fredrik Lundh
Zbigniew Braniecki wrote: > It's really a nice pitfall, I can hardly imagine anyone expecting this, > or how easily could I find this info (e.g. what query should I give to > google to get it without bothering people on this group) looking things up in the documentation *before* deciding that y

Re: ElementTree and namespaces in the header only

2008-01-15 Thread Fredrik Lundh
Peter Bengtsson wrote: > root = Element('feed', xmlns='http://www.w3.org/2005/Atom') > root.set('xmlns:se', NS_URL) > entry = SubElement(root, 'entry') > SubElement(root, 'title').text = 'Title' > SubElement(entry, SEN('category')).text = 'Category' > But surely the xmlns:se attribute on the tag

Re: time.time or time.clock

2008-01-14 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > """ > > time.clock() isn't high enough resolution for Ubuntu, and time.time() > isn't > high enough resolution on windows. > > Take a look at datetime. It is good to the micro-second on Linux and > milli-second on Windows. datetime.datetime.now() does the same thing

Re: time.time or time.clock

2008-01-13 Thread Fredrik Lundh
John Machin wrote: > AFAICT that was enough indication for most people to use time.clock on > all platforms ... which was unfortunate, given that time.clock() isn't even a proper clock on most Unix systems; it's a low-resolution sample counter that can happily assign all time to a process that

Re: Manually installing PIL

2008-01-13 Thread Fredrik Lundh
j igisbert.etra-id wrote: > this. I have download Imaging-1.1.6 source code, and I found PIL folder, > but not binary file. If I download windows exe installer, it works > great, but I want to install manually for installing it on my PDA as the name implies, the source code distribution co

Re: Simple List division problem

2008-01-13 Thread Fredrik Lundh
thebjorn wrote: > Eh... oh, forgot that it was "pulling requirements out of thin air" week on c.l.python. > def chop(lst, length): > n = len(lst) / length > z = [lst[i:i+n] for i in xrange(0, len(lst), n)] > if len(z[-1]) < n and len(z) > 1: > z[-2].extend(z.pop(-1)) >

Re: __init__ explanation please

2008-01-13 Thread Fredrik Lundh
Erik Lind wrote: > I'm new to Python, and OOP. I've read most of Mark Lutz's book and more > online and can write simple modules, but I still don't get when __init__ > needs to be used as opposed to creating a class instance by assignment. nothing is ever created by plain assignment in Python;

Re: __init__ explanation please

2008-01-13 Thread Fredrik Lundh
Jeroen Ruigrok van der Werven wrote: > I personally tend to see __init__ or __new__ as equivalent to what other > languages call a constructor. > > (And I am sure some people might disagree with that. ;)) given that they do different things, I'm not sure it's that helpful to describe them *both

Re: about sort a list with integer key

2008-01-13 Thread Fredrik Lundh
lotrpy wrote: > key = int(itemgetter(0)) is wrong, key = lambda x:int(x[0]) works. > but s.b. told me itemgetter execute more quickly . so you're more interested in speed than in correctness? ;-) operator.itemgetter is a function factory that creates a *function* that fetches the given item fr

Re: sqlite3 is it in the python default distro?

2008-01-12 Thread Fredrik Lundh
Martin Marcher wrote: > I can see that sqlite is in the standard lib documentation: > http://docs.python.org/lib/module-sqlite3.html > > however debian and ubuntu (and gentoo according to the packages info) seem > _not_ to include it. http://packages.debian.org/python-sqlite -- http://mail.

Re: IDLE won't start in Python 2.5 for Windows

2008-01-12 Thread Fredrik Lundh
mikez302 wrote: > I opened a command window in my Python25 folder and tried typing > pythonw. I just got another command prompt as if the program ran but > didn't do anything. It looked like this: > > C:\Python25>pythonw > > C:\Python25> "pythonw" is the console-less version of the Python run

Re: Simple List division problem

2008-01-12 Thread Fredrik Lundh
marcstuart wrote: > How do I divide a list into a set group of sublist's- if the list is > not evenly dividable ? consider this example: > > x = [1,2,3,4,5,6,7,8,9,10] > y = 3 # number of lists I want to break x into > z = y/x > > what I would like to get is 3 sublists > > print z[0] = [1

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