htmldata 1.1.1
Bug-fix release of htmldata, fixes error when parsing whitespace inside tags. Description of the htmldata module, from its PyPI site: http://cheeseshop.python.org/pypi/htmldata/ Extract and modify HTML/CSS URLs, translate HTML documents - list data structures. The htmldata module allows one to translate HTML documents back and forth to list data structures. This allows for programmatic reading and writing of HTML documents, with much flexibility. Functions are also available for extracting and/or modifying all URLs present in the HTML or stylesheets of a document. I have found this library useful for writing robots, for wrapping all of the URLs on websites inside my own proxy CGI script, for filtering HTML, and for doing flexible wget-like mirroring. It keeps things as simple as possible, so it should be easy to learn. Supports XHTML, too. Connelly Barnes http://www.connellybarnes.com/ __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: Leo 4.4.4 beta 4 released
Leo 4.4.4 beta 4 is available at: http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106 This beta 4 version fixes all bugs reported against Leo 4.4.4 beta 3. Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html Leo 4.4.4 contains many important features originally planned for later releases. The highlights of Leo 4.4.4: - The Great Graph Aha (tm): simple scripts allow Leo outlines to represent arbitrary directed graphs. There is no need for a separate 'graph world'. The graphed.py plugin is a direct result of this Aha. The graphed.py plugin allows you to create general graphs from Leo outlines. - @menus trees in settings files create all of Leo's menus. It is now dead easy to make Leo's menus look the way you want. - @buttons trees in settings files create common @button nodes created in all Leo outlines. - @auto nodes eliminate sentinels in derived files, thereby allowing people to collaborate using Leo more easily. - New commands for resolving cvs conflicts. - A threading_colorizer plugin replaces the __jEdit_colorizer__ plugin. This plugin features much better performance and a new, elegant algorithm. - Leo is now compatible with jython. - Better support for icons in headlines. - The usual assortment of bug fixes and other minor improvements. Links: -- Leo: http://webpages.charter.net/edreamleo/front.html Home: http://sourceforge.net/projects/leo/ Download: http://sourceforge.net/project/showfiles.php?group_id=3458 CVS: http://leo.tigris.org/source/browse/leo/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ceODBC 1.2
What is ceODBC? ceODBC is a Python extension module that enables access to databases using the ODBC API and conforms to the Python database API 2.0 specifications with a few additions. I have tested this on Windows against SQL Server, Access, dBASE and Oracle and others have reported success on more obscure drivers. On Linux I have tested this against PostgreSQL. Where do I get it? http://ceodbc.sourceforge.net What's new? 1) Added support for time data as requested by Dmitry Solitsky. 2) Added support for Python 2.4 as requested by Lukasz Szybalski. 3) Added support for setting the autocommit flag in the connection constructor since some drivers do not support transactions and raise a driver not capable exception if any attempt is made to turn autocommit off; thanks to Carl Karsten for working with me to resolve this problem. 4) Added support for calculating the size and display size of columns in the description attribute of cursors as requested by Carl Karsten. 5) Use SQLFreeHandle() rather than SQLCloseCursor() since closing a cursor in the ODBC sense is not the same as closing a cursor in the DB API sense and caused strange exceptions to occur if no query was executed before calling cursor.close(). 6) Added additional documentation to README.txt as requested by Lukasz Szybalski. 7) Tweaked setup script and associated configuration files to make it easier to build and distribute; better support for building with cx_Logging if desired. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
transmit an array via socket
I want to transmit an array via socket from a host to another. How to do it? thank you. --jeff _ Largest network of startups. Find new startup opportunities. Click here. http://thirdpartyoffers.juno.com/TGL2111/fc/Ioyw6iieVGxKk95ANW9UY46ZNrfO3Mp24IBoFARajXJnlSuTKfzxO4/ -- http://mail.python.org/mailman/listinfo/python-list
Re: simple question on dictionary usage
Frank Stutzman wrote: My apologies in advance, I'm new to python Say, I have a dictionary that looks like this: record={'BAT': '14.4', 'USD': '24', 'DIF': '45', 'OAT': '16', 'FF': '3.9', 'C3': '343', 'E4': '1157', 'C1': '339', 'E6': '1182', 'RPM': '996', 'C6': '311', 'C5': '300', 'C4': '349', 'CLD': '0', 'E5': '1148', 'C2': '329', 'MAP': '15', 'OIL': '167', 'HP': '19', 'E1': '1137', 'MARK': '', 'E3': '1163', 'TIME': '15:43:54', 'E2': '1169'} From this dictionary I would like to create another dictionary calld 'egt') that has all of the keys that start with the letter 'E'. In otherwords it should look like this: egt = {'E6': '1182','E1': '1137','E4': '1157','E5': '1148', 'E2': '1169','E3': '1163'} This should work - egt = dict([i for i in d.items() if i[0].startswith('E')]) Frank Millman -- http://mail.python.org/mailman/listinfo/python-list
Re: simple question on dictionary usage
This should work - egt = dict([i for i in d.items() if i[0].startswith('E')]) Of course I meant record.items(), not d.items(). Sorry. Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: Decimal literals in Python.
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] writes: assert 0b1 is 0x1 That this doesn't raise `AssertionError` is an implementation detail. It's not guaranteed the two objects are really the same. I think Ben is getting at 0b1 and 0x1 being the same type, while the proposed 0d1 is a different type. I don't see anything wrong with 1d. We already have 1j and I don't think that's going away in 3.0. -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples within tuples
On 26 Ott, 23:33, Stargaming [EMAIL PROTECTED] wrote: He certainly is -- *you* are misreading *him*. The nit he's picking is the non-terminated string (quotation mark/apostrophe missing). right, now i got it! beside this, i'm trying to use the reduceXML function proposed by Larry.. but I found out that sometimes pyrxp parses the newline too... By now I guess it's not its fault, but it's becuase of the way the xml file is written -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding decorators in a file
On Oct 27, 3:14 am, Andrew West [EMAIL PROTECTED] wrote: Probably a bit of weird question. I realise decorators shouldn't be executed until the function they are defined with are called, but is there anyway for me to find all the decorates declared in a file when I import it? Or perhaps anyway to find the decorators by loading the file by other methods (with out simply parsing it by hand). There is no need for having *parser Angst* in Python. Once you understand the syntactical structure of the language it's easy to move on. I show you how to deal with it using EasyExtend for grepping parse trees ( which is much easier than using regexps for that purpose ). Alternatively you can use the compiler package. It hides some low level stuff being present in EE on this level. You need to decide how you want to reduce mental overhead and achieve simplicity that fits your brain. EasyExtend is available at www.fiber-space.de Here is a small tutorial: # purpose -- seeking for decorators and decorated functions in Python 2.5 stdlibs contextlib.py import inspect import parser import symbol import token # just import contextlib, keep source and create a parse tree import contextlib src = inspect.getsource(contextlib) # keep source cst = parser.suite(src).tolist() # create concrete syntax tree as a nested list # so far its all standard lib stuff... # ... now something new: from EasyExtend.csttools import find_node, find_all functions = find_all(cst, symbol.funcdef) # You need to know how these nodes are structured to get more information out of them # This can be looked up in EasyExtend/Grammar which contains a copy of Pythons Grammar or # in the same file in Pythons source distribution. Here are the relevant rules: # decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE # decorators: decorator+ # funcdef: [decorators] 'def' NAME parameters ':' suite # We see immediately that it's not all that simple. Decorators can be methods and the first name # in dotted-name can be the name of an object. For demonstration purposes we simplify our # assumptions and suppose to have plain function decorators func_info = {} for f in functions: decorator_info = set() # store decorator information here decorators = find_node(f, symbol.decorators) # we do *not* want all decorators # since there might be those related to # a closure that is handled separately if decorators: decos = find_all(decorators, symbol.decorator) for deco in decos: # token.NAME has structure [1, 'name', line_no] deco_name = find_node(deco, token.NAME)[1] args = find_node(deco, symbol.arglist) # ... we analyze args later decorator_info.add((deco_name, args)) f_names = find_all(f, token.NAME, level = 1) # set level information otherwise you # get all names defined anywhere in # funcdef func_name = f_names[1][1] # the first name is 'def', the second one the func_name func_info[func_name] = decorator_info # Note: you can move from syntax tree representation straightforward back to a textual # representation. This requires not much work but the following import is nevertheless # conceptual overhead I do not try to explain in detail here: from EasyExtend.fibers.zero.fiber import unparse # zero represents *Python* in the larger # context of EasyExtend applications # unparse transforms a cst of a particular # grammar back to source code for func_name, deco_info in func_info.items(): for (deco_name, deco_args) in deco_info: print func_name, deco_name, (unparse(deco_args) if deco_args else ()) # I get the rather unspectacular result #nested contextmanager () # You might verify this manually... -- http://mail.python.org/mailman/listinfo/python-list
Re: simple question on dictionary usage
On Oct 27, 8:02 am, Frank Millman [EMAIL PROTECTED] wrote: This should work - egt = dict([i for i in d.items() if i[0].startswith('E')]) Of course I meant record.items(), not d.items(). Sorry. Frank On reflection, although my solution is a bit shorter than some others, it may not be as efficient, as it retrieves the key and value for *every* entry in 'record' before testing whether the key begins with 'E'. If the dictionary is large, this may be a consideration. Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: Decimal literals in Python.
On Oct 26, 1:54 am, Lennart Benschop [EMAIL PROTECTED] wrote: My proposal: - Any decimal constant suffixed with the letter D or d will be interpreted as a literal of the Decimal type. This also goes for decimal constants with exponential notation. There's nothing new here that hasn't already been proposed and discussed on python-dev. There were no major objections to the idea; however, it will need to wait until there is a good C implementation of the decimal module (which is in the works but coming along very, very slowly). Also, once we have a C coded decimal object, further work would be needed to make it integrate well with the rest of the language (i.e. making sure that everything allows numeric inputs can handle a decimal object as a possible input). FWIW, using the decimal module is not at all as onerous as the OP makes it sound. I write: from decimal import Decimal as D print D(1) / D(7) + D('0.123456') That isn't much of a burden compared with: print 1d / 7d + 0.123456d You would still need to import decimal so you can set the context parameters (like precision and rounding). Also, most non-toy scripts have *very* few literals in them; instead, the decimal values arise from calculations, user inputs, and file of data. Casting those to the correct type is really no more difficult that it is with other types: s = raw_input('Input temperature') print int(s), Decimal(s), float(s) Raymond -- http://mail.python.org/mailman/listinfo/python-list
cannot open webpage which requires authentication
I tried using urllib.urlopen to open a personalized webpage (my.yahoo.com) but it doesn't work: print urllib.urlopen(http://my.yahoo.com).read() Instead of returning my.yahoo.com, it returns a page asking me to log in. So then I tried urllib.urlencode: data = urllib.urlencode({'action': 'https://login.yahoo.com/config/ login?', 'login': mylogin, 'passwd': mypassword}) print urllib.urlopen(http://my.yahoo.com, data).read() However, this doesn't work either. Is there a way to do this? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: transmit an array via socket
Jeff Pang schrieb: I want to transmit an array via socket from a host to another. How to do it? thank you. Using XMLRPC or Pyro or other RPC mechanisms instead of reinventing a wheel that is larger than the socket API suggests in the first place. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: transmit an array via socket
On Oct 26, 11:52 pm, Jeff Pang [EMAIL PROTECTED] wrote: I want to transmit an array via socket from a host to another. How to do it? thank you. Try this: client: --- import socket s = socket.socket() host = 'localhost' port = 3030 s.connect( (host, port) ) arr = [1, 2, 3] for elmt in arr: send_str = %s, % str(elmt) while send_str: chars_sent = s.send(send_str) send_str = send_str[chars_sent:] s.close() server: --- import socket s = socket.socket() host = localhost port = 3030 s.bind((host, port)) s.listen(5) while(Ctrl-C hasn't been entered): new_sock, addr = s.accept() data_list = [] while True: partial_data = new_sock.recv(1012) data_list.append(partial_data) if not partial_data: #then got all the data break data_str = ''.join(data_list)[:-1] #chop off trailing comma arr_strs = data_str.split(,) arr_ints = [int(elmt) for elmt in arr_strs] print arr_ints -- http://mail.python.org/mailman/listinfo/python-list
How can i do proxy in urllib.urlopen?
Hi i want to do proxy in urllib.urlopen how can i do this ? And which proxy type have i can prefer ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Going past the float size limits?
[EMAIL PROTECTED] wrote: On Oct 26, 6:56 pm, Chris Mellon [EMAIL PROTECTED] wrote: What in the world are you trying to count? The calculation looks like this A = 0.35 T = 0.30 C = 0.25 G = 0.10 and then I basically continually multiply those numbers together. I need to do it like 200,000+ times but that's nuts. I can't even do it 1000 times or the number rounds off to 0.0. I tried taking the inverse of these numbers as I go but then it just shoots up to inf. Yeah right. Nuts it is. 0.35*0.3*0.25*0.1 is approximately a third of a third of a quarter of a tenth, or more precisely 2.625 parts in a thousand. So after the second set of mutiplies, you have about 6.89 parts in a million, and then 0.18 parts in a billion after the third, and so on - the exponent grows by between -3 and -2 on every iteration. So 0.002625**20 is a number so small that its about as close as you can practically get to bugger-all, as it is less than 10 ** -40, and more than 10**-60 Now I have heard rumours that there are approximately 10**80 elementary particles in the universe, so this is much less than one of them, even if my rumour is grossly wrong. A light year is of the order of 9.46*10**18 millimetres, and no human has ever been that far away from home. Call it 10**19 for convenience. So your number slices the last millimetre in a light year into more than 10**399981 parts. Have you formulated the problem that you are trying to solve properly? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: transmit an array via socket
Jeff Pang p...uno.com wrote: I want to transmit an array via socket from a host to another. How to do it? thank you. pickle it and send it and unpickle it on the other side. See the cPickle module docs for loads and dumps. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: How can i do proxy in urllib.urlopen?
I read the urllib reference and set http_proxy=my proxy. But it didn't work. I can't even get authenticated. Is there anyway that we can set the proxy? -- http://mail.python.org/mailman/listinfo/python-list
Re: Going past the float size limits?
On Oct 26, 8:00 pm, Grant Edwards [EMAIL PROTECTED] wrote: On 2007-10-26, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: What in the world are you trying to count? The calculation looks like this A = 0.35 T = 0.30 C = 0.25 G = 0.10 The bases in DNA? and then I basically continually multiply those numbers together. I need to do it like 200,000+ times but that's nuts. Exactly. It sure looks like what you're doing is nuts. I can't even do it 1000 times or the number rounds off to 0.0. I tried taking the inverse of these numbers as I go but then it just shoots up to inf. Can you explain what it is you're trying to calculate? Looks pretty obviously to be a calculation of the probability that bases in the given ratios would randomly form a particular sequence. What use this would be I cannot tell. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: sem_post: Invalid argument
Jonathan Gardner wrote: On Oct 25, 2:19 pm, robert [EMAIL PROTECTED] wrote: Jonathan Gardner wrote: On Oct 25, 12:56 pm, robert [EMAIL PROTECTED] wrote: On a server the binary (red hat) installed python2.4 and also a fresh compiled python2.5 spits sem_post: Invalid argument. What is this and how can this solved? ... Python 2.4.3 (#1, Jun 6 2006, 21:10:41) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-54)] on linux2 ... server [~]# uname -a Linux server 2.4.34.1-p4-smp-bigmem-JWH #1 SMP Mon Mar 19 03:26:57 JST 2007 i686 i686 i386 GNU/Linux Are you sure you have compatible binaries? Or did you install a random RPM without checking for dependencies? Should be compatible - but I am not sure if the kernel was recompiled on this machine. And at least the fresh ./configure'ed and compiled py2.5, which yields the same problem, should be maximum compatible. Maybe because this machine is a smp-bigmem .. At this point, I would start digging into the error messages themselves. Maybe a shout out to the developers of whatever code is generating that error message. When you understand under what conditions that error message is thrown, perhaps it will yield some insight into what python is doing differently than everything else. In the Python2.4 sources just this piece causes the sem_post error message: void PyThread_release_lock(PyThread_type_lock lock) { sem_t *thelock = (sem_t *)lock; int status, error = 0; dprintf((PyThread_release_lock(%p) called\n, lock)); status = sem_post(thelock); CHECK_STATUS(sem_post); } === ERRORS The sem_post() function will fail if: [EINVAL] The sem does not refer to a valid semaphore. === with EINVAL - to me the only remaining reason is somehow a wrong sem_t memory layout - in the C compiler header file on this rented server - though the lock was established ok!?? ... -- http://mail.python.org/mailman/listinfo/python-list
MAN+_-WOMAN_+|=SEX WORLD
MAN+_-WOMAN_+|=SEX WORLD DATING AND ROMANCE * http://www.freewebs.com/sociwok/ http://amigos.com/go/g903136-pmem -- http://mail.python.org/mailman/listinfo/python-list
Dr. Wallach...
Im Tierfutter sind 41 wichtige Nährstoffe... In der Babynahrung sind nur 11 der wichtigen Nährstoffe... Unsere Nahrung im Supermarkt enthält noch weniger lebenswichtige Mineralien und Vitamine... Erfahren Sie kostenlos die schockierende Wahrheit in Das Geheimniss der 91 essentiellen Nährstoffe -- http://mail.python.org/mailman/listinfo/python-list
Re: transmit an array via socket
Hendrik van Rooyen wrote: Jeff Pang p...uno.com wrote: I want to transmit an array via socket from a host to another. How to do it? thank you. pickle it and send it and unpickle it on the other side. See the cPickle module docs for loads and dumps. In particular note: Warning: The pickle module is not intended to be secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source. Pickle works great for lots of things, but combining pickle and socket is scary. If an unfriendly can connect to our socket, they can feed us a *poison* pickle. The marshal module is at least as bad. The marshaling in RPC facilities tends to be much safer. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
ANN: Leo 4.4.4 beta 4 released
Leo 4.4.4 beta 4 is available at: http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106 This beta 4 version fixes all bugs reported against Leo 4.4.4 beta 3. Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html Leo 4.4.4 contains many important features originally planned for later releases. The highlights of Leo 4.4.4: - The Great Graph Aha (tm): simple scripts allow Leo outlines to represent arbitrary directed graphs. There is no need for a separate 'graph world'. The graphed.py plugin is a direct result of this Aha. The graphed.py plugin allows you to create general graphs from Leo outlines. - @menus trees in settings files create all of Leo's menus. It is now dead easy to make Leo's menus look the way you want. - @buttons trees in settings files create common @button nodes created in all Leo outlines. - @auto nodes eliminate sentinels in derived files, thereby allowing people to collaborate using Leo more easily. - New commands for resolving cvs conflicts. - A threading_colorizer plugin replaces the __jEdit_colorizer__ plugin. This plugin features much better performance and a new, elegant algorithm. - Leo is now compatible with jython. - Better support for icons in headlines. - The usual assortment of bug fixes and other minor improvements. Links: -- Leo: http://webpages.charter.net/edreamleo/front.html Home: http://sourceforge.net/projects/leo/ Download: http://sourceforge.net/project/showfiles.php?group_id=3458 CVS: http://leo.tigris.org/source/browse/leo/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-list
Re: simple question on dictionary usage
On Oct 27, 1:16 am, Frank Millman [EMAIL PROTECTED] wrote: On Oct 27, 8:02 am, Frank Millman [EMAIL PROTECTED] wrote: This should work - egt = dict([i for i in d.items() if i[0].startswith('E')]) Of course I meant record.items(), not d.items(). Sorry. Frank On reflection, although my solution is a bit shorter than some others, it may not be as efficient, as it retrieves the key and value for *every* entry in 'record' before testing whether the key begins with 'E'. That can be fixed by using record.iteritems() instead of record.items(). If the dictionary is large, this may be a consideration. Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: simple question on dictionary usage
Frank Stutzman a écrit : My apologies in advance, I'm new to python Say, I have a dictionary that looks like this: record={'BAT': '14.4', 'USD': '24', 'DIF': '45', 'OAT': '16', 'FF': '3.9', 'C3': '343', 'E4': '1157', 'C1': '339', 'E6': '1182', 'RPM': '996', 'C6': '311', 'C5': '300', 'C4': '349', 'CLD': '0', 'E5': '1148', 'C2': '329', 'MAP': '15', 'OIL': '167', 'HP': '19', 'E1': '1137', 'MARK': '', 'E3': '1163', 'TIME': '15:43:54', 'E2': '1169'} From this dictionary I would like to create another dictionary calld 'egt') that has all of the keys that start with the letter 'E'. In otherwords it should look like this: egt = {'E6': '1182','E1': '1137','E4': '1157','E5': '1148', 'E2': '1169','E3': '1163'} This should be pretty easy, Indeed !-) but somehow with all my googling I've not found a hint. egt = dict((k, v) for k, v in record.iteritems() if k.startswith('E')) -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expression
Finally I solved the problem, with some really minor things to tweak. I guess it's true that I had two problems working with regular expressions. Thank you all for your help. I really learned a lot on quite a difficult problem. Final Code: #For text files in a directory... #Analyzes a randomly organized UTF8 document with EINECS, CAS, Chemical, and Chemical Formula #into a document structured as EINECS|CAS|Chemical|Chemical Formula. import os import codecs import re path = C:\\text_samples\\text\\ path2 = C:\\text_samples\\text\\output\\ EINECS = re.compile(r'^\d\d\d-\d\d\d-\d$') CAS = re.compile(r'^\d*-\d\d-\d$') FORMULA = re.compile(r'([A-Z][A-Za-z0-9]+\.?[A-Za-z0-9]+/?[A-Za- z0-9]+)') def iter_elements(tokens): product = [] for tok in tokens: if EINECS.match(tok) and len(product) = 4: match = re.match(FORMULA,product[-1]) if match: product[2:-1] = [' '.join(product[2:-1])] yield product product = [] else: product[2:-1] = [' '.join(product[2:])] del product[-1] yield product product = [] product.append(tok) yield product for text in os.listdir(path): input_text = os.path.join(path,text) output_text = os.path.join(path2,text) input = codecs.open(input_text, 'r','utf8') output = codecs.open(output_text, 'w', 'utf8') tokens = input.read().split() for element in iter_elements(tokens): output.write('|'.join(element)) output.write(\r\n) input.close() output.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: simple question on dictionary usage
My take too :-) dict(item for item in record.iteritems() if item[0][0] == 'E') Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: NUCULAR fielded text searchable indexing
On Oct 17, 7:20 am, Steve Holden [EMAIL PROTECTED] wrote: I still remember Gadfly fondly. What a great piece of software Gadfly is ... congrats on that Aaron. For me it was one of the first Python packages that truly stood out and made me want to learn Python. i. -- http://mail.python.org/mailman/listinfo/python-list
Re: simple question on dictionary usage
On Sat, 27 Oct 2007 05:23:30 -0700, bearophileHUGS wrote: My take too :-) dict(item for item in record.iteritems() if item[0][0] == 'E') ``s.startswith('E')`` is a little safer than ``s[0] == 'E'`` as the former returns `False` if `s` is empty while the latter raises an `IndexError`. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Going past the float size limits?
On Sat, 27 Oct 2007 10:24:41 +0200, Hendrik van Rooyen wrote: So 0.002625**20 is a number so small that its about as close as you can practically get to bugger-all, as it is less than 10 ** -40, and more than 10**-60 If you read the rest of the thread, you'll see I give a much more accurate estimate. It's approaching 10**-52. Now I have heard rumours that there are approximately 10**80 elementary particles in the universe, so this is much less than one of them, even if my rumour is grossly wrong. A light year is of the order of 9.46*10**18 millimetres, and no human has ever been that far away from home. Call it 10**19 for convenience. So your number slices the last millimetre in a light year into more than 10**399981 parts. Numbers like 10**52 (the reciprocal of the product found) is a perfectly reasonable number if you're dealing with (say) permutations. Admittedly, even something of the complexity of Go only has about 10**150 possible moves, but Go is simplicity itself compared to (say) Borges' Library of Babel or the set of all possible genomes. It's not even what mathematicians call a large number -- it can be written using ordinary notation of powers. For large numbers that can't be written using ordinary notation, see here: http://en.wikipedia.org/wiki/Large_number http://www.scottaaronson.com/writings/bignumbers.html For instance, Ackermann's Sequence starts off quite humbly: 2, 4, 27 ... but the fourth item is 4**4**4**4 (which has 10,154 digits) and the fifth can't even be written out in ordinary mathematical notation. Calculating numbers like 10**52 or its reciprocal is also a very good exercise in programming. Anyone can write a program to multiply two floating point numbers together and get a moderately accurate answer: product = X*Y # yawn But multiplying 200,000 floating point numbers together and getting an accurate answer somewhere near 10**-52 requires the programmer to actually think about what they're doing. You can't just say: A,T,C,G = (0.35, 0.30, 0.25, 0.10) product = map(operator.mul, [A*T*C*G]*20) and expect to get anywhere. Despite my fear that this is a stupid attempt by the Original Poster's professor to quantify the old saw about evolution being impossible (...blah blah blah hurricane in a junk yard blah blah Concorde blah blah blah...), I really like this homework question. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to create a PUG mailing list?
In article [EMAIL PROTECTED], Kevin D. Smith [EMAIL PROTECTED] wrote: I'm trying to get a Python User Group started in Norman, OK and I want to get one of those fancy mailing lists on mail.python.org. There is a link there to create a new list if you have the proper authority. How does someone get the proper authority? Expressing interest. ;-) Seriously, just send email to [EMAIL PROTECTED] -- they're a bit strapped for time, so it may take a few days. -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ Typing is cheap. Thinking is expensive. --Roy Smith -- http://mail.python.org/mailman/listinfo/python-list
How to include docs using distutils?
I have a simple setup.py file: #!/usr/bin/env python from distutils.core import setup setup(name='lockfile', author='Skip Montanaro', author_email='[EMAIL PROTECTED]', maintainer='Skip Montanaro', maintainer_email='[EMAIL PROTECTED]', url='http://www.webfast.com/~skip/python/', download_url='http://www.webfast.com/~skip/python/lockfile.tar.gz', version='0.1', py_modules=['lockfile'], data_files=[('doc', ['lockfile.rst'])], ) I've used the data_files arg to setup to note where the docs live. Alas, the sdist command doesn't include this in the tar file: % tar tfz dist/lockfile-0.1.tar.gz lockfile-0.1/ lockfile-0.1/lockfile.py lockfile-0.1/PKG-INFO lockfile-0.1/README lockfile-0.1/setup.py I'm a complete distutils novice. I can't for the life of me understand why the doc directory isn't included in the tar file. As far as I can tell distutils has no explicit provision at all for distributing documentation, which seems very weird. What am I missing? Thanks, Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: simple question on dictionary usage
On Sat, 27 Oct 2007 04:29:51 +, Frank Stutzman wrote: My apologies in advance, I'm new to python Say, I have a dictionary that looks like this: record={'BAT': '14.4', 'USD': '24', 'DIF': '45', 'OAT': '16', 'FF': '3.9', 'C3': '343', 'E4': '1157', 'C1': '339', 'E6': '1182', 'RPM': '996', 'C6': '311', 'C5': '300', 'C4': '349', 'CLD': '0', 'E5': '1148', 'C2': '329', 'MAP': '15', 'OIL': '167', 'HP': '19', 'E1': '1137', 'MARK': '', 'E3': '1163', 'TIME': '15:43:54', 'E2': '1169'} From this dictionary I would like to create another dictionary calld 'egt') that has all of the keys that start with the letter 'E'. In otherwords it should look like this: egt = {'E6': '1182','E1': '1137','E4': '1157','E5': '1148', 'E2': '1169','E3': '1163'} With my tongue firmly in cheek, I present the following obfuscated solution: eval({ + reduce(lambda x,y: y+', '+x, [mo.group(1) for mo in __import__ ('re').finditer(r('E.*?'\s*:\s*'.*?'),?, str(record))], ) + }) The above should be a single line. eval(), reduce(), lambda, string concatenation in the least efficient way possible, regexes... could it get any worse than this? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: Decimal literals in Python.
On Oct 27, 12:12 am, Ben Finney [EMAIL PROTECTED] wrote: Matimus [EMAIL PROTECTED] writes: The trailing L [for 'long' literals] is going away in Python 3.0. Yes. On the other hand, we are gaining '0b' for binary literals, to go along with '0o' for octal and '0x' for hexadecimal. So, the original poster might get further by proposing an '0dNNN.NNN' syntax for 'decimal.Decimal' literals. At least the syntax would be consistent and wouldn't add a new punctuation character to the language... [snip] Some languages have or permit 0q or 0Q for octal to reduce the chance of confusion of 'O' (oh) with '0' (zero) in uppercase, eg. 0Q123 is clearer than 0O123 (0 oh 123), although lowercase is better, eg. 0q123 or 0o123. -- http://mail.python.org/mailman/listinfo/python-list
A lib to build query string...
Hi! I have a pager component. This component is makes database slices (record sets) and it is use query string's PageIndex element to identify the actual page. This component is makes pager buttons in HTML to control. Like this: 4 5 6 My problem that I need to search and I need to use pager in the resultset. This time I need to give all search parameters to the controller HTML. I wanna automatize that with this: qdict = parse_query(query_string) qdict['pageindex'] = neededpageindex new_query_string = make_query_string(qdict) Is anybody knows about a function that can build query string from parameter list? I very need that! Thanks for it! dd -- http://mail.python.org/mailman/listinfo/python-list
Re: Going past the float size limits?
On Oct 27, 8:12?am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sat, 27 Oct 2007 10:24:41 +0200, Hendrik van Rooyen wrote: So 0.002625**20 is a number so small that its about as close as you can practically get to bugger-all, as it is less than 10 ** -40, and more than 10**-60 If you read the rest of the thread, you'll see I give a much more accurate estimate. It's approaching 10**-52. Now I have heard rumours that there are approximately 10**80 elementary particles in the universe, so this is much less than one of them, even if my rumour is grossly wrong. A light year is of the order of 9.46*10**18 millimetres, and no human has ever been that far away from home. Call it 10**19 for convenience. So your number slices the last millimetre in a light year into more than 10**399981 parts. Numbers like 10**52 (the reciprocal of the product found) is a perfectly reasonable number if you're dealing with (say) permutations. Admittedly, even something of the complexity of Go only has about 10**150 possible moves, but Go is simplicity itself compared to (say) Borges' Library of Babel or the set of all possible genomes. And numbers of that size needn't be intractable. The run time to generate a Collatz sequence is logarithmic to the starting number. A number with 53328 digits only takes about 2.5 million iterations. Of course, you can't test ALL the numbers of that size, but often we're researching only certain types, such as the ith kth Generation Type [1,2] Mersenne Hailstone: Closed form: Type12MH(k,i) Find ith, kth Generation Type [1,2] Mersenne Hailstone using the closed form equation 2**(6*((i-1)*9**(k-1)+(9**(k-1)-1)/2+1)-1)-1 2**5-1 generation: 1 2**29-1 generation: 2 2**245-1 generation: 3 2**2189-1 generation: 4 2**19685-1 generation: 5 2**177149-1 generation: 6 2**1594325-1 generation: 7 2**14348909-1 generation: 8 2**129140165-1 generation: 9 2**1162261469-1 generation:10 1.141 seconds Generation 10 has over a billion bits or 300 million digits. I had to stop there because an exponent of 32 bits gives an outrageous exponent error. The closed form formula only works for a very specific type of number. The research goal was to come with a generic algorithm that works with any Type and see if the algorithm obtains the same results: Verify Type12MH Hailstones: Find ith, kth Generation Type (xyz) Hailstone using the non-recursive equation (gmpy.divm(y**(k-1)-prev_gen[2],y-x,y**(k-1))/ y**(k-2))*xyz[1]**(k-1)+prev_gen[3] where i=((hailstone-geni(k,1,xyz))/(xyz[1]**k))+1 2**5-1 generation: 1 2**29-1 generation: 2 2**245-1 generation: 3 2**2189-1 generation: 4 2**19685-1 generation: 5 2**177149-1 generation: 6 2**1594325-1 generation: 7 2**14348909-1 generation: 8 2**129140165-1 generation: 9 2**1162261469-1 generation:10 4.015 seconds There are legitimate uses for such large numbers and Python's ability to handle this was what got me interested in using Python in the first place. It's not even what mathematicians call a large number -- it can be written using ordinary notation of powers. For large numbers that can't be written using ordinary notation, see here: http://en.wikipedia.org/wiki/Large_numberhttp://www.scottaaronson.com/writings/bignumbers.html For instance, Ackermann's Sequence starts off quite humbly: 2, 4, 27 ... but the fourth item is 4**4**4**4 (which has 10,154 digits) and the fifth can't even be written out in ordinary mathematical notation. Calculating numbers like 10**52 or its reciprocal is also a very good exercise in programming. Anyone can write a program to multiply two floating point numbers together and get a moderately accurate answer: product = X*Y # yawn But multiplying 200,000 floating point numbers together and getting an accurate answer somewhere near 10**-52 requires the programmer to actually think about what they're doing. You can't just say: A,T,C,G = (0.35, 0.30, 0.25, 0.10) product = map(operator.mul, [A*T*C*G]*20) and expect to get anywhere. Despite my fear that this is a stupid attempt by the Original Poster's professor to quantify the old saw about evolution being impossible (...blah blah blah hurricane in a junk yard blah blah Concorde blah blah blah...), I really like this homework question. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
good example of C extension for Mac OS X
Hi All, Does anyone now of a good example to use as template for a C program extension that needs to be built on the Mac OS X. Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: Decimal literals in Python.
On Oct 27, 3:09 pm, MRAB [EMAIL PROTECTED] wrote: On Oct 27, 12:12 am, Ben Finney [EMAIL PROTECTED] wrote: Matimus [EMAIL PROTECTED] writes: The trailing L [for 'long' literals] is going away in Python 3.0. Yes. On the other hand, we are gaining '0b' for binary literals, to go along with '0o' for octal and '0x' for hexadecimal. So, the original poster might get further by proposing an '0dNNN.NNN' syntax for 'decimal.Decimal' literals. At least the syntax would be consistent and wouldn't add a new punctuation character to the language... [snip] Some languages have or permit 0q or 0Q for octal to reduce the chance of confusion of 'O' (oh) with '0' (zero) in uppercase, eg. 0Q123 is clearer than 0O123 (0 oh 123), although lowercase is better, eg. 0q123 or 0o123. Even clearer is not to allow octal literals :) Is there *any* use for them? -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list
Re: good example of C extension for Mac OS X
On Oct 27, 4:11 pm, chewie54 [EMAIL PROTECTED] wrote: Does anyone now of a good example to use as template for a C program extension that needs to be built on the Mac OS X. There's good, basic examples in the documentation on extending python: http://docs.python.org/ext/ -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: Decimal literals in Python.
Even clearer is not to allow octal literals :) Is there *any* use for them? +1 I find that anything I have even the remotest inkling of using octal for can be done just as easily with hex. -tkc -- http://mail.python.org/mailman/listinfo/python-list
mod_python, ElementTree and Aapche 2.0
Hi, this is a slightly vague question but I'm really puzzled as to when I write a mod_python (3.1.3) program that makes use of ElementTree and call it via a URL, the program simply stops when I do something like s = # some XML document in a string root = XML(s) There is no exception at all - the browser just shows a blank page But running the code outside of the web server makes it run fine. This is on a RHEL 4 machine, with Apache 2.0.52 and Python 2.3.4 Has anybody ever seen this type of behavior? Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Consistent mapping from frame to function
Is there a consistent way to map a frame object to a function / method object? Methods usually hang off of parameter 1, and functions usually in the global or local scope. But lambda functions and decorators are not so easily mapped. You can get access to the executing code object from the frame, but I don't see a consistent way to map it to the function. Any suggestion? -- http://mail.python.org/mailman/listinfo/python-list
sort a list
hello, I'm new to python and this list.I hope this question don't repeat an old story on the list. I have a number list,say it's [3,2,1,4,5],I want to sort it as [1,2,3,4,5],how to do? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
os.walk and recursive deletion
Hello, I'm playing around with os.walk and I made up del_tree(path) which I think is correct (in terms of the algorithm, but not as python wants it :)). As soon as some directory is deleted the iterator of os.walk chokes. OK that is somehow clear to me as it can't be valid anymore since it can't go to the just deleted directory but it is in the iterator. I generated the test data with (bash, don't know of other shell expansion features) # root=test # mkdir $root # mkdir -p # $root/{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}/{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z} # touch $root/{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}/{0,1,2,3,4,5,6,7,8,9} # touch $root/{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}/{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}/{0,1,2,3,4,5,6,7,8,9} Here goes the script, as far as I tested it it runs fine in test mode. Now that is just use the print statements like attached below. as soon as os.rmdir and os.unlink are involved the iterator chokes. How do I get around that, or what should I use to be able to recursively delete everything under a certain subdir? #--snip import sys import os import unittest def del_tree(path): walker = os.walk(path) for entry in walker: cwd = entry[0] subdirs = entry[1] files = entry[2] print Checking directory: %s %(cwd, ) if files: for file in files: file = os.path.join(cwd, file) print The file is now: %s % (file, ) #os.unlink(file) print OK directory %s has no more files, checking for subdirs... % (cwd, ) else: print OK directory %s NEVER HAD FILES, checking for subdirs... % (cwd, ) if not subdirs: print We can delete: %s % (cwd, ) #os.rmdir(cwd) else: for subdir in subdirs: subdir = os.path.join(cwd, subdir) print We need to recurse into: %s % (subdir, ) del_tree(subdir) #os.rmdir(path) print Removing: %s % (path, ) #--snap -- http://noneisyours.marcher.name http://feeds.feedburner.com/NoneIsYours -- http://mail.python.org/mailman/listinfo/python-list
how to creating html files with python
hello, I have one strange requirement, I need to create html files through python and add some data from the database. it is a GUI based application developed in WX python. and the reports need to come out in html for some strange reason which is off topic to discuss here. but the point is that how do I do it? should I create a normal file object and write the html with the data into it or are there some modules to do it? regards, Krishnakant. -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: Decimal literals in Python.
On Oct 27, 10:27 am, Paul Hankin [EMAIL PROTECTED] wrote: On Oct 27, 3:09 pm, MRAB [EMAIL PROTECTED] wrote: On Oct 27, 12:12 am, Ben Finney [EMAIL PROTECTED] wrote: Matimus [EMAIL PROTECTED] writes: The trailing L [for 'long' literals] is going away in Python 3.0. Yes. On the other hand, we are gaining '0b' for binary literals, to go along with '0o' for octal and '0x' for hexadecimal. So, the original poster might get further by proposing an '0dNNN.NNN' syntax for 'decimal.Decimal' literals. At least the syntax would be consistent and wouldn't add a new punctuation character to the language... [snip] Some languages have or permit 0q or 0Q for octal to reduce the chance of confusion of 'O' (oh) with '0' (zero) in uppercase, eg. 0Q123 is clearer than 0O123 (0 oh 123), although lowercase is better, eg. 0q123 or 0o123. Even clearer is not to allow octal literals :) Is there *any* use for them? The mode argument to os.chmod. -- http://mail.python.org/mailman/listinfo/python-list
Re: sort a list
[EMAIL PROTECTED] schrieb: hello, I'm new to python and this list.I hope this question don't repeat an old story on the list. I have a number list,say it's [3,2,1,4,5],I want to sort it as [1,2,3,4,5],how to do? your_list.sort() Please read the documentation, all of this is properly documented. And even google would have brought that up really fast: google:python list sort 1) http://xahlee.org/perl-python/sort_list.html (Oh my, it's Xah) 2) http://docs.python.org/lib/typesseq-mutable.html (official python docs) So the first two links give you all the information you needed. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: simple question on dictionary usage
Wow, what a great group! Lots of useful and kind suggestions to what I was sure was a fairly dumb question. A few comments on some selected suggestions (but I appreciate all of them) Edward Kozlowski wrote: egt = {} for key in record: if key.startswith('E'): egt[key] = record[key] I actually had come up with something like this, but thought it wasn't quite as pythonish as it should be. It is certainly much more readable to a neophyte to python. Bruno Desthuilliers wrote: egt = dict((k, v) for k, v in record.iteritems() if k.startswith('E')) This is what I was looking for. I thought I had seen something simular to this in one of the tutorials I had read, but couldn't seem to find it. Steven D'Aprano: eval({ + reduce(lambda x,y: y+', '+x, [mo.group(1) for mo in __import__ ('re').finditer(r('E.*?'\s*:\s*'.*?'),?, str(record))], ) + }) Ah! Now this is one solution I can get my teeth into. If its not obvious, I'm a recovering perl programmer. Thanks to all -- Frank Stutzman -- http://mail.python.org/mailman/listinfo/python-list
Re: how to creating html files with python
krishnakant Mane schrieb: hello, I have one strange requirement, I need to create html files through python and add some data from the database. it is a GUI based application developed in WX python. and the reports need to come out in html for some strange reason which is off topic to discuss here. but the point is that how do I do it? should I create a normal file object and write the html with the data Essentially, yes. into it or are there some modules to do it? There are a bazillion templating systems out there. Beginning with python's own string interpolation, to KID, genshi, Mako, tenjin, cheeta, ... continue Search this NG for python templating engines, and you'd be overwhelmed by the answers. Happy chosing your evil, Diez -- http://mail.python.org/mailman/listinfo/python-list
Event for multithread help advice
I have two threads going class guiThread(threading.Thread) class mainThread(threading.Thread) Within the guiThread, I have an instance of class GUIFramework(Frame) in this Tkinter instance I have a ListBox. The second thread, mainThread, has an instance of a custom class the will need to send out text or other objects to the gui. What is the best or easiest way to send, let's say text, from mainThread to the guiThread ListBox? Should I use a custom Event class, pubsub, or Queue? This is the way I have things right now (not in its entirety): - start.py import threading import thread import time import GUIFramework import myFoo class guiThread(threading.Thread): def __init__(self, threadID, name): self.threadID = threadID self.name = name self.guiFrame = GUIFramework(master=None) threading.Thread.__init__(self) def run(self): print Starting + self.name self.guiFrame.mainloop() print Exiting + self.name class mainThread(threading.Thread): def __init__(self, threadID, name): self.threadID = threadID self.name = name self.myFoo = myFoo() threading.Thread.__init__(self) def run(self): print Starting + self.name self.myFoo.alive() print Exiting + self.name def start(): Start #Create new threads threadgui = guiThread(1, threadgui) threadmain= carlThread(2, threadmain) #Start new Threads threadgui.start() threadmain.run() while threadmain.isAlive(): if not threadgui.isAlive(): doExit = 1 pass print Exiting Main Thread if __name__ == '__main__': start() - I've tried a fews things but I really haven't had any luck. -- Thanks, Joe -- http://mail.python.org/mailman/listinfo/python-list
Alarming message when running Python code
I'm not sure if this query should be directed to comp.lang.python or comp.os.linux.misc so I intend to post it to both with apologies if it's inappropriate on either. I have a small python utility which I wrote myself and which crawls through a directory comparing all possible pairs of files. Under Windows it works fine, while the same code under Linux (Fedora Core 3) works for a while then starts continuously throwing up the following message Message from [EMAIL PROTECTED] at [date/time] localhost kernel: CPU1: Temperature above threshold While the code is continues to work, it is greatly slowed by these constant messages, and of ourse I am left wondering if my computer is about to explode! Is it really true that the code causes overheating under Linux and not under Windows? Or does Windows ignore the problem (and so am I risking damage by running the code)? Or are the Linux messages spurious, and if so how can I suppress them and ensure they do not slow the running of the code? Grateful for any help - preferably not too technical. Peter -- http://mail.python.org/mailman/listinfo/python-list
multi-protocol url-based IO -- pure python kioslave-like module?
Wheel reinvention preemption question: is there an existing pure- python library with functionality similar to KDE's kio/kioslave implementation? A multi-protocol, extensible library based on URLs that abstracts directory listing and file read/write? I'm looking to use it in client code, not server, so it doesn't have to be asynchronous like kio; ideally it would be small and only depend on the standard python library. Here's what I'm aware of: * urllib2 doesn't handle opening URLs for writing, meaning that it's incapable of supporting WebDAV or e.g. the fish:// protocol * twisted is built to handle multiple protocols, but is an extremely large package aiming to simplify low-level server and client code * Boa Contstructor has something called Explorers which support multiple protocols, but seems pretty tied to its gui implementation * PyKDE can interface with the KDE shared libraries, but obviously that's not pure python. (Or standalone or small. :) * the somewhat related PEP-268 for WebDAV support, but that was withdrawn. My google-fu doesn't show much else. Any pointers would be appreciated! Thanks, Rob -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib2 weirdness when https_proxy environment variable is exported
Devraj [EMAIL PROTECTED] writes: I have been extensively using Python's urllib2 while developing a project with the Google Data API. The Google Data API uses httplib to place all of its requests. However I have been using urllib2 and some handlers that I discovered in an ASPN article to handle HTTPS proxies in my code. The Google Data API relies on an environment variable called https_proxy to get information about the proxy to be used. However urllib2 starts spitting out the BadStatusLine exception if the https_proxy environment variable is found. [...] This is because urllib2 does not support HTTPS proxies (neither does urllib). See Python cookbook for a hack to get it working. John -- http://mail.python.org/mailman/listinfo/python-list
Re: how to creating html files with python
On Oct 27, 12:12 pm, krishnakant Mane [EMAIL PROTECTED] wrote: I have one strange requirement, I need to create html files through python and add some data from the database. The only strange thing here is that you think this is a strange requirement :) This is quite typical, and practically required for web development. As Diez pointed out, your main problem will be which of the dozen or so template packages to pick. Depending on your criteria (expressive power, syntax close to python, performance, stability etc.) you may narrow it down to a handful. George -- http://mail.python.org/mailman/listinfo/python-list
Re: Alarming message when running Python code
peter wrote: I'm not sure if this query should be directed to comp.lang.python or comp.os.linux.misc so I intend to post it to both with apologies if it's inappropriate on either. I have a small python utility which I wrote myself and which crawls through a directory comparing all possible pairs of files. Under Windows it works fine, while the same code under Linux (Fedora Core 3) works for a while then starts continuously throwing up the following message Message from [EMAIL PROTECTED] at [date/time] localhost kernel: CPU1: Temperature above threshold While the code is continues to work, it is greatly slowed by these constant messages, and of ourse I am left wondering if my computer is about to explode! Is it really true that the code causes overheating under Linux and not under Windows? Or does Windows ignore the problem (and so am I risking damage by running the code)? Or are the Linux messages spurious, and if so how can I suppress them and ensure they do not slow the running of the code? Grateful for any help - preferably not too technical. Peter How well is the fan working on your computer? How recently have you cleaned the dust out of it? Touch it. Is it hot? Do you have the same problem if you turn off your computer for two hours before you run your program? I wouldn't run the risk if it were my computer. If a basic cleaning doesn't take care of the problem, take your computer to a professional. Cheers, Cliff P.S. This is not a python-specific issue. -- http://mail.python.org/mailman/listinfo/python-list
xmpfilter-a-like for python (code annotation)
http://eigenclass.org/hiki/xmpfilter looks cool , anything like this for python? any reason that we culd not do simmilar ? -- http://mail.python.org/mailman/listinfo/python-list
Re: multi-protocol url-based IO -- pure python kioslave-like module?
On 27 Okt, 18:26, Rob McMullen [EMAIL PROTECTED] wrote: Wheel reinvention preemption question: is there an existing pure- python library with functionality similar to KDE's kio/kioslave implementation? A multi-protocol, extensible library based on URLs that abstracts directory listing and file read/write? I'm looking to use it in client code, not server, so it doesn't have to be asynchronous like kio; ideally it would be small and only depend on the standard python library. Something like itools.vfs, perhaps? http://www.ikaaro.org/itools http://download.ikaaro.org/doc/itools/Chapter--VFS.html Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: xmpfilter-a-like for python (code annotation)
On Sat, 27 Oct 2007 17:10:13 +, [EMAIL PROTECTED] wrote: http://eigenclass.org/hiki/xmpfilter looks cool , anything like this for python? any reason that we culd not do simmilar ? I just read that page and am a little confused. This program adds assertions based on the actual code, i.e. if the code is wrong it nonetheless adds assertions that don't fail. I always thought one writes assertions to test what the code should do and not what it actually does!? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: os.walk and recursive deletion
Martin Marcher wrote: Hello, I'm playing around with os.walk and I made up del_tree(path) which I think is correct (in terms of the algorithm, but not as python wants it :)). As soon as some directory is deleted the iterator of os.walk chokes. OK that is somehow clear to me as it can't be valid anymore since it can't go to the just deleted directory but it is in the iterator. I generated the test data with (bash, don't know of other shell expansion features) # root=test # mkdir $root # mkdir -p # $root/{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}/{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z} # touch $root/{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}/{0,1,2,3,4,5,6,7,8,9} # touch $root/{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}/{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}/{0,1,2,3,4,5,6,7,8,9} Here goes the script, as far as I tested it it runs fine in test mode. Now that is just use the print statements like attached below. as soon as os.rmdir and os.unlink are involved the iterator chokes. How do I get around that, or what should I use to be able to recursively delete everything under a certain subdir? #--snip import sys import os import unittest def del_tree(path): walker = os.walk(path) for entry in walker: cwd = entry[0] subdirs = entry[1] files = entry[2] print Checking directory: %s %(cwd, ) if files: for file in files: file = os.path.join(cwd, file) print The file is now: %s % (file, ) #os.unlink(file) print OK directory %s has no more files, checking for subdirs... % (cwd, ) else: print OK directory %s NEVER HAD FILES, checking for subdirs... % (cwd, ) if not subdirs: print We can delete: %s % (cwd, ) #os.rmdir(cwd) else: for subdir in subdirs: subdir = os.path.join(cwd, subdir) print We need to recurse into: %s % (subdir, ) del_tree(subdir) #os.rmdir(path) print Removing: %s % (path, ) #--snap While it is possible to mix recursion and os.walk()... def del_tree(path): for cwd, subdirs, files in os.walk(path): print Checking directory: %s %(cwd, ) if files: for file in files: file = os.path.join(cwd, file) print The file is now: %s % (file, ) os.unlink(file) print OK directory %s has no more files, checking for subdirs... % (cwd, ) else: print OK directory %s NEVER HAD FILES, checking for subdirs... % (cwd, ) for subdir in subdirs: subdir = os.path.join(cwd, subdir) print We need to recurse into: %s % (subdir, ) del_tree(subdir) break # ugly but necessary print Removing: %s % (path, ) os.rmdir(path) ...the idea behind it is that you use it instead of recursion: def del_tree(root): for path, dirs, files in os.walk(root, False): for fn in files: os.unlink(os.path.join(path, fn)) for dn in dirs: os.rmdir(os.path.join(path, dn)) os.rmdir(root) The second parameter to os.walk() ensures that the tree is walked depth-first, i. e. the contents of a directory are seen before the directory itself. Personally, I would prefer a recursive implementation based on os.listdir(), def del_tree(root): for name in os.listdir(root): path = os.path.join(root, name) if os.path.isdir(path): del_tree(path) else: os.unlink(path) os.rmdir(root) an approach that is also taken by shutils.rmtree(). Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: os.walk and recursive deletion
On Sat, 27 Oct 2007 18:07:44 +0200, Martin Marcher wrote: Hello, I'm playing around with os.walk and I made up del_tree(path) which I think is correct (in terms of the algorithm, but not as python wants it :)). It's not correct in terms of the algorithm if you take the algorithm of `os.walk()` into the equation. Here goes the script, as far as I tested it it runs fine in test mode. Now that is just use the print statements like attached below. as soon as os.rmdir and os.unlink are involved the iterator chokes. How do I get around that, or what should I use to be able to recursively delete everything under a certain subdir? #--snip import sys import os import unittest def del_tree(path): walker = os.walk(path) `os.walk()` is itself diving recursivly into the subdirectories… for entry in walker: cwd = entry[0] subdirs = entry[1] files = entry[2] print Checking directory: %s %(cwd, ) if files: for file in files: file = os.path.join(cwd, file) print The file is now: %s % (file, ) #os.unlink(file) print OK directory %s has no more files, checking for subdirs... % (cwd, ) else: print OK directory %s NEVER HAD FILES, checking for subdirs... % (cwd, ) if not subdirs: print We can delete: %s % (cwd, ) #os.rmdir(cwd) else: for subdir in subdirs: subdir = os.path.join(cwd, subdir) print We need to recurse into: %s % (subdir, ) del_tree(subdir) …and here you are calling the your function recursively which then calls again `os.walk()` on that subdirectory. That's a little bit too much. Just use `os.listdir()` (and `os.path.isdir()`) in your recursive function. #os.rmdir(path) print Removing: %s % (path, ) #--snap Or `shutil.rmtree()`. :-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
urllib: cannot open webpage which requires authentication
I tried using urllib.urlopen to open a personalized webpage (my.yahoo.com) but it doesn't work: print urllib.urlopen(http://my.yahoo.com).read() Instead of returning my.yahoo.com, it returns a page asking me to log in. So then I tried urllib.urlencode: data = urllib.urlencode({'action': 'https://login.yahoo.com/config/ login?', 'login': mylogin, 'passwd': mypassword}) print urllib.urlopen(http://my.yahoo.com, data).read() However, this doesn't work either. Is there a way to do this? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to creating html files with python
On Oct 27, 12:02 pm, George Sakkis [EMAIL PROTECTED] wrote: The only strange thing here is that you think this is a strange requirement :) This is quite typical, and practically required for web development. I was wondering about this myself the other day. Suppose you wanted to get by on the cheap without setting up a whole new Joomla or WordPress installation for another smallish blog or website where you are the only poster, and all you need is simple CMS. How hard would it be to create, say, a calendar of events, or news postings using MySQL and Python and HTML. Create the page on your local machine using Python templating, and then just post the HTML code daily? I'm a rank amateur, but was wondering if this is silly and making work, or if one of those templating systems you all are mentioning would work for simple CMS and calendaring? Thanks, rd -- http://mail.python.org/mailman/listinfo/python-list
Re: xmpfilter-a-like for python (code annotation)
On Oct 27, 6:27 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: On Sat, 27 Oct 2007 17:10:13 +, [EMAIL PROTECTED] wrote: http://eigenclass.org/hiki/xmpfilter looks cool , anything like this for python? any reason that we culd not do simmilar ? I just read that page and am a little confused. This program adds assertions based on the actual code, i.e. if the code is wrong it nonetheless adds assertions that don't fail. I always thought one writes assertions to test what the code should do and not what it actually does!? Ciao, Marc 'BlackJack' Rintsch Its more the inline annotation lie here http://eigenclass.org/hiki.rb?xmpfilter#l4 that I wanted -- http://mail.python.org/mailman/listinfo/python-list
Is the subprocess module thread-safe?
Can the subprocess module be used to launch subprocesses from threads? Or does the subprocess module affect the entire process context, like fork? Or is this OS dependent? Also, if you launch processes from the subprocess module module and don't wait them to complete, do zombies accumulate under UNIX/Linux? John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: Decimal literals in Python.
Even clearer is not to allow octal literals :) Is there *any* use for them? The mode argument to os.chmod. You mean instead of import this os.chmod(filename, os.R_OK | os.W_OK | os.X_OK) which explicitly (rather than implicitly) spells it out? -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: About Pywin32's invoke
kernel1983 [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] By reading the doc of pywin32 we can invoke COM like: o = win32com.client.Dispatch(Excel.Application) but is it possible to invoke some GUID directly? Yes, you can do something like win32com.client.Dispatch('{00024500---C000-0046}') If COM was going to be invoked by python, must it support IDispatch? Not neccessarily. Pythoncom has compiled-in support for many interfaces that don't inherit from IDispatch, but it requires that someone write code to wrap the interface. Roger == Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups = East and West-Coast Server Farms - Total Privacy via Encryption = -- http://mail.python.org/mailman/listinfo/python-list
Re: Alarming message when running Python code
[Followup-To: header set to comp.os.linux.misc.] On 2007-10-27, peter [EMAIL PROTECTED] wrote: I'm not sure if this query should be directed to comp.lang.python or comp.os.linux.misc so I intend to post it to both with apologies if it's inappropriate on either. I have a small python utility which I wrote myself and which crawls through a directory comparing all possible pairs of files. Under Windows it works fine, while the same code under Linux (Fedora Core 3) works for a while then starts continuously throwing up the following message Message from [EMAIL PROTECTED] at [date/time] localhost kernel: CPU1: Temperature above threshold While the code is continues to work, it is greatly slowed by these constant messages, and of ourse I am left wondering if my computer is about to explode! Is it really true that the code causes overheating under Linux and not under Windows? Or does Windows ignore the problem (and so am I risking damage by running the code)? Or are the Linux messages spurious, and if so how can I suppress them and ensure they do not slow the running of the code? Grateful for any help - preferably not too technical. Controlling CPU temperature is the job of the operating system and the hardware. Do you have the latest version of the kernel? Do you hear the fans running at full speed when your code runs? Maybe you need new fans or a new heatsink, or you need to clean the ones you have. Why are you still using FC3? Which version of Windows do you use? 98? XP with no service pack? -- http://mail.python.org/mailman/listinfo/python-list
Re: good example of C extension for Mac OS X
There is a C template in file Modules/xxmodule.c in Python 2.5, maybe earlier. /Jean Brouwers On Oct 27, 8:11 am, chewie54 [EMAIL PROTECTED] wrote: Hi All, Does anyone now of a good example to use as template for a C program extension that needs to be built on the Mac OS X. Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: good example of C extension for Mac OS X
There is a C template in file Modules/xxmodule.c in Python 2.5, maybe earlier. /Jean Brouwers On Oct 27, 8:11 am, chewie54 [EMAIL PROTECTED] wrote: Hi All, Does anyone now of a good example to use as template for a C program extension that needs to be built on the Mac OS X. Thanks, -- http://mail.python.org/mailman/listinfo/python-list
while within while
I've been having some problems with using a while statement for one menu within another while statement for the main menu, first time I've done it. It's with choice number two from the menu. When I run the program, I get a UnboundLocalError: local variable 'ai' referenced before assignment. I initialize ai as , but then it just skips to the you choose scissors I choose and nothing shows up. As soon as I take away the while again[0] == y: statement, the program is fine again which leads me to think I'm just placing it in the wrong place. I just want to ask the user if they would like to play again and loop them back to the weapons menu if they choose yes. If they choose no, loop them back to the main menu. I've placed the question again=raw_input(Would you like to play again? ) at the end the tasks for menu choice two. Ignore threeone step at a time. ;) thx import random def main(): #define and initialize variables #choice as int choice = 0 #weapon choice as int weaponchoice = 0 #number of wins win = 0 #number of loses lose = 0 #number of ties tie = 0 #number of rounds rounds = 0 #play again loop again = no #intro print READY TO PLAY ROCK, PAPER, SCISSORS??? print #Menu loop while choice != 4: #display menu print Please choose from the following menu: print 1. See the rules print 2. Play against the computer print 3. Play a two player game print 4. Exit #prompt user for their menu choice choice = input(Please enter your choice here: ) print #if statements to determine which choice if choice == 1: print print The rules of the game are as follows: print print Rock Covers Rock print print Rock Smashes Scissors print print Scissors Cuts Paper print print elif choice == 2: while again[0] == y: #display menu print Please choose a weapon from the following menu: print 1. Rock print 2. Paper print 3. Scissors while weaponchoice != 1 and weaponchoice != 2 and weaponchoice != 3: weaponchoice = input(Please choose a weapon: ) if weaponchoice != 1 and weaponchoice != 2 and weaponchoice != 3: print print Error. Please enter a number from 1-3. decision = (1, 2, 3) ai = str((random.choice(decision))) if ai == 1: ai = rock if ai == 2: ai = paper if ai == 3: ai = scissors if weaponchoice == 1: weaponchoice = rock elif weaponchoice == 2: weaponchoice = paper else: weaponchoice = scissors print = print you choose + weaponchoice print print I choose + ai print if weaponchoice == rock and ai == scissors: win += 1 print You WIN by SMASHING those SCISSORS! elif weaponchoice == paper and ai == rock: win += 1 print You WIN by COVERING that ROCK! elif weaponchoice == scissors and ai == paper: win += 1 print You WIN by CUTTING that PAPER! elif weaponchoice == ai: tie += 1 print YOU TIE! else: lose += 1 print YOU LOSE! print \nRounds Won: , + win print \nRounds Lost: , + lose print \nRounds Tied: , + tie print print again=raw_input(Would you like to play again? ) elif choice == 3: print test elif choice == 4: print Have a great day! print print Thanks for playing! else: #invalid print Invalid selection. Please enter a number from 1 - 4. print -- http://mail.python.org/mailman/listinfo/python-list
while within while
K I've since fixed the UnboundLocalError: local variable 'ai' referenced before assignment error, I forgot to include decision = (1, 2, 3) inside for each number. Now when I run it, I get this.. main() READY TO PLAY ROCK, PAPER, SCISSORS??? Please choose from the following menu: 1. See the rules 2. Play against the computer 3. Play a two player game 4. Exit Please enter your choice here: 2 = you choose scissors I choose YOU LOSE! Rounds Won: 0 Rounds Lost: 1 Rounds Tied: 0 Would you like to play again? y Please choose from the following menu: 1. See the rules 2. Play against the computer 3. Play a two player game 4. Exit Please enter your choice here: 2 Please choose a weapon from the following menu: 1. Rock 2. Paper 3. Scissors Please choose a weapon: 1 and then the weapon submenu repeats over and over. It's also like the program is ignoring if ai == 1: ai = rock if ai == 2: ai = paper if ai == 3: ai = scissors since it says I choose -- http://mail.python.org/mailman/listinfo/python-list
Re: good example of C extension for Mac OS X
On Oct 27, 2:59 pm, MrJean1 [EMAIL PROTECTED] wrote: There is a C template in file Modules/xxmodule.c in Python 2.5, maybe earlier. /Jean Brouwers On Oct 27, 8:11 am, chewie54 [EMAIL PROTECTED] wrote: Hi All, Does anyone now of a good example to use as template for a C program extension that needs to be built on the Mac OS X. Thanks, I have looked at the docs on the python.org but specifically looking for examples showing how to deal with linked lists and more about when to use references Py_INCREF and Py_DECREF I didn't find Modules/xxmodule.c on my Mac OS X installation. Thanks again -- http://mail.python.org/mailman/listinfo/python-list
Re: while within while
Shawn Minisall wrote: K I've since fixed the UnboundLocalError: local variable 'ai' referenced before assignment error, I forgot to include decision = (1, 2, 3) inside for each number. You mean like decision = (1, 2, 3) ? I don't think that would have caused the error you reported. You probably changed something else as well. Now when I run it, I get this.. main() READY TO PLAY ROCK, PAPER, SCISSORS??? Please choose from the following menu: 1. See the rules 2. Play against the computer 3. Play a two player game 4. Exit Please enter your choice here: 2 = you choose scissors I choose YOU LOSE! Rounds Won: 0 Rounds Lost: 1 Rounds Tied: 0 Would you like to play again? y Please choose from the following menu: 1. See the rules 2. Play against the computer 3. Play a two player game 4. Exit Please enter your choice here: 2 Please choose a weapon from the following menu: 1. Rock 2. Paper 3. Scissors Please choose a weapon: 1 and then the weapon submenu repeats over and over. It's also like the program is ignoring if ai == 1: ai = rock if ai == 2: ai = paper if ai == 3: ai = scissors since it says I choose Lo and behold: it *is* ignoring that block. Why? Or in other words what set of conditions have to be true in order to reach that block? Which one of them is false? (Hint: Check your while loops, and your initialization variables.) Also, Why not use decision = ('rock', 'paper', 'scissors')? Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
Re: xmpfilter-a-like for python (code annotation)
On Sat, 27 Oct 2007 17:57:06 +, [EMAIL PROTECTED] wrote: On Oct 27, 6:27 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: On Sat, 27 Oct 2007 17:10:13 +, [EMAIL PROTECTED] wrote: http://eigenclass.org/hiki/xmpfilter looks cool , anything like this for python? any reason that we culd not do simmilar ? I just read that page and am a little confused. This program adds assertions based on the actual code, i.e. if the code is wrong it nonetheless adds assertions that don't fail. I always thought one writes assertions to test what the code should do and not what it actually does!? Its more the inline annotation lie here http://eigenclass.org/hiki.rb?xmpfilter#l4 that I wanted Can you give *useful* examples? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: Decimal literals in Python.
On Sat, 27 Oct 2007 13:28:02 -0500, Tim Chase wrote: Even clearer is not to allow octal literals :) Is there *any* use for them? The mode argument to os.chmod. You mean instead of import this os.chmod(filename, os.R_OK | os.W_OK | os.X_OK) which explicitly (rather than implicitly) spells it out? And the equivalent of ``os.chmod(filename, 0777)`` looks like what!? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: object inheritance
On Friday 26 Oct 2007 6:21:57 pm Anand wrote: On Oct 26, 5:31 pm, Pradeep Jindal [EMAIL PROTECTED] wrote: Can you tell any specific use case for doing this? I have many implementaions of a db interface. SimpleDB - simple implementation BetterDB - optimized implementation CachedDB - an implementation with caching of queries RestrictedDB - implementation with permissions Now, I want to combine these implementations and use. Typical use case scenarios are: db = RestrictedDB(CachedDB(SimpleDB())) db = RestrictedDB(SimpleDB()) db = RestrictedDB(BetterDB()) db = RestrictedDB(CachedDB(BetterDB()) db = CachedDB(SimpleDB()) etc.. I agree with Duncan. According to me, this should be called Delegation rather than inheritance. And delegation should work without any conflicts of identifier names and all that. I think, it should be all about several objects implementing a protocol (interface) and that should work cleanly. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to creating html files with python
hi George, On 27/10/2007, George Sakkis [EMAIL PROTECTED] wrote: On Oct 27, 12:12 pm, krishnakant Mane [EMAIL PROTECTED] wrote: I have one strange requirement, I need to create html files through python and add some data from the database. The only strange thing here is that you think this is a strange requirement :) This is quite typical, and practically required for web development. As Diez pointed out, your main problem will be which of the dozen or so template packages to pick. Depending on your criteria I am finding it difficult to choose. my only requirement is to create an htmo file with normal html taggs but the values come from a database connection. so I want to get rid of doing the entire concatination right from start till end. I don't mind opening a file and doing file.write() but it will be nice of some module to help me get the data concatinated with taggs and rather even better if I can do complex things like creating an html table whos rows contain data coming from a result set. here I would like to have the tagging more like functions, some thing like report.bold(this must be bold ) and this function to return a line with the bolded html which looks in the file as b this must be bold /b so instead of I doing the concatination myself, python makes it easy. and I will have lot of complex tables etc to do like this. so please help me choose one. regards, Krishnakant. -- http://mail.python.org/mailman/listinfo/python-list
cron, python and samba restart
Hello, I'm working on a project, and VMware has problems with suspending the virtual machine. We are accessing the machine through samba. However, when I suspend the VM, it stops the Samba service. The solution we hit upon was to run a script that checks, say, once a minute to determine whether the machine was active or suspended. If it's been longer than a minute, we restart the samba service. I have been able to manually execute the script, and it properly restarts the service. When running from cron, however, the service won't restart. I am able to write the file out, so I know it's running the script. Is there something in the way I'm calling with the subprocess.call() function that's not able to work through cron? My concern is that I'm using sudo, and that may be where the problem lies. I've had the process run as both root and as localuser in the crontab, both with and without sudoing the command. None works. I don't know how cron would run a sudo command in this case, anyways... Any hints would be appreciated. -- #!/usr/bin/python import os.path import time import subprocess t = str(int(time.time())) f = gasr.dat if os.path.exists(f): file = open(f,'r') timestamp = file.readline() file.close() cur_time = int(time.time()) difference_in_mins = (cur_time - int(timestamp))/60 if difference_in_mins 1: subprocess.call('sudo /etc/init.d/samba restart', shell=True) file = open(f,'w') file.write(t) file.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: Decimal literals in Python.
Marc 'BlackJack' Rintsch wrote: On Sat, 27 Oct 2007 13:28:02 -0500, Tim Chase wrote: Even clearer is not to allow octal literals :) Is there *any* use for them? The mode argument to os.chmod. You mean instead of import this os.chmod(filename, os.R_OK | os.W_OK | os.X_OK) which explicitly (rather than implicitly) spells it out? And the equivalent of ``os.chmod(filename, 0777)`` looks like what!? Ciao, Marc 'BlackJack' Rintsch Ugly. But is one function in one library, which doesn't even exist in one of the major operating systems really worth its own syntactic construct in the language? It seems that it would be fairly simple for python to treat the octal argument as a string, rather than an int: os.chmod(filename, 777) If somebody had a good *general* use for octal, it might be worth having in the language. Otherwise, it seems like an unused which is only kept around because it used to get played with. (back in the days of six bit hardware?) Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
Re: tuples within tuples
J. Clifford Dyer wrote: On Fri, Oct 26, 2007 at 06:59:51AM -0700, [EMAIL PROTECTED] wrote regarding Re: tuples within tuples: Resolve *what*? The problem isn't clear yet; at least to me. Above you say what you get. What exactly do you want? Examples please. Sorry for my poor english, but I meant: how can I obtain a list of A and C starting from something like this? (A,B,C,D) that could be ('tagA', None, [('tagB', None, ['bobloblaw], None)], None) but also ('tagA', None, description, None) when I don't know if C is a tuple or not? I guess that, at least, within the cicle I may test if C is a tuple or not.. And then apply the same cicle for C... and so on Am i right? ciao korovev So, to clarify the piece that you still haven't explicitly said, you want to keep the tag name and children of every element in your XML document. (which is different from keeping (A, C) from tuple (A, B, C, D), because you want to modify C as well, and it's decendants.) As a first solution, how about: def reduceXML(node): if type(node) == str: return node else: return (node[0], reduceXML(node[2]) N.B. Beware of stack limitations. Also, as noted elsewhere in the string, your C is actually a list of Cs. So replace my else statement with return [(child[0], reduceXML(child[2])) for child in node] I think that'll do what you need. However, I'm not sure why you need to. You're not getting any new information out of your data structure. Why not just ignore the attributes and the spare tuplet (or whatever you call tuple-items) when you do the real processing next time through? Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python, ElementTree and Aapche 2.0
On Oct 28, 3:02 am, Rajarshi [EMAIL PROTECTED] wrote: Hi, this is a slightly vague question but I'm really puzzled as to when I write a mod_python (3.1.3) program that makes use of ElementTree and call it via a URL, the program simply stops when I do something like s = # some XML document in a string root = XML(s) There is no exception at all - the browser just shows a blank page But running the code outside of the web server makes it run fine. This is on a RHEL 4 machine, with Apache 2.0.52 and Python 2.3.4 Has anybody ever seen this type of behavior? Try reading: http://www.dscpl.com.au/wiki/ModPython/Articles/ExpatCausingApacheCrash Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: Yet another comparison of Python Web Frameworks
Thomas, Like many others I have been going round the same loop for months. I have struggled with most of the Python solutions, including TurboGears and have given up and gone back to ColdFusion. I am not trying to kick of a religious war about the pros and cons of ColdFusion as a scripting langauge, but IMHO, as a development environment (Dreamweaver), it is unbeatable. In one product, out of the box I can integrate database access and web design, including AJAX, in one GUI IDE. Ok, the IDE is on Windows, but the servers run on Linux. This seems to be an aspect of web design that has been totally ignored in the Python community. Developers have been falling over each other to come up with yet another web development framework ( about 15 at the last count!), but they are all a collection of bits and pieces from all over the place. Turbogears is attempting to pull it all together, but that is like trying to hit a moving target. As soon as you get something working they move to a different level of one of the components and it all falls apart. For example, you might try widgets and get them working with Kid Templates. Then you read that they want you to move to Genshi Templates and after wasting hours, you find the small print and discover you need different widgets to work with Genshi. Some may think it is a strength of Python to have so many options, but I think it is a weakness and putting people off using Python for Web development, driving them to products like PHP, Rails or ColdFusion. When I develop a web application, I don't want to have to decide whether to use mod-python, Cherrypy, Django, Pylons... for my server. Then I have to decide whether to access my database with basic SQL or learn the quirky options available with SQLObjects or SQLAlchemy, with or without, Elixir. Finally, I have to decide which of umpteen templating systems to use and hope that it will work with the rest of the components. Am I asking too much to have a Python product X which is a fully self-contained web development framework? John B On 6 Oct, 11:44, Thomas Wittek [EMAIL PROTECTED] wrote: Michele Simionato: At work we are shopping for a Web framework, so I have been looking at the available options on the current market. At least, you missed Turbo Gears :)http://turbogears.org/ For me, it feels more integrated than Pylons. -- Thomas Wittek Web:http://gedankenkonstrukt.de/ Jabber: [EMAIL PROTECTED] GPG: 0xF534E231 -- http://mail.python.org/mailman/listinfo/python-list
Re: how to creating html files with python
krishnakant Mane schrieb: [snip] so instead of I doing the concatination myself, python makes it easy. and I will have lot of complex tables etc to do like this. so please help me choose one. Did you actually looked for a template language as suggested here? Now to make your life easier: If you like XML, use genshi. If you plan to generate something else than HTML, use cheetah. Use google or whatever search engine you prefer to find those packages. cheers Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: Decimal literals in Python.
On 2007-10-27, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: On Sat, 27 Oct 2007 13:28:02 -0500, Tim Chase wrote: Even clearer is not to allow octal literals :) Is there *any* use for them? The mode argument to os.chmod. You mean instead of import this os.chmod(filename, os.R_OK | os.W_OK | os.X_OK) which explicitly (rather than implicitly) spells it out? And the equivalent of ``os.chmod(filename, 0777)`` looks like what!? os.chmod(filename, int('777', 8)) It's good enough for most other bases. ;) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: A lib to build query string...
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Is anybody knows about a function that can build query string from parameter list? I very need that! urllib.urlencode? http://docs.python.org/lib/module-urllib.html#l2h-3888 -- Lawrence, oluyede.org - neropercaso.it It is difficult to get a man to understand something when his salary depends on not understanding it - Upton Sinclair -- http://mail.python.org/mailman/listinfo/python-list
Questions for the Python Devs Out There
I'm with an open source game engine project - Project Angela (www.projectangela.org) and I'm writing in hopes that you guys will have some advice for me. We're working on an entirely new concept in gaming engines - Ruleset Markup Languge (RML) that will allow game rules to be engine agnostic meaning that if you decide to change platforms you can take your rules - in essence your game - with you without having to do a lot of rewriting. That said, I'm looking for advice on how to reach python developers who might be interested in working on this project. If anyone reading this is interested, please feel free. We've just moved to a new web site and the forums are at http://www.projectangela.org:8081/plone-site/zforum. Much information is still stored on our old site http://www.rpg-gamerz.com. If you know of places that I might be able to post queries for python developers, I'm certainly open to suggestions. Since I'm guessing that all of you are quite active in the python community, I'd appreciate pointers. TIA, RecentCoin aka Morrighu -- http://mail.python.org/mailman/listinfo/python-list
Unix domain socket in python example?
Hi, How are you? I'm completly new in python but I know a little of C. I developed a small application in python which generate and receive some data from times in times (question of seconds) and I need to send this data to a unix domain socket (/var/run/sfp) and read the response and print on the screen. I looked for a example of source code in python which connect to a unix doman socket, send some data and print the response on the screen, however I were unable to find it. Can someone please point me to some resource in the internet that have a code like that one in a fashion that I can adapt it? Or maybe post a example code here in the forum.. Thank you, Cheers -- http://mail.python.org/mailman/listinfo/python-list
Re: good example of C extension for Mac OS X
You will need to download the MacOS X version from http://www.python.org/download/releases/2.5.1/. It contains the source code. /Jean Brouwers On Oct 27, 12:31 pm, chewie54 [EMAIL PROTECTED] wrote: On Oct 27, 2:59 pm, MrJean1 [EMAIL PROTECTED] wrote: There is a C template in file Modules/xxmodule.c in Python 2.5, maybe earlier. /Jean Brouwers On Oct 27, 8:11 am, chewie54 [EMAIL PROTECTED] wrote: Hi All, Does anyone now of a good example to use as template for a C program extension that needs to be built on the Mac OS X. Thanks, I have looked at the docs on the python.org but specifically looking for examples showing how to deal with linked lists and more about when to use references Py_INCREF and Py_DECREF I didn't find Modules/xxmodule.c on my Mac OS X installation. Thanks again -- http://mail.python.org/mailman/listinfo/python-list
Re: while within while
On Sat, 27 Oct 2007 15:11:37 -0400, Shawn Minisall wrote: I've been having some problems with using a while statement for one menu within another while statement for the main menu, first time I've done it. [snip] def main(): [and snip masses and masses of code] The first thing you should do is break your program up into functions rather than putting everything into one massive lump of code. I know some people who, once they reach ten lines of code, break it up into a separate function. That's possibly a little extreme, but at the very least you should split each logical group of code into its own function. For example, your main() function might look something vaguely like this: def main(): initialize() welcome() finished = False while not finished: finished = play_game() goodbye() Notice that there's only one while loop. That's because the inner while loop is inside the play_game() function. Perhaps the biggest reason for splitting your code into functions is that it allows you to isolate each logical task as a separate piece of code, write it, test and debug it in isolation. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
iterating over the other and finding the greatest
hi everybody, I have file with four columns:the content: column1column2 col3 col4 1175123443A_16_P03652190 12771336387A_16_P41582022 1723178298A_16_P03652191 18801932270A_16_P41582024 1000120210001261539A_16_P41582025 100018001000185916A_16_P41582026 100018751000192343A_16_P21378376 1000196610002011361A_16_P03652193 for the column3 : have carry out a process ab then i should print the line and if bc then i should print the line and cd then i should print... like this i have to continue.say for eg: 43387 so the first row is omitted, 387 is greater then 98 so i can print the line second row... my code: fh = open('364010_spacing','r') for lines in fh.readlines(): data = lines.strip().split('\t') start =data[0].strip() end = data[1].strip() values = data[2].strip() id = data[3].strip() if a b :#hanged up here print lines but i am not able to do the above can you people guide me in a right way.. I should proceed further... regards shafreen -- http://mail.python.org/mailman/listinfo/python-list
Re: Unix domain socket in python example?
On 2007-10-28, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Can someone please point me to some resource in the internet that have a code like that one in a fashion that I can adapt it? http://docs.python.org/lib/socket-example.html It's trivial to change it from INET to UNIX domain. Or maybe post a example code here in the forum.. # Echo server program import socket,os s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: os.remove(/tmp/socketname) except OSError: pass s.bind(/tmp/socketname) s.listen(1) conn, addr = s.accept() while 1: data = conn.recv(1024) if not data: break conn.send(data) conn.close() # Echo client program import socket s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(/tmp/socketname) s.send('Hello, world') data = s.recv(1024) s.close() print 'Received', repr(data) -- Grant Edwards grante Yow! Look!! Karl Malden! at visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: multi-protocol url-based IO -- pure python kioslave-like module?
On Oct 27, 10:13 am, Paul Boddie [EMAIL PROTECTED] wrote: Something like itools.vfs, perhaps? http://www.ikaaro.org/itools http://download.ikaaro.org/doc/itools/Chapter--VFS.html Thanks for the pointer -- I hadn't run across itools before. It also gave me some new ideas for google search words and found http://wiki.python.org/moin/CodingProjectIdeas/FileSystemVirtualization with a few more ideas. Thanks for the help. Rob -- http://mail.python.org/mailman/listinfo/python-list
Re: elementtree w/utf8
Tim Arnold wrote: snip On a related note, I have another question--where/how can I get the cElementTree.py module? Sorry for something so basic, but I tried installing cElementTree, but while I could compile with setup.py build, I didn't end up with a cElementTree.py file anywhere. The directory structure on my system (HPux, but no root access) doesn't work well with setup.py install. thanks, --Tim Arnold I had the same question a while ago and the answer is ElementTree is now part of the standard library. http://docs.python.org/lib/module-xml.etree.ElementTree.html Ross -- http://mail.python.org/mailman/listinfo/python-list
Re: while within while
On Oct 27, 7:11 pm, Shawn Minisall [EMAIL PROTECTED] wrote: snip import random def main(): #define and initialize variables #choice as int choice = 0 #weapon choice as int weaponchoice = 0 #number of wins win = 0 #number of loses lose = 0 #number of ties tie = 0 #number of rounds rounds = 0 #play again loop again = no snip In Python, you usually don't need to define your variables in advance. Choice is determined as a number by your use of input() and the response of the user, and in other code it could later be changed to another type. So your initial declaration was unnecessary.'Dynamic typing' its called, one of the joys of the language compared to Java, C etc.. So not doing that would make your code a bit simpler, one less thing to worry about Tony -- http://mail.python.org/mailman/listinfo/python-list
[issue1329] Different 3.0a1 exit behavior
Jean Brouwers added the comment: Attached is an updated dlibtest.c file. It prints a message in the con- /destructor functions and if that fails it calls _exit(9). Compile and run it as before and check the exit status. If the latter is 9 or 011, a printf error occurred indicating e.g. that stdout was closed or something similar. This version can also be used with gdb, either by pre-loading the dlibtest.so library within gdb or before invoking gdb. To preload the library within gdb (on Linux) use gdb .../python (gdb) set environment LD_PRELOAD ./dlibtest.so (gdb) run . or to preload before gdb use setenv LD_PRELOAD ./dlibtest.so gdb .../python (gdb) run . Lastly, my previous observations about this issue were clearly a trompe d'oeil, especially my statement that PyImport_Cleanup never returned. The missing print statements *after* the PyImport_Cleanup call are simply due to printf errors, and nothing else ;-) Added file: http://bugs.python.org/file8625/dlibtest.c __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1329 __ #include stdio.h #include string.h #include unistd.h #ifndef __GNUC__ # error requires the GNU compiler #endif extern const char* __progname; /* call printf() only if inside python binary */ static void _printf (const char* fmt, const char* arg1, const char* arg2) { if (!strcmp(python, __progname)) { if (printf(fmt, arg1, arg2) 0) { _exit(9); /* stdout closed? */ } } } #if 0 /* pick this ... */ static void __attribute__((constructor)) /* called on main() */ _ctor (void) { _printf(*** %s called in %s ...\n, ctor, __progname); } static void __attribute__((destructor)) /* called on exit() */ _dtor (void) { _printf(*** %s called in %s ...\n, dtor, __progname); } #else /* ... or this case */ static void /* called on Python exit */ _dtor (void) { _printf(*** %s called in %s ...\n, dtor, __progname); } /* the weak attribute prevents unresolved symbol errors */ extern int Py_AtExit (void(*func)(void)) __attribute__((weak)); static void __attribute__((constructor)) /* called on main() */ _ctor (void) { _printf(*** %s called in %s ...\n, ctor, __progname); if (Py_AtExit) { _printf(*** %s %s\n, Py_AtExit, (Py_AtExit(_dtor) 0 ? failed! : OK)); } } #endif /* = Build this file into a shared library, then pre-load that library with the Python binary as follows. On Linux, compile as gcc -o dlibtest.os -c -m32 -Wall -Werror -fPIC dlibtest.c gcc -o dlibtest.so -m32 -ldl -shared dlibtest.os and then run env LD_PRELOAD=./dlibtest.so .../python On MacOS X, compile as gcc -o dlibtest.os -c -Wall -Werror -march=i686 -fPIC dlibtest.c gcc -o dlibtest.dylib -undefined dynamic_lookup -lpthread -dynamiclib dlibtest.os and run env DYLD_INSERT_LIBRARIES=./dlibtest.dylib .../python.exe To preload the library within gdb (on Linux) use gdb .../python (gdb) set environment LD_PRELOAD ./dlibtest.so (gdb) run . or use setenv LD_PRELOAD ./dlibtest.so gdb .../python (gdb) run . After Ctrl-D two messages should have been printed, but 3.0a1 prints only the first one. An exist status is 9 or 011 indicates that a printf error occurred. Here is a log from Linux with my 3.0a1 and 2.51 builds and with 2.3.4 included with the Linux distro: $ gcc -o dlibtest.os -c -m32 -Wall -Werror -fPIC dlibtest.c $ gcc -o dlibtest.so -m32 -ldl -shared dlibtest.os $ env LD_PRELOAD=./dlibtest.so ~/Python-3.0a1/python *** ctor called ... Python 3.0a1 (py3k, Oct 26 2007, 09:45:17) [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2 Type help, copyright, credits or license for more information. $ env LD_PRELOAD=./dlibtest.so ~/Python-2.5.1/python *** ctor called ... Python 2.5.1 (r251:54863, Oct 22 2007, 16:19:11) [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2 Type help, copyright, credits or license for more information. *** dtor called ... $ env LD_PRELOAD=./dlibtest.so /usr/bin/python *** ctor called ... Python 2.3.4 (#1, May 2 2007, 19:26:00) [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2 Type help, copyright, credits or license for more information. *** dtor called ... Similarly on MacOS X with Python 2.3.5 distributed by Apple: % env DYLD_INSERT_LIBRARIES=./dlibtest.dylib ~/Python-3.0a1/python.exe *** ctor called ... Python 3.0a1 (py3k, Oct 25 2007, 14:55:57) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type help, copyright, credits or license for more information. ^D % env DYLD_INSERT_LIBRARIES=./dlibtest.dylib ~/Python-2.5.1/python.exe *** ctor called ... Python 2.5.1 (r251:54863, Oct 22 2007, 16:18:08) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type help, copyright, credits or license for more information. ^D *** dtor called ... % env
[issue1329] Different 3.0a1 exit behavior
Neal Norwitz added the comment: When I run with the attached patch, I see the message: *** dtor called in python ... Is that the behavior you expect? Added file: http://bugs.python.org/file8626/stdout-close.patch __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1329 __Index: Python/pythonrun.c === --- Python/pythonrun.c (revision 58681) +++ Python/pythonrun.c (working copy) @@ -725,7 +725,8 @@ } PySys_SetObject(__stdin__, std); PySys_SetObject(stdin, std); - Py_DECREF(std); + /* Purposefully lose a ref to stdin so it is never closed. */ + /* Py_DECREF(std); */ /* Set sys.stdout */ if (!(std = PyFile_FromFd(fileno(stdout), stdout, w, -1, @@ -734,7 +735,8 @@ } PySys_SetObject(__stdout__, std); PySys_SetObject(stdout, std); - Py_DECREF(std); + /* Purposefully lose a ref to stdout so it is never closed. */ + /* Py_DECREF(std); */ /* Set sys.stderr */ if (!(std = PyFile_FromFd(fileno(stderr), stderr, w, -1, @@ -743,7 +745,8 @@ } PySys_SetObject(__stderr__, std); PySys_SetObject(stderr, std); - Py_DECREF(std); + /* Purposefully lose a ref to stderr so it is never closed. */ + /* Py_DECREF(std); */ if (0) { error: ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1341] correction for test_fileinput in py3k on Windows
Changes by Martin v. Löwis: -- keywords: +patch __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1341 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1597850] Cross compiling patches for MINGW
Scott Tsai added the comment: I messed up while generating cross-2.5.1.patch last time. Added a hackish way to set disabled_module_list in setup.py from corresponding environment variable. Added file: http://bugs.python.org/file8628/cross-2.5.1.patch _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1597850 _diff --exclude=configure -urN Python-2.5.1/configure.in Python-2.5.1-hacked/configure.in --- Python-2.5.1/configure.in 2007-03-12 18:50:51.0 +0800 +++ Python-2.5.1-hacked/configure.in 2007-10-27 14:31:18.0 +0800 @@ -9,6 +9,11 @@ AC_CONFIG_SRCDIR([Include/object.h]) AC_CONFIG_HEADER(pyconfig.h) +# find compiler while respecting --host setting +AC_CANONICAL_HOST() +AC_CHECK_TOOLS(CC,gcc cc) +AC_CHECK_TOOLS(CXX,g++ c++) + dnl This is for stuff that absolutely must end up in pyconfig.h. dnl Please use pyport.h instead, if possible. AH_TOP([ @@ -163,8 +168,8 @@ # Set name for machine-dependent library files AC_SUBST(MACHDEP) AC_MSG_CHECKING(MACHDEP) -if test -z $MACHDEP -then +if test -z $MACHDEP; then +if test $cross_compiling = no; then ac_sys_system=`uname -s` if test $ac_sys_system = AIX -o $ac_sys_system = Monterey64 \ -o $ac_sys_system = UnixWare -o $ac_sys_system = OpenUNIX; then @@ -172,6 +177,23 @@ else ac_sys_release=`uname -r` fi +else + m=`$CC -dumpmachine` + changequote(, )#dnl + ac_sys_system=`expr $m : [^-]*-\([^-]*\)` + changequote([, ])#dnl + + + case $ac_sys_system in + cygwin*) ac_sys_system=`echo $ac_sys_system | sed s/cygwin/CYGWIN/g `;; + darwin*) ac_sys_system=`echo $ac_sys_system | sed s/darwin/Darwin/g `;; + freebsd*) ac_sys_system=`echo $ac_sys_system | sed s/freebsd/FreeBSD/g `;; + linux*) ac_sys_system=`echo $ac_sys_system | sed s/linux/Linux/g `;; + esac + + +fi + ac_md_system=`echo $ac_sys_system | tr -d '[/ ]' | tr '[[A-Z]]' '[[a-z]]'` ac_md_release=`echo $ac_sys_release | @@ -419,8 +441,8 @@ if test -z $CXX then case $CC in -gcc)AC_PATH_PROG(CXX, [g++], [g++], [notfound]) ;; -cc) AC_PATH_PROG(CXX, [c++], [c++], [notfound]) ;; +gcc)AC_CHECK_TOOL(CXX, [g++], [notfound]) ;; +cc) AC_CHECK_TOOL(CXX, [c++], [notfound]) ;; esac if test $CXX = notfound then @@ -429,7 +451,7 @@ fi if test -z $CXX then - AC_CHECK_PROGS(CXX, $CCC c++ g++ gcc CC cxx cc++ cl, notfound) + AC_CHECK_TOOLS(CXX, $CCC c++ g++ gcc CC cxx cc++ cl, notfound) if test $CXX = notfound then CXX= @@ -480,9 +502,11 @@ then AC_MSG_RESULT(yes) BUILDEXEEXT=.exe +case_sensitive=no else - AC_MSG_RESULT(no) - BUILDEXEEXT=$EXEEXT +AC_MSG_RESULT(no) +BUILDEXEEXT=$EXEEXT +case_sensitive=yes fi rmdir CaseSensitiveTestDir @@ -681,9 +705,9 @@ AC_MSG_RESULT($LDLIBRARY) -AC_PROG_RANLIB -AC_SUBST(AR) -AC_CHECK_PROGS(AR, ar aal, ar) +# find tools while respecting --host setting +AC_CHECK_TOOL(RANLIB,ranlib) +AC_CHECK_TOOLS(AR,ar aal,ar) AC_SUBST(SVNVERSION) AC_CHECK_PROG(SVNVERSION, svnversion, found, not-found) @@ -801,7 +825,7 @@ AC_TRY_RUN([int main() { return 0; }], ac_cv_no_strict_aliasing_ok=yes, ac_cv_no_strict_aliasing_ok=no, - ac_cv_no_strict_aliasing_ok=no) + ac_cv_no_strict_aliasing_ok=yes) CC=$ac_save_cc AC_MSG_RESULT($ac_cv_no_strict_aliasing_ok) if test $ac_cv_no_strict_aliasing_ok = yes @@ -3345,30 +3369,19 @@ AC_MSG_RESULT(no) ) -AC_MSG_CHECKING(for /dev/ptmx) - -if test -r /dev/ptmx -then - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_DEV_PTMX, 1, - [Define if we have /dev/ptmx.]) -else - AC_MSG_RESULT(no) -fi - -AC_MSG_CHECKING(for /dev/ptc) - -if test -r /dev/ptc -then - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_DEV_PTC, 1, - [Define if we have /dev/ptc.]) -else - AC_MSG_RESULT(no) -fi +AC_CHECK_FILE(/dev/ptmx, + [AC_DEFINE(HAVE_DEV_PTMX, 1, + [Define if we have /dev/ptmx.])], + []) + +AC_CHECK_FILE(/dev/ptc, + [AC_DEFINE(HAVE_DEV_PTC, 1, + [Define if we have /dev/ptc.])], + []) AC_MSG_CHECKING(for %zd printf() format support) -AC_TRY_RUN([#include stdio.h +AC_CACHE_VAL(ac_cv_printf_zd_format, + AC_TRY_RUN([#include stdio.h #include stddef.h #include string.h @@ -3400,7 +3413,7 @@ }], [AC_MSG_RESULT(yes) AC_DEFINE(PY_FORMAT_SIZE_T, z, [Define to printf format modifier for Py_ssize_t])], - AC_MSG_RESULT(no)) + AC_MSG_RESULT(no))) AC_CHECK_TYPE(socklen_t,, AC_DEFINE(socklen_t,int, @@ -3430,6 +3443,63 @@ done AC_MSG_RESULT(done) +# Cross compiling +AC_SUBST(cross_compiling) + +if test $cross_compiling = yes; then +AC_MSG_CHECKING(cc for build) +CC_FOR_BUILD=${CC_FOR_BUILD-cc} +else +CC_FOR_BUILD=${CC_FOR_BUILD-$CC} +fi + +if test $cross_compiling = yes; then + AC_MSG_RESULT($CC_FOR_BUILD) +fi + +AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler (default: cc)]) + +if test $cross_compiling = yes; then +AC_MSG_CHECKING(python for build) +
[issue1597850] Cross compiling patches for MINGW
Scott Tsai added the comment: Grumble, uploaded wrong version of patch. Added file: http://bugs.python.org/file8629/cross-2.5.1.patch _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1597850 _diff -urN --exclude configure --exclude 'config.*' Python-2.5.1/configure.in Python-2.5.1-hacked/configure.in --- Python-2.5.1/configure.in 2007-03-12 18:50:51.0 +0800 +++ Python-2.5.1-hacked/configure.in 2007-10-27 16:46:39.0 +0800 @@ -9,6 +9,11 @@ AC_CONFIG_SRCDIR([Include/object.h]) AC_CONFIG_HEADER(pyconfig.h) +# find compiler while respecting --host setting +AC_CANONICAL_HOST() +AC_CHECK_TOOLS(CC,gcc cc) +AC_CHECK_TOOLS(CXX,g++ c++) + dnl This is for stuff that absolutely must end up in pyconfig.h. dnl Please use pyport.h instead, if possible. AH_TOP([ @@ -163,8 +168,8 @@ # Set name for machine-dependent library files AC_SUBST(MACHDEP) AC_MSG_CHECKING(MACHDEP) -if test -z $MACHDEP -then +if test -z $MACHDEP; then +if test $cross_compiling = no; then ac_sys_system=`uname -s` if test $ac_sys_system = AIX -o $ac_sys_system = Monterey64 \ -o $ac_sys_system = UnixWare -o $ac_sys_system = OpenUNIX; then @@ -172,6 +177,23 @@ else ac_sys_release=`uname -r` fi +else + m=`$CC -dumpmachine` + changequote(, )#dnl + ac_sys_system=`expr $m : [^-]*-\([^-]*\)` + changequote([, ])#dnl + + + case $ac_sys_system in + cygwin*) ac_sys_system=`echo $ac_sys_system | sed s/cygwin/CYGWIN/g `;; + darwin*) ac_sys_system=`echo $ac_sys_system | sed s/darwin/Darwin/g `;; + freebsd*) ac_sys_system=`echo $ac_sys_system | sed s/freebsd/FreeBSD/g `;; + linux*) ac_sys_system=`echo $ac_sys_system | sed s/linux/Linux/g `;; + esac + + +fi + ac_md_system=`echo $ac_sys_system | tr -d '[/ ]' | tr '[[A-Z]]' '[[a-z]]'` ac_md_release=`echo $ac_sys_release | @@ -419,8 +441,8 @@ if test -z $CXX then case $CC in -gcc)AC_PATH_PROG(CXX, [g++], [g++], [notfound]) ;; -cc) AC_PATH_PROG(CXX, [c++], [c++], [notfound]) ;; +gcc)AC_CHECK_TOOL(CXX, [g++], [notfound]) ;; +cc) AC_CHECK_TOOL(CXX, [c++], [notfound]) ;; esac if test $CXX = notfound then @@ -429,7 +451,7 @@ fi if test -z $CXX then - AC_CHECK_PROGS(CXX, $CCC c++ g++ gcc CC cxx cc++ cl, notfound) + AC_CHECK_TOOLS(CXX, $CCC c++ g++ gcc CC cxx cc++ cl, notfound) if test $CXX = notfound then CXX= @@ -480,9 +502,11 @@ then AC_MSG_RESULT(yes) BUILDEXEEXT=.exe +case_sensitive=no else - AC_MSG_RESULT(no) - BUILDEXEEXT=$EXEEXT +AC_MSG_RESULT(no) +BUILDEXEEXT=$EXEEXT +case_sensitive=yes fi rmdir CaseSensitiveTestDir @@ -681,9 +705,9 @@ AC_MSG_RESULT($LDLIBRARY) -AC_PROG_RANLIB -AC_SUBST(AR) -AC_CHECK_PROGS(AR, ar aal, ar) +# find tools while respecting --host setting +AC_CHECK_TOOL(RANLIB,ranlib) +AC_CHECK_TOOLS(AR,ar aal,ar) AC_SUBST(SVNVERSION) AC_CHECK_PROG(SVNVERSION, svnversion, found, not-found) @@ -801,7 +825,7 @@ AC_TRY_RUN([int main() { return 0; }], ac_cv_no_strict_aliasing_ok=yes, ac_cv_no_strict_aliasing_ok=no, - ac_cv_no_strict_aliasing_ok=no) + ac_cv_no_strict_aliasing_ok=yes) CC=$ac_save_cc AC_MSG_RESULT($ac_cv_no_strict_aliasing_ok) if test $ac_cv_no_strict_aliasing_ok = yes @@ -3345,30 +3369,19 @@ AC_MSG_RESULT(no) ) -AC_MSG_CHECKING(for /dev/ptmx) - -if test -r /dev/ptmx -then - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_DEV_PTMX, 1, - [Define if we have /dev/ptmx.]) -else - AC_MSG_RESULT(no) -fi - -AC_MSG_CHECKING(for /dev/ptc) - -if test -r /dev/ptc -then - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_DEV_PTC, 1, - [Define if we have /dev/ptc.]) -else - AC_MSG_RESULT(no) -fi +AC_CHECK_FILE(/dev/ptmx, + [AC_DEFINE(HAVE_DEV_PTMX, 1, + [Define if we have /dev/ptmx.])], + []) + +AC_CHECK_FILE(/dev/ptc, + [AC_DEFINE(HAVE_DEV_PTC, 1, + [Define if we have /dev/ptc.])], + []) AC_MSG_CHECKING(for %zd printf() format support) -AC_TRY_RUN([#include stdio.h +AC_CACHE_VAL(ac_cv_printf_zd_format, + AC_TRY_RUN([#include stdio.h #include stddef.h #include string.h @@ -3400,7 +3413,7 @@ }], [AC_MSG_RESULT(yes) AC_DEFINE(PY_FORMAT_SIZE_T, z, [Define to printf format modifier for Py_ssize_t])], - AC_MSG_RESULT(no)) + AC_MSG_RESULT(no))) AC_CHECK_TYPE(socklen_t,, AC_DEFINE(socklen_t,int, @@ -3430,6 +3443,63 @@ done AC_MSG_RESULT(done) +# Cross compiling +AC_SUBST(cross_compiling) + +if test $cross_compiling = yes; then +AC_MSG_CHECKING(cc for build) +CC_FOR_BUILD=${CC_FOR_BUILD-cc} +else +CC_FOR_BUILD=${CC_FOR_BUILD-$CC} +fi + +if test $cross_compiling = yes; then + AC_MSG_RESULT($CC_FOR_BUILD) +fi + +AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler (default: cc)]) + +if test $cross_compiling = yes; then +AC_MSG_CHECKING(python for build) +PYTHON_FOR_BUILD=${PYTHON_FOR_BUILD-python} +PYTHON_FOR_BUILD=`which $PYTHON_FOR_BUILD` +else +