REMINDER: OSCON 2008 Call for Proposals
The O'Reilly Open Source Convention (OSCON) is accepting proposals for tutorials and presentations. The submission period ends Feb 4. OSCON 2008 will be in Portland, Oregon July 21-25. For more information and to submit a proposal, see http://conferences.oreilly.com/oscon/ -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ All problems in computer science can be solved by another level of indirection. --Butler Lampson -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: python24 symbol file...pyhon24.pdb
[EMAIL PROTECTED] wrote: I've seen a few references on the net to a python24.pdb file. I assume it's a symbol file along the lines of the pdb files issued by microsoft for their products. Maybe I'm wrong. .pdb files (program database) are created by MS' compiler, see http://en.wikipedia.org/wiki/Program_database. Python doesn't ship the files. You have to compile Python yourself to get the pdb files. Christian -- http://mail.python.org/mailman/listinfo/python-list
python2.4-dbg and C modules
Hello, please, when I try to run my code under python2.4-dbg from Ubuntu, the interpreter complains that the Py_InitModule4 symbol is undefined in a C module I'm using (PyOpenAL): ImportError: /var/lib/python-support/python2.4/_openal.so: undefined symbol: Py_InitModule4 Google reveals that this problem is not specific just to PyOpenAL, but I couldn't find out what is the essence of the problem and how python-2.4dbg is different from python2.4 except for including debugging symbols, because in plain python2.4 the module works fine. Also, the same thing happens with python 2.5 (not the -dbg variant). Please, what is the problem and how to overcome it? Thank you, Hynek Hanke -- http://mail.python.org/mailman/listinfo/python-list
Re: python24 symbol file...pyhon24.pdb
En Wed, 23 Jan 2008 05:04:35 -0200, [EMAIL PROTECTED] escribió: I've seen a few references on the net to a python24.pdb file. I assume it's a symbol file along the lines of the pdb files issued by microsoft for their products. Maybe I'm wrong. Has anyone seen such an animal? I don't get why you care so much about that file. It's useful to debug a crash in python.exe, but I can't see any other useful purpose (if you only have the python executable and the .pdb available). Also, is there source code available for python24 for Windoze? I have seen reference to source code but not in a package for Windows. There is a single source package shared by all platforms. You can download and compile it, and you'll get your own version of python.pdb if you like. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: translating Python to Assembler
On 1/23/08, Christian Heimes [EMAIL PROTECTED] wrote: Wim Vander Schelden wrote: Python modules and scripts are normally not even compiled, if they have been, its probably just the Python interpreter packaged with the scripts and resources. No, that is not correct. Python code is compiled to Python byte code and execute inside a virtual machine just like Java or C#. It's even possible to write code with Python assembly and compile the Python assembly into byte code. You most certainly meant: Python code is not compiled into machine code. I didn't know that python uses a VM, I thought it still used an interpretter! You learn something new everyday :) Thanks, Wim -- http://mail.python.org/mailman/listinfo/python-list
Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?
Hello to all I am trying to learn python at the moment studying an example program (cftp.py from the twisted framework, if you want to know) There I found a line foo = (not f and 1) or 0 In this case f may be None or a string. If I am not wrong here, one could simply write foo = not f because if f = None: (not f) = true, (true and 1) = true, (true or 0) = true or if f = 'bar' (not f) = false (false and 1) = false (false or 0) = false So why bothering with the longer version? I hope, I made clear, what I want... CU Kristian -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML parsing confusion
On 2008-01-23 01:29, Gabriel Genellina wrote: En Tue, 22 Jan 2008 19:20:32 -0200, Alnilam [EMAIL PROTECTED] escribió: On Jan 22, 11:39 am, Diez B. Roggisch [EMAIL PROTECTED] wrote: Alnilam wrote: On Jan 22, 8:44 am, Alnilam [EMAIL PROTECTED] wrote: Pardon me, but the standard issue Python 2.n (for n in range(5, 2, -1)) doesn't have an xml.dom.ext ... you must have the mega-monstrous 200-modules PyXML package installed. And you don't want the 75Kb BeautifulSoup? Ugh. Found it. Sorry about that, but I still don't understand why there isn't a simple way to do this without using PyXML, BeautifulSoup or libxml2dom. What's the point in having sgmllib, htmllib, HTMLParser, and formatter all built in if I have to use use someone else's modules to write a couple of lines of code that achieve the simple thing I want. I get the feeling that this would be easier if I just broke down and wrote a couple of regular expressions, but it hardly seems a 'pythonic' way of going about things. This is simply a gross misunderstanding of what BeautifulSoup or lxml accomplish. Dealing with mal-formatted HTML whilst trying to make _some_ sense is by no means trivial. And just because you can come up with a few lines of code using rexes that work for your current use-case doesn't mean that they serve as general html-fixing-routine. Or do you think the rather long history and 75Kb of code for BS are because it's creator wasn't aware of rexes? I am, by no means, trying to trivialize the work that goes into creating the numerous modules out there. However as a relatively novice programmer trying to figure out something, the fact that these modules are pushed on people with such zealous devotion that you take offense at my desire to not use them gives me a bit of pause. I use non-included modules for tasks that require them, when the capability to do something clearly can't be done easily another way (eg. MySQLdb). I am sure that there will be plenty of times where I will use BeautifulSoup. In this instance, however, I was trying to solve a specific problem which I attempted to lay out clearly from the outset. I was asking this community if there was a simple way to use only the tools included with Python to parse a bit of html. There are lots of ways doing HTML parsing in Python. A common one is e.g. using mxTidy to convert the HTML into valid XHTML and then use ElementTree to parse the data. http://www.egenix.com/files/python/mxTidy.html http://docs.python.org/lib/module-xml.etree.ElementTree.html For simple tasks you can also use the HTMLParser that's part of the Python std lib. http://docs.python.org/lib/module-HTMLParser.html Which tools to use is really dependent on what you are trying to solve. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 23 2008) Python/Zope Consulting and Support ...http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 -- http://mail.python.org/mailman/listinfo/python-list
Re: difflib confusion
On 23/01/2008, Paul Hankin [EMAIL PROTECTED] wrote: On Jan 22, 6:57 pm, krishnakant Mane [EMAIL PROTECTED] wrote: hello all, I have a bit of a confusing question. firstly I wanted a library which can do an svn like diff with two files. let's say I have file1 and file2 where file2 contains some thing which file1 does not have. now if I do readlines() on both the files, I have a list of all the lines. I now want to do a diff and find out which word is added or deleted or changed. and that too on which character, if not at least want to know the word that has the change. any ideas please? Have a look at difflib in the standard library. I am aware of the difflib library but still can't figure out. I know that differences in two lines can be got but how to get it between words? regards, Krishna -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?
On Jan 23, 9:45 am, Kristian Domke [EMAIL PROTECTED] wrote: Hello to all I am trying to learn python at the moment studying an example program (cftp.py from the twisted framework, if you want to know) There I found a line foo = (not f and 1) or 0 In this case f may be None or a string. If I am not wrong here, one could simply write foo = not f because if f = None: (not f) = true, (true and 1) = true, (true or 0) = true or if f = 'bar' (not f) = false (false and 1) = false (false or 0) = false So why bothering with the longer version? I hope, I made clear, what I want... CU Kristian f = None foo = (not f and 1) or 0 # this gives you 1 f = None foo = not f # this gives you True -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML parsing confusion
The pages I'm trying to write this code to run against aren't in the wild, though. They are static html files on my company's lan, are very consistent in format, and are (I believe) valid html. Obvious way to check this is to go to http://validator.w3.org/ and see what it tells you about your html... -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?
Kristian Domke wrote: Hello to all I am trying to learn python at the moment studying an example program (cftp.py from the twisted framework, if you want to know) There I found a line foo = (not f and 1) or 0 In this case f may be None or a string. If I am not wrong here, one could simply write foo = not f because if f = None: (not f) = true, (true and 1) = true, (true or 0) = true or if f = 'bar' (not f) = false (false and 1) = false (false or 0) = false So why bothering with the longer version? Good catch! It's my guess that you've found a way to improve on a bit of carelessly written code. However there *is* a (subtle) difference between not f and (not f and 1) or 0 The first produces a boolean value, and the second produces an int value, but since one is a subclass of the other, you'd have to write quite perverse code care about the difference. Gary Herron I hope, I made clear, what I want... Quite. CU Kristian -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing objects
On Jan 22, 2008 10:59 PM, [EMAIL PROTECTED] wrote: I am writing a game, and it must keep a list of objects. I've been representing this as a list, but I need an object to be able to remove itself. It doesn't know it's own index. If I tried to make each object keep track of it's own index, it would be invalidated when any object with a lower index was deleted. The error was that when I called list.remove(self), it just removed the first thing in hte list with the same type as what I wanted, rather than the object I wanted. The objects have no identifying charachteristics, other than thier location in memory So my question: How do I look something up in a list by it's location in memory? does python even support pointers? Is there a better way? To put it simply, list.remove(self) ought to work. Are you sure it's not working? list.remove self doesn't delete the first matching type, it deletes the first object that IS what you passed, or failing that, it deletes the first object that == what you pass. I use an idiom often in my games, where rather than deleting objects on the fly, which is not very thread-safe in case you have something scanning through the objects, I set a property .kill on objects that are about to die, and then rebuild the list in the main loop with only objects that haven't been killed. I don't know if it's better, but it would probably work in your situation if list.remove(self) isn't working (which is strange). The other benefit of my idiom, is that objects don't need to have a reference to the object list, and any other function that wants to delete that object needs no other references besides the object itself. I have trouble with references a lot in complex games, and where I can I prefer not to have them. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?
Gary Herron napisał(a): However there *is* a (subtle) difference between not f and (not f and 1) or 0 The first produces a boolean value, and the second produces an int value, but since one is a subclass of the other, you'd have to write quite perverse code care about the difference. Twisted sems to be perverted to the root. -- Jarek Zgoda Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101 We read Knuth so you don't have to. (Tim Peters) -- http://mail.python.org/mailman/listinfo/python-list
Re: Hebrew in idle ans eclipse (Windows)
Recall: When I read data using sql I got a sequence like this: \x88\x89\x85 But when I entered heberw words directly in the print statement (or as a dictionary key) I got this: \xe8\xe9\xe5 Now, scanning the encoding module I discovered that cp1255 maps '\u05d9' to \xe9 while cp856 maps '\u05d9' to \x89, so trasforming \x88\x89\x85 to \xe8\xe9\xe5 is done by Hebrew Windows apparently uses cp1255 (aka windows-1255) as the ANSI code page, used in all GUI APIs, and cp856 as the OEM code page, used in terminal window - and, for some reason, in MS SQL. My qestion is, is there a way I can deduce cp856 and cp1255 from the string itself? That's not possible. You have to know where the string comes from. to know what the encoding is. In the specific case, if the string comes out of MS SQL, it apparently has cp856 (but I'm sure you can specify the client encoding somewhere in SQL server, or in pymssql) I don't know how IDLE guessed cp856, but it must have done it. I don't know why you think it did. You said you entered \xe9 directly into the source code in IDLE, so a) this is windows-1255, not cp856, and b) IDLE just *used* windows-1255 (i.e. the ANSI code page), it did not guess it. If you are claimaing that the program import pymssql con = pymssql.connect(host='192.168.13.122',user='sa',password='',database='tempdb') cur = con.cursor() cur.execute('select firstname, lastname from [users]') lines = cur.fetchall() print repr(lines[0]) does different things depending on whether it is run in IDLE or in a terminal window - I find that hard to believe. IDLE/Tk has nothing to do with that. It's the *repr* that you are printing, ie. all escaping has been done before IDLE/Tk even sees the text. So it must have been pymssql that returns different data in each case. It could be that the DB-API does such things, see http://msdn2.microsoft.com/en-us/library/aa937147(SQL.80).aspx Apparently, they do the OEMtoANSI conversion when you run a console application (i.e. python.exe), whereas they don't convert when running a GUI application (pythonw.exe). I'm not quite sure how they find out whether the program is a console application or not; the easiest thing to do might be to turn the autoconversion off on the server. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: python24 symbol file...pyhon24.pdb
Also, is there source code available for python24 for Windoze? I have seen reference to source code but not in a package for Windows. It's available from http://www.python.org/ftp/python/2.4/Python-2.4.tgz Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: python2.4-dbg and C modules
please, when I try to run my code under python2.4-dbg from Ubuntu, the interpreter complains that the Py_InitModule4 symbol is undefined in a C module I'm using (PyOpenAL): ImportError: /var/lib/python-support/python2.4/_openal.so: undefined symbol: Py_InitModule4 Google reveals that this problem is not specific just to PyOpenAL, but I couldn't find out what is the essence of the problem and how python-2.4dbg is different from python2.4 except for including debugging symbols, because in plain python2.4 the module works fine. The dbg version does not define Py_InitModule4, but Py_InitModule4TraceRefs. This is a safety-measure to prevent modules compiled for the nodebug version of Python to load into the debug version. There are major changes to the internal interpreter data structures in the debug version, so you have to recompile your module with the debug headers. HTH, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?
Sorry, posted to quickly. Yes your logic is correct about the logic of the return, but theirs actually differs in what it returns, and I am guessing it is an important change. Where is this foo used? Perhaps its value is used in a way a boolean return couldn't be? Just a note, with these kind of points it is often worth just opening up a python console and printing out the results. Though I do agree with you, at first look it seems almost redundant to use 1 and 0. Personally haven't seen this before, rather like it! :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?
Kristian Domke [EMAIL PROTECTED] wrote: foo = (not f and 1) or 0 In this case f may be None or a string. If I am not wrong here, one could simply write foo = not f Yes, it sounds pretty silly, and not just on the level you spotted. The only difference between the two expressions is that the original sets foo to an integer whereas your version sets it to a bool. So the question of which is most appropriate actually comes down to what foo is being used for. Is there really some code which requires a numeric value of 1 when f is None or an empty string and a value of 0 for any other string? I can't think offhand of any obvious situations where you would want that. My guess is that foo is being used later as a condition in an 'if' statement. If you really do need an integer then in Python 2.5+ another way to write it would be: foo = 0 if f else 1 Also 'foo' is a silly name since it gives no indication at about the purpose of the expression, but I'm hoping that was just you paraphrasing the code you posted. Ok, I just looked at the code, it is indeed being used as a boolean, so self.useProgressBar = not f or self.useProgressBar = f is not None if you want to be more specific about checking for None. -- http://mail.python.org/mailman/listinfo/python-list
InstallShield file properties issues
Hi, I am using Install Shield 11 express to create an upgrade package (msi) and came across an issue i.e. when installer installs the package it changes the created date of the files to modified date (changes created date with modified date), in my situation the files have modified date newer than the created date on source system and which I want to retain on the target system. That date difference helps me not to over write these files in next upgrade package. My questions are why Install Shield is showing that behavior or is there another reason for this? Is there any way to retain the created date, originally the file has? For this purpose I tested Install Shield's file properties options i.e. Use System Attributes which is used as, file installed with the same properties that it has on the development system, but it don't seems to be working in my case. Regards, Hassan -- http://mail.python.org/mailman/listinfo/python-list
what's wrong with the wmi.Terminate() method?
hi, here is my script: import win32con import time import wmi c = wmi.WMI() for process in c.Win32_Process(name = notepad.exe): print process.ProcessId, process.Name process.Terminate () when I have only one notepad.exe process in my system, this works fine, but when I have more than one notepad.exe , after terminal the first notepad.exe, the Terminate() for the second notepad.exe process will generate the following error: 3156 notepad.exe 6100 notepad.exe Traceback (most recent call last): File F:\thunder\python\program\wmi \create_terminal_notepad.py, line 16, in module process.Terminate () File C:\Python25\Lib\site-packages\wmi.py, line 376, in __call__ handle_com_error (error_info) File C:\Python25\Lib\site-packages\wmi.py, line 188, in handle_com_error raise x_wmi, \n.join (exception_string) wmi.x_wmi: -0x7ffdfff7 - 发生意外(ps: exception happened)。 Error in: SWbemObjectEx -0x7ffbeffe - 找不到(ps:Can not found) I don't know why this happend, is there somebody could give me a hand? -- http://mail.python.org/mailman/listinfo/python-list
Module/package hierarchy and its separation from file structure
Hello, In writing some non-trivial amount of Python code I keep running into an organizational issue. I will try to state the problem fairly generally, and follow up with a (contrived) example. The root cause of my difficulties is that by default, the relationship between a module hierarchy and the structure of files on disk is too strong for my taste. I want to separate the two as much as possible, but I do not want to resort to non-conventional hacks to do it. I am posting this in an attempt to present what I perceive to be a practical problem, and to get suggestions for solutions, or opinions on the most practical policy for how to deal with it. Like I said, I would like a weaker relationship between file system structure and module hierarchy. In particular there are two things I would like: * Least importantly, I don't like jamming code into __init__.py, as a personal preference. * Most importantly, I do not like to jam large amounts of code into a single source file, just for the purpose of keeping the public interface in the same package. An contrived but hopefully illustrative example: We have an organization Org, which has a library, and as part of that library is code that relates to doing something with animals. As a result, the interesting top-level package for this example is: org.lib.animal Suppose now that I want an initial implementation of the most important animal. I want to create the class (but see [1]): org.lib.animal.Monkey The public interface consists of that class only (and possibly a small handful of functions). The implementation is quite significant however - it is 500 lines of code long. At this point, we had to jam those 500 lines of code into __init__.py. Let's ignore my personal preference of not liking to put code in __init__.py; the fact remains that we have 500 lines of code in a single source file. Now, we want to continue working on this library, adding ten additional animals. At this point, we have these choices (it seems to me): (1) Simply add these to __init__.py, resulting in __init__.py being 5000 lines long[2]. (2) Put each animal into its own file, resulting in org.lib.animal.Monkey now becoming org.lib.animal.monkey.Monkey, and animal X becoming org.lib.animal.x.X. The problem I have is that both of these solutions are, in my opinion, very ugly: * (1) is ugly from a source code management perspective, because jamming 5000 lines of code for ten different animals into a single file is bad for obvious reasons. * (2) is ugly because we introduce org.lib.animal.x.X for animal X, which: (a) is redundant in terms of naming (b) redundant in function since we have a single package for each animal containing nothing but a single class of the same name Clearly, (1) is bad due to file/source structure reasons, and (2) is bad for module organizational reasons. So we are back to my original wish - I want to separate the two, so that I can solve (1) indepeendently of (2). Now, I realize that __init__.py can contain arbitrary code, and that one can override __import__. However, I do not want to resort to hacks just to solve this problem; I would prefer some established convention in the community, or at least something that is elegant. Does are people's thoughts on this problem? Let me just shoot down one possible suggestion right away, to show you what I am trying to accomplish: I do *not* want to simply break out X into org.lib.animal.x, and have org.lib.animal import org.lib.animal.x.X as X. While this naively solves the problem of being able to refer to X as org.lib.animal.X, the solution is anything but consistent because the *identity* of X is still org.lib.animal.x.X. Examples of way this breaks things: * X().__class__.__name__ gives unexpected results. * Automatically generated documentation will document using the real package name. * Moving the *actual* classes around by way of this aliasing would break things like pickled data structure as a result of the change of actual identity, unless one *always* pre-emptively maintains this shadow hierarchy (which is a problem in and of itself). Thus, it's not clean. It breaks the module abstraction and as a result has unintended consequences. I am looking for some kind of clean solution. What do people do about this in practice? [1] Optionally, we might introduce an animals package such that it would become org.lib.animal.animals.Monkey, if we thought we were going to have a lot of public API outside of the animals themselves. This does not affect this dicussion however, as the exact same thing would apply to org.lib.animal.animals as applies to org.lib.animal in the above example. [2] Ignoring for now that it may not be realistic that every animal implementation would be that long; in many cases a lot of code would be in common. But feel free to substitude for something else (a Zoo say). -- /
Re: what's wrong with the wmi.Terminate() method?
[EMAIL PROTECTED] wrote: [... snip same problem as reported to python-win32 ...] See my reply on python-win32. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: pairs from a list
On Tue, 22 Jan 2008 23:33:00 -0800, George Sakkis wrote: As I mentioned already, I consider the seeking of the most efficient solution a legitimate question, regardless of whether a dumb solution is fast enough for an application. Call it a don't be sloppy principle if you wish. Sure, by why do you limit efficient and don't be sloppy to mean write the fastest executing code you can, regardless of every other trade-off? Because there are trade-offs: * execution time * compilation time * memory use at run-time * size of source code on disk * size of compiled code on disk * ease of writing it in the first place * ease of maintenance * correctness * fragility in the face of malformed data * readability and ease of comprehension * elegance (however you judge that!) * making sure the usage of various resources never exceed some set of upper bounds etc. Some of these are relatively unimportant (e.g. the size of the source code), but others are extremely important and far too often ignored (e.g. readability and even correctness). In fact, fastest isn't even a meaningful attribute. Does it mean: * the worst-case is fastest * the best-case is fastest * the average-case is fastest * fastest on typical data * all of the above etc. What counts as typical data? How do you average all the cases? Asking what's the fastest without considering these issues is a good sign that the person asking is being sloppy, something you should be against. It's the same reason I always use xrange() instead of range() for a loop, although in practice the difference is rarely measurable. Well, that's (now) a no-brainer. Once upon a time, range() used to be faster for small enough lists, and whatever difference there is in readability is insignificant except for utter newbies, so there's no real trade-off to make unless you care about the extra x. But... do you write list.__len__() instead of len(list) to save a few nanoseconds? If you do, you're guilty of pessimization instead of optimization: for built-in lists, len() is actually faster, by a lot. It's only an optimization -- and a significant one -- for custom classes. So, do you write this: if isinstance(alist, list): value = len(alist) # optimize for lists else: value = alist.__len__() # optimize for classes every time you want the length of an arbitrary sequence? If you did, you'd be pessimizing again. That code runs nearly twice as slowly as just calling the built-in len(). Optimizing the parts doesn't mean you have optimized the whole. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Computer Laptops
Zenith Director Laptop, Lenovo Laptop Model No: 3000 Y500, HCL Notebook Model No: AXX2202, Zenith Presidio Laptop many model of laptop please visit - http://www.homeshop18.com/hs18shop/faces/tiles/category.jsp?catalogueID=2categoryID=920parentCategoryID=909q=sid=bid=prc=k1=k2=k3=k4=k5=k6=k7=k8=k9=k10=k11=k12= -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?
I am surprised nobody pointed out explicitely that True==1 and False==0 so that for instance 5*(True+True)==10 and even (but implementation-dependent) : 5*(True+True) is 10 BB -- http://mail.python.org/mailman/listinfo/python-list
Announcement: Python module for pacparser (parses proxy auto-config files)
Fellas, I am mighty pleased to announce the release of python module for pacparser. pacparser is a library to parse proxy auto-config (PAC) files. Proxy auto-config files are already a vastly used web proxy configuration method these days (either directly or via web proxy autodiscovery protocol) and almost all popular web browsers support them. pacparser python module brings in PAC file parsing capability to python programs. Using it, python web software can now work with proxy auto-config files. I am hoping, web software programmers will appreciate it. At least I've been looking for such a thing for a while :). For documentation and available packages, please visit project homepage at http://code.google.com/p/pacparser Direct download links: Source archive: http://pacparser.googlecode.com/files/pacparser-1.0.3.tar.gz Compiled module for python 2.5 and win32: http://pacparser.googlecode.com/files/pacparser-python25-1.0.3-win32.zip I have tested the module to work on Python 2.2 - 2.5 on Linux and Win32. Cheers :-), Manu -- Manu Garg http://www.manugarg.com Journey is the destination of life. -- http://mail.python.org/mailman/listinfo/python-list
Re: Module/package hierarchy and its separation from file structure
On Wed, 23 Jan 2008 03:49:56 -0600, Peter Schuller wrote: Let me just shoot down one possible suggestion right away, to show you what I am trying to accomplish: I do *not* want to simply break out X into org.lib.animal.x, and have org.lib.animal import org.lib.animal.x.X as X. Then you shoot down the idiomatic answer I guess. That's what most people do. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess and (ampersand)
Steven Bethard wrote: I'm having trouble using the subprocess module on Windows when my command line includes special characters like (ampersand):: command = 'lynx.bat', '-dump', 'http://www.example.com/?x=1y=2' kwargs = dict(stdin=subprocess.PIPE, ... stdout=subprocess.PIPE, ... stderr=subprocess.PIPE) proc = subprocess.Popen(command, **kwargs) proc.stderr.read() 'y' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n As you can see, Windows is interpreting that as separating two commands, instead of being part of the single argument as I intend it to be above. Is there any workaround for this? How do I get treated like a regular character using the subprocess module? A little experimentation suggests that the problem's somehow tied up with the .bat file. ie this works for me (doubly complicated because of the long firefox path: code import subprocess cmd = [ rc:\Program Files\Mozilla Firefox\firefox.exe, http://local.goodtoread.org/search?word=timcached=0; ] subprocess.Popen (cmd) /code but this doesn't: c:/temp/firefox.bat c:\Program Files\Mozilla Firefox\firefox.exe %* /c:/temp/firefox.bat code import subprocess cmd = [ rc:\temp\firefox.bat, http://local.goodtoread.org/search?word=timcached=0; ] subprocess.Popen (cmd) /code although, interestingly, it seems to cut off at the = before the . Not sure how significant that is. So, even assuming we're looking at the same situation, I suppose one solution for you is to break out the .bat file. But that may not be a possibility. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: UDP Client/Server
Guilherme Polo wrote: class FooRequestHandler(BaseRequestHandler): ... def handle(self): ... data, addr_info = self.request[1].recvfrom(65534) Your FooReceiveServer subclasses UDPServer, it already handled the recvfrom for you, so, this is wrong. hmm then why do I receive every second request, shouldn't then no data at all come up? Also the next thing that would be a problem would be if I do data = self.request[0] I do get the data but where would I get the info from to which endpoint I need to send the answer? martin -- http://noneisyours.marcher.name http://feeds.feedburner.com/NoneIsYours You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing objects
[EMAIL PROTECTED] wrote: I am writing a game, and it must keep a list of objects. I've been representing this as a list, but I need an object to be able to remove itself. It doesn't know it's own index. If I tried to make each object keep track of it's own index, it would be invalidated when any object with a lower index was deleted. The error was that when I called list.remove(self), it just removed the first thing in hte list with the same type as what I wanted, rather than the object I wanted. The objects have no identifying charachteristics, other than thier location in memory So my question: How do I look something up in a list by it's location in memory? does python even support pointers? Is there a better way? You could use a doubly linked list. The class 'deque' from collections is such a list but I don't known how to delete a specific element without this ugly (expensive?) rotate method. Here is my solution in pure Python #!/usr/bin/python import re class Queue(object): __slots__= 'Head', 'Tail', '__iter__','NNd' def __init__(self): self.Head= None self.Tail= None self.NNd= None def append(self,N): if self.Head == None: self.Head= N self.Tail= self N._enqueue_after(self.Tail) self.Tail= N def dequeue(self,N): Father, Son= N._dequeue() if self.Tail == N: self.Tail= Father if self.Head == N: self.Head= Son if self.Head == None: self.Tail= None def enqueue_after(self,N,Father): N._enqueue_after(Father) if self.Tail == Father: self.Tail= N def enqueue_before(self,N,Son): N._enqueue_before(Son) if self.Head == Son: self.Head= N def __iter__(self): next= self.Head # allows to dequeue the current element in a loop while True: current= next if current == None: raise StopIteration next= current._next() yield current class Node(object): # partially application specific __slots__= 'next', 'NNd','PNd','key','data' def __init__(self,Key,Data,P=None,N=None): # P = Previous N = Next if P != None: P.NNd= self if N != None: N.PNd= self self.PNd= P self.NNd= N self.key= Key self.data= Data def _enqueue_after(self,Father): self.NNd= Father.NNd self.PNd= Father Father.NNd= self def _enqueue_before(self,Son): self.NNd= Son self.PNd= Son.PNd Son.PNd= self def _dequeue(self): if self.PNd != None: self.PNd.NNd= self.NNd if self.NNd != None: self.NNd.PNd= self.PNd Father= self.PNd Son=self.NNd self.PNd= self.NNd= None return Father,Son def _next(self): return self.NNd def __str__(self): # highly application specific return '(%s:%s)' % (self.key,self.data) # some tests MyQ= Queue() MyQ.append( Node('HJ','3949') ) print MyQ.Head,MyQ.Tail,MyQ.Head.key MyQ.append( Node('CJ','10149') ) print MyQ.Head,MyQ.Tail,MyQ.Head.key N= MyQ.Head print queue: ,N.key,- N= N.NNd print next: ,N.key,- N= N.NNd if N != None: print next: ,N.key,- else: print no next: for N in MyQ: print loop-,N print N.key,N.data MyQ.dequeue(MyQ.Tail) print --- after dequeue print Head: ,MyQ.Head, Tail: ,MyQ.Tail for N in MyQ: print loop2-,N print N.key,N.data MyQ.dequeue(MyQ.Tail) print after second dequeue print Head: ,MyQ.Head, Tail: ,MyQ.Tail for N in MyQ: print loop3-,N print N.key,N.data ENJOY, Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany -- http://mail.python.org/mailman/listinfo/python-list
application error in python
hello group i am working on a project where most of the code has been written in c++ but the web component is written in python. Initially we have been using python2.4 and vs.net2003 but recently we decided to move ahead with python2.5 and vs.net2005. the problem that has been haunting me for while now is when i am trying to access a few functions in c++ through python by building .pyd extension, python.exe crashes saying an application error has occured any clues why this happened as everythiing was working well in .net2003 and python2.4 thanks abhishek -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess and (ampersand)
Steven Bethard wrote: I'm having trouble using the subprocess module on Windows when my command line includes special characters like (ampersand):: command = 'lynx.bat', '-dump', 'http://www.example.com/?x=1y=2' kwargs = dict(stdin=subprocess.PIPE, ... stdout=subprocess.PIPE, ... stderr=subprocess.PIPE) proc = subprocess.Popen(command, **kwargs) proc.stderr.read() 'y' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n As you can see, Windows is interpreting that as separating two commands, instead of being part of the single argument as I intend it to be above. Is there any workaround for this? How do I get treated like a regular character using the subprocess module? Although I'm sure you'll have looked into this already, the subprocess module on Windows is using CreateProcess pretty straightforwardly: http://msdn2.microsoft.com/en-us/library/ms682425(VS.85).aspx The docs there say that, to call a batch file, you need to specify the command interpreter with /c and pass the batch file, but as far as I can see it makes no difference! (Probably means there's a special-caser behind the scenes of CreateProcess). TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with processing XML
Hi, Paul Boddie wrote: People will, of course, tell you that you shouldn't use a DOM for anything and that the consensus is to use ElementTree or lxml (see above), but I can't help feeling that this has a damaging effect on the XML situation for Python: some newcomers would actually benefit from the traditional APIs, may already be familiar with them from other contexts, and may consider Python lacking if the support for them is in apparent decay. It requires a degree of motivation to actually attempt to maintain software providing such APIs (which was my solution to the problem), but if someone isn't totally bound to Python then they might easily start looking at other languages and tools in order to get the job done. I had a discussion with Java people lately and they were all for Ruby, Groovy and similar languages, because they have curly braces and are easy to learn when you know Java. My take on that is: Python is easy to learn, full-stop. It's the same for DOM: when you know DOM from (usually) the Java world, having a DOM-API in Python keeps you from having to learn too many new things. But when you get your nose kicked into ElementTree, having to learn new things will actually help you in understanding that what you knew before did not support your way of thinking. http://www.python.org/about/success/esr/ So, there is a learning curve, but it's much shorter than what you already invested to learn 'the wrong thing'. It's what people on this list tend to call their unlearning curve. Stefan -- http://mail.python.org/mailman/listinfo/python-list
wxpython
I am trying to open a file containing non displayable characters like contents an exe file. The is is with the below mentioned code: self.text_ctrl_1.SetValue(file_content) If the file_content contains non displayable characters I am getting an error like this: Traceback (most recent call last): File C:\Documents and Settings\joe_jacob\Desktop\notepad.py, line 102, in open_file self.text_ctrl_1.SetValue(file_content) File D:\softwares\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx \_controls.py, line 1708, in SetValue return _controls_.TextCtrl_SetValue(*args, **kwargs) File D:\softwares\Python25\lib\encodings\cp1252.py, line 15, in decode return codecs.charmap_decode(input,errors,decoding_table) UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 2: character maps to undefined I am trying to create an encryption program so if I open any file even if it is an exe file it should display in text ctrl. What is this problem with this ? How can I rectify this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing XML that's embedded in HTML
Hi, Mike Driscoll wrote: I got lxml to create a tree by doing the following: from lxml import etree from StringIO import StringIO parser = etree.HTMLParser() tree = etree.parse(filename, parser) xml_string = etree.tostring(tree) context = etree.iterparse(StringIO(xml_string)) No idea why you need the two steps here. lxml 2.0 supports parsing HTML in iterparse() directly when you pass the boolean html keyword. However, when I iterate over the contents of context, I can't figure out how to nab the row's contents: for action, elem in context: if action == 'end' and elem.tag == 'relationship': # do something...but what!? # this if statement probably isn't even right I would really encourage you to use the normal parser here instead of iterparse(). from lxml import etree parser = etree.HTMLParser() # parse the HTML/XML melange tree = etree.parse(filename, parser) # if you want, you can construct a pure XML document row_root = etree.Element(newroot) for row in tree.iterfind(//Row): row_root.append(row) In your specific case, I'd encourage using lxml.objectify: http://codespeak.net/lxml/dev/objectify.html It will allow you to do this (untested): from lxml import etree, objectify parser = etree.HTMLParser() lookup = objectify.ObjectifyElementClassLookup() parser.setElementClassLookup(lookup) tree = etree.parse(filename, parser) for row in tree.iterfind(//Row): print row.relationship, row.StartDate, row.Priority * 2.7 Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: UDP Client/Server
2008/1/23, Martin Marcher [EMAIL PROTECTED]: Guilherme Polo wrote: class FooRequestHandler(BaseRequestHandler): ... def handle(self): ... data, addr_info = self.request[1].recvfrom(65534) Your FooReceiveServer subclasses UDPServer, it already handled the recvfrom for you, so, this is wrong. hmm then why do I receive every second request, shouldn't then no data at all come up? Because you are blocked on that call waiting for data to come, so the second request will wake up there. Next request you will get blocked on this call again. Also the next thing that would be a problem would be if I do data = self.request[0] I do get the data but where would I get the info from to which endpoint I need to send the answer? self.client_address. Also, you could use self.packet to get the data martin -- http://noneisyours.marcher.name http://feeds.feedburner.com/NoneIsYours You are not free to read this message, by doing so, you have violated my licence and are required to urinate publicly. Thank you. -- http://mail.python.org/mailman/listinfo/python-list -- -- Guilherme H. Polo Goncalves -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a HTML parser who can reconstruct the original html EXACTLY?
On 2008-01-23, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I am looking for a HTML parser who can parse a given page into a DOM tree, and can reconstruct the exact original html sources. Why not keep a copy of the original data instead? That would be VERY MUCH SIMPLER than trying to reconstruct a parsed tree back to original source text. sincerely, Albert -- http://mail.python.org/mailman/listinfo/python-list
Re: wxpython
joe jacob wrote: I am trying to open a file containing non displayable characters like contents an exe file. The is is with the below mentioned code: self.text_ctrl_1.SetValue(file_content) If the file_content contains non displayable characters I am getting an error like this: Traceback (most recent call last): File C:\Documents and Settings\joe_jacob\Desktop\notepad.py, line 102, in open_file self.text_ctrl_1.SetValue(file_content) File D:\softwares\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx \_controls.py, line 1708, in SetValue return _controls_.TextCtrl_SetValue(*args, **kwargs) File D:\softwares\Python25\lib\encodings\cp1252.py, line 15, in decode return codecs.charmap_decode(input,errors,decoding_table) UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 2: character maps to undefined I am trying to create an encryption program so if I open any file even if it is an exe file it should display in text ctrl. What is this problem with this ? How can I rectify this? If I may be permitted a bit of levity at your expense: you're asking how to display non displayable characters! The most serious answer I can give is: how do you *want* to display those characters? What do you *expect* to appear in the text control. wxPython is trying to interpret your byte stream as a Unicode text stream encoded as cp1252. But it's not, so it gives up in a heap. One solution is to pass the repr of file_content. Another solution is for you to prefilter the text, replacing non-printables by their hex value or by some marker. Not much in it, really. code import random file_content = .join ( chr (random.randint (0, 255)) for i in range (1000) ) munged_text = .join ( c if 32 = ord (c) = 126 else hex (ord (c)) for c in file_content ) print repr (file_content) print munged_text /code TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing objects
On Tue, 22 Jan 2008 22:59:07 -0800, bladedpenguin wrote: I am writing a game, and it must keep a list of objects. I've been representing this as a list, but I need an object to be able to remove itself. It doesn't know it's own index. If I tried to make each object keep track of it's own index, it would be invalidated when any object with a lower index was deleted. The error was that when I called list.remove(self), it just removed the first thing in hte list with the same type as what I wanted, rather than the object I wanted. The objects have no identifying charachteristics, other than thier location in memory So my question: How do I look something up in a list by it's location in memory? does python even support pointers? That's the wrong question. It wouldn't even help you solve your problem. Example: alist = [object1, object2, object3, object4] object3 is at location 0xb7d27df4 in memory. Now how do you delete it from alist? You say that list.remove(self) just removed the first thing in the list with the same type -- that suggests a bug in your code, not in remove(). Perhaps self isn't what you think it is? Here's how it should work: class MyClass(object): def __init__(self, name): self.name = name def __repr__(self): return %s % self.name def delete_me(self, alist): alist.remove(self) obj1 = MyClass(Fred) obj2 = MyClass(Betty) obj3 = MyClass(Jill) alist = [obj1, obj2, obj3] Now let's see it in action: alist [Fred, Betty, Jill] obj3.delete_me(alist) # tell obj3 to delete itself from the list alist [Fred, Betty] Works fine. But what you can't do is create a NEW object, one that isn't in the list but just looks similar, and expect it to be removed: MyClass(Fred).delete_me(alist) # a different Fred. Traceback (most recent call last): File stdin, line 1, in module File stdin, line 7, in delete_me ValueError: list.remove(x): x not in list For that to work, you need to give your class an __eq__ method, and have it match by name: # put this in MyClass def __eq__(self, other): return self.name == self.other Now any instance MyClass(Fred) is equal to any other MyClass(Fred), and remove will work Is there a better way? You might also consider using a dictionary instead of a list. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?
On Wed, 23 Jan 2008 09:30:28 +, Duncan Booth wrote: Kristian Domke [EMAIL PROTECTED] wrote: foo = (not f and 1) or 0 In this case f may be None or a string. If I am not wrong here, one could simply write foo = not f Yes, it sounds pretty silly, and not just on the level you spotted. The only difference between the two expressions is that the original sets foo to an integer whereas your version sets it to a bool. So the question of which is most appropriate actually comes down to what foo is being used for. But since Python bools are subclasses from int, both of them are actually ints. One happens to look like 1, and the other looks like True. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing objects
On Jan 23, 2:24 am, Robert Kern [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: I am writing a game, and it must keep a list of objects. I've been representing this as a list, but I need an object to be able to remove itself. It doesn't know it's own index. If I tried to make each object keep track of it's own index, it would be invalidated when any object with a lower index was deleted. The error was that when I called list.remove(self), it just removed the first thing in hte list with the same type as what I wanted, rather than the object I wanted. The objects have no identifying charachteristics, other than thier location in memory By default, classes that do not implement the special methods __eq__ or __cmp__ get compared by identity; i.e. (x == y) == (x is y). Double-check your classes and their super-classes for implementations of one of these methods. mylist.remove(x) will check x is mylist[i] first and only check x == mylist[i] if that is False. In [1]: class A(object): ...: def __eq__(self, other): ...: print '%r == %r' % (self, other) ...: return self is other ...: def __ne__(self, other): ...: print '%r != %r' % (self, other) ...: return self is not other ...: ...: In [2]: As = [A() for i in range(10)] In [3]: As Out[3]: [__main__.A object at 0xf47f70, __main__.A object at 0xf47d90, __main__.A object at 0xf47db0, __main__.A object at 0xf47cb0, __main__.A object at 0xf47eb0, __main__.A object at 0xf47e70, __main__.A object at 0xf47cd0, __main__.A object at 0xf47e10, __main__.A object at 0xf47dd0, __main__.A object at 0xf47e90] In [4]: A0 = As[0] In [5]: A0 Out[5]: __main__.A object at 0xf47f70 In [6]: As.remove(A0) In [7]: As Out[7]: [__main__.A object at 0xf47d90, __main__.A object at 0xf47db0, __main__.A object at 0xf47cb0, __main__.A object at 0xf47eb0, __main__.A object at 0xf47e70, __main__.A object at 0xf47cd0, __main__.A object at 0xf47e10, __main__.A object at 0xf47dd0, __main__.A object at 0xf47e90] In [8]: A0 Out[8]: __main__.A object at 0xf47f70 In [9]: A9 = As[-1] In [10]: As.remove(A9) __main__.A object at 0xf47d90 == __main__.A object at 0xf47e90 __main__.A object at 0xf47db0 == __main__.A object at 0xf47e90 __main__.A object at 0xf47cb0 == __main__.A object at 0xf47e90 __main__.A object at 0xf47eb0 == __main__.A object at 0xf47e90 __main__.A object at 0xf47e70 == __main__.A object at 0xf47e90 __main__.A object at 0xf47cd0 == __main__.A object at 0xf47e90 __main__.A object at 0xf47e10 == __main__.A object at 0xf47e90 __main__.A object at 0xf47dd0 == __main__.A object at 0xf47e90 In [11]: As Out[11]: [__main__.A object at 0xf47d90, __main__.A object at 0xf47db0, __main__.A object at 0xf47cb0, __main__.A object at 0xf47eb0, __main__.A object at 0xf47e70, __main__.A object at 0xf47cd0, __main__.A object at 0xf47e10, __main__.A object at 0xf47dd0] In [12]: A9 Out[12]: __main__.A object at 0xf47e90 If you cannot find an implementation of __eq__ or __cmp__ anywhere in your code, please try to make a small, self-contained example like the one above but which demonstrates your problem. So my question: How do I look something up in a list by it's location in memory? does python even support pointers? If you need to keep an __eq__ that works by equality of value instead of identity, then you could keep a dictionary keyed by the id() of the object. That will correspond to its C pointer value in memory. In [13]: id(A9) Out[13]: 16023184 In [14]: hex(_) Out[14]: '0xf47e90' Is there a better way? Possibly. It looks like you are implementing a cache of some kind. Depending on exactly how you are using it, you might want to consider a weak dictionary instead. A weak dictionary, specifically a WeakValueDictionary, acts like a normal dictionary, but only holds a weak reference to the object. A weak reference does not increment the object's reference count like a normal (strong) reference would. Consequently, once all of the strong references disappear, the object will be removed from the WeakValueDictionary without your having to do anything explicit. If this corresponds with when you want the object to be removed from the cache, then you might want to try this approach. Use id(x) as the key if there is no more meaningful key that fits your application. http://docs.python.org/lib/module-weakref.html -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco So, in general, is it more efficient to use a dictionary or to override the __eq__ function? -- http://mail.python.org/mailman/listinfo/python-list
Re: translating Python to Assembler...sorry if this is duplicated...it's unintentional
My expertise, if any, is in assembler. I'm trying to understand Python scripts and modules by examining them after they have been disassembled in a Windows environment. Maybe you could also profit from diassembling Pythons bytecode into MNEmonics of the Python Virtual Machine ? http://docs.python.org/lib/module-dis.html Because disassembling python scripts with any other disassembler will not likely lead to something usefull: a) the .pyc and pyo files are in Python Bytecode, that is assembler for the Python Virtual Machine Processor, disassemble with the mentioned module b) python2x.dll is in i386-Assembler, but contains the virtual machine. Understanding that will you will learn a lot of great programming concepts from some of the most brilliant minds on this planet; but will give you no hint to understand Python scripts, as they are running on top of that VM. Like disassembling the Hybrid Power Drive of a Lexus GS450h will teach you nothing about navigating from Berlin to Paris. Best wishes, Harald -- http://mail.python.org/mailman/listinfo/python-list
Re: docbook and xmlproc
Tim Arnold wrote: I'm unable to get xmlproc to validate my docbook test file. This is new territory for me, so I'd appreciate any advice on what I'm doing wrong. Using python 2.4 on HPux10.20. I do not have much experience with xmlproc, but I'd encourage you to use lxml, which uses the parser and DTD validator of libxml2. http://codespeak.net/lxml/dev/ http://codespeak.net/lxml/dev/validation.html Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing objects
On Jan 23, 2008 9:55 AM, Steven D'Aprano [EMAIL PROTECTED] wrote: For that to work, you need to give your class an __eq__ method, and have it match by name: # put this in MyClass def __eq__(self, other): return self.name == self.other Do you mean: # put this in MyClass def __eq__(self, other): return self.name == other.name ? -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML parsing confusion
On Jan 23, 3:54 am, M.-A. Lemburg [EMAIL PROTECTED] wrote: I was asking this community if there was a simple way to use only the tools included with Python to parse a bit of html. There are lots of ways doing HTML parsing in Python. A common one is e.g. using mxTidy to convert the HTML into valid XHTML and then use ElementTree to parse the data. http://www.egenix.com/files/python/mxTidy.htmlhttp://docs.python.org/lib/module-xml.etree.ElementTree.html For simple tasks you can also use the HTMLParser that's part of the Python std lib. http://docs.python.org/lib/module-HTMLParser.html Which tools to use is really dependent on what you are trying to solve. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 23 2008) Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 Thanks. So far that makes 3 votes for BeautifulSoup, and one vote each for libxml2dom, pyparsing, and mxTidy. I'm sure those would all be great solutions, if I was looking to solve my coding question with external modules. Several folks have mentioned now that they think that if I have files that are valid XHTML, that I could use htmllib, HTMLParser, or ElementTree (all of which are part of the standard libraries in v 2.5). Skipping past html validation, and html to xhtml 'cleaning', and instead starting with the assumption that I have files that are valid XHTML, can anyone give me a good example of how I would use _ htmllib, HTMLParser, or ElementTree _ to parse out the text of one specific childNode, similar to the examples that I provided above using regex? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with processing XML
On 23 Jan, 12:03, Stefan Behnel [EMAIL PROTECTED] wrote: I had a discussion with Java people lately and they were all for Ruby, Groovy and similar languages, because they have curly braces and are easy to learn when you know Java. My take on that is: Python is easy to learn, full-stop. Well, that may be so, but it's somewhat beside the point in question. It's the same for DOM: when you know DOM from (usually) the Java world, having a DOM-API in Python keeps you from having to learn too many new things. But when you get your nose kicked into ElementTree, having to learn new things will actually help you in understanding that what you knew before did not support your way of thinking. I'm not disputing the benefits of the ElementTree approach, but one has to recall that the DOM is probably the most widely used XML API out there (being the one most client-side developers are using) and together with the other standards (XPath and so on) isn't as bad as most people like to make out. Furthermore, I don't think it does Python much good to have people acting all Ruby on Rails and telling people to throw out everything they ever did in order to suck up the benefits, regardless of the magnitude of those benefits; it comes across as saying that your experience counts for nothing compared to our superior skills. Not exactly the best way to keep people around. As I noted in my chronology, the kind of attitude projected by various people in the Python community at various times (and probably still perpetuated in the Ruby community) is that stuff originating from the W3C is bad like, for example, XSLT because it's like Lisp but all in XML (yuck!), and yet for many tasks the most elegant solution is actually XSLT because it's specifically designed for those very tasks. Fortunately or unfortunately, XSLT didn't make it into the standard library and thus isn't provided in a way which may or may not seem broken but, like the DOM stuff, if the support for standardised/ recognised technologies is perceived as deficient, and given the point above about glossing over what people themselves bring with them to solve a particular problem, then people are quite likely to gloss over Python than hear anyone's sermon about how great Python's other XML technologies are. http://www.python.org/about/success/esr/ So, there is a learning curve, but it's much shorter than what you already invested to learn 'the wrong thing'. It's what people on this list tend to call their unlearning curve. Well, maybe if someone helped the inquirer with his namespace problem he'd be getting along quite nicely with his unlearning curve. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: translating Python to Assembler
[EMAIL PROTECTED] wrote: My expertise, if any, is in assembler. I'm trying to understand Python scripts and modules by examining them after they have been disassembled in a Windows environment. IMHO, that approach doesn't make sense to understand scripts or modules (except if you have some kind of super brain -- because Python is _very_ high level). It only does if you want to understand the Python compiler/interpreter you use. For compilers that output machine code directly this *may* make sense (but for more complex programs it will become very difficult). If you'd like to get a low level look into how things are done in Python, try the dis module. Using dis.dis, you can look at disassembled Python byte code. Regards, Björn -- BOFH excuse #251: Processes running slowly due to weak power supply -- http://mail.python.org/mailman/listinfo/python-list
Re: translating Python to Assembler
Grant Edwards wrote: Trying to find assembly language stuff to look at is futile. Python doesn't get compiled into assembly language. So, how do processors execute Python scripts? :) If you want to learn Python, then read a book on Python. ACK. Regards, Björn -- BOFH excuse #198: Post-it Note Sludge leaked into the monitor. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem deriving form type long
Gabriel Genellina wrote: En Mon, 21 Jan 2008 18:33:10 -0200, Frederic Rentsch [EMAIL PROTECTED] escribió: Hi, here's something that puzzles me: class Fix_Point (long): def __init__ (self, l): long.__init__ (self, l * 0x1): fp = Fix_Point (99) fp 99 You have to override __new__, not __init__. Immutable types like numbers and tuples don't use __init__. See http://docs.python.org/ref/customization.html That's a big help! Thank you very much. Frederic -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing objects
bladedpenguin wrote: So, in general, is it more efficient to use a dictionary or to override the __eq__ function? Rule of thumb: If you want to add/remove arbitrary objects from a collection a dictionary (or set) is always faster than a list. You may still have to override the __eq__() and __hash__() methods whenever you have distinct objects that can be equal. Caveat: don't use dictionaries if the result of obj1 == obj2 # items in the dict can change during the lifetime of the collection. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Max Long
[EMAIL PROTECTED] wrote: Indeed, as the docs pointed out. I guess I was confused by If pylong is greater than ULONG_MAX, an OverflowError is raised. at http://docs.python.org/api/longObjects.html. Take care -- this is about unsigned long data type of C, not a Python long instance. Regards, Björn -- BOFH excuse #75: There isn't any problem -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a HTML parser who can reconstruct the original html EXACTLY?
On Jan 23, 7:39 pm, A.T.Hofkamp [EMAIL PROTECTED] wrote: On 2008-01-23, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I am looking for a HTML parser who can parse a given page into a DOM tree, and can reconstruct the exact original html sources. Why not keep a copy of the original data instead? That would be VERY MUCH SIMPLER than trying to reconstruct a parsed tree back to original source text. sincerely, Albert Thank u for your reply. but what I really need is the mapping between each DOM nodes and the corresponding original source segment. -- http://mail.python.org/mailman/listinfo/python-list
Re: translating Python to Assembler
Wim Vander Schelden wrote: I didn't know that python uses a VM, I thought it still used an interpretter! You learn something new everyday :) still? I don't think Python ever used a different model. Most modern languages are using an interpreted byte code approach: http://en.wikipedia.org/wiki/Interpreted_language#Languages_usually_compiled_to_a_virtual_machine_code IMHO .NET/C# is missing from the list. Christian -- http://mail.python.org/mailman/listinfo/python-list
pythonic backtrace with gdb
Hello, please, I'm trying to obtain a pythonic backtrace via gdb to be able to debug deadlock situations in a multi-threaded program by attaching to the running process. I'm running the program under python2.4-dbg, When I try to load the .gdbinit script obtained at http://wiki.python.org/moin/DebuggingWithGdb , gdb crashes however with the following error (full session listing): (gdb) attach 10753 Attaching to program: /usr/bin/python, process 10753 warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7fff575fd000 0x2b33537177fb in ?? () from /lib64/ld-linux-x86-64.so.2 (gdb) pystack /tmp/buildd/gdb-6.6.dfsg.90.20070912/gdb/regcache.c:164: internal-error: register_type: Assertion `regnum = 0 regnum descr-nr_cooked_registers' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) [answered Y; input not from terminal] /tmp/buildd/gdb-6.6.dfsg.90.20070912/gdb/regcache.c:164: internal-error: register_type: Assertion `regnum = 0 regnum descr-nr_cooked_registers' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Create a core file of GDB? (y or n) [answered Y; input not from terminal] Neúspěšně ukončen (SIGABRT) I've also tried to use the backtrace script here http://mashebali.com/?Python_GDB_macros:The_Macros:Backtrace But I get a different error: (gdb) pbt Invalid type combination in ordering comparison. I'm using GDB version 6.6.90. Could you please suggest what can I do to be able to get the backtrace? Thank you, Hynek Hanke -- http://mail.python.org/mailman/listinfo/python-list
Re: A global or module-level variable?
On Jan 22, 1:00 pm, Paul Rubin http://[EMAIL PROTECTED] wrote: If you have to do it that way, use: Is there a better way? A more Pythonic way? -- http://mail.python.org/mailman/listinfo/python-list
How avoid both a newline and a space between 2 print commands?
print foo print bar has a newline in between foo and bar print foo, print bar has a space in between foo and bar How prevent ANYTHING from going in between foo and bar ?? (Without defining a string variable.) Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a HTML parser who can reconstruct the original html EXACTLY?
On 23 Jan, 14:20, kliu [EMAIL PROTECTED] wrote: Thank u for your reply. but what I really need is the mapping between each DOM nodes and the corresponding original source segment. At the risk of promoting unfashionable DOM technologies, you can at least serialise fragments of the DOM in libxml2dom [1]: import libxml2dom d = libxml2dom.parseURI(http://www.diveintopython.org/;, html=1) print d.xpath(//p)[7].toString() Storage and retrieval of the original line and offset information may be supported by libxml2, but such information isn't exposed by libxml2dom. Paul [1] http://www.python.org/pypi/libxml2dom -- http://mail.python.org/mailman/listinfo/python-list
RE: question
Just wanted to say thanks to everyone for these helpful replies! I really appreciate it! :-) Jay -- http://mail.python.org/mailman/listinfo/python-list
A GUI framework for running simulations
Hello! I am currently working on writing a simulation engine for special relativity physics. I'm writing it in Python, of course. I'm doing fine with the engine, but I want a GUI framework in which I could use it conveniently, and test different setups on it. I'm not so strong with GUI programming. I looked at Tkinter, I looked at WxPython, I looked at PythonCard. It all looks pretty daunting. My question is, does there exist a GUI package that is intended specifically for simulations? I saw a program called Golly, which is a simulation for Conway's Game of Life. Its GUI had most of the features I needed. For example, you can load a setup, there are play and stop buttons, you can change a setup and save it, etc. So does anyone know of a general GUI framework for running simulations? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with processing XML
Hi, Paul Boddie wrote: I'm not disputing the benefits of the ElementTree approach, but one has to recall that the DOM is probably the most widely used XML API out there (being the one most client-side developers are using) and together with the other standards (XPath and so on) isn't as bad as most people like to make out. I didn't deny that it works in general. However, it does not fit into the standard ways things work in Python. Furthermore, I don't think it does Python much good to have people acting all Ruby on Rails and telling people to throw out everything they ever did in order to suck up the benefits, regardless of the magnitude of those benefits; it comes across as saying that your experience counts for nothing compared to our superior skills. Not exactly the best way to keep people around. I would have formulated it a bit different from my experience, which usually is: people complain on the list that they can't manage to get X to work for them. Others tell them: don't use X, use Y, implicitly suggesting that you may have to learn it, but it will help you get your problem done in a way that you can /understand/ (i.e. that will fix your code for you, by enabling you to fix it yourself). From my experience, this works in most (although admittedly not all) cases. But in any case, this reduction of complexity is an important step towards making people ask less questions. As I noted in my chronology, the kind of attitude projected by various people in the Python community at various times (and probably still perpetuated in the Ruby community) is that stuff originating from the W3C is bad The W3C is good in defining standards for portability and interoperability. APIs rarely fall into that bag. They should be language specific as they are made for use in a programming language, and therefore must match the way this language works. However, programming languages themselves are sometimes made for interoperability, and this is definitely true for XSLT and XQuery. I am a big fan of domain specific languages, because they (usually) are great in what they are designed for, and nothing more. like the DOM stuff, if the support for standardised/ recognised technologies is perceived as deficient, and given the point above about glossing over what people themselves bring with them to solve a particular problem, then people are quite likely to gloss over Python than hear anyone's sermon about how great Python's other XML technologies are. It's not about other XML technologies, it's only about making the standard XML technologies accessible and usable. It's about designing interfaces in a way that matches the tool people are using anyway, which in this case is Python. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: How avoid both a newline and a space between 2 print commands?
[EMAIL PROTECTED] wrote: print foo print bar has a newline in between foo and bar print foo, print bar has a space in between foo and bar How prevent ANYTHING from going in between foo and bar ?? (Without defining a string variable.) sys.stdout.write(foo) sys.stdout.write(bar) Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: How avoid both a newline and a space between 2 print commands?
Hi, Use import sys sys.stdout.write(foo) sys.stdout.write(bar) (and, possibly, sys.stdout.flush() to get the text to show up, it might wait for the end of a complete line otherwise). The alternative import sys print foo, sys.stdout.softspace=0 print bar is just too hackish. In Python 3, this will be improved! Remco On Jan 23, 2008 3:03 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: print foo print bar has a newline in between foo and bar print foo, print bar has a space in between foo and bar How prevent ANYTHING from going in between foo and bar ?? (Without defining a string variable.) Chris -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: A GUI framework for running simulations
2008/1/23, [EMAIL PROTECTED] [EMAIL PROTECTED]: Hello! I am currently working on writing a simulation engine for special relativity physics. I'm writing it in Python, of course. I'm doing fine with the engine, but I want a GUI framework in which I could use it conveniently, and test different setups on it. I'm not so strong with GUI programming. I looked at Tkinter, I looked at WxPython, I looked at PythonCard. It all looks pretty daunting. My question is, does there exist a GUI package that is intended specifically for simulations? I saw a program called Golly, which is a simulation for Conway's Game of Life. Its GUI had most of the features I needed. For example, you can load a setup, there are play and stop buttons, you can change a setup and save it, etc. Golly uses wxWidgets, and if you are planning to use Python then you would be using wxPython. So does anyone know of a general GUI framework for running simulations? All them serves this purpose. The main part of your gui application will be a custom widget that you will need to do yourself. -- http://mail.python.org/mailman/listinfo/python-list -- -- Guilherme H. Polo Goncalves -- http://mail.python.org/mailman/listinfo/python-list
csv to xls using python 2.1.3
Hi I need to convert a .csv file to .xls file using python 2.1.3 which means I can't use pyExcelerator! Does anyone know how I can do this? Many thanks LizzyLiz -- http://mail.python.org/mailman/listinfo/python-list
twisted: problem with sftp-client
Hello Folks, I don't know, if it is ok to post large portions of code, but I have really no idea where the problem lies, so I don't have much of a choice. I am programming a tool, which in the end shall connect to an sftp-server, take the list of files in a specified directory, searches for some special names and mailes them to different persons. I am only at the start at the moment. As orientation I use the cftp.py programm from twisted.conch with some alterations because of not having userinteraction. At its current state the programm should do nothing but getting the listing of files from a server. It works fine with the cfto.py, so the server is ok. But while the cftp.py script gets 'files' as an exceptions.EOFError exeption in the StdioClient._cbReadFile at the end of the listing, I just get another list and run into wall (aka Traceback): 2008/01/23 16:14 +0200 [SSHChannel session (0) on SSHService ssh-connection on SimpleTransport,client] Unhandled Error Traceback (most recent call last): File /usr/lib/python2.5/site-packages/twisted/python/log.py, line 48, in callWithLogger return callWithContext({system: lp}, func, *args, **kw) File /usr/lib/python2.5/site-packages/twisted/python/log.py, line 33, in callWithContext return context.call({ILogContext: newCtx}, func, *args, **kw) File /usr/lib/python2.5/site-packages/twisted/python/context.py, line 59, in callWithContext return self.currentContext().callWithContext(ctx, func, *args, **kw) File /usr/lib/python2.5/site-packages/twisted/python/context.py, line 37, in callWithContext return func(*args,**kw) --- exception caught here --- File /usr/lib/python2.5/site-packages/twisted/conch/ssh/filetransfer.py, line 52, in dataReceived f(data) File /usr/lib/python2.5/site-packages/twisted/conch/ssh/filetransfer.py, line 694, in packet_STATUS msg, data = getNS(data) File /usr/lib/python2.5/site-packages/twisted/conch/ssh/common.py, line 39, in getNS l, = struct.unpack('!L',s[c:c+4]) File struct.py, line 87, in unpack return o.unpack(s) struct.error: unpack requires a string argument of length 4 I have no Idea, and hope here is someone who can help me. Kristian from twisted.internet import reactor, defer, protocol from twisted.conch.ssh import connection, filetransfer, keys, userauth from twisted.conch.ssh import channel, transport, common from twisted.conch.client import options, default, connect from twisted.python import log, failure import sys, time publicKey = 'some public key' privateKey ='''some private key''' USER = 'sftpuser' def run(): opts = options.ConchOptions() opts['host'] = 'localhost' opts['user'] = USER opts['port'] = 22 log.startLogging(sys.stdout) log.msg('logging started') protocol.ClientCreator(reactor, SimpleTransport).connectTCP(opts['host'], opts['port']) reactor.run() # start the event loop def doConnect(options): host = options['host'] user = options['user'] port = options['port'] conn = SSHConnection vhk = default.verifyHostKey uao = UserAuthClient(user, conn) d = connect.connect(host, port, options, vhk, uao) d.addErrback(_ebExit) return d def _ebExit(f): if hasattr(f.value, 'value'): s =f.value.value else: s = str(f) log.msg( s ) try: reactor.stop() except: pass def _cleanExit(): try: reactor.stop() except: pass class SimpleTransport(transport.SSHClientTransport): def verifyHostKey(self, hostKey, fingerprint): log.msg('host key fingerprint: %s' % fingerprint) return defer.succeed(1) def connectionSecure(self): self.requestService( UserAuthClient(USER, SSHConnection())) class UserAuthClient(userauth.SSHUserAuthClient): Simple User Authentication Client def getPassword(self, prompt = None): return # this says we won't do password authentication def getPublicKey(self): return keys.getPublicKeyString(data = publicKey) def getPrivateKey(self): return defer.succeed(keys.getPrivateKeyObject(data = privateKey)) class SSHConnection(connection.SSHConnection): def serviceStarted(self): log.msg('Service started') self.openChannel(SSHSession(conn = self)) class SSHSession(channel.SSHChannel): name = 'session' def channelOpen(self, irgnoreData): log.msg('session %s is open' % self.id) request = 'subsystem' d = self.conn.sendRequest(self, request, common.NS('sftp'), wantReply=1) d.addCallback(self._cbSubsystem) d.addErrback(_ebExit) return d def _cbSubsystem(self, result): log.msg('Establishing Subsystem') self.client = SFTPClient()
Re: csv to xls using python 2.1.3
LizzyLiz wrote: Hi I need to convert a .csv file to .xls file using python 2.1.3 which means I can't use pyExcelerator! Does anyone know how I can do this? Many thanks LizzyLiz Use win32com.client to start Excel, tell it to .Open the .csv file and then tell it to .SaveAs an Excel workbook. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: A GUI framework for running simulations
Hi, check SimPy module and then http://www.showmedo.com/videos/series?name=pythonThompsonVPythonSeries KM On Jan 23, 2008 8:10 PM, Guilherme Polo [EMAIL PROTECTED] wrote: 2008/1/23, [EMAIL PROTECTED] [EMAIL PROTECTED]: Hello! I am currently working on writing a simulation engine for special relativity physics. I'm writing it in Python, of course. I'm doing fine with the engine, but I want a GUI framework in which I could use it conveniently, and test different setups on it. I'm not so strong with GUI programming. I looked at Tkinter, I looked at WxPython, I looked at PythonCard. It all looks pretty daunting. My question is, does there exist a GUI package that is intended specifically for simulations? I saw a program called Golly, which is a simulation for Conway's Game of Life. Its GUI had most of the features I needed. For example, you can load a setup, there are play and stop buttons, you can change a setup and save it, etc. Golly uses wxWidgets, and if you are planning to use Python then you would be using wxPython. So does anyone know of a general GUI framework for running simulations? All them serves this purpose. The main part of your gui application will be a custom widget that you will need to do yourself. -- http://mail.python.org/mailman/listinfo/python-list -- -- Guilherme H. Polo Goncalves -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: csv to xls using python 2.1.3
Perfect! Thanks :-) LizzyLiz -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess and (ampersand)
Tim Golden [EMAIL PROTECTED] wrote: but this doesn't: c:/temp/firefox.bat c:\Program Files\Mozilla Firefox\firefox.exe %* /c:/temp/firefox.bat code import subprocess cmd = [ rc:\temp\firefox.bat, http://local.goodtoread.org/search?word=timcached=0; ] subprocess.Popen (cmd) /code You need to use double quotes both in the .BAT file and in the string you pass to subprocess.Popen(). Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] [EMAIL PROTECTED] -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess and (ampersand)
Ross Ridge wrote: Tim Golden [EMAIL PROTECTED] wrote: but this doesn't: c:/temp/firefox.bat c:\Program Files\Mozilla Firefox\firefox.exe %* /c:/temp/firefox.bat code import subprocess cmd = [ rc:\temp\firefox.bat, http://local.goodtoread.org/search?word=timcached=0; ] subprocess.Popen (cmd) /code You need to use double quotes both in the .BAT file and in the string you pass to subprocess.Popen(). Ross Ridge In the context of my example above, could you just say which bit you thing should be quoted and isn't? (That sounds sarcastic, but isn't; I just want to understand if I've missed something). If you simply requote the second element in the cmd list ('http:/.') then the internal quotes are escaped by some part of the mechanism and it still doesn't work. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: A GUI framework for running simulations
[EMAIL PROTECTED] wrote: Hello! I am currently working on writing a simulation engine for special relativity physics. I'm writing it in Python, of course. I'm doing fine with the engine, but I want a GUI framework in which I could use it conveniently, and test different setups on it. I'm not so strong with GUI programming. I looked at Tkinter, I looked at WxPython, I looked at PythonCard. It all looks pretty daunting. My question is, does there exist a GUI package that is intended specifically for simulations? I saw a program called Golly, which is a simulation for Conway's Game of Life. Its GUI had most of the features I needed. For example, you can load a setup, there are play and stop buttons, you can change a setup and save it, etc. So does anyone know of a general GUI framework for running simulations? although quit premature, PyLab_Works might be of interest, see some demos here (watch the demo at the bottom first): http://oase.uci.kun.nl/~mientki/data_www/pylab_works/pw_animations_screenshots.html (you can contact me offline if PyLab_Works looks interesting to you). cheers, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Re: How avoid both a newline and a space between 2 print commands?
On Jan 23, 9:03 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: print foo print bar has a newline in between foo and bar print foo, print bar has a space in between foo and bar How prevent ANYTHING from going in between foo and bar ?? (Without defining a string variable.) Chris print %s%s % (foo, bar) ## If %s%s doesn't violate your condition of not defining a string variable, I'm not sure. -- http://mail.python.org/mailman/listinfo/python-list
Python CGI script and CSS style sheet
All: I'm working with a Python CGI script that I am trying to use with an external CSS (Cascading Style Sheet) and it is not reading it from the web server. The script runs fine minus the CSS formatting. Does anyone know if this will work within a Python CGI? It seems that line 18 is not being read properly. One more thing. I tested this style sheet with pure html code (no python script) and everything works great. Listed below is a modified example. ++ 1#!/usr/bin/python 2 3import cgi 4 5print Content-type: text/html\n 6tag_form = cgi.FieldStorage() 7 8head_open_close = 9head 10 meta http-equiv=content-type content=text/html; charset=UTF-8 11 titleTag Sheet/title 12 link rel=stylesheet type=text/css href=central.css 13 /head 14 15 body_open = 16 body 17 !-- tag page -- 18 table class=tag-sheet 19tbody 20 Thank you, Christopher -- http://mail.python.org/mailman/listinfo/python-list
Lxml on mac
Hi, What to one do if one what to use lxml(http://codespeak.net/lxml/ index.html) on a mac? Best regards -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a HTML parser who can reconstruct the original html EXACTLY?
Hi, kliu wrote: what I really need is the mapping between each DOM nodes and the corresponding original source segment. I don't think that will be easy to achieve. You could get away with a parser that provides access to the position of an element in the source, and then map changes back into the document. But that won't work well in the case where the parser inserts or deletes content to fix up the structure. Anyway, the normal focus of broken HTML parsing is in fixing the source document, not in writing out a broken document. Maybe we could help you better if you explained what your actual intention is? Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Lxml on mac
[EMAIL PROTECTED] wrote: What to one do if one what to use lxml(http://codespeak.net/lxml/ index.html) on a mac? Have you tried installing up-to-date versions of libxml2/libxslt and running easy_install lxml ? Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with processing XML
On 23 Jan, 15:12, Stefan Behnel [EMAIL PROTECTED] wrote: Paul Boddie wrote: I'm not disputing the benefits of the ElementTree approach, but one has to recall that the DOM is probably the most widely used XML API out there (being the one most client-side developers are using) and together with the other standards (XPath and so on) isn't as bad as most people like to make out. I didn't deny that it works in general. However, it does not fit into the standard ways things work in Python. You're only one step away from using the magic word. I agree that writing getAttribute all the time instead of, say, using magic attributes (provided the characters employed are lexically compatible with Python - another thing that people tend to overlook) can be distressing for some people, but as usual the language comes to the rescue: you can assign the method to a shorter name, amongst other things. If you want to stray from the standards then with some APIs (as you know), you can override various classes and provide your own convenience attributes and methods, but the interoperability remains beneath. Furthermore, I don't think it does Python much good to have people acting all Ruby on Rails and telling people to throw out everything they ever did in order to suck up the benefits, regardless of the magnitude of those benefits; it comes across as saying that your experience counts for nothing compared to our superior skills. Not exactly the best way to keep people around. I would have formulated it a bit different from my experience, which usually is: people complain on the list that they can't manage to get X to work for them. Others tell them: don't use X, use Y, implicitly suggesting that you may have to learn it, but it will help you get your problem done in a way that you can /understand/ (i.e. that will fix your code for you, by enabling you to fix it yourself). If people feel that they've solved 90% of the problem using tools they're become familiar with, I think it's somewhat infuriating to be told to forget about the last 10% and to use something else. We don't know how nasty the code is in the case of this particular inquirer, but I've seen nothing recently where the DOM specifically was obstructing anyone's comprehension. In one case, had PyXML or minidom been up-to-date, the solution would have been within easy reach (the textContent property), but with everyone being waved off to greener pastures, there's probably little gratitude to be had in doing the legwork to fix and enhance those implementations. [...] like the DOM stuff, if the support for standardised/ recognised technologies is perceived as deficient, and given the point above about glossing over what people themselves bring with them to solve a particular problem, then people are quite likely to gloss over Python than hear anyone's sermon about how great Python's other XML technologies are. It's not about other XML technologies, it's only about making the standard XML technologies accessible and usable. It's about designing interfaces in a way that matches the tool people are using anyway, which in this case is Python. Well, the standard XML technologies include those covered by PyXML, like it or not, and whilst some APIs may be nicer than the variants of the standard APIs provided by PyXML, there's a lot of potential in those standards that hasn't been exploited in Python. Consider why the last Web browser of note written in Python was Grail, circa 1996, for example. Paul -- http://mail.python.org/mailman/listinfo/python-list
Python printing!
Hy. How to use printer in python. I goggled little i I found only some win32 package which doesn't look processing for cross platform application. (I'm using USB printer and I tried to f=open(dev/...) usb port but i couldn't fond where printer is! Tnx! SMALLp -- http://mail.python.org/mailman/listinfo/python-list
Re: twisted: problem with sftp-client
On Wed, 23 Jan 2008 15:43:47 +0100, Kristian Domke [EMAIL PROTECTED] wrote: Hello Folks, I don't know, if it is ok to post large portions of code, but I have really no idea where the problem lies, so I don't have much of a choice. I am programming a tool, which in the end shall connect to an sftp-server, take the list of files in a specified directory, searches for some special names and mailes them to different persons. I am only at the start at the moment. As orientation I use the cftp.py programm from twisted.conch with some alterations because of not having userinteraction. At its current state the programm should do nothing but getting the listing of files from a server. It works fine with the cfto.py, so the server is ok. But while the cftp.py script gets 'files' as an exceptions.EOFError exeption in the StdioClient._cbReadFile at the end of the listing, I just get another list and run into wall (aka Traceback): 2008/01/23 16:14 +0200 [SSHChannel session (0) on SSHService ssh-connection on SimpleTransport,client] Unhandled Error Traceback (most recent call last): File /usr/lib/python2.5/site-packages/twisted/python/log.py, line 48, in callWithLogger return callWithContext({system: lp}, func, *args, **kw) File /usr/lib/python2.5/site-packages/twisted/python/log.py, line 33, in callWithContext return context.call({ILogContext: newCtx}, func, *args, **kw) File /usr/lib/python2.5/site-packages/twisted/python/context.py, line 59, in callWithContext return self.currentContext().callWithContext(ctx, func, *args, **kw) File /usr/lib/python2.5/site-packages/twisted/python/context.py, line 37, in callWithContext return func(*args,**kw) --- exception caught here --- File /usr/lib/python2.5/site-packages/twisted/conch/ssh/filetransfer.py, line 52, in dataReceived f(data) File /usr/lib/python2.5/site-packages/twisted/conch/ssh/filetransfer.py, line 694, in packet_STATUS msg, data = getNS(data) File /usr/lib/python2.5/site-packages/twisted/conch/ssh/common.py, line 39, in getNS l, = struct.unpack('!L',s[c:c+4]) File struct.py, line 87, in unpack return o.unpack(s) struct.error: unpack requires a string argument of length 4 I have no Idea, and hope here is someone who can help me. Kristian [snip] def _cbOpenList(self, directory): files = [] log.msg('direc.:%s' % str(directory)) log.msg('direc.:%s' % type(directory)) log.msg('direc.:%s' % str(directory.parent)) log.msg('direc.:%s' % type(directory.parent)) d = directory.read() d.addCallback(self._cbReadFile, files, directory) d.addErrback(self._ebRaeadFile, files, directory) You typo'd the errback method name above. This doesn't cause the problem you're having, though. There appears to be a bug in FX_EOF handling in filetransfer.py which results in the problem you see. It's not completely clear to me why cftp.py doesn't encounter the same issue. I filed #3009 in the Twisted issue tracker for this problem. I twiddled the source a bit and seem to have fixed it, so I think the issue should be easily resolvable. If you want, you can help out with this by writing unit tests for the issue and submitting a patch. Contributing to Twisted is described on this page: http://twistedmatrix.com/trac/wiki/TwistedDevelopment Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML parsing confusion
On Jan 23, 2008 7:40 AM, Alnilam [EMAIL PROTECTED] wrote: Skipping past html validation, and html to xhtml 'cleaning', and instead starting with the assumption that I have files that are valid XHTML, can anyone give me a good example of how I would use _ htmllib, HTMLParser, or ElementTree _ to parse out the text of one specific childNode, similar to the examples that I provided above using regex? Have you looked at any of the tutorials or sample code for these libraries? If you had a specific question, you will probably get more specific help. I started writing up some sample code, but realized I was mostly reprising the long tutorial on SGMLLib here: http://www.boddie.org.uk/python/HTML.html -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Lxml on mac
On Jan 23, 4:19 pm, Stefan Behnel [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: What to one do if one what to use lxml(http://codespeak.net/lxml/ index.html) on a mac? Have you tried installing up-to-date versions of libxml2/libxslt and running easy_install lxml ? Stefan No not yet. That was my nest step. But do anybody know if there is an easy way to use schema validation in python(on a mac) ? -- http://mail.python.org/mailman/listinfo/python-list
Re: A GUI framework for running simulations
On Jan 23, 5:12 pm, Stef Mientki [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Hello! I am currently working on writing a simulation engine for special relativity physics. I'm writing it in Python, of course. I'm doing fine with the engine, but I want a GUI framework in which I could use it conveniently, and test different setups on it. I'm not so strong with GUI programming. I looked at Tkinter, I looked at WxPython, I looked at PythonCard. It all looks pretty daunting. My question is, does there exist a GUI package that is intended specifically for simulations? I saw a program called Golly, which is a simulation for Conway's Game of Life. Its GUI had most of the features I needed. For example, you can load a setup, there are play and stop buttons, you can change a setup and save it, etc. So does anyone know of a general GUI framework for running simulations? although quit premature, PyLab_Works might be of interest, see some demos here (watch the demo at the bottom first):http://oase.uci.kun.nl/~mientki/data_www/pylab_works/pw_animations_sc... (you can contact me offline if PyLab_Works looks interesting to you). cheers, Stef Mientki Thank you, Stef and Guilherme. I'll be checking those things out. If anyone else who has an idea for something that can help me, I'll be happy to hear it! Ram. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGTK, Glade, and ComboBoxEntry.append_text()
On Jan 21, 5:44 pm, Greg Johnston [EMAIL PROTECTED] wrote: Hey all, I'm a relative newbie to Python (switched over from Scheme fairly recently) but I've been usingPyGTKand Glade to create an interface, which is a combo I'm very impressed with. There is, however, one thing I've been wondering about. It doesn't seem possible to modifyComboBoxEntrychoice options on the fly--at least with append_text(), etc--because they were not created with gtk.combo_box_entry_new_text(). Basically, I'm wondering if there's any way around this. Thank you, Greg Johnston P.S. If anyone reads this later wondering how to do it, all you need to do is prime the ComboBoxEntry with a blank entry in Glade. You can then use append_text(), insert_text(), etc. on the object, as well as remove_text(0) to get rid of your blank entry. -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing XML that's embedded in HTML
John and Stefan, On Jan 23, 5:33 am, Stefan Behnel [EMAIL PROTECTED] wrote: Hi, Mike Driscoll wrote: I got lxml to create a tree by doing the following: from lxml import etree from StringIO import StringIO parser = etree.HTMLParser() tree = etree.parse(filename, parser) xml_string = etree.tostring(tree) context = etree.iterparse(StringIO(xml_string)) No idea why you need the two steps here. lxml 2.0 supports parsing HTML in iterparse() directly when you pass the boolean html keyword. I don't know why I have 2 steps either, now that I look at it. However, I don't do enough XML parsing to get real familiar with the ins and outs of Python parsing either, so it's mainly just my inexperience. And I also got lost in the lxml tutorials... However, when I iterate over the contents of context, I can't figure out how to nab the row's contents: for action, elem in context: if action == 'end' and elem.tag == 'relationship': # do something...but what!? # this if statement probably isn't even right I would really encourage you to use the normal parser here instead of iterparse(). from lxml import etree parser = etree.HTMLParser() # parse the HTML/XML melange tree = etree.parse(filename, parser) # if you want, you can construct a pure XML document row_root = etree.Element(newroot) for row in tree.iterfind(//Row): row_root.append(row) In your specific case, I'd encourage using lxml.objectify: http://codespeak.net/lxml/dev/objectify.html It will allow you to do this (untested): from lxml import etree, objectify parser = etree.HTMLParser() lookup = objectify.ObjectifyElementClassLookup() parser.setElementClassLookup(lookup) tree = etree.parse(filename, parser) for row in tree.iterfind(//Row): print row.relationship, row.StartDate, row.Priority * 2.7 Stefan I'll give your ideas a go and also see if what the others posted will be cleaner or faster. Thank you all. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Just for fun: Countdown numbers game solver
Hi Arnaud and Dan Arnaud == Arnaud Delobelle [EMAIL PROTECTED] writes: What was wrong with the very fast(?) code you sent earlier? Arnaud I thought it was a bit convoluted, wanted to try something I Arnaud thought had more potential. I think the problem with the second Arnaud one is that I repeat the same 'fold' too many times. and later: Arnaud Yes, I've been doing this by writing an 'action' (see my code) that Arnaud takes note of all reached results. These are both comments about pruning, if I understand you. In the first you weren't pruning enough and in the second you're planning to prune more. I'm giving up thinking about this problem because I've realized that the pruning solution is fundamentally subjective. I.e., whether or not you consider two solutions to be the same depends on how hard you're willing to think about them (and argue that they're the same), or how smart you are. I have a new version that does some things nicely, but in trying to do efficient pruning, I've realized that you can't satisfy everyone. Some examples for the problem with target 253, numbers = 100, 9, 7, 6, 3, 1 Firstly, there are nice solutions that go way negative, like: 1 7 6 3 9 sub mul mul sub or 1 - 7 * 6 * (3 - 9) Here's a pruning example. Are these the same? 1 3 7 100 9 sub sub mul sub or 1 - 3 * (7 - 100 - 9) 1 3 7 9 100 sub add mul sub or 1 - 3 * (7 - 9 - 100) I think many people would argue that that's really the same and that one of the two should not appear in the output. The same goes for your earlier example for 406. It's 4 * 100 + 2 x 3, and 2 x 3 + 100 * 4, and so on. My latest program does all these prunings. But you can argue that you should push even further into eliminating things that are the same. You could probably make a pretty fast program that stores globally all the states it has passed through (what's on the stack, what numbers are yet to be used, what's the proposed op) and never does them again. But if you push that, you'll wind up saying that any two solutions that look like this: ... 1 add e.g. 6 9 3 sub mul 7 mul 1 add or 6 * (9 - 3) * 7 + 1 7 6 mul 9 3 sub mul 1 add or 7 * 6 * (9 - 3) + 1 are the same. And if we go that far, then a really smart person might argue that this 100 7 sub 9 sub 3 mul 1 add or (100 - 7 - 9) * 3 + 1 is also the same (because all these solutions get to 252 and then add 1, so they're clearly the same, right?): Once you've gone that far, you might even argue that on a particular problem of a particular difficulty (subjectively matching what your brain is capable of) all solutions that start out by pushing 1 onto the stack are actually the same. And if you're even smarter than that, you might just look at any problem and say Hey, that's easy! The answer is X or There's clearly no solution because you'd immediately just see the answer (if any) and that all others were just obvious variants. E.g., if I said to you: make 20 out of (20, 10, 10, 3), I imagine you could immediately list the answer(s?) 20 = 20 20 = 10 + 10 20 = 20 + 10 - 10 20 = 20 - 10 + 10 etc., and explain that those are all really the same. You'd prune on the spot, and consider it obvious that the pruning was fully justified. But my 6-year-old son couldn't tell you that, and I doubt he'd agree with your prunings. OK, enough examples. I'm just trying to illustrate that the (difficult) problem of efficiently pruning doesn't have an objective solution. Pruning is subjective. OTOH, the decision problem does this puzzle have any solutions or not (and if so, produce one) does. That's why I'm going to stop working on this. My stack solution code is fun, but working on making it prune better is a black hole. And to make matters worse, the more I push it (i.e., the more advanced its prunings get), the less likely (some) people are to agree that its output is still correct. You can't win. If anyone wants the stack simulation code, send me an email. Terry -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble writing to database: RSS-reader
On Jan 21, 11:25 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Mon, 21 Jan 2008 18:38:48 -0200, Arne [EMAIL PROTECTED] escribi�: On 21 Jan, 19:15, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: This should not prevent you from learning how to properly parse XML (hint: with an XML parser). XML is *not* a line-oriented format, so you just can't get nowhere trying to parse it this way. HTH Do you think i should use xml.dom.minidom for this? I've never used it, and I don't know how to use it, but I've heard it's useful. So, I shouldn't use this techinicke (probably wrong spelled) trying to parse XML? Should i rather use minidom? Thank you for for answering, I've learnt a lot from both of you, Desthuilliers and Genellina! :) Try ElementTree instead; there is an implementation included with Python 2.5, documentation athttp://effbot.org/zone/element.htmand another implementation available athttp://codespeak.net/lxml/ import xml.etree.cElementTree as ET import urllib2 rssurl = 'http://www.jabber.org/news/rss.xml' rssdata = urllib2.urlopen(rssurl).read() rssdata = rssdata.replace('', 'amp;') # ouch! tree = ET.fromstring(rssdata) for item in tree.getiterator('item'): print item.find('link').text print item.find('title').text print item.find('description').text print Note that this particular RSS feed is NOT a well formed XML document - I had to replace the with amp; to make the parser happy. -- Gabriel Genellina This look very interesting! But it looks like that no documents is well-formed! I've tried several RSS-feeds, but they are eighter undefined entity or not well-formed. This is not how it should be, right? :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Lxml on mac
[EMAIL PROTECTED] wrote: On Jan 23, 4:19 pm, Stefan Behnel wrote: [EMAIL PROTECTED] wrote: What to one do if one what to use lxml(http://codespeak.net/lxml/ index.html) on a mac? Have you tried installing up-to-date versions of libxml2/libxslt and running easy_install lxml ? No not yet. That was my nest step. But do anybody know if there is an easy way to use schema validation in python(on a mac) ? You mean: easier than the above? Likely not many... Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess and (ampersand)
Ross Ridge wrote: Tim Golden [EMAIL PROTECTED] wrote: but this doesn't: c:/temp/firefox.bat c:\Program Files\Mozilla Firefox\firefox.exe %* /c:/temp/firefox.bat code import subprocess cmd = [ rc:\temp\firefox.bat, http://local.goodtoread.org/search?word=timcached=0; ] subprocess.Popen (cmd) /code Ross Ridge wrote: You need to use double quotes both in the .BAT file and in the string you pass to subprocess.Popen(). Tim Golden [EMAIL PROTECTED] wrote: ... If you simply requote the second element in the cmd list ('http:/.') then the internal quotes are escaped by some part of the mechanism and it still doesn't work. Hmm... I guess things are much more messy than that. CMD doesn't do standard quote processing of it's arguments or .BAT file arguments, and so is incompatible with how subprocess quotes args lists. It looks like you need use a string instead of list with subprocess.Popen and not use quotes in the batch file. So something like: firefox.bat: c:\Program Files\Mozilla Firefox\firefox.exe %1 code: subprocess.Popen(r'c:\temp\firefox.bat http://local.goodtoread.org/search?word=timcached=0;') This works. The other thing that works is to put extra quotes around the URL when you pass in the list:: command= 'lynx.bat', '-dump', 'http://www.example.com/?x=1^y=2;' proc = subprocess.Popen(command, ... stdin=subprocess.PIPE, ... stdout=subprocess.PIPE, ... stderr=subprocess.PIPE) proc.stdout.read() ' You have reached this web page by typing example.com, example.net,\n or example.org into your web browser.\n\n These domain names are reserved for use in documentation and are not\n available for registration. See [1]RFC 2606, Section 3.\n\nReferences\n\n 1. http://www.rfc-editor.org/rfc/rfc2606.txt\n' I tried this before, and posted it, but I had mistakenly read from stderr instead of stdout. Thanks for making me double-check that code! STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Python CGI script and CSS style sheet
I'm working with a Python CGI script that I am trying to use with an external CSS (Cascading Style Sheet) and it is not reading it from the web server. The script runs fine minus the CSS formatting. Does anyone know if this will work within a Python CGI? It seems that line 18 is not being read properly. One more thing. I tested this style sheet with pure html code (no python script) and everything works great. Listed below is a modified example. ++ 1#!/usr/bin/python 2 3import cgi 4 5print Content-type: text/html\n The answer is it depends. Mostly on the configuration of your web-server. Assuming you're serving out of a cgi-bin/ directory, you'd be referencing http://example.com/cgi-bin/foo.py If your webserver (apache, lighttpd, whatever) has been configured for this directory to return contents of non-executable items, your above code will reference http://example.com/cgi-bin/central.css and so you may be able to just drop the CSS file in that directory. However, I'm fairly certain that Apache can be (and often is) configured to mark folders like this as execute only, no file-reading. If so, you'll likely get some sort of Denied message back if you fetch the CSS file via HTTP. A better way might be to reference the CSS file as /media/central.css 12 link rel=stylesheet type=text/css href=/media/central.css / and then put it in a media folder which doesn't have the execute-only/no-read permission set. Another (less attractive) alternative is to have your CGI sniff the incoming request, so you can have both http://example.com/cgi-bin/foo.py http://example.com/cgi-bin/foo.py?file=css using the 'file' GET parameter to return the CSS file instead of your content. I'd consider this ugly unless deploy-anywhere is needed, in which case it's not so bad because the deployment is just the one .py file (and optionally an external CSS file that it reads and dumps). -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing XML that's embedded in HTML
Stefan, I would really encourage you to use the normal parser here instead of iterparse(). from lxml import etree parser = etree.HTMLParser() # parse the HTML/XML melange tree = etree.parse(filename, parser) # if you want, you can construct a pure XML document row_root = etree.Element(newroot) for row in tree.iterfind(//Row): row_root.append(row) In your specific case, I'd encourage using lxml.objectify: http://codespeak.net/lxml/dev/objectify.html It will allow you to do this (untested): from lxml import etree, objectify parser = etree.HTMLParser() lookup = objectify.ObjectifyElementClassLookup() parser.setElementClassLookup(lookup) tree = etree.parse(filename, parser) for row in tree.iterfind(//Row): print row.relationship, row.StartDate, row.Priority * 2.7 Stefan Both the normal parser example and the objectify example you gave me give a traceback as follows: Traceback (most recent call last): File \\clippy\xml_parser2.py, line 70, in -toplevel- for row in tree.iterfind(//Row): AttributeError: 'etree._ElementTree' object has no attribute 'iterfind' Is there some kind of newer version of lxml? Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Python CGI script and CSS style sheet
Tim, Thanks for the information and I'll work with you suggestions. Also, I will let you know what I find. Thanks again, Christopher Tim Chase wrote: I'm working with a Python CGI script that I am trying to use with an external CSS (Cascading Style Sheet) and it is not reading it from the web server. The script runs fine minus the CSS formatting. Does anyone know if this will work within a Python CGI? It seems that line 18 is not being read properly. One more thing. I tested this style sheet with pure html code (no python script) and everything works great. Listed below is a modified example. ++ 1#!/usr/bin/python 2 3import cgi 4 5print Content-type: text/html\n The answer is it depends. Mostly on the configuration of your web-server. Assuming you're serving out of a cgi-bin/ directory, you'd be referencing http://example.com/cgi-bin/foo.py If your webserver (apache, lighttpd, whatever) has been configured for this directory to return contents of non-executable items, your above code will reference http://example.com/cgi-bin/central.css and so you may be able to just drop the CSS file in that directory. However, I'm fairly certain that Apache can be (and often is) configured to mark folders like this as execute only, no file-reading. If so, you'll likely get some sort of Denied message back if you fetch the CSS file via HTTP. A better way might be to reference the CSS file as /media/central.css 12 link rel=stylesheet type=text/css href=/media/central.css / and then put it in a media folder which doesn't have the execute-only/no-read permission set. Another (less attractive) alternative is to have your CGI sniff the incoming request, so you can have both http://example.com/cgi-bin/foo.py http://example.com/cgi-bin/foo.py?file=css using the 'file' GET parameter to return the CSS file instead of your content. I'd consider this ugly unless deploy-anywhere is needed, in which case it's not so bad because the deployment is just the one .py file (and optionally an external CSS file that it reads and dumps). -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess and (ampersand)
Tim Golden [EMAIL PROTECTED] wrote: but this doesn't: c:/temp/firefox.bat c:\Program Files\Mozilla Firefox\firefox.exe %* /c:/temp/firefox.bat code import subprocess cmd = [ rc:\temp\firefox.bat, http://local.goodtoread.org/search?word=timcached=0; ] subprocess.Popen (cmd) /code Ross Ridge wrote: You need to use double quotes both in the .BAT file and in the string you pass to subprocess.Popen(). Tim Golden [EMAIL PROTECTED] wrote: ... If you simply requote the second element in the cmd list ('http:/.') then the internal quotes are escaped by some part of the mechanism and it still doesn't work. Hmm... I guess things are much more messy than that. CMD doesn't do standard quote processing of it's arguments or .BAT file arguments, and so is incompatible with how subprocess quotes args lists. It looks like you need use a string instead of list with subprocess.Popen and not use quotes in the batch file. So something like: firefox.bat: c:\Program Files\Mozilla Firefox\firefox.exe %1 code: subprocess.Popen(r'c:\temp\firefox.bat http://local.goodtoread.org/search?word=timcached=0;') Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] [EMAIL PROTECTED] -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing XML that's embedded in HTML
On Jan 22, 5:31 pm, Paul McGuire [EMAIL PROTECTED] wrote: On Jan 22, 10:57 am, Mike Driscoll [EMAIL PROTECTED] wrote: Hi, I need to parse a fairly complex HTML page that has XML embedded in it. I've done parsing before with the xml.dom.minidom module on just plain XML, but I cannot get it to work with this HTML page. The XML looks like this: ... Once again (this IS HTML Day!), instead of parsing the HTML, pyparsing can help lift the interesting bits and leave the rest alone. Try this program out: Happy post-HTML Day to you! from pyparsing import makeXMLTags,Word,nums,Combine,oneOf,SkipTo,withAttribute htmlWithEmbeddedXml = HTML Body p bHey! this is really bold!/b Row status=o RelationshipOwner/Relationship Priority1/Priority StartDate07/16/2007/StartDate StopsExistNo/StopsExist NameDoe, John/Name Address1905 S 3rd Ave , Hicksville IA 9/Address /Row Row status=o RelationshipOwner/Relationship Priority2/Priority StartDate07/16/2007/StartDate StopsExistNo/StopsExist NameDoe, Jane/Name Address1905 S 3rd Ave , Hicksville IA 9/Address /Row table trTdthis is in a table, woo-hoo!/td more HTML blah blah blah... # define pyparsing expressions for XML tags rowStart,rowEnd = makeXMLTags(Row) relationshipStart,relationshipEnd = makeXMLTags(Relationship) priorityStart,priorityEnd = makeXMLTags(Priority) startDateStart,startDateEnd = makeXMLTags(StartDate) stopsExistStart,stopsExistEnd = makeXMLTags(StopsExist) nameStart,nameEnd = makeXMLTags(Name) addressStart,addressEnd = makeXMLTags(Address) # define some useful expressions for data of specific types integer = Word(nums) date = Combine(Word(nums,exact=2)+/+ Word(nums,exact=2)+/+Word(nums,exact=4)) yesOrNo = oneOf(Yes No) # conversion parse actions integer.setParseAction(lambda t: int(t[0])) yesOrNo.setParseAction(lambda t: t[0]=='Yes') # could also define a conversion for date if you really wanted to # define format of a Row, plus assign results names for each data field rowRec = rowStart + \ relationshipStart + SkipTo(relationshipEnd)(relationship) + relationshipEnd + \ priorityStart + integer(priority) + priorityEnd + \ startDateStart + date(startdate) + startDateEnd + \ stopsExistStart + yesOrNo(stopsexist) + stopsExistEnd + \ nameStart + SkipTo(nameEnd)(name) + nameEnd + \ addressStart + SkipTo(addressEnd)(address) + addressEnd + \ rowEnd # set filtering parse action rowRec.setParseAction(withAttribute(relationship=Owner,priority=1)) # find all matching rows, matching grammar and filtering parse action rows = rowRec.searchString(htmlWithEmbeddedXml) # print the results (uncomment r.dump() statement to see full # result for each row) for r in rows: # print r.dump() print r.relationship print r.priority print r.startdate print r.stopsexist print r.name print r.address This prints: Owner 1 07/16/2007 False Doe, John 1905 S 3rd Ave , Hicksville IA 9 In addition to parsing this data, some conversions were done at parse time, too - 1 was converted to the value 1, and No was converted to False. These were done by the conversion parse actions. The filtering just for Row's containing Relationship=Owner and Priority=1 was done in a more global parse action, called withAttribute. If you comment this line out, you will see that both rows get retrieved. -- Paul (Find out more about pyparsing athttp://pyparsing.wikispaces.com.) I've heard of this module, but never used it. Your code runs almost out of the box on my file and returns the correct result. That's pretty cool! It looks like the wiki you linked to has quite a few pieces of example code. I'll have to look this over. While I like lxml's very Object Oriented way of doing things, I tend to get overwhelmed by their tutorials for some reason. One more example of all those college OOP classes being a waste of money... Thank you for the help. Mike -- http://mail.python.org/mailman/listinfo/python-list
py2exe: python modules and applicaation
Hello again, I'am working a simple application with wxpython, py2exe and directpython.After I write python code in my wxpython textctrl, then my application must save that code and create ( pgssetup2.py script ), and then with py2exe create (.exe) of the code. ( my application is builded with py2exe too ). Here is example of code the converts from .py to .exe: try: process2=subprocess.Popen([python,pgssetup2.py,py2exe,- d,exe],shell=True, stdout=subprocess.PIPE) stdout_value = process2.communicate()[0] except NameError,e: print e When I run this code before converting to exe it works fine but in .exe there is no error but It wont work. I think it's problem with modules py2exe and directpython how can I append that modules to my application? Regards, Vedran -- http://mail.python.org/mailman/listinfo/python-list
Re: Python printing!
SMALLp wrote: Hy. How to use printer in python. I goggled little i I found only some win32 package which doesn't look processing for cross platform application. (I'm using USB printer and I tried to f=open(dev/...) usb port but i couldn't fond where printer is! You perhaps want to look at something like wxPython where someone's already done the dirty work for you: http://wiki.wxpython.org/Printing I assume other x-platform toolkits like Qt have similar facilities. Python itself is a bit lower-level than that and as far as I know no-one's put together a x-platform printing module, so you could be the first. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing XML that's embedded in HTML
Mike Driscoll wrote: Both the normal parser example and the objectify example you gave me give a traceback as follows: Traceback (most recent call last): File \\clippy\xml_parser2.py, line 70, in -toplevel- for row in tree.iterfind(//Row): AttributeError: 'etree._ElementTree' object has no attribute 'iterfind' Is there some kind of newer version of lxml? Yep, lxml 2.0. It's currently in beta, but that doesn't say much. http://codespeak.net/lxml/dev/ Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?
Boris Borcic wrote: I am surprised nobody pointed out explicitely that True==1 and False==0 Several of us did indeed point this out by saying that bool's are a subclass of ints. so that for instance 5*(True+True)==10 and even (but implementation-dependent) : 5*(True+True) is 10 BB -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a HTML parser who can reconstruct the original html EXACTLY?
On 2008-01-23, kliu [EMAIL PROTECTED] wrote: On Jan 23, 7:39 pm, A.T.Hofkamp [EMAIL PROTECTED] wrote: On 2008-01-23, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I am looking for a HTML parser who can parse a given page into a DOM tree, and can reconstruct the exact original html sources. Why not keep a copy of the original data instead? That would be VERY MUCH SIMPLER than trying to reconstruct a parsed tree back to original source text. Thank u for your reply. but what I really need is the mapping between each DOM nodes and the corresponding original source segment. Why do you think there is a simple one-to-one relation between nodes in some abstract DOM tree, and pieces of source?, For example, the outermost tag HTML.../HTML is not an explicit point in the tree. If if it is, what piece of source should be attached to it? Everything? Just the text before and after it? If so, what about the source text of the second tag? Last but not least, what do you intend to do with the source-text before the HTML and after the /HTML tags? In other words, you are going to have a huge problem deciding what corresponding original source segment means for each tag. This is exactly the reason why current tools do not do what you want. If you really want this, you probably have to do it yourself mostly from scratch (ie starting with a parsing framework and writing a custom parser yourself). That usually boils down to attaching source text to tokens in the lexical parsing phase. If you have a good understanding of the meaning of corresponding original source segment, AND you have perfect HTML, this is doable, but not very nice. There exist parsers that can do what you want IF YOU HAVE PERFECT HTML, but using those tools implies a very steep learning curve of about 2-3 months under the assumption that you know functional languages (if you don't, add 2-3 months or so steep learning curve :) ). If you don't have perfect HTML, you are probably more or less lost. Most tools cannot deal with that situation, and those that can do smart re-shuffling to make things parsable, which means there is really no one-to-one mapping any more (after re-shuffling). In other words, I think you really don't want what you want, at least not in the way that you consider now. Please give us information about your goal, so we can think about alternative approaches to solve your problem. sincerely, Albert -- http://mail.python.org/mailman/listinfo/python-list
Re: pairs from a list
Steven D'Aprano wrote: In fact, fastest isn't even a meaningful attribute. Does it mean: * the worst-case is fastest * the best-case is fastest * the average-case is fastest * fastest on typical data * all of the above I confess that it did not occur to me that there might be an interesting distinction among these cases for the question of how to get sequential pairs from a list. How would one draw these distinctions in this case? Thanks, Alan Isaac PS Just for context, the sequential pairs were needed in a simulation, but my question was primarily prompted by my surprise that the approaches I looked at differed as much as they did. -- http://mail.python.org/mailman/listinfo/python-list
Re: application error in python
On Jan 23, 4:29 am, abhishek [EMAIL PROTECTED] wrote: hello group i am working on a project where most of the code has been written in c++ but the web component is written in python. Initially we have been using python2.4 and vs.net2003 but recently we decided to move ahead with python2.5 and vs.net2005. the problem that has been haunting me for while now is when i am trying to access a few functions in c++ through python by building .pyd extension, python.exe crashes saying an application error has occured any clues why this happened as everythiing was working well in .net2003 and python2.4 thanks abhishek It could be that Python 2.5 is still built and linked against version 7.1 of the Microsoft C run-time. VS 2005 links against version 8.0 of the Microsoft C run-time. The two versions of the DLL are incompatible, and will cause crashes if memory is allocated from one DLL and then freed with the other. File handles also opened with one C run-time DLL cannot be used with the other version either. Unfortunately, there's no really good fix for this. Microsoft made their libraries and C run-time incompatible between versions of Visual Studio. Rather than force all Python developers to switch to VS 2005, the Python core developers stayed with the previous compiler. If you absolutely must be able to pass file handles and memory with VS 2005 DLLs, you must recompile Python with VS 2005. You will also need to recompile all DLL libraries, such as wxPython, LXML, and the PIL. Pure Python modules and libraries will be unaffected. The easiest solution, however, is to use Python 2.5 and Visual Studio 2003. --Jason -- http://mail.python.org/mailman/listinfo/python-list