Re: How to apply the user's HTML environment in a Python programme?
On 2012-09-21 08:57, BobAalsma wrote: This text can be behind a username/password, but for several reasons, I don't want to know those. So I would like to set up a situation where the user logs in (if/when appropriate), points out the URL to my programme and my programme would then be able to read that particular text. I do this from a bat file that I will later translate to Python. I tell my work wiki which file I want. I use chrome, so for every new session I'm asked for my credentials. However, that is all transparent to my bat file. For that matter, when I download a new build from part of another bat file, I use Firefox and never see the credential exchange. I wouldn't expect any different behavior using Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: 'indent'ing Python in windows bat
On 2012-09-19 05:22, Thomas Rachel wrote: Am 18.09.2012 15:03 schrieb David Smith: I COULD break down each batch file and write dozens of mini python scripts to be called. I already have a few, too. Efficiency? Speed is bad, but these are bat files, after all. The cost of trying to work with a multitude of small files is high, though, and I realized I had better go to a mix. In order to achieve this, it might be very useful to either have a module for each (bigger) part to be achieved which you can call with ... Or you have one big interpreter which works this way: class Cmd(object): Command collector ... ... This is suitable for many small things and can be used this way: ... Thomas Thomas, Beautiful. Gotta love it. I'll see if I can get the interpreter going. I particularly like it because I will be able to copy and paste wholesale when I stitch the final product back together again. Many thanks. Going back to the one-liner, I discovered the following individual lines work: print('hi') if 1: print('hi') print('hi');print('hi2') if 1: print('hi');print('hi2') but not: print('hi');if 1: print('hi') Chokes on the 'if'. On the surface, this is not consistent. I'll drop the one-liners for now since I have something that I can work with as I learn to wrestle with Python. thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: 'indent'ing Python in windows bat
On 2012-09-19 14:18, Terry Reedy wrote: stating correctly that it works for exec(). My mistake. I fancied you were talking shell, not python. I now see that Python 3 has exec() as a built-in. python -c exec('print(\hi\)\nif 0:\n print(\hi\)\nelif 1:\n print(\hi2\)') worked right off the *.bat. Shades of sed! Note I used a one space indentation. A tab works fine, too. python -c exec('print(%1)\nif 1: print(2)') and calling 'tem 3' prints 3 2 Thanks for the exhaustive study. :-) I'll keep it in mind. I hope I don't have to do this, though. That said, if you have many multiline statements, putting them in a separate file or files may be a good idea. ASAP I'm hoping to have each bat swallowed completely by python. My current bathon or pytch file closes an old session then opens the session I select just like the bat mom used to bake. Thank you again, Terry, and thanks to all -- even the *nix'ers. Might come in handy if I get back into that again. -- http://mail.python.org/mailman/listinfo/python-list
Re: 'indent'ing Python in windows bat
Thank you all. Roy Smith gets the most thanks, though he didn't answer my general question -- he showed me how to look at that specific structure differently. Terry Reedy might get thanks for her idea if I can ever figure the correct escape sequences that will make both windows and the Python interpreter happy. Bat makes bash/sed combos look like a breeze... I thought you guys wouldn't want a treatise about WHY I was doing it this way and left it at one sentence. For whatever record, this is the sentence most missed. I'm converting windows bat files little by little to Python 3 as I find time and learn Python. I COULD stop doing all my other work to learn Python and convert all the batch files in one fell swoop. Efficiency? Fast way to get fired. Better to fit this in during the many small breaks I have. That's how the bat files were built over time in the first place. Or this email. I COULD break down each batch file and write dozens of mini python scripts to be called. I already have a few, too. Efficiency? Speed is bad, but these are bat files, after all. The cost of trying to work with a multitude of small files is high, though, and I realized I had better go to a mix. Some sections can be broken down to one liners. Efficiency? Speed is terrible, but it's far faster than typing commands. OTOH, I have the organization I need on the original bat file, which is slowly being rem'ed out. As I learn and have the time, the one-liners will melt together into a py file to be called from the bat file. Eventually, the bat will disappear back into the broken Window from whence it came. Ugly, eh? I have under my belt scads of different languages from Fortran (using JCL!), Pascal, C++ to bash, sed, awk to Forth, assembly and a large cast of others. No big deal. My brain and Python, however, do NOT mix. I have been trying to learn the thing for over a decade and figure this will either force my brain into seeing the heart of the beast, or be swallowed in the attempt. Bat files are ugly cripples, but even on Windows a two-legged quick and dirty dog is better than mistake-prone typing and button clicking. After conversion, I'm aiming to make these erstwhile ugly cripples fly when I find the time and as I stuff more Python down my gullet. I agree. For those who have the unbroken time and understanding of Python, this is idiotic. back to work, -- http://mail.python.org/mailman/listinfo/python-list
'indent'ing Python in windows bat
Hello, I'm essentially a newbie in Python. My problem in searching the archives is not knowing what words to use to ask. I'm converting windows bat files little by little to Python 3 as I find time and learn Python. The most efficient method for some lines is to call Python like: python -c import sys; sys.exit(3) How do I indent if I have something like: if (sR=='Cope'): sys.exit(1) elif (sR=='Perform') sys.exit(2) else sys.exit(3) My sole result in many attempts is Syntax Error. Thank you for any help. -- http://mail.python.org/mailman/listinfo/python-list
Re: SAX: Short tag's ...
Thomas Lehmann wrote: Hi! Is there a way to recognize short tags in a XML? I'm implementing a SAX handler... Problem: storing the XML code I would need this information in the startElement ... How can I handle this? element id=abc / element id=xyz any text/element So ... are you writing as you read? If so, I'm not sure you can know which form to write out immediately. Best bet would be to delay write until the next SAX event. The next SAX event will tell if the element should be written as element / or element. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: IDE for python similar to visual basic
r wrote: On Sep 11, 7:08 am, Nobody nob...@nowhere.com wrote: (snip) I'm saying that the user understands their workflow and environment better than the application's programmers. The user should be able to decide which menu items are shown and where, which buttons are shown and where, etc. The code doesn't need to know this level of detail, let alone dictate it. I completely disagree with this idea of user customization of the GUI. Sounds more like adolescent accessorizing to me. How is changing the location of a button, or entry, or whatever, actually going to make workflow more easier? Sounds like somebody failed to get input from their users at design time. Or somebody has the inability to relate to their end users. However i know some out there like the styles and skins crap, which is a different animal altogether than what you speak of. Would a mechanic give you a screw driver so you could adjust the fuel/ air ratio yourself? If he did i would never take my car back again! Just reeks of incompetence!! Only qualified persons should fix cars, same for software! Speaking for backyard mechanics everywhere, I sometimes want the screwdriver. :-) --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Running Sum script
Jul wrote: hello, I have a .txt file that is in this format -- 12625 17000 12000 14500 17000 12000 17000 14500 14500 12000 ...and so on... i need to create a python script that will open this file and have a running sum until the end of file. it sounds really simple its just for some reason i am having problem with it. i would really appreciate your help It is really simple. Can you post the code you've written so far? --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Running Sum script
Jul wrote: On Sep 4, 2:21 pm, Stephen Fairchild someb...@somewhere.com wrote: Jul wrote: hello, I have a .txt file that is in this format -- 12625 17000 12000 14500 17000 12000 17000 14500 14500 12000 ...and so on... i need to create a python script that will open this file and have a running sum until the end of file. Untested: with open(numbers.txt, r) as f: print sum(int(x) for x in f) -- Stephen Fairchild thats what i have so far -- #!/usr/bin/python import os.path #open up the file formisanoOpen = open(formisano_num.txt, r) #read in all the data into a list readData = formisanoOpen.readLines() #set up a sum sum = 0; #begin a loop for trial in readData: #the next line is indented (YA doesn't indent) sum += int(trial) #loop is over, so unindent #report the sum print sum end but it doesnt want to run for some reason ... ok ... what do you get. If it's an error, please post the stack trace. Please help us help you -- provide details. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: obscure problem using elementtree to make xhtml website
Lee wrote: Elementtree (python xml parser) will transform markup like tag boo=baa/tag into tag boo=baa / which is a reasonable thing to do for xml (called minimization, I think). But this caused an obscure problem when I used it to create the xhtml parts of my website, causing Internet Explorer to display nearly blank pages. I explain the details at http://lee-phillips.org/scripttag/ and am writing here as a heads-up to anyone who might be using a workflow similar to mine: writing documents in xml and using python and elementtree to transform those into xhtml webpages, and using the standard kludge of serving them as text/html to IE, to get around the latter's inability to handle xml. I can't be the only one (and I doubt this problem is confined to elementtree). Lee Phillips It's not just Elementtree that does this .. I've seen others libraries (admittedly in other languages I won't mention here) transform empty tags to the self-terminating form. A whitespace text node or comment node in between *should* prevent that from happening. AFAIK, the only tag in IE xhtml that really doesn't like to be reduced like that is the script tag. Firefox seems to be fine w/ self-terminating script / tags. At any rate, I tend to put a comment node in between the begin and end to prevent the reduction: script src= ... type=text/javascript!-- --/script --David -- http://mail.python.org/mailman/listinfo/python-list
Re: python daemon - compress data and load data into MySQL by pyodbc
MacRules wrote: Sean DiZazzo wrote: On Sep 2, 8:36 pm, MacRules macru...@nome.com wrote: Hi, I installed Python daemon, pyodbc module to access the back-end DB server. My setup is like this load data job - Python Daemon A, port 6000 - Python Daemon B, port 7000 - MySQL Daemon A will perform data compression, such as GZIP, and send over data to Daemon B. Daemon B will perform data uncompression, GUNZIP, and insert records to MySQL or MSSQL or Oracle. Where should I start this to code this? Can someone give me a hint, as detail as possible here? I am a python newbie. Thanks for all the help I can get, Start by reading the tutorial. http://docs.python.org/tutorial/ ~Sean Are you a Python expert? Can you show me the basic coding to get a Daemon (pass through insert data) up and insert to the backend MySQL? You've asked a rather large and non-specific question. What avenues have you explored so far? Can you describe the problem this is designed to solve? --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on the csv library
vsoler wrote: Thank you very much for all your comments. After reading them I can conclude that: 1- the CSV format is not standardized; each piece of software uses it differently True, but there are commonalities. See http://en.wikipedia.org/wiki/Comma-separated_values 2- the C in CSV does not mean comma for Microsoft Excel; the ; comes from my regional Spanish settings The C really does stand for comma. I've never seen MS spit out semi-colon separated text on a CSV format. 3- Excel does not even put quotes around litteral texts, not even when the text contains a blank There is no need to quote text literals with whitespace in them. There is a need when a newline exists or when the separator character is embedded in the field. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions on XML
joy99 wrote: Dear Group, I like to convert some simple strings of natural language to XML. May I use Python to do this? If any one can help me, on this. I am using primarily UTF-8 based strings, like Hindi or Bengali. Can I use Python to help me in this regard? How can I learn good XML aspects of Python. If any one can kindly name me a book or URL. I am using Python2.6 on Windows XP with IDLE as GUI. Best Regards, Subhabrata. Take a look at xml.etree.ElementTree package and it's contents. It's included in the binary distributions of Python 2.6. There are lot's of books out covering XML and UTF-8 is exactly where you want to be w/ XML. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
Aahz wrote: In article mailman.3765.1248685391.8015.python-l...@python.org, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Sunday 26 July 2009 21:26:46 David Robinow wrote: I'm a mediocre programmer. Does this mean I should switch to PHP? I have searched, but I can find nothing about this mediocre language. Could you tell us more? :-P (For anyone who is confused by Hendrik's humor, he is saying that David was referring to a programming language named mediocre. English grammar is confusing!) LOL ... I'm an American and that wasn't all that clear :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Help understanding the decisions *behind* python?
Piet van Oostrum wrote: Hendrik van Rooyen hend...@microcorp.co.za (HvR) wrote: HvR On Monday 20 July 2009 21:26:07 Phillip B Oldham wrote: On Jul 20, 6:08 pm, Duncan Booth duncan.bo...@invalid.invalid wrote: The main reason why you need both lists and tuples is that because a tuple of immutable objects is itself immutable you can use it as a dictionary key. Really? That sounds interesting, although I can't think of any real- world cases where you'd use something like that. HvR simplest is something like a point in the cartesian plane with HvR an associated attribute like colour. There are numerous other examples. Anytime you need a key that is not a single object but composed of more than one: Name + birthday Street + number + City Student + Course etc. Compound keys (like what's listed above) can also be used for sorting lists of dictionaries using DSU style sorting. Something I believe (and I could be wrong) won't work with mutable types like lists. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Python code for testing well parenthesized expression
Jeremy Sanders wrote: candide wrote: I'm trying to implement in Python a function testing if an expression is well parenthesized. For instance the expression zx4er(1(er(Yy)ol)ol)ik is correctly parenthesized but this one zx(4er(1(er(Yy)ol)ol)ik is not. My code follows at the end. If you have a better algorithm or a better Python code (I'm a beginner in the Python world), don't hesitate ... Don't you want to just test that the number of (s equals the number of )s or am I missing the point? a='aAAA(bbb(cc)))' a.count('(') == a.count(')') Jeremy Using straight counting, )z))ab(c(ew( would be well parenthesized. I suspect a better way would be to iterate over the string using a balance counter that increases 1 for every open, decreases 1 for every close. A negative balance at any moment would indicate an error as well as an ending balance greater than 0. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter problem
Paul Simon wrote: Peter Otten __pete...@web.de wrote in message news:h3481q$d95$0...@news.t-online.com... Paul Simon wrote: Chris Rebert c...@rebertia.com wrote in message news:mailman.2863.1247095339.8015.python-l...@python.org... On Wed, Jul 8, 2009 at 4:18 PM, Paul Simonpsi...@sonic.net wrote: I have the tkinter problem and need some assistance to straighten it out. From the web page http://wiki.python.org/moin/TkInter; I tested as in step 1 and cannot import _tkinter. I do not have that file on my computer, but do have tkinter.py in /usr/local/lib/python2.6/lib-tk. as well as the directories /usr/lib/tk8.5 and /usr/lib/tcl8.5. This python stuff is great, but the documentation frequently feels like it is just a bit out of my grasp. I realize that all of this is free but I understand the instructions on the web page to repair only to the point of confusion. I'm not an expert. How do I modify my python configuration? Is there a file that needs to be edited? Which setup.py file do I use? Make? or python setup.py build and python setup.py install? Thanks. I appreciate your help. - How did you install Python? - What Linux distro are you using? Cheers, Chris http://blog.rebertia.com Im using Mandriva 2008.1. I have to tell you honestly that I'm not sure exactly how I installed Python. Originally I had installed 2.5 from RPM but 2.6 was not available for my distro (2008.1) in RPM. I downloaded something from python.org and installed. Not sure if it was tarball or zip file. Zip or tar doesn't matter, you are installing from source. Python has to find the necessary include files for tcl/tk. These are in separate packages that you have to install before you invoke Python's configure script. I don't know what they are called on your system -- look for tk-dev.rpm, tcl-dev.rpm or similar. You may run into the same problem with other modules like readline. Peter Thank you Peter. I understand what you are saying but don't know how to do it. Although I installed from source, I followed a cookbook recipe. Could you tell me what files to execute, where they might be, and file arguments? I'm just ignorant, not stupid. ;-). Paul Just install the tkinter package from the Mandriva Linux Control Center's Software Management system. I just did it, doing a search for tkinter brought it right up. All done. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Clarity vs. code reuse/generality
kj wrote: In 7x4otsux7f@ruckus.brouhaha.com Paul Rubin http://phr...@nospam.invalid writes: kj no.em...@please.post writes: sense = cmp(func(hi), func(lo)) assert sense != 0, func is not strictly monotonic in [lo, hi] bisection search usually just requires the function to be continuous and to have its value cross the target somewhere between the endpoints, not be monotonic. Try the algorithm I posted with lo = -pi/4, hi = 2*pi, func = cos, target = -1, and see what you get... I regard the very special case of func(hi)==func(lo)==target as pathological (analogous to the fact that a stopped watch is exactly right twice a day), and not one I care to support. I do think you should support that case, under the do 'nothing' gracefully principle. You keep missing the point that this is an *internal* *helper* *convenience* function, meant to abstract away common logic from a handful of places and thus eliminate some code repetition within a module. It is *not* a library function intended to be called from elsewhere. So talk of supporting anything is besides the point. Any internal use of this function that applies it to a non-strictly-monotonic function is, by assumption, an error. kj First, let me say *I got the point*. I use asserts, but only in unit testing where I want to test the result of some action for correctness. In the course of programming product code, I personally don't think they should ever be used exactly for the reasons everyone else is pointing out. They can be disabled with the -O option and that changes the program's behavior in ways that could break in production. If you insist on teaching the assert statement, teach it in the context of writing unit testing code. Its an extremely valuable skill. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: logging of strings with broken encoding
Thomas Guettler wrote: Hi, I have bug in my code, which results in the same error has this one: https://bugs.launchpad.net/bzr/+bug/295653 {{{ Traceback (most recent call last): File /usr/lib/python2.6/logging/__init__.py, line 765, in emit self.stream.write(fs % msg.encode(UTF-8)) .. UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 8: ordinal not in range(128) }}} I run Python 2.6. In SVN the code is the same (StreamHandler ... def emit...): http://svn.python.org/view/python/branches/release26-maint/Lib/logging/__init__.py?revision=72507view=markup I think msg.encode(UTF-8, 'backslashreplace') would be better here. What do you think? Should I fill a bugreport? Thomas I think you have to decode it first using the strings original encoding whether that be cp1252 or mac-roman or any of the other 8-bit encodings. Once that's done, you can encode in UTF-8 --David -- http://mail.python.org/mailman/listinfo/python-list
Re: What text editor is everyone using for Python
Lacrima wrote: I am new to python. And now I am using trial version of Wing IDE. But nobody mentioned it as a favourite editor. So should I buy it when trial is expired or there are better choices? I use Wing IDE and like it. It very nicely enforces consistent space indentations and other Python basics that might fall through the cracks when writing. I'm not too hot on the auto-suggest, but I haven't seen any other IDE do better. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: How to walk up parent directories?
Matthew Wilson wrote: Is there already a tool in the standard library to let me walk up from a subdirectory to the top of my file system? In other words, I'm looking for something like: for x in walkup('/home/matt/projects'): ... print(x) /home/matt/projects /home/matt /home / I know I could build something like this with various os.path components, but I'm hoping I don't have to. TIA Matt You should take a look at the os.path module. Seems like you might find something in that toolbox for this. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Noob - a couple questions involving a web app
Kyle T. Jones wrote: Bruno Desthuilliers, my dear, dear friend, there was this time, oh, 4/29/2009 3:02 AM or thereabouts, when you let the following craziness loose on Usenet: Kyle T. Jones a écrit : Been programming for a long time, but just starting out with Python. Not a professional programmer, just that guy in one of those organizations that won't hire a pro, instead saying Hey, Kyle knows computer stuff - let's have him do this (and that, and the other, etc). So, the higher ups want a web app that'll let them enter (from an intranet page) a rather simple, but quite lengthy, list - details to be stored in a MySQL database... just normal stuff here, entering, editing, and deleting entries, sorting, etc. On the internet side of things, folks get the info served up to them, can sort it in a few ways, etc - it's pretty basic stuff. (snip) I can only second Arnaud and Emile : Django is very probably what you're looking for, and by all means better than any PHP thingie - wrt/ both development time and security. You'll indeed first have to learn the framework (and Python of course), and learn how to deploy your app in production (which can be a bit tricky if you're not familiar with server admin), but there's a good documentation and a very helpful community around both the Django framework and the Python language. Thanks everyone! Wow, pretty much a consensus - a rarity with these types of questions, at least in my experience. Ok, sounds like I need to be looking at Django. Thanks for the advice! Cheers! Consensus?! ... that just won't do. :-) I've started with Pylons and have found it very nice. Loose enough to tinker with the inner workings but complete and working right out of the box (or paster in Pylons case). --David -- http://mail.python.org/mailman/listinfo/python-list
Re: How to locate the bit in bits string?
Li Wang wrote: 2009/4/29 Tim Chase python.l...@tim.thechases.com: Li Wang wrote: Hi: If I use an integer to represent bits: e.g. 99 represents '1100011' How can I locate, say the second bit of 99(i.e. '1')? Although bin(99)[4] could be used to locate it, this transform cost too much memory (99 only needs 2Bytes, while string '1100011' needs 7Bytes). Anyone knows how to locate the second bit without using bin() function? You mean def get_bit(number, bit): return (number bit) 1 ? Hummm, I have tried this method too, the problem is its time complexity. If the length of my bits is n, then the time complexity is O(n). When I tried to implement this in practice, it did consume a lot of time. So do you know how could I locate the bit in O(1) time? Transform it into a string is a method, but takes too much space (when I try to process a 2M file, it used more than 100M memory.). Thank you very much. -tkc So... I can only conclude you are looking for bit x in the entirety of a file. First you'll have to figure out what byte to look at w/ a little integer division, then read to that point and test for the specific bit -- I'm thinking a bitwise and operation with a bit mask. Should be really fast. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Modifying the value of a float-like object
eric.le.bi...@spectro.jussieu.fr wrote: It looks like what is needed here are a kind of mutable float. Is there a simple way of creating such a type? I don't mind changing the value through x.value = 1.23 instead of x = 1.23... :) On Apr 14, 3:03 pm, eric.le.bi...@spectro.jussieu.fr wrote: Hello, Is there a way to easily build an object that behaves exactly like a float, but whose value can be changed? The goal is to maintain a list [x, y,…] of these float-like objects, and to modify their value on the fly (with something like x.value = 3.14) so that any expression like x +y uses the new value. I thought of two solutions, both of which I can't make to work: 1) Use a class that inherits from float. This takes care of the behave like float part. But is it possible to change the value of the float associated with an instance? That is, is it possible to do: x = MyFloat(1.23); x.change_value(3.14) so that x's float value becomes 3.14? 2) The other possibility I thought of was: use a class that defines a 'value' member (x.value). This takes care of the value can be changed part. But is it possible/easy to make it fully behave like a float (including when passed to functions like math.sin)? Alternatively, I'd be happy with a way of handling numerical uncertainties in Python calculations (such as in calculate the value and uncertainty of a*sin(b) knowing that a=3.0 +/- 0.1 and b=1.00 +/- 0.01). Any idea would be much appreciated! I think you'll have to describe your use case a little better. I don't see why you'd need a mutable float. As long as the reference x is visible to the other parts of your code, when that code uses x, it'll always get the right instance of a float object. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Floor value in math operators
AggieDan04 wrote: On Apr 8, 12:08 pm, David Smith d...@cornell.edu wrote: Avi wrote: Hi, This will be a very simple question to ask all the awesome programmers here: How can I get answer in in decimals for such a math operator: 3/2 I get 1. I want to get 1.5 Thanks in advance, Avi I'm going to assume your operands are variables instead of numeric literals. Why not consider doing a type conversion to float or Decimal and then perform the division? Because float(x) and Decimal(x) fail for complex numbers and lose precision if x is a rational or a multi-precision float. The OP didn't ask for anything complicated or high precision -- just wanted to divide two integer values and get a float/Decimal output. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Floor value in math operators
Avi wrote: Hi, This will be a very simple question to ask all the awesome programmers here: How can I get answer in in decimals for such a math operator: 3/2 I get 1. I want to get 1.5 Thanks in advance, Avi I'm going to assume your operands are variables instead of numeric literals. Why not consider doing a type conversion to float or Decimal and then perform the division? --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Goes Mercurial
Kay Schluehr wrote: On 1 Apr., 07:56, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand wrote: In message 35d429fa-5d13-4703- a443-6a95c740c...@o6g2000yql.googlegroups.com, John Yeung wrote: Here's one that clearly expresses strong antipathy: http://mail.python.org/pipermail/python-dev/2009-March/087971.html There are lots of GUI- and Web-based front ends to Git. And look at on-line services like GitHub and Gitorious. The level of support for it is huge. Ironically Mercurials most popular UI frontend Tortoise is going to crash Python tools ( like Wing-IDE ) on Windows. That's a known issue for about a year and more and the developers are not inclined to fix it. This doesn't really increase my trust that Mercurials UI tools are of a higher quality than Git's no matter which platform is used. The conflict between TortoiseHg and Wing IDE can be fixed by simply uninstalling the Tortoise Overlays. You loose the graphic overlay on folders, but otherwise everything works. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: cross platform accessing paths (windows, linux ...)
Vlastimil Brom wrote: 2009/3/13 hendra kusuma penguinr...@gmail.com: you may want to use os.sep to replace manually written / \ : for each os I heard that unix/linux use / as directory separator while windows use \ and mac os use : Thanks for the notice about the : path separator on mac; windows uses \ but normally also accepts /. Now I see, the diversity is yet greater, than I thought (cf. http://en.wikipedia.org/wiki/Path_(computing) regards Vlasta The ':' separator is for old Mac systems using Mac OS prior to version 10.0. As of 10.0, they've moved to a unix based environment where the path separator is now a '/' character. There's been enough time passed you'll have a very hard time finding one of the old systems. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Keeping the Console Open with IDLE
W. eWatson wrote: Matimus wrote: On Feb 19, 8:06 pm, W. eWatson notval...@sbcglobal.net wrote: I'm using IDLE for editing, but execute programs directly. If there are execution or compile errors, the console closes before I can see what it contains. How do I prevent that? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7 N, 121° 2' 32 W, 2700 feet Web Page: www.speckledwithstars.net/ Open a console window and type in the name of the script rather than just double clicking on it. Or, you can terminate your script with a 'raw_input(press enter to quit)'. Matt I can open the Python command line from Start, but how do I navigate to the folder where the program is? I'm not sure whether I should feel old or write a smart alec comment -- I suppose there are people in the world who don't know what to do with a command prompt Assuming a Windows system: 2. Type 'cd ' (as in Change Directory) in the command prompt window (w/o the single quote characters) 3. Drag/drop the folder containing your python script to your command prompt window 4. Hit enter in your command prompt window. 5. Type python my_script_name.py to execute my_script_name.py. --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Keeping the Console Open with IDLE
W. eWatson wrote: I'm not sure whether I should feel old or write a smart alec comment -- I suppose there are people in the world who don't know what to do with a command prompt Assuming a Windows system: 2. Type 'cd ' (as in Change Directory) in the command prompt window (w/o the single quote characters) 3. Drag/drop the folder containing your python script to your command prompt window 4. Hit enter in your command prompt window. 5. Type python my_script_name.py to execute my_script_name.py. --David If I enter just cd, then it tells me cd is not defined. If I enter c:/python25, it tells me I have a syntax error at c in c:. The title of the black background window I have up with a prompt shown in it is Python(command line). Maybe this isn't the real Python console window? What I want is that if I execute the program by double clicking on its name to display the console window with the program or syntax errors shown without it closing in a split second. Putting read_raw in it doesn't work, since some error prevents it from ever being seen. What I meant was open open the command prompt, type cd, space, DO NOT hit enter yet. Drag the folder with your script into the command prompt window. Then go to the command prompt window and hit enter. This should compose a command similar to the following: C:\Documents and Settings\user cd C:\Documents and Settings\user\My Documents\My Project C:\Documents and Settings\user\My Documents\My Project _ --David -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question: Explain this behavior - a followup
max wrote: David Smith [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: range statements, the example doesn't work. Given that the beginning and ending values for the inner range statement are the same, the inner range statement will never be Is your question about the semantics of for else blocks or about the suitability of the algorithm given in the example? The for else block is behaving exactly as expected... Good question. The question was directed at the latter, the suitability of algorithm for determining prime numbers. range(1,1) [] range(500,500) [] see http://groups- beta.google.com/group/comp.lang.python/browse_frm/thread/d6c084e791a00 2f4?q=for+elsehl=en for a good explanation of when the else part of the loop is executed. Basically, whenever the loop is exited normally, which is what happens when you iterate over an empty list like the one returned by range(1,1) max -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question: Explain this behavior - a followup
First, thanks to those who offered answers. They didn't really answer my question, only because I had not worked through the example sufficiently well. Doing this, I believe I understand what is happening, and, if my understanding is correct, have discovered that for other beginning and ending values for the two range statements, the example doesn't work. Given that the beginning and ending values for the inner range statement are the same, the inner range statement will never be executed for its first iternation; the else will be. This is not correct. Simply make the beginning value a non-prime number, and the program still prints out that that number is prime. Changing both beginning and ending values on the two statements, the ouput is differentially buggy. -- http://mail.python.org/mailman/listinfo/python-list
Newbie question: Explain this behavior
Why does code snippet one work correctly, but not two. The only difference is the placement of the else. I know that indentation affects execution, but how does it change behavior in the following examples? Thank you. 1. for n in range(2, 10): for x in range(2, n): if n % x == 0: print n, 'equals', x, '*', n/x break else: # loop fell through without finding a factor print n, 'is a prime number' Output: 2 is a prime number 3 is a prime number 4 equals 2 * 2 5 is a prime number 6 equals 2 * 3 7 is a prime number 8 equals 2 * 4 9 equals 3 * 3 2. for n in range(2, 10): for x in range(2, n): if n % x == 0: print n, 'equals', x, '*', n/x break else: # loop fell through without finding a factor print n, 'is a prime number' Output: 3 is a prime number 4 equals 2 * 2 5 is a prime number 5 is a prime number 5 is a prime number 6 equals 2 * 3 7 is a prime number 7 is a prime number 7 is a prime number 7 is a prime number 7 is a prime number 8 equals 2 * 4 9 is a prime number 9 equals 3 * 3 -- http://mail.python.org/mailman/listinfo/python-list
Installing new version, erasing previous versions of Python
I currently have Python 2.2 and 2.3.4 installed. I want to install Python 2.4, and erase 2.3.4, but retain 2.2, for I need it for my connectivity program. According to the the documentation: If you have a previous installation of Python that you don't want to replace yet, use make altinstall the same set of files as make install except it doesn't create the hard link to pythonversion named python and it doesn't install the manual page at all. And prior to this, it says: All subdirectories created will have Python's version number in their name, e.g. the library modules are installed in /usr/local/lib/pythonversion/ by default, where version is the major.minor release number (e.g. 2.1). The Python binary is installed as pythonversion and a hard link named python is created. The only file not installed with a version number in its name is the manual page, installed as /usr/local/man/man1/python.1 by default. If I understand the above correctly, 1) make install and make altinstall use the same process, the only difference being the man page update, and the hard link, and 2) that previous versions of python are not deleted. Therefore I should be able to install 2.4 without deleting 2.2.2. If I wish to delete 2.3.4, I have to rm -r the appropriate directories. Any caveats? Is there any crosstalk between 2.2.2 and 2.4 modules? Thank you. -- David Smith 1845 Purdue Ave #3 Los Angeles Calif 90025-5592 (310) 478-8050 -- http://mail.python.org/mailman/listinfo/python-list