ANN: DirectPython 11 0.1
The first alpha release of DirectPython 11 is ready for testing. DirectPython 11 is an extension to the Python programming langugage which provides access to the Microsoft Windows Direct3D 11 API. Home page: http://directpython11.sourceforge.net/ Downloads: http://sourceforge.net/projects/directpython11/files/ -- Heikki Salo -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Checker 1.3 Released!
I'm pleased to announce a new release of Checker. This is a cross-platform, pluggable tool for comparing the configuration of a machine with a known configuration stored in text files in a source control system all written in Python. This release and the previous release fix ordering issues in file listings as well as generalise operating package listing to support RedHat-like systems in addition to Debian-like systems. For more information, please see: http://www.simplistix.co.uk/software/python/checker cheers, Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Execute 1.2 Released!
I'm pleased to announce the first public release of Execute. This is a collection of common patterns for executing commands as sub processes. It supports executing a simple command that requires no input in a sub process and can return: - text sent to the standard error and output streams - the return code set by the command - both of the above as a tuple For more information, please see: http://www.simplistix.co.uk/software/python/execute cheers, Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
ANN: Chicago Python User Group August meeting this Thursday 7pm ITA
ChiPy = 7 PM Thursday Aug 12, 2010 (This Thursday in the loop) RSVP here - https://spreadsheets.google.com/viewform?formkey=dHVLOTNTU3oxTzJKYjB3RmV4eVZkMEE6MA Get ready for the best ChiPy meeting ever! We will head over to ITA in the loop for this free and informative (not to mention fun and filling) Chicago Python User Group. ChiPy newcomer (but not new to Python or speaking for that matter) Steve Ayers will be leading the show for some data mining tips. PyGame and Python 3 porting guide overviews to follow. Finally, we will have a panel discussion that will dispel some of the Cloud Computing myths and define the term from the Pythonic perspective. Topics -- * (45 min) Data Mining With Python -- Steve Ayers * (10 min) Break for Pizza ( Thanks, Paul May Associates http://paulmayassociates.com/ ) * (15 min) PyWeek competition and PyGame library Example -- Eugenia Gabrielova * (20 min) Python 3 porting guide walk-through -- Brian Curtin * (20+ min) Panel Discussion on, Defining 'Cloud computing' and how Python relates See ChiPy List for Details http://mail.python.org/pipermail/chicago/2010-August/thread.html#7033 Location Illinois Technology Association (ITA) 200 S. Wacker Drive 15th Floor Chicago, IL 60606 312.435.2805 http://www.illinoistech.org Metra: exit on Adams St, walk East across the bridge, first door on the right. Sign Up --- RSVP please so we know how much pizza/beer to order: https://spreadsheets.google.com/viewform?formkey=dHVLOTNTU3oxTzJKYjB3RmV4eVZkMEE6MA About the group --- ChiPy is made up of people of all levels of programming and Python knowledge. At every meeting we have had both beginning programmers, people who are just starting to use Python, as well as experienced Python programmers. Don't be intimidated about coming to a meeting. Note that ChiPy is not a formal organization. We collect no dues, elect no officers, and keep no roster. Signing up for the mailing list carries no obligation. Nor does showing up at the meetings. Nor, at least so far, does anything else we have done, although we always appreciate it when our presenters show up. (They usually do!) http://chipy.org ___ Chicago mailing list chic...@python.org http://mail.python.org/mailman/listinfo/chicago -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: Using the print command in Python3
On 10-Aug-2010, at 11:04 AM, Benjamin Kaplan wrote: On Mon, Aug 9, 2010 at 10:17 PM, Grady Knotts gradykno...@gmail.com wrote: In earlier versions of Python I can do: print 'A', print 'B' to print everything on the same line: 'A B' But I don't know how to do this with Python3 I've been trying things like: print('A',) print('B') and it prints two different lines. So, do I get two different print statements to output on the same line? help(print) Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. -- http://mail.python.org/mailman/listinfo/python-list One method of doing this: Use the join method of the string: print(.join([ 'A' , 'space B' ] ) This will give you : 'AspaceB' I have used extra spaces just for clarity. Hope this helps ! Nav -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft lessening commitment to IronPython and IronRuby
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: Frankly I never understood the point of IronPython and IronRuby. They seemed like a desperate attempt to keep Dotnet relevant in the modern world of dynamic languages. Looks like it was a failure. Yawn. I'm not sure that's really fair. The .NET Common Language Runtime is a vast and very useful class library, including two complete GUI systems. The thought was that IronPython and IronRuby would let people who were comfortable in those languages tap into the CLR. In the end, it seemed to me that writing an IronPython program was mostly an exercise of writing it in C# and then translating. .NET is just too tuned for C# and VB. Although IronPython was a good fit, it was just not a great fit. -- Tim Roberts, t...@probo.com Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: mailbox.mbox not locking mbox properly
tinn...@isbd.co.uk wrote: I'm using the python mailbox class in a script that processes incoming mail and delivers it to various mbox format mailboxes. It appears that, although I am calling the lock method on the destination before writing to the mbox and calling unlock afterwards the locking isn't working correctly. ... So it seems that python's mailbox class locking isn't playing nicely with mutt's mailbox locking whereas postfix's locking does work correctly. Correct. The dest.flush() method creates a temporary file, copies the entire modified mailbox into it, removed the original file, and renames the temp file into place. The Postfix MDA, like most MDAs, just opens the existing file and appends the new data to it. Has anyone seen this problem before, and/or do I need to anything more than the following for the locking to work correctly:- It's not the locking. It's the flush mechanism. The mbox class doesn't know that the ONLY thing you did was an append. You might have modified other messages in the middle. If you want to do an append, you'll need to write your own subclass of mbox. -- Tim Roberts, t...@probo.com Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python parsing XML file problem with SAX
Christian Heimes, 10.08.2010 01:39: Am 10.08.2010 01:20, schrieb Aahz: The docs say, Parses an XML section into an element tree incrementally. Sure sounds like it retains the entire parsed tree in RAM. Not good. Again, how do you parse an XML file larger than your available memory using something other than SAX? The document at http://www.ibm.com/developerworks/xml/library/x-hiperfparse/ explains it one way. The iterparser approach is ingenious but it doesn't work for every XML format. Let's say you have a 10 GB XML file with one millionpart/ tags. An iterparser doesn't load the entire document. Instead it iterates over the file and yields (for example) one million ElementTrees for eachpart/ tag and its children. You can get the nice API of ElementTree with the memory efficiency of a SAX parser if you obey Listing 4. In the very common case that you are interested in all children of the root element, it's even enough to intercept on the specific tag name (lxml.etree has an option for that, but an 'if' block will do just fine in ET) and just .clear() the child element at the end of the loop body. That results in very fast and simple code, but will leave the tags in the tree while only removing their content and attributes. Usually works well enough for several ten thousand elements, especially when using cElementTree. As usual, a bit of benchmarking will uncover the right way to do it in your case. That's also a huge advantage over SAX: iterparse code is much easier to tune into a streamlined loop body when you need it. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft lessening commitment to IronPython and IronRuby
In message 7fr16650meigqgmj8rh0n3a66q9r4j4...@4ax.com, Tim Roberts wrote: The .NET Common Language Runtime is a vast and very useful class library, including two complete GUI systems. Used only by corporate code-cutter drones. Go on, name one creative thing which was ever done in Dotnet. -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft lessening commitment to IronPython and IronRuby
Lawrence D'Oliveiro, 10.08.2010 08:42: In message7fr16650meigqgmj8rh0n3a66q9r4j4...@4ax.com, Tim Roberts wrote: The .NET Common Language Runtime is a vast and very useful class library, including two complete GUI systems. Used only by corporate code-cutter drones. Go on, name one creative thing which was ever done in Dotnet. Erm, this is Microsoft. It's not about being creative, it's about selling stuff to users. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is python not written in C++ ?
Carl Banks wrote: I highly doubt the Python source would build with a C++ compiler. As Christian showed, it doesn't. However, look around the sources a bit. There are lots of places where e.g. the returnvalue of malloc() (or, rather, the macro that resolves to something like it) is explicitly type-cast to the according pointer type. When asked on the developers' list, it was said that this was intended for compatibility with C++, e.g. in cases where people want to embed Python into their C++ projects. Of course, this contradicts Christian's statement that C++ compatibility wasn't considered useful enough. *shrug* Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft lessening commitment to IronPython and IronRuby
Tim Roberts wrote: I'm not sure that's really fair. The .NET Common Language Runtime is a vast and very useful class library, including two complete GUI systems. The thought was that IronPython and IronRuby would let people who were comfortable in those languages tap into the CLR. Is there any way for a non-.NET program to access a .NET library? Or is it necessary to drink the entire bottle of .NET kool-aid? -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Using the print command in Python3
On Tue, 10 Aug 2010 00:17:03 -0500, Grady Knotts wrote: In earlier versions of Python I can do: print 'A', print 'B' to print everything on the same line: 'A B' But I don't know how to do this with Python3 I've been trying things like: print('A',) print('B') and it prints two different lines. So, do I get two different print statements to output on the same line? print(Hello, end=' ') print(world) outputs: Hello world -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft lessening commitment to IronPython and IronRuby
On Tue, 10 Aug 2010 18:42:35 +1200, Lawrence D'Oliveiro wrote: In message 7fr16650meigqgmj8rh0n3a66q9r4j4...@4ax.com, Tim Roberts wrote: The .NET Common Language Runtime is a vast and very useful class library, including two complete GUI systems. Used only by corporate code-cutter drones. Go on, name one creative thing which was ever done in Dotnet. Not just Dotnet, but Python on Dotnet. http://www.python.org/about/success/resolver/ http://blog.jonudell.net/2007/09/27/first-look-at-resolver-an-ironpython-based-spreadsheet/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
In message 56a18e2b-4967-4a63-852e-1eb53bb6e...@j8g2000yqd.googlegroups.com, Alex Barna wrote: So what happens to this field (Windows GUI automation) ? Can’t understand the point to it. “GUI automation” is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. Tasks that can be automated are most easily, flexibly, and above all reliably, done via command lines and other such scripting interfaces. -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft lessening commitment to IronPython and IronRuby
On Tue, 10 Aug 2010 20:07:06 +1200, Gregory Ewing wrote: Tim Roberts wrote: I'm not sure that's really fair. The .NET Common Language Runtime is a vast and very useful class library, including two complete GUI systems. The thought was that IronPython and IronRuby would let people who were comfortable in those languages tap into the CLR. Is there any way for a non-.NET program to access a .NET library? Or is it necessary to drink the entire bottle of .NET kool-aid? http://www.mono-project.com/Main_Page -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft lessening commitment to IronPython and IronRuby
Steven D'Aprano, 10.08.2010 10:04: On Tue, 10 Aug 2010 18:42:35 +1200, Lawrence D'Oliveiro wrote: Go on, name one creative thing which was ever done in Dotnet. Not just Dotnet, but Python on Dotnet. http://www.python.org/about/success/resolver/ At the very end of that article, I found this statement: Resolver One is Windows only This sounds like a major drawback to me. It might be an acceptable early project priority if the app is only targeting the desktop, but this system additionally claims to be a web-accessible spreadsheet. If this is supposed to run on a server, it means that it will always suffer from the headless click-here-to-continue problem. It might not be too hard to port the app to Mono, but the rather explicit claim above doesn't make me feel very comfortable about that upgrade path... Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: File Manager in Tkinter
In article d4m1661blus6baj1lrd37j5vk4dau35...@4ax.com, John wrote: As a learning exercise in Tkinter I htought about making a very simple and basic file manager for my own use. I tried searching google for any sample project and could not find anything. Not exactly sure how to start I tought I could ask here? I thought about making two listboxes one to list folders only the other files inside. I tried to make one listbox first but did not know how to list folders only. You just have to filter them explicitely by using os.path.isdir on each file name. from Tkinter import * import os path = D:\\ s = Scrollbar() L = Listbox() s.pack(side=RIGHT, fill=Y) L.pack(side=LEFT, fill=Y) s.config(command=L.yview) L.config(yscrollcommand=s.set) for filename in os.listdir(path): Add here: if os.path.isdir(os.path.join(path, filename)): L.insert(END, filename) mainloop() Is there a way to list folders with images? AFAIK, not with a Listbox. You can do it with a Canvas, but it's much more complicated than using a Listbox, so maybe you should try to make your Listbox-only version works first. Any suggestions or help how to proced would be appreciated. Thank you Good luck! -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
On Tue, 10 Aug 2010 20:05:12 +1200, Lawrence D'Oliveiro wrote: In message 56a18e2b-4967-4a63-852e-1eb53bb6e...@j8g2000yqd.googlegroups.com, Alex Barna wrote: So what happens to this field (Windows GUI automation) ? Can’t understand the point to it. “GUI automation” is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. There have been plenty of systems for recording user actions and playing them back. They're very useful at times. http://en.wikipedia.org/wiki/Macro_recorder http://en.wikipedia.org/wiki/Macro_(computer_science) You might even have heard of one of them... Emacs. I hear that it's moderately popular among Linux users. http://www.linuxjournal.com/article/3769 Tasks that can be automated are most easily, flexibly, and above all reliably, done via command lines and other such scripting interfaces. That's a matter of opinion, and it clearly depends on the nature of the GUI and CLI, as well as what task you're trying to automate. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
On Aug 10, 5:56 am, alex23 wuwe...@gmail.com wrote: Alex Barna alex.lavoro.pro...@gmail.com wrote: So what happens to this field (Windows GUI automation) ? Either someone cares enough to do something about it, or everyone just defaults to using AutoIT-like tools. There were a lot of development but then all ceased, except pywinauto has a final release in April, but really low community activity. Does it mean AutoIt has much more advantages than Python tools (which I have not realized) ? Which Python implementation are you planning on contributing to? I'd say pywinauto. It's more O-O than the other tools. Excerpt from its homepage (http://pywinauto.openqa.org/): quote Most other tools are not object oriented you end up writing stuff like: window = findwindow(title = Untitled - Notepad, class = Notepad) SendKeys(window, %OF) # Format - Font fontdialog = findwindow(title = Font) buttonClick(fontdialog, OK) I was hoping to create something more userfriendly (and pythonic): win = app.UntitledNotepad win.MenuSelect(Format-Font) app.Font.OK.Click() /quote Alex Barna -- http://mail.python.org/mailman/listinfo/python-list
MailingLogger 3.3.3 Released!
I'm pleased to announce a new release of Mailinglogger. Mailinglogger provides two handlers for the standard python logging framework that enable log entries to be emailed either as the entries are logged or as a summary at the end of the running process. The handlers have the following features: - customisable and dynamic subject lines for emails sent - emails sent with an X-Mailer header for easy filtering - flood protection to ensure the number of emails sent is not excessive - support for SMTP servers that require authentication - fully documented and tested The latest releases of ZConfig provides a great way to configure the python logging framework without having to resort to the appalling .ini-based configuration stuff: from ZConfig import configureLoggers configureLoggers(''' ... logger ...level INFO ...logfile ... PATH STDOUT ... format %(levelname)s %(name)s %(message)s .../logfile ... /logger ... ''') This release and the previous release fix some problems with interpolating non-text objects into log messages and running the tests in non-GMT timezones. For more information, please see: http://www.simplistix.co.uk/software/python/mailinglogger or http://pypi.python.org/pypi/mailinglogger cheers, Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list
delegate functions to member
Hi! I have an extension module (a plugin written with Boost.Python) and around that a wrapper class that adapts a few things. Since the module is a plugin, there are multiple implementations of this. What I'm currently doing is this: plugin = __import__(plugin_name) class PluginWrapper(plugin.PluginClass): ... This means that the definition of class PluginWrapper actually depends on the previously loaded module. What I would like to do is to define the wrapper just once and instead pass the plugin module to the constructor: class PluginWrapper(object): ... plugin = __import__(plugin_name) instance = PluginWrapper(plugin) Now, I use the wrapper to make some function more friendly (e.g. default parameters, keyword-parameters, wrapping raw handles) but I want other functions from the baseclass to remain untouched. If I use a baseclass, this lookup is automatic. However, when I pass the instance to the constructor, I have to store it in a member, and then I have to add code for every function only to delegate it to that member. Is there an easy and generic way out of this? Thanks! Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: mailbox.mbox not locking mbox properly
Tim Roberts t...@probo.com wrote: tinn...@isbd.co.uk wrote: I'm using the python mailbox class in a script that processes incoming mail and delivers it to various mbox format mailboxes. It appears that, although I am calling the lock method on the destination before writing to the mbox and calling unlock afterwards the locking isn't working correctly. ... So it seems that python's mailbox class locking isn't playing nicely with mutt's mailbox locking whereas postfix's locking does work correctly. Correct. The dest.flush() method creates a temporary file, copies the entire modified mailbox into it, removed the original file, and renames the temp file into place. Yes, I just took a look at the mailbox.py code and it does exactly that which of course screws up just about any normal MUA looking at the mbox. Grr! The Postfix MDA, like most MDAs, just opens the existing file and appends the new data to it. Has anyone seen this problem before, and/or do I need to anything more than the following for the locking to work correctly:- It's not the locking. It's the flush mechanism. The mbox class doesn't know that the ONLY thing you did was an append. You might have modified other messages in the middle. If you want to do an append, you'll need to write your own subclass of mbox. OK, thanks. In reality I can probably just use straightforward file reading and writing as the *only* thing I will ever be doing is to append a message to a mailbox file. I think there should be a big warning in the mailbox documentation to this effect as doing it the way that Python's mailbox class does it will break all sorts of things. There should maybe be a specific 'append' method. -- Chris Green -- http://mail.python.org/mailman/listinfo/python-list
Re: Subprocess Problem (Wait and while)
On 09/08/2010 17:08, Alban Nona wrote: Hi, I have some problem with my actual code. In fact, the script is done to work within nuke from the foundry which is a compositing software. Homever, I have some code difficulties as I quite new in the area. Here the deal: Im using subprocess command to copy some files into local directory, like this: cmd = ['xcopy', '/E', '/I', '/Q', '/Y', '%s' % _folder.replace('/', '\\'), '%s' % _temp.replace('/', '\\')] subprocess.Popen(cmd, shell=True) Its copying quite well. I have no problem with that. But, after the copy I would like to continue my code, but ONLY if the copy is done. If Im using a WAIT, its freezing the main program (nuke) until the copy in done. I want to avoid that. I also try call but same thing. Its freezing... I though about something like: while subprocess not finished: Do nothing else: Continue Program Have a look at the .poll method of subprocess.Popen Like this its checking if the files is copying and do nothing until its done. I also tough: while os.listdir(src) != os.listdir(dst): Do nothing Else: Continue program That's unlikely to work because Windows will create the directory entry first (and at the complete size) and will then fill it in as it copies. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Circular imports (again)
Frank Millman fr...@chagford.com wrote in message news:i3ov9e$du...@dough.gmane.org... Hi all I know the problems related to circular imports, and I know some of the techniques to get around them. However, I find that I bump my head into them from time to time, which means, I guess, that I have not fully understood how to organise my code so that I avoid them in the first place. [...] So I think my main question is, is this a symptom of a flaw in my approach, or is this something that all programmers bump into from time to time? Thanks for the replies. All good info, but it was Ethan that put me onto the right track. I omitted to mention one thing originally, as I did not think it important, but it turns out to be crucial. My code is organised into three 'packages', not 'modules'. To reproduce my situation, I did some tests with the following hierarchy - top/ a.py /bb __init__.py b.py /cc __init__.py c.py a.py import bb.b import cc.c bb.b.foo() cc.c.foo() b.py import cc.c def foo(): print 'in b.foo, call c.bar' cc.c.bar() def bar(): print ' bar in b' c.py import bb.b def foo(): print 'in c.foo, call b.bar' bb.b.bar() def bar(): print ' bar in c' If I run 'a.py', I get the correct result - in b.foo, call c.bar bar in c in c.foo, call b.bar bar in b I changed 'a.py' - a.py from bb import b from cc import c b.foo() c.foo() It still worked. Next I changed 'b.py' - b.py from cc import c def foo(): print 'in b.foo, call c.bar' c.bar() def bar(): print ' bar in b' It still worked. Then I changed 'c.py' - c.py from bb import b def foo(): print 'in b.foo, call c.bar' b.bar() def bar(): print ' bar in b' Now I get the following traceback - Traceback (most recent call last): File F:\dd\a.py, line 1, in module from bb import b File F:\dd\bb\b.py, line 1, in module from cc import c File F:\dd\cc\c.py, line 1, in module from bb import b ImportError: cannot import name b Now that I understand this, I can work around my problem by using fully-qualified module names. But it would be interesting to know the underlying reason for this behaviour. I am using python 2.6.2. Thanks for any insights. Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: delegate functions to member
Ulrich Eckhardt wrote: Hi! I have an extension module (a plugin written with Boost.Python) and around that a wrapper class that adapts a few things. Since the module is a plugin, there are multiple implementations of this. What I'm currently doing is this: plugin = __import__(plugin_name) class PluginWrapper(plugin.PluginClass): ... This means that the definition of class PluginWrapper actually depends on the previously loaded module. What I would like to do is to define the wrapper just once and instead pass the plugin module to the constructor: class PluginWrapper(object): ... plugin = __import__(plugin_name) instance = PluginWrapper(plugin) Now, I use the wrapper to make some function more friendly (e.g. default parameters, keyword-parameters, wrapping raw handles) but I want other functions from the baseclass to remain untouched. If I use a baseclass, this lookup is automatic. However, when I pass the instance to the constructor, I have to store it in a member, and then I have to add code for every function only to delegate it to that member. Is there an easy and generic way out of this? Use getattr() class W(object): ... def __init__(self, wrapped): self._wrapped = wrapped ... def __getattr__(self, name): ... return getattr(self._wrapped, name) ... class A(object): ... def hello(self): print hello ... a = A() w = W(a) w.hello() hello However, with newsytle classes this doesn't work for __special__ methods w.__str__() '__main__.W object at 0x7f04ef2d4c50' Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: delegate functions to member
On Tue, Aug 10, 2010 at 2:01 AM, Ulrich Eckhardt eckha...@satorlaser.com wrote: Hi! I have an extension module (a plugin written with Boost.Python) and around that a wrapper class that adapts a few things. Since the module is a plugin, there are multiple implementations of this. What I'm currently doing is this: plugin = __import__(plugin_name) class PluginWrapper(plugin.PluginClass): ... This means that the definition of class PluginWrapper actually depends on the previously loaded module. What I would like to do is to define the wrapper just once and instead pass the plugin module to the constructor: class PluginWrapper(object): ... plugin = __import__(plugin_name) instance = PluginWrapper(plugin) Now, I use the wrapper to make some function more friendly (e.g. default parameters, keyword-parameters, wrapping raw handles) but I want other functions from the baseclass to remain untouched. If I use a baseclass, this lookup is automatic. However, when I pass the instance to the constructor, I have to store it in a member, and then I have to add code for every function only to delegate it to that member. Is there an easy and generic way out of this? Create the subclass(es) dynamically: def wrap(plug_in): class PluginWrapper(plug_in.PluginClass): ... return PluginWrapper plugin = __import__(plugin_name) WrappedPlugin = wrap(plugin) Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: easy question on parsing python: is not None
Ben Finney wrote: Peter Pearson ppear...@nowhere.invalid writes: Hey, that's a cute example, but . . . what a trap! Is it possible to document the use-the-object-not-the-string requirement loudly enough that people won't get caught? Don't use strings for such values. The data isn't going to be used, so there's no sense using a semantically rich data type like a string. Instead, use an ‘object’ instance; then, the only way to get a binding that will compare equal is to use the very object itself. FORWARD = object() BACKWARD = object() Strings may have their use, most of the time providing a string representation of the object, here is an example: FORWARD = object() print 'moving %s' % FORWARD moving object object at 0xb7dab5a8 Another approach using strings: class Direction: FORWARD = 'forward' print moving %s' % Direction.FORWARD moving forward Note that Direction.FORWARD is Direction.FORWARD is safe and will return True. JM -- http://mail.python.org/mailman/listinfo/python-list
Execute 1.2 Released!
I'm pleased to announce the first public release of Execute. This is a collection of common patterns for executing commands as sub processes. It supports executing a simple command that requires no input in a sub process and can return: - text sent to the standard error and output streams - the return code set by the command - both of the above as a tuple For more information, please see: http://www.simplistix.co.uk/software/python/execute cheers, Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: mailbox.mbox not locking mbox properly
On Tue, Aug 10, 2010 at 2:01 AM, tinn...@isbd.co.uk wrote: Tim Roberts t...@probo.com wrote: tinn...@isbd.co.uk wrote: I'm using the python mailbox class in a script that processes incoming mail and delivers it to various mbox format mailboxes. It appears that, although I am calling the lock method on the destination before writing to the mbox and calling unlock afterwards the locking isn't working correctly. ... So it seems that python's mailbox class locking isn't playing nicely with mutt's mailbox locking whereas postfix's locking does work correctly. Correct. The dest.flush() method creates a temporary file, copies the entire modified mailbox into it, removed the original file, and renames the temp file into place. Yes, I just took a look at the mailbox.py code and it does exactly that which of course screws up just about any normal MUA looking at the mbox. Grr! The Postfix MDA, like most MDAs, just opens the existing file and appends the new data to it. Has anyone seen this problem before, and/or do I need to anything more than the following for the locking to work correctly:- It's not the locking. It's the flush mechanism. The mbox class doesn't know that the ONLY thing you did was an append. You might have modified other messages in the middle. If you want to do an append, you'll need to write your own subclass of mbox. OK, thanks. In reality I can probably just use straightforward file reading and writing as the *only* thing I will ever be doing is to append a message to a mailbox file. I think there should be a big warning in the mailbox documentation to this effect as doing it the way that Python's mailbox class does it will break all sorts of things. There should maybe be a specific 'append' method. File a documentation and/or library bug: http://bugs.python.org/ Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Checker 1.3 Released!
I'm pleased to announce a new release of Checker. This is a cross-platform, pluggable tool for comparing the configuration of a machine with a known configuration stored in text files in a source control system all written in Python. This release and the previous release fix ordering issues in file listings as well as generalise operating package listing to support RedHat-like systems in addition to Debian-like systems. For more information, please see: http://www.simplistix.co.uk/software/python/checker cheers, Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
On Aug 10, 10:05 am, Lawrence D'Oliveiro Can’t understand the point to it. “GUI automation” is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. Automating GUI is for testing. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is python not written in C++ ?
In message mailman.1863.1281378450.1673.python-l...@python.org, Christian Heimes wrote: There isn't really a point in cluttering the source with type casts. Makes you wonder why they bothered using a typed language at all. -- http://mail.python.org/mailman/listinfo/python-list
Re: delegate functions to member
Peter Otten wrote: Use getattr() class W(object): ... def __init__(self, wrapped): self._wrapped = wrapped ... def __getattr__(self, name): ... return getattr(self._wrapped, name) ... I thought there was something like this, thanks! :) When I read this, I thought OK, now I only have check first if the attribute can be looked up in 'self' first, but even that isn't the case. I tried it and added another function to class W above, which I can call just as if it was defined in _wrapped, so obviously (?) the __getattr__ lookup isn't done there. So, short follow-up question: Why does this work? Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace and inserting strings within .txt files with the use of regex
Please help me with these last changes before i try to perform an overall change. its almost done! -- http://mail.python.org/mailman/listinfo/python-list
Re: delegate functions to member
Ulrich Eckhardt wrote: Peter Otten wrote: Use getattr() class W(object): ... def __init__(self, wrapped): self._wrapped = wrapped ... def __getattr__(self, name): ... return getattr(self._wrapped, name) ... I thought there was something like this, thanks! :) When I read this, I thought OK, now I only have check first if the attribute can be looked up in 'self' first, but even that isn't the case. The getattr() call inside __getattr__() raises an AttributeError if it can't find an attribute called name in self._wrapped. This very thing you'd have to do if you wanted to signal that an attribute doesn't exist, like in class A: ... def __getattr__(self, name): ... if name == foo: return 42 ... raise AttributeError ... a = A() a.foo 42 a.bar Traceback (most recent call last): File stdin, line 1, in module File stdin, line 4, in __getattr__ AttributeError I tried it and added another function to class W above, which I can call just as if it was defined in _wrapped, so obviously (?) the __getattr__ lookup isn't done there. So, short follow-up question: Why does this work? __getattr__() is a fallback that is only tried when the normal lookup fails. If you need to intercept every attribute lookup use __getattribute__() instead: class A(object): ... def __getattr__(self, name): ... print __getattr__(%r) % name ... return 42 ... def __getattribute__(self, name): ... print __getattribute__(%r) % name ... return super(A, self).__getattribute__(name) ... a = A() a.foo = yadda a.foo __getattribute__('foo') 'yadda' a.bar __getattribute__('bar') __getattr__('bar') 42 Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Python why questions
Ben Finney wrote: D'Arcy J.M. Cain da...@druid.net writes: No. You are giving me math and logic but the subject was common sense. Common sense is often unhelpful, and in such cases the best way to teach something is to plainly contradict that common sense. Common sense, for example, would have the Earth as a flat surface with the Sun and Moon as roughly-identically-sized objects orbiting the Earth. Is it better to pander to that common sense, or to vigorously reject it in order to teach something more useful? I could'nt agree more. If it was not for my scolarship, I would gladly think that the earth is flat and the sun is moving around. It took thousands of years for *1* man to figure out that was wrong. So if there is one thing that common sense is not helpful, then that thing is finding the Truth. JM Ignorance is the mother of all traditions (V. Hugo) -- http://mail.python.org/mailman/listinfo/python-list
Newbie question - calculating prime numbers
Hey Everyone, I'm currently trying to work through MIT's opencourseware and am using python. The second assignment they offer is to determine the 1000th prime number. Below is the code I am using: #Assignment 1a #Determine the 1000th prime number candidate=3 #Already know that 2 is prime primeCount=1 while (primeCount=1000): for i in range (2,candidate): if ((candidate%i)==0): print(candidate, is not a prime) else: print(candidate, is a prime!) primeCount+=1 candidate+=2 Now I'm not looking for a solution, but I'm hoping that someone can at least tell me where the error in my logic is. The outer loop keeps count and will keep iterating until the 1000th prime number has been found. The inner loop just attempts to divide the candidate number by each possible factor until it's reached, and then increases the candidate number value by two since even numbers above 2 aren't prime. The if statement inside the inner loop simply checks if there is a remainder when attempting to divide the candidate by the possible factor. If there isn't, its a factor and we can print not a prime. If there is always a remainder, nothing is a factor and so the candidate is a prime. I figured it seemed simple enough, but I keep getting a massive output and almost nothing listed is a correct prime number. Please be gentle, its my first post and I haven't programmed in ages :) -Matty -- http://mail.python.org/mailman/listinfo/python-list
Weird Python behaviour
Hello, Lets say that I want to feed an optional list to class constructor: class Family(): def __init__(self, fName, members = []): self.fName = fName self.members = members Now, lets add members to two different instances of Family: f1 = Family(Smith) f1.members.append(Bill) f2 = Family(Smithers) f2.members.append(Joe) Finally, lets look at the members in the Smithers family: print f2.members output: ['Bill', 'Joe'] Why on earth is the output ['Bill', 'Joe']!? Is there a simple solution that separates f1 and f2 without forcing me to write code for the special case when you don't feed members to the __init__()-function? /Jonas -- http://mail.python.org/mailman/listinfo/python-list
Re: freeze function calls
Santiago Caracol wrote: Hello, I want to write a web application that does this: (1) The user submits a query: - | What is the answer? | - Submit (2) The web server gives the user N answers and a button saying More answers: . answer 1 . answer 2 . answer 3 More answers I am aware of several ways to do this: I could calculate all answers, but show only the first N of them. For certain kinds of calulations, I could use a kind of setoff argument. But I would like to do it in a more general and (hopefully) efficient way: I want the function or object that calculates the answers to be frozen at the point at which it has already calculated N answers. If the function gets a More answers-signal within a reasonable period of time, it goes on producing more answers exactly at the point at which it got frozen. If no signal is sent, the function call is terminated automatically after M seconds. Note that, although the program to be written is a web application, this is not a question about web application specific things. My only difficulty is how to freeze function calls. Has anyone done something of this kind? Python offers an elegant mechanism to calculate values on demand: the generator function: def calculate_answers(): ... for i in range(100): ... print calculating answer #%d % i ... yield i * i ... from itertools import islice gen = calculate_answers() This builds the generator but doesn't run the code inside. Now let's look at the first three answers: for answer in islice(gen, 3): ... print the answer is, answer ... calculating answer #0 the answer is 0 calculating answer #1 the answer is 1 calculating answer #2 the answer is 4 If you repeat the last step you get the next three answers: for answer in islice(gen, 3): ... print the answer is, answer ... calculating answer #3 the answer is 9 calculating answer #4 the answer is 16 calculating answer #5 the answer is 25 Peter -- http://mail.python.org/mailman/listinfo/python-list
shelf-like list?
I'm looking for a module that implements persistent lists: objects that behave like lists except that all their elements are stored on disk. IOW, the equivalent of shelves, but for lists rather than a dictionaries. Does anyone know of such a module? (I suppose that I could slap together a crude implementation of such a thing by wrapping a shelf with suitable methods to simulate the list interface. But I'd rather not roll my own if a tested implementation already exist.) TIA! ~K -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Python behaviour
Jonas Nilsson wrote: Lets say that I want to feed an optional list to class constructor: class Family(): def __init__(self, fName, members = []): Why on earth is the output ['Bill', 'Joe']!? Is there a simple solution that separates f1 and f2 without forcing me to write code for the special case when you don't feed members to the __init__()-function? Congrats; you just encountered a very popular new trap ;) The most recent explanation is only one day old: http://mail.python.org/pipermail/python-list/2010-August/1252316.html Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: delegate functions to member
Peter Otten wrote: Ulrich Eckhardt wrote: So, short follow-up question: Why does this work? __getattr__() is a fallback that is only tried when the normal lookup fails. If you need to intercept every attribute lookup use __getattribute__() instead: Thank you Peter, that was the missing piece to understand it! Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: freeze function calls
Python offers an elegant mechanism to calculate values on demand: the generator function: def calculate_answers(): ... for i in range(100): ... print calculating answer #%d % i ... yield i * i ... Thanks for pointing this out. I was aware of the yield statement. My problem is this: (1) The user submits a query: - | What is the answer? | - Submit (2) The web server gives the user N answers and a button saying More answers: . answer 1 . answer 2 . answer 3 More answers At this stage the function that writes html to the user has been called. The call must be terminated, or else, the user doesn't get any html. This means that the call of the answer-calculating function, whether it uses yield or not, is also terminated. This means, when the user presses the More answers-button, the calculation has to start at the beginning. -- http://mail.python.org/mailman/listinfo/python-list
Re: freeze function calls
Santiago Caracol wrote: Python offers an elegant mechanism to calculate values on demand: the generator function: def calculate_answers(): ... for i in range(100): ... print calculating answer #%d % i ... yield i * i ... Thanks for pointing this out. I was aware of the yield statement. My problem is this: (1) The user submits a query: - | What is the answer? | - Submit (2) The web server gives the user N answers and a button saying More answers: . answer 1 . answer 2 . answer 3 More answers At this stage the function that writes html to the user has been called. The call must be terminated, or else, the user doesn't get any html. This means that the call of the answer-calculating function, whether it uses yield or not, is also terminated. This means, when the user presses the More answers-button, the calculation has to start at the beginning. Adapted from the wsgiref documentation at http://docs.python.org/library/wsgiref.html $ cat wsgi_demo.py from wsgiref.util import setup_testing_defaults from wsgiref.simple_server import make_server from itertools import count, islice def answers(): for i in count(): yield Answer #%d\n % i gen = answers() def simple_app(environ, start_response): setup_testing_defaults(environ) status = '200 OK' headers = [('Content-type', 'text/plain')] start_response(status, headers) return islice(gen, 3) httpd = make_server('', 8000, simple_app) print Serving on port 8000... httpd.serve_forever() Run the above with $ python wsgi_demo.py Serving on port 8000... Now point your favourite browser to http://localhost:8000/ and hit refresh. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question - calculating prime numbers
Matty Sarro wrote: Hey Everyone, I'm currently trying to work through MIT's opencourseware and am using python. The second assignment they offer is to determine the 1000th prime number. Below is the code I am using: #Assignment 1a #Determine the 1000th prime number candidate=3 #Already know that 2 is prime primeCount=1 while (primeCount=1000): for i in range (2,candidate): if ((candidate%i)==0): print(candidate, is not a prime) else: print(candidate, is a prime!) primeCount+=1 candidate+=2 Now I'm not looking for a solution, but I'm hoping that someone can at least tell me where the error in my logic is. The outer loop keeps count and will keep iterating until the 1000th prime number has been found. The inner loop just attempts to divide the candidate number by each possible factor until it's reached, and then increases the candidate number value by two since even numbers above 2 aren't prime. The if statement inside the inner loop simply checks if there is a remainder when attempting to divide the candidate by the possible factor. If there isn't, its a factor and we can print not a prime. If there is always a remainder, nothing is a factor and so the candidate is a prime. I figured it seemed simple enough, but I keep getting a massive output and almost nothing listed is a correct prime number. Please be gentle, its my first post and I haven't programmed in ages :) -Matty Once you discover a particular value is not a prime, you need to get out of that for loop. Add a break after the appropriate print. Also, the print that says it IS a prime is misplaced. You only know that if you've gone all the way through the loop without ever hitting the break. That's a candidate for the 'else' clause of the for loop. There are other changes you could make for efficiency, but get it working correctly first. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question - calculating prime numbers
Hey Dave, Thank you for the heads up. I actually bashed my head against the desk a few times and eventually I realized what I was doing wrong. Here's my final code (slightly optimized) that's verified and working. Out of curiousity, what other optimizations could I throw at it (without diving too deep too fast). #Assignment 1a #Determine the 1000th prime number candidate=1 #Already know that 2 is prime primeCount=1 while (primeCount=1000): isPrime=true i=2 halfCand=(candidate/2) while (isPrime==true) and (i=halfCand): if ((candidate%i)==0): isPrime=false else: i+=1 if isPrime==true: print(candidate, is a prime.) primeCount+=1 #else: #print(candidate, is not a prime.) candidate+=2 print(The 1000th prime number is ,(candidate-2)) On Tue, Aug 10, 2010 at 8:51 AM, Dave Angel da...@ieee.org wrote: Matty Sarro wrote: Hey Everyone, I'm currently trying to work through MIT's opencourseware and am using python. The second assignment they offer is to determine the 1000th prime number. Below is the code I am using: #Assignment 1a #Determine the 1000th prime number candidate=3 #Already know that 2 is prime primeCount=1 while (primeCount=1000): for i in range (2,candidate): if ((candidate%i)==0): print(candidate, is not a prime) else: print(candidate, is a prime!) primeCount+=1 candidate+=2 Now I'm not looking for a solution, but I'm hoping that someone can at least tell me where the error in my logic is. The outer loop keeps count and will keep iterating until the 1000th prime number has been found. The inner loop just attempts to divide the candidate number by each possible factor until it's reached, and then increases the candidate number value by two since even numbers above 2 aren't prime. The if statement inside the inner loop simply checks if there is a remainder when attempting to divide the candidate by the possible factor. If there isn't, its a factor and we can print not a prime. If there is always a remainder, nothing is a factor and so the candidate is a prime. I figured it seemed simple enough, but I keep getting a massive output and almost nothing listed is a correct prime number. Please be gentle, its my first post and I haven't programmed in ages :) -Matty Once you discover a particular value is not a prime, you need to get out of that for loop. Add a break after the appropriate print. Also, the print that says it IS a prime is misplaced. You only know that if you've gone all the way through the loop without ever hitting the break. That's a candidate for the 'else' clause of the for loop. There are other changes you could make for efficiency, but get it working correctly first. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft lessening commitment to IronPython and IronRuby
Steven D'Aprano steve-remove-t...@cybersource.com.au writes: On Tue, 10 Aug 2010 20:07:06 +1200, Gregory Ewing wrote: Is there any way for a non-.NET program to access a .NET library? Or is it necessary to drink the entire bottle of .NET kool-aid? http://www.mono-project.com/Main_Page Anyone thinking of using Mono needs to be aware of the dangers of software patents in general, and of .NET in paticular. The copyright license for Mono is under free software terms. But that gives no license at all for the patents. Novell, who have an exclusive deal for those patents, happily encourages use of Mono by third parties. The controversy has raged for a number of years. For more coverage than you have time for, see URL:http://techrights.org/wiki/index.php/Mono. The issue has polarised discussion, unfortunately, and there is a lot of name-calling and hyperbole on the record now. As the Mono site hints, the patent situation for .NET is *very* muddy. Microsoft hold patents covering much of .NET, but have made a (non-binding) “Community Promise” that applies to *some* parts of .NET URL:http://www.mono-project.com/Licensing#Patents. -- \“It is seldom that liberty of any kind is lost all at once.” | `\ —David Hume | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question - calculating prime numbers
On 10/08/2010 12:57, Matty Sarro wrote: Hey Everyone, I'm currently trying to work through MIT's opencourseware and am using python. The second assignment they offer is to determine the 1000th prime number. Below is the code I am using: #Assignment 1a #Determine the 1000th prime number candidate=3 #Already know that 2 is prime primeCount=1 while (primeCount=1000): for i in range (2,candidate): if ((candidate%i)==0): print(candidate, is not a prime) else: print(candidate, is a prime!) primeCount+=1 candidate+=2 Now I'm not looking for a solution, but I'm hoping that someone can at least tell me where the error in my logic is. Hi Matty, Dave Angel has already given you some helpful stuff. I would only like to add that you need three states inside your loop a) Candidate is known to be prime b) Candidate is known to be not prime c) Candidate may or may not be prime and the code has to keep working on it. You are detecting the is not prime case correctly. The other two situations are confused. A candidate is only prime if it is not divisible by *any* number other than 1 or itself. Two hints for efficiency: If candidate has a factor, one of those factors MUST be = square root of candidate - so you don't need to loop through so many. If x is prime, all multiples of x are not prime. See sieve of Eratosthenes. Regards Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question - calculating prime numbers
Matty Sarro wrote: Hey Dave, Thank you for the heads up. I actually bashed my head against the desk a few times and eventually I realized what I was doing wrong. Here's my final code (slightly optimized) that's verified and working. Out of curiousity, what other optimizations could I throw at it (without diving too deep too fast). #Assignment 1a #Determine the 1000th prime number candidate=1 #Already know that 2 is prime primeCount=1 while (primeCount=1000): isPrime=true i=2 halfCand=(candidate/2) while (isPrime==true) and (i=halfCand): if ((candidate%i)==0): isPrime=false else: i+=1 if isPrime==true: print(candidate, is a prime.) primeCount+=1 #else: #print(candidate, is not a prime.) candidate+=2 print(The 1000th prime number is ,(candidate-2)) Congrats! One obvious thing would be to replace the true and false strings with actual boolean values: isPrime = True ... while isPrime and i = halfCand: ... etc. For a different perspective on the problem have a look at http://mail.python.org/pipermail/python-list/2009-November/1226626.html Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question - calculating prime numbers
Matty Sarro wrote: Hey Dave, Thank you for the heads up. I actually bashed my head against the desk a few times and eventually I realized what I was doing wrong. Here's my final code (slightly optimized) that's verified and working. Out of curiousity, what other optimizations could I throw at it (without diving too deep too fast). #Assignment 1a #Determine the 1000th prime number candidate=1 #Already know that 2 is prime primeCount=1 while (primeCount=1000): isPrime=true i=2 halfCand=(candidate/2) while (isPrime==true) and (i=halfCand): if ((candidate%i)==0): isPrime=false else: i+=1 if isPrime==true: print(candidate, is a prime.) primeCount+=1 #else: #print(candidate, is not a prime.) candidate+=2 print(The 1000th prime number is ,(candidate-2)) snip You top-posted, which messed up the message sequence. You should post your message AFTER whatever you're quoting. Your code starts by printing that 1 is prime, which it's not. And it doesn't print 2. Those two errors happen to cancel, so the 1000th prime is still right. But the initial value for candidate= should be 3, not 1. I didn't try to figure where the other error is, but somewhere your count is off by one. You've changed your code from using the built-in control flow to doing it by hand. That's almost never a good idea, and in this case it'll slow you down. Learn about the break statement to break out of a for loop or while loop. It saves doing multiple tests in the loop construct. Use True and False, not strings. Your halfCand could have been rootCand; you only need to check up to the square root of the candidate (see math.sqrt()). In fact, you only need to check those primes you've already built, up to the square root. For example, to tell if 23 is prime, you only need to divide by 2, 3 and 5. This would require that you build a list of results, appending to it whenever you find a new prime. It would mean that primeCount is not needed, as it's simply len(primeList). I don't know which of these ideas has already been covered in your class. But if you used all of these ideas, your code would be smaller and much faster. Currently, it spends more time in the print statements than in calculating, so I temporarily commented out the print of the first 999 primes. I coded up a quick version, and without the prints of individual primes, it sped up 1.3 secs to 0.03 secs. If I have both versions do the first 10,000 primes, the original takes 176 secs, while mine takes 0.5 DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python why questions
On Tue, 10 Aug 2010 13:51:17 +0200 Jean-Michel Pichavant jeanmic...@sequans.com wrote: Pardon the response to the response. I missed Ben's message. Ben Finney wrote: D'Arcy J.M. Cain da...@druid.net writes: No. You are giving me math and logic but the subject was common sense. Common sense is often unhelpful, and in such cases the best way to teach something is to plainly contradict that common sense. I even agree with you. However, the OP was claiming that zero based counting contradicted common sense and that was what I was responding to. I would never use common sense to prove anything. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: freeze function calls
Run the above with $ python wsgi_demo.py Serving on port 8000... Thanks a lot for this code. The problem with it is that the whole application IS a generator function. That means that if I run the code at, say foo.org, then any user that visits the site will augment the answer number of the server running at foo.org. What I am trying to do is to process specific queries for different users. Each user is supposed to get his very own answers to his very own questions. And if a user doesn't hit the More answers-button during a certain period of time, the generator or function call reponsible for answering his question is supposed to be killed or thrown-away or forgotten. If the user asks a new question (while the answers to the old question are still being displayed), then the generator or function call is also supposed to be forgotten and a new generator or function call -- one that matches the user's new question -- is supposed to be initiated. Santiago -- http://mail.python.org/mailman/listinfo/python-list
how to save a whole web page with something block
Hi everyone, I want to save a web page. I use urllib to parse the web page. But I find the saved file, where some content is missing. The missing part is block from the original web page, such as this part div style=display: block; id=GeneInts.../div.I don't know how to parse a whole page without something block in it. Could you help me figure it out? Thank you! This is my program url = 'http://receptome.stanford.edu/hpmr/SearchDB/getGenePage.asp? Param=4502931ProtId=1ProtType=Receptor' f = urllib.urlretrieve(url,'test.html') -- http://mail.python.org/mailman/listinfo/python-list
Re: How to capture all the environment variables from shell?
On 8/2/2010 4:33 AM, Thorsten Kampe wrote: * Tim Chase (Mon, 26 Jul 2010 21:42:24 -0500) On 07/26/10 21:26, Steven W. Orr wrote: Please! Never export anything from your .bashrc unless you really know what you're doing. Almost all exports should be done in your .bash_profile Could you elaborate on your reasoning why (or why-not)? I've found that my .bash_profile doesn't get evaluated when I crank up another terminal window, while my bashrc does. Thus I tend to put my exports in my ~/.bashrc so they actually take effect in my shell... ~/.bash_profile is only evaluated for login shells and ~/.bashrc only for non-login shells. Thus it's recommended to keep ~/.bash_profile empty (except a source statement for .bashrc) and put all your settings, aliases, exports, etc. in .bashrc. Thorsten Sorry. Dead wrong. Please reread the above comment I wrote. If you set your environment variables in the .bashrc then you completely lose the ability of environment variables to be inherited by sub-shells. Again, envvars should be set in the .bash_profile, most everything else should be set in the .bashrc, and the .bashrc should be sourced into the .bash_profile to solve the problem that you thought you were solving. After that, and again, be aware that the .bashrc alone is executed for login shells *which are not interactive*. for example: ssh somemachine 'echo Hello' This command will *not* go through the .bash_profile but it will go through the .bashrc. This means that for cases like this, we want to check to see if the bash process is interactive or not inside the .bashrc and then do the right thing. Inside your .bashrc=== [[ -z $PS1 ]] setPATHHere EOInside your .bashrc=== This is not needed for the above degenerate case, but it is needed if the command in question is kept in a directory that you normally find in a place that is part of your personal login PATH. E.G., If myprog lives in ~/bin then ssh somemachine myprog will fail unless you use the above construct. Hopefully, I'll only have to re-explain this another google times... -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net steve orr -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Python behaviour
On Tue, Aug 10, 2010 at 4:58 AM, Jonas Nilsson j...@spray.se wrote: Hello, Lets say that I want to feed an optional list to class constructor: class Family(): def __init__(self, fName, members = []): self.fName = fName self.members = members Now, lets add members to two different instances of Family: f1 = Family(Smith) f1.members.append(Bill) f2 = Family(Smithers) f2.members.append(Joe) Finally, lets look at the members in the Smithers family: print f2.members output: ['Bill', 'Joe'] Why on earth is the output ['Bill', 'Joe']!? Is there a simple solution that separates f1 and f2 without forcing me to write code for the special case when you don't feed members to the __init__()-function? /Jonas In python, a function definition is an executable statement, not a declaration. Default args only get evaluated once- when the function is first created. You have to use a sentinel value and create the object inside the function if you want it to get executed every time. class Family(): def __init__(self, fName, members = None): if members is None : members = [] self.fName = fName self.members = members If None is a valid argument to this function, then make a dummy object and check identity (to make sure it's *that* object and not just something that evaluates equal). sentinel = object() def something_that_accepts_none(foo = sentinel) : if foo is sentinel : foo = {} # other stuff -- http://mail.python.org/mailman/listinfo/python-list
Re: File Manager in Tkinter
On Tue, 10 Aug 2010 10:40:53 +0200, Eric Brunel eric.bru...@pragmadev.com wrote: In article d4m1661blus6baj1lrd37j5vk4dau35...@4ax.com, John wrote: As a learning exercise in Tkinter I htought about making a very simple and basic file manager for my own use. I tried searching google for any sample project and could not find anything. Not exactly sure how to start I tought I could ask here? I thought about making two listboxes one to list folders only the other files inside. I tried to make one listbox first but did not know how to list folders only. You just have to filter them explicitely by using os.path.isdir on each file name. from Tkinter import * import os path = D:\\ s = Scrollbar() L = Listbox() s.pack(side=RIGHT, fill=Y) L.pack(side=LEFT, fill=Y) s.config(command=L.yview) L.config(yscrollcommand=s.set) for filename in os.listdir(path): Add here: if os.path.isdir(os.path.join(path, filename)): L.insert(END, filename) mainloop() Is there a way to list folders with images? AFAIK, not with a Listbox. You can do it with a Canvas, but it's much more complicated than using a Listbox, so maybe you should try to make your Listbox-only version works first. Any suggestions or help how to proced would be appreciated. Thank you Good luck! Thank you both for the suggestions. Have you ever tried to make one? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to save a whole web page with something block
I want to save a web page. I use urllib to parse the web page. But I find the saved file, where some content is missing. The missing part is block from the original web page, such as this part div style=display: block; id=GeneInts.../div.I don't know how to parse a whole page without something block in it. Could you help me figure it out? Thank you! This is my program url = 'http://receptome.stanford.edu/hpmr/SearchDB/getGenePage.asp? Param=4502931ProtId=1ProtType=Receptor' f = urllib.urlretrieve(url,'test.html') A web server may present different output depending on the client used. When you use your browser to look at the source and then use urllib's saved file you access the web server with different clients. I'm not saying this is your problem, but potentially it is. So you might want to make urllib appear as a browser by sending the appropriate headers. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Python behaviour
On 10 Ago, 13:58, Jonas Nilsson j...@spray.se wrote: Hello, Lets say that I want to feed an optional list to class constructor: class Family(): def __init__(self, fName, members = []): self.fName = fName self.members = members Now, lets add members to two different instances of Family: f1 = Family(Smith) f1.members.append(Bill) f2 = Family(Smithers) f2.members.append(Joe) Finally, lets look at the members in the Smithers family: print f2.members output: ['Bill', 'Joe'] Why on earth is the output ['Bill', 'Joe']!? Is there a simple solution that separates f1 and f2 without forcing me to write code for the special case when you don't feed members to the __init__()-function? /Jonas You stumbled in two python common pitfalls at once :-) One, the default arguments issue, was already pointed to you. The other one is that python variables are just names for objects. Assigning a variable never mean making a copy, it just means using another name for the same object. There used to be a very nice (also graphic) explanationor this somewhere on the web, but my googling skills failed me this time, so instead I'll show you the concept using your own code: class Family: ... def __init__(self, fName, members = []): ... self.fname = fName ... self.members = members ... mlist = [Bill] f1 = Family(Smiths, mlist ) mlist.append( John ) # attempt to not-so-clever reyse of the sme variable f2 = Family(Smithers, mlist ) f1.members ['Bill', 'John'] Now my example is a bit contrieved but I'm sure you got the idea : in your example is better to copy the list with self.members = members[:]. Better yet, you could make use of python arguments grouping feature : class Family: ... def __init__(self, fName, *members ): ... self.members = list(members) # because members is a tuple ... self.fname = fName ... f1 = Family(Smith) f1.members.append(Bill) f2 = Family(Smithers) f2.members.append(Joe) f2.members ['Joe'] f1.members ['Bill'] This solves your no initial member special case and allows for an easier syntax for creating class instances (no brackets involved) f3 = Family(Bochicchio, Angelo, Francesco, Mario) f3.members ['Angelo', 'Francesco', 'Mario'] Ciao FB -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace and inserting strings within .txt files with the use of regex
Νίκος wrote: [snip] The ID number of each php page was contained in the old php code within this string PageID = some_number So instead of create a new ID number for eaqch page i have to pull out this number to store to the beginnign to the file as comment line, because it has direct relationship with the mysql database as in tracking the number of each webpage and finding the counter of it. # Grab the PageID contained within the php code and store it in id variable id = re.search( 'PageID = ', src_data ) How to tell Python to Grab that number after 'PageID = ' string and to store it in var id that a later use in the program? If the part of the file you're trying to match look like this: PageID = 12 then the regex should look like this: PageID = (\d+) and the code should look like this: page_id = re.search(r'PageID = (\d+)', src_data).group(1) The page_id will, of course, be a string. also i made another changewould something like this work: === # open same php file for storing modified data print ( 'writing to %s' % dest_f ) f = open(src_f, 'w') f.write(src_data) f.close() # rename edited .php file to .html extension dst_f = src_f.replace('.php', '.html') os.rename( src_f, dst_f ) === Because instead of creating a new .html file and inserting the desired data of the old php thus having two files(old php, and new html) i decided to open the same php file for writing that data and then rename it to html. Would the above code work? Why wouldn't it? -- http://mail.python.org/mailman/listinfo/python-list
Re: freeze function calls
Santiago Caracol wrote: Run the above with $ python wsgi_demo.py Serving on port 8000... Thanks a lot for this code. The problem with it is that the whole application IS a generator function. That means that if I run the code at, say foo.org, then any user that visits the site will augment the answer number of the server running at foo.org. What I am trying to do is to process specific queries for different users. Each user is supposed to get his very own answers to his very own questions. And if a user doesn't hit the More answers-button during a certain period of time, the generator or function call reponsible for answering his question is supposed to be killed or thrown-away or forgotten. If the user asks a new question (while the answers to the old question are still being displayed), then the generator or function call is also supposed to be forgotten and a new generator or function call -- one that matches the user's new question -- is supposed to be initiated. Didn't you say you weren't interested in the web specific aspects? You may be able to do it by hand (the environ argument will probably include an IP that you can use to look up the generator in a dictionary) but I'd rather say you need a web framework that provides the session management. Cherrypy is a lightweight one, and after some try and way too much error I came up with # warning: newbie code import cherrypy from itertools import islice, count def answers(): for i in count(): yield Answer #%d\n % i class PythonRunner(object): def index(self): try: gen = cherrypy.session[gen] except KeyError: cherrypy.session[gen] = gen = answers() return htmlbody%s/body/html % .join(islice(gen, 3)) index.exposed = True if __name__ == '__main__': cherrypy.quickstart(PythonRunner(), config=cherry.conf) The contents of cherry.conf are: [global] server.socket_host = 127.0.0.1 server.socket_port = 8080 server.thread_pool = 10 [/] tools.sessions.on = True #tools.sessions.storage_type = file #tools.sessions.storage_path = ./sessions tools.sessions.timeout = 60 See the result on http://localhost:8080/index I opened the page in Firefox and Konqueror, and the numbers were independent, so I'm pretty sure it works on a bigger scale, too. $ python -c 'import cherrypy; print cherrypy.__version__' 3.1.2 Note that storage_type = file is straight out for generators because they cannot be pickled. The workaround here would be a class like class Answers(object): def __init__(self): self.i = 0 def __iter__(self): return self def next(self): result = Answer #%d\n % self.i self.i += 1 return result Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Python behaviour
Hi, On 2010-08-10 17:01, Francesco Bochicchio wrote: There used to be a very nice (also graphic) explanationor this somewhere on the web, but my googling skills failed me this time, so instead I'll show you the concept using your own code: Probably this isn't the page you're referring to, but I only recently gave a beginners' talk at EuroPython: http://sschwarzer.com/download/robust_python_programs_europython2010.pdf The topic of identity and assignments starts on slide 7, nice graphics start on slide 10. ;-) Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: File Manager in Tkinter
On Aug 9, 9:53 pm, John wrote: As a learning exercise in Tkinter I htought about making a very simple and basic file manager for my own use. I tried searching google for any sample project and could not find anything. Not exactly sure how to start I tought I could ask here? I thought about making two listboxes one to list folders only the other files inside. I tried to make one listbox first but did not know how to list folders only. Filter with os.path.isdir() Is there a way to list folders with images? Any suggestions or help how to proced would be appreciated. If you are using a Tkinter with Ttk (Tk 8.5), then use the treeview widget: http://docs.activestate.com/activepython/3.1/python/library/tkinter.ttk.html For more advanced needs, there is a Tk extension called tktreectrl that does some very cool views and has lots of controls: http://tktreectrl.sourceforge.net/ Jeff -- http://mail.python.org/mailman/listinfo/python-list
Re: Microsoft lessening commitment to IronPython and IronRuby
On 08/10/2010 02:07 AM, Gregory Ewing wrote: Tim Roberts wrote: I'm not sure that's really fair. The .NET Common Language Runtime is a vast and very useful class library, including two complete GUI systems. The thought was that IronPython and IronRuby would let people who were comfortable in those languages tap into the CLR. Is there any way for a non-.NET program to access a .NET library? Or is it necessary to drink the entire bottle of .NET kool-aid? Well the only way for a non-.net program to access a .NET library is to either embed .NET or use some kind of bridge via RPC. So basically, the answer is no. You pretty much have to embrace .NET or not use it. -- http://mail.python.org/mailman/listinfo/python-list
Re: File Manager in Tkinter
On Tue, 10 Aug 2010 10:58:39 -0400 j...@mail.python.org wrote: Thank you both for the suggestions. Have you ever tried to make one? -- http://mail.python.org/mailman/listinfo/python-list I don't know if my first reply went out so I'll repeat Here is a list box dialog written to allow selection of one of a specific type of file. It is a method in a larger gui object that controls hardware on a remote machine (called a PAN) and loads commands from files. def modeFiles(self): try: sysFile = self.chkConnected() except Disconnect,e: return (False, '') self.pan.ppxGetAVP( ('modeFdir', ) ) dir = self.pan.avps['modeFdir'].get() fileList = fetchModFiles(self.pan, dir=dir) flist = [] for file in fileList: idx = rfind(file, '/') flist.append(file[idx+1:]) dlg = Pmw.ComboBoxDialog(self.parent, title = 'Mode File Select', buttons=('Load', 'Cancel'), defaultbutton='Load', combobox_labelpos=N, label_text='Which Mode file to load', scrolledlist_items=flist, listbox_width=32) dlg.geometry('240x300+30+250') dlg.tkraise() result = dlg.activate(geometry='240x300+30+250') if result == 'Load': print loading %s/%s %(dir, dlg.get()) self.pan.ppxSetMode( (dlg.get(),) ) else: print leaving here is fetchModFilesz def fetchModFiles(pan=None, dir=None): A function to read mod files on remote pan in directory dir fileList = [] if pan is not None: if dir is None: rCmd = /bin/echo $MONSOON_HOME dir = commands.getoutput(ssh -X -l monsoon %s '%s' % (pan.panName, rCmd) ) dir = dir+os.sep+'_'+pan.sysName lsCmd = /bin/ls %s/*.mod%(dir,) resp = commands.getoutput(ssh -X -l monsoon %s '%s'% (pan.panName, lsCmd)) fileList = resp.split(\n) else: pass return fileList Someday I may have time to go back and clean these up and generalize them. But as the only software guy on a 3 man-year project due to complete in 9 months quick and dirty is the rule. Nick nbuchh...@noao.edu Day phone: (520) 318-8203 Time is an illusion, Lunchtime doubly so - Ford Prefect Time is an illusion perpetrated by the manufacturers of space. -- http://mail.python.org/mailman/listinfo/python-list
Re: File Manager in Tkinter
On Tue, 10 Aug 2010 09:20:31 -0700 (PDT), Jeff Hobbs jeff.ho...@gmail.com wrote: On Aug 9, 9:53 pm, John wrote: As a learning exercise in Tkinter I htought about making a very simple and basic file manager for my own use. I tried searching google for any sample project and could not find anything. Not exactly sure how to start I tought I could ask here? I thought about making two listboxes one to list folders only the other files inside. I tried to make one listbox first but did not know how to list folders only. Filter with os.path.isdir() Is there a way to list folders with images? Any suggestions or help how to proced would be appreciated. If you are using a Tkinter with Ttk (Tk 8.5), then use the treeview widget: http://docs.activestate.com/activepython/3.1/python/library/tkinter.ttk.html For more advanced needs, there is a Tk extension called tktreectrl that does some very cool views and has lots of controls: http://tktreectrl.sourceforge.net/ Jeff My python is version 2.6.5. Would you recomend I upgrade and if yes to which version? from tkinter import ttk Traceback (most recent call last): File pyshell#0, line 1, in module from tkinter import ttk ImportError: No module named tkinter -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Python behaviour
On 10 Ago, 13:58, Jonas Nilsson j...@spray.se wrote: You stumbled in two python common pitfalls at once :-) One, the default arguments issue, was already pointed to you. The other one is that python variables are just names for objects. Assigning a variable never mean making a copy, it just means using another name for the same object. There used to be a very nice (also graphic) explanationor this somewhere on the web, but my googling skills failed me this time, so instead I'll show you the concept using your own code: class Family: ... def __init__(self, fName, members = []): ... self.fname = fName ... self.members = members ... mlist = [Bill] f1 = Family(Smiths, mlist ) mlist.append( John ) # attempt to not-so-clever reyse of the sme variable f2 = Family(Smithers, mlist ) f1.members ['Bill', 'John'] Now my example is a bit contrieved but I'm sure you got the idea : in your example is better to copy the list with self.members = members[:]. Better yet, you could make use of python arguments grouping feature : class Family: ... def __init__(self, fName, *members ): ... self.members = list(members) # because members is a tuple ... self.fname = fName ... f1 = Family(Smith) f1.members.append(Bill) f2 = Family(Smithers) f2.members.append(Joe) f2.members ['Joe'] f1.members ['Bill'] This solves your no initial member special case and allows for an easier syntax for creating class instances (no brackets involved) f3 = Family(Bochicchio, Angelo, Francesco, Mario) f3.members ['Angelo', 'Francesco', 'Mario'] Ciao FB Thanks everyone. I was a bit steamed about the problem as it was very unexpected. Because I couldn't figure out what key words to google on, I resorted to posting the problem here. /Jonas -- http://mail.python.org/mailman/listinfo/python-list
type enforcement in _ssl.sslwrap
ssl.SSLSocket.__init__ makes a call to _ssl.sslwrap (in the C module). That in turn makes a call to PyArg_ParseTuple, which casts the first arg of _ssl.sslwrap into a PySocketModule.Sock_Type object. My problem is that I am trying to pass in an object that implements the Socket interface, but does not inherit from _socket.socket, like you do with file-like objects. Is there a way to make this work, or is the PyArg_ParseTuple call going to stop me. Would I need to have _ssl.sslwrap do something differently with its args? -eric -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird Python behaviour
On 10 Ago, 17:57, Stefan Schwarzer sschwar...@sschwarzer.net wrote: Hi, On 2010-08-10 17:01, Francesco Bochicchio wrote: There used to be a very nice (also graphic) explanationor this somewhere on the web, but my googling skills failed me this time, so instead I'll show you the concept using your own code: Probably this isn't the page you're referring to, but I only recently gave a beginners' talk at EuroPython: http://sschwarzer.com/download/robust_python_programs_europython2010.pdf The topic of identity and assignments starts on slide 7, nice graphics start on slide 10. ;-) Stefan Also good :-) But I finally found the page I was referring to: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables Ciao --- FB -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is python not written in C++ ?
On Aug 10, 12:06 am, Ulrich Eckhardt eckha...@satorlaser.com wrote: Carl Banks wrote: I highly doubt the Python source would build with a C++ compiler. As Christian showed, it doesn't. However, look around the sources a bit. There are lots of places where e.g. the returnvalue of malloc() (or, rather, the macro that resolves to something like it) is explicitly type-cast to the according pointer type. When asked on the developers' list, it was said that this was intended for compatibility with C++, e.g. in cases where people want to embed Python into their C++ projects. Of course, this contradicts Christian's statement that C++ compatibility wasn't considered useful enough. I question why it needs to be compatible with C++ to be able to embed Python in a C++ project. How many C++ compilers out there don't come bundled with a C compiler? Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
On 08/10/2010 12:25 PM, Alex Barna wrote: On Aug 10, 10:05 am, Lawrence D'Oliveiro Can’t understand the point to it. “GUI automation” is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. Automating GUI is for testing. And sometimesfor working around SW, whch has no cli or other interface and should be automated -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
On 08/10/10 20:13, News123 wrote: On 08/10/2010 12:25 PM, Alex Barna wrote: On Aug 10, 10:05 am, Lawrence D'Oliveiro Can’t understand the point to it. “GUI automation” is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. Automating GUI is for testing. And sometimesfor working around SW, whch has no cli or other interface and should be automated That and when you are forced using a gui and need to 'copy and paste' between two programs that have no native bridge except for the one that is between the keyboard and chair, then it is nice to know that there is a way of automating it. -- mph -- http://mail.python.org/mailman/listinfo/python-list
Re: python interview quuestions
James Mills prolo...@shortcircuit.net.au writes: On Sat, Aug 7, 2010 at 4:32 AM, Tim Chase python.l...@tim.thechases.com wrote: I would like to aquint myself with Python Interview questions This came up a while ago: http://www.mail-archive.com/python-list@python.org/msg168961.html Most of that thread is still relevant (perhaps throw in some py3l questions too) A common thing you can do in interviews is ask your interviewee to write (in Python) a solution to the FizzBuzz problem. Any good competent Python programmer should be able to do this in 5-10mins (5 if you're good). cheers james Fizzbuzz is annoying in interviews. I've never worked at a job where I was under a timer while a group of people sat across from me and scrutinized everything I was doing. I don't see how it can honestly tell you anything useful about the person you're interviewing either. Do you really think that what you assume about the interviewee based on characteristics you can infer from their solution to be really, honestly true? They might even completely bomb the solution and still be a brilliant programmer, but you'll never know that if you trust this simple fizzbuzz test. I've been in those interviews on both sides of the table. Neither side was a good experience. If a test is necessary, make it a take-home or demand source code if they have it. Read their code and judge for yourself the quality of their work. Any questions in an interview should be the usual get to know you type stuff. What was the most difficult challenge you've faced on the job? How did you respond? That sort of thing. -- http://mail.python.org/mailman/listinfo/python-list
a article on does lang influence thought
Great article. 〈Lost in Translation〉 (2010-07-23), by By Lera Boroditsky. From The Wall Street Journal. “New cognitive research suggests that language profoundly influences the way people see the world; a different sense of blame in Japanese and Spanish” http://online.wsj.com/article/SB10001424052748703467304575383131592767868.html no surprise to lispers. though, standard caution apply here... do take the findings in the story lightly, as such non-scientific writing usually are full of vague notions, misleading, and sometimes outright incorrect. Also, for those of you dumb mono-USers... perhaps it's time to pick up another lang. lol and, time to learn lojban too! • Xah's lojban page http://xahlee.org/lojban/lojban.html Xah ∑ http://xahlee.org/ ☄ -- http://mail.python.org/mailman/listinfo/python-list
Re: python interview quuestions
On Tue, Aug 10, 2010 at 1:44 PM, J Kenneth King ja...@agentultra.com wrote: James Mills prolo...@shortcircuit.net.au writes: On Sat, Aug 7, 2010 at 4:32 AM, Tim Chase python.l...@tim.thechases.com wrote: I would like to aquint myself with Python Interview questions This came up a while ago: http://www.mail-archive.com/python-list@python.org/msg168961.html Most of that thread is still relevant (perhaps throw in some py3l questions too) A common thing you can do in interviews is ask your interviewee to write (in Python) a solution to the FizzBuzz problem. Any good competent Python programmer should be able to do this in 5-10mins (5 if you're good). cheers james Fizzbuzz is annoying in interviews. I've never worked at a job where I was under a timer while a group of people sat across from me and scrutinized everything I was doing. I don't see how it can honestly tell you anything useful about the person you're interviewing either. Do you really think that what you assume about the interviewee based on characteristics you can infer from their solution to be really, honestly true? They might even completely bomb the solution and still be a brilliant programmer, but you'll never know that if you trust this simple fizzbuzz test. The interviews where I've been asked to write code, the interviewers had almost no interest in the code I actually wrote. They wanted me to think out loud, to see how I approached the problem. To make sure I did actually know how to program and not just copy/paste from a text book. I've been in those interviews on both sides of the table. Neither side was a good experience. If a test is necessary, make it a take-home or demand source code if they have it. Read their code and judge for yourself the quality of their work. Any questions in an interview should be the usual get to know you type stuff. What was the most difficult challenge you've faced on the job? How did you respond? That sort of thing. -- Now those questions are completely useless for those of us still in school. Because almost nothing we've done so far really says anything about how we'll do on the job. When I get an interview like that, I usually end up with the same 2-3 responses to every single question, because those are the only experieces I've had outside of well I had this tough homework assignment. -- http://mail.python.org/mailman/listinfo/python-list
Re: Image histogram
Yes, my question is regarding PIL. And basically I need to reload an image given a new histogram. The new histogram has still the same amount of overall pixels however I have only switched a couple of picks. Another thing I have tried was using a function that could be given to the point module but problem with that was that I didnt want to apply the function to every single count in the histogram. I only need to change two or three picks there. Is this something that could be done with PIL modules at all? Thank you and sorry for the confusion, Anahita On Mon, Aug 9, 2010 at 4:27 PM, Anahita Yazdi atya...@ucdavis.edu wrote: Hi, I was just wondering how would I be able to get some extra help regarding editing an image's histogram using python's module? I have modified a histogram of an image however I dont know how to apply the new histogram to the image and basically reload the image based on its new modified histogram instead of its own histogram? In the other words how should I make changes on an image's histogram in a way that the image recognizes the new histogram and gets changed? I need to somehow introduce a LUT for the image and use .point(table) function to reload the image however I am not sure how to make the right LUT from a modified histogram! Thanks for the help in advance, Anahita -- http://mail.python.org/mailman/listinfo/python-list
Re: File Manager in Tkinter
On Aug 10, 9:43 am, John wrote: On Tue, 10 Aug 2010 09:20:31 -0700 (PDT), Jeff Hobbs jeff.ho...@gmail.com wrote: On Aug 9, 9:53 pm, John wrote: As a learning exercise in Tkinter I htought about making a very simple and basic file manager for my own use. I tried searching google for any sample project and could not find anything. Not exactly sure how to start I tought I could ask here? I thought about making two listboxes one to list folders only the other files inside. I tried to make one listbox first but did not know how to list folders only. Filter with os.path.isdir() Is there a way to list folders with images? Any suggestions or help how to proced would be appreciated. If you are using a Tkinter with Ttk (Tk 8.5), then use the treeview widget: http://docs.activestate.com/activepython/3.1/python/library/tkinter.t... For more advanced needs, there is a Tk extension called tktreectrl that does some very cool views and has lots of controls: http://tktreectrl.sourceforge.net/ Jeff My python is version 2.6.5. Would you recomend I upgrade and if yes to which version? The version of python really isn't tightly coupled to the version of Tk, it is the configuration of how that python is built. ActivePython builds with Tk 8.5, so if you are using that, and it is v3.1 (where ttk is in the core), then just do: pypm install pyttk which will install the wrapper you need for Ttk into v2.6 or 2.7 python. You need to make sure that you have Tk 8.5 (Tkinter.TkVersion = 8.5) for ttk to work (though not technically true, the 8.4 tile version has subtle differences). The core python distro is still using the older Tk 8.4 in stock installers iiuc. Jeff -- http://mail.python.org/mailman/listinfo/python-list
Re: File Manager in Tkinter
On Tue, 10 Aug 2010 14:51:14 -0700 (PDT), Jeff Hobbs jeff.ho...@gmail.com wrote: On Aug 10, 9:43 am, John wrote: On Tue, 10 Aug 2010 09:20:31 -0700 (PDT), Jeff Hobbs jeff.ho...@gmail.com wrote: On Aug 9, 9:53 pm, John wrote: As a learning exercise in Tkinter I htought about making a very simple and basic file manager for my own use. I tried searching google for any sample project and could not find anything. Not exactly sure how to start I tought I could ask here? I thought about making two listboxes one to list folders only the other files inside. I tried to make one listbox first but did not know how to list folders only. Filter with os.path.isdir() Is there a way to list folders with images? Any suggestions or help how to proced would be appreciated. If you are using a Tkinter with Ttk (Tk 8.5), then use the treeview widget: http://docs.activestate.com/activepython/3.1/python/library/tkinter.t... For more advanced needs, there is a Tk extension called tktreectrl that does some very cool views and has lots of controls: http://tktreectrl.sourceforge.net/ Jeff My python is version 2.6.5. Would you recomend I upgrade and if yes to which version? The version of python really isn't tightly coupled to the version of Tk, it is the configuration of how that python is built. ActivePython builds with Tk 8.5, so if you are using that, and it is v3.1 (where ttk is in the core), then just do: pypm install pyttk which will install the wrapper you need for Ttk into v2.6 or 2.7 python. You need to make sure that you have Tk 8.5 (Tkinter.TkVersion = 8.5) for ttk to work (though not technically true, the 8.4 tile version has subtle differences). The core python distro is still using the older Tk 8.4 in stock installers iiuc. Jeff My version is from python.org can I upgrade my version to 8.5? tia for all the help much appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: python interview quuestions
Agreed. Although anything that involves take home or reading of their code runs the risk of the candidate presenting somebody else's work... It was never a good experience being responsible for the hiring of somebody based on how well they sell themselves in an interview - some people are hopeless sales people and yet could be fantastic programmers! I mean lets face it, if you were good at selling would you still be a programmer? :-) I know who makes the most money! Of course there is the question of job satisfaction... I usually just tried to get a feel for their stated experience and ask some questions just to make sure they weren't presenting somebodies else's (fictitious even!) resume. You generally make the best decision based on a number of factors about each candidate and depend on the 3 or 6 month trial period to weed out any bad mistakes you may have made during selection! I remember one team I managed had an individual from overseas (I won't mention the country or anything) - and therefore background checks by HR were not really possible. The person made so many fundamental mistakes that I went to the project manager and asked to see the resume - there was no way in this world that they had ever done even 1/100th of what their resume stated! :-) Obviously the interviewers for that person where completely conned and missed the (what should have been) obvious signs that the resume and candidate did not match. This was one of the many reasons why I decided on a career change and went back to being a dumb and happy programmer! That was 14 years ago now and I haven't regretted the decision one single day of that time :-) Peter On Aug 11, 6:44 am, J Kenneth King ja...@agentultra.com wrote: James Mills prolo...@shortcircuit.net.au writes: On Sat, Aug 7, 2010 at 4:32 AM, Tim Chase python.l...@tim.thechases.com wrote: I would like to aquint myself with Python Interview questions This came up a while ago: http://www.mail-archive.com/python-l...@python.org/msg168961.html Most of that thread is still relevant (perhaps throw in some py3l questions too) A common thing you can do in interviews is ask your interviewee to write (in Python) a solution to the FizzBuzz problem. Any good competent Python programmer should be able to do this in 5-10mins (5 if you're good). cheers james Fizzbuzz is annoying in interviews. I've never worked at a job where I was under a timer while a group of people sat across from me and scrutinized everything I was doing. I don't see how it can honestly tell you anything useful about the person you're interviewing either. Do you really think that what you assume about the interviewee based on characteristics you can infer from their solution to be really, honestly true? They might even completely bomb the solution and still be a brilliant programmer, but you'll never know that if you trust this simple fizzbuzz test. I've been in those interviews on both sides of the table. Neither side was a good experience. If a test is necessary, make it a take-home or demand source code if they have it. Read their code and judge for yourself the quality of their work. Any questions in an interview should be the usual get to know you type stuff. What was the most difficult challenge you've faced on the job? How did you respond? That sort of thing. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is python not written in C++ ?
Am 10.08.2010 09:06, schrieb Ulrich Eckhardt: Carl Banks wrote: I highly doubt the Python source would build with a C++ compiler. As Christian showed, it doesn't. However, look around the sources a bit. There are lots of places where e.g. the returnvalue of malloc() (or, rather, the macro that resolves to something like it) is explicitly type-cast to the according pointer type. When asked on the developers' list, it was said that this was intended for compatibility with C++, e.g. in cases where people want to embed Python into their C++ projects. Of course, this contradicts Christian's statement that C++ compatibility wasn't considered useful enough. It doesn't contradict at all. In order to embed Python into a C++ application, it is sufficient if the Python header files can be compiled with a C++ compiler, and linking to the C function works properly - which is indeed the case. People integrate Python with C++ quite often, both for embedding it into C++, and for writing extension modules in C++. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: python interview quuestions
In article 507f1970-9c15-4200-a90b-6ebc018c0...@a4g2000prm.googlegroups.com, Peter peter.milli...@gmail.com wrote: Agreed. Although anything that involves take home or reading of their code runs the risk of the candidate presenting somebody else's work... I expect a candidate to emphasize their positive qualities, perhaps even exaggerate a little. The point of a technical interview is to assess just how much of each :-) What I do NOT expect is outright prevarication. I go into the interview with the assumption that the candidate is, if nothing else, honest. In any case, if the candidate were to submit somebody else's work, it would come out pretty quickly as we discussed their code. I suppose one question I might ask would be, Can you explain why, when I copy-paste one of your comments into a google search box, your entire program appears? I usually just tried to get a feel for their stated experience and ask some questions just to make sure they weren't presenting somebodies else's (fictitious even!) resume. Amazingly enough, that does happen. I once got two resumes in the same pile which were word-for-word identical, except for the name on the top. I've been around the block a few times, but I was still shocked. I'm not sure what was more shocking; that people could be that dishonest, or that they could be so clumsy and stupid about it. -- http://mail.python.org/mailman/listinfo/python-list
Splitting a sequence into pieces with identical elements
Suppose you have a sequence s , a string for say, for instance this one : spppaeggg We want to split s into the following parts : ['s', 'ppp', 'a', '', 'e', 'ggg', ''] ie each part is a single repeated character word. What is the pythonic way to answer this question? A naive solution would be the following : # --- z='spppaeggg' zz=[] while z: k=1 while z[:k]==k*z[0]: k+=1 zz+=[z[:k-1]] z=z[k-1:] print zz # --- but I guess this code is not very idiomatic :( -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting a sequence into pieces with identical elements
On Tue, Aug 10, 2010 at 5:37 PM, candide cand...@free.invalid wrote: Suppose you have a sequence s , a string for say, for instance this one : spppaeggg We want to split s into the following parts : ['s', 'ppp', 'a', '', 'e', 'ggg', ''] ie each part is a single repeated character word. What is the pythonic way to answer this question? If you're doing an operation on an iterable, always leaf thru itertools first: http://docs.python.org/library/itertools.html from itertools import groupby def split_into_runs(seq): return [.join(run) for letter, run in groupby(seq)] If itertools didn't exist: def split_into_runs(seq): if not seq: return [] iterator = iter(seq) letter = next(iterator) count = 1 words = [] for c in iterator: if c == letter: count += 1 else: word = letter * count words.append(word) letter = c count = 1 words.append(letter*count) return words Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting a sequence into pieces with identical elements
On 08/10/10 19:37, candide wrote: Suppose you have a sequence s , a string for say, for instance this one : spppaeggg We want to split s into the following parts : ['s', 'ppp', 'a', '', 'e', 'ggg', ''] ie each part is a single repeated character word. While I'm not sure it's idiomatic, the overabuse of regexps in Python certainly seems prevalent enough to be idiomatic ;-) As such, you can use: import re r = re.compile(r'((.)\1*)') #r = re.compile(r'((\w)\1*)') s = 'spppaeggg' results = [m.group(0) for m in r.finditer(s)] Additionally, you have all the properties of the match-object (which includes the start/end) available too if you need). You don't specify what you want to have happen with non-letters (whitespace, punctuation, etc). The above just treats them like any other character, finding repeats. If you just want word characters, you can use the 2nd (\w) version, or adjust accordingly. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting a sequence into pieces with identical elements
Tim Chase wrote: On 08/10/10 19:37, candide wrote: Suppose you have a sequence s , a string for say, for instance this one : spppaeggg We want to split s into the following parts : ['s', 'ppp', 'a', '', 'e', 'ggg', ''] ie each part is a single repeated character word. While I'm not sure it's idiomatic, the overabuse of regexps in Python certainly seems prevalent enough to be idiomatic ;-) As such, you can use: import re r = re.compile(r'((.)\1*)') #r = re.compile(r'((\w)\1*)') That should be \2, not \1. Alternatively: r = re.compile(r'(.)\1*') #r = re.compile(r'(\w)\1*') s = 'spppaeggg' results = [m.group(0) for m in r.finditer(s)] Additionally, you have all the properties of the match-object (which includes the start/end) available too if you need). You don't specify what you want to have happen with non-letters (whitespace, punctuation, etc). The above just treats them like any other character, finding repeats. If you just want word characters, you can use the 2nd (\w) version, or adjust accordingly. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to implement a pipeline...??? Please help
On 7 Ago, 07:30, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Fri, 6 Aug 2010 16:47:58 -0700 (PDT), Ritchy lelis ritchy_g...@hotmail.com declaimed the following in gmane.comp.python.general: Guys i'm asking if it's possible for a generic function for a pipeline, all the suggestions ideas are welcome. I've not done metaclasses, so don't know if a metaclass would be of use... Since it appears one would have to have something that generates functions on the fly based upon inputs... I look at details on what you are trying to create and see a series-parallel circuit architecture with clocked stages and delay lines for the summing of the outputs. That is, when the clock ticks, every stage in the unit does its processing and provides and output... On the next tick, those outputs become inputs to the subsequent stage and the process repeats Also if you have a specific solution for my problem I will be grateful for it here. I'm still blinking at the thought of doing analog to digital conversion in Python! I sure wouldn't hold out much hope of real-time signal processing. There is a reason ADC and DAC are done in hardware, even if the intermediate processing is with general purpose processors. I'm also not sure I understand the np.linspace(1,1, Inc)... Looking up documentation implies you are trying to create a vector of inc length, evenly populated by values between 1 and 1... which means a vector of all 1s... Might it not be faster to just v = [1] * inc and pass v to some numpy method for conversion from Python list to numpy vector? (the -1 to 1 at least makes sense) Me? I'd probably create a class in which the __init__() takes a value specifying the number of stages. It would than create suitable lists to track values, some sort of counter (c), a Semaphore (s) [initialized at 0 -- ie, already acquired/block], a thread for EACH stage, and an Event (e) object Each stage thread, initialized with its position in the pipeline. The threads perform an e.wait() call. They also, after the wait is released, perform an e.clear() call. As their processing, they each grab from the pipeline input list the current value for their position. After processing they update their position in the output list(s), they decrement the counter c (maybe put a lock around access to c). The thread that decrements c to 0 is responsible for releasing the semaphore. The main code of the class instance is responsible for a loop that does: set up the input list based on current value of stage outputs, initialize c to the count of stages (minus 1?), e.set() to signal all stage threads to process the current conditions, s.acquire() to block until the last processed thread (by c hitting 0) does s.release(). It then collects the output lists, does whatever shifting is needed to prepare for the next cycle... Actually, that loop may not be a loop so much as a method off the class like digitalOutput = adcInstance.step(analogInput) which is, itself, in a loop. That is, something like... myADC = ADC(stages=10) while True: voltage = getNextAnalogInput() digital = myADC.step(voltage) outputDigitalValue() Obviously I've not taken the time to actually lay out all the instance lists needed for inputs and outputs, nor the code of threads (while one can create the first stages-1 threads with a loop, the final stage needs a discrete creation) When one finds that the threading solution is really slow (though understandable in terms of the hardware circuit -- one thread per stage makes the stages easy to code), THEN one might try to figure out how to implement an iterative version... I suspect using numpy would be the third optimization -- removing iteration by using parallel vector operations. -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.com HTTP://wlfraed.home.netcom.com/ Hi First of all i would like to thank you for your time and help. I appreciate your suggestions and they seems very good to me... The only problem it's that i'm newbie at python programming, but still interested to learn more and more... I already got a solution through harsh but it worked. at least I got the wave form i wanted. Next i'm going to let you'll my solution here. It's rudimentary but it work's. Seems very perceptible that's why i will not explain it right now but if in case of doubt I will: Pipeline Function: from flash1b5 import flash1b5 from flash1b5 import * from flash2b import flash2b from flash2b import * import matplotlib.pyplot as plt import numpy as np from pylab import * if __name__ == __main__: Inc = raw_input(Valor do Incrimento = ) Vref = np.linspace(1,1, Inc) Vi = np.linspace(-1,1, Inc) #x = np.linspace(-1,1, Inc) #Vi = 1*sin(2*pi*(x-1/4)) Cs =
Re: python interview quuestions
On Fri, Aug 6, 2010 at 10:31 PM, Tim Chase python.l...@tim.thechases.com wrote: [...] More over, it can be done in just a single line of Python. 7 if you're not very familiar with Python. While it *can* be done in one line, I'm not sure it's the most legible solution. Though I must say I like this one-line python version: for i in range(1, 101): print ((i%3==0 and 'fizz' or '') + (i%5==0 and 'buzz' or '')) or i (adjust 3 and 5 for your local flavor of fizzbuzz) I'm not sure I'd hire a candidate that proposed this as a solution in earnest, but I'd have fun chatting with them :) I didn't believe it could take more than 5 minutes, but this took me ~10 minutes, though I'm familiar with python and I did the FizzBuzz one-liners before: http://gist.github.com/518370 Well.. I tried to use generators to make it cool but changed it for a test-friendly approach. I'll find hard to remember the one-liners in an interview and get it right. Rolando Espinoza La fuente www.insophia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Splitting a sequence into pieces with identical elements
On 08/10/10 20:30, MRAB wrote: Tim Chase wrote: r = re.compile(r'((.)\1*)') #r = re.compile(r'((\w)\1*)') That should be \2, not \1. Alternatively: r = re.compile(r'(.)\1*') Doh, I had played with both and mis-transcribed the combination of them into one malfunctioning regexp. My original trouble with the 2nd one was that r.findall() (not .finditer) was only returning the first letter of each because that's what was matched. Wrapping it in the extra set of parens and using \2 returned the actual data in sub-tuples: s = 'spppaeggg' import re r = re.compile(r'(.)\1*') r.findall(s) # no repeated text, just the initial letter ['s', 'p', 'a', 'm', 'e', 'g', 's'] [m.group(0) for m in r.finditer(s)] ['s', 'ppp', 'a', '', 'e', 'ggg', ''] r = re.compile(r'((.)\2*)') r.findall(s) [('s', 's'), ('ppp', 'p'), ('a', 'a'), ('', 'm'), ('e', 'e'), ('ggg', 'g'), ('', 's')] [m.group(0) for m in r.finditer(s)] ['s', 'ppp', 'a', '', 'e', 'ggg', ''] By then changing to .finditer() it made them both work the way I wanted. Thanks for catching my mistranscription. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
In message abe9b308-db83-4ca8-a71a-12d2025a7...@i31g2000yqm.googlegroups.com, Alex Barna wrote: On Aug 10, 10:05 am, Lawrence D'Oliveiro Can’t understand the point to it. “GUI automation” is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. Automating GUI is for testing. But the most egregious GUI problems are going to be with humans being unable to figure out how to do something, am I right? How are you going to uncover those problems, except by testing with real people? Automated testing isn’t going to do it. -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
In message 4c61a4f5$0$5804$426a3...@news.free.fr, News123 wrote: On 08/10/2010 12:25 PM, Alex Barna wrote: On Aug 10, 10:05 am, Lawrence D'Oliveiro Can’t understand the point to it. “GUI automation” is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. Automating GUI is for testing. And sometimesfor working around SW, whch has no cli or other interface and should be automated Who would design software in such a brain-dead way? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to capture all the environment variables from shell?
On 10Aug2010 10:07, Steven W. Orr ste...@syslang.net wrote: | On 8/2/2010 4:33 AM, Thorsten Kampe wrote: | * Tim Chase (Mon, 26 Jul 2010 21:42:24 -0500) | On 07/26/10 21:26, Steven W. Orr wrote: | Please! Never export anything from your .bashrc unless you | really know what you're doing. Almost all exports should be | done in your .bash_profile | | Could you elaborate on your reasoning why (or why-not)? I've | found that my .bash_profile doesn't get evaluated when I crank up | another terminal window, while my bashrc does. Thus I tend to | put my exports in my ~/.bashrc so they actually take effect in my | shell... | | ~/.bash_profile is only evaluated for login shells and ~/.bashrc only | for non-login shells. Thus it's recommended to keep ~/.bash_profile | empty (except a source statement for .bashrc) and put all your settings, | aliases, exports, etc. in .bashrc. | | Sorry. Dead wrong. Please reread the above comment I wrote. If you set your | environment variables in the .bashrc then you completely lose the ability of | environment variables to be inherited by sub-shells. Again, envvars should be | set in the .bash_profile, most everything else should be set in the .bashrc, and | the .bashrc should be sourced into the .bash_profile to solve the problem that | you thought you were solving. | | After that, and again, be aware that the .bashrc alone is executed for login | shells *which are not interactive*. for example: | | ssh somemachine 'echo Hello' | | This command will *not* go through the .bash_profile but it will go through the | .bashrc. No, only interactive shells use the .bashrc. Still, you're quite right that envvars belong in the .bash_profile. .bashrc is for trivial setup stuff relevant only to interactive shells (for example history settings and interactive aliases). | This means that for cases like this, we want to check to see if the | bash process is interactive or not inside the .bashrc and then do the right thing. | | Inside your .bashrc=== | [[ -z $PS1 ]] setPATHHere | EOInside your .bashrc=== This is Very Wrong. (RedHat do this test - it is bogus - if I set $PS1 in my profile it breaks badly.) Instead, test $-: case $- in *i*) echo INTERACTIVE ;; *) echo BATCH ;; esac | This is not needed for the above degenerate case, but it is needed if the | command in question is kept in a directory that you normally find in a place | that is part of your personal login PATH. E.G., If myprog lives in ~/bin then | | ssh somemachine myprog | | will fail unless you use the above construct. | | Hopefully, I'll only have to re-explain this another google times... googol, surely? The reason .bashrc gets overused for envars, aside from ignorance and propagated bad habits, is that in a GUI desktop the setup sequence is often a bit backwards. A conventional terminal/console login means you get a login shell that sources your .{bash_}profile. And from there one would start a GUI and all the .profile stuff has been run Once, as it should be. But when the login itself is a GUI the various terminals get started _before_ the .profile stuff gets sourced, because the terminal is started by the desktop manager. Once common fix for this is to make all new terminals run login shells. Ugh, but it does work. But it they're not login shells, people stuff everything into their .bashrc because the .profile doesn't get sourced. And so the common awful setup you're bemoaning. Cheers, -- Cameron Simpson c...@zip.com.au DoD#743 http://www.cskk.ezoshosting.com/cs/ For us, Zettai Zetsumei Toshi is an allegory for relations between the sexes, and it works especially well at this because we don't speak Japanese. She will say things, and we have no idea what the hell is going on, and then we'll select from a list of responses, but we have no idea which one is the right one, and then they're all wrong. It works on a lot of levels. - Tycho @ _Penny_Arcade_ -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
On 2010-08-11, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: In message abe9b308-db83-4ca8-a71a-12d2025a7...@i31g2000yqm.googlegroups.com, Alex Barna wrote: On Aug 10, 10:05 am, Lawrence D'Oliveiro Can???t understand the point to it. ???GUI automation??? is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. Automating GUI is for testing. But the most egregious GUI problems are going to be with humans being unable to figure out how to do something, am I right? How are you going to uncover those problems, except by testing with real people? Automated testing isn???t going to do it. Automated GUI testing isn't intended to uncover those sorts of problems in GUI design. Automated GUI intended to uncover problems in the underlying program functionality, and is used mainly for regression testing to insure that changes made to a program didn't cause any unintended changes in program behavior. Automated GUI testing often isn't even being used to test the program whos GUI is being automated. It's often used to test _other_ programs with which the GUI-automated-program interacts. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
On 2010-08-11, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: In message 4c61a4f5$0$5804$426a3...@news.free.fr, News123 wrote: On 08/10/2010 12:25 PM, Alex Barna wrote: On Aug 10, 10:05 am, Lawrence D'Oliveiro Can???t understand the point to it. ???GUI automation??? is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. Automating GUI is for testing. And sometimesfor working around SW, whch has no cli or other interface and should be automated Who would design software in such a brain-dead way? In my experience, almost everybody who designes apps for MS Windows. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
On 2010-08-10 21:57 , Lawrence D'Oliveiro wrote: In message abe9b308-db83-4ca8-a71a-12d2025a7...@i31g2000yqm.googlegroups.com, Alex Barna wrote: On Aug 10, 10:05 am, Lawrence D'Oliveiro Can’t understand the point to it. “GUI automation” is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. Automating GUI is for testing. But the most egregious GUI problems are going to be with humans being unable to figure out how to do something, am I right? Possibly, but it's not the *only* important problem. Automated GUI testing is usually a form of regression testing. You want to make sure that the behavior of parts of the GUI did not change when you made what should be unrelated modifications to the code. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
On 2010-08-10 21:59 , Lawrence D'Oliveiro wrote: In message4c61a4f5$0$5804$426a3...@news.free.fr, News123 wrote: On 08/10/2010 12:25 PM, Alex Barna wrote: On Aug 10, 10:05 am, Lawrence D'Oliveiro Can’t understand the point to it. “GUI automation” is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. Automating GUI is for testing. And sometimesfor working around SW, whch has no cli or other interface and should be automated Who would design software in such a brain-dead way? People who are not being paid for a CLI or other interface. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: How to capture all the environment variables from shell?
On 11Aug2010 13:08, I wrote: | On 10Aug2010 10:07, Steven W. Orr ste...@syslang.net wrote: [...] | | After that, and again, be aware that the .bashrc alone is executed for login | | shells *which are not interactive*. for example: | | | | ssh somemachine 'echo Hello' | | | | This command will *not* go through the .bash_profile but it will go through the | | .bashrc. | | No, only interactive shells use the .bashrc. And then I read more closely and saw this in man bash: Bash attempts to determine when it is being run by the remote shell daemon, usually rshd. If bash determines it is being run by rshd, it reads and executes commands from ~/.bashrc, if that file exists and is readable. It will not do this if invoked as sh. The --norc option may be used to inhibit this behavior, and the --rcfile option may be used to force another file to be read, but rshd does not generally invoke the shell with those options or allow them to be specified. Frankly, bash's startup behaviour is so corrupt (well, capricious anway) that I despair of it; I use zsh when possible. It also tries to be all things to all people, but is a bit saner. (And it doesn't hardwire ^W either!) Cheers, -- Cameron Simpson c...@zip.com.au DoD#743 http://www.cskk.ezoshosting.com/cs/ To be positive: To be mistaken at the top of one's voice. Ambrose Bierce (1842-1914), U.S. author. The Devil's Dictionary (1881-1906). -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand writes: Alex Barna wrote: On Aug 10, 10:05 am, Lawrence D'Oliveiro Can’t understand the point to it. “GUI automation” is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. Automating GUI is for testing. But the most egregious GUI problems are going to be with humans being unable to figure out how to do something, am I right? You asked to understand the point of GUI automation. Alex responded with one (there may well be others) very good point of GUI automation: automated testing of the GUI's behaviour. What you raise here is not the point of GUI automation. Is you understanding of the point of GUI automation improved? -- \ “I turned to speak to God/About the world's despair; But to | `\ make bad matters worse/I found God wasn't there.” —Robert Frost | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
In message mailman.1936.1281496277.1673.python-l...@python.org, Robert Kern wrote: On 2010-08-10 21:57 , Lawrence D'Oliveiro wrote: In message abe9b308-db83-4ca8-a71a-12d2025a7...@i31g2000yqm.googlegroups.com, Alex Barna wrote: On Aug 10, 10:05 am, Lawrence D'Oliveiro Can’t understand the point to it. “GUI automation” is a contradiction in terms, because a GUI is designed for use by humans to do manual tasks, not ones that can be automated. Automating GUI is for testing. But the most egregious GUI problems are going to be with humans being unable to figure out how to do something, am I right? Possibly, but it's not the *only* important problem. Automated GUI testing is usually a form of regression testing. You want to make sure that the behavior of parts of the GUI did not change when you made what should be unrelated modifications to the code. Again, that’s something that primarily affects real users, when they find some function is no longer in the place where they expect it to be. You have to test with real users to find out what they think of this sort of thing. -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
In message i3t449$7c...@reader1.panix.com, Grant Edwards wrote: Automated GUI intended to uncover problems in the underlying program functionality ... That “underlying” functionality has nothing to do with the GUI, then. Why not test it directly, rather than go through the GUI? Automated GUI testing often isn't even being used to test the program whos GUI is being automated. It's often used to test _other_ programs with which the GUI-automated-program interacts. Again, this sounds like it has nothing to do with the GUI per se. -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI automation tool (windows)
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand writes: In message i3t449$7c...@reader1.panix.com, Grant Edwards wrote: Automated GUI intended to uncover problems in the underlying program functionality ... That “underlying” functionality has nothing to do with the GUI, then. Why not test it directly, rather than go through the GUI? Because that behaviour can be different when tested in a way that doesn't involve using the actual program's interface. The GUI is part of the program's behaviour, remember, and just about any non-trivial GUI program will have quite complex behaviour specifically in its GUI. Is the concept of testing the actual program behaviour really foreign to you? If not, what part of this concept is causing you difficulty? -- \ “Two paradoxes are better than one; they may even suggest a | `\ solution.” —Edward Teller | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list