Re: Inconsistent SMTP/Gmail connection drop
On Wed, Aug 3, 2011 at 5:46 PM, Astley Le Jasper wrote: > > Any ideas? > Is it possible that the first email is sent before the network connection has been properly established? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek www: http://dstanek.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Application and package of the same name
On 19-Oct 19:34, Paul Moore wrote: > On 19 October 2017 at 19:18, Skip Montanaro wrote: > > > > This is in Python 2.7, FWIW. What am I missing? > > My immediate reaction is "you shouldn't name your main program and > your package the same". It's not a pattern I've seen commonly used. > This is actually a common pattern I see when teaching the language. For example, when a student wants to test out a package like requests many seem to initially want to create a requests.py module. Then they become very confused when they get an AttributeError on requests.get(). -- david stanek web: https://dstanek.com twitter: https://twitter.com/dstanek -- https://mail.python.org/mailman/listinfo/python-list
Re: Tips or strategies to understanding how CPython works under the hood
On 09-Jan 15:21, Robert O'Shea wrote: > > Been subscribed to this thread for a while but haven't contributed much. +1. I'm a lurker too. > So besides just grabbing a chunk of CPython source code and digesting it, I > was wondering if those of you have read and understood the source code, do > you have any tips or good starting points? > There are a ton of videos on Youtube that talk about Python internals. I liked https://www.youtube.com/playlist?list=PLzV58Zm8FuBL6OAv1Yu6AwXZrnsFbbR0S quite a bit. Even though I knew a good portion of the material, there was still a lot of new stuff. -- david stanek web: https://dstanek.com twitter: https://twitter.com/dstanek -- https://mail.python.org/mailman/listinfo/python-list
Re: why does list's .remove() does not return an object?
On 17-May-2018 12:37, Ned Batchelder wrote: > On 5/17/18 12:28 PM, Dan Strohl via Python-list wrote: > > On 2018-05-17 11:26 AM, Abdur-Rahmaan Janhangeer wrote: > > > I don't understand what this would return? x? You already have x. Is > > > it meant to make a copy? x has been mutated, so I don't understand the > > > benefit of making a copy of the 1-less x. Can you elaborate on the > > > problem you are trying to solve? > > > > > > --Ned. > > > > > > > > > assignment to another var > > > > > Though I don’t know what the OP was specifically looking for I could see a > > benefit to returning the item deleted. > > Notice that this is not the thing the OP wanted returned. I believe they > are looking to return the list, not the item. > I'm guessing that they want to be able to do some sort of method chaining like: the_list.remove(x).remove(y) Although the clarifying example was contrived and confusing. A more concrete example would be greatly appreciated. -- david stanek web: https://dstanek.com twitter: https://twitter.com/dstanek -- https://mail.python.org/mailman/listinfo/python-list
Cleveland Ohio Python Meeting
October 6 from 18:30-20:30 A presentation will be given on Django and I am sure that we will discuss web frameworks in general. Everyone is welcome. For more details take a look at http://www.clepy.org/meetings/2005_10_06_mtg_details David -- GPG keyID #6272EDAF on http://pgp.mit.edu Key fingerprint = 8BAA 7E11 8856 E148 6833 655A 92E2 3E00 6272 EDAF pgpnP0qEOfwCq.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Cleveland Ohio Python Meeting
On Wed, Sep 28, 2005 at 07:10:15AM -0400, David Stanek wrote: > October 6 from 18:30-20:30 > > A presentation will be given on Django and I am sure that we will > discuss web frameworks in general. Everyone is welcome. For more > details take a look at > http://www.clepy.org/meetings/2005_10_06_mtg_details This meeting will actually be held on Oct. 3rd. Sorry for any confusion. -- www.roninds.net GPG keyID #6272EDAF on http://pgp.mit.edu Key fingerprint = 8BAA 7E11 8856 E148 6833 655A 92E2 3E00 6272 EDAF pgpqa8r4yptRX.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
ANN: Cleveland Area Python Interest Group
I am attempting to start a Cleveland (Ohio) Python Interest Group. This group is a revival of the very inactive Cleveland Python Meetup Group. If you are in the Cleveland area and are interested goto http://www.clepy.org for more information. -- David Stanek www.roninds.net GPG keyID #6272EDAF on http://pgp.mit.edu Key fingerprint = 8BAA 7E11 8856 E148 6833 655A 92E2 3E00 6272 EDAF pgpW57k8JKQkE.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python config problem
On Fri, Jun 03, 2005 at 01:16:17PM -0600, Manuel Pellecer wrote: > i want to use mod_python with Apache2 and i made a .htaccess in the > subdirectory where i have all my scripts: > > The .htacces goes like this: > > AddHandler mod_python .py > PythonHandler mptest > PythonDebug On Try adding the following line to your .htaccess file: PythonPath "sys.path + ['/your/path']" Where '/your/path' is the path in which mptest.py resides. -- David Stanek www.roninds.net GPG keyID #6272EDAF on http://pgp.mit.edu Key fingerprint = 8BAA 7E11 8856 E148 6833 655A 92E2 3E00 6272 EDAF pgpqT33AXn9gS.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Python interest group software
Is there already any software out there to manage a Python Interest Group? Something that can register users, take RSVPs for meetings, etc. -- David Stanek www.roninds.net GPG keyID #6272EDAF on http://pgp.mit.edu Key fingerprint = 8BAA 7E11 8856 E148 6833 655A 92E2 3E00 6272 EDAF pgprkGXMh0xiQ.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Autogenerate functions (array of lambdas)
On 9/6/07, Chris Johnson <[EMAIL PROTECTED]> wrote: > > What I want to do is build an array of lambda functions, like so: > > a = [lambda: i for i in range(10)] > > (This is just a demonstrative dummy array. I don't need better ways to > achieve the above functionality.) > > print [f() for f in a] > > results in: [9, 9, 9, 9, 9, 9, 9, 9, 9, 9] > rather than the hoped for: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > > Clearly, lambda is returning the object i, which is left at the last > value of range(10). The following is my solution. > > t = lambda i: lambda: i > a = [t(i) for i in range(10)] > > or the somewhat more terse: > > a = [(lambda i: lambda: i)(i) for i in range(10)] > > This gives the behavior which, intuitively, I expected from the > original syntax. So my questions are: > 1) Does this make sense as what should be done here? That is, would > this be the behavior you'd want more often than not? As I said, > intuitively, I would think the lambda would treat the iterator > variable as a constant in this context. > 2) Is there a better or preferred method than the one I've found? A more explicit example of your solution would be: >>> def gen(i): ... return lambda: i # bind to the i passed in ... >>> l = [gen(i) for i in range(10)] >>> [f() for f in l] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Your initial lambda: i creates a function that binds to i in the current scope. When you wrapped that in another lambda you were creating a new scope with a new value of i and returning a function bound to that value for i. Take a look at closures: http://www.ibm.com/developerworks/linux/library/l-prog2.html#h1 http://ivan.truemesh.com/archives/000392.html David -- http://www.traceback.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting original working directory
On 9/6/07, rave247 rave247 <[EMAIL PROTECTED]> wrote: > > If I could use os.getcwd() or save the value to some variable before > calling os.chdir() I would do it, believe me. However I can't because it > is the part of code where I can't do any changes. Why is it not possible. If nothing else create a new module that does the os.getcwd() then call the module that you cannot change. Also I do not agree that such thing is not possible because after python > script finishes its work, it naturally gets back into the original location > from where you started the script (in shell you are in the original location > after script finishes). So this information has to be stored somewhere > (probably in shell which runs the interpreter) and there *must* be a way > how to get it. Simply after calling os.chdir() the original value doen't > disappear, I think it just needs some nice hack if python doesn't provide a > way how to get it. > The shell is back to where it started for a very different reason. I won't go into it, because it's not about Python. However, if you know what shell you will *always* be using to run the script, then there may be a way. Bash, for example, will have the path where you were when the script started in os.environ['PWD']. I suspect most shells have something similar. David -- http://www.traceback.org -- http://mail.python.org/mailman/listinfo/python-list
Re: SVN/CVS and Branching
On Thu, Feb 19, 2009 at 7:10 AM, Jeff Dyke wrote: > Fair enough. Say my project is called foo, and it has many > submodules. So there are imports that may look like `import foo.bar` > or `from foo.bar import baz`, if i change the top level directory, it > is no longer foo and then those imports do not work as originally > written. The way i currently do this is to create a branch, say > foo2, and create a symbolic link named foo pointing at foo2, after > renaming foo, when i want to work on the branch and remove the link > when i want to work on the head. This actually works fine, but > thought there may be a better way. > > Jeff > I think that your project structure is faulty. In Subversion I do something like: * FooProject/trunk/foo * FooProject/branches/TRY-foo2 TRY-foo2 is an svn cp of trunk so checking out TRY-foo2 gives you a TRY-foo2 directory containing a foo package. My DVCS projects go essentially the same thing. -- David http://www.traceback.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic misunderstanding of generators
On Mon, Dec 22, 2008 at 4:47 AM, Barak, Ron wrote: > > if __name__ == "__main__": > filename = "sac.log.gz" > log_stream = LogStream(filename) > line_ = log_stream.next_line(log_stream.input_file) > print line_ > > $ python LogManager_try.py > > A method or function containing a yield statement will return a generator instance when called. Which is what is happening in your example. What you want to do is something like: for line in log_stream.next_line(log_stream.input_file): print line To make the code bit simpler and more OO you should not need to pass anything into next_line(). It is a part the object so it naturally has access to its properties. That being said you can then use __iter__ instead and then you can then do something like: for line in log_stream: print line OTOH If your LogStreamer class doesn't keep any additional state I would probably just create a single generator function. -- David http://www.traceback.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Event Driven programming - Doubts
On Mon, Dec 22, 2008 at 9:57 AM, Kottiyath wrote: > > If so, Even though data locking etc is not a problem, are we not still > having threads? Will it not still cause scalability problems in high > traffic? > If not, could somebody let me know how it is done? This somewhat depends on the application. Is it IO bound or CPU bound? >From what I understand about twisted you will only have one process and one thread which means you will only be using one CPU. -- David http://www.traceback.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Exec inside a class method to call other class methods?
On Thu, Dec 25, 2008 at 1:22 PM, Matthew Dubins wrote: > Hello all, > > I have made a python script to upload contact information from an excel > worksheet to an online database. One part of the program that really > tripped me up was when I wanted to call specific class methods that I had > made to deal with specific types of contact information (Parent's name, > Child's name, Phone #, etc). My first thought was to make it easy using the > exec statement. > The code (a method within a class) looked like this: > -- > def parse(self, data, data_type) > exec "self.__parse_%s(data)" % data_type > -- > The data_type variable contains strings that exactly match the spellings of > the 2nd word in the titles of the class methods that I wanted to call for > each data_type inputted into the parse function. For some reason, *it > didn't work*. Alternately, I found the ugly code shown below to be > functional. As you can see, for each data_type, I call the corresponding > class method that I've specified. Please help me to transform my ugly > functional code into concise functional code. :) > > Thanks, > Matthew > -- > def parse(self, data, data_type): > if data_type == 'nocall': > self.__parse_nocall(data) > elif data_type == 'DOB': > self.__parse_DOB(data) > elif data_type == 'gender': > self.__parse_gender(data) > elif data_type == 'Prematurity': > self.__parse_Prematurity(data) > elif data_type == 'email': > self.__parse_email(data) > elif data_type == 'languages': > self.__parse_languages(data) > elif data_type == 'phone': > self.__parse_phone(data) > elif data_type == 'cname': > self.__parse_cname(data) > elif data_type == 'pname': > self.__parse_pname(data) > elif data_type == 'address': > self.__parse_address(data) > elif data_type == 'duedate': > self.__parse_dudedate(data) > I would look for a way to reorganize your code so that each type contains its own parse method. -- David http://www.traceback.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Exec inside a class method to call other class methods?
On Thu, Dec 25, 2008 at 6:22 PM, Matthew Dubins wrote: > Each type does contain its own parsing method. It's just that, as it > stands, one method is being used to shunt off the data to the correct > parsing method. > Not really. You have all of the parsing methods in a single class. Is it possible for each data class to have a parse method? class DOB(object): def parse(...): pass There are many pros and cons do this way of doing things. Google polymorphism and possibly duck typing to see some interesting discussions. -- David http://www.traceback.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Exec inside a class method to call other class methods?
You won't need the dictionary at all if each type has a parse method. On 12/25/08, Chris Rebert wrote: > On Thu, Dec 25, 2008 at 4:16 PM, J. Clifford Dyer > wrote: > >> and so forth. Then your if/else chain can be pulled out to the place >> where you instantiate each field: >> >> if data_type=='address': >>field=AddressDataField(data) >> elif data_type=='due_date': >>field=DueDateDataField(data) >> else: >>field = DataField(data) >> > > And then you use a dictionary of data_type to class to get rid of the > if-else chain altogether: > > type2klass = {'address' : AddressDataField, 'due_date' : DueDateDataField} > #etc > Klass = type2klass.get(data_type, DataField) #use DataField as fallback > default > field = Klass(data) > > Merry Christmas, > Chris > > -- > Follow the path of the Iguana... > http://rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- Sent from my mobile device David http://www.traceback.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Code coverage to Python code
On Sun, Jan 4, 2009 at 9:26 PM, Roy Smith wrote: > In article , > Robert Kern wrote: > >> Hussein B wrote: >> > Hey, >> > What is the best code coverage tool available for Python? >> >> I like Titus Brown's figleaf. >> >> http://darcs.idyll.org/~t/projects/figleaf/doc/ > > I was playing with Ned Batchelder's coverage.py module today. Once I > stopped screwing around trying to get the "easy install" stuff to work and > just copied the danged .py file to my site-packages directory, I was up and > running in a few minutes. > > I suppose there's a lot of bells and whistles you could add, but it ran my > code and told me which lines had executed and which hadn't. That pretty > much seems like what you want a code coverage tool to do. > > http://nedbatchelder.com/code/modules/coverage.html It will show lines as covered when they are executed by the interpreter. Class statements, function definitions, etc. can show up as executed. Are you seeing other code show up as covered? Recently I pushed a branch of an experimental project I am calling Barbarian[0]. It uses nose, figleaf and pylint to generate HTML for a project. A blog post with a more detailed description will be posted within a few days. [0] http://code.launchpad.net/~dstanek/+junk/Barbarian -- David http://www.traceback.org -- http://mail.python.org/mailman/listinfo/python-list
Re: PyPI editing
On Thu, Mar 5, 2009 at 3:32 AM, andrew cooke wrote: > > Apparently not (this will probably change, but see > http://pypi.python.org/pypi/LEPL/2.0.1 which is currently displaying > restructured text literally) > Did you put the ReST in the description or the long_description? Take a look at the setup.py from the example you gave: http://code.google.com/p/pypp/source/browse/trunk/setup.py. Warning: I have not done this myself. -- David http://www.traceback.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is lambda allowed as a key in a dict?
On Mon, Mar 9, 2009 at 11:07 PM, Daniel Fetchinson wrote: > Python 2.5.1 (r251:54863, Oct 30 2007, 13:45:26) > [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. x = { } x[lambda arg: arg] = 5 x[lambda arg: arg] > Traceback (most recent call last): > File "", line 1, in > KeyError: at 0x2abaab18> > > Is this a case of "we are all adults here"? I should only blame myself > for making an unnamed function a dictionary key or should it be > forbidden? Or am I missing something completely? > Each time you are using lambda to create a new anonymous function object. It is not giving you the same object. If you save the reference to the lambda you can easily get it back: >>> l = lambda arg: arg >>> >>> d= {} >>> d[l] = 5 >>> d[l] 5 -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Style question - defining immutable class data members
On Sat, Mar 14, 2009 at 12:32 PM, Maxim Khitrov wrote: > Very simple question on the preferred coding style. I frequently write > classes that have some data members initialized to immutable values. > For example: > > class Test(object): > def __init__(self): > self.some_value = 0 > self.another_value = None > > Similar effect can be achieved by defining some_value and > another_value for the entire class, like so: > > class Test(object): > some_value = 0 > another_value = None > > The advantage of doing this is that the assignments are evaluated once > and thus the creation of that class is a bit faster. Access is still > performed through self.some_value and self.another_value. Is there a > reason to prefer the first style over the second? > In general I think it can be fine as long as you do use immutable values. I use this pattern when I create data transfer objects[0]. Normally these objects don't have any methods. So you want to be careful that you are doing it for the right reason. When I create objects that are not DTOs I don't do this. [0] http://martinfowler.com/eaaCatalog/dataTransferObject.html -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: __init__ vs. __del__
2009/3/21 Randy Turner : > There are a number of use-cases for object "cleanup" that are not covered by > a generic garbage collector... > > For instance, if an object is "caching" data that needs to be flushed to > some persistent resource, then the GC has > no idea about this. > > It seems to be that for complex objects, clients of these objects will need > to explictly call the objects "cleanup" routine > in some type of "finally" clause, that is if the main "thread" of execution > is some loop that can terminate either expectedly or > unexpectedly > > Relying on a generic GC is only for simple object cleanup...at least based > on what I've read so far. > > Someone mentioned a "context manager" earlier...I may see what this is about > as well, since I'm new to the language. > If you add a .close method to your class you can use contextlib.closing[0]. I have used this to clean up distributed locks and other non-collectable resources. 0. http://docs.python.org/library/contextlib.html#contextlib.closing -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Thoughts on language-level configuration support?
On Mon, Mar 30, 2009 at 9:40 AM, jfager wrote: > I've written a short post on including support for configuration down > at the language level, including a small preliminary half-functional > example of what this might look like in Python, available at > http://jasonfager.com/?p=440. > > The basic idea is that a language could offer syntactic support for > declaring configurable points in the program. The language system > would then offer an api to allow the end user to discover a programs > configuration service, as well as a general api for providing > configuration values. > What value does this have over simply having a configuration file. In your load testing application you could have easily checked for the settings in a config object. I think that the discover-ability of configuration can be handled with example configs and documentation. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Thoughts on language-level configuration support?
On Tue, Mar 31, 2009 at 3:19 AM, jfager wrote: > > "Simply having a configuration file" - okay. What format? What if > the end user wants to keep their configuration info in LDAP? Did the > library I'm including make the same decisions, or do I have to do some > contortions to adapt? Didn't I write basically this exact same code > for the last umpteen projects I worked on, just schlepping around > config objects? > Ah I see your point here. During PyCon I was trying to add the ability to inject configuration into objects that are constructed by the snake-guice framework. The code is not yet in the Subversion repository, but I did brain dump a little documentation[0]. It is still very much a work in progress. 0. http://code.google.com/p/snake-guice/wiki/InjectingConfiguration -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Thoughts on language-level configuration support?
On Tue, Mar 31, 2009 at 10:01 AM, jfager wrote: > On Mar 31, 6:02 am, David Stanek wrote: >> On Tue, Mar 31, 2009 at 3:19 AM, jfager wrote: >> >> > "Simply having a configuration file" - okay. What format? What if >> > the end user wants to keep their configuration info in LDAP? Did the >> > library I'm including make the same decisions, or do I have to do some >> > contortions to adapt? Didn't I write basically this exact same code >> > for the last umpteen projects I worked on, just schlepping around >> > config objects? >> >> Ah I see your point here. During PyCon I was trying to add the ability >> to inject configuration into objects that are constructed by the >> snake-guice framework. The code is not yet in the Subversion >> repository, but I did brain dump a little documentation[0]. It is >> still very much a work in progress. >> >> 0.http://code.google.com/p/snake-guice/wiki/InjectingConfiguration > > This is getting close :) I think it would be nice if you didn't have > to come up with your own names (so that projects across different > authors would share more or less the same naming structure), and if > those names didn't encode their expectation of a particular end-user > configuration scheme. > For my purpose I am writing the glue infrastructure that allows components to be put together within an application. What I am missing is a schema-like way to define configuration files. I have debated starting a project to do that, but at this time I'm already overextended :-) -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Thoughts on language-level configuration support?
On Tue, Mar 31, 2009 at 9:42 PM, Lawrence D'Oliveiro wrote: > In message <36148830-22c0-4f19-ab23- > d04d8755a...@s28g2000vbp.googlegroups.com>, jfager wrote: > >> I've written a short post on including support for configuration down >> at the language level ... > > If you're advocating anything resembling php.ini, you deserve to die. > I am pretty sure that is uncalled for. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Spring-like IoC in python?
On Sun, Apr 5, 2009 at 5:51 AM, Giovanni Giorgi wrote: > Hi all, I have just read the Thread "Thoughts on language-level > configuration support?" started by jfager. > I have worked in the past days with Java Spring. > I found very valuable the ideas behind Inversion of Control (IoC). > I think it should be a very nice feature to get into python too. > In detail, I think the most important concept is the ability to auto-wire > dependencies declared in the configuration file. > It is the "added value" of such idea in my own opinion. > Spring is heavily based on type declaration (in form of concrete class of > interfaces) so this approach is not the preferred path in a dynamically > language like Python. > Do someone have tried or seen something like IoC container based on Python? > There are several projects implementing IoC in Python. The three I am most familiar with are snake-guice[0], pinsor[1] and SpringPython[2]. I think they are all worth investigating. I started snake-guice as a clone of the google-guice project (a Java IoC framework.) I liked several things that I just didn't see anywhere else: 1. Language based configuration because XML sucks 2. In code hints about what will be injected 3. Not a container - the injector injects and gets out of the way The documentation is a little lacking, but that will be changing in the next few days. Examples of using snake-guice with CherryPy, Django and TurboGears are just a few days off as well. The API tests[3] show simple clear examples. The project is going to be used on several very large websites. So you can expect it to be maintained for quite a while. I would encourage you to look at each project and leave feedback where you can. It can only help each project. 0. http://code.google.com/p/snake-guice/ 1. http://code.google.com/p/pinsor/ 2. http://springpython.webfactional.com/ 3. http://code.google.com/p/snake-guice/source/browse/trunk/snakeguice/tests/test_api_25.py -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Spring-like IoC in python?
On Sun, Apr 5, 2009 at 9:24 AM, andrew cooke wrote: > David Stanek wrote: > [...] >> The documentation is a little lacking, but that will be changing in >> the next few days. Examples of using snake-guice with CherryPy, Django >> and TurboGears are just a few days off as well. The API tests[3] show >> simple clear examples. > [...] >> 3. >> http://code.google.com/p/snake-guice/source/browse/trunk/snakeguice/tests/test_api_25.py > > can i make a suggestion? add comments to those tests explaining what they > do in fairly boring, introductory detail (ie "we are injecting a value in > ... because ..."). > > also, explain "ch" (class hierarchy) or, if it's just a meaningless module > name, use > > from ... import Person > > because i thought it was something important and now think it's noise and > if its noise it wasted my time. i know "Person" is the kind of class used > in examples, but i am unsure if "ch" is something special your system > needs or not. > > i was going to argue that ioc isn't needed in python because the > motivation for it in java - that you need a more concise configuration > language - doesn't exist. what's the point of using xml to simulate a > scripting language when you are already in a scripting language. but > maybe i have missed something, given that this stuff exists (hence me > trying to understand it). > That is a very good point. Up until recently I had been mostly working on getting it ready to use at work. I am only beginning my attempt to get community involvement. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Imports in python are static, any solution?
On Mon, Apr 13, 2009 at 11:59 AM, Ravi wrote: > foo.py : > > i = 10 > > def fi(): > global i > i = 99 > > bar.py : > > import foo > from foo import i > > print i, foo.i > foo.fi() > print i, foo.i > > This is problematic. Well I want i to change with foo.fi() . Why not only import foo and using foo.i? In fi() when you set i = 99 you are creating a new object called i in foo's namespace. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing all extra commandline arguments to python program, Optparse raises exception
On Thu, Apr 16, 2009 at 10:05 AM, sapsi wrote: > Hello, > Im using optparse and python 2.6 to parse some options, my commandline > looks like > > prog [options] start|stop extra-args-i-will-pas-on > > The options are --b --c --d > > The extra options are varied are are passed onto another program e.g -- > quiet --no-command , my program doesnt care what these are but instead > passes them onto another program. > > I know these will always follow start|stop. > > However optparse tries to process them and throws an exception - how > can i prevent this without placing all the extra-args in quotes. > In Linux (maybe in Windows) you can tell an application to stop processing args by using '--'. Given this code: import sys from optparse import OptionParser op = OptionParser() op.add_option('--a', dest='a', action='store_true', default=False) op.add_option('--b', dest='b', action='store_true', default=False) opts, args = op.parse_args(sys.argv) print 'opts:', opts print 'args:', args Here is an example use: eee0:~% python junk.py --a -- --c {'a': True, 'b': False} ['junk.py', '--c'] -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: execfile (exec?) create non consistent locals() state
>> I expected exec to work the same, but apparently I was wrong. Is there is a >> way to exec a file "more" correctly? thus avoid the need to resort to >> awkward solutions such as using the locals() dictionary? > > I don't know personally. Perhaps a kind soul will chime in. > Why not just exec into a dictionary like this: {{{ eee0:~% cat execme.py a = 0 def func(): print a eee0:~% python Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> d = {} >>> execfile('execme.py', d, d) >>> d['a'] 0 >>> d['func']() 0 >>> }}} -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)
On Wed, Apr 22, 2009 at 7:06 PM, David Lyon wrote: > > One of the big challenges for Python going forward is providing a testing > infrastructure for Python Packages. > > There are now over 6,000 packages listed on PyPi - and this number can only > get bigger. > Interesting ideas, but I'm not sure I see the value. As a package developer I publish eggs for various Python versions and a source package. In some of my newer stuff I have been thinking of using 2.6+ features, which means I don't care if it runs on any other version. I've been fine so far in relying on my code running the same on all platforms. I don't use any of the platform specific modules, but if I did as a package developer I can just say "too bad -you need Linux". I have been bitten a few times by hardcoding '/' instead of os.path.sep, but I get a bug report and make a fix. So far no big deal. I think that if you do this or snakebite gets up and running then projects should opt in to platform/Python versions. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)
On Wed, Apr 22, 2009 at 10:39 PM, David Lyon wrote: > Hi David, > > > > Yes, I agree... > > But as an end-application-developer, I would put it to you that it is a lot > of effort for developers to humanly contact the package developers every > time we end-developers find a bug. > The task (for us developers) involves: > > finding the project page for the project... > finding their tracking system.. > sometimes finding the project is abandoned > entering the bug > waiting a few days > If they took the time to find the package, install the package and learn to use it then they can file a bug report. And if it is on a platform that I don't have access to who will submit the patch? > Given that Python 3 is now on its way > > It strikes me that are a lot of packages that are about to break. > I think it is safe to assume that if the package maintainer didn't port to Python 3 that it won't work. > What I am talking about (regression testing) already exists in the Perl > world.. > > So I am hoping to have at least the same in the Python Universe > > It seems to me that from your perspective there would be no change? just > > bug reports coming sooner, rather than later. > Not really. If you are running my unit tests then you have a 50/50 chance of finding a bug. The path bug I mentioned earlier would not have been found on Windows by running my tests. It would, however, been caught by real usage. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)
On Thu, Apr 23, 2009 at 2:47 AM, Daniel Fetchinson wrote: > > The OP is just thinking out loud that it would be great if developers > could count on some help for testing various platforms and versions. > And I agree, it would indeed be great. > I think you interpreted the OP differently. As I said before the idea is not a bad one, but as a package developer I get to decide which platforms and versions my code supports. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)
On Thu, Apr 23, 2009 at 12:33 AM, David Lyon wrote: > Hi Steve, >>> Why should the package developer dictacte which python version the >>> package will run on ? >> >> Because they're the developer. Who else should decide what Python >> versions to support? > The developer shouldn't be making such decisions at all > What hardware or operating systems we run his/her programs on is > up to the real world to decide. > If you think about it logically... why are we even asking our > developers to even "build" their packages for specific python > versions in the first place? > They should just: > You should abandon this argument. Your original idea of a huge build infrastructure had some merit. This is just off the wall. If I use win32com how do you expect me to support Linux? What about the many packages on PYPI containing C? What if I decide to write only to Python 3? Who will support the other platforms if not the developer? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Packages : A looming problem? packages might no longer work? (well not on your platform or python version anyway)
On Thu, Apr 23, 2009 at 1:12 PM, norseman wrote: > > BB's, User Lists, all repositories can make these required before > acceptance. > > This is open source. I volunteer my time on the projects that I maintain. If you don't like the quality or lack of documentations, tests, etc. Contribute. Or just don't use the software. What maybe another option is to have a karma rating on PYPI. Maybe based off of home much you are included in other packages or some other factors. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Configuring pylint for local conventions (was: pyflakes, pylint, pychecker - and other tools)
On Thu, Apr 23, 2009 at 12:00 PM, Aahz wrote: > In article <874owf4gky.fsf...@benfinney.id.au>, > Ben Finney wrote: >>a...@pythoncraft.com (Aahz) writes: >>> >>> Second, you can configure pylint to respect your personal style >> >>How? I haven't seen any decent documentation on doing so. > > Actually, I don't know how, I'm just repeating what was claimed at a > presentation on pylint. ;-) I've traditionally used pychecker myself > and haven't seen any reason to switch. I believe you just: pylint --generate-rcfile > ~/.pylintrc and then customize that file. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Configuring pylint for local conventions
On Thu, Apr 23, 2009 at 10:21 PM, Ben Finney wrote: > Ben Finney writes: > >> David Stanek writes: >> >> > I believe you just: >> > pylint --generate-rcfile > ~/.pylintrc >> > and then customize that file. >> >> This is the part that I'm asking how to do. What documentation is there >> on this configuration file and recommendations on how to modify it? > > For bonus points, I'm actually wanting to know how to configure it per > *project*, and applying that configuration for all programmers of that > project. Having one set of coding conventions per *user* seem like a > recipe for frustration. > I find that the comments in the file it generates are enough. I haven't needed any more documentation than that. For project specific configuration I just keep a config file[1] in the project's source repository. Then make my build script[2] specify that file when I run 'paver lint'. [1] http://bitbucket.org/dstanek/snake-guice/src/tip/pylint.cfg [2] http://bitbucket.org/dstanek/snake-guice/src/tip/pavement.py -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: object query assigned variable name?
On Fri, May 1, 2009 at 12:48 PM, Steven D'Aprano wrote: > On Fri, 01 May 2009 09:24:10 -0700, warpcat wrote: > >> I'd like it to print, when instanced, something like this: >> > s = Spam() >> I’m assigned to s! >> >> But it seems prohibitively hard (based on my web and forum searches) for >> an object to know what variable name is has been assigned to when >> created. > > Can't be done. Objects don't know what names they are bound to. > While objects don't know what they are assigned to, they can be made to find out. Unless you have a good use case I don't think that you really want to be doing it. DecoratorTools allows you to do this. I have code that allows you to use a a function like: class C: attr = inject(Customer) The inject function does know that it is being assigned to attr. There is tracing/frame introspection black magic involved. So much so that I have been debating removing that feature. The code is on Bitbucket[1]. It has a little extra complication because inject can also be used as a decorator. The key is the decorate_assignment call in the inject function. Again I don't think you really want to do this. [1] http://bitbucket.org/dstanek/snake-guice/src/tip/snakeguice/decorators.py -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Python code-bloat tool-- warning n00b stuff...
On Mon, May 18, 2009 at 12:45 PM, david wright > > I would suggest looking into TDD (test driven development). > > This technique would be a good fit to eliminate you feeling of code bloat, in > TDD you only write the necessary amount > of code to make your test pass, hence you never write code that is not going > to be utilized. > > It takes a little while to get used to this technique ( also, it can be much > more difficult to apply in some situations) but it's well worth the effort. > :). You'll have no trouble finding tons of resources for this topic. TDD does help cut down on code bloat, but not because you are only coding what will actually be used. Rather because of rule #3: 1. Red - write just enough test code to make a test fail 2. Green - write just enough production code to make the test pass 3. Refactor - mercilessly reduce duplication 4. Repeat -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: strip char from list of strings
On Mon, May 18, 2009 at 3:30 PM, Laurent Luce wrote: > > I have the following list: > > [ 'test\n', test2\n', 'test3\n' ] > > I want to remove the '\n' from each string in place, what is the most > efficient way to do that ? > What have you tried so far? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance java vs. python
On Tue, May 19, 2009 at 5:43 PM, namekuseijin wrote: > someone said: > > If you took a look at Java, you would > notice that the core language syntax is much simpler than Python's. > > thanks for the laughs whoever you are! > I'm no Java fan, but I do agree that the core language is a bit easier for people to grasp. I have also heard that from other developers as well. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: try except inside exec
On Fri, May 29, 2009 at 11:55 AM, Michele Petrazzo wrote: > > My goal is to execute a function received from a third-part, so I cannot > modify as you made in your first piece of code. > I want a "clean" exception with the real line code/tb so I can show a "real" > error message. This means that the try/execpt has to include the passed > function and catch every possible exception. > > Do you have any ideas on how can I figure this out? > Is the thirdparty function the entire STR or just the a_funct part? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: scaling problems
On Mon, May 19, 2008 at 8:47 PM, James A. Donald <[EMAIL PROTECTED]> wrote: > I am just getting into python, and know little about it, and am > posting to ask on what beaches the salt water crocodiles hang out. > > 1. Looks to me that python will not scale to very large programs, > partly because of the lack of static typing, but mostly because there > is no distinction between creating a new variable and utilizing an > existing variable, so the interpreter fails to catch typos and name > collisions. I am inclined to suspect that when a successful small > python program turns into a large python program, it rapidly reaches > ninety percent complete, and remains ninety percent complete forever. I can assure you that in practice this is not a problem. If you do proper unit testing then you will catch many, if not all, of the errors that static typing catches. There are also tools like PyLint, PyFlakes and pep8.py will also catch many of those mistakes. > 2. It is not clear to me how a python web application scales. Python > is inherently single threaded, so one will need lots of python > processes on lots of computers, with the database software handling > parallel accesses to the same or related data. One could organize it > as one python program for each url, and one python process for each > http request, but that involves a lot of overhead starting up and > shutting down python processes. Or one could organize it as one > python program for each url, but if one gets a lot of http requests > for one url, a small number of python processes will each sequentially > handle a large number of those requests. What I am really asking is: > Are there python web frameworks that scale with hardware and how do > they handle scaling? What is the difference if you have a process with 10 threads or 10 separate processes running in parallel? Apache is a good example of a server that may be configured to use multiple processes to handle requests. And from what I hear is scales just fine. I think you are looking at the problem wrong. The fundamentals are the same between threads and processes. You simply have a pool of workers that handle requests. Any process is capable of handling any request. The key to scalability is that the processes are persistent and not forked for each request. > Please don't read this as "Python sucks, everyone should program in > machine language expressed as binary numbers". I am just asking where > the problems are. The only real problem I have had with process pools is that sharing resources is harder. It is harder to create things like connection pools. -- David http://www.traceback.org -- http://mail.python.org/mailman/listinfo/python-list
Re: scaling problems
On Tue, May 20, 2008 at 12:03 AM, James A. Donald <[EMAIL PROTECTED]> wrote: > On Mon, 19 May 2008 21:04:28 -0400, "David Stanek" > <[EMAIL PROTECTED]> wrote: >> What is the difference if you have a process with 10 threads or 10 >> separate processes running in parallel? Apache is a good example of a >> server that may be configured to use multiple processes to handle >> requests. And from what I hear is scales just fine. >> >> I think you are looking at the problem wrong. The fundamentals are the >> same between threads and processes. > > I am not planning to write a web server framework, but to use one. > Doubtless a python framework could be written to have satisfactory > scaling properties, but what are the scaling properties of the ones > that have been written? > Both Django and TurborGears work well for me. When you step back and think about it all of the popular web frameworks would do just fine. The ones that don't do multiprocessing out of the box would be trivial to load balance behind Apache or a real load balancer. Again the problem here is the number of connections to the database, once you get big enough to worry about it. -- David http://www.traceback.org -- http://mail.python.org/mailman/listinfo/python-list
Re: pylint naming conventions?
On Sun, Jun 7, 2009 at 9:23 AM, Esmail wrote: > Ben Finney wrote: >> >> Esmail writes: >> >>> I am confused by pylint's naming conventions, I don't think the are in >>> tune with Python's style recommendations (PEP 8?) >>> >>> Anyone else think this? >> >> It's hard to know, without examples. Can you give some output of pylint >> that you think doesn't agree with PEP 8? > > Sure, I will next time I have a nice self-contained example. Perhaps not > that > many people are using pylint? I was expecting a bunch of messages either > contradicting my observation or agreeing with it :-) .. but perhaps this > indicates that there's no issue. It is my understanding that it does check for PEP8 names. Even if it doesn't it is really easy to change. If you run 'pylint --generate-rcfile' (i think) it will output the configuration that it is using. You can then save this off and customize it. > > I'll try to come up with a nice short code example in the next few days > to demonstrate what I think the problem is and post it, thanks for the > suggestion. If you didn't have an example handy what prompted you to start this thread? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Odd closure issue for generators
On Thu, Jun 4, 2009 at 7:42 PM, Scott David Daniels wrote: > Brian Quinlan wrote: >> >> This is from Python built from the py3k branch: >> >>> c = (lambda : i for i in range(11, 16)) >> >>> for q in c: >> ... print(q()) >> ... >> 11 >> 12 >> 13 >> 14 >> 15 >> >>> # This is expected >> >>> c = (lambda : i for i in range(11, 16)) >> >>> d = list(c) >> >>> for q in d: >> ... print(q()) >> ... >> 15 >> 15 >> 15 >> 15 >> 15 >> >>> # I was very surprised > > You are entitled to be surprised. Then figure out what is going on. > Hint: it is the moral equivalent of what is happening here: > > >>> c = [] > >>> for i in range(11, 16): > c.append(lambda: i) > > >>> i = 'Surprise!' > >>> print([f() for f in c]) > ['Surprise!', 'Surprise!', 'Surprise!', 'Surprise!', 'Surprise!'] > > >>> i = 0 > >>> print([f() for f in c]) > [0, 0, 0, 0, 0] > > The body of your lambda is an un-evaluated expression with a reference, > not an expression evaluated at the time of loading c. TO get what you > expected, try this: > > >>> c = [] > >>> for i in range(11, 16): > c.append(lambda i=i: i) > > >>> i = 'Surprise!' > >>> print([f() for f in c]) > [11, 12, 13, 14, 15] > > When you evaluate a lambda expression, the default args are evaluated, > but the expression inside the lambda body is not. When you apply that > evaluated lambda expression, the expression inside the lambda body is > is evaluated and returned. > Getting around this can be pretty easy: c = (lambda i=i: i for i in range(11, 16)) for q in (list(c)): print(q()) -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Guidance on initialization code in a module
On Tue, Jun 16, 2009 at 4:54 PM, mrstevegross wrote: > Is there a common way to initialize various stuff in a module? That > is, I have some code in my module that I want to run whenever the > module is imported. Currently, my module looks like this: > > === foo.py === > def something(): > ... > > def somethingelse(): > ... > > something() > === EOF === > > Is the 'something()' line at the end in an ok location? I just put it > at the end. Maybe there's some special __init__() mechanism for > modules? Or should I use the 'if __name__ != '__main__'' trick? > I think what you are doing is fine. The only thing that I would do differently is rename 'something' to 'initialize'. That way your intent is really obvious. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Get name of class without instance
Try Foo.__name__ if Foo is a class object. On 6/24/09, Bryan wrote: > Given a class: > > class Foo(object): > pass > > How can I get the name "Foo" without having an instance of the class? > > str(Foo) gives me more than just the name Foo. "__main__.Account" > Foo.__class__.__name__ gives me "type" > > I don't want to do: > Foo().__class__.__name__ if possible. I would rather avoid the > constructor. I just want to get a string "Foo" > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Sent from my mobile device David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Unexpected behaviour of inner functions/ decorators
On Tue, Jun 30, 2009 at 1:44 PM, Francesco Bochicchio wrote: > [snip] > It looks like the decorator uses an older instance of 'funct', which > does not yet > have the attribute dinamically attached to it. This seem to be > confirmed by the fact that adding the attribute before > rebinding the function name, the problem disappear: The decorator is using the original function that you defined. By decorating 'funct' you are actually rebinding that name to the 'inner_f' function. So the statement 'funct.enabled = True' is actually creating an enabled property on the 'inner_f' function. Take a look at this code: >>> def def_f(f): ... def inner_f(): ... if iam.enabled: ... f() ... iam = inner_f ... return inner_f ... >>> @def_f ... def funct(): ... print 'Ciao' ... >>> funct.enabled = True >>> funct() Ciao -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for the right library for a simple HTTP client
On Fri, Jul 10, 2009 at 1:29 AM, scriptlear...@gmail.com wrote: > I am trying to implement a simple client that can do the following: > 1)to send the following kinds of HTTP requests and validate responses > 1.1 GET > 1.2 POST with application/x-www-form-urlencoded encoding > 1.3 POST with multipart/form-data encoding > > 2)to set any number of (even duplicate) headers. For example, I may > intentionally add the following Cookie: headers to a request: > Cookie: id_1=v1;Domain=sample.com;Path=/ > Cookie: id_1=v1;Domain=sample.com;Path=/ <--same as the one above > Cookie: id_2=v1;Domain=sample.com;Path=/ > > 3)to set proxy cfg so requests can go through a proxy server to reach > the target server. > > 4)to send multiple requests simultaneously. > > > I have Python 2.4.1 on Solaris 9 and 10, and I don't have any plan to > upgrade to latest version of Python. > > I looked around and I found httplib and urllib. Are they sufficient > for my tasks 1 to 3 above? Any good sample codes will be great. > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > I like urllib2. The examples[1] are pretty good. [1] http://www.python.org/doc/2.4.1/lib/urllib2-examples.html -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: How to unbuffer Python's output
2009/7/14 Lily Gao : > Hi, All > > I am calling a python program in perl and use redirection, > > Like : > > `python x.py > 1.log 2>&1` Try tihs instead: python x.py 2>&1 > 1.log -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Override a method but inherit the docstring
On Fri, Jul 17, 2009 at 2:58 AM, Peter Otten<__pete...@web.de> wrote: > Ben Finney wrote: > >> Howdy all, >> >> The following is a common idiom:: >> >> class FooGonk(object): >> def frobnicate(self): >> """ Frobnicate this gonk. """ >> basic_implementation(self.wobble) >> >> class BarGonk(FooGonk): >> def frobnicate(self): >> special_implementation(self.warble) >> >> The docstring for ‘FooGonk.frobnicate’ is, intentionally, perfectly >> applicable to the ‘BarGonk.frobnicate’ method also. Yet in overriding >> the method, the original docstring is not associated with it. >> >> Ideally there would be a way to specify that the docstring should be >> inherited. The best I can come up with is:: >> >> class BarGonk(FooGonk): >> def frobnicate(self): >> special_implementation(self.warble) >> frobnicate.__doc__ = FooGonk.frobnicate.__doc__ >> >> but that violates DRY (the association between BarGonk and FooGonk is >> being repeated), puts the docstring assignment awkwardly after the end >> of the method instead of at the beginning where docstrings normally go, >> and reads poorly besides. >> >> What is the most Pythonic, DRY-adherent, and preferably least-ugly >> approach to override a method, but have the same docstring on both >> methods? > > Just thinking aloud: Write a patch for pydoc that looks up the base-class > documentation. > > B.f.__doc__ will continue to return None, but > > help(B.f) will show something like > > No documentation available for B.f. > > Help for A.f: > yadda yadda > > > Of course that might be misleading when A.f and B.f are up to something > completely different... > This should never be the case. It violates LSP and would be very confusing to readers of the code. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Override a method but inherit the docstring
On Fri, Jul 17, 2009 at 3:52 AM, Steven D'Aprano wrote: > On Fri, 17 Jul 2009 12:58:48 +1000, Ben Finney wrote: > >>> Using a decorator in this manner requires repeating the super class >>> name. Perhaps there is a way to get the bases of BarGonk, but I don't >>> think so, because at the time that the decorator is called, BarGonk is >>> not yet fully defined. >> >> Yes, I tried a few different ways, but within the decorator it seems the >> function object is quite unaware of what class it is destined for. > > > When the decorator is called, the function object is just a function > object, not a method, so there is no concept of "what class it is > destined for". > def dec(func): > ... print type(func) > ... try: > ... print func.im_class > ... except: > ... print "no im_class" > ... return func > ... class Test(object): > ... @dec > ... def spam(self): > ... pass > ... > > no im_class type(Test.spam) > Test.spam.im_class > > > > I suppose you could try to determine what namespace you're currently when > the class is created, but that's surely going to be fragile and messy. > It isn't too bad. I got the idea to use the method's enclosing scope[1] in my decorator[2] from DecoratorTools. I am working to remove it because it make me sad, but it does work. [1] http://code.google.com/p/snake-guice/source/browse/snakeguice/decorators.py#51 [2] http://code.google.com/p/snake-guice/source/browse/snakeguice/decorators.py#58 -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Python import Error
On Sat, Jul 18, 2009 at 3:14 AM, Kalyan Chakravarthy wrote: > Hi All, > I am using Python 2.6, MySQL 4.0 , I have successfully > Instaled MySQLdb (MySQL-python-1.2.3c1.win32-py2.6) in my system. I tested > through command prompt with "import MySQLdb ", its not shwing any errors > (means its instaled successfully), I set Eneceranment variable for Python > > I am running simple application with import "MySQLdb" to get the connection > to MySQL, But its throwing "No module named MySQLdb", Please any one tell me > what couled be the reasion > > is there any version miss match with python and MySQL ? > > Since last 3days I am strugling on this > Off the top of my head I would say that maybe you are using one python binary from the command-line and another in your script or possibly your python path is foobar. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the private variables content
On Tue, Jul 21, 2009 at 6:00 PM, Rhodri James wrote: > On Tue, 21 Jul 2009 21:55:18 +0100, Ryniek90 wrote: > >> Hi. >> I'm writing some class, and decided to use inside private method and some >> private variables. While with method i haven't got any problem's with >> variables i have. > > There is no mechanism in Python that makes attributes truly private. > self._number is an attribute just like any other, the whole business > with _leading_underscores is purely a matter of convention. If you > have an instance attribute or method with a leading underscore, you > know that using it or calling it isn't something you're supposed > to do outside its class, but nothing will stop you doing exactly that > if you're rude enough to try. > Doubling the _ will give you a little more privacy. It really just mangles the attribute name, but it close to what you want. I just use a _single_under to tell other programmers that they shouldn't be accessing that attribute directly. To my knowledge nothing bad has happened because things are public and using the __double_under makes testing a little harder. >>> class C(object): ... def __init__(self): ... self.__x = 0 ... >>> c = C() >>> c.__x Traceback (most recent call last): File "", line 1, in AttributeError: 'C' object has no attribute '__x' >>> c._C__x 0 -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 performance problems only in python
On Thu, Jul 23, 2009 at 9:02 AM, Stef Mientki wrote: > > btw, I don't know if it's of any importance, the SQL-statement I perform is > select OPNAMEN.*, NAME, NAME_, SCORES.SCORE, PATIENT.* > from OPNAMEN > inner join POID_VLID on OPNAMEN.POID = POID_VLID.POID > inner join VRAAGLST on VRAAGLST.VLID = POID_VLID.VLID > inner join VLID_SSID on VRAAGLST.VLID = VLID_SSID.VLID > inner join SUBSCHAAL_GEGEVENS on SUBSCHAAL_GEGEVENS.SSID = VLID_SSID.SSID > inner join POID_SSID_SCID on ( OPNAMEN.POID = > POID_SSID_SCID.POID ) and > ( SUBSCHAAL_GEGEVENS.SSID = > POID_SSID_SCID.SSID ) > inner join SCORES on SCORES.SCID = > POID_SSID_SCID.SCID > inner join PID_POID on OPNAMEN.POID = PID_POID.POID > inner join PATIENT on PATIENT.PID = PID_POID.PID > where substr ( lower( NAME) , 1, 6) = 'cis20r' > and lower ( NAME_ ) = 'fatigue' > and TEST_COUNT in (3,4) > and DATETIME > 39814.0 > and SCORE < 30 Warning: I suck at SQL and hate it with a passion... By using lower() on the left side of the where expressions I believe that you are table scanning. So it is not the size of the data returned, but the size of the data that needs to be scanned. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 performance problems only in python
On Thu, Jul 23, 2009 at 6:29 PM, Stef Mientki wrote: > > but because the same SQL-statement in Delphi performed well, > I thought it was a problem with the Python implementation. Same SQL, but were you also using Sqlite in Delphi? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Is "feedparser" deprecated?
On Fri, Aug 7, 2009 at 3:07 PM, John Nagle wrote: > Feedparser requires SGMLlib, which has been removed from Python 3.0. > Feedparser hasn't been updated since 2007. Does this mean Feedparser > is dead? > The release is from 2007, but there are several recent commits. http://code.google.com/p/feedparser/source/list -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: hashability
On Wed, Aug 12, 2009 at 2:18 AM, Asun Friere wrote: > On Aug 12, 3:32 pm, James Stroud > wrote: > >> You should be more imaginative. > > I'm by no means discounting that there might be some actual problem > you're trying to solve here, but I honestly can't see it. How about a cache? Hashing by id means nothing across machines or even process runs on the same machine. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: httplib incredibly slow :-(
On Tue, Aug 11, 2009 at 4:25 PM, Chris Withers wrote: > Hi All, > > I'm using the following script to download a 150Mb file: > > from base64 import encodestring > from httplib import HTTPConnection > from datetime import datetime > > conn = HTTPSConnection('localhost') > headers = {} > auth = 'Basic '+encodestring('username:password').strip() > headers['Authorization']=auth > t = datetime.now() > print t > conn.request('GET','/somefile.zip',None,headers) > print 'request:',datetime.now()-t > response = conn.getresponse() > print 'response:',datetime.now()-t > data = response.read() > print 'read:',datetime.now()-t > > The output shows it takes over 20 minutes to do this. > However, this is on a local network, and downloading the same file in IE > takes under 3 seconds! > > I saw this issue: > > http://bugs.python.org/issue2576 > > I tried changing the buffer size to 4096 in a subclass as the issue > suggested, but I didn't see the reported speed improvement. > I'm using Python 2.6.2. > > Does anyone know of an alternative library for creating http requests and > getting their responses that's faster but hopefully has a similar interface? > I tried to reproduce this, but I could not. Could you paste in the output of your script? Also on the same box where you run this script can you test with curl or wget? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Function to apply superset of arguments to a function
On Wed, Sep 9, 2009 at 12:45 PM, Andrey Fedorov wrote: > Hi all, > > I've written a function [1] called apply_some which takes a set of > keywords arguments, filters only those a function is expecting, and > calls the function with only those arguments. This is meant to > suppress TypeErrors - a way to abstract the logic which checks what > arguments a passed-in function accepts. > > For example: > >> def foo(x=1, y=2): >> return (x,y) >> >> apply_some(foo, y=0, z="hi") // calls foo(y=0) >> -> (1,0) > > I'd like to expand this to fill undefined arguments with None, but > before I do, does anyone know of any packages/libraries which either > do something similar or would make this code cleaner? > > Cheers, > Andrey > > 1. http://gist.github.com/183375 > -- > http://mail.python.org/mailman/listinfo/python-list > What is your use-case for using this? It seems really odd to me. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: HTTP POST File without cURL
On Wed, Sep 9, 2009 at 1:57 PM, John D Giotta wrote: > I'm working with an API that allows me to POST a zip file via HTTP and > the documentation uses a cURL example. cURL works, but when I try to > POST the file via python it fails. > I don't want to use cURL (since I'm trying to be transparent and > dependency-less), but I can't find anything online that works. > > When I use multipart/form-data methods (found here > http://code.activestate.com/recipes/146306/), the recipient cannot > decipher the attached file. > > This is about the most difficult thing I've had to do with python and > yet it is supposed to be the very basics of HTTP. > > Example cURL command: > curl -v -u username:passwd --data-binary @/home/jdgiotta/test.zip -H > "Content-Type: application/zip" https://host/selector > > Is there a valid way to do this? > Without seeing code it is hard to tell what is happening. What I would do is capture the HTTP traffic and compare Python to cURL. Then you'll know how to change you script. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Function to apply superset of arguments to a function
On Wed, Sep 9, 2009 at 5:03 PM, Mel wrote: > David Stanek wrote: >> On Wed, Sep 9, 2009 at 12:45 PM, Andrey Fedorov >> wrote: > >>> I've written a function [1] called apply_some which takes a set of >>> keywords arguments, filters only those a function is expecting, and >>> calls the function with only those arguments. This is meant to >>> suppress TypeErrors - [ ... ] > >> What is your use-case for using this? It seems really odd to me. > > I may have run into one possible use. I have a program that uses DB-API 2.0 > to work with a database, sometimes SQLite3, sometimes PostgreSQL. Connect > parameters are built up in a dict from a combination of defaults, > environment values, and command-line arguments. This dictionary has to be > pruned down before calling connect, because sqlite3.connect doesn't take the > wide assortment of arguments that are needed for PostgreSQL. The existing > program does this "by hand", being programmed in advance to know which > parameters are acceptable to which database module. > The way I would normally do it is to use the URI format and based on the scheme choose a handler. For example: mysql://u...@host:server/db, would translate to a mysql specific function that knows what to do. Adding support for new schemes does mean an additional function, but I like the control. And it's explicit. I worry about the magic of the OP's approach. In your example generate a dictionary in a generic way and apply it to a set of functions. What happens if in the future if connect_mysql adds adds a parameter with the same name as one in connect_postgres, but different semantics. Now the magic is broken and you have an ugly special case. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Python server locks up
On Wed, Sep 9, 2009 at 4:28 PM, Zac Burns wrote: > > How would you suggest to figure out what is the problem? > I don't think you said your OS so I'll assume Linux. Sometimes it is more noise than value, but stracing the process may shed light on what system calls are being made. This in turn may help you narrow your focus. I find strace helps me a ton in some really tough problems. Are you watching for swapping, CPU usage, etc.? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list