Pyro 3.8 released
I'm happy to announce Pyro 3.8 -- Python's own powerful remote method invocation technology! You can get it via http://pyro.sourceforge.net, then go to the SF project homepage download area. While 3.8 is a bug-fix release there are quite a lot of improvements since the previous version. Please check the changes chapter in the manual for details: http://pyro.sourceforge.net/manual/12-changes.html#latest Have fun, and thanks for your interest, support, and feedback! --Irmen de Jong ** What is Pyro? Pyro is an acronym for PYthon Remote Objects. Pyro is an advanced and powerful Distributed Object Technology system written entirely in Python, that is designed to be very easy to use. It is extremely easy to implement a distributed system with Pyro, because all network communication code is abstracted and hidden from your application. You just get a remote Python object and invoke methods on the object on the other machine. Pyro offers you a Name Server, an Event Service, mobile objects, remote exceptions, dynamic proxies, remote attribute access, automatic reconnection, a very good and detailed manual, and many examples to get you started right away. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Pygments 0.11 Straußenei released
I've just uploaded the Pygments 0.11 packages to CheeseShop. Pygments is a generic syntax highlighter written in Python. Download it from http://pypi.python.org/pypi/Pygments, or look at the demonstration at http://pygments.org/demo. Many thanks go to Tim Hatch for writing or integrating most of the bug fixes and new features in this release. Of course, thanks to all other contributors too! - Lexers added: * Nasm-style assembly language, thanks to delroth * YAML, thanks to Kirill Simonov * ActionScript 3, thanks to Pierre Bourdon * Cheetah/Spitfire templates, thanks to Matt Good * Lighttpd config files * Nginx config files * Gnuplot plotting scripts * Clojure * POV-Ray scene files * Sqlite3 interactive console sessions * Scala source files, thanks to Krzysiek Goj - Lexers improved: * C lexer highlights standard library functions now and supports C99 types. * Bash lexer now correctly highlights heredocs without preceding whitespace. * Vim lexer now highlights hex colors properly and knows a couple more keywords. * Irc logs lexer now handles xchat's default time format (#340) and correctly highlights lines ending in . * Support more delimiters for perl regular expressions (#258). * ObjectiveC lexer now supports 2.0 features. - Added Visual Studio style. - Updated markdown processor to Markdown 1.7. - Support roman/sans/mono style defs and use them in the LaTeX formatter. - The RawTokenFormatter is no longer registered to ``*.raw`` and it's documented that tokenization with this lexer may raise exceptions. - New option ``hl_lines`` to HTML formatter, to highlight certain lines. - New option ``prestyles`` to HTML formatter. - New option *-g* to pygmentize, to allow lexer guessing based on filetext (can be slowish, so file extensions are still checked first). - ``guess_lexer()`` now makes its decision much faster due to a cache of whether data is xml-like (a check which is used in several versions of ``analyse_text()``. Several lexers also have more accurate ``analyse_text()`` now. Cheers, Georg -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: mpmath 0.9 released
Hi, Mpmath version 0.9 is now available from the website: http://code.google.com/p/mpmath/ It can also be downloaded from the Python Package Index: http://pypi.python.org/pypi/mpmath/0.9 Mpmath is a pure-Python library for arbitrary-precision floating-point arithmetic that implements an extensive set of mathematical functions. It can be used as a standalone library or via SymPy (http://code.google.com/p/sympy/). The most significant change in 0.9 is that mpmath now transparently uses GMPY (http://code.google.com/p/gmpy/) integers instead of Python's builtin integers if GMPY is installed. This makes mpmath much faster at high precision. Computing 1 million digits of pi, for example, now only takes ~10 seconds. Extensive benchmarks (with and without GMPY) are available here: http://mpmath.googlecode.com/svn/bench/mpbench.html Credit goes to Case Van Horsen for implementing GMPY support. There are many new functions, including Jacobi elliptic functions (contributed by Mike Taschuk), various exponential integrals, Airy functions, Fresnel integrals, etc. Several missing basic utility functions have also been added, and Mario Pernici has taken great care to optimize the implementations of various elementary functions. For a more complete changelog, see: http://mpmath.googlecode.com/svn/trunk/CHANGES Bug reports and other comments are welcome at the issue tracker: http://code.google.com/p/sympy/issues/list or the mpmath mailing list: http://groups.google.com/group/mpmath Thanks to all who contributed code or provided feedback for this release! Fredrik -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Filling in Degrees in a Circle (Astronomy)
Maric Michaud wrote: Le Saturday 23 August 2008 01:12:48 W. eWatson, vous avez écrit : The other night I surveyed a site for astronomical use by measuring the altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north clockwise around the site to 360 degrees, almost north again) of obstacles, trees. My purpose was to feed this profile of obstacles (trees) to an astronomy program that would then account for not sighting objects below the trees. When I got around to entering them into the program by a file, I found it required the alt at 360 azimuth points in order from 0 to 360 (same as 0). Instead I have about 25 points, and expected the program to be able to do simple linear interpolation between those. Is there some simple operational device in Python that would allow me to create an array (vector) of 360 points from my data by interpolating between azimuth points when necessary? All my data I rounded to the nearest integer. Maybe there's an interpolation operator? As an example, supposed I had made 3 observations: (0,0) (180,45) and (360,0). I would want some thing like (note the slope of the line from 0 to 179 is 45/180 or 0.25): alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0 az : 0, 1,2,3, 180 Of course, I don't need the az. Not sure I got it, but is that fulfill your specs ? [20]: def interpolate(a, b) : slope = float(b[1] - a[1]) / (b[0] - a[0]) return [ slope * float(i) for i in xrange(b[0]-a[0] + 1) ] : [23]: interpolate((0, 0), (180, 45)) ...[23]: [0.0, 0.25, 0.5, 0.75, 44.5, 44.75, 45.0] [29]: interpolate((80, 20), (180, 45)) [0.0, 0.25, 0.5, 0.75, 1.0, 1.25, ... 24.5, 24.75, 25.0] Yes, the interpolation part looks right, but the tricky part is to be able to go through the list and find where one needs to generate all the missing az angles. A chunk of my data is in a post above yours. Here's a more revealing set of data where four data points are known: az el 0 10 4 14 (slope is 1) 12 30 (slope is 2) 15 15 (slope is -5) 16 points need to be generated, 0 to 15, representing 15 degrees around the circle. So, I'm doing this in my head, one would get 0 10 (slope is 1) 1 11 2 12 3 13 4 14 5 16 (slope is 2) 6 18 7 18 ... 12 30 13 25 14 20 15 15 I use Python occasionally, and starting up requires some effort, but I've finally decided to take a go at this. I'm working on this now, but my knowledge of python needs refreshing. Right now I have a file of all the az,el data I've collected, and I'd like to open it with Python for XP. However, Python doesn't like this: junkfile = open('c:\tmp\junkpythonfile','w') I get junkfile = open('c:\tmp\junkpythonfile','w') IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile' This problematic segment is just a hack of a similar statement which has the same problem and a much longer path. I suspect the problem is with the back slash. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
Carl Banks wrote: On Aug 22, 7:12 pm, W. eWatson [EMAIL PROTECTED] wrote: Is there some simple operational device in Python that would allow me to create an array (vector) of 360 points from my data by interpolating between azimuth points when necessary? All my data I rounded to the nearest integer. Maybe there's an interpolation operator? There's nothing built in, but see the bisect module. It is a good way to determine which interval you are in, and you can interpolate the points yourself. Carl Banks I'll take a look. I just posted above yours with a more insightful set of data than the first three pointer. Yes, some way of bisecting, or chopping is the trick here. One is just trying to fill in all the gaps with interpolation and produce 360 points to feed to the telescope software. It's sort of like giving someone, and forgetting interpolation here, the sequence 20, 30, blank, 60, 70, 80 and asking for the two missing tens between 30 and 60. 40 and 50, of course. The fellow above wrote an interpolate function that will probably fit the bill. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (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/ -- http://mail.python.org/mailman/listinfo/python-list
Error accessing the system registery
Hello members ! a message box is appearing when I goto 'Tools References' in VBA or VB6. I have tried many options but issue is not resolved yet. I have no administrator's rights in PC. can anybody resolve my problem ??? Best Regards M. Saqib Khan -- http://mail.python.org/mailman/listinfo/python-list
Re: Should Python raise a warning for mutable default arguments?
On Fri, 22 Aug 2008 20:37:09 -0700, Carl Banks wrote: On Aug 22, 10:42 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: Sometimes it seems that barely a day goes by without some newbie, or not- so-newbie, getting confused by the behaviour of functions with mutable default arguments. No sooner does one thread finally, and painfully, fade away than another one starts up. I suggest that Python should raise warnings.RuntimeWarning (or similar?) when a function is defined with a default argument consisting of a list, dict or set. (This is not meant as an exhaustive list of all possible mutable types, but as the most common ones that I expect will trip up newbies.) The warning should refer to the relevant FAQ or section in the docs. What do people think? -1 There's nothing questionable about using a mutable default argument, as long as you don't mutate it. There's nothing questionable about using a mutable default argument, so long as you know what behaviour to expect. I too use that behaviour, I like that behaviour, and I'm tired of people who want it fixed. Nevertheless, it is surprising to many people. My aim is to make it a little less surprising. Python shouldn't raise a warning just because something *might* be due to a misunderstanding. That's one opinion. As I've eluded to in an early post, I don't believe Python should refuse to perform an operation just because it might be slow. Nevertheless, that's precisely what the sum() function does. I'm suggesting a warning rather than an exception, but other than that, I suggest that there's precedence to what I am suggesting. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: setattr and getattr, when to use?
On Fri, 22 Aug 2008 20:50:17 -0700, maestro wrote: Why are these functions there? Is it somehow more idiomatic to use than to do obj.field ? Heavens no!!! Using setattr and getattr is *less* idiomatic. Is there something you can with them that you can't by obj.field reference? Absolutely. Consider: class Foo(object): pass foo = Foo() setattr(foo, x y, 1) print getattr(foo, x y) That's probably an abuse of setattr/getattr, but there are times where you might not know the name of the attribute until runtime, so you can't write foo.attr since you don't know what to write in place of attr. That's where setattr and getattr (as well as delattr and hasattr) come into play. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: 'While' question
Wojtek Walczak wrote: On Fri, 22 Aug 2008 10:42:13 -0400, Ben Keshet wrote: Thanks. I tried to use 'for' instead of 'while' as both of you suggested. It's running well as my previous version but breaks completely instead of just skipping the empty file. I suspect the reason is that this part is inside another 'for' so it stops everything. I just want to it to break only one 'for', that is go back to 5th line in the example code (directory C has one empty file): for line in f: ^^^ line = line.rstrip() if PRIMARY not in line: j += 1 if j == 20: break else: for line in f: ^^^ You're iterating through the same value in inner and outer loop. Don't do that. It's hard to predict the behavior of such a code. Regarding break statement, it breaks only the inner loop and returns to the outer loop/block. It would be great if you could reduce your code to a short piece that illustrates your problem and that we could all run. I ended up using another method as someone suggested to me. I am still not sure why the previous version got stuck on empty files, while this one doesn't: receptors = ['A' 'B'] for x in receptors: # open out_file for appending for each 'x' in receptors, close at same level out_file = open('c:/Linux/Dock_method_validation/%s/validation/pockets.out' %(x),'a') for i in range(10): for r in (7, 9, 11, 13, 15, 17): f = open('c:/Linux/Dock_method_validation/%s/validation/ligand_ran_line_%s_%sA_secondary_scored.mol2' %(x,i,r), 'r') # assume 'PRIMARY' should be found first # set flag for string 'PRIMARY' primary = False # iterate on file object, empty files will be skipped for line in f: if 'PRIMARY' in line: primary = True out_file.write(line.strip()) # copy scores elif 'TRIPOS' not in line and primary: out_file.write(line.strip()) out_file.write(' ') elif 'TRIPOS' in line and primary: break print out_file.write('\n') f.close() out_file.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: Error accessing the system registery
On Fri, 22 Aug 2008 23:33:32 -0700, SaqibKhan wrote: Hello members ! a message box is appearing when I goto 'Tools References' in VBA or VB6. I have tried many options but issue is not resolved yet. I have no administrator's rights in PC. can anybody resolve my problem ??? To solve your problem, start with this website. http://www.catb.org/~esr/faqs/smart-questions.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list
problems debugging python script on server
I'm having some problems debugging a python script on my server. I'm getting a 500 Internal Server Error. What the script does is take a link and then scrape a page and store some info from the page into a database. It seemed to be working fine until I changed one line of code from: shortenLink = /forum-replies.cfm?t=+threadNum+p=+pageNum +#r+anchorNum to: shortenLink = /forum-replies.cfm?t=+threadNum+p=+pageNum +#r+anchorNum if pageNum == '1': shortenLink = /forum-replies.cfm?t=+threadNum+#r+anchorNum Here is the form page where the link is submitted: http://goodbyepolar.com/cgi-bin/avatar.py Here is the code from the script that processes the form: http://codedumper.com/avuno You can use this URL in the form page to generate the 500 Internal Server Error: http://forums.whirlpool.net.au/forum-replies-herring.cfm?r=16373017tpr=1035665,1,2 As you can see from my codedump, I'm using import cgitb; cgitb.enable() to try to find the error, but with no success. I'm really at a loss as to why it's generating this error. Any help would be appreciated. Cheers. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems debugging python script on server
cgitb.enable() to try to find the error, but with no success. I'm really at a loss as to why it's generating this error. Apache's error_log and access_log are your friends. In this particular case your script breaks something http-server related: premature end of headers, incorrect permissions on script, wrong interpreter script, etc. Anyway the right reason is in the http server's logs. -- http://mail.python.org/mailman/listinfo/python-list
Re: def X(l=[]): weirdness. Python bug ?
Bart van Deenen wrote: I've stumbled onto a python behavior that I don't understand at all. http://effbot.org/zone/default-values.htm Is this correct behavior or is it a Python bug? Python's been out there for nearly 20 years. I think you safely can assume that if this really was a bug, someone else would have found it by now. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter, toplevel and images
Pedro wrote: and I just can see a grey window with a close button... However, when I try the same code with the root I can see both images... Can anyone give me a tip? this was cross-posted to the tkinter mailing list; in case someone stumbles upon this via a search engine, here's a link that explains why this happens: http://effbot.org/tkinterbook/photoimage.htm#note /F -- http://mail.python.org/mailman/listinfo/python-list
Pyro 3.8 released
I'm happy to announce Pyro 3.8 -- Python's own powerful remote method invocation technology! You can get it via http://pyro.sourceforge.net, then go to the SF project homepage download area. While 3.8 is a bug-fix release there are quite a lot of improvements since the previous version. Please check the changes chapter in the manual for details: http://pyro.sourceforge.net/manual/12-changes.html#latest Have fun, and thanks for your interest, support, and feedback! --Irmen de Jong ** What is Pyro? Pyro is an acronym for PYthon Remote Objects. Pyro is an advanced and powerful Distributed Object Technology system written entirely in Python, that is designed to be very easy to use. It is extremely easy to implement a distributed system with Pyro, because all network communication code is abstracted and hidden from your application. You just get a remote Python object and invoke methods on the object on the other machine. Pyro offers you a Name Server, an Event Service, mobile objects, remote exceptions, dynamic proxies, remote attribute access, automatic reconnection, a very good and detailed manual, and many examples to get you started right away. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is my thinking Pythonic?
Bruno Desthuilliers wrote: Given the lack of proper support for the descriptor protocol in old-style classes and a couple other diverging behaviors, I wouldn't say that advising newcomers to use new-style classes is so pointless. Yeah, but if you don't need descriptors, new-style classes don't buy you anything (except a slight slowdown in certain situations). Dogmatic use of new-style classes (or any other new feature) isn't pythonic. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: The Importance of Terminology's Quality
On Sat, 23 Aug 2008 00:06:28 -0400, John W Kennedy wrote: Martin Gregorie wrote: Not necessarily. An awful lot of CPU cycles were used before microcode was introduced. Mainframes and minis designed before about 1970 didn't use or need it No, most S/360s used microcode. I never used an S/360. I thought microcode came into the IBM world with S/370 and Future Series (which later reappeared as the AS/400, which I did use). Didn't the S/370 load its microcode off an 8 inch floppy? -- martin@ | Martin Gregorie gregorie. | Essex, UK org | -- http://mail.python.org/mailman/listinfo/python-list
How to know a top directory?
Hey there, Help me please. How to know a top directory? I mean I have path /this/ is/path and I wanna get /this/is. Also I want to use it as platform independent. If I want to pass c: \that\path then I need to get c:\that. Does anyone have ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to know a top directory?
On Sat, 23 Aug 2008 04:15:25 -0700 (PDT), Grigory Temchenko wrote: Help me please. How to know a top directory? I mean I have path /this/ is/path and I wanna get /this/is. Also I want to use it as platform independent. If I want to pass c: \that\path then I need to get c:\that. Does anyone have ideas? Read about os.path module. It's all in there: http://docs.python.org/lib/module-os.path.html -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list
xpath questions...
Hi... playing around with xpath and the html dom... i've got a sample: html body form action='foo' name='cat' /form /body /html i can create a test xpath: //form/[action and get the form stuff... i'm curious, is there a way to select an attribute, only if another attribute in the element is set to a given value?? something like //form/[EMAIL PROTECTED]'foo'[EMAIL PROTECTED] which would try to return name, if the action==foo didn't see this in any of the docs that i reviewed.. nor could i get it to work when i was playing around with xpather on firefox.. thoughts/comments/pointers... thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: xpath questions...
bruce wrote: playing around with xpath and the html dom... are you sure this question belongs on a Python forum? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: How to know a top directory?
Grigory wrote... I have path /this/is/path and I wanna get /this/is. Also I want to use it as platform independent. If I want to pass c: \that\path then I need to get c:\that. import os print os.path.split(/home/user/motoom)[0] print os.path.split(c:\\prj\\techniques\\python)[0] -- The ability of the OSS process to collect and harness the collective IQ of thousands of individuals across the Internet is simply amazing. - Vinod Vallopillil http://www.catb.org/~esr/halloween/halloween4.html -- http://mail.python.org/mailman/listinfo/python-list
Odd behaviour on importing variable from module
Hi, I've found the following behaviour on importing a variable from a module somewhat odd. The behaviour is identical in Python 2.5 and 3.0b2. In summary, here's what happens. I have a module, oddmodule.py (below), that defines a variable, OddVariable, by assigning a value A to it. The file I execute, mainfile.py, imports and re-binds OddVariable to a value B. I have two test modules which import the OddVariable in two different ways, one via import oddmodule and another via from oddmodule import OddVariable. The weird behaviour is that by importing using the former syntax, I can see OddVariable bound to B (as expected), but the latter syntax sees it bound A. Is this the intended behaviour? Am I misunderstanding what is going on here? Source code: oddmodule.py print(Importing oddmodule) OddVariable = [not, initialized] def OddFunction(): print(OddVariable from oddmodule.OddFunction:, OddVariable) mainfile.py import oddmodule import testmodule1 import testmodule2 print(Initializing OddVariable) oddmodule.OddVariable = [some, list] print() testmodule2.DoTest() print() testmodule1.DoTest() testmodule1.py from oddmodule import OddVariable, OddFunction def DoTest(): print(STARTING testmodule1.DoTest) print(OddVariable from testmodule1:, OddVariable) OddFunction() print(FINISHED testmodule1.DoTest) testmodule2.py import oddmodule def DoTest(): print(STARTING testmodule2.DoTest) print(OddVariable from testmodule2:, oddmodule.OddVariable) oddmodule.OddFunction() print(FINISHED testmodule2.DoTest) OUTPUT: Importing oddmodule Initializing OddVariable STARTING testmodule2.DoTest OddVariable from testmodule2: ['some', 'list'] OddVariable from oddmodule.OddFunction: ['some', 'list'] FINISHED testmodule2.DoTest STARTING testmodule1.DoTest OddVariable from testmodule1: ['not', 'initialized'] !!! OLD VALUE !!! OddVariable from oddmodule.OddFunction: ['some', 'list'] FINISHED testmodule1.DoTest Many thanks, Roman -- http://mail.python.org/mailman/listinfo/python-list
Re: xpath questions...
Hi, this is totally not Python related, so this is the wrong list. bruce wrote: form action='foo' name='cat' i'm curious, is there a way to select an attribute, only if another attribute in the element is set to a given value?? something like //form/[EMAIL PROTECTED]'foo'[EMAIL PROTECTED] which would try to return name, if the action==foo //[EMAIL PROTECTED]'foo']/@name didn't see this in any of the docs that i reviewed.. nor could i get it to work when i was playing around with xpather on firefox.. thoughts/comments/pointers... Read a good XPath tutorial. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: How to know a top directory?
Michiel Overtoom wrote: I have path /this/is/path and I wanna get /this/is. Also I want to use it as platform independent. If I want to pass c: \that\path then I need to get c:\that. import os print os.path.split(/home/user/motoom)[0] print os.path.split(c:\\prj\\techniques\\python)[0] in this case, os.path.dirname() is more convenient. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd behaviour on importing variable from module
rs387 wrote: I've found the following behaviour on importing a variable from a module somewhat odd. The behaviour is identical in Python 2.5 and 3.0b2. the construct from oddmodule import OddVariable, OddFunction assigns the *values* of the given module names to new variables in the importing module's namespace. that is, you're binding new names to the values the variables happen to have when the from-import statement is executed. given this, the behaviour should be no more surprising than A = value B = A A = new value print B # prints value reading up on how objects and names work in Python could be a good idea; this page might help: http://effbot.org/zone/python-objects.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd behaviour on importing variable from module
rs387 wrote: I've found the following behaviour on importing a variable from a module somewhat odd. The behaviour is identical in Python 2.5 and 3.0b2. In summary, here's what happens. I have a module, oddmodule.py (below), that defines a variable, OddVariable, by assigning a value A to it. The file I execute, mainfile.py, imports and re-binds OddVariable to a value B. I have two test modules which import the OddVariable in two different ways, one via import oddmodule and another via from oddmodule import OddVariable. The weird behaviour is that by importing using the former syntax, I can see OddVariable bound to B (as expected), but the latter syntax sees it bound A. Is this the intended behaviour? Yes. Think of from module import var as a shortcut for import module var = module.var del module This is not entirely correct as 'from package import module' implicitly imports 'module' but should explain the binding behaviour. Peter -- http://mail.python.org/mailman/listinfo/python-list
RE: xpath questions...
Hi guys.. Regarding the xpath question I've posed, some have said that it shouldn't be here on the mailing list. Give that I'm writing the test scripts/apps in python, using the python libs, where else should it be posted? I mean, I could post the entire sample script so you can see that it's using python, but I simplified the issue. So, please tell me, just where should the question be posted? Thanks -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Fredrik Lundh Sent: Saturday, August 23, 2008 4:44 AM To: python-list@python.org Subject: Re: xpath questions... bruce wrote: playing around with xpath and the html dom... are you sure this question belongs on a Python forum? /F -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: xpath questions...
bruce wrote: Regarding the xpath question I've posed, some have said that it shouldn't be here on the mailing list. Give that I'm writing the test scripts/apps in python, using the python libs, where else should it be posted? I mean, I could post the entire sample script so you can see that it's using python, but I simplified the issue. there was zero Python content left after the simplification. maybe you should at least mention what library you're using to play around with xpath and the html dom ? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: __eq__ problem with subclasses
On Fri, 22 Aug 2008 14:37:06 -0600 Daniel Israel [EMAIL PROTECTED] wrote: I am very confused by the following behavior. I have a base class which defines __eq__. I then have a subclass which does not. When I evaluate the expression a==b, where a and b are elements of these classes, __eq__ is always called with the subclass as the first argument, regardless of the order I write my expression. I can't see why this would be desired behavior. I am sure that Python is doing some optimization based on the fact that ==, like * and + but unlike / and - are commutative. Why does a1==a2 generate a call to c1.__eq__(a2, a1) instead of c1.__eq__(a1, e2)? This is important because I am writing a math library in which '==' is being used for assignment, i.e., 'a==b+c' set 'a' equal to the sum of 'b' and 'c'. So 'a==b' is very different from 'b==a'. But isn't that what a = b + c does? -- D'Arcy J.M. Cain [EMAIL PROTECTED] | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
RE: xpath questions...
valid point...!! here's the test python.. ugly as it is!! Lodge It New All About ? Paste #83093 Paste Details posted on 2008-08-23 @ 15:22 reply to this paste download paste compare with paste select different colorscheme Autumn Borland Bw Colorful Default Emacs Friendly Fruity Manni Murphy Native Pastie Perldoc Trac Vs toggle line numbers 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 #!/usr/bin/python # # test.py # # scrapes/extracts the basic data for the college # # # the app gets/stores # name # url # address (street/city/state # phone # ##3 #test python script import re import libxml2dom import urllib import urllib2 import sys, string from mechanize import Browser import mechanize #import tidy import os.path import cookielib from libxml2dom import Node from libxml2dom import NodeList import subprocess import MySQLdb #import mysql_config import time # # Parse pricegrabber.com urlopen = urllib2.urlopen ##cj = urllib2.cookielib.LWPCookieJar() Request = urllib2.Request br = Browser() br2 = Browser() user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' values1 = {'name' : 'Michael Foord', 'location' : 'Northampton', 'language' : 'Python' } headers = { 'User-Agent' : user_agent } url=http://schedule.berkeley.edu/; url=http://schedule.psu.edu/; #=== if __name__ == __main__: # main app txdata = None # # get the kentucky test pages #br.set_cookiejar(cj) br.set_handle_redirect(True) br.set_handle_referer(True) br.set_handle_robots(False) br.addheaders = [('User-Agent', 'Firefox')] #cnt is the page count for the master url murl=url print url =,murl br.open(murl) #cj.save(COOKIEFILE)# resave cookies res = br.response() # this is a copy of response s = res.read() # s contains HTML not XML text d = libxml2dom.parseString(s, html=1) #get the input/text dialogs #tn1 = //[EMAIL PROTECTED]'main_content']/form[1]/input[position()=1]/@name q=//img/parent::*/attribute::href q=//[EMAIL PROTECTED]'cos_search1']/@action t1=d.xpath(q) print href = ,t1 print hnode =,t1[0].nodeValue print htest =,t1[0].textContent print htesttt =,t1[0].toString() sys.exit() thanks!! -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Fredrik Lundh Sent: Saturday, August 23, 2008 5:58 AM To: python-list@python.org Subject: Re: xpath questions... bruce wrote: Regarding the xpath question I've posed, some have said that it shouldn't be here on the mailing list. Give that I'm writing the test scripts/apps in python, using the python libs, where else should it be posted? I mean, I could post the entire sample script so you can see that it's using python, but I simplified the issue. there was zero Python content left after the simplification. maybe you should at least mention what library you're using to play around with xpath and the html dom ? /F -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Problems calling batch files (*.bat) from Python???
Hello, I am new in Python programming and I have the following problem: I have a script in which I need to open an application (called from a batch file - trace.bat). For this purpuse, I'm executing the following piece of code: import os, win32process from win32api import Sleep os.chdir(D:\\Marian\\Proiecte\\AMT\\Trace) os.startfile(launch_trace.bat) #subprocess.call(D:\\Marian\\Proiecte\\AMT\\Trace\\trace.bat) #pr = win32process.CreateProcess(None, D:\\Marian\\Proiecte\\AMT\\Trace\\trace.bat, None, None, 0, win32process.NORMAL_PRIORITY_CLASS, None, None, win32process.STARTUPINFO()) But, when I call the os.startfile(launch_trace.bat) command, the program prompter appears, but the program called in the batch file is opened ONLY after the whole script has finished the execution. Unfortunatley, after this line there are some very important things that has to be executed in the right order. I mean, the execution of the batch file is important for the rest of the code. What is strange is that if I execute this code step-by-step, using the debugger, or if I put a breakpoint on the launch_trace line and then I step on it, everything is working fine - the Trace application is launced correctly. Could anyone help in this direction? I need to launch the application and after this I want to continue the execution of the script. Thank you in advance! P.S. I've also tried with processes (see the commented lines) and I get the same problems; for MSWord application, the behavior is the same - it is launched after the script ends. Also, I have to mention that I don't have a DLL of this application and it is not a COM application in order to control it from Python. Marian -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd behaviour on importing variable from module
the construct from oddmodule import OddVariable, OddFunction assigns the *values* of the given module names to new variables in the importing module's namespace. that is, you're binding new names to the values the variables happen to have when the from-import statement is executed. Ah right, this does indeed explain what I'm seeing. For some reason I thought from module import variable magically makes variable an alias, so to speak, for module.var, which of course it does not. Yes. Think of from module import var as a shortcut for import module var = module.var del module Good tip, I'll remember this. Thanks very much Fredrik, Peter! Roman -- http://mail.python.org/mailman/listinfo/python-list
RE: xpath questions...
valid point...!! here's the test python.. ugly as it is!! #!/usr/bin/python # # test.py # # scrapes/extracts the basic data for the college # # # the app gets/stores # name # url # address (street/city/state # phone # ##3 #test python script import re import libxml2dom import urllib import urllib2 import sys, string from mechanize import Browser import mechanize #import tidy import os.path import cookielib from libxml2dom import Node from libxml2dom import NodeList import subprocess import MySQLdb #import mysql_config import time # # Parse pricegrabber.com urlopen = urllib2.urlopen ##cj = urllib2.cookielib.LWPCookieJar() Request = urllib2.Request br = Browser() br2 = Browser() user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' values1 = {'name' : 'Michael Foord', 'location' : 'Northampton', 'language' : 'Python' } headers = { 'User-Agent' : user_agent } url=http://schedule.berkeley.edu/; url=http://schedule.psu.edu/; #=== if __name__ == __main__: # main app txdata = None # # get the kentucky test pages #br.set_cookiejar(cj) br.set_handle_redirect(True) br.set_handle_referer(True) br.set_handle_robots(False) br.addheaders = [('User-Agent', 'Firefox')] #cnt is the page count for the master url murl=url print url =,murl br.open(murl) #cj.save(COOKIEFILE)# resave cookies res = br.response() # this is a copy of response s = res.read() # s contains HTML not XML text d = libxml2dom.parseString(s, html=1) #get the input/text dialogs #tn1 = //[EMAIL PROTECTED]'main_content']/form[1]/input[position()=1]/@name q=//img/parent::*/attribute::href q=//[EMAIL PROTECTED]'cos_search1']/@action t1=d.xpath(q) print href = ,t1 print hnode =,t1[0].nodeValue print htest =,t1[0].textContent print htesttt =,t1[0].toString() sys.exit() thanks!! -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Fredrik Lundh Sent: Saturday, August 23, 2008 5:58 AM To: python-list@python.org Subject: Re: xpath questions... bruce wrote: Regarding the xpath question I've posed, some have said that it shouldn't be here on the mailing list. Give that I'm writing the test scripts/apps in python, using the python libs, where else should it be posted? I mean, I could post the entire sample script so you can see that it's using python, but I simplified the issue. there was zero Python content left after the simplification. maybe you should at least mention what library you're using to play around with xpath and the html dom ? /F -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Python open of c:\ path Problem
Title: Signature.html Python doesn't like this: junkfile = open('c:\tmp\junkpythonfile','w') I get junkfile = open('c:\tmp\junkpythonfile','w') IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile' This problematic segment is just a hack of a similar statement which has the same problem and a much longer path. I suspect the problem is with the back slash. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (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 "Equilibrium is when all the fast things have happened, and all of the slow things have not." -- Richard Feynman Web Page: www.speckledwithstars.net/ -- http://mail.python.org/mailman/listinfo/python-list
ctypes: loading .so file on Linux
Hi, I am am falling at the first hurdle when trying to access a library using ctypes. I have a file libucdb.so which the file command says is shared object, but I cannot get it to load: Any help would be appreciated: dmccarthy: file /opt/questasim_6.4/questasim/linux/libucdb.a /opt/ questasim_= 6.4/questasim/linux/libucdb.so /opt/questasim_6.4/questasim/linux/libucdb.a: current ar archive /opt/questasim_6.4/questasim/linux/libucdb.so: ELF 32-bit LSB shared object,= Intel 80386, version 1 (SYSV), not stripped dmccarthy: python ActivePython 2.5.1.1 (ActiveState Software Inc.) based on Python 2.5.1 (r251:54863, May 2 2007, 08:46:07) [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2 Type help, copyright, credits or license for more information. cdll.LoadLibrary(libc.so.6) Traceback (most recent call last): File stdin, line 1, in module NameError: name 'cdll' is not defined from ctypes import * ^[[A^[[A ^e stdin, line 1 SyntaxError: invalid syntax cdll.LoadLibrary(libc.so.6) CDLL 'libc.so.6', handle 2a958a2900 at 2a95dda490 cdll.LoadLibrary(libucdb.so) Traceback (most recent call last): File stdin, line 1, in module File /software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/ lib/pyth= on2.5/ctypes/__init__.py, line 423, in LoadLibrary return self._dlltype(name) File /software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/ lib/pyth= on2.5/ctypes/__init__.py, line 340, in __init__ self._handle =3D _dlopen(self._name, mode) OSError: libucdb.so: cannot open shared object file: No such file or directo= ry cdll.LoadLibrary(libc.so.6) CDLL 'libc.so.6', handle 2a958a2900 at 2a95df3ad0 libc =3D CDLL(libc.so.6) libc CDLL 'libc.so.6', handle 2a958a2900 at 2a95dda490 libc =3D CDLL(libucdb.so) Traceback (most recent call last): File stdin, line 1, in module File /software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/ lib/pyth= on2.5/ctypes/__init__.py, line 340, in __init__ self._handle =3D _dlopen(self._name, mode) OSError: libucdb.so: cannot open shared object file: No such file or directo= ry libc =3D CDLL(/opt/questasim_6.4/questasim/linux/libucdb.so) Traceback (most recent call last): File stdin, line 1, in module File /software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/ lib/pyth= on2.5/ctypes/__init__.py, line 340, in __init__ self._handle =3D _dlopen(self._name, mode) OSError: /opt/questasim_6.4/questasim/linux/libucdb.so: cannot open shared o= bject file: No such file or directory ^[[A File stdin, line 1 ^ SyntaxError: invalid syntax - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: Should Python raise a warning for mutable default arguments?
2008/8/22 Peter Otten [EMAIL PROTECTED]: [EMAIL PROTECTED] wrote: DrScheme is an implementation of Scheme that is very newbie-friendly. It has several limited sub-languages, etc. So maybe a command line option can be added to Python3 ( - newbie ? :-) ) that just switches on similar warnings, to help newbies (in schools, where there's a teacher that encourages to always use that command line option) avoid some of the most common traps. Or maybe bundle pychecker with idle? I think that is an excellent idea! In fact why can't pychecker be included in the standard distribution? I'd love it if compilation was done with pychecker checking by default. Python could definitely use a -Wall mode. -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Tkinter
J-Burns wrote: Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. OK, looks like you are getting direct answers, but I thought I'd mention an easy way to experiment with Tkinter programming. If you start Idle with the -n switch (*), then anything you do shares the same mainloop as Idle, and your window manipulation is live. This means, that immediately after typing in: import Tkinter f = Tkinter.Frame() You will see the frame f show up. You can experiment directly with watching the effects of calls that you make in the interactive interpretter. (*) Easy way to do this: On some systems, associate a button with pythonw -m idlelib.idle -n. On a Windows system with an Idle shortcut/button/icon already: Copy the shortcut/button/icon Right-click the shortcut and select the properties menu. On the General tab of the Properties window: Give the shortcut a nicer name (I use Idle25-n for mine). On the Shortcut tab of the properties window, add a space and a -n to the target line. Click OK, and try out your new button. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
W. eWatson wrote: ... I'm working on this now, but my knowledge of python needs refreshing. Right now I have a file of all the az,el data I've collected, and I'd like to open it with Python for XP. However, Python doesn't like this: junkfile = open('c:\tmp\junkpythonfile','w') I get junkfile = open('c:\tmp\junkpythonfile','w') IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile' This problematic segment is just a hack of a similar statement which has the same problem and a much longer path. I suspect the problem is with the back slash. A standard windows error. note that '\t' is a tab, and I doubt you have a directory named tab m p. Get in the habit of _always_ using: junkfile = open(r'c:\tmp\junkpythonfile','w') or junkfile = open('c:\\tmp\\junkpythonfile','w') for file names. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Python open of c:\ path Problem
Wayne Watson wrote: Python doesn't like this: junkfile = open('c:\tmp\junkpythonfile','w') I get junkfile = open('c:\tmp\junkpythonfile','w') IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile' The clue, if you needed one, is there in that traceback. Notice the *single* slash before the t in contrast with the *double* slash before the j. In short, you need to double up your backslashes, or use a raw string or forward slashes. There's an FAQ somewhere but I can't be bothered to look for it right now. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Python open of c:\ path Problem
Wayne Watson wrote: Python doesn't like this: junkfile = open('c:\tmp\junkpythonfile','w') I get junkfile = open('c:\tmp\junkpythonfile','w') IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile' \ is used as an escape character in string literals, so \t doesn't mean what you think it does. see http://docs.python.org/ref/strings.html for details. to work around this, use double backslashes (foo\\bar), raw strings (rfoo\bar), or, usually easiest, forward slashes (foo/bar). /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Generate alphabet?
On Sat, Aug 23, 2008 at 6:02 AM, ssecorp [EMAIL PROTECTED] wrote: In Haskell I can do [1..10] for range(1,11) and ['a'..'z'] for a list of the alphabet. Is there a way in Python to generate chars? how about: import string ','.join(string.ascii_lowercase) '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' -- Best Regards, Leo Jay -- http://mail.python.org/mailman/listinfo/python-list
Re: Should Python raise a warning for mutable default arguments?
On Aug 23, 4:09 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Fri, 22 Aug 2008 20:37:09 -0700, Carl Banks wrote: On Aug 22, 10:42 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: Sometimes it seems that barely a day goes by without some newbie, or not- so-newbie, getting confused by the behaviour of functions with mutable default arguments. No sooner does one thread finally, and painfully, fade away than another one starts up. I suggest that Python should raise warnings.RuntimeWarning (or similar?) when a function is defined with a default argument consisting of a list, dict or set. (This is not meant as an exhaustive list of all possible mutable types, but as the most common ones that I expect will trip up newbies.) The warning should refer to the relevant FAQ or section in the docs. What do people think? -1 There's nothing questionable about using a mutable default argument, as long as you don't mutate it. There's nothing questionable about using a mutable default argument, so long as you know what behaviour to expect. I too use that behaviour, I like that behaviour, and I'm tired of people who want it fixed. Nevertheless, it is surprising to many people. My aim is to make it a little less surprising. Python shouldn't raise a warning just because something *might* be due to a misunderstanding. That's one opinion. 1. When you print spurious warnings, the overall effectiveness of the warning system is diminished. People start to ignore them, either by disabling them or by mentally tuning out. This in turn makes people less likely to notice if a real warning is printed. When you print a warning, you better be %99.9 sure that it's something worth warning about, otherwise you are doing more harm than good. (Story time: I once worked on a system that displayed warnings to jet fighter pilots. Our requirements were not to show the pilot a warning unless the airplane actually tries something and fails, even if the computer is absolutely sure that it would fail. Ex: if computer knows for sure the engine can't produce more than (say) 50% rated thrust, the pilot does not get a warning unless he actually requests more than 50% thrust. The reason is for this, according to the senior engineers on the team, was that pilots would start to ignore the warning lights REALLY FAST.) 2. It's rude to be presumptuous, which is what the compiler would be if it printed this warning. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Should Python raise a warning for mutable default arguments?
On Aug 22, 10:32 pm, Peter Otten [EMAIL PROTECTED] wrote: Christian Heimes wrote: Steven D'Aprano wrote: I suggest that Python should raise warnings.RuntimeWarning (or similar?) when a function is defined with a default argument consisting of a list, dict or set. (This is not meant as an exhaustive list of all possible mutable types, but as the most common ones that I expect will trip up newbies.) The warning should refer to the relevant FAQ or section in the docs. What do people think? -0 from me. I'd rather feature it more prominently in the tutorial, a section The five most common pitfalls or something like that. I don't see a chance for your proposal. How are you going to detect mutable objects? Custom types can be mutable as well as immutable. A check at compilation time for list literals would catch 90 % of the cases. The warning would be targeted at newbies after all. It might still be a source of confusion when they try to import someone else's code that uses mutable defaults intentionally. -1. I think, as many people before me has said, we should treat programmers as an adult[1], and doesn't try to babysit them by giving a warning, or worse as an exception. But I do agree that python should have something like -Wall, where programmers are warned of all potential problems. [1] Anyway, you spent your time being a newbie only for a very short time. -- http://mail.python.org/mailman/listinfo/python-list
Re: Generators can only yield ints?
On Aug 23, 5:44 am, defn noob [EMAIL PROTECTED] wrote: def letters(): a = xrange(ord('a'), ord('z')+1) B = xrange(ord('A'), ord('Z')+1) while True: yield chr(a) yield chr(B) l = letters() l.next() Traceback (most recent call last): File pyshell#225, line 1, in module l.next() File pyshell#223, line 5, in letters yield chr(a) TypeError: an integer is required Any way to get around this? The most direct translation on what you've done, with corrections, is either this: def letters(): a = xrange(ord('a'), ord('z') + 1) B = xrange(ord('A'), ord('Z') + 1) while True: yield a yield B l = letters() l.next() xrange(97, 123) or this: def letters(): a = xrange(ord('a'), ord('z') + 1) B = xrange(ord('A'), ord('Z') + 1) while True: yield [chr(char) for char in a] yield [chr(char) for char in B] l = letters() l.next() ['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'] but my psychic ability guessed that you actually wanted this instead: def letters(): a = xrange(ord('a'), ord('z') + 1) B = xrange(ord('A'), ord('Z') + 1) a = [chr(char) for char in a] B = [chr(char) for char in B] index = 0 while index 26: yield a[index] yield B[index] index += 1 l = letters() l.next() 'a' or possibly in a more pythonic style, using for: def letters(): a = xrange(ord('a'), ord('z') + 1) B = xrange(ord('A'), ord('Z') + 1) for lower, upper in zip(a, B): yield chr(lower) yield chr(upper) l = letters() l.next() 'a' paralelly, my psychic ability also tells me that you might prefer this instead: def letters(): a = xrange(ord('a'), ord('z') + 1) B = xrange(ord('A'), ord('Z') + 1) for lower, upper in zip(a, B): yield chr(lower), chr(upper) l = letters() l.next() ('a', 'A') -- http://mail.python.org/mailman/listinfo/python-list
Re: __eq__ problem with subclasses
Daniel Israel wrote: I am very confused by the following behavior. I have a base class which defines __eq__. I then have a subclass which does not. When I evaluate the expression a==b, where a and b are elements of these classes, __eq__ is always called with the subclass as the first argument, regardless of the order I write my expression. I can't see why this would be desired behavior. This is the quickest way to make sure that an over-ridden __eq__ gets called (that is, before the __eq__ is looked up, it asks, in this comparison of a and b (where type(a) == A and type(b) == B), is A != B and (A a subclass of B or B a subclass of A)? If so, there is one object of a more general type (the superclass), and one object of a more specific type (the subclass). If you have this situation, the more specific class _may_ have over-ridden the comparison method (in this case __eq__) of the more general class. We want to use the more specific comparison in such cases (as the subclass may have a way of folding in extra data into the comparisons in a way the general could not). However, without looking up the comparison method in the more specific subclass, you don't know whether or not there _is_ an over-riding method. Once you have done the work of the method lookup for one of the objects (which you must do to determine whether you _need_ to evaluate in a special order), the decision becomes, Do we then throw away the work we did looking up the comparison method on one arg and compute a comparison on the other arg? The cost of allowing the expression order to determine the call made when no comparison override is provided would be more computation before finally dispatching on the method. Would you want to slow down the comparison to get the behavior you seem to want? --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Python 3000 C API Changes
I am trying to find out what Python C APIs are changing from Python 2.5 to Python 3.0 but there does not seem to be a single list of changes (or at least google is not finding one). If someone knows about where I should look, please let me know. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Tkinter
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: On Aug 22, 7:20 am, J-Burns [EMAIL PROTECTED] wrote: . . . If I have a drop down box in Pythons tkinter, is it possible that the entities that the drop down has are items that have been picked up from a notepad file via file handling? You can just open the file once (on the script's start), when you press a button, or every so often, that will update the drop-down box. . . . I find a notepad file so incongruous in this setting that I wonder if J-Burns meant something other than, the contents of a file which might have been generated originally through use of Notepad. If, for example, he has in mind, the current contents of a Notepad editing session, that, too, is possible with Python; 'fact, most any interpretation I can imagine is acessible with Python. The first step is simply to be clear about the goal. -- http://mail.python.org/mailman/listinfo/python-list
Re: rules of thumb for cross os code
In article [EMAIL PROTECTED], DwBear75 [EMAIL PROTECTED] wrote: I am considering using python as a replacement for a lot of bash scripting that I have been doing. I would like to be as cross platform . . . 2) nifty lambda's or other things to create functions fit for the environment 3) capturing return codes of other executables called from python; ie use os.system, or popen? or ? I don't understand 2); maybe URL: http://www.pardus.org.tr/eng/projects/comar/PythonInPardus.html is a response, although I suspect it's at a different level than you had in mind. For 3), read URL: http://docs.python.org/lib/node536.html on Replacing os.system(), although I have several personal quibbles with details of the subprocess reference documentation. -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
Scott David Daniels wrote: W. eWatson wrote: ... I'm working on this now, but my knowledge of python needs refreshing. Right now I have a file of all the az,el data I've collected, and I'd like to open it with Python for XP. However, Python doesn't like this: junkfile = open('c:\tmp\junkpythonfile','w') I get junkfile = open('c:\tmp\junkpythonfile','w') IOError: [Errno 2] No such file or directory: 'c:\tmp\\junkpythonfile' This problematic segment is just a hack of a similar statement which has the same problem and a much longer path. I suspect the problem is with the back slash. A standard windows error. note that '\t' is a tab, and I doubt you have a directory named tab m p. Get in the habit of _always_ using: junkfile = open(r'c:\tmp\junkpythonfile','w') or junkfile = open('c:\\tmp\\junkpythonfile','w') for file names. --Scott David Daniels [EMAIL PROTECTED] Thanks. r did the job nicely. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3000 C API Changes
On Sat, Aug 23, 2008 at 11:34 AM, rahul [EMAIL PROTECTED] wrote: I am trying to find out what Python C APIs are changing from Python 2.5 to Python 3.0 but there does not seem to be a single list of changes (or at least google is not finding one). If someone knows about where I should look, please let me know. -- http://docs.python.org/dev/3.0/whatsnew/3.0.html#build-and-c-api-changes http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestion for improved ImportError message
On Aug 15, 7:42 pm, [EMAIL PROTECTED] wrote: Lie: I'm not sure there are any reason to test for failed import in doctest) I have code that uses numpy if available, otherwise uses slower normal Python code. Inside the doctests I'd like to test both situations... Why? Is there a difference in result if you have used numpy and python code? If that is, I smell a bad code. What numpy and python code version would return in that situation should be the same (practically it isn't always feasible though). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestion for improved ImportError message
Lie wrote: I have code that uses numpy if available, otherwise uses slower normal Python code. Inside the doctests I'd like to test both situations... Why? Is there a difference in result if you have used numpy and python code? If that is, I smell a bad code. What numpy and python code version would return in that situation should be the same (practically it isn't always feasible though). maybe the point is to use doctest to *verify* that the code generates the same result whether or not numpy is used? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Psycho question
On Aug 8, 7:18 pm, David C. Ullrich [EMAIL PROTECTED] wrote: The one thing that puzzles me about all the results is why // is so much slower than / inside that Psyco loop. Just an oversight. The optimization about '/' between integers was not copied for the case of '//' between integers. Fixed in the svn head :-) Armin -- http://mail.python.org/mailman/listinfo/python-list
Total No. of Records in a File?
I have an ordinary text file with a CR at the end of a line, and two numbers in each line. Is there some way to determine the number of lines (records) in the file before I begin reading it? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Total No. of Records in a File?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Err...you want to know what is in a file before you open it? This could be done if you keep some external database documenting changes made to the file. But unless I misunderstand what you're saying, then it's not possible to know the contents of a file without opening and reading that file. W. eWatson wrote: I have an ordinary text file with a CR at the end of a line, and two numbers in each line. Is there some way to determine the number of lines (records) in the file before I begin reading it? -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkiwSZ4ACgkQLMI5fndAv9hXugCeJs5XBkLLne6ljqQggB/MoAVs SNIAoJxsU04cwcZMrH9QjElAbMD34RdK =RlmP -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Total No. of Records in a File?
On 2008-08-23, W. eWatson [EMAIL PROTECTED] wrote: I have an ordinary text file with a CR at the end of a line, and two numbers in each line. Is there some way to determine the number of lines (records) in the file before I begin reading it? If the lines are fixed lengh (e.g. always 12 bytes long), then you can use os.stat() or os.fstat() to find the size of the file. Divide the size of the file by the number of bytes in a line, and you get the number of lines. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: Total No. of Records in a File?
W. eWatson wrote: I have an ordinary text file with a CR at the end of a line, and two numbers in each line. Is there some way to determine the number of lines (records) in the file before I begin reading it? In the general case, no. A file is just a bunch of bytes. If you know that all lines have exactly the same length, you can of course fetch the file size and divide by the line size, but that doesn't work for arbitrary files. Why do you need to know the number of lines before reading it, btw? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Total No. of Records in a File?
Nick Dumas wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Err...you want to know what is in a file before you open it? This could be done if you keep some external database documenting changes made to the file. But unless I misunderstand what you're saying, then it's not possible to know the contents of a file without opening and reading that file. W. eWatson wrote: I have an ordinary text file with a CR at the end of a line, and two numbers in each line. Is there some way to determine the number of lines (records) in the file before I begin reading it? -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkiwSZ4ACgkQLMI5fndAv9hXugCeJs5XBkLLne6ljqQggB/MoAVs SNIAoJxsU04cwcZMrH9QjElAbMD34RdK =RlmP -END PGP SIGNATURE- Maybe. I could see it if the file were truly in a record format. The # of records might be kept by the OS. It's conceivable that Python or the OS might see a file with a CR as recordized. All unlikely though. Just checkin'. How about in a slightly different case. Suppose I want to know the number of files in a folder? The OS and maybe some Python method might know that. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: 'While' question
Ben Keshet wrote: ... I ended up using another method as someone suggested to me. I am still not sure why the previous version got stuck on empty files, while this one doesn't: receptors = ['A' 'B'] *** Alarm bells *** Do you mean ['AB'], or do you mean ['A', 'B']? ...(more code one way) ... Don't be afraid of defining functions, you are nested too deeply to easily understand, and hence likely to make mistakes. For similar reasons, I don't like names like x and i unless there are no better names. Also, since you don't seem to really need to write, I used print. The comments would be better if I knew the field a bit (or your code had had better names). Try something like (obviously I couldn't test it, so untested code): OUTPUT = 'c:/Linux/Dock_method_validation/%s/validation/pockets.out' INPUT = ('c:/Linux/Dock_method_validation/%s/validation/' 'ligand_ran_line_%s_%sA_secondary_scored.mol2') def extract_dist(dest, receptor, line, ligand): '''Get distances after PRIMARY from the appropriate file ''' source = open(INPUT % (receptor, line, ligand), 'r') gen = iter(source) # get a name for walking through the file. try: # Find the start for j, text in enumerate(gen): if 'PRIMARY' in text: print dest, text.strip(), break if j == 19: # Stop looking after 20 lines. return # nothing here, go on to the next one # copy scores up to TRIPOS for text in gen: if 'TRIPOS' in text: break print dest, text.strip(), print print dest finally: source.close() for receptor in 'A', 'B': # open out_file for appending per receptor, close at same level out_file = open(OUTPUT % receptor, 'a') for line in range(10): for ligand in (7, 9, 11, 13, 15, 17): extract_dist(out_file, receptor, line, ligand) out_file.close() --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Total No. of Records in a File?
On 23.08.2008, W. eWatson [EMAIL PROTECTED] wroted: Maybe. I could see it if the file were truly in a record format. The # of records might be kept by the OS. It's conceivable that Python or the OS might see a file with a CR as recordized. Isn't it much easier to use a database instead? That's what they're made for. How about in a slightly different case. Suppose I want to know the number of files in a folder? The OS and maybe some Python method might know that. Use os and os.path. For a simple case the length of os.listdir() could suffice, but then you might need to filter out sub-directories, or maybe count files in them too using os.walk(). GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl -- http://mail.python.org/mailman/listinfo/python-list
Re: Should Python raise a warning for mutable default arguments?
On Aug 23, 9:40 am, Carl Banks [EMAIL PROTECTED] wrote: On Aug 23, 4:09 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Fri, 22 Aug 2008 20:37:09 -0700, Carl Banks wrote: On Aug 22, 10:42 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: Sometimes it seems that barely a day goes by without some newbie, or not- so-newbie, getting confused by the behaviour of functions with mutable default arguments. No sooner does one thread finally, and painfully, fade away than another one starts up. I suggest that Python should raise warnings.RuntimeWarning (or similar?) when a function is defined with a default argument consisting of a list, dict or set. (This is not meant as an exhaustive list of all possible mutable types, but as the most common ones that I expect will trip up newbies.) The warning should refer to the relevant FAQ or section in the docs. What do people think? -1 There's nothing questionable about using a mutable default argument, as long as you don't mutate it. There's nothing questionable about using a mutable default argument, so long as you know what behaviour to expect. I too use that behaviour, I like that behaviour, and I'm tired of people who want it fixed. Nevertheless, it is surprising to many people. My aim is to make it a little less surprising. Python shouldn't raise a warning just because something *might* be due to a misunderstanding. That's one opinion. 1. When you print spurious warnings, the overall effectiveness of the warning system is diminished. People start to ignore them, either by disabling them or by mentally tuning out. This in turn makes people less likely to notice if a real warning is printed. Carl Banks Question: what is real warning? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems calling batch files (*.bat) from Python???
I haven't tested Your code, so can't tell You why it is working as You say. But to open batch file in my script I use simple: subprocess.Popen(c:\VerrLongPath\AnotherPath\mybatch.bat).communicate() You can also play with pipes for Popen... Algirdas Brazas - Original Message - From: Marian Popa To: python-list@python.org Sent: Saturday, August 23, 2008 4:29 PM Subject: Problems calling batch files (*.bat) from Python??? Hello, I am new in Python programming and I have the following problem: I have a script in which I need to open an application (called from a batch file - trace.bat). For this purpuse, I'm executing the following piece of code: import os, win32process from win32api import Sleep os.chdir(D:\\Marian\\Proiecte\\AMT\\Trace) os.startfile(launch_trace.bat) #subprocess.call(D:\\Marian\\Proiecte\\AMT\\Trace\\trace.bat) #pr = win32process.CreateProcess(None, D:\\Marian\\Proiecte\\AMT\\Trace\\trace.bat, None, None, 0, win32process.NORMAL_PRIORITY_CLASS, None, None, win32process.STARTUPINFO()) But, when I call the os.startfile(launch_trace.bat) command, the program prompter appears, but the program called in the batch file is opened ONLY after the whole script has finished the execution. Unfortunatley, after this line there are some very important things that has to be executed in the right order. I mean, the execution of the batch file is important for the rest of the code. What is strange is that if I execute this code step-by-step, using the debugger, or if I put a breakpoint on the launch_trace line and then I step on it, everything is working fine - the Trace application is launced correctly. Could anyone help in this direction? I need to launch the application and after this I want to continue the execution of the script. Thank you in advance! P.S. I've also tried with processes (see the commented lines) and I get the same problems; for MSWord application, the behavior is the same - it is launched after the script ends. Also, I have to mention that I don't have a DLL of this application and it is not a COM application in order to control it from Python. Marian -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Total No. of Records in a File?
Fredrik Lundh wrote: W. eWatson wrote: I have an ordinary text file with a CR at the end of a line, and two numbers in each line. Is there some way to determine the number of lines (records) in the file before I begin reading it? In the general case, no. A file is just a bunch of bytes. If you know that all lines have exactly the same length, you can of course fetch the file size and divide by the line size, but that doesn't work for arbitrary files. Why do you need to know the number of lines before reading it, btw? /F Actually, it was a matter of curiosity, and maybe absent mindedness. I was envisioning a program where I might want to run up and down a file a lot, sometimes deleting a record interactively at the request of the user. However, I wanted to keep him alert to the total number of records remaining. However, in retrospect, I more likely do this with files in a folder. I also want him to be able to skip around in the Win OS folder by saying something like go forward 3 files. I'd like not to have to read all the files between the two points. The whole idea needs some more thinking. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Should Python raise a warning for mutable default arguments?
Question: what is real warning? Don't MAKE ME have to tell you AGAIN -- Stanley C. Kitching Human Being Phoenix, Arizona -- http://mail.python.org/mailman/listinfo/python-list
Re: How to search the Python manuals
On Fri, 22 Aug 2008 16:17:16 -0400, Terry Reedy instructs a procedure for locating the behavior of default function arguments: -- For WinXP (I have no idea of how the manuals works elsewhere): Windows is against my religion, so I may be completely off base here :) ... snip prolonged clicky-clicky tap dance instructions. ... The way I read it is that one has little trouble answering a question by reading the documentation if one knows *exactly* where to look. It is much easier to find where to look if the documentation corpus has a proper index. Since indexing is hard work that's effectively impossible to automate, I suspect Python's documentation is no better than many other open-source software projects. I learned what little Python I know from Martelli's book, which is quite well indexed. Those last 80 pages are very well worn. Jim Wilson Gainesville, FL -- http://mail.python.org/mailman/listinfo/python-list
ctypes initializer
Is there a way to initialize a ctypes Structure to point to an offset into a buffer? I don't know if the way I'm doing it is supported. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to search the Python manuals
On Sat, 23 Aug 2008 21:00:57 +, JBW wrote: It is much easier to find where to look if the documentation corpus has a proper index. Since indexing is hard work that's effectively impossible to automate, I suspect Python's documentation is no better than many other open-source software projects. I think the indexes of the documentation are quite good: http://docs.python.org/lib/genindex.html http://docs.python.org/ref/genindex.html First occurance of default in the reference index leads to the information about default parameters and that they are executed once, when the ``def`` statement is executed: http://docs.python.org/ref/function.html#l2h-634 Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
W. eWatson wrote: The other night I surveyed a site for astronomical use by measuring the altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north clockwise around the site to 360 degrees, almost north again) of obstacles, trees. My purpose was to feed this profile of obstacles (trees) to an astronomy program that would then account for not sighting objects below the trees. When I got around to entering them into the program by a file, I found it required the alt at 360 azimuth points in order from 0 to 360 (same as 0). Instead I have about 25 points, and expected the program to be able to do simple linear interpolation between those. Is there some simple operational device in Python that would allow me to create an array (vector) of 360 points from my data by interpolating between azimuth points when necessary? All my data I rounded to the nearest integer. Maybe there's an interpolation operator? As an example, supposed I had made 3 observations: (0,0) (180,45) and (360,0). I would want some thing like (note the slope of the line from 0 to 179 is 45/180 or 0.25): alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0 az : 0, 1,2,3, 180 Of course, I don't need the az. If I understand you right, I think using interpolation as provided by scipy would do what you need. Here's an example: from scipy.interpolate.interpolate import interp1d angles = [0, 22, 47.5, 180, 247.01, 360] altitudes = [18, 18, 26, 3, 5, 18] desired_angles = range(0, 361) skyline = interp1d(angles, altitudes, kind=linear) vals = skyline(desired_angles) # that is, vals will be the interpolated altitudes at each of the # desired angles. if 1: # plot this out with matplotlib import pylab as mx mx.figure() mx.plot(angles, altitudes, 'x') mx.plot(desired_angles, vals) mx.show() -- http://mail.python.org/mailman/listinfo/python-list
dropwhile question
list(itertools.dropwhile(lambda x: x5,range(10))) [5, 6, 7, 8, 9] Why doesn't this work? list(itertools.dropwhile(lambda x: 2x5,range(10))) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Thanks, Raj -- For him who has conquered the mind, the mind is the best of friends; but for one who has failed to do so, his very mind will be the greatest enemy. Rajanikanth -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
I completed a Win Python program and it has generated the necessary data, which I have in turn used successfully with the telescope software. Is there some way to turn this into an executable program for people who do not have Python? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: dropwhile question
On Sat, 23 Aug 2008 14:54:09 -0700, Rajanikanth Jammalamadaka wrote: list(itertools.dropwhile(lambda x: x5,range(10))) [5, 6, 7, 8, 9] Why doesn't this work? list(itertools.dropwhile(lambda x: 2x5,range(10))) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] It *does* work. `dropwhile()` drops as long as the callable returns a true value and then it stops dropping. First value is 0 and ``2 0 5`` is `False` so nothing is dropped. What have you expected? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: dropwhile question
Rajanikanth Jammalamadaka wrote: list(itertools.dropwhile(lambda x: x5,range(10))) [5, 6, 7, 8, 9] Why doesn't this work? list(itertools.dropwhile(lambda x: 2x5,range(10))) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] it works exactly as specified: help(itertools.dropwhile) Help on class dropwhile in module itertools: class dropwhile(__builtin__.object) | dropwhile(predicate, iterable) -- dropwhile object | | Drop items from the iterable while predicate(item) is true. | Afterwards, return every element until the iterable is exhausted. 205 False maybe you meant to use itertools.ifilter? help(itertools.ifilter) Help on class ifilter in module itertools: class ifilter(__builtin__.object) | ifilter(function or None, sequence) -- ifilter object | | Return those items of sequence for which function(item) is true. | If function is None, return the items that are true. list(itertools.ifilter(lambda x: x5,range(10))) [0, 1, 2, 3, 4] list(itertools.ifilter(lambda x: 2x5,range(10))) [3, 4] /F -- http://mail.python.org/mailman/listinfo/python-list
Re: How to know a top directory?
On Aug 23, 5:24 am, Fredrik Lundh [EMAIL PROTECTED] wrote: Michiel Overtoom wrote: I have path /this/is/path and I wanna get /this/is. Also I want to use it as platform independent. If I want to pass c: \that\path then I need to get c:\that. import os print os.path.split(/home/user/motoom)[0] print os.path.split(c:\\prj\\techniques\\python)[0] in this case, os.path.dirname() is more convenient. /F Thanks a lot! -- http://mail.python.org/mailman/listinfo/python-list
Re: dropwhile question
Fredrik Lundh wrote: maybe you meant to use itertools.ifilter? help(itertools.ifilter) Help on class ifilter in module itertools: class ifilter(__builtin__.object) | ifilter(function or None, sequence) -- ifilter object | | Return those items of sequence for which function(item) is true. | If function is None, return the items that are true. list(itertools.ifilter(lambda x: x5,range(10))) [0, 1, 2, 3, 4] list(itertools.ifilter(lambda x: 2x5,range(10))) [3, 4] or, more likely, ifilterfalse: list(itertools.ifilterfalse(lambda x: x5,range(10))) [5, 6, 7, 8, 9] list(itertools.ifilterfalse(lambda x: 2x5,range(10))) [0, 1, 2, 5, 6, 7, 8, 9] /F -- http://mail.python.org/mailman/listinfo/python-list
Re: dropwhile question
Rajanikanth Jammalamadaka wrote: list(itertools.dropwhile(lambda x: x5,range(10))) [5, 6, 7, 8, 9] Why doesn't this work? list(itertools.dropwhile(lambda x: 2x5,range(10))) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Because it drops _while_ the condition is True (which it is for the first 0 entries in the sequence). What you want is: list(x for x in range(10) if 2 x 5) Note that: list(itertools.dropwhile(lambda x: x5, range(10)+range(10))) is [5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], not [5, 6, 7, 8, 9, 5, 6, 7, 8, 9]. --Scott David Daniels Scott.Daniels.Acm.Org -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
tom wrote: W. eWatson wrote: The other night I surveyed a site for astronomical use by measuring the altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north clockwise around the site to 360 degrees, almost north again) of obstacles, trees. My purpose was to feed this profile of obstacles (trees) to an astronomy program that would then account for not sighting objects below the trees. When I got around to entering them into the program by a file, I found it required the alt at 360 azimuth points in order from 0 to 360 (same as 0). Instead I have about 25 points, and expected the program to be able to do simple linear interpolation between those. Is there some simple operational device in Python that would allow me to create an array (vector) of 360 points from my data by interpolating between azimuth points when necessary? All my data I rounded to the nearest integer. Maybe there's an interpolation operator? As an example, supposed I had made 3 observations: (0,0) (180,45) and (360,0). I would want some thing like (note the slope of the line from 0 to 179 is 45/180 or 0.25): alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0 az : 0, 1,2,3, 180 Of course, I don't need the az. If I understand you right, I think using interpolation as provided by scipy would do what you need. Here's an example: from scipy.interpolate.interpolate import interp1d angles = [0, 22, 47.5, 180, 247.01, 360] altitudes = [18, 18, 26, 3, 5, 18] desired_angles = range(0, 361) skyline = interp1d(angles, altitudes, kind=linear) vals = skyline(desired_angles) # that is, vals will be the interpolated altitudes at each of the # desired angles. if 1: # plot this out with matplotlib import pylab as mx mx.figure() mx.plot(angles, altitudes, 'x') mx.plot(desired_angles, vals) mx.show() I decided this morning and roll up my sleeves and write the program. I plan to take a deeper plunge in the next month than my so far erratic look over the last 18 or more months It's working. The above looks like it's on the right track. Is scipy some collection of astro programs? mx is a graphics character plot? I just hauled it into IDLE and tried executing it. from scipy.interpolate.interpolate import interp1d ImportError: No module named scipy.interpolate.interpolate Apparently, something is missing. I posted a recent msg a bit higher that will probably go unnoticed, so I'll repeat most of it. How do I get my py code into some executable form so that Win users who don't have python can execute it? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
Dennis Lee Bieber wrote: On Fri, 22 Aug 2008 23:18:17 -0700, W. eWatson [EMAIL PROTECTED] declaimed the following in comp.lang.python: I'll take a look. I just posted above yours with a more insightful set of data than the first three pointer. Yes, some way of bisecting, or chopping is the trick here. One is just trying to fill in all the gaps with interpolation and produce 360 points to feed to the telescope software. It's sort of like giving someone, and forgetting interpolation here, the sequence 20, 30, blank, 60, 70, 80 and asking for the two missing tens between 30 and 60. 40 and 50, of course. Presuming the data is an ordered list (in azimuth) of az/el pairs, AND that the last measurement does not close the circle (eg: (0, 1), (90, 5), (180, 5), (270, 2) ) the first step would be to append a data point consisting of the first azimuth data point + 360, but with the same elevation value. With normalization at the output, this would work if the first data point was not at 0. Then one would perform repeated interpolations over pairs of data points, outputting the first pair as the first value, and stopping when the azimuth reached the second pair. Something like (watch out for line wrapping): -=-=-=-=-=-=- import pprint def gatherPoints(): pointList = [] while True: cAz = raw_input(Enter Azimuth in integer degrees (blank line to exit) : ) cAz = cAz.strip() if not cAz: break az = int(cAz) cEl = raw_input(Enter Elevation in real degrees for azimuth %s : % az).strip() el = float(cEl) pointList.append( (az, el) ) if pointList: pointList.append( (pointList[0][0] + 360, pointList[0][1]) ) return pointList def interpolate(start, end, step): slope = float(end[1] - start[1]) / (end[0] - start[0]) iPoints = [ (i, (slope * (i - start[0])) + start[1]) for i in range(start[0], end[0], step) ] return iPoints if __name__ == __main__: points = gatherPoints() output = [] if points: for s in range(len(points) - 1): output.extend(interpolate(points[s], points[s+1], 1)) pprint.pprint(output) -=-=-=-=-=-=- Close. A nice looking piece of code. Something for me to learn from. I play with python on a pretty irregular basis. The game here is like someone gives you five distinct integer numbers from 1 to 10 in order, and one needs to write a program to fill in the gaps. In my case, the numbers go from 0 to 359, and I have lots of gaps. I gave a pretty illustrative example in a post above. 11:10 pm last night. Of course, not only the gaps from 0 to 359 need to be filled in, but the interpolated values of the related values need to be obtained. Elevation. As I just posted to the fellow below you. I decided this morning and roll up my sleeves and write the program. I plan to take a deeper plunge in the next month than my so far erratic look over the last 18 or more months It's working. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (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/ -- http://mail.python.org/mailman/listinfo/python-list
Turning py into an Executable Program for Win?
How do I get my py code into some executable form so that Win users who don't have python can execute it? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes initializer
castironpi napisał(a): Is there a way to initialize a ctypes Structure to point to an offset into a buffer? I don't know if the way I'm doing it is supported. There is a high probability you're abusing ctypes too much, but it's possible. The following seems to work: from ctypes import * class S(Structure): _fields_ = [('x', c_uint), ('y', c_int)] rawdata = create_string_buffer('\xEE\xFF\x78\x56\x34\x12\xFF\xFF\xFF \xFF\xAA') # Try to make a structure s of type S which takes its data from rawdata # buffer, starting at index 2 s = cast(c_void_p(addressof(rawdata)+2), POINTER(S)).contents print hex(s.x), s.y # Should be 12345678h and -1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Turning py into an Executable Program for Win?
On 24 Aug, 01:28, W. eWatson [EMAIL PROTECTED] wrote: How do I get my py code into some executable form so that Win users who don't have python can execute it? Py2exe: http://www.py2exe.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
W. eWatson wrote: tom wrote: W. eWatson wrote: The other night I surveyed a site for astronomical use by measuring the altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north clockwise around the site to 360 degrees, almost north again) of obstacles, trees. My purpose was to feed this profile of obstacles (trees) to an astronomy program that would then account for not sighting objects below the trees. When I got around to entering them into the program by a file, I found it required the alt at 360 azimuth points in order from 0 to 360 (same as 0). Instead I have about 25 points, and expected the program to be able to do simple linear interpolation between those. Is there some simple operational device in Python that would allow me to create an array (vector) of 360 points from my data by interpolating between azimuth points when necessary? All my data I rounded to the nearest integer. Maybe there's an interpolation operator? As an example, supposed I had made 3 observations: (0,0) (180,45) and (360,0). I would want some thing like (note the slope of the line from 0 to 179 is 45/180 or 0.25): alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0 az : 0, 1,2,3, 180 Of course, I don't need the az. If I understand you right, I think using interpolation as provided by scipy would do what you need. Here's an example: from scipy.interpolate.interpolate import interp1d angles = [0, 22, 47.5, 180, 247.01, 360] altitudes = [18, 18, 26, 3, 5, 18] desired_angles = range(0, 361) skyline = interp1d(angles, altitudes, kind=linear) vals = skyline(desired_angles) # that is, vals will be the interpolated altitudes at each of the # desired angles. if 1: # plot this out with matplotlib import pylab as mx mx.figure() mx.plot(angles, altitudes, 'x') mx.plot(desired_angles, vals) mx.show() I decided this morning and roll up my sleeves and write the program. I plan to take a deeper plunge in the next month than my so far erratic look over the last 18 or more months It's working. The above looks like it's on the right track. Is scipy some collection of astro programs? mx is a graphics character plot? I just hauled it into IDLE and tried executing it. from scipy.interpolate.interpolate import interp1d ImportError: No module named scipy.interpolate.interpolate Apparently, something is missing. I posted a recent msg a bit higher that will probably go unnoticed, so I'll repeat most of it. How do I get my py code into some executable form so that Win users who don't have python can execute it? Both scipy and matplotlib are not part of the standard Python distribution so they would need to be installed separately. Scipy is useful for scientific data analysis, and matplotlib is useful for making plots. Since you want to wrap everything into a Windows executable, it's probably easiest for you not to use scipy. At the least, I suspect it would make your executable file much larger, but I've never made a Windows executable so I don't know the details. As for making an executable, I'm not the one to ask, but googling leads to this: http://effbot.org/pyfaq/how-can-i-create-a-stand-alone-binary-from-a-python-script.htm which looks like a good place to start. Tom -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes initializer
On Aug 23, 6:43 pm, [EMAIL PROTECTED] wrote: castironpi napisa³(a): Is there a way to initialize a ctypes Structure to point to an offset into a buffer? I don't know if the way I'm doing it is supported. There is a high probability you're abusing ctypes too much, but it's possible. The following seems to work: from ctypes import * class S(Structure): _fields_ = [('x', c_uint), ('y', c_int)] rawdata = create_string_buffer('\xEE\xFF\x78\x56\x34\x12\xFF\xFF\xFF \xFF\xAA') # Try to make a structure s of type S which takes its data from rawdata # buffer, starting at index 2 s = cast(c_void_p(addressof(rawdata)+2), POINTER(S)).contents print hex(s.x), s.y # Should be 12345678h and -1 Output is 0x12345678L -1, as you state. I understand that '\xEE\xFF' is skipped with addressof(rawdata)+ 2, which makes +2 an offset into the buffer. At this point, I'd say the use of 'cast' is dubious, but possible to support. My problem comes in, in that the buffer I have comes from a non-ctypes source. It is a, drumroll please mmap. My goals in exploring this are persistence and IPC, which are certainly not abusing Python too much. 'ctypes' may not be right for the job though. The solution I looked at got even worse than 'from _ctypes import _cast_addr'. I want a supported way to do it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
tom wrote: Both scipy and matplotlib are not part of the standard Python distribution so they would need to be installed separately. Scipy is useful for scientific data analysis, and matplotlib is useful for making plots. For a review of a really nice looking wrapper around lots of open-source mathematical tools, look here: http://vnoel.wordpress.com/2008/05/03/bye-matlab-hello-python-thanks-sage/ it is called SAGE and includes both of the above and lots more goodies. for sage itself: http://www.sagemath.org/ -- http://mail.python.org/mailman/listinfo/python-list
A variables variables
how can I declare a variable with another variable name? for example I will use PHP: $a= hello; $a_hello=baybay; print ${'a_'.$a) //output: baybay how can i do it with no Arrays using python thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: A variables variables
On Aug 23, 7:25 pm, Gandalf [EMAIL PROTECTED] wrote: how can I declare a variable with another variable name? for example I will use PHP: $a= hello; $a_hello=baybay; print ${'a_'.$a) //output: baybay how can i do it with no Arrays using python thanks! Here's one idea. a= 'hello' a_hello= 'bayb' print eval( 'a_'+ a ) bayb Also, you can look up locals() and globals(), or getattr, if you do this in a class. -- http://mail.python.org/mailman/listinfo/python-list
Re: A variables variables
i don't know if this volatiles array condition or not but any way q='asd' asdasd=20 print globals()[q+'asd'] -- http://mail.python.org/mailman/listinfo/python-list
Re: Should Python raise a warning for mutable default arguments?
On Aug 23, 2:57 pm, Cousin Stanley [EMAIL PROTECTED] wrote: Question: what is real warning? Don't MAKE ME have to tell you AGAIN -- Stanley C. Kitching Human Being Phoenix, Arizona Two black eyes. Haa haa. My question comes from: less likely to notice if a real warning is printed. And this one is a real one, is my point. -- http://mail.python.org/mailman/listinfo/python-list
Re: property() usage - is this as good as it gets?
On Aug 22, 11:18 am, David Moss [EMAIL PROTECTED] wrote: Hi, I want to manage and control access to several important attributes in a class and override the behaviour of some of them in various subclasses. Below is a stripped version of how I've implemented this in my current bit of work. It works well enough, but I can't help feeling there a cleaner more readable way of doing this (with less duplication, etc). Is this as good as it gets or can this be refined and improved especially if I was to add in a couple more attributes some fairly complex over-ride logic? #!/usr/bin/env python class A(object): def __init__(self): self._x = None self._y = None def _set_x(self, value): self._x = value def _get_x(self): return self._x x = property(_get_x, _set_x) def _set_y(self, value): self._y = value def _get_y(self): return self._y y = property(_get_y, _set_y) To the OP: you have a unique procedure executed for every attribute of an instance, for each of set, get, and del. That's a lot of code. If you don't want unique procedures, what patterns should they follow? What is wrong with the way you overrode 'get_x' above? When brainstorming, don't restrict yourself to Python syntax-- make something up, and we'll write Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Turning py into an Executable Program for Win?
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: On 24 Aug, 01:28, W. eWatson [EMAIL PROTECTED] wrote: How do I get my py code into some executable form so that Win users who don't have python can execute it? Py2exe: http://www.py2exe.org/ More generally, URL: http://wiki.python.org/moin/How_to_make_exe_on_Windows . -- http://mail.python.org/mailman/listinfo/python-list
Re: A variables variables
On Aug 23, 7:25 pm, Gandalf [EMAIL PROTECTED] wrote: how can I declare a variable with another variable name? for example I will use PHP: $a= hello; $a_hello=baybay; print ${'a_'.$a) //output: baybay Doing this sort of thing in Python is very anti idiom. how can i do it with no Arrays using python Why would you not want to use a list? I see no reason not to. thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3000 C API Changes
On Aug 23, 10:34 am, rahul [EMAIL PROTECTED] wrote: I am trying to find out what Python C APIs are changing from Python 2.5 to Python 3.0 but there does not seem to be a single list of changes (or at least google is not finding one). If someone knows about where I should look, please let me know. Yes, this is a bit of a problem at the moment. You could look at the 3.0 NEWS file: http://svn.python.org/view/python/branches/py3k/Misc/NEWS?view=markup. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to search the Python manuals
JBW wrote: On Fri, 22 Aug 2008 16:17:16 -0400, Terry Reedy instructs a procedure for locating the behavior of default function arguments: -- For WinXP (I have no idea of how the manuals works elsewhere): Windows is against my religion, so I may be completely off base here :) ... snip prolonged clicky-clicky tap dance instructions. ... The way I read it is that one has little trouble answering a question by reading the documentation if one knows *exactly* where to look. Then you read wrong. What my tap-dance instructions said were to find the right *CHAPTER* (for upcoming 2.6/3.0) and use ^Find to find the exact place. If you don't know that def statements are compound statements and not lexical analysis, data, expressions, or simple statements, they you would profit from reading a bit more at the top of each chapter. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: A variables variables
Gandalf wrote: how can I declare a variable with another variable name? for example I will use PHP: $a= hello; $a_hello=baybay; print ${'a_'.$a) //output: baybay how can i do it with no Arrays using python Others have given you the direct answer. But using lists or dicts is almost always a better solution in Python than synthesizing global/local namespace names. a={'hello':'baybay'} print a['hello'] -- http://mail.python.org/mailman/listinfo/python-list
Re: The Importance of Terminology's Quality
Martin Gregorie wrote: On Sat, 23 Aug 2008 00:06:28 -0400, John W Kennedy wrote: Martin Gregorie wrote: Not necessarily. An awful lot of CPU cycles were used before microcode was introduced. Mainframes and minis designed before about 1970 didn't use or need it No, most S/360s used microcode. I never used an S/360. I thought microcode came into the IBM world with S/370 and Future Series (which later reappeared as the AS/400, which I did use). Didn't the S/370 load its microcode off an 8 inch floppy? Some did, but not all. The 370/145 was the first, and made a big splash thereby. As to the 360s: 20 (Incompatible subset) I don't know 22 (Recycled end-of-life 30) CROS 25 Loaded from punched cards 30 CROS 40 TROS 44 (Subset) None 50 CROS 60, 62, 65 ROS 64, 66, 67 ROS 70, 75 None 85 I don't know 91, 95 I don't know -- probably none 195I don't know CROS used plastic-coated foil punched cards as the dielectrics of 960 capacitors each. TROS used little transformer coils that might or might not be severed. ROS means it was there, but I don't know the technology. -- John W. Kennedy Those in the seat of power oft forget their failings and seek only the obeisance of others! Thus is bad government born! Hold in your heart that you and the people are one, human beings all, and good government shall arise of its own accord! Such is the path of virtue! -- Kazuo Koike. Lone Wolf and Cub: Thirteen Strings (tr. Dana Lewis) -- http://mail.python.org/mailman/listinfo/python-list
Imports visibility in imported modules problem
Hello , The problem I'm asking about is how can imported modules be aware of other imported modules so they don't have to re-import them (avoiding importing problems and Consicing code and imports ) Take Example :- in A.py :- import B print dir() # no problems we can see B which contain re module and C module B.C.W() # our problem here we get an empty list in B.py :- import re import C in C.py :- def W(): print dir() # when called from A we get [] though other imports has been made to re and others my goal is basically making W() aware of the re module when called from A why am i doing this in the first place I'm in the process of a medium project where imports of modules start to make a jungle and i wanted all needed imports to be in a single file (namely __init__.py) and then all imports are made once and other modules feel it another reason to do this that my project is offering 2 interfaces (Console and GUI through Qt) and i needed a general state class ( whether i'm in Console or GUI mode) to be available for all , for determining state and some public functions ,and just injecting Imports everywhere seems a bad technique in many ways (debugging , modifying ...etc ) in PHP Require would do the trick neatly ... so is there is something I'm missing here or the whole technique is bad in which case what do you suggest ? Thanks, Regards, Mohamed Yousef -- http://mail.python.org/mailman/listinfo/python-list
Re: Imports visibility in imported modules problem
On Aug 23, 7:27 pm, Mohamed Yousef [EMAIL PROTECTED] wrote: The problem I'm asking about is how can imported modules be aware of other imported modules so they don't have to re-import them (avoiding importing problems and Consicing code and imports ) You could import sys and look at sys.modules why am i doing this in the first place I'm in the process of a medium project where imports of modules start to make a jungle and i wanted all needed imports to be in a single file (namely __init__.py) and then all imports are made once and other modules feel it This doesn't sound like a good idea. If A imports a module which is automatically imported into B's namespace, that sounds like a maintenance nightmare. another reason to do this that my project is offering 2 interfaces (Console and GUI through Qt) and i needed a general state class ( whether i'm in Console or GUI mode) to be available for all , for determining state and some public functions ,and just injecting Imports everywhere seems a bad technique in many ways (debugging , modifying ...etc ) I still don't understand. in PHP Require would do the trick neatly ... so is there is something I'm missing here or the whole technique is bad in which case what do you suggest ? I don't know what to suggest, in that you haven't yet stated anything that appears to be a problem with how Python works. If two different modules import the same third module, there is no big performance penalty. The initialization code for the third module is only executed on the first import, and the cost of having the import statement find the already imported module is trivial. -- http://mail.python.org/mailman/listinfo/python-list
Imports awareness in Imported modules problem
Hello , The problem I'm asking about is how can imported modules be aware of other imported modules so they don't have to re-import them (avoiding importing problems and Consicing code and imports ) Take Example :- in A.py :- import B print dir() # no problems we can see B which contain re module and C module B.C.W() # our problem here we get an empty list in B.py :- import re import C in C.py :- def W(): print dir()# when called from A we get [] though other imports has been made to re and others my goal is basically making W() aware of the re module when called from A why am i doing this in the first place I'm in the process of a medium project where imports of modules start to make a jungle and i wanted all needed imports to be in a single file (namely __init__.py) and then all imports are made once and other modules feel it another reason to do this that my project is offering 2 interfaces (Console and GUI through Qt) and i needed a general state class ( whether i'm in Console or GUI mode) to be available for all , for determining state and some public functions ,and just injecting Imports everywhere seems a bad technique in many ways (debugging , modifying ...etc ) in PHP Require would do the trick neatly ... so is there is something I'm missing here or the whole technique is bad in which case what do you suggest Thanks, Regards, Mohamed Yousef -- http://mail.python.org/mailman/listinfo/python-list
Re: Filling in Degrees in a Circle (Astronomy)
tom wrote: W. eWatson wrote: tom wrote: W. eWatson wrote: The other night I surveyed a site for astronomical use by measuring the altitude (0-90 degrees above the horizon) and az (azimuth, 0 degrees north clockwise around the site to 360 degrees, almost north again) of obstacles, trees. My purpose was to feed this profile of obstacles (trees) to an astronomy program that would then account for not sighting objects below the trees. When I got around to entering them into the program by a file, I found it required the alt at 360 azimuth points in order from 0 to 360 (same as 0). Instead I have about 25 points, and expected the program to be able to do simple linear interpolation between those. Is there some simple operational device in Python that would allow me to create an array (vector) of 360 points from my data by interpolating between azimuth points when necessary? All my data I rounded to the nearest integer. Maybe there's an interpolation operator? As an example, supposed I had made 3 observations: (0,0) (180,45) and (360,0). I would want some thing like (note the slope of the line from 0 to 179 is 45/180 or 0.25): alt: 0, 0.25, 0.50, 0.75, ... 44.75, 45.0 az : 0, 1,2,3, 180 Of course, I don't need the az. If I understand you right, I think using interpolation as provided by scipy would do what you need. Here's an example: from scipy.interpolate.interpolate import interp1d angles = [0, 22, 47.5, 180, 247.01, 360] altitudes = [18, 18, 26, 3, 5, 18] desired_angles = range(0, 361) skyline = interp1d(angles, altitudes, kind=linear) vals = skyline(desired_angles) # that is, vals will be the interpolated altitudes at each of the # desired angles. if 1: # plot this out with matplotlib import pylab as mx mx.figure() mx.plot(angles, altitudes, 'x') mx.plot(desired_angles, vals) mx.show() I decided this morning and roll up my sleeves and write the program. I plan to take a deeper plunge in the next month than my so far erratic look over the last 18 or more months It's working. The above looks like it's on the right track. Is scipy some collection of astro programs? mx is a graphics character plot? I just hauled it into IDLE and tried executing it. from scipy.interpolate.interpolate import interp1d ImportError: No module named scipy.interpolate.interpolate Apparently, something is missing. I posted a recent msg a bit higher that will probably go unnoticed, so I'll repeat most of it. How do I get my py code into some executable form so that Win users who don't have python can execute it? Both scipy and matplotlib are not part of the standard Python distribution so they would need to be installed separately. Scipy is useful for scientific data analysis, and matplotlib is useful for making plots. Since you want to wrap everything into a Windows executable, it's probably easiest for you not to use scipy. At the least, I suspect it would make your executable file much larger, but I've never made a Windows executable so I don't know the details. As for making an executable, I'm not the one to ask, but googling leads to this: http://effbot.org/pyfaq/how-can-i-create-a-stand-alone-binary-from-a-python-script.htm which looks like a good place to start. Tom What modules do I need to use pylab? I've installed scipy and numpy. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (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/ -- http://mail.python.org/mailman/listinfo/python-list
two's complement bytes
I'm dabbling with AVR's for a project I have and that means I have to use C (ageist my will). Because my AVR will be tethered to my laptop, I am writing most of my logic in python, in the hopes of using at little C as possible. In my quest I came across a need to pass a pair of sign extended two's complement bytes. After painfully reading the wikipedia article on what two's complement was, I then thought of how I would handle this in python. I don't really recall ever having to work in binary with python, so I really am clueless on what to do. I can feed python either two hex bytes or binary, but how do I convert it into an int, and more importantly how do I make sure it handles the sign properly? -- http://mail.python.org/mailman/listinfo/python-list