RELEASED Python 2.4.2, release candidate 1
On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.4.2 (release candidate 1). Python 2.4.2 is a bug-fix release. See the release notes at the website (also available as Misc/NEWS in the source distribution) for details of the more than 60 bugs squished in this release. Assuming no major problems crop up, a final release of Python 2.4.2 will follow in about a week's time. For more information on Python 2.4.2, including download links for various platforms, release notes, and known issues, please see: http://www.python.org/2.4.2 Highlights of this new release include: - Bug fixes. According to the release notes, more than 60 have been fixed, including bugs that prevented Python from working properly on 64 bit HP/UX and AIX systems. Highlights of the previous major Python release (2.4) are available from the Python 2.4 page, at http://www.python.org/2.4/highlights.html Enjoy the new release, Anthony Anthony Baxter [EMAIL PROTECTED] Python Release Manager (on behalf of the entire python-dev team) -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANNOUNCE: nautilus-python 0.4.1
I am pleased to announce the first public release of nautilus-python. The new release is available from ftp.gnome.org: http://ftp.gnome.org/pub/GNOME/sources/nautilus-python/0.4/nautilus-python-0.4.1.tar.gz What's new since 0.4.1: * Memory leaks plugged (Gustavo) * Do not install examples (Gustavo) * Improve documentation (Gustavo) * Allow extensions to be loaded from $HOME (Gustavo) I'd like to thank the following people, for helping me during the development: Sidnei da Silva, Gustavo Carneiro, Thomas Vander Stichele, Sebastien Bacher and Ross Burton. Sidnei da Silva is writing an integration tool for plone desktop: http://awkly.org/files/menu.png Ross Burton is writing a dpkg interface. Blurb: Nautilus is the file manager used by the GNOME desktop environment. Nautilus-python provides bindings for the extension API in nautilus. With help of it you can write extensions that goes beyond the standard shell script interface like context menuitems, additional list columns and property pages. nautilus-python requires nautilus = 2.6.0, PyGTK = 2.8.0, gnome-python 2.12.0 and Python = 2.3.5 Bug reports should be made in GNOMEs bugzilla: http://bugzilla.gnome.org/enter_bug.cgi?product=nautilus-python -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Upcoming Python talk in Toronto
Seneca College is Canada's largest, with over 100,000 students and more than 260 programs. On October 24, 2005, Seneca will be hosting their 4th annual Free Software and Open Source Symposium in Toronto, Ontario. Here is a link to the agenda. http://cs.senecac.on.ca/soss/2005/agenda.php I will be giving a Python talk at the symposium. The talk is titled Python Power -- Learning, Teaching and Doing with the World's Easiest Programming Language. The talk is based on 3 short programs, which gives the audience a practical sense of the broad application range, ease of use, and power of Python. The following link leads to an overview of the presentation. http://cs.senecac.on.ca/soss/2005/presentations/george.php Hope to see you all there :-) George. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Help w/ easy python problem
Actually, it is not a sin curve i need to plot, it is dots running down the page in the shape of a sin curve like this . . . etc... -- http://mail.python.org/mailman/listinfo/python-list
Re: Help w/ easy python problem
Actually, it is not a sin curve i need to plot, it is dots running down the page in the shape of a sin curve like this . . . etc... -- http://mail.python.org/mailman/listinfo/python-list
Re: Python win32com com_error: (-2147418113
Usually this means the COM object has to run in a full ActiveX container. You can host it in IE, or Pythonwin can act as a container with some effort. See \pythonwin\pywin\Demos\ocx for some examples of using OCX objects that require a container. Roger g.franzkowiak [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm trying to use a proprietary windows software with COM and win32com. The result is everytime the error message com_error: (-2147418113, 'Catastrophic failure', None, None) I've read this in some e-mails, but can't find the solution and I have not enough experience with Windows and COM. Can anybody help ? This ist the test script. #-- import sys from win32com.client import gencache import win32com.client if __name__=='__main__': flag = None gencache.EnsureModule('{A5FE85B0-D562-11D3-A8E8-00609727A3F3}', 0, 1, 0) o = win32com.client.Dispatch('VISIONP400DATACONTROL.VisionP400DataControlCtrl.1') Debug output: o == win32com.gen_py.A5FE85B0-... instance at 0x17707056 o.connectToVisionP400 == bound method_D try: flag = o.connectToVisionP400() Error by function call == Unhandled exception while debugging... Traceback (most recent call last): File S:\Python\DCOM\test.py, line , in ? flag = o.connectToVisionP400() File C:\Programme\Python\Python2.4\lib\site-packages\win32com\gen_py\A5FE85B0-D562-11D3-A8E8-00609727A3F3x0x1x0.py, line 60, in connectToVisionP400 return self._oleobj_.InvokeTypes(12, LCID, 1, (11, 0), (),) com_error: (-2147418113, 'Catastrophic failure', None, None) except: flag = *** - The connection not possible ! print flag Regards gerd == Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 100,000 Newsgroups ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- -- http://mail.python.org/mailman/listinfo/python-list
Re: Intermediate to expert book
Tony Houghton [EMAIL PROTECTED] writes: Can anyone recommend a good book for intermediate up to expert level? ... 2.4 would be a bonus. I've heard good things about Dive Into Python. I see it can be downloaded or read online, and on a very quick browse it seems to be suitably to the point and cover some useful stuff that was missing from or too deeply buried in Learning Python. I find it easier to read printed material though, so I'd consider buying it. What sort of opinions do people here have of it? -- The address in the Reply-To is genuine and should not be edited. See http://www.realh.co.uk/contact.html for more reliable contact addresses. Dive Into Python is really a great book about doing nifty tricks in a pythonic way. Since you are already a programmer and learn the classic things about python just by reading the tutorial, it's better to read Dive Into Python and learn the python way of doing things. -- Love Respect GNU/Linux Magpie, n.: A bird whose theivish disposition suggested to someone that it might be taught to talk. -- Ambrose Bierce, The Devil's Dictionary Tonguç Yumruk -- http://mail.python.org/mailman/listinfo/python-list
Re: Free seminar on domain-specific modeling
Hello Michael, The alternate point is that during computing history, many, many, many promises were made for many, many, many, technologies based on the same principle of raising the abstraction level. Many, many, many of those technologies promised much and failed to deliver on their claims when used beyond the people inventing/using those technologies. True, DSM however is not so much a new method for develping software. It's been used since the early 1990ies as far as I know and seen many sccessful implementations of it in varying sectors of industry: From mobile phones (Nokia uses it to develop the software running in all their phones) to IP switching platforms (Lucent), CRM systems, pacemakers, home automation systems, J2EE-based B2B portals (insurance industry), car infotainment systems (Audi A6), messaging systems (USAF), enterprise apps on smartphones (Nokia series60), Tooling industry and many more. Success with DSM depends on several factors like a common platform used for developing applications or variants of applications and the presence of domain-expertise: That leaves out one-time projects. One thing is relatively clear - your approach appears to include a graphical approach to systems building. Personally I suspect that the fact people are able to engage other parts of their brain when building these systems beyond linguistic is the real reason you see benefits, rather than actually the specific thing that led to the visual approach being possible. It is actually based on the graphical approach. The important thing I see here is that specific instances of this approach are defined by a company's expert developer instead of by a standards-body or a vendor, this puts the expert in the driver-seat so to say, he/she gets the ability to formalize (changing) development practices in his/her problem domain for the rest of the (less experienced) developers to follow automatically. Instead of adopting a one-size-fits-all approach companies/developers get to tailor the approach to the specific needs of their unique problem domain. It does not eliminate coding but attempts to minimize the need for it and leave it to the people who are really good at it. (On a sad note it looks like you're reinvented how hardware is designed and made, but not made the intuitive leap :-/ ) I suppose you mean software here? It seems I fail to make the leap towards understanding what you mean with this, feel free to elaborate. Regards, Martijn -- http://mail.python.org/mailman/listinfo/python-list
Re: Code to read Cobol data files
none wrote: Hi, Any one know of some code to read cobol data files thanks timb I posted some here maybe 5+ years ago that would convert COBOL comp-3, comp-4, and comp-5 fields (as from Realia) to whatever. I suppose you can still find it in google somewhere. There was some help for cracking one of the other COBOL file formats at a site called Wotsit's file formats or something like that. This helped me access data out of ISAM files from one of the non-Realia desktop COBOLs. It was one of the more popular COBOL versions way back in the 1980's, but I don't recall anymore which one it was, but I'd guess RM Cobol if I had to. COBOL has/had an indexed file type defined in the language, and the COBOL vendors each implemented it independently, I think. So there are variations in both the coding of various field/record types and the way that the files are put together. But Python can handle it if you can figure out the rules. Al -- http://mail.python.org/mailman/listinfo/python-list
Re: PyEphem on winXP
[EMAIL PROTECTED] schrieb im Newsbeitrag news:[EMAIL PROTECTED] | Hi, | | I'm a (sort of) newbie to python and would like to install the PyEphem | extension to Python. I'm using Python 2.4 | I obtained PyEphem from: | http://rhodesmill.org/brandon/projects/pyephem.html | | When i ran python setup.py install my error was: | error: Python was built with version 7.1 of Visual Studio, and | extensions need to be built with the same version of the compiler, but | it isn't installed | | Browsing this group led me to the following URL where I could get (for | free) the Visual C++ Toolkit 2003: | http://www.microsoft.com/downloads/details.aspx?FamilyId=272BE09D-40BB-49FD-9CB0-4BFA122FA91Bdisplaylang=en | | However I still see the same error when running | python setup.py install. | I know that Visual C++ Toolkit 2003 is the same as version 7.1, but is | this the same as Visual Studio 7.1? It should work. Did you follow the instructions as per http://www.vrplumber.com/programming/mstoolkit/ ? I've had success using that approach... HTH, -- Vincent Wehren | | If so, can Visual Studio 7.1 be obtained for free? | If not, is there a workaround? | | I've seen suggestions in the group that you can recompile Python 2.4 | using MinGW or some other c compiler. I'd be willing to do that, but | do not know how to go about recompiling python. Advice on this would | also be helpful. | | Thanks, | James | -- http://mail.python.org/mailman/listinfo/python-list
Re: Help w/ easy python problem
[EMAIL PROTECTED] napisał(a): Actually, it is not a sin curve i need to plot, it is dots running down the page in the shape of a sin curve like this . . . etc... Seems, like a homework to me :-) Anyway, use the following hints: math.sin() is your sine function, ranging, from -1.0 to 1.0 inclusively set up a for loop printing the strings containing spaces, and one dot at the appropriate location with: - the appropriate argument increase step between the lines (print statements) - the appropriate scaling of the -1.0, 1.0 range into e.g. 0, 71, representing the 72 characters wide lines being printed. Tomasz Lisowski -- http://mail.python.org/mailman/listinfo/python-list
Re: Help w/ easy python problem
[EMAIL PROTECTED] wrote: I am very much a beginner to python. I have been working on writing a very simple program and cannot get it and was hoping someone could help me out. Basically i need to write a code to print a sin curve running down the page from top to bottom. The trick is I have to do this using only 7-8 lines of code. Any ideas? This sounds like homework, and I think you should do that on your own. One hint, though: You could take a look at the standard module math. /MiO -- http://mail.python.org/mailman/listinfo/python-list
Re: plateform info.
Mikael Olofsson wrote: Monu Agrawal wrote: Hi I want to know whether the program is being run on windows or on Xnix. Is there any variable or method which tells me that it's windows? Will this help? import sys sys.platform 'win32' There is also the platform module, that can give you a lot more information about the your platform. Try help(platform). /MiO Adding onto this (which may be of need), but if this seems to be a hijack, my apologies.. Is there a way of getting the path to the site-packages directory? Considering that Mac OSX with Fink installs python libraries in /sw/lib/pythonversion, Mac OSX itself has python libraries in /System/Library/Frameworks/Python.framework/Versions/version/lib, etc etc... maurice -- http://mail.python.org/mailman/listinfo/python-list
Re: Do thread die?
Frithiof Andreas Jensen wrote: Maurice LING [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I do have another dumb question which is OT here. Say aFunc method instantiates a SOAP server that serves forever, will it prevent bFunc from running as a separate thread? If the SOAP server thread never sleeps or block, it will effectively stop everything else in your program by eating all the CPU time available. If it does some IO and other OS functions, probably not because it is likely to block on those - I do not know SOAPpy in detail, but it being a socket-based server it should end up in a select loop somewhere. i.e. block when no work is available. which is what you want. For example, class myClass4: def repeat(self, s): return s+s def aFunc(self, a): import SOAPpy serv = SOAPpy.SOAPServer((a[0], a[1])) serv.registerFunction(repeat) serv.serve_forever() def bFunc(self, b): pass def runAll(self, a, b): threading.Thread(target=self.aFunc, args = (a)).start() threading.Thread(target=self.bFunc, args = (b)).start() if __name__=='__main__': myClass4().runAll(['localhost', 8000], 'hi') Will the 2nd thread (bFunc) ever run since the 1st thread is running forever? Intuitively, I think that both threads will run but I just want to be doubly sure, because some of my program logic depends on the 2nd thread running while the 1st thread acts as a SOAP server or something. Both should run independently, sharing the CPU-time available for your application. Remember main is a thread too, so you will want main to hang around while your threads are running and you will want main to block on something also, thread.join(), time.sleep(), command line parser e.t.c. whatever is natural. Somehow I cannot reconcile your replies because I am essentially asking the same thing and expanding on the original question with an example of what I am trying to do, but the replies seems contradictory. Do you mind to explain a bit more? thanks Maurice -- http://mail.python.org/mailman/listinfo/python-list
Re: plateform info.
Mikael Olofsson wrote: Monu Agrawal wrote: Hi I want to know whether the program is being run on windows or on Xnix. Is there any variable or method which tells me that it's windows? Will this help? import sys sys.platform 'win32' There is also the platform module, that can give you a lot more information about the your platform. Try help(platform). /MiO Adding onto this (which may be of need), but if this seems to be a hijack, my apologies.. Is there a way of getting the path to the site-packages directory? Considering that Mac OSX with Fink installs python libraries in /sw/lib/pythonversion, Mac OSX itself has python libraries in /System/Library/Frameworks/Python.framework/Versions/version/lib, etc etc... maurice -- http://mail.python.org/mailman/listinfo/python-list
RELEASED Python 2.4.2, release candidate 1
On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.4.2 (release candidate 1). Python 2.4.2 is a bug-fix release. See the release notes at the website (also available as Misc/NEWS in the source distribution) for details of the more than 60 bugs squished in this release. Assuming no major problems crop up, a final release of Python 2.4.2 will follow in about a week's time. For more information on Python 2.4.2, including download links for various platforms, release notes, and known issues, please see: http://www.python.org/2.4.2 Highlights of this new release include: - Bug fixes. According to the release notes, more than 60 have been fixed, including bugs that prevented Python from working properly on 64 bit HP/UX and AIX systems. Highlights of the previous major Python release (2.4) are available from the Python 2.4 page, at http://www.python.org/2.4/highlights.html Enjoy the new release, Anthony Anthony Baxter [EMAIL PROTECTED] Python Release Manager (on behalf of the entire python-dev team) -- http://mail.python.org/mailman/listinfo/python-list
Re: Object default value
On 20 Sep 2005 12:31:19 -0700, ago [EMAIL PROTECTED] wrote: Is it possible to have a default value associated python objects? I.e. to flag an attribute in such a way that the assignment operator for the object returns the default attribute instead of the object itself, but calls to other object attributes are properly resolved? (I don't think so, but I am not sure) Example: class obj(object): x=1 #assume x is somehow made into a default value y=2 Ideally this should be the result: myobj=obj() normal print myobj #- 1 expression myobj interpreted as myobj.x? print myobj.y #- 2 normal x=myobj normal, because expression myobj in this context of immediate assignment does not mean myobj.x? print x #- 1 expression x is the same as expression myobj, which is intrpreted as myobj.x (alias x.x) if not assigned? print type(x) #int ditto If you wanted to have this effect inside a function, you could write a byte-code-munging decorator to evaluate selected_name as selected_name.selected_attr except where assigning to an alias name is all that a statement does, as in x = myobj. But what if you actually wanted to pass the object per se somewhere, or return it from a function? Maybe you could have the expression myobj.x mean the normal myobj, and vice versa in a kind of terrible symmetry ;-) Then usage might be something like @agostino_effect(myobj='x') # eval myobj as myobj.x def foo(): myobj=obj() print myobj #- 1 print myobj.y #- 2 x = myobj print x #- 1 return x, myobj, x.y, myobj.x # with .x having symmetrically-other effect ;-) xval, myobjval, x_dot_y_val, myobj_per_se = foo() # assignment from function is not interfered with myobj_per_se.y #-2 myobj_per_se #- 1 myobj_val.y - AttributeError: 'int' object has no attribute 'y' I'm not suggesting this is a good way to go forward, I am just playing with the feasibility of doing what you want, even if it's not good for you ;-) I suspect there is a better way, but it wouldn't be that hard to do the above, as you can see from the code of foo that the agostino_effect decorator would be modifying: def foo(): ... myobj=obj() ... print myobj #- 1 ... print myobj.y #- 2 ... x = myobj ... print x #- 1 ... return x, myobj, x.y, myobj.x # with .x having symmetrically-other effect ;-) ... import dis dis.dis(foo) 2 0 LOAD_GLOBAL 0 (obj) 3 CALL_FUNCTION0 6 STORE_FAST 0 (myobj) 3 9 LOAD_FAST0 (myobj) Here you'd notice that the next instruction was not STORE_FAST so you'd insert a LOAD_ATTR1 (x) similar to the .y access below 12 PRINT_ITEM 13 PRINT_NEWLINE 4 14 LOAD_FAST0 (myobj) 17 LOAD_ATTR2 (y) Here you'd notice the above wasn't LOAD_ATTR (x) (which you'd otherwise have to remove for object-per-se) 20 PRINT_ITEM 21 PRINT_NEWLINE 5 22 LOAD_FAST0 (myobj) 25 STORE_FAST 1 (x) This you notice is an immediate assignment and you leave it alone, and note the alias 6 28 LOAD_FAST1 (x) Here you notice the alias and insert LOAD_ATTR1 (x) as before with myobj 31 PRINT_ITEM 32 PRINT_NEWLINE 7 33 LOAD_FAST1 (x) insert LOAD_ATTR1 (x) again 36 LOAD_FAST0 (myobj) insert LOAD_ATTR1 (x) again 39 LOAD_FAST1 (x) 42 LOAD_ATTR2 (y) other attribute, no change to above byte code 45 LOAD_FAST0 (myobj) 48 LOAD_ATTR3 (x) anti-attribute, remove above byte code 51 BUILD_TUPLE 4 54 RETURN_VALUE You might want to do the same for LOAD_GLOBAL/STORE_GLOBAL, and STORE_DEREF/LOAD_DEREF, I don't know. But it wouldn't be a big deal to get a hack working. Thorough testing is another matter, not to mention justifying it ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: Object default value
ago wrote: Is it possible to have a default value associated python objects? I.e. to flag an attribute in such a way that the assignment operator for the object returns the default attribute instead of the object itself, but calls to other object attributes are properly resolved? (I don't think so, but I am not sure) Python is not Visual Basic. In Visual Basic, objects could have a default property which was set when the object variable was assigned to, but that was only possible because object variables had to be set with Set, not Let. Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: Do thread die?
Frithiof Andreas Jensen wrote: Maurice LING [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I do have another dumb question which is OT here. Say aFunc method instantiates a SOAP server that serves forever, will it prevent bFunc from running as a separate thread? If the SOAP server thread never sleeps or block, it will effectively stop everything else in your program by eating all the CPU time available. If it does some IO and other OS functions, probably not because it is likely to block on those - I do not know SOAPpy in detail, but it being a socket-based server it should end up in a select loop somewhere. i.e. block when no work is available. which is what you want. For example, class myClass4: def repeat(self, s): return s+s def aFunc(self, a): import SOAPpy serv = SOAPpy.SOAPServer((a[0], a[1])) serv.registerFunction(repeat) serv.serve_forever() def bFunc(self, b): pass def runAll(self, a, b): threading.Thread(target=self.aFunc, args = (a)).start() threading.Thread(target=self.bFunc, args = (b)).start() if __name__=='__main__': myClass4().runAll(['localhost', 8000], 'hi') Will the 2nd thread (bFunc) ever run since the 1st thread is running forever? Intuitively, I think that both threads will run but I just want to be doubly sure, because some of my program logic depends on the 2nd thread running while the 1st thread acts as a SOAP server or something. Both should run independently, sharing the CPU-time available for your application. Remember main is a thread too, so you will want main to hang around while your threads are running and you will want main to block on something also, thread.join(), time.sleep(), command line parser e.t.c. whatever is natural. Somehow I cannot reconcile your replies because I am essentially asking the same thing and expanding on the original question with an example of what I am trying to do, but the replies seems contradictory. Do you mind to explain a bit more? thanks Maurice -- http://mail.python.org/mailman/listinfo/python-list
COM error Access is denied
Hello, I try to make web testing using Pamie and it use win32com to call Internet Explorer. A access denied COM_error occurs and I don't know how to solve it. I'm administrator of my workstation and I install myself Pyton and win32com Any idea ? File D:\pyatf\Browser.py, line 32, in do exec self.%s(*args) % actionName File string, line 1, in ? File C:\Python24\lib\site-packages\cPAMIE.py, line 1024, links[linkNum].Click() File C:\Python24\Lib\site-packages\win32com\client\dynamic __call__ return self._get_good_object_(self._oleobj_.Invoke(*allAr defaultDispatchName,None) com_error: (-2147024891, 'Access is denied.', None, None) --- Thanks Fabian Skivée -- http://mail.python.org/mailman/listinfo/python-list
python image library TIFF
Hi does anyone have any experience using the Python Image library to determine if a Tiff is in the G4 or G3 codec? -- http://mail.python.org/mailman/listinfo/python-list
Re: Question About Logic In Python
Ron Adam wrote: Steven D'Aprano wrote: So.. bool(a and b) * value Would return value or zero, which is usually what I want when I do this type of expression. That's all very interesting, and valuable advice for somebody who doesn't understand how Python's logical operators work, but the question is, when would you actually want that type of expression? It's a filter which returns a value or zero depending on conditions a and b. Some examples... High pass filter: (value 0) * value Low pass filter: (value 0) * value Band pass filter: (min value max) * value Changing and and or to return bools only, doesn't prevent us from doing anything we can already do. It just means changing the context to explicitly return a non bool when you want one as I did here. In practice, how often do you really care that your truth values have the specific values 0 and 1 rather than anything false and anything true? In what circumstances? We can separate these into two groups... 1. True and false condition testing in which the result of the condition is not used in any further expressions. You are correct in this case, it doesn't matter. Any True values would work. 2. Expressions that will be used in a calculation or another expression. By which you appear to mean expressions in which Boolean values are used as numbers. This matters because if you aren't careful your results may not be what you expect. Well yes, but then I wouldn't necessarily expect good results if I tried to use a nail file as a tyre-lever, either. If you abuse the intent of anything sufficiently you should expect trouble. But then, you seem to like trouble ;-) But group (2) can also be a part of group (1). So then again it may matter there too. This has more to do with clarity and separating function into forms that have the potential for least surprises. Or to put it another way, forms that are predictable with no exceptional circumstances. In boolean math it is useful to add and subtract. a = b = True a + b 2 # Non boolean result. Quite. True * True 1 # Why not return True here as well? Why not return 42? Why not return a picture of a banana? This is like adding two integer types and getting a float. No it isn't. It's like trying to multiply April 2 1994 by June 5 2005. The operation isn't defined. So you choose an arbitrary definition and say it would be nice if it worked like this instead of how it actually does work. When in fact it doesn't really work at all, except for the most tenuous possible value of work. It's an accident, because Guido decided that least code breakage was good when Booleans were introduced. There's the possibility of adding two (normally) True values and getting a False result. a = True b = -1 a + b # True_value + True = False_value 0 Which is yet another reason why it makes absolutely no sense to apply arithmetic operations to Boolean values. Should bool type act like bools as expressed here? http://www.ee.surrey.ac.uk/Projects/Labview/boolalgebra/ # P1: X = 0 or X = 1 # P2: 0 . 0 = 0 # P3: 1 + 1 = 1 # P4: 0 + 0 = 0 # P5: 1 . 1 = 1 # P6: 1 . 0 = 0 . 1 = 0 # P7: 1 + 0 = 0 + 1 = 1 Table 1: Boolean Postulates Python's bools work this way if you use 'and' and 'or' and always cast any non bools to bools first. But it would be easier IMO if bool operations gave bool results so I wouldn't need to do: bool_result = a and bool(b) or bool_result = bool(a and b) You are, of course, ignoring the huge amount of code breakage this little change you'd find so convenient would cause. On one hand these seem like little things, but little things is sometimes what will bite you the hardest as they are more likely to get by your guard. Kindly think again about the vast number of times that Python programmers have relied on the documented property of and, which says that it returns the left operand (without evaluating the right one) unless the left operand is equivalent to False, in which case it returns the right operand. You talk about least surprises and in my opinion as though your opinions are the only ones that anyone would dream of holding. This is in itself quite surprising to me. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: python image library TIFF
bryan rasmussen wrote: Hi does anyone have any experience using the Python Image library to determine if a Tiff is in the G4 or G3 codec? PIL don't support G3/G4 encoding. You can use freeimagepy that is another python graphic package. Michele (freeimagepy developer :) ) -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython Notebook crash when pressing alt key
Kreedz wrote: Did it freeze for you too with the alt+f while focus on the tab? No, the program appears to work perfectly normally. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Noobie Starting New Project
Having looked in these sorts of areas before and having a general interest in it, I'd like to make some suggestions. I wouldn't go an implement OBD-II yourself in Python, especially not in a serial port. There are in fact (at least) 4 different OBD-II protocols that I won't rattle off the names of here because I can't remember them. You have to do strange things like setting the serial port to 5 baud, send a start byte, then set it to 10400 baud and wait an indeterminate amount of time for a reply etc. More info here (http://www.andywhittaker.com/ecu/obdii_software.htm). People have done it like this with varying degrees of success on specific car models (VAG-COM for VW and Audi cars for example) but never a generic solution. There is an implementation (http://freediag.sourceforge.net/) which works with various interfaces and protocols but it's not been touched since 2003. I could never get this working in my car as it doesn't support the OBD-II/CAN protocol. You could wrap this if you think it will work for you (UNIX only, no Win32 not even under cygwin). There are devices which plug into OBD-II and have a dongle on the end which does the OBD-II protocol detection and decoding for you and just gives you a serial stream out. These are much more reliable (and much more like what the real car industry uses). There are many but here's one supplier (http://www.gendan.co.uk/viewcategory.php?category=117). Googling for scantool will find the rest. Using python to either implement the proper serial protocol used by these or wrap their existing libraries (if they come with one) would, I think, be a much quicker and potentially more successful approach. As for other sensors, I found a great USB accelerometer (www.phidgets.com) which I've used in python. They supply a library with a COM interface so I used the pythonwin COM module to access it. They also have a more traditional C library (with source) if you want to wrap it with python, you'd need to do this if you want to use their Linux or Mac OSX libraries. Phidgets make a whole set of cheap sensors including temps, pressures etc. all accessible through USB. GPS is easy and there are numerous ways to implement NMEA or Garmin simple text protocols. Or you could use GPSD (http://gpsd.berlios.de/). I've been about to start a similar project, just using an accelerometer with temporal speed corrections using GPS for a little while now. I've got the maths sorted and the framework I just haven't decided on some of the finer details I was going to do it in C++ but python seemed a much better choice. The only thing that concerns me is a lack of a good timer but I must admit I've not looked into it too hard. I hope this gets you started. Cheers, Robin -- http://mail.python.org/mailman/listinfo/python-list
Re: best solution to for loop
Hi, I have several apps which connect to a database, fetch some data an put this into a gtk.TreeStore, but if the result set is 1500 row long, the app response slowly The first thing to test is whether it's Python or the database that's the bottleneck. 1500 rows isn't all that much for a database, but it might not be trivial either. Even if the bottleneck is Python, the solution might be to limit the amount of data that you process. For example, rather than displaying all 1500 records in a tree (nobody wants to scroll through 1500 records anyway), try grouping them by the first letter of their name. Display a tree consisting of each letter, then when the user clicks that letter: cur.execute(SELECT * FROM clients WHERE name LIKE ' + letter + %') -- I had picked out the theme of the baby's room and done other things. I decided to let Jon have this. - Jamie Cusack (of the Netherlands), whose husband Jon finally talked her into letting him name their son Jon 2.0 -- http://mail.python.org/mailman/listinfo/python-list
Re: python image library TIFF
Thanks! I hadn't known about FreeImage either so double thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help w/ easy python problem
[EMAIL PROTECTED] wrote: I am very much a beginner to python. I have been working on writing a very simple program and cannot get it and was hoping someone could help me out. Basically i need to write a code to print a sin curve running down the page from top to bottom. The trick is I have to do this using only 7-8 lines of code. Any ideas? Yes : do your homework yourself. When you'll run into trouble with *your* code, then post here for help. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding where to store application data portably
On Thu, 22 Sep 2005 02:14:57 +, Ron Adam wrote: Don't all file managers have an option to hide files beginning with '.'? I don't want to hide them. I just don't want them in my face when I open my home directory. +1 This has been a gripe of mine on windows as well, and hiding files (or extensions) is definitely not the answer. Personally I think hidden files do more harm than good. It's not a substitute for good file management, and it not an acceptable alternative to good security either. Agreed. If hidden files are under the control of the user, then they aren't really hidden, they are merely filtered from the current view. Filtering may be useful in many circumstances, but if you are filtering the same files all the time (eg don't show me files starting with a period or don't show me files with the invisible flag set) then you should stick them in a subdirectory. And if hidden files aren't under the control of the user (as certain obscure ways of hiding files under Windows aren't), then it is a serious security risk. You, the user might not be able to hide the files, but you can bet some virus will. Eg if you drop an executable file in the Windows XP font directory, it will not show up in the file explorer. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Chronological Processing of Files
Just to clarify: Newest== modified last The processing\sorting should apply to all the files found recursively during the entire walk. That being said, thanks for all the responses. I'll test the code shortly and get back to everyone. ps. This is why comp.lang.python is truly the greatest list ever. (better than comp.lang.lisp?) Everyone is so helpful. Thanks again guys. -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding where to store application data portably
Ron Adam wrote: Tony Houghton wrote: I'm using pygame to write a game called Bombz which needs to save some data in a directory associated with it. In Unix/Linux I'd probably use ~/.bombz, in Windows something like C:\Documents And Settings\user\Applicacation Data\Bombz. There are plenty of messages in the archives for this group about how to find the correct location in Windows, but what about Mac OS? There I don't know the correct location for this sort of thing at all. And there are other, more obscure systems like RISC OS (it may not have pygame but it definitely has python). Surely this is something that's crying out for an official function in os or sys. This works on Win XP. Not sure if it will work on Linux. import os parent = os.path.split(os.path.abspath(os.sys.argv[0]))[0] file = parent + os.sep + '.bombz' Ooh, no, I don't want saved data to go in the installation directory. In general that practice encourages people to run with Admin access, and it's about time Windows users were discouraged from that. -- The address in the Reply-To is genuine and should not be edited. See http://www.realh.co.uk/contact.html for more reliable contact addresses. -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for system/network monitoring tool written in Python
Mike Meyer [EMAIL PROTECTED] writes: I've found a fair number of systems/network monitoring tools (things like Big Brother, Big Sister, cricket, etc.) written in Perl. Depressing isn't it! I'm curious if there are any written in Python. I couldn't find any after extensive searching. I wasn't really looking for Python solutions as such, more avoiding things in Perl/PHP etc. but I would have noticed any Python ones. I won't bore you with my theories on why this is. Some applications such as nagios and moodss will at least allow you to write your own scripts in Python. This is probably OK for small networks. Eddie -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for system/network monitoring tool written in Python
On 9/22/05, Mike Meyer [EMAIL PROTECTED] wrote: I've found a fair number of systems/network monitoring tools (things like Big Brother, Big Sister, cricket, etc.) written in Perl. I'm curious if there are any written in Python. There's EDDIE - http://eddie-tool.net/. I've never used it myself, but I can confirm that its author, Chris, is a good bloke and can hold his ale, for what that's worth. ;-) -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding where to store application data portably
Ron Adam wrote: Tony Houghton wrote: I'm using pygame to write a game called Bombz which needs to save some data in a directory associated with it. In Unix/Linux I'd probably use ~/.bombz, in Windows something like C:\Documents And Settings\user\Applicacation Data\Bombz. There are plenty of messages in the archives for this group about how to find the correct location in Windows, but what about Mac OS? There I don't know the correct location for this sort of thing at all. And there are other, more obscure systems like RISC OS (it may not have pygame but it definitely has python). Surely this is something that's crying out for an official function in os or sys. This works on Win XP. Not sure if it will work on Linux. import os parent = os.path.split(os.path.abspath(os.sys.argv[0]))[0] file = parent + os.sep + '.bombz' Cheers, Ron Since you've gone to the trouble to use os.path functions why not use file = os.path.join(parent, 'bombz') regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding where to store application data portably
On Tue, 2005-09-20 at 23:03 +0100, Tony Houghton wrote: I'm using pygame to write a game called Bombz which needs to save some data in a directory associated with it. In Unix/Linux I'd probably use ~/.bombz, in Windows something like C:\Documents And Settings\user\Applicacation Data\Bombz. There are plenty of messages in the archives for this group about how to find the correct location in Windows, but what about Mac OS? ~/.bombz works equally well on OSX. -- http://mail.python.org/mailman/listinfo/python-list
idle
Hi, is there no IDLE in Python2.4? o-o Thomas -- http://mail.python.org/mailman/listinfo/python-list
How to use writelines to append new lines to an existing file
Hi there, I would like to open an existing file that contains some lines of text in order to append a new line at the end of the content. My first try was: f = open('/tmp/myfile', 'w') #create new file for writing f.writelines('123') #write first line f.close() f = open('/tmp/myfile', 'w') #open existing file to append new line f.writelines('456') f.close() f = open('/tmp/myfile', 'r') # open file for reading f.read() '456' I supposed to have: f.read() '123\n456\n' Does f = open('/tmp/myfile', 'w') overwrite the existing file or does f.writelines('456') replace the first line in the existing file? Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: Brute force sudoku cracker
Op 2005-09-21, Tom Anderson schreef [EMAIL PROTECTED]: On Mon, 19 Sep 2005, Antoon Pardon wrote: Op 2005-09-17, Tom Anderson schreef [EMAIL PROTECTED]: On Fri, 16 Sep 2005, Bas wrote: -any ideas how to easily incorporate advanced solving strategies? solve(problem1) and solve(problem2) give solutions, but solve(problem3) gets stuck... the only way to solve arbitrary sudoku problems is to guess. That is strange, in al the puzzles that I have solved untill now, I never needed to guess, unless the puzzle had multiple solutions, which personnally I find inferior. Well, if we are to believe Lance Fortnow, a fairly expert comptational complexionist, that's probably not generally true: http://weblog.fortnow.com/2005/08/sudoku-revisited.html It's this bit: Since we don't believe that NP has fast probabilistic algorithms, we expect that there are no efficient procedures to completing a generalized Sudoku grid That makes me think that there probably isn't a non-backtracking method, since that would almost certainly be polynomial-time. The thing is, the puzzles you encounter in the wild have been designed to be solved by humans, using non-backtracking methods; they're much easier to solve than the general class of Sudoku. Well I stand corrected. Thanks for the information. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use writelines to append new lines to an existing file
Use file = open(open('/tmp/myfile', 'a')) the second time when you want to append line Nico Grubert [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi there, I would like to open an existing file that contains some lines of text in order to append a new line at the end of the content. My first try was: f = open('/tmp/myfile', 'w') #create new file for writing f.writelines('123') #write first line f.close() f = open('/tmp/myfile', 'w') #open existing file to append new line f.writelines('456') f.close() f = open('/tmp/myfile', 'r') # open file for reading f.read() '456' I supposed to have: f.read() '123\n456\n' Does f = open('/tmp/myfile', 'w') overwrite the existing file or does f.writelines('456') replace the first line in the existing file? Nico -- http://mail.python.org/mailman/listinfo/python-list
Re: C#3.0 and lambdas
Steven Bethard a écrit : Steven D'Aprano wrote: I would love to see your test code and profiling results that demonstrate that explicit tuple unpacking in the body of a function is faster than tuple unpacking (implicit or explicit) in the header of a function. Should be pretty close. I believe the byte-code is nearly identical: You forgot the most important function : f3 def f1((x,y)): ... print x,y ... def f2(x_y): ... x,y = x_y ... print x,y ... def f3(x_y): ... print x_y[0], x_y[1] ... import dis dis.dis(f1) 1 0 LOAD_FAST0 (.0) 3 UNPACK_SEQUENCE 2 6 STORE_FAST 1 (x) 9 STORE_FAST 2 (y) 2 12 LOAD_FAST1 (x) 15 PRINT_ITEM 16 LOAD_FAST2 (y) 19 PRINT_ITEM 20 PRINT_NEWLINE 21 LOAD_CONST 0 (None) 24 RETURN_VALUE dis.dis(f2) 2 0 LOAD_FAST0 (x_y) 3 UNPACK_SEQUENCE 2 6 STORE_FAST 2 (x) 9 STORE_FAST 1 (y) 3 12 LOAD_FAST2 (x) 15 PRINT_ITEM 16 LOAD_FAST1 (y) 19 PRINT_ITEM 20 PRINT_NEWLINE 21 LOAD_CONST 0 (None) 24 RETURN_VALUE dis.dis(f3) 2 0 LOAD_FAST0 (x_y) 3 LOAD_CONST 1 (0) 6 BINARY_SUBSCR 7 PRINT_ITEM 8 LOAD_FAST0 (x_y) 11 LOAD_CONST 2 (1) 14 BINARY_SUBSCR 15 PRINT_ITEM 16 PRINT_NEWLINE 17 LOAD_CONST 0 (None) 20 RETURN_VALUE -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for system/network monitoring tool written in Python
See http://pynms.sourceforge.net/ Also see Google. :) David. -- http://mail.python.org/mailman/listinfo/python-list
need to divide a date
Hey there, i am doing a plotting application. i am using mxRelativeDateTimeDiff to get how much time is between date x and date y now what i need to do is divide that time by 20 to get 20 even time slots for plotting on a graph. For example, if the difference between them is 20 hours, i need 20 plots, each an hour apart. if its 40 minutes, i need 20 plots that are 2 minutes apart. what would be a way i could pull this off? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling python scripts from C# programs
You should also be aware of IronPython, although it is not suitable for production use due to its reliance on a beta version of the .NET runtime. In some future time, IronPython will probably be the cleanest and simplest way to integrate Python with existing .NET code. http://www.ironpython.com/ -- http://mail.python.org/mailman/listinfo/python-list
time challenge
Hey there, i am doing a plotting application. i am using mxRelativeDateTimeDiff to get how much time is between date x and date y now what i need to do is divide that time by 20 to get 20 even time slots for plotting on a graph. For example, if the difference between them is 20 hours, i need 20 plots, each an hour apart. if its 40 minutes, i need 20 plots that are 2 minutes apart. what would be a way i could pull this off? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: unusual exponential formatting puzzle
Paul Rubin wrote: Neal Becker [EMAIL PROTECTED] writes: Like a puzzle? I need to interface python output to some strange old program. It wants to see numbers formatted as: e.g.: 0.23456789E01 Yeah, that was normal with FORTRAN. My solution is to print to a string with the '% 16.9E' format, then parse it with re to pick off the pieces and fix it up. Pretty ugly. Any better ideas? That's probably the simplest. Acutally, I found a good solution using the new decimal module: def Format(x): Produce strange exponential format with leading 0 s = '%.9E' % x d = decimal.Decimal (s) (sign, digits, exp) = d.as_tuple() s = '' if (sign == 0): s += ' ' else: s += '-' s += '0.' e = len (digits) + exp for x in digits: s += str (x) s += 'E' s += '%+03d' % e return s -- http://mail.python.org/mailman/listinfo/python-list
How to tell if an exception has been caught ( from inside the exception )?
Hi everyone, I'm writing an exception that will open a trouble ticket for certain events. Things like network failure. I thought I would like to have it only open a ticket if the exception is not caught. Is there a way to do this inside the Exception? As far as I can see there are only two events called on the exception, __init__ and __del__, both of which will be called wether or not an exception is caught (right?) Am I missing something, or is there a way to do this with exceptions? Thanks! Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use writelines to append new lines to an existing file
On Thursday 22 September 2005 05:52, Nico Grubert wrote: Does f = open('/tmp/myfile', 'w') overwrite the existing file or does f.writelines('456') replace the first line in the existing file? Here's an excerpt from open.__doc__ The mode can be 'r', 'w' or 'a' for reading (default), writing or appending. The file will be created if it doesn't exist when opened for writing or appending; it will be truncated when opened for writing. Tom -- http://mail.python.org/mailman/listinfo/python-list
Re: How to tell if an exception has been caught ( from inside the exception )?
If the exception isn't caught, it is printed to standard error. This means that either __str__ or __repr__ is called (to convert it to a displayable string). If the exception is caught, those methods *probably* won't be called. -- Where you are is not as important as where you are going. - Oliver Wendell Holmes, U.S. Supreme Court Justice -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl's documentation come of age
Måns Rullgård [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] This guy deserves two ascii trolls: ___ /| /| | | ||__|| | Please do | / O O\__ NOT | / \ feed the| / \ \ trolls | / _\ \ __| /|\\ \ || / | | | |\/ || / \|_|_|/ \__|| / / \|| || / | | /|| --| | | |// | --| * _| |_|_|_| | \-/ *-- _--\ _ \ // | / _ \\ _ // |/ * / \_ /- | - | | * ___ c_c_c_C/ \C_c_c_c +---+ .:\:\:/:/:. | PLEASE DO NOT |:.:\:\:/:/:.: | FEED THE TROLLS | :=.' - - '.=: | | '=(\ 9 9 /)=' | Thank you, | ( (_) ) | Management | /`-vvv-'\ +---+ / \ | |@@@ / /|,|\ \ | |@@@ /_// /^\ \\_\ @x@@x@| | |/ WW( ( ) )WW \/| |\| __\,,\ /,,/__ \||/ | | | jgs (__Y__) /\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ == And the Original Troll: s sS. S, $Ss, SSs$$SSs, s SSs$$s,Ss. SSs$$$$ss sSSs$$SSS$$sSSS. s sSSSs$$S$$sSSs$s, ss$$SSS$$sSS$$SS, s sSSs$$SSS$$sSSSs$$SSs, sSs$$s$$SSS$$sSS$$s sSSs$$SS$$SS$$sSSs$$SS, s$$$SSS$$sSSS$$SSs, sSs$$Ss$$s SSS$$SSS$$SS, .SSSs$$SSs$$SSS, S$$SS$$S, .Ss$$SSSs$$SSS $SSS$$SSS$$SSS .s$$Ss$$S$' SSs$$SS$$SSS$s s$$S$S$$sS SSs$$SSS$$sSSS `SSSs$$SSS$$sS s$$SSS$$sSSS' `SSs$$SSS$$s Ss$$SSSSS$$sSS' `SSS%,;mnv%%;;;%%vnm;,%SS' `SSS.vnnmmvmmn%%;%%nmmvmmnnv.SS' `S,vnnmmvv' `vmmn%;%nmmv' `vvmmnnv,%%%S' /vmnnnvnnmmmvv, .vnnnv;vnnnv, .vvmmmnnvnnnmv\ ;vm;%%nvnnn%;mmm;%nnnvn%%;mv; `vmm;%nvnnnnv%;mmm;%vnnnnvn%;mmv' `vmmnvnnnvv%;m%%m%%m;%vvnnnvnmmv' \vvvnnnvvv;vnnnv;vvvnnnvvv/ \vvnnn;vvv;v;vvv;nnnvv/ \vvnnnvv;%;%;%;%;%;vvnnnvv/ .,v% \nnnmnnn/%v,. .,vvnnnvv%;%;%;%;%;%;%;%vvnnvv,. .,vvvv,. ,vvnnvv, ,vvnvvnnvvnvv, .vvnn `nn' nnvv. .vvnn' mmmm `nnvv. vmmvnmmvnmmv' ., `vmmnvmmnvmmv `nm%nm%nm%' nn `%mn%mn%mn' nn nn(*)n .vmmmmv, .vnvvnv. .vvnvvvvvvnvv. vvnnnmmmvnnnvv .vvnnn' `vvvnnnvv. vvnnvv vvnvv .vvnnnv vnnvv. vnmnvnmnvnmnvnmnvnm. .mnvnmnvnmnvnmnvnmv vmmm%mmm%mmm%mmm%mmm mmm%mmm%mmm%mmm%mmm -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use writelines to append new lines to an existing file
Nico Grubert [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: Hi there, I would like to open an existing file that contains some lines of text in order to append a new line at the end of the content. My first try was: f = open('/tmp/myfile', 'w') #create new file for writing f.writelines('123') #write first line f.close() f = open('/tmp/myfile', 'w') #open existing file to append new line f.writelines('456') f.close() f = open('/tmp/myfile', 'r') # open file for reading f.read() '456' I supposed to have: f.read() '123\n456\n' Does f = open('/tmp/myfile', 'w') overwrite the existing file or does f.writelines('456') replace the first line in the existing file? Nico There is a good explanation in the tutorial: http://docs.python.org/tut/node9.html#SECTION00920 and more detail is available in the docs for builtin functions: http://docs.python.org/lib/built-in-funcs.html (look under file() but probably still use open()) That said, open(file, 'a') will open an existing file to append. max -- http://mail.python.org/mailman/listinfo/python-list
Convert from unicode to int
Hi Is there any simpler way to convert a unicode numeric to an int than: int(u'1024'.encode('ascii')) ?? regards tores -- http://mail.python.org/mailman/listinfo/python-list
re.split() problem
Hi all. re.split() doesn't work as I intend. My Python Version is 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32. For example, r = re.compile('^$', re.MULTILINE) r.split('foo\nbar\n\nbaz') ['foo\nbar\n\nbaz'] but I expected ['foo\nbar\n', 'baz']. This problem has been discussed following threads. [ 852532 ] ^$ won't split on empty line http://sourceforge.net/tracker/index.php?func=detailaid=852532group_id=5470atid=105470 re.split on empty patterns http://thread.gmane.org/gmane.comp.python.devel/62231 Will it be fixed in Python 2.4.2? Regards, -- Masayuki Takemura -- http://mail.python.org/mailman/listinfo/python-list
Re: How to tell if an exception has been caught ( from inside theexception )?
Paul Dale wrote: I'm writing an exception that will open a trouble ticket for certain events. Things like network failure. I thought I would like to have it only open a ticket if the exception is not caught. Is there a way to do this inside the Exception? As far as I can see there are only two events called on the exception, __init__ and __del__, both of which will be called wether or not an exception is caught (right?) Am I missing something, or is there a way to do this with exceptions? if you want to trap uncaught exceptions, add an except handler to the top level of your program: try: main() except MySpecialException, v: v.open_trouble_ticket() a less convoluted approach would be do to def open_trouble_ticket(exctype, value, traceback): ... try: main() except: open_trouble_ticket(*sys.exc_info()) or, in recent Python versions, import sys def open_trouble_ticket(exctype, value, traceback): ... sys.excepthook = open_trouble_ticket main() /F -- http://mail.python.org/mailman/listinfo/python-list
Open PDF
Hello, I would like to know how to open a PDF document from a python script, any suggestions are appreciated. Thanks, JR -- http://mail.python.org/mailman/listinfo/python-list
Re: Threading, real or simulated?
Op 2005-09-22, Sam schreef [EMAIL PROTECTED]: Jp Calderone writes: On Wed, 21 Sep 2005 18:23:33 -0500, Sam [EMAIL PROTECTED] wrote: I'm using Python 2.3.5 with pygtk 2.4.1, and I'm using the second threading approach from pygtk's FAQ 20.6 - invoking gtk.gdk.threads_init(), and wrapping all gtk/gdk function calls with gtk.threads_enter()/gtk.threads_leave() I start a thread, via thread.Threading.start(). The thread then calls a particularly time consuming C function, from an extension module. I find that when the thread is running the C code, the GUI hangs even though I'm not inside the threads_enter/threads_leave territory. Does the extension module release the GIL? It sounds like it does not. Of course, there are a dozen other mistakes that could be made which would have roughly this symptom. It's difficult to say which is the problem without actually seeing any code. What's the GIL?. The general interpretor lock. In general changing python internals is not thread-safe. The current implementation uses a lock (the GIL) for thread to safely rebind variable or mutate object. The result is that threads are serialised. The extension module is invoked outside of threads_enter/threads_leave(). It looks like thread.Threading() only simulates threading, by having the python interpreter multiplex between running threads. Is real threading possible, so that I do something time-consuming in the thread, without hanging the GUI? Assuming you mean threading.Thread, this is a native thread. It is not a simulation. Something else is going wrong. Then I must have something locked. Here's what I do: Yes you have locked the GIL. Take a look at the following URL: http://docs.python.org/api/threads.html, hope it helps. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert from unicode to int
Tor Erik Sønvisen wrote: Hi Is there any simpler way to convert a unicode numeric to an int than: int(u'1024'.encode('ascii')) why doesn't: int(u'104') work for you? -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert from unicode to int
On 2005-09-22, Tor Erik Sønvisen [EMAIL PROTECTED] wrote: Hi Is there any simpler way to convert a unicode numeric to an int than: int(u'1024'.encode('ascii')) int(u'1024') 1024 Didn't that work for you when you tried it? -- Grant Edwards grante Yow! FIRST, I'm covering at you with OLIVE OIL and visi.comPRUNE WHIP!! -- http://mail.python.org/mailman/listinfo/python-list
Stampare su stampante aghi
Salve a tutti, sono alle prese con delle stampe su stampanti ad aghi... Per stampare puro testo la soluzione più gettonata sembra essere f = open(LPT1:) f.write(bla bla) f.close() devo dire che funziona benissimo, ma mi piacerebbe essere slegato falla parallela (sempre meno frequente) e inviare il puro testo da stampare scegliendo una delle stampanti installate sulla macchina senza starmi a preoccupare di come o dove sia configurata (locale, rete, usb, etc). Come posso fare? Grazie, Luca. -- http://mail.python.org/mailman/listinfo/python-list
Re: plateform info.
Maurice LING [EMAIL PROTECTED] writes: Is there a way of getting the path to the site-packages directory? import sys import os for dir in sys.path: ... if os.path.split(dir)[-1] == 'site-packages': ... print dir ... /usr/opt/lib/python2.4/site-packages But there's seldom a reason to want this. Considering that Mac OSX with Fink installs python libraries in /sw/lib/pythonversion, Mac OSX itself has python libraries in /System/Library/Frameworks/Python.framework/Versions/version/lib, etc etc... And darwinportgs puts them in /Library/Frameworks/Python.framework/Versions/Version/lib/... but includes /opt/local/lib/python2.4/site-packages in sys.path. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
NTEventLogHandler not logging `info'?
This code doesn't seem to do what I think it should do: # python 2.3.2 # not sure of my win32 extensions version import logging from logging.handlers import NTEventLogHandler logger = logging.getLogger(testlogger) handler = NTEventLogHandler(testlogger) logger.addHandler(handler) logger.info(This is a test) I expected to see an `information' message in my `Application' event log. Any ideas? Thanks, jw -- http://mail.python.org/mailman/listinfo/python-list
Re: Open PDF
I would like to know how to open a PDF document from a python script You mean open it and display it to the user? Under Windows you may be able to get away with just executing the file (as though it were an executable): import os os.system(c:/path/to/file.pdf) Under Linux you can probably use xpdf or gpdf: os.system(xpdf /path/to/file.pdf) Note that you should check the return code of system to see if the execution was successful. For example, the user might not have xpdf installed. -- Don't try to be charming, witty or intellectual. Just be yourself. - Mrs. Cuomo's poorly worded advice to her husband (then governor of New York) shortly before his speech to the New York Press Club -- http://mail.python.org/mailman/listinfo/python-list
Re: How to tell if an exception has been caught ( from inside the exception )?
Paul Dale wrote: Hi everyone, I'm writing an exception that will open a trouble ticket for certain events. Things like network failure. I thought I would like to have it only open a ticket if the exception is not caught. Is there a way to do this inside the Exception? As far as I can see there are only two events called on the exception, __init__ and __del__, both of which will be called wether or not an exception is caught (right?) Am I missing something, or is there a way to do this with exceptions? Is there some reason you can't wrap your entry point with a try:except? e.g. if __name__ == __main__: try: main() except OpenTicket, e: process_open_ticket(e) -- http://mail.python.org/mailman/listinfo/python-list
Re: need to divide a date
[EMAIL PROTECTED] wrote: Hey there, i am doing a plotting application. i am using mxRelativeDateTimeDiff to get how much time is between date x and date y now what i need to do is divide that time by 20 to get 20 even time slots for plotting on a graph. For example, if the difference between them is 20 hours, i need 20 plots, each an hour apart. if its 40 minutes, i need 20 plots that are 2 minutes apart. what would be a way i could pull this off? thanks C:\Steve\Projects\Pythonpython Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import mx.DateTime as dt d1 = dt.DateTime(2005, 1, 1) d2 = dt.DateTime(2005, 1, 21) rdt = dt.RelativeDateTimeDiff(d2, d1) rdt RelativeDateTime instance for '-MM-(+20) HH:MM:SS' at 0x9f1300 rdt/20 RelativeDateTime instance for '-MM-(+01) HH:MM:SS' at 0x9d5e90 for i in range(20): ...print dt.DateTime(2000) + i*(rdt/20) ... C:\Python24\lib\site-packages\mx\DateTime\DateTime.py:585: DeprecationWarning: i nteger argument expected, got float return DateTime(year, month, 1) + \ 2000-01-01 00:00:00.00 2000-01-02 00:00:00.00 2000-01-03 00:00:00.00 2000-01-04 00:00:00.00 2000-01-05 00:00:00.00 2000-01-06 00:00:00.00 2000-01-07 00:00:00.00 2000-01-08 00:00:00.00 2000-01-09 00:00:00.00 2000-01-10 00:00:00.00 2000-01-11 00:00:00.00 2000-01-12 00:00:00.00 2000-01-13 00:00:00.00 2000-01-14 00:00:00.00 2000-01-15 00:00:00.00 2000-01-16 00:00:00.00 2000-01-17 00:00:00.00 2000-01-18 00:00:00.00 2000-01-19 00:00:00.00 2000-01-20 00:00:00.00 Does this help? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding where to store application data portably
rbt [EMAIL PROTECTED] writes: On Tue, 2005-09-20 at 23:03 +0100, Tony Houghton wrote: I'm using pygame to write a game called Bombz which needs to save some data in a directory associated with it. In Unix/Linux I'd probably use ~/.bombz, in Windows something like C:\Documents And Settings\user\Applicacation Data\Bombz. There are plenty of messages in the archives for this group about how to find the correct location in Windows, but what about Mac OS? ~/.bombz works equally well on OSX. But Mac users - as opposed to Unix geeks - will expect to find it in ~/Library/Application Support/Bombz. Us unix geeks can symlink that to ~/.bombz if we use the application on both platforms. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: idle
On Thu, 22 Sep 2005 14:31:22 +0200, TK [EMAIL PROTECTED] wrote: Hi, is there no IDLE in Python2.4? o-o Thomas Sure, on Windows: C:\Python24\Lib\idlelib\idle.pyw You should have a shortcuts in your StartMenu und Python 2.4 -- Franz Steinhaeusler -- http://mail.python.org/mailman/listinfo/python-list
Need help:Unable to make runnable Python on AIX 4.3.3
I have a vexing problem and seek some input on how to fix it. Starting with Python 2.4.0, I have been unable to compile a working Python on our AIX 4.3.3 development system. I can compile a working Python 2.3.x with no problem. The failure symptom is that Python 2.4.x fails its unit tests on test_builtin with a Segmentation fault. Turning on verbose test output in the Makefile via the '-v' flag yields the following: (Much output from passing tests elided) test_open (test.test_builtin.BuiltinTest) ... ok test_ord (test.test_builtin.BuiltinTest) ... ok test_pow (test.test_builtin.BuiltinTest) ... ok test_range (test.test_builtin.BuiltinTest) ... ok test_reduce (test.test_builtin.BuiltinTest) ... ok gmake: *** [test] Segmentation fault Any ideas on how to find/fix this problem? I'd hate to get locked into Python 2.3, but that's what will happen if I can't solve this. -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for system/network monitoring tool written in Python
David Wilson [EMAIL PROTECTED] writes: See http://pynms.sourceforge.net/ Thanks for the pointer. And to Simon Brunning for the pointer to Eddie. Also see Google. :) While everything may be in Google, it's not always obvious how to get it out. I've managed to extract a score of systems from Google - but none based on Python... mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: re.split() problem
Masayuki Takemura wrot: re.split() doesn't work as I intend. it works as it's supposed to work. empty matches are not considered to be valid split points, partially because it doesn't really make sense to split on nothing in most cases, but mostly because doing so will, most likely, result in a lot more split doesn't do what I want reports than the current design... For example, r = re.compile('^$', re.MULTILINE) r.split('foo\nbar\n\nbaz') ['foo\nbar\n\nbaz'] but I expected ['foo\nbar\n', 'baz']. so use an ordinary string split, or rephrase your RE. if not else, you can always invert your problem: s = foo\nbar\n\nbaz re.findall((?s).*\n\n|.+$, s) ['foo\nbar\n\n', 'baz'] (this also lets you use finditer so you can process huge texts without having to hold everything in memory) Will it be fixed in Python 2.4.2? 2.4.2 is a bug fix release. doesn't work as you intend doesn't really count as a bug (unless you wrote the specification, of course, which I don't think you did...) /F -- http://mail.python.org/mailman/listinfo/python-list
Simultaneous Adobe Reader
Hello, From windows, using a python script how can I open Adobe Reader without displaying a PDF document? Furthermore, using a script is it possible torun two Adobe Reader sessions simulatneously. Thanks in advance. Kind Regards, JR -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for system/network monitoring tool written in Python
Simon Brunning [EMAIL PROTECTED] writes: On 9/22/05, Mike Meyer [EMAIL PROTECTED] wrote: I've found a fair number of systems/network monitoring tools (things like Big Brother, Big Sister, cricket, etc.) written in Perl. I'm curious if there are any written in Python. There's EDDIE - http://eddie-tool.net/. I've never used it myself, How annoying that I didn't even notice one that was named after me. It's not what I was after but interesting none the less. Eddie -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding where to store application data portably
On Thu, 22 Sep 2005 00:23:56 +1000 Steven D'Aprano wrote: I wish the Linux Standard Base folks would specify that settings files should all go into a subdirectory like ~/settings rather than filling up the home directory with cruft. That was acceptable in the days when people only looked at their files with ls, but in these days of GUI file managers, it is ridiculous that there are more than 100 dot files and directories in my home directory. So it is the very rationale why dot-files historically considered as hidden in all unix shells and filemanagers. tilting at windmills Can I ask developers to break with the obsolete and annoying habit of creating user-specific config files as ~/.app-name and use ~/settings/app-name instead? /tilting at windmills There is an other way around: look at your home dir as if it is your settings dir and don't clutter it with files other than application config dot-files. Just make ~/files/, ~/bin/ ~/lib/ etc. for it. -- jk -- http://mail.python.org/mailman/listinfo/python-list
Re: NTEventLogHandler not logging `info'?
Jaime Wyant wrote: This code doesn't seem to do what I think it should do: # python 2.3.2 # not sure of my win32 extensions version import logging from logging.handlers import NTEventLogHandler logger = logging.getLogger(testlogger) handler = NTEventLogHandler(testlogger) logger.addHandler(handler) logger.info(This is a test) I expected to see an `information' message in my `Application' event log. Any ideas? By default, the logger's level is WARNING, because you haven't explicitly set a level and the level inherited from the parent logger is WARNING (this is the default value for the root logger level). So if you add a line before the logger.info() call: logger.setLevel(logging.INFO) # or you can use logging.DEBUG Then you should see an entry appear in the NT Event log. -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl's documentation come of age
Steve Holden [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Jim Hugunin's keynote speech at this year's PyCon was accompanied by a projection if his interactive interpreter session, and I know I wasn't alone in finding this a convincing example of Microsoft's (well, Jim's, really) full integration of Python into the .net framework. Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org Which .Net integreation technology are you speaking of? BTW, PyCon.org seems to be down (at least not reachable from here at the moment.) thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Open PDF
Dan [EMAIL PROTECTED] writes: Under Linux you can probably use xpdf or gpdf: os.system(xpdf /path/to/file.pdf) Note that you should check the return code of system to see if the execution was successful. For example, the user might not have xpdf installed. This is the problem that the open package was designed to solve. The API for Python apps is still under development, but if you do 'os.system(open /path/to/file.pdf)', open will use the users preferred pdf viewer, and interact with the user to select one if they don't have a prefernce on record. mike -- Mike Meyer [EMAIL PROTECTED] http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Python installation root directory problem
Hi, I am trying to install python 2.4.1 on a windows XP machine. Whether I choose to install 'for me' or 'for all users, and no matter where I select as the root directory, the installer always puts the python root in C:\, which is obviously a bit messy. I am running this instalaltion as a slightly restricted non-administrative user, but I can create the C:\Python24 directory that I specified in the installation program and put files in it, so I do not think this can be the reason the installer fails. I have uninstalled python and deleted all references to it in the registry, then reinstalled, and experienced the same effect. Does anyone have any ideas what this might be? Thanks, Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling python scripts from C# programs
Another option is to implement the needed python code in COM server and call that from C#. A simple example of python COM server can be seen about halfway down the page here http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html -- http://mail.python.org/mailman/listinfo/python-list
Re: NTEventLogHandler not logging `info'?
I must be missing something. This is what I read from the documentation: When a logger is created, the level is set to NOTSET (which causes all messages to be processed in the root logger, or delegation to the parent in non-root loggers). :/ Thanks! jw On 22 Sep 2005 08:21:48 -0700, Vinay Sajip [EMAIL PROTECTED] wrote: Jaime Wyant wrote: This code doesn't seem to do what I think it should do: # python 2.3.2 # not sure of my win32 extensions version import logging from logging.handlers import NTEventLogHandler logger = logging.getLogger(testlogger) handler = NTEventLogHandler(testlogger) logger.addHandler(handler) logger.info(This is a test) I expected to see an `information' message in my `Application' event log. Any ideas? By default, the logger's level is WARNING, because you haven't explicitly set a level and the level inherited from the parent logger is WARNING (this is the default value for the root logger level). So if you add a line before the logger.info() call: logger.setLevel(logging.INFO) # or you can use logging.DEBUG Then you should see an entry appear in the NT Event log. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: NTEventLogHandler not logging `info'?
BTW - you're suggestion worked. Thanks again! jw On 9/22/05, Jaime Wyant [EMAIL PROTECTED] wrote: I must be missing something. This is what I read from the documentation: When a logger is created, the level is set to NOTSET (which causes all messages to be processed in the root logger, or delegation to the parent in non-root loggers). :/ Thanks! jw On 22 Sep 2005 08:21:48 -0700, Vinay Sajip [EMAIL PROTECTED] wrote: Jaime Wyant wrote: This code doesn't seem to do what I think it should do: # python 2.3.2 # not sure of my win32 extensions version import logging from logging.handlers import NTEventLogHandler logger = logging.getLogger(testlogger) handler = NTEventLogHandler(testlogger) logger.addHandler(handler) logger.info(This is a test) I expected to see an `information' message in my `Application' event log. Any ideas? By default, the logger's level is WARNING, because you haven't explicitly set a level and the level inherited from the parent logger is WARNING (this is the default value for the root logger level). So if you add a line before the logger.info() call: logger.setLevel(logging.INFO) # or you can use logging.DEBUG Then you should see an entry appear in the NT Event log. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling python scripts from C# programs
David Wilson wrote: http://www.ironpython.com/ It should be noted that they (?) don't seem to update that site anymore, you can find 0.9.1 here: http://workspaces.gotdotnet.com/ironpython There is also Boo, which is Python-like (with some differences) but is a .NET Language itself. I never understood if IronPython was ment to be fully Python compatible, so I don't know if Boo is the same or further from what you may want... anyways, http://boo.codehaus.org/ -- http://mail.python.org/mailman/listinfo/python-list
Indexed variables
Hello, being an almost complete Python AND programming neophyte I would like to ask the following - very elementary, as I might suspect - question: How do I do the following flawed things right: a1=a2=0 def f(x): if x == a1: a1 = a1 + 1 elif x == a2: a2 = a2 + 1 Now if I call f with f(a2) only a1, of course, is incremented because the if-clause does only check for the value of the input and the values of a1 and a2 are identical. So how do I define the function such as to discrimate wheter I call it by f(a1) or f(a2) ? Thank you very much, Peter -- Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko! Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython Notebook crash when pressing alt key
Kreedz wrote: Could Windows version have anything to do with this?? Else I've got some really weird issue... I'm on Windows 2000 Professional Yes, that definitely counts as a wierd issue. wink I couldn't reproduce the bug either. C:\temppython ActivePython 2.4.1 Build 247 (ActiveState Corp.) based on Python 2.4.1 (#65, Jun 20 2005, 17:01:55) [MSC v.1310 32 bit (Intel)] on win32 import wx wx.__version__ '2.6.1.0' It's the unicode build, in case that makes any difference. Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: Indexed variables
a1=a2=0 def f(x): if x == a1: a1 = a1 + 1 elif x == a2: a2 = a2 + 1 Now if I call f with f(a2) only a1, of course, is incremented because the if-clause does only check for the value of the input and the values of a1 and a2 are identical. So how do I define the function such as to discrimate wheter I call it by f(a1) or f(a2) ? What you are trying to do is to create a function with a side effect. (Side effect is when a function changes its environment. The environment of a function is everything that is not local to that function, plus the actual parameters and I/O devices.) If you really want to change an actual parameter inside an object, then you should use a mutable object. In Python, there are two kinds of objects: mutable and immutable. Immutable objects cannot change their value. Integers are immutable. The object zero will always be zero. You can add another integer to it, but it will create another object, while the zero object will remain zero. There are other immutable objects. For example, tuples are immutable. t = (1,2,3) This object is an immutable tuple. You cannot change its value. Mutable objects can change their values. For example, lists are mutable. L = [1,2,3] Usually, mutable objects have methods to change their value. L.append(4) print L [1,2,3,4] So if you really want to create a function with a side effect, do something like this: a1 = [0] a2 = [0] def f(x): ... if x is a1: ... a1[0] += 1 ... elif x is a2: ... a2[0] += 1 ... a1 [0] f(a1) a1 [1] a2 [0] But please note that having side effect is generally considered harmful. Please read the tutorial, these things are explained quite well. http://docs.python.org/tut/tut.html Best, Les -- http://mail.python.org/mailman/listinfo/python-list
Re: Indexed variables
[EMAIL PROTECTED] wrote: So how do I define the function such as to discrimate wheter I call it by f(a1) or f(a2) ? I don't want to sound rude, but I think you'll be better served by telling us why you would want to do such a thing - ten to one someone can suggest a better way to acomplish you end goal, rather than discriminating on which variable is passed to a function. -- http://mail.python.org/mailman/listinfo/python-list
Re: Indexed variables
On Thu, 22 Sep 2005 [EMAIL PROTECTED] wrote: How do I do the following flawed things right: Well, that depends on what you mean by 'right'. I'm going to give you two solutions; one that answers your apparent question, and one that addresses what i suspect is your true question. a1=a2=0 def f(x): if x == a1: a1 = a1 + 1 elif x == a2: a2 = a2 + 1 The problem here is to do with how variables work. When you say f(a2), you don't mean call f, and pass a2 as the parameter, you say call f, and pass the value of a2 as the parameter. It's a bit like if you have a cat, and two tins of sardines; you might say you feed a tin of sardines to the cat, but really, you're feeding it the sardines that were in the tin - you have to take them out of it first. Accordingly, if the sardines are identical, the cat has no way of knowing which tin the sardines came out of. I guess you know this. So, first solution. What you can do is, rather than sending a value into f, is send the name of the variable you want to operate on, say as a string: a1 = a2 = 0 def f(name): if (name == a1): a1 = a1 + 1 elif (name == a2): a2 = a2 + 1 You could even do this fully generically, using some magic: a1 = a2 = 0 def f(name): g = globals() g[name] = g[name] + 1 I make absolutely no warranty that this will always do what you expect! However, in my centuries of experience on programming newsgroups, if there's one thing that i've learned, it's that people who want to do this usually don't actually want to do this. They have some real need for storing a varying number of values under arbitrary names, and they think that the way to do this is by having a different variable for each. They are almost always wrong. What they really want is the second solution: a collection object, like a list or dictionary: a = {} a[1] = 0 a[2] = 0 def f(number): a[number] = a[number] + 1 This avoids mucking about with the variable namespace, which is usually a bad idea, and it means you have all the variables grouped together in one place, making it easy to look at them all together, or pass them to some other function, or whatever. For extra style, try this: a = {} def f(number): a[number] = a.get(number, 0) That effectively automatically initialises every value stored in a to zero. Hope this helps, tom -- The ``is'' keyword binds with the same precedence as ``.'', even when it's not actually there. -- Larry Wall, Apocalypse 2 -- http://mail.python.org/mailman/listinfo/python-list
Re: Indexed variables
If you really want to change an actual parameter inside an object, then inside a function, I mean -- http://mail.python.org/mailman/listinfo/python-list
Re: Question About Logic In Python
Steve Holden wrote: Ron Adam wrote: 2. Expressions that will be used in a calculation or another expression. By which you appear to mean expressions in which Boolean values are used as numbers. Or compared to other types, which is common. This matters because if you aren't careful your results may not be what you expect. Well yes, but then I wouldn't necessarily expect good results if I tried to use a nail file as a tyre-lever, either. If you abuse the intent of anything sufficiently you should expect trouble. But then, you seem to like trouble ;-) Steve... You seem to agree, but think if any one has a problem with this, it's a misuse or an abuse. Ok. fair enough. Its not so much I like trouble, It's more that I tend to get stuck on contradictions and inconsistencies. They bug me. (sometimes I bug myself as well) ;-) True * True 1 # Why not return True here as well? Why not return 42? Why not return a picture of a banana? My question still stands. Could it be helpful if bools were preserved in more cases than they are now? My feelings is that it isn't needed as long as you strictly use your own modules, functions, and classes, and can depend on the behavior you decide on. But if you are using routines and object written by others, you can't always be sure if a values should be treated as a bool or as an integer. Preserving bools when possible, may help in that regard. This is like adding two integer types and getting a float. No it isn't. It's like trying to multiply April 2 1994 by June 5 2005. The operation isn't defined. So you choose an arbitrary definition and say it would be nice if it worked like this instead of how it actually does work. Sure, but if we didn't suggest changes, then nothing would change. We would just have extremely detailed documentation of everything and strict rules of use so that we don't misuse them. ;-) When in fact it doesn't really work at all, except for the most tenuous possible value of work. It's an accident, because Guido decided that least code breakage was good when Booleans were introduced. Good point, but it could be changed in Python 3000 since it will drop the backwards compatible requirement. This doesn't mean that it should though. The reasons for doing so still need to be sufficient. There's the possibility of adding two (normally) True values and getting a False result. a = True b = -1 a + b # True_value + True = False_value 0 Which is yet another reason why it makes absolutely no sense to apply arithmetic operations to Boolean values. Again you agree, yet disagree. Ok, I see your point about breaking code, but should this be changed, either throw an exception or by changing to a boolean operation in Python 3000? You already consider it an abuse. You are, of course, ignoring the huge amount of code breakage this little change you'd find so convenient would cause. I'm not suggesting anything be changed before Python 3000 which has as a purpose of changing things that haven't been changed because of backwards compatibility. And I don't think I'm the only one who has suggested these. On one hand these seem like little things, but little things is sometimes what will bite you the hardest as they are more likely to get by your guard. Kindly think again about the vast number of times that Python programmers have relied on the documented property of and, which says that it returns the left operand (without evaluating the right one) unless the left operand is equivalent to False, in which case it returns the right operand. The shortcut behavior would still work, but the returned values would be either True or False. I agree the above is useful behavior, but I also see the boolean behavior as desirable. I would like both in clear and separate contexts if possible. Guido said the other day on python-dev, he would consider having 'and' and 'or' return True and False in order to reduce bugs, if a trinary was also added. It's not as short to type, but the same functionality would still be present in the language. Another possibility would be to just add bool operators '||' and '' which would always return True and False and leave 'and' and 'or' as they are. You talk about least surprises and in my opinion as though your opinions are the only ones that anyone would dream of holding. This is in itself quite surprising to me. No, in my opinion means exactly that, It's my personal opinion. You are free and welcome to express your opinion as well. And least surprises is, I believe, a good thing to strive for. Weather or not this would fit that I'm not sure. It's quite possible that some of these changes would create more surprises not less. Also these ideas aren't mine, they are fairly standard concepts that other languages use as well, nothing really new here. Cheers, Ron --
Re: Writing a parser the right way?
Thanks for the hints. I just found NLTK and MontyLingua. And yes, it is just adventure game language. This means every tense except present tense is discarded as not changing world. Furthermore the parser will make a lot of assumptions, which are perhaps 90% right, not perfect: if word[-2:] == ly: return Adverb(word) Note that uppercase words are identified before, so Willy is parsed correctly as a noun. On the other hand silly boy, will not return a correct result. Currently it is just a proof-of-concept. Maybe i can integrate a better parser engine later. The idea is a kind of mud, where you talk correct sentences instead of go north. I envision a difference like Diablo to PenPaper. I'd call it more a collaborative story telling game, than a actual RPG. I fed it your sentences, Paul. Result: ['I', 'drive', 'a'] ['red'] ['truck'] should be: ['I'] ['drive'] ['a', 'red', 'truck'] Verbs are the tricky part i think. There is no way to recognice them. So i will have to get a database ... work to do. ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding where to store application data portably
Steve Holden wrote: Ron Adam wrote: Tony Houghton wrote: I'm using pygame to write a game called Bombz which needs to save some data in a directory associated with it. In Unix/Linux I'd probably use ~/.bombz, in Windows something like C:\Documents And Settings\user\Applicacation Data\Bombz. There are plenty of messages in the archives for this group about how to find the correct location in Windows, but what about Mac OS? There I don't know the correct location for this sort of thing at all. And there are other, more obscure systems like RISC OS (it may not have pygame but it definitely has python). Surely this is something that's crying out for an official function in os or sys. This works on Win XP. Not sure if it will work on Linux. import os parent = os.path.split(os.path.abspath(os.sys.argv[0]))[0] file = parent + os.sep + '.bombz' Cheers, Ron Since you've gone to the trouble to use os.path functions why not use file = os.path.join(parent, 'bombz') It just didn't come to mind first. I don't use os.path that often. Thanks. :-) regards Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Python installation root directory problem
Further diggingappears to show this is an instance of the problem documented here: http://tinyurl.com/82dt2 Running msiexec with logging revealed the following lines: MSI (s) (48:F8) [18:15:47:990]: Ignoring disallowed property X MSI (s) (48:F8) [18:15:47:990]: Ignoring disallowed property TARGETDIR MSI (s) (48:F8) [18:15:47:990]: Ignoring disallowed property DLLDIR MSI (s) (48:F8) [18:15:47:990]: Ignoring disallowed property USERNAME MSI (s) (48:F8) [18:15:47:990]: Ignoring disallowed property COMPANYNAME MSI (s) (48:F8) [18:15:47:990]: Ignoring disallowed property SOURCEDIR MSI (s) (48:F8) [18:15:47:990]: Ignoring disallowed property ROOTDRIVE Values were not being passed from the UI to the actual installation script as they were untrusted. This can be resolved as described in the link above by using SecureCustomProperties. I have therefore submitted this to the sourceforge bug tracker. Matt Matt Leslie [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I am trying to install python 2.4.1 on a windows XP machine. Whether I choose to install 'for me' or 'for all users, and no matter where I select as the root directory, the installer always puts the python root in C:\, which is obviously a bit messy. I am running this instalaltion as a slightly restricted non-administrative user, but I can create the C:\Python24 directory that I specified in the installation program and put files in it, so I do not think this can be the reason the installer fails. I have uninstalled python and deleted all references to it in the registry, then reinstalled, and experienced the same effect. Does anyone have any ideas what this might be? Thanks, Matt -- http://mail.python.org/mailman/listinfo/python-list
Linux/Python - SQL*Server Connexion chain
Hi, Have you guys any good experience on connecting a Python (Zope) app running on Linux to a Windoze SQL*Server ? Many thanks by advance to report your success, failure, pitfalls (...) and used products. Even reports using commercial solutions are welcome. -- Gilles -- http://mail.python.org/mailman/listinfo/python-list
Re: time challenge
nephish wrote: i am doing a plotting application If its 40 minutes, i need 20 plots that are 2 minutes apart. what would be a way i could pull this off? thanks Sounds like homework related to another assignment discussed above. Write your code, try to get it to work, and _then_ if you have problems ask smart questions here about specific issues you have with getting your code to work. See: http://www.catb.org/~esr/faqs/smart-questions.html -Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Threading, real or simulated?
Antoon Pardon wrote: Op 2005-09-22, Sam schreef [EMAIL PROTECTED]: What's the GIL?. The general interpretor lock. In general changing python internals That should be global (and, more pedantically, interpreter). -- http://mail.python.org/mailman/listinfo/python-list
How to show percentage
Dear All: I have a question of show percentage. For example ,I want to show the percentage of 1/3 = 33.33% I use the 1*100/3 = 33 it is 33 not 33.33 , how to show the 33.33 % Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Writing a parser the right way?
beza1e1 wrote: Verbs are the tricky part i think. There is no way to recognice them. So i will have to get a database ... work to do. ;) Try the Brill tagger[1] or MXPOST[2]. STeVe [1] http://www.cs.jhu.edu/~brill/code.html [2] ftp://ftp.cis.upenn.edu/pub/adwait/jmx/jmx.tar.gz -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl's documentation come of age
Mike wrote: Jim Hugunin's keynote speech at this year's PyCon was accompanied by a projection if his interactive interpreter session, and I know I wasn't alone in finding this a convincing example of Microsoft's (well, Jim's, really) full integration of Python into the .net framework. Which .Net integreation technology are you speaking of? http://workspaces.gotdotnet.com/ironpython /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Linux/Python - SQL*Server Connexion chain
Gilles Lenfant wrote: Have you guys any good experience on connecting a Python (Zope) app running on Linux to a Windoze SQL*Server ? Yep. I wrote bindings to ODBTP (http://odbtp.sourceforge.net/) using ctypes. It worked really well, good performance and quite reliable. You can see an alpha version at http://benjiyork.com/software.html. I'm not using it any more, but have a more recent version that I really should package up. -- Benji York -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding where to store application data portably
Tony Houghton wrote: This works on Win XP. Not sure if it will work on Linux. import os parent = os.path.split(os.path.abspath(os.sys.argv[0]))[0] file = parent + os.sep + '.bombz' Ooh, no, I don't want saved data to go in the installation directory. In general that practice encourages people to run with Admin access, and it's about time Windows users were discouraged from that. Yes, it occurred to me you didn't want to do that after I posted. Looks like maybe the correct place would be as you suggested, but maybe doing it this way would be better. import os user = os.path.join( os.environ[USERPROFILE], 'Application Data', 'Bombz' ) Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: Question About Logic In Python
Steve Holden [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Which is yet another reason why it makes absolutely no sense to apply arithmetic operations to Boolean values. Except for counting the number of true values. This and other legitimate uses of False/True as 0/1 (indexing, for instance) were explicitly considered as *features* of the current design when it was entered. The design was not merely based on backwards compatibility, but also on actually use cases which Guido did not want to disable. There was lots of discussion on c.l.p. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: How to show percentage
Traditionally, one part of the expression has to be a float for the result to be a float (this is a holdover from C). So 100/3.0 will give you the result you want. Alternatively, you can put from __future__ import division at the top of your script, and then 100/3 will return a float. http://www.python.org/doc/2.2.3/whatsnew/node7.html -- http://mail.python.org/mailman/listinfo/python-list
Re: How to show percentage
You need to convert 1 or 3 to a float. How about: def pct(num, den): return (float(num)/den) * 100 ... pct(1, 3) 33.329 Peace Bill Mill bill.mill at gmail.com On 22 Sep 2005 10:51:43 -0700, Sen-Lung Chen [EMAIL PROTECTED] wrote: Dear All: I have a question of show percentage. For example ,I want to show the percentage of 1/3 = 33.33% I use the 1*100/3 = 33 it is 33 not 33.33 , how to show the 33.33 % Thanks -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list