TaskCoach: first SyncML release candidate
This is a preliminary release for testing purposes. It features synchronization of tasks and notes with a Funambol server, so indirectly with any application supporting SyncML, either natively or through a plugin (Outlook, most recent cell phones, iPods, etc). As the package name hints, this is highly experimental, so please backup your files before trying it. You can download this release from the SourceForge download page: http://sourceforge.net/project/showfiles.php?group_id=130831package_id=183625 What is Task Coach? Task Coach is a simple task manager that allows for hierarchical tasks, i.e. tasks in tasks. Task Coach is open source (GPL) and is developed using Python and wxPython. You can download Task Coach from: http://www.taskcoach.org In addition to the source distribution, packaged distributions are available for Windows XP/Vista, Mac OS X, and Linux (Debian and RPM format). Note that Task Coach is alpha software, meaning that it is wise to backup your task file regularly, and especially when upgrading to a new release. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
[ANN] Release 0.70.3 of Task Coach
Hi, I'm happy to announce release 0.70.3 of Task Coach. This release fixes a few bugs introduced in the previous release. Bugs fixed: * wxPython 2.8.8.1 generates images in a new, backwards incompatible way, even when told not to do that. This bug affects users that have an older version of wxPython installed and use one of the Linux packages. Fixed by adding the relevant pieces from wxPython 2.8.8.1 to the Task Coach sources. * Opening a new task viewer didn't work. * Closing effort viewers causes exceptions. What is Task Coach? Task Coach is a simple task manager that allows for hierarchical tasks, i.e. tasks in tasks. Task Coach is open source (GPL) and is developed using Python and wxPython. You can download Task Coach from: http://www.taskcoach.org In addition to the source distribution, packaged distributions are available for Windows XP/Vista, Mac OS X, and Linux (Debian and RPM format). Note that Task Coach is alpha software, meaning that it is wise to back up your task file regularly, and especially when upgrading to a new release. Cheers, Frank -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Good python equivalent to C goto
On Aug 17, 12:35 am, Michael Torrie [EMAIL PROTECTED] wrote: However it's not necessary in python to do any of this, since you can define nested functions that have access to the parent scope. Anytime you need to clean up, just call the nested cleanup function and then return. That is unnecessary and dangerous in Python. 98% of the time the Python interpreter cleans up what you would have had to clean up by hand in C. The rest of the time you should be using a try...finally block to guarantee cleanup, or a with block to get the interpreter do it for you. Calling a nested function to perform cleanup is prone to omission errors, and it doesn't guarantee that cleanup will happen if an exception is raised. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: how to add property dynamically?
akonsu wrote: hello, i need to add properties to instances dynamically during run time. this is because their names are determined by the database contents. so far i found a way to add methods on demand: class A(object) : def __getattr__(self, name) : if name == 'test' : def f() : return 'test' setattr(self, name, f) return f else : raise AttributeError('%s' object has no attribute '%s' % (self.__class__.__name__, name)) this seems to work and i can invoke method test() on an object. it would be nice to have it as property though. so i tried: class A(object) : def __getattr__(self, name) : if name == 'test' : def f() : return 'test' setattr(self, name, property(f)) return f else : raise AttributeError('%s' object has no attribute '%s' % (self.__class__.__name__, name)) but this does not work, instance.test returns a callable but does not call it. i am not an expert in python, would someone please tell me what i am doing wrong? thanks konstantin Are you sure you can't get by by adding attributes to the instance that hold the values that the property would return? class A(object): def __init__(self, dbvaluedict): self.__dict__.update(dbvaluedict) dbvaluedict = dict('test': 'test') a = A(dbvaluedict) print a.test test If this doesn't help. You might want to start at the beginning and explain what it is you are trying to accomplish. What you are trying to do is very unusual. -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing exceptions in PEP 3107
On Aug 15, 3:42 pm, Christoph Zwerschke [EMAIL PROTECTED] wrote: Carl Banks wrote: IOW, there is currently no recommended way to do *anything* with annotations(**). That is entirely left up to users and third-party packages, and the PEP goes out of its way to disclaim all authority on policy. The following quote from the PEP sums it up well: Following from point 2, this PEP makes no attempt to introduce any kind of standard semantics, even for the built-in types. This work will be left to third-party libraries. That's right, the PEP does not say how the information is to be *interpreted*, but it does say what the information is *about* (e.g. a certain parameter or the return value). No it doesn't. The PEP says what the information's typical use case is, not what purpose it's mandated for. You are free to use it for other things. For example, the following usage is obvious and sensible (insofar as listing exceptions is sensible): def f(x : int) - int, raises(TypeError) Think of the return value annotation as more of a function outcome annotation. The following are all reasonable uses of it: def f() - no_return def g() - modifies_argument def h() - modifies_global_config def j() - raises(StopIteration) The designers of Python could have added syntax speficially to list exceptions, but the fact is, the return value annotation can handle this perfectly well without needing specific syntax. Python does not like to add unnecessary syntax. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Large production environments using ZODB/ZOE?
Phillip B Oldham [EMAIL PROTECTED] writes on Thu, 7 Aug 2008 09:26:04 -0700 (PDT): I've been reading a lot recently on ZODB/ZOE, but I've not seen any reference to its use in large-scale production envrironments. Are there any real-world examples of ZODB/ZOE in use for a large system? By large, I'm thinking in terms of both horizontally-scaled systems and in terms of data storage size. We are using it to host about a hundred domains of the Haufe Mediengruppe, among others www.haufe.de, www.lexware.de and www.redmark.de. Dieter -- http://mail.python.org/mailman/listinfo/python-list
Re: Good python equivalent to C goto
as an oldtimer, I know that in complex code the goto statement is still the easiest to code and understand. I propose this solution using exception. The string exception is deprecated but is simpler for this example. # DeprecationWarning: raising a string exception is deprecated def Goto_is_not_dead(nIn): try: if (nIn == 1): raise 'Goto_Exit' if (nIn == 2): raise 'Goto_Exit' print 'Good Input ' + str(nIn) raise 'Goto_Exit' except 'Goto_Exit': print 'any input ' + str(nIn) if __name__ == '__main__': Goto_is_not_dead(2) Goto_is_not_dead(3) -- http://mail.python.org/mailman/listinfo/python-list
Re: Good python equivalent to C goto
On Sat, 16 Aug 2008 23:20:52 +0200, Kurien Mathew wrote: Any suggestions on a good python equivalent for the following C code: while (loopCondition) { if (condition1) goto next; if (condition2) goto next; if (condition3) goto next; stmt1; stmt2; next: stmt3; stmt4; } (Don't) use the `goto` module: http://entrian.com/goto/ :-) from goto import goto, label # ... while loop_condition: if condition1 or condition2 or condition3: goto .next print 'stmt1' print 'stmt2' label .next print 'stmt3' print 'stmt4' Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
how many nested for can we utilize?
when I use 20 for ,SystemError: too many statically nested blocks When I use 100 for ,IndentationError: too many levels of indentation How to handle these errors? -- http://mail.python.org/mailman/listinfo/python-list
Plot pkg - Multiple Y axes?
Hello, You can make Multiple Y Axes plots in Excel using Multy_Y or EZplot. There is a demo version at www.OfficeExpander.com Cheers! __ Hello, I'm searching for a plotting package that will allow multiple y axes of different scales. For example I'd like to overlay 4 or 5 time series with each series having a separate axis. Does anyone know of such a package? Thank you, Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
Patrol Sun wrote: when I use 20 for ,SystemError: too many statically nested blocks When I use 100 for ,IndentationError: too many levels of indentation How to handle these errors? so why exactly are you trying to nest 20 or 100 for-in loops? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: The Importance of Terminology's Quality
On Sat, 16 Aug 2008 21:46:18 -0400, John W Kennedy wrote: The 1401 was a decent enough processor for many industrial tasks -- at that time -- but for general programming it was sheer horror. But the easiest machine language /ever/. True, very true. M4 -- http://mail.python.org/mailman/listinfo/python-list
Re: The Importance of Terminology's Quality
On Sat, 16 Aug 2008 21:46:18 -0400, John W Kennedy wrote: Martijn Lievaart wrote: On Thu, 14 Aug 2008 18:33:30 -0400, John W Kennedy wrote: Actually, I was thinking of the 1401. But both the 1620 and the 1401 (without the optional Advanced Programming Feature) share the basic omission of any instruction that could do call-and-return without hard-coding an adcon with the address of the point to be returned to. (The Advanced Programming Feature added a 1401 instruction, Store B-address Register, that, executed as the first instruction of a subroutine, could store the return-to address.) Rgh Don't. Bring. Back. Those. Nightmares. Please. The 1401 was a decent enough processor for many industrial tasks -- at that time -- but for general programming it was sheer horror. But the easiest machine language /ever/. What? Even easier than ICL 1900 PLAN or MC68000 assembler? That would be difficult to achieve. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | -- http://mail.python.org/mailman/listinfo/python-list
Re: QT, ctypes dll and SEG Faults
Hi, If the crash occurs in __init__, why do you give us more code ? The crash can occur because you pass a char* to your library. This char* is not managed by your library but by Python. This means that when the constructor is finished, the string is freed and the char* is not valid anymore. This is perhaps what is causing your error. I can't say more because your code sample is too long and not well explained (what is happening and what should happen ?) Matthieu 2008/8/17 sapsi [EMAIL PROTECTED]: On Aug 16, 11:37 pm, sapsi [EMAIL PROTECTED] wrote: Hello, Below is a small class using ctypes and libspectre to read a postscript file. My program is a PyQT 4.4 application and when the user clicks on a entry in a QTableWidget, i run PostScriptImage( filename_as_contained_in_clicked_tableWidgetItem ) However on i get a segfault while trying document_load. Surprisingly, before i run sys.exit(app.exec_()) (i.e before the app starts) if run PostScriptImage(command_line_specified_ps_file) it works! I know the ctypes so file works with QT since i wrote an application using it, but i hadn't separated the ctypes stuff into separate class (i.e the spectre code was in the widget method). Any ideas why the crash? Regards Saptarshi --Python Code-- class PostScriptImage: def __init__(self,filename): print Doc New self.document=libspec.spectre_document_new() print Load Doc , filename #crashed in the following line# libspec.spectre_document_load(self.document,filename) print Done load doc if libspec.spectre_document_status(self.document): return False self.scale=[1.0,1.0] self.quicksetup() def quicksetup(self): print RC rc=libspec.spectre_render_context_new() print Get 0th Page page=libspec.spectre_document_get_page (self.document, 0) if libspec.spectre_document_status(self.document): raise Exception(Spectre:Setup Document Error) w= c_int() h= c_int() print Page Size libspec.spectre_page_get_size(page, byref(w),byref(h)) self.initialSize=(h.value*1.0,w.value*1.0) self.initialAspect=float(h.value)/float(w.value) self.npages=libspec.spectre_document_get_n_pages(self.document) To answer my own question, partially, i found out if i replace filename with a hard coded value it doesn't crash. Now why is that? Does python lose the reference? Should i store filename as attributed of the object? Regards Saptarshi -- http://mail.python.org/mailman/listinfo/python-list -- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher -- http://mail.python.org/mailman/listinfo/python-list
Re: QT, ctypes dll and SEG Faults
On Sat, 16 Aug 2008 21:17:25 -0700 (PDT), sapsi wrote: Below is a small class using ctypes and libspectre to read a postscript file. My program is a PyQT 4.4 application �and when the user clicks on a entry in a QTableWidget, i run PostScriptImage( filename_as_contained_in_clicked_tableWidgetItem ) However on i get a segfault while trying document_load. Surprisingly, before i run sys.exit(app.exec_()) (i.e before the app starts) if run PostScriptImage(command_line_specified_ps_file) it works! To answer my own question, partially, i found out if i replace filename with a hard coded value it doesn't crash. Now why is that? Does python lose the reference? Should i store filename as attributed of the object? Are you sure that the hardcoded value is _exactly_ the same as the one passed to __init__? Try it in __init__ to make sure: assert filename == 'your_hardcoded_value' And why won't you try to store the filename as an attribute? (even though I doubt it could help). -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list
Re: how to add property dynamically?
akonsu a écrit : hello, i need to add properties to instances dynamically during run time. this is because their names are determined by the database contents. so far i found a way to add methods on demand: class A(object) : def __getattr__(self, name) : if name == 'test' : def f() : return 'test' setattr(self, name, f) return f else : raise AttributeError('%s' object has no attribute '%s' % (self.__class__.__name__, name)) this seems to work and i can invoke method test() on an object. Nope. This adds per-instance *function* attributes - not *methods*. class A(object) : def __getattr__(self, name) : if name == 'test' : def f(self) : return %s.test % self setattr(self, name, f) return f else : raise AttributeError( '%s' object has no attribute '%s' \ % (self.__class__.__name__, name) ) a = A() a.test() = Traceback (most recent call last): File stdin, line 1, in module TypeError: f() takes exactly 1 argument (0 given) To add methods on a per-instance basis, you have to manually invoke the descriptor protocol's implementation of function objects: class A(object) : def __getattr__(self, name) : if name == 'test' : def f(self) : return %s.test % self m = f.__get__(self, type(self)) setattr(self, name, m) return m else : raise AttributeError( '%s' object has no attribute '%s' \ % (self.__class__.__name__, name) ) it would be nice to have it as property though. so i tried: class A(object) : def __getattr__(self, name) : if name == 'test' : def f() : return 'test' setattr(self, name, property(f)) return f else : raise AttributeError('%s' object has no attribute '%s' % (self.__class__.__name__, name)) but this does not work, instance.test returns a callable but does not call it. Properties must be class attributes. The only way (the only way I know) to get them to work as instance-attributes is to overload __getattribute__, which is tricky and may have pretty bad impact on lookup perfs - and ruins the whole point of using properties FWIW. i am not an expert in python, would someone please tell me what i am doing wrong? Wrong solution to your problem, I'd say. Let's start again: i need to add properties to instances dynamically during run time. this is because their names are determined by the database contents. Care to elaborate ? I may be wrong, but I suspect you're trying to roll your own python/database mapper. If so, there are quite a couple Python ORMs around. Else, please tell us more. -- http://mail.python.org/mailman/listinfo/python-list
adding properties dynamically (how to?)
I didn't want to hijack the original thread but I have basically the same request... On Aug 17, 7:09 am, Bruno Desthuilliers [EMAIL PROTECTED] wrote: akonsu a écrit : hello, [SNIP] Wrong solution to your problem, I'd say. Let's start again: i need to add properties to instances dynamically during run time. this is because their names are determined by the database contents. Care to elaborate ? I may be wrong, but I suspect you're trying to roll your own python/database mapper. If so, there are quite a couple Python ORMs around. Else, please tell us more. I'm not the original poster, but I'd like to do the same thing (for a different reason). I have a program (crunchy) that is extensible via plugins. New options available via plugins can be turned on or off (or selected among a list of options). I have a module for user preferences (let's call it prefs.py) that allows the setting of these options (and do error checking, automatic saving of the options selected for future sessions, etc.). These options are implemented as properties. Currently I have it simplified so that only two lines need to be added to prefs.py to add new options; something like options = { ... 'new_option': [value1, value2, ..., valueN], ...} and class Preferences(object): ... new_option = make_property('new_option', 'some nicely worded help string') === make_property is a custom define function that return fgets, fsets, fdel and doc. Ideally, I'd like to be able to define new would-be properties from the plugin and add them to the class prior to creating instances. In other words, have something like === for option in options_defined_in_plugins: add_option_as_property_to_Preferences(Preferences, option, ...) user_preferences = Preferences() Performance in this case would not be an issue. Cheers, André -- http://mail.python.org/mailman/listinfo/python-list
Re: adding properties dynamically (how to?)
André a écrit : I didn't want to hijack the original thread but I have basically the same request... On Aug 17, 7:09 am, Bruno Desthuilliers [EMAIL PROTECTED] wrote: akonsu a écrit : hello, [SNIP] Wrong solution to your problem, I'd say. Let's start again: i need to add properties to instances dynamically during run time. this is because their names are determined by the database contents. Care to elaborate ? I may be wrong, but I suspect you're trying to roll your own python/database mapper. If so, there are quite a couple Python ORMs around. Else, please tell us more. I'm not the original poster, but I'd like to do the same thing (for a different reason). I have a program (crunchy) that is extensible via plugins. New options available via plugins can be turned on or off (or selected among a list of options). I have a module for user preferences (let's call it prefs.py) that allows the setting of these options (and do error checking, automatic saving of the options selected for future sessions, etc.). These options are implemented as properties. Currently I have it simplified so that only two lines need to be added to prefs.py to add new options; something like options = { ... 'new_option': [value1, value2, ..., valueN], ...} and class Preferences(object): ... new_option = make_property('new_option', 'some nicely worded help string') === make_property is a custom define function that return fgets, fsets, fdel and doc. You may want to write your own descriptor object instead. The 'property' class is just one possible way to use the descriptor protocol for smart attributes. Ideally, I'd like to be able to define new would-be properties from the plugin and add them to the class prior to creating instances. In other words, have something like === for option in options_defined_in_plugins: add_option_as_property_to_Preferences(Preferences, option, ...) user_preferences = Preferences() Not the same problem as the OP here. Your properties are not per-instance, so just adding them to the class is ok. Remember that in Python, classes are objects too, and (a couple corner cases set aside) nothing prevent you from dynamically adding attributes to an object. The following snippets are equivalent: class Foo1(object): attrib = object() class Foo2(object): pass Foo2.attrib = object() class Foo3(object): pass setattr(Foo3, 'attrib', object()) -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing exceptions in PEP 3107
Carl Banks schrieb: You are free to use it for other things. For example, the following usage is obvious and sensible (insofar as listing exceptions is sensible): def f(x : int) - int, raises(TypeError) Think of the return value annotation as more of a function outcome annotation. That's fine, but then this should be mentioned in the PEP3107. Instead it says explicitly that the - syntax is for the type of a function's return value. If it's intended to be used in a more general way like you suggested, then the wording used in the PEP is misleading. (The wording *the* type is problematic anyway, since a Python function can return different types in different situations.) It's still unclear for me whether annotations on thrown exceptions are included in PEP3107 (as per your suggestion), or are not covered by PEP3107 at all (as Duncan suggests), or whether this question has just not yet been settled. -- Christoph -- http://mail.python.org/mailman/listinfo/python-list
Vmware api
Hi List, Has anyone here played around with getting python to talk to the vmware api's. I have had a quick look at vmware's api and there is no out of the box python packages, but I believe that there might be some third party wrappers around? If anyone has any info that would be great. Thanks Regards, Luke Hamilton Solutions Architect RPM Solutions Pty Ltd Mobile: 0430 223 558 [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Python process communication
Hi, I'd like to write a script that will connect to another already running process, pipe some data to it's input and receive data from it's output. I can create another process using subprocess module, but how do I connect to already running process? Maybe there is a better solution for process communication? I've searched in the net and found nothing, so I've decided to post my problem here, hopefully someone will help me. Thanks in advance Marek Aaron Sapota -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing exceptions in PEP 3107
Terry Reedy wrote: I would agree... but... The problem is that code that uses a function hardly cares whether an exception that replaces the normal return is raised explicitly, by a syntax operation (and these are not yet completely documented, though perhaps they should be), or by a function called within the function. I often read that argument that info on thrown exceptions does not matter in Python, but I beg to differ. Just as a simple and well-known example, it is absolutely important to know that the str.index() method throws a ValueError if nothing is found, while the str.find() method should never throw a ValueError. -- Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: Good python equivalent to C goto
On 2008-08-16, Dennis Lee Bieber [EMAIL PROTECTED] wrote: On Sat, 16 Aug 2008 23:20:52 +0200, Kurien Mathew [EMAIL PROTECTED] declaimed the following in comp.lang.python: Hello, Any suggestions on a good python equivalent for the following C code: while (loopCondition) { if (condition1) goto next; if (condition2) goto next; if (condition3) goto next; stmt1; stmt2; next: stmt3; stmt4; } Nasty code even for C... I've never used goto in C... I do sometimes, but it's for exception handling, and in Python one uses try/raise/except. The example above isn't the best way to show this, but perhaps something like the code below while loopCondition: try: if condition 1: raise MyException if condition 2: raise MyException if condition 3: raise MyException stmt1; stmt2; stmt3; except: MyException pass stmt4; stmt5; -- Grant Edwards grante Yow! People humiliating at a salami! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Windows / Tkinter - problem with grid - not able to place widgets at desired places
Hi, I'm learning Python and Tkinter. I've started programming in Eclipse with PyDev. I'm intending to create a GUI. I'm not able to understand the Grid manager perhaps because there is quite a less documentation available for it on the net. My desired GUI is attached in the mail. Although I've tried writing a class module for this GUI but I'm not able to set all things right in the GUI. The Biggest problem seems to be with the Grid Manager in terms how it divides a window in Rows / columns. etc. I'm not able to place none of the widgets correctly in the GUI. For your convenience, I'm attaching this code also as myModule1.py . Please some one review it and help create me this GUI. PS: The desired GUI is attached as a GIF file. The version v1.4.5.1 is a label the contents of which are dynamically picked. Thanks and regards, Rajat attachment: Desired GUI.GIF#Filename:myModule1 #Description: Creates the basic Tkinter programs #Author: Rajat Dudeja #Date:16.08.2008 from Tkinter import * #GUI class class myAppGUI: def __init__(self, master): #Start Test Button self.bStartTest = Button( master, \ text = Start Test, \ command = self.hStartTest, \ ) self.bStartTest.config( justify = CENTER, \ padx = 20, \ width = 10, #pady= 5, \ relief = RAISED ) self.bStartTest.grid( row = 10, \ column = 2, \ columnspan = 1, \ sticky = EW) #Commit Results Button self.bCommitResults = Button( master, \ text = Commit Results, \ command = self.hCommitResults \ ) self.bCommitResults.config( justify = CENTER, \ padx = 20, \ #pady= 5, \ width = 10, \ relief = RAISED ) self.bCommitResults.grid( row = 10, \ column = 5, \ columnspan = 1, \ sticky = EW) #Exit Button self.bExit = Button( master, \ text = Exit, \ command = master.quit ) self.bExit.config( justify = CENTER, \ padx = 20, \ width= 10, \ relief = RAISED, \ ) self.bExit.grid( row = 10, \ column = 8, \ columnspan = 1, \ sticky = EW) #Labels and Drop down menus #Label 1 self.lAnalysisLib = Label( master, \ text = Analysis Library:, \ justify = RIGHT) self.lAnalysisLib.grid(row = 0) #Label 2 self.lRefAnalysisLibVer = Label( master, \ text = Reference Analysis Libary Version:, \ justify = LEFT) self.lRefAnalysisLibVer.config( wraplength = 100 ) self.lRefAnalysisLibVer.grid(row = 5) def hStartTest(self): print 'Starting Test...' def hCommitResults(self): print 'Commiting to SVN...' #End of myAppGUI Class # Main Program myRoot = Tk() myRoot.title(Test Automation) myRoot.minsize(800, 400) myAppGUIObject = myAppGUI(myRoot) myRoot.mainloop()-- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 A good quote I read (I can't remember who it was from, though) is If you need more than three levels of indentation, then something is seriously wrong with your code. Possibly Guido himself? Anyway. If you've got 100 levels of for, you're probably making things way harder than they need to be. Fredrik Lundh wrote: Patrol Sun wrote: when I use 20 for ,SystemError: too many statically nested blocks When I use 100 for ,IndentationError: too many levels of indentation How to handle these errors? so why exactly are you trying to nest 20 or 100 for-in loops? /F -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkioM70ACgkQLMI5fndAv9jBhgCeM5hjNaAtlDosJq1DSZyPnBcL 7NYAoKKwnSdR20YDGXvjpAP8KUWfw/rl =PajF -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
Nick Dumas wrote: A good quote I read (I can't remember who it was from, though) is If you need more than three levels of indentation, then something is seriously wrong with your code. Possibly Guido himself? Anyway. If you've got 100 levels of for, you're probably making things way harder than they need to be. assuming 100 levels of for and 2 items in each sequence, you'll end up with 1267650600228229401496703205376 iterations through the inner loop. assuming each iteration takes a picosecond, it'll take approx 40 billion years to run the program. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
On Sun, 17 Aug 2008 16:39:26 +0200, Fredrik Lundh wrote: A good quote I read (I can't remember who it was from, though) is If you need more than three levels of indentation, then something is seriously wrong with your code. Possibly Guido himself? Anyway. If you've got 100 levels of for, you're probably making things way harder than they need to be. assuming 100 levels of for and 2 items in each sequence, you'll end up with 1267650600228229401496703205376 iterations through the inner loop. assuming each iteration takes a picosecond, it'll take approx 40 billion years to run the program. I guess that's exactly why the OP asks the question. He just wants to start as soon as possible ;-) -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list
Boost reference container problem( std::vectorAClass*)
Hello, I am wrapping the reference container vector as document suggests. typedef std::vectorCUEEntity* EntityContainer; class_CUEEntity(Entity, initCUEEntity*()); class_EntityContainer(EntityContainer) .def(vector_indexing_suiteEntityContainer, true() ) ; When I try to iterate in python all I get is the following error: TypeError: No to_python (by-value) converter found for C++ type: class CUEEntity * As you can see CUEEntity is wrapped propery, and I am aable to access and use that class without problems, I can not find the information on adding return policies to wrapped container classes. I will appreciate if you can point me solution or a sample. regards -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
Wojtek Walczak wrote: it'll take approx 40 billion years to run the program. I guess that's exactly why the OP asks the question. He just wants to start as soon as possible ;-) required reading: The Effects of Moore's Law and Slacking on Large Computations http://arxiv.org/abs/astro-ph/9912202 /F -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
On 17 Aug, 17:17, Fredrik Lundh [EMAIL PROTECTED] wrote: required reading: The Effects of Moore's Law and Slacking on Large Computations http://arxiv.org/abs/astro-ph/9912202 Or maybe this...? http://docs.python.org/tut/node6.html#SECTION00660 And this: http://www.freenetpages.co.uk/hp/alan.gauld/tutrecur.htm Paul -- http://mail.python.org/mailman/listinfo/python-list
python-mode errors
When I start python mode I get the error: idle error: #buffer easygui.py -Wrong number of arguments : #subr set-match-data 2 The Python mode version is 4.78 Is this a known problem? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib getting SSL certificate info
Fredrik Lundh wrote: Ghirai wrote: Using urllib, is there any way i could access some info about the SSL certificate (when opening a https url)? I'm really interested in the fingerprint. I haven't been able to find anything so far. you can get some info via (undocumented?) attributes on the file handle: import urllib f = urllib.urlopen(https://mail.google.com/;) f.fp httplib.SSLFile instance at 0x00CE2508 ['issuer', 'read', 'server', 'write'] f.fp._ssl.issuer() '/C=ZA/O=Thawte Consulting (Pty) Ltd./CN=Thawte SGC CA' f.fp._ssl.server() '/C=US/ST=California/L=Mountain View/O=Google Inc/CN=mail.google.com' /F If you really need details from the SSL cert, you usually have to use M2Crypto. The base SSL package doesn't actually do much with certificates. It doesn't validate the certificate chain. And those strings of attributes you can get are ambiguious; data fields may contain unescaped /, which is the field separator. I went through this last year and had to use M2Crypto, which is something of a headache but more or less works. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
On Sun, 17 Aug 2008 17:17:06 +0200, Fredrik Lundh wrote: it'll take approx 40 billion years to run the program. I guess that's exactly why the OP asks the question. He just wants to start as soon as possible ;-) required reading: The Effects of Moore's Law and Slacking on Large Computations http://arxiv.org/abs/astro-ph/9912202 Kinda buddhist approach. Anyway, it might work out, unless the number of for loops is increasing in time and in 18 months it may be - let's say - 20 nested for loops more ;) Got to ask the OP. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
Paul Boddie wrote: required reading: The Effects of Moore's Law and Slacking on Large Computations http://arxiv.org/abs/astro-ph/9912202 Or maybe this...? http://docs.python.org/tut/node6.html#SECTION00660 and functions will solve the 40-billion year computation problem exactly how? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Vmware api
Hi! Luke, You can use the vmrun command for interacting with VMware Workstation/Fusion. You can do something like import os os.system('vmrun start .vmxFile') os.system('vmrun stop .vmxFile') If you can be more specific about your needs, I may be able to help you further. Thanks, Raj On Sun, Aug 17, 2008 at 6:19 AM, Luke Hamilton [EMAIL PROTECTED] wrote: Hi List, Has anyone here played around with getting python to talk to the vmware api's. I have had a quick look at vmware's api and there is no out of the box python packages, but I believe that there might be some third party wrappers around? If anyone has any info that would be great. Thanks Regards, Luke Hamilton Solutions Architect RPM Solutions Pty Ltd Mobile: 0430 223 558 [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list -- For him who has conquered the mind, the mind is the best of friends; but for one who has failed to do so, his very mind will be the greatest enemy. Rajanikanth -- http://mail.python.org/mailman/listinfo/python-list
how to call API Functions in python
how to call API Functions in python -- http://mail.python.org/mailman/listinfo/python-list
Re: how to call API Functions in python
raashid bhatt wrote: how to call API Functions in python The same way as you'd call any other function, of course. What API are you referring to? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Good python equivalent to C goto
Kurien Mathew wrote: Hello, Any suggestions on a good python equivalent for the following C code: while (loopCondition) { if (condition1) goto next; if (condition2) goto next; if (condition3) goto next; stmt1; stmt2; next: stmt3; stmt4; } Thanks Kurien -- http://mail.python.org/mailman/listinfo/python-list I would not be too happy if I saw C code like that in my repository. This is equivalent: while (loopCondition) { if (!(condition1 || condition2 || condition3)) { stmt1; stmt2; } stmt3; stmt4; } In Python: while (loopCondition): if not (condition1 or condition2 or condition3): stmt1 stmt2 stmt3 stmt4 If stmt3 and stmt4 are error cleanup code, I would use try/finally. while loopCondition: try: if condition1: raise Error1() if condition2: raise Error2() if condition3: raise Error3() stmt1 stmt2 finally: stmt3 stmt4 This will also bail out of the loop on and exception and the exception will get to the next level. If you don't want that to happen, put an appropriate except block before the finally. -Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Good python equivalent to C goto
On Aug 17, 8:09 pm, Matthew Fitzgibbons [EMAIL PROTECTED] wrote: Kurien Mathew wrote: Hello, Any suggestions on a good python equivalent for the following C code: while (loopCondition) { if (condition1) goto next; if (condition2) goto next; if (condition3) goto next; stmt1; stmt2; next: stmt3; stmt4; } Thanks Kurien -- http://mail.python.org/mailman/listinfo/python-list I would not be too happy if I saw C code like that in my repository. This is equivalent: while (loopCondition) { if (!(condition1 || condition2 || condition3)) { stmt1; stmt2; } stmt3; stmt4; } In Python: while (loopCondition): if not (condition1 or condition2 or condition3): stmt1 stmt2 stmt3 stmt4 If stmt3 and stmt4 are error cleanup code, I would use try/finally. while loopCondition: try: if condition1: raise Error1() if condition2: raise Error2() if condition3: raise Error3() stmt1 stmt2 finally: stmt3 stmt4 This will also bail out of the loop on and exception and the exception will get to the next level. If you don't want that to happen, put an appropriate except block before the finally. -Matt- Hide quoted text - - Show quoted text - class Goto_Target(Exception): pass def Goto_is_not_dead(nIn): try: if (nIn == 1): raise Goto_Target if (nIn == 2): raise Goto_Target inv = 1.0 / nIn print 'Good Input ' + str(nIn) + ' inv=' + str(inv) except Goto_Target: pass except Exception, e: print 'Error Input ' + str(nIn) + ' ' + str(e) finally: print 'any input ' + str(nIn) if __name__ == '__main__': Goto_is_not_dead(0) Goto_is_not_dead(2) Goto_is_not_dead(3) -- http://mail.python.org/mailman/listinfo/python-list
like a for loop for a string
Okay, so lets say you have a list: funList = [1,2,3,4,5] and you do: for x in funList: print x this will print 1-5 But I am wondering is there a way to something like this: funString = string string string non-string non-string string and for string in funString: print something I know you can't do that; but, is there a way do do something similar that gets the same result? -- View this message in context: http://www.nabble.com/like-a-%22for-loop%22-for-a-string-tp19022098p19022098.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to call API Functions in python
On Aug 17, 11:08 am, Fredrik Lundh [EMAIL PROTECTED] wrote: raashid bhatt wrote: how to call API Functions in python The same way as you'd call any other function, of course. What API are you referring to? /F i am talking about WINAPI -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Alexnb wrote: But I am wondering is there a way to something like this: funString = string string string non-string non-string string and for string in funString: print something I know you can't do that; but, is there a way do do something similar that gets the same result? you seem to have forgotten to specify the result. or did you mean that the above should print 1-5? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: how to call API Functions in python
On Sun, 17 Aug 2008 11:22:52 -0700 (PDT), raashid bhatt wrote: how to call API Functions in python The same way as you'd call any other function, of course. �What API are you referring to? i am talking about WINAPI I am not a Windows guy, but maybe ctypes module will be helpful for you. -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Alexnb wrote: Okay, so lets say you have a list: funList = [1,2,3,4,5] and you do: for x in funList: print x this will print 1-5 But I am wondering is there a way to something like this: funString = string string string non-string non-string string and for string in funString: print something I know you can't do that; but, is there a way do do something similar that gets the same result? Your funString has six elements, funList has five. How do you want the result to appear on the page? It is possible that the % operator could help you. Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
On 17 Aug, 19:36, Fredrik Lundh [EMAIL PROTECTED] wrote: and functions will solve the 40-billion year computation problem exactly how? I was thinking more about the need to nest for statements to a depth of 20 levels, which I imagine only arises on a just in case basis for the inquirer. In other words, the inquirer may have input that could theoretically demand twenty levels of state, each level provided by a single for statement, but in practice they might only need to manage a few levels of state. In any case, we're potentially seeing the use of the wrong tool for the job, and I am speculating that functions would be the right tool, but unless the inquirer is willing to show the code (which I haven't seen in this thread yet), it's hard to speculate further. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Ya just an example, to print the numbers 1-5 Fredrik Lundh wrote: Alexnb wrote: But I am wondering is there a way to something like this: funString = string string string non-string non-string string and for string in funString: print something I know you can't do that; but, is there a way do do something similar that gets the same result? you seem to have forgotten to specify the result. or did you mean that the above should print 1-5? /F -- http://mail.python.org/mailman/listinfo/python-list -- View this message in context: http://www.nabble.com/like-a-%22for-loop%22-for-a-string-tp19022098p19022155.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
On Sun, 17 Aug 2008 11:22:37 -0700 (PDT), Alexnb wrote: funString = string string string non-string non-string string and for string in funString: print something I know you can't do that; but, is there a way do do something similar that gets the same result? What's that? Do you mean _this_: somestr = string1 string2 string3 for i in somestr.split(): ...print i ... string1 string2 string3 ? -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list
Re: how to call API Functions in python
raashid bhatt wrote: The same way as you'd call any other function, of course. What API are you referring to? i am talking about WINAPI use pywin32 or ctypes: http://wiki.python.org/moin/PyWin32 http://docs.python.org/lib/module-ctypes.html for some kinds of Windows programming, IronPython might be an even better choice: http://www.codeplex.com/IronPython /F -- http://mail.python.org/mailman/listinfo/python-list
Re: how to call API Functions in python
On Aug 17, 11:27 am, Wojtek Walczak [EMAIL PROTECTED] wrote: On Sun, 17 Aug 2008 11:22:52 -0700 (PDT), raashid bhatt wrote: how to call API Functions in python The same way as you'd call any other function, of course. What API are you referring to? i am talking about WINAPI I am not a Windows guy, but maybe ctypes module will be helpful for you. -- Regards, Wojtek Walczak,http://www.stud.umk.pl/~wojtekwa/ Thanks a lot man That is what i wanted to know -- http://mail.python.org/mailman/listinfo/python-list
Re: Vmware api
I would also be interested in anything anyone can offer. I spend some time looking around, and took a fair stab at using the wsdl2py that comes with The ZSI package. Ultimately I couldn't get anything to work, and reverted to using perl (yuk). I'm interested mostly in interrogating the ESX servers to get configuration and performance data, from external hosts. Thanks! Eric -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Wojtek Walczak: somestr = string1 string2 string3 for i in somestr.split(): ...print i ... string1 string2 string3 I'm waiting for a str.xsplit still :-) If I write and submit a C implementation of xsplit how many chances do I have to see it included into Python? :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
So what exactly does that do? Returns a generator, instead of a list? I'm waiting for a str.xsplit still :-) If I write and submit a C implementation of xsplit how many chances do I have to see it included into Python? :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
Nick Dumas schreef: A good quote I read (I can't remember who it was from, though) is If you need more than three levels of indentation, then something is seriously wrong with your code. Possibly Guido himself? Linus Torvalds in the Linux kernel coding style document: [...] The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program. (http://lxr.linux.no/linux/Documentation/CodingStyle) -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: Good python equivalent to C goto
[EMAIL PROTECTED] wrote: On Aug 17, 8:09 pm, Matthew Fitzgibbons [EMAIL PROTECTED] wrote: Kurien Mathew wrote: Hello, Any suggestions on a good python equivalent for the following C code: while (loopCondition) { if (condition1) goto next; if (condition2) goto next; if (condition3) goto next; stmt1; stmt2; next: stmt3; stmt4; } Thanks Kurien -- http://mail.python.org/mailman/listinfo/python-list I would not be too happy if I saw C code like that in my repository. This is equivalent: while (loopCondition) { if (!(condition1 || condition2 || condition3)) { stmt1; stmt2; } stmt3; stmt4; } In Python: while (loopCondition): if not (condition1 or condition2 or condition3): stmt1 stmt2 stmt3 stmt4 If stmt3 and stmt4 are error cleanup code, I would use try/finally. while loopCondition: try: if condition1: raise Error1() if condition2: raise Error2() if condition3: raise Error3() stmt1 stmt2 finally: stmt3 stmt4 This will also bail out of the loop on and exception and the exception will get to the next level. If you don't want that to happen, put an appropriate except block before the finally. -Matt- Hide quoted text - - Show quoted text - class Goto_Target(Exception): pass def Goto_is_not_dead(nIn): try: if (nIn == 1): raise Goto_Target if (nIn == 2): raise Goto_Target inv = 1.0 / nIn print 'Good Input ' + str(nIn) + ' inv=' + str(inv) except Goto_Target: pass except Exception, e: print 'Error Input ' + str(nIn) + ' ' + str(e) finally: print 'any input ' + str(nIn) if __name__ == '__main__': Goto_is_not_dead(0) Goto_is_not_dead(2) Goto_is_not_dead(3) -- http://mail.python.org/mailman/listinfo/python-list I think this is needlessly ugly. You can accomplish the same with a simple if-else. In this case you're also masking exceptions other than Goto_Target, which makes debugging _really_ difficult. If you need to have the cleanup code executed on _any_ exception, you can still use try-finally without any except blocks. Your code is equivalent to this: def goto_is_dead(n): try: if n == 0 or n == 1 or n == 2: # if you're validating input, validate the input print Error Input %s % n else: print Good Input %s inv= %s % (n, (1. / n)) finally: print any input %s % n if __name__ == '__main__': goto_id_dead(0) goto_id_dead(2) goto_id_dead(3) More concise, readable, and maintainable. -Matt -- http://mail.python.org/mailman/listinfo/python-list
dynamic attribute syntax
Hi all, Thinking of a syntax for 'getattr' and 'setattr' dynamic access. 'obj.prop' has an easy access, but att= 'prop' getattr( obj, att ) is much clumsier, while no less useful, maybe more. What are the changes, pros and cons, involved in something like: obj:att for a dynamic access, and obj.att for static? Snice readability is a factor, I'm open to other markings than ':'. '$' and '?' are available, and I note that a~b, a:b, and, a!b for identifiers 'a' and 'b' are unambiguous. -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Alexnb wrote: Ya just an example, to print the numbers 1-5 Sorry, I still don't have the slightest idea what you expect the code to do. /F But I am wondering is there a way to something like this: funString = string string string non-string non-string string and for string in funString: print something I know you can't do that; but, is there a way do do something similar that gets the same result? you seem to have forgotten to specify the result. or did you mean that the above should print 1-5? -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Basically I want the code to be able to pick out how many strings there are and then do something with each, or the number. When I say string I mean how many strings are in the string string string string non-string string Does that help? Fredrik Lundh wrote: Alexnb wrote: Ya just an example, to print the numbers 1-5 Sorry, I still don't have the slightest idea what you expect the code to do. /F But I am wondering is there a way to something like this: funString = string string string non-string non-string string and for string in funString: print something I know you can't do that; but, is there a way do do something similar that gets the same result? you seem to have forgotten to specify the result. or did you mean that the above should print 1-5? -- http://mail.python.org/mailman/listinfo/python-list -- View this message in context: http://www.nabble.com/like-a-%22for-loop%22-for-a-string-tp19022098p19022694.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Eric Wertman: So what exactly does that do? Returns a generator, instead of a list? Allows you to iterate on the parts in a lazy way, without creating the whole list of the pieces. The arguments are the same of str.split(). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: dynamic attribute syntax
On 17 Aug, 21:29, castironpi [EMAIL PROTECTED] wrote: What are the changes, pros and cons, involved in something like: obj:att for a dynamic access, and obj.att for static? A previous proposal and discussion can be found here: http://www.python.org/dev/peps/pep-0363/ Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Alexnb wrote: Basically I want the code to be able to pick out how many strings there are and then do something with each, or the number. When I say string I mean how many strings are in the string string string string non-string string Does that help? not really, since you haven't defined what string and non-string are or how strings are separated from each other, and, for some odd reason, refuse to provide an actual example that includes both a proper sample string *and* the output you'd expect. please don't use the mailing list to play 20 questions. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
On 2008-08-17, Alexnb [EMAIL PROTECTED] wroted: Basically I want the code to be able to pick out how many strings What do you mean by string? foo = abc abc cde abc ijk abc cde abc foo is one string. If you want substrings, specify what kind of substrings you mean. All occurences of abc, for example. there are and then do something with each, or the number. When I say string I mean how many strings are in the string string string string non-string string Do you mean something like count and return all occurences of the substring 'abc' in foo? Looks like you should use the re module. GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl -- http://mail.python.org/mailman/listinfo/python-list
Re: Good python equivalent to C goto
On Aug 16, 11:20 pm, Kurien Mathew [EMAIL PROTECTED] wrote: Hello, Any suggestions on a good python equivalent for the following C code: while (loopCondition) { if (condition1) goto next; if (condition2) goto next; if (condition3) goto next; stmt1; stmt2; next: stmt3; stmt4; } Extract complex test as a function. Assuming conditions 1, 2 and 3 are difficult enough not to put them all one one line, put them in a function which describes what they're testing. def should_do_12(args): if condition1: return False if condition2: return False if condition3: return False return True while loop_condition: if should_do_12(args): stmt1 stmt2 stmt3 stmt4 This is probably the right way to write it in C too. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
2008/8/17 Alexnb [EMAIL PROTECTED] Basically I want the code to be able to pick out how many strings there are and then do something with each, or the number. When I say string I mean how many strings are in the string string string string non-string string Does that help? Not quite sure, if i underestand the task you want to achieve correctly, but do you maybe mean something like the following? (here under string the exact wording string is meant; obviously any section of the input string will be a string too) fun_string = string string string non-string non-string string fun_words = fun_string.split() fun_words ['string', 'string', 'string', 'non-string', 'non-string', 'string'] strings_from_fun_words = [word for word in fun_words if word == string] strings_from_fun_words ['string', 'string', 'string', 'string'] len(fun_words) 6 len(strings_from_fun_words) 4 HTH Vlasta -- http://mail.python.org/mailman/listinfo/python-list
Re: dynamic attribute syntax
On Aug 17, 2:46 pm, Paul Boddie [EMAIL PROTECTED] wrote: On 17 Aug, 21:29, castironpi [EMAIL PROTECTED] wrote: What are the changes, pros and cons, involved in something like: obj:att for a dynamic access, and obj.att for static? A previous proposal and discussion can be found here: http://www.python.org/dev/peps/pep-0363/ Paul Thanks for the reference. Well, check out the two alternatives, a~b and a!b, which are easy on the eyes, and weren't proposed, but don't allow expressions. (Turns out 'if a:b' is valid, so never mind that one.) I also won't let you forget that $ and ? are unused so far too. I see syntax was one of the complaints. -- http://mail.python.org/mailman/listinfo/python-list
Re: dynamic attribute syntax
castironpi wrote: 'obj.prop' has an easy access, but att= 'prop' getattr( obj, att ) is much clumsier, while no less useful, maybe more. maybe more? ok, you *are* utterly and completely unable to post anything that makes any sense at all to anyone that uses Python. plonkeliplonk. -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Uhm, string and non-string are just that, words within the string. Here shall I dumb it down for you? string = yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8 It doesn't matter what is in the string, I want to be able to know exactly how many yes's there are. I also want to know what is after each, regardless of length. So, I want to be able to get text1, but not text4 because it is after no and I want all of text5+more Text because it is after yes. It is like the yeses are bullet points and I want all the info after them. However, all in one string. Fredrik Lundh wrote: Alexnb wrote: Basically I want the code to be able to pick out how many strings there are and then do something with each, or the number. When I say string I mean how many strings are in the string string string string non-string string Does that help? not really, since you haven't defined what string and non-string are or how strings are separated from each other, and, for some odd reason, refuse to provide an actual example that includes both a proper sample string *and* the output you'd expect. please don't use the mailing list to play 20 questions. /F -- http://mail.python.org/mailman/listinfo/python-list -- View this message in context: http://www.nabble.com/like-a-%22for-loop%22-for-a-string-tp19022098p19022976.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: dynamic attribute syntax
On Aug 17, 3:05 pm, Fredrik Lundh [EMAIL PROTECTED] wrote: castironpi wrote: 'obj.prop' has an easy access, but att= 'prop' getattr( obj, att ) is much clumsier, while no less useful, maybe more. maybe more? ok, you *are* utterly and completely unable to post anything that makes any sense at all to anyone that uses Python. plonkeliplonk. More constructive contributions on both sides there. Good one. -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
On 17 Aug, 20:22, Alexnb [EMAIL PROTECTED] wrote: But I am wondering is there a way to something like this: funString = string string string non-string non-string string and for string in funString: print something I know you can't do that; but, is there a way do do something similar that gets the same result? Perhaps this... for s in funString.split(): if s == string: print something Assuming that you want to iterate over the separate words in funString (for which you need to use the split method on funString), and that you only want to print something when the word being considered is string. To understand why this may (or may not) be what you want, try and articulate what needs to happen. You appear to want to treat funString like the list of numbers, and it could be that you consider the boundaries between the elements in funString to be spaces (although you don't say). So, first we need to get a list which meets your requirements: funString.split() # [string, string, string, non- string, ...] Then, you want to visit the elements in this list, perhaps - that's where the for loop comes in. However, you use string as the loop variable which isn't going to work (as you may already have discovered). So let's use a variable instead: for s in funString.split(): print s This will print all the elements in that list. It appears that you only want to consider string, however, so that means that you need to test the value of s and to only do something if s is equal to string - that's where the if statement comes in. When you have data which doesn't immediately fit into an existing piece of code, don't be afraid to experiment at the Python prompt and to try and turn your data into something the existing code can use. And don't expect magic: if your first instinct produces a syntax error ('for string in funString') consider what you are trying to express and then try and find language constructs to express it. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
On 2008-08-17, Alexnb [EMAIL PROTECTED] wroted: string = yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8 It doesn't matter what is in the string, I want to be able to know exactly how many yes's there are. - cut here - import re foo = yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8 results = re.findall(yes, foo) len(results) 6 results ['yes', 'yes', 'yes', 'yes', 'yes', 'yes'] - cut here - I also want to know what is after each, regardless of length. So, I want to be able to get text1, but not text4 because it is after no and I want all of text5+more Text because it is after yes. It is like the yeses are bullet points and I want all the info after them. However, all in one string. I guess this can be done with regular expressions: http://www.python.org/doc/current/lib/module-re.html Read about groups, then write an appropriate regex. GS -- Grzegorz Staniak gstaniak _at_ wp [dot] pl -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Alexnb wrote: Uhm, string and non-string are just that, words within the string. From what I can tell, this is the first time you use the word word in your posts. Here shall I dumb it down for you? No, you should do what you should have done from the very beginning: explain what you want in unambiguous terms. Given that the dumbed down version only has superficial similarities with your earlier posts, this is obviously something that you need to practice. string = yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8 It doesn't matter what is in the string, I want to be able to know exactly how many yes's there are. I also want to know what is after each, regardless of length. So, I want to be able to get text1, but not text4 because it is after no It's after yes as well, as part of the string text3 no text4. and I want all of text5+more Text because it is after yes. It is like the yeses are bullet points and I want all the info after them. However, all in one string. Ok, so you have *two* separators, yes and no, and you want all the text fragments that follow a yes separator? Do you seriously argue that anyone anywhere would have been able to figure that out from your original description? funString = string string string non-string non-string string and for string in funString: print something Anyway, I guess I'd split on the separator, and use a list comprehension to pick out the texts you want. E.g. text = ... as above ... parts = re.split(r\b(yes|no)\b, text) parts = [parts[i+1].strip() ... for i in xrange(1, len(parts), 2) ... if parts[i] == yes] len(parts) 6 parts ['text1', 'text2', 'text3', 'text5+more Text', 'text6', 'text8'] Alternatively, just use text.split() to split the text in a list of words, and loop over that, keeping track of the words you want to keep. A bit more work, but maybe easier to grok if you're not used to list comprehensions/generator expressions. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
2008/8/17 Alexnb [EMAIL PROTECTED] Uhm, string and non-string are just that, words within the string. Here shall I dumb it down for you? string = yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8 It doesn't matter what is in the string, I want to be able to know exactly how many yes's there are. I also want to know what is after each, regardless of length. So, I want to be able to get text1, but not text4 because it is after no and I want all of text5+more Text because it is after yes. It is like the yeses are bullet points and I want all the info after them. However, all in one string. As already has been suggested, you could use regular expressions for that (if there isn't some more complex parsing necessary). Maybe something like this could work: import re input_text = yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8 no text9 yes_parts = re.findall(r(?s)\byes\b.*?(?=yes|no|$), input_text) yes_parts ['yes text1 ', 'yes text2 ', 'yes text3 ', 'yes text5+more Text ', 'yes text6 ', 'yes text8 '] The pattern searches for the string yes followed by the shortest possible arbitrary text until next yes, no or the end of input string is reached. \b should prevent matching yes as a part of other words, (?s) lets the . match newlines, in case there would be multiline input. Possibly the trailing spaces could be handled specifically if necessary. Vlasta -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Am Sun, 17 Aug 2008 13:12:36 -0700 schrieb Alexnb: Uhm, string and non-string are just that, words within the string. Here shall I dumb it down for you? Please, bear with us. You are deep into the problem, we are not. It doesn't help to be rude. If you can explain your problem well, you are halfway through to the solution. string = yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8 It doesn't matter what is in the string, I want to be able to know exactly how many yes's there are. I also want to know what is after each, regardless of length. So, I want to be able to get text1, but not text4 because it is after no and I want all of text5+more Text because it is after yes. It is like the yeses are bullet points and I want all the info after them. However, all in one string. How about this: s=yes t1 yes t2 no t3 yes t4 no t5 l=s.split() l ['yes', 't1', 'yes', 't2', 'no', 't3', 'yes', 't4', 'no', 't5'] for i in range(1,len(l),2): ... if l[i-1] == 'yes': print l[i] t1 t2 t4 Now your problem is reduced to splitting the input into (yes/no) and (text) pairs. For a simple string like the one above split() is ok, but string = yes text4 yes text5+more Text yes text6 no text7 will be split into [ ... 'yes', 'text5+more', 'Text', 'yes', ...], breaking my simple algorithm. You could look for the index() of 'yes' / 'no', but then you'd have to make sure that 'text' does not contain 'yes' or 'no'. HTH. Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: python-mode errors
Rustom Mody wrote: When I start python mode I get the error: idle error: #buffer easygui.py -Wrong number of arguments : #subr set-match-data 2 The Python mode version is 4.78 Is this a known problem? there are plenty of google hits for that message, and they all seem to agree that the problem is caused by using ELC files generated for a newer emacs with an older version. try loading the EL file to see if the problem goes away. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Python process communication
[EMAIL PROTECTED] wrote: I'd like to write a script that will connect to another already running process, pipe some data to it's input and receive data from it's output. I can create another process using subprocess module, but how do I connect to already running process? Maybe there is a better solution for process communication? I've searched in the net and found nothing, so I've decided to post my problem here, hopefully someone will help me. do you control the other process? can you make it listen to a local socket or a named pipe? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing exceptions in PEP 3107
On Aug 17, 9:34 am, Christoph Zwerschke [EMAIL PROTECTED] wrote: Carl Banks schrieb: You are free to use it for other things. For example, the following usage is obvious and sensible (insofar as listing exceptions is sensible): def f(x : int) - int, raises(TypeError) Think of the return value annotation as more of a function outcome annotation. That's fine, but then this should be mentioned in the PEP3107. Evidently the thing that really needs to be mentioned in the PEP is don't be pedantic. Instead it says explicitly that the - syntax is for the type of a function's return value. If it's intended to be used in a more general way like you suggested, then the wording used in the PEP is misleading. (The wording *the* type is problematic anyway, since a Python function can return different types in different situations.) For some reason, you keep trying to interpret the PEP's description as policy. Once again: the PEP disclaims all authority on policy. If the PEP intended you to use the annotations only for what it said the annotations were for, then it wouldn't have disclaimed that authority. It's still unclear for me whether annotations on thrown exceptions are included in PEP3107 (as per your suggestion), or are not covered by PEP3107 at all (as Duncan suggests), or whether this question has just not yet been settled. According to the PEP you can do anything you want with the annotations. PEP 3107 does not specify policy. There is no question to settle. If it bothers you that much, go file a bug report. Someone might even change it. But it's nothing but needless pedantry. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Ok, after sending my post, I see, that the code got a bit screewed up, but morover, there should probably be a word boundary in the closing part of the regexp. A next attempt + added stripping the yes delimiter and the whitespace...: import re input_text = yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8 no text9 yes_parts = re.findall(r(?s)\byes\b.*?(?=\byes\b|\bno\b|$), input_text) yes_parts_infos = [item[3:].strip() for item in yes_parts] yes_parts ['yes text1 ', 'yes text2 ', 'yes text3 ', 'yes text5+more Text ', 'yes text6 ', 'yes text8 '] yes_parts_infos ['text1', 'text2', 'text3', 'text5+more Text', 'text6', 'text8'] HTH, Vlasta -- http://mail.python.org/mailman/listinfo/python-list
list/tuple/dict question
hi guys/gals... got a basic question that i can't get my hands around. i'm trying to programatically create/use a list/tuple (or whatever the right phrase in pyton is!!) basically, something like: foo = [] foo.append('cat') foo.append('dog') foo[1] = [] (and in this case, i really want to have a list called 'cat' to be created!!) when i've tried this, i don't get a list called 'cat', instead (as i expected) the foo[1] is now a [] (list)) so foo is now ['cat', [] ] ultimatelly , i want to be able to dynamically create a number of lists that i name/create/manipulate on the fly, within the test app. ie, be able to then create a list/array cat = ['a','b','c',] a dict doesn't seem to work, as it is essentially a series of key/values, which isn't exactly what i want... thoughts/comments/code samples would be reatly appreciated. looking at various sites/samples cia google hasn't helped... thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Good python equivalent to C goto
On Aug 17, 9:23 pm, Matthew Fitzgibbons [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: On Aug 17, 8:09 pm, Matthew Fitzgibbons [EMAIL PROTECTED] wrote: Kurien Mathew wrote: Hello, Any suggestions on a good python equivalent for the following C code: while (loopCondition) { if (condition1) goto next; if (condition2) goto next; if (condition3) goto next; stmt1; stmt2; next: stmt3; stmt4; } Thanks Kurien -- http://mail.python.org/mailman/listinfo/python-list I would not be too happy if I saw C code like that in my repository. This is equivalent: while (loopCondition) { if (!(condition1 || condition2 || condition3)) { stmt1; stmt2; } stmt3; stmt4; } In Python: while (loopCondition): if not (condition1 or condition2 or condition3): stmt1 stmt2 stmt3 stmt4 If stmt3 and stmt4 are error cleanup code, I would use try/finally. while loopCondition: try: if condition1: raise Error1() if condition2: raise Error2() if condition3: raise Error3() stmt1 stmt2 finally: stmt3 stmt4 This will also bail out of the loop on and exception and the exception will get to the next level. If you don't want that to happen, put an appropriate except block before the finally. -Matt- Hide quoted text - - Show quoted text - class Goto_Target(Exception): pass def Goto_is_not_dead(nIn): try: if (nIn == 1): raise Goto_Target if (nIn == 2): raise Goto_Target inv = 1.0 / nIn print 'Good Input ' + str(nIn) + ' inv=' + str(inv) except Goto_Target: pass except Exception, e: print 'Error Input ' + str(nIn) + ' ' + str(e) finally: print 'any input ' + str(nIn) if __name__ == '__main__': Goto_is_not_dead(0) Goto_is_not_dead(2) Goto_is_not_dead(3) -- http://mail.python.org/mailman/listinfo/python-list I think this is needlessly ugly. You can accomplish the same with a simple if-else. In this case you're also masking exceptions other than Goto_Target, which makes debugging _really_ difficult. If you need to have the cleanup code executed on _any_ exception, you can still use try-finally without any except blocks. Your code is equivalent to this: def goto_is_dead(n): try: if n == 0 or n == 1 or n == 2: # if you're validating input, validate the input print Error Input %s % n else: print Good Input %s inv= %s % (n, (1. / n)) finally: print any input %s % n if __name__ == '__main__': goto_id_dead(0) goto_id_dead(2) goto_id_dead(3) More concise, readable, and maintainable. -Matt- Hide quoted text - - Show quoted text - as mentioned 'in complex code the goto statement is still the easiest to code and understand'. The examples are very small and do not require that at all. I agree it's ugly. Just to show a way to do it. A very few functions where I use goto in C or C# are a few hundred lines of code, difficult to split in smaller functions. A lot of common data. One coming to my mind is a complex validation function for the user input of a complex transaction. If any test fails, goto the cleaning part and issue error message. The goto code is the simpler way to do it. We are not talking about simple if-else, but let say 20 if-else. Many nested if-else are more difficult to understand and do not fit better the semantics. -- http://mail.python.org/mailman/listinfo/python-list
Re: list/tuple/dict question
bruce wrote: a dict doesn't seem to work, as it is essentially a series of key/values, which isn't exactly what i want... so what do you think a variable namespace is? as usual, Python works best if you use it to write Python program, and in Python, the right way to store a collection of name/value pairs is to use a dictionary: stuff = {} foo = [] foo.append('cat') foo.append('dog') stuff[foo[1]] = [] /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Good python equivalent to C goto
[EMAIL PROTECTED] wrote: The goto code is the simpler way to do it. We are not talking about simple if-else, but let say 20 if-else. Many nested if-else are more difficult to understand and do not fit better the semantics. let's see... $ cd ~/svn/python25 $ grep goto */*.c | wc 21077038 86791 but given that the Python language doesn't have a goto statement, can we perhaps drop this subtopic now? /F -- http://mail.python.org/mailman/listinfo/python-list
RE: list/tuple/dict question
Hi Fredrik... so, this still doesn't get me an array called 'cat', or 'dog' or do i somehow use stuff to add/extract the vals...??? thanks -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Fredrik Lundh Sent: Sunday, August 17, 2008 2:27 PM To: python-list@python.org Subject: Re: list/tuple/dict question bruce wrote: a dict doesn't seem to work, as it is essentially a series of key/values, which isn't exactly what i want... so what do you think a variable namespace is? as usual, Python works best if you use it to write Python program, and in Python, the right way to store a collection of name/value pairs is to use a dictionary: stuff = {} foo = [] foo.append('cat') foo.append('dog') stuff[foo[1]] = [] /F -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: list/tuple/dict question
bruce wrote: so, this still doesn't get me an array called 'cat', or 'dog' sure does, in the stuff dictionary: stuff = {} foo = [] foo.append('cat') foo.append('dog') stuff[foo[1]] = [] stuff {'dog': []} (note that Python indexing starts with zero, so foo[1] refers to the dog entry). or do i somehow use stuff to add/extract the vals...??? stuff[dog] [] stuff[dog].append(1) stuff[dog] [1] etc. /F -- http://mail.python.org/mailman/listinfo/python-list
Time-dependent method
Hi all! I was wondering if it is possible to call a method such that if it takes more than say 1 minute to complete, it will give up and do something else instead. Thanks in advance! -- http://mail.python.org/mailman/listinfo/python-list
Re: Time-dependent method
hypermonkey2 wrote: I was wondering if it is possible to call a method such that if it takes more than say 1 minute to complete, it will give up and do something else instead. as mentioned in the recent Create a process with a 'time to live' thread: http://code.activestate.com/recipes/307871/ /F -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
On Aug 17, 8:40 pm, [EMAIL PROTECTED] wrote: Eric Wertman: So what exactly does that do? Returns a generator, instead of a list? Allows you to iterate on the parts in a lazy way, without creating the whole list of the pieces. The arguments are the same of str.split(). If it was introduced into Python v3.x then wouldn't it have to be called str.split in order to be consistent with xrange - range? :-) -- http://mail.python.org/mailman/listinfo/python-list
command line tool for process communication
Hello guys, I have a program which is run through command line .I am trying to create another command line tools which controls this program. So for example in my new program when i give newprog -a then it should invoke the existing tool and perform one of its operation.eg existtprog -s How could this be done in python? Optparse can be used to make the new tool but what should be done to control the existing tool from the new tool? Thanks in advance. Aditya -- http://mail.python.org/mailman/listinfo/python-list
Re: command line tool for process communication
aditya shukla wrote: I have a program which is run through command line .I am trying to create another command line tools which controls this program. So for example in my new program when i give newprog -a then it should invoke the existing tool and perform one of its operation.eg http://operation.eg existtprog -s How could this be done in python? Optparse can be used to make the new tool but what should be done to control the existing tool from the new tool? http://docs.python.org/lib/module-subprocess.html ? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
MRAB: If it was introduced into Python v3.x then wouldn't it have to be called str.split in order to be consistent with xrange - range? :-) xsplit may be a name fit for Python 2.6/2.7. Regarding Python 3.0 you may be right, but then when you want the list of parts you have to do: list(somestring.split()) While to count the number of parts on Python 3.0 this may suffice: sum(1 for part in somestring.split()) Unless you use a leniter() function that counts the lazy iterations (its functionality can be folded inside the len() too, like in some lazy languages). Most of the times I think a lazy splitting may suffice, so in Python 3.0 the eager version may be absent :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
online tutorials?
I want to learn how to program in python and would like to know if you guys know of any free online tutorials. Or is it too complicated to learn from a site or books? -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
Alexnb wrote: Uhm, string and non-string are just that, words within the string. Here shall I dumb it down for you? string = yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8 It doesn't matter what is in the string, I want to be able to know exactly how many yes's there are. I also want to know what is after each, regardless of length. So, I want to be able to get text1, but not text4 because it is after no and I want all of text5+more Text because it is after yes. It is like the yeses are bullet points and I want all the info after them. However, all in one string. It seems like this is the type of thing the re module would be good at. But for your example, this would work too: for s in string.split('no'): if 'yes' in s: j = s.index('yes') print s[j+4:] -- http://mail.python.org/mailman/listinfo/python-list
Re: online tutorials?
On 18 Aug, 00:53, Gits [EMAIL PROTECTED] wrote: I want to learn how to program in python and would like to know if you guys know of any free online tutorials. Or is it too complicated to learn from a site or books? Start here, perhaps: http://wiki.python.org/moin/BeginnersGuide As for whether it's too complicated to learn from written materials, that may depend on how much programming tuition you've had already. I'd already used quite a few languages before finding Python, so it may be the case that you are in a different audience than I was, but the following page may point you towards suitable tutorials: http://wiki.python.org/moin/BeginnersGuide/NonProgrammers Good luck! Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing exceptions in PEP 3107
Carl Banks wrote: If it bothers you that much, go file a bug report. Someone might even change it. But it's nothing but needless pedantry. Has my de domain inspired you to rant about pedantry? No, it does not bother me that much. I just thought the PEP could be clearer here and explicitly mention the thrown exceptions as a use case instead of only speaking about return values. Of course, if you're Dutch, it may be obvious, but for a dimwitted German things are not always obvious. -- Christoph -- http://mail.python.org/mailman/listinfo/python-list
Re: online tutorials?
On Sun, Aug 17, 2008 at 5:53 PM, Gits [EMAIL PROTECTED] wrote: I want to learn how to program in python and would like to know if you guys know of any free online tutorials. Or is it too complicated to learn from a site or books? Hi, I learned using dive into python, available online, and it is the best tutorial I am aware of: http://diveintopython.org/ cheers, David -- http://mail.python.org/mailman/listinfo/python-list
Re: like a for loop for a string
On Sun, 17 Aug 2008 12:07:45 -0700 (PDT), [EMAIL PROTECTED] wrote: I'm waiting for a str.xsplit still :-) If I write and submit a C implementation of xsplit how many chances do I have to see it included into Python? :-) Got no idea, but it might be a nice try. It should be a quite good memory saver for very large strings. While browsing the implementation of split method I discovered something I didn't really realise before. While calling split method without arguments it treats all four signs: ' ', '\n', '\r' and '\t' as a whitespace, so it's not the same as str.split(' '). Moreover, specifying maxsplit argument whenever possible seems to be a good practice. Anyway, go ahead with that xsplit thing :-) -- Regards, Wojtek Walczak, http://www.stud.umk.pl/~wojtekwa/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Missing exceptions in PEP 3107
On Aug 17, 7:25 pm, Christoph Zwerschke [EMAIL PROTECTED] wrote: Carl Banks wrote: If it bothers you that much, go file a bug report. Someone might even change it. But it's nothing but needless pedantry. Has my de domain inspired you to rant about pedantry? Actually, no. Carl Banks P.S. My great-grandfather's surname was von Bank when he emigrated to America. -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
Of course We needn't 100 levels,but I use the exec function can concise the code. See the attachment. 2008/8/17 Fredrik Lundh [EMAIL PROTECTED] Nick Dumas wrote: A good quote I read (I can't remember who it was from, though) is If you need more than three levels of indentation, then something is seriously wrong with your code. Possibly Guido himself? Anyway. If you've got 100 levels of for, you're probably making things way harder than they need to be. assuming 100 levels of for and 2 items in each sequence, you'll end up with 1267650600228229401496703205376 iterations through the inner loop. assuming each iteration takes a picosecond, it'll take approx 40 billion years to run the program. /F -- http://mail.python.org/mailman/listinfo/python-list #= # # Python Source File -- Created with SAPIEN Technologies PrimalScript 4.1 # # NAME: Problem 52 # # AUTHOR: patrol , ustc # DATE : 2008-8-7 # # COMMENT: # # URL:http://projecteuler.net/index.php?section=problemsid=52 # Result:142857 #= import sys import string def isPro52Num(n): s=[] for i in range(1,7): s.append(str(i*n)) for i in s[0]: ll = len(string.join(string.split(s[0],i),'')) for j in range(1,6): if ll!=len(string.join(string.split(s[j],i),'')): return False return True def f(n): index=[] num=[] digitsList=[0]+range(2,10) for i in range(n): index.append(1) num.append(1) num.append(1) stringCode='for index[0] in digitsList:\n' for i in range(1,n): stringCode += '\t'*(i+0)+'num[%d] = num[%d]*10 + index[%d]\n'%(i-1,i-2,i-1) \ +'\t'*(i+0)+'for index[%d] in digitsList:\n'%i stringCode +='\t'*n+'num[%d] = num[%d]*10 + index[%d]\n'%(n-1,n-2,n-1) \ +'\t'*n+'if isPro52Num(num[%d]):\n'%(n-1) \ +'\t'*(n+1)+'print num[%d]\n'%(n-1) \ +'\t'*(n+1)+'sys.exit()\n' exec(stringCode) length = 1 while True: f(length) length += 1 -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
I found that the recursive function run very slowly 2008/8/18 Paul Boddie [EMAIL PROTECTED] On 17 Aug, 17:17, Fredrik Lundh [EMAIL PROTECTED] wrote: required reading: The Effects of Moore's Law and Slacking on Large Computations http://arxiv.org/abs/astro-ph/9912202 Or maybe this...? http://docs.python.org/tut/node6.html#SECTION00660 And this: http://www.freenetpages.co.uk/hp/alan.gauld/tutrecur.htm Paul -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
Yes, I can solve the problem by recursive function. I guess Function Call consume more resources than nested For. So I use the nested For by using exec function. 2008/8/18 Paul Boddie [EMAIL PROTECTED] On 17 Aug, 19:36, Fredrik Lundh [EMAIL PROTECTED] wrote: and functions will solve the 40-billion year computation problem exactly how? I was thinking more about the need to nest for statements to a depth of 20 levels, which I imagine only arises on a just in case basis for the inquirer. In other words, the inquirer may have input that could theoretically demand twenty levels of state, each level provided by a single for statement, but in practice they might only need to manage a few levels of state. In any case, we're potentially seeing the use of the wrong tool for the job, and I am speculating that functions would be the right tool, but unless the inquirer is willing to show the code (which I haven't seen in this thread yet), it's hard to speculate further. Paul -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: how many nested for can we utilize?
I use the exec function. my code's levels are less than 3. BTW,Linus Torvalds is NOT always right. 2008/8/18 Roel Schroeven [EMAIL PROTECTED] Nick Dumas schreef: A good quote I read (I can't remember who it was from, though) is If you need more than three levels of indentation, then something is seriously wrong with your code. Possibly Guido himself? Linus Torvalds in the Linux kernel coding style document: [...] The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program. (http://lxr.linux.no/linux/Documentation/CodingStyle) -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Python does not get environment variable when using cron.
Hello all, I am attempting to execute an automated test (written in Python) via cron. I have to check the HOSTNAME variable as part of the test, oddly under cron the HOSTNAME environment variable is not in the os.environ dictionary. I know that cron runs in a subshell that does not have all of the normally set environment variables. HOSTNAME is not one of those variables, it is set even in cron's subshell. Why doesn't python get this variable? Is this a bug in python2.4? From a cronjob to check environment variables in cron's shell vs python's os.environ (please excuse my lack of creativity in naming convention)- BASH=/bin/bash BASH_ARGC=() BASH_ARGV=() BASH_EXECUTION_STRING='set; echo -; echo import os; print os.environ | python' BASH_LINENO=() BASH_SOURCE=() BASH_VERSINFO=([0]=3 [1]=1 [2]=17 [3]=1 [4]=release [5]=i686-redhat-linux-gnu) BASH_VERSION='3.1.17(1)-release' DIRSTACK=() EUID=501 GROUPS=() HOME=/home/regression HOSTNAME=regress5 HOSTTYPE=i686 IFS=$' \t\n' LOGNAME=regression MACHTYPE=i686-redhat-linux-gnu OPTERR=1 OPTIND=1 OSTYPE=linux-gnu PATH=/usr/local/bin:/bin:/usr/bin:/home/regression/bin PPID=819 PS4='+ ' PWD=/home/regression PYTHONPATH=/home/regression/lib SHELL=/bin/bash SHELLOPTS=braceexpand:hashall:interactive-comments SHLVL=1 TERM=xterm UID=501 USER=regression _=/bin/bash - {'TERM': 'xterm', 'SHELL': '/bin/bash', 'SHLVL': '1', 'PYTHONPATH': '/home/regression/lib', 'PWD': '/home/regression', 'LOGNAME': 'regression', 'USER': 'regression', 'HOME': '/home/regression', 'PATH': '/usr/local/bin:/bin:/usr/bin:/home/regression/bin', '_': '/usr/bin/python'} Thanks, Steve -- http://mail.python.org/mailman/listinfo/python-list