Official reason for omitting inspect.currentcallable() ?

2012-08-12 Thread kj
Is there an *explicitly stated* reason (e.g. in a PEP, or in some python dev list message) for why the inspect module (at least for Python 2.7) does not include anything like a "currentcallable()" function that would *stably*[1] return the currently executing callable object? (It seems unlikely

Re: Official reason for omitting inspect.currentcallable() ?

2012-08-13 Thread kj
In Chris Angelico writes: >I'm not familiar with it by that name, but Pike's this_function is >what the OP's describing. You got it. >It's a useful construct in theory when you want to write in recursion, >which was part of the rationale behind PE

How to get initial absolute working dir reliably?

2012-08-18 Thread kj
What's the most reliable way for "module code" to determine the absolute path of the working directory at the start of execution? (By "module code" I mean code that lives in a file that is not meant to be run as a script, but rather it is meant to be loaded as the result of some import statement

Why doesn't Python remember the initial directory?

2012-08-19 Thread kj
As far as I've been able to determine, Python does not remember (immutably, that is) the working directory at the program's start-up, or, if it does, it does not officially expose this information. Does anyone know why this is? Is there a PEP stating the rationale for it? Thanks! -- http://ma

Re: Why doesn't Python remember the initial directory?

2012-08-19 Thread kj
In Roy Smith writes: >In article , kj >wrote: >> As far as I've been able to determine, Python does not remember >> (immutably, that is) the working directory at the program's start-up, >> or, if it does, it does not officially expose this information. &

Java is killing me! (AKA: Java for Pythonheads?)

2011-08-12 Thread kj
n implementing and testing functions with optional arguments in Java would be appreciated. TIA! kj -- http://mail.python.org/mailman/listinfo/python-list

sick of distribute, setup, and all the rest...

2011-11-26 Thread kj
it's an all-out disgrace. when is python going to get a decent module distribution system??? and don't tell me to do it myself: it's clear that the sorry situation we have now is precisely that too many programmers without the requisite expertise or policy-making authority have decided to pitch

Overcoming herpetophobia (or what's up w/ Python scopes)?

2005-06-17 Thread kj
d during my first attempt. My question is: is there any tutorial on Python scoping aimed at diehard Perlheads? Thanks! kj -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. -- http://mail.python.org/mailman/listinfo/python-list

How to code dynamically created methods?

2007-06-20 Thread kj
is with my naive attempt to add a method to class A dynamically (in the last two lines of the definition of _auto). What's the right way to do this? Thanks! kj -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to code dynamically created methods?

2007-06-20 Thread kj
Nevermind, I found the problem... Thanks, kj In <[EMAIL PROTECTED]> kj <[EMAIL PROTECTED]> writes: >I've tried a bazillion ways to code dynamically generated methods, >to no avail. >The following snippet is a very simplified (and artificial) demo >of the proble

ISO programming projects

2007-04-01 Thread kj
a C compiler) or not terribly useful to the average person (e.g. a function that efficiently computes the n-th Fibonacci number). Any pointers would be much appreciated. kj -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it,

ISO books of official Python docs

2008-01-09 Thread kj
Is it possible to buy the official Python docs in book form? If so, I'd very much appreciate the name(s) and author(s) of the book(s). TIA! kynnjo -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. -- ht

Re: ISO books of official Python docs

2008-01-10 Thread kj
In <[EMAIL PROTECTED]> gordyt <[EMAIL PROTECTED]> writes: >Howdy kynnjo, >> Is it possible to buy the official Python docs in book form? If >> so, I'd very much appreciate the name(s) and author(s) of the >> book(s). >I haven't seen them in print form, but you can download PDF's from >here: >h

ISO Python example projects (like in Perl Cookbook)

2008-01-10 Thread kj
I'm looking for "example implementations" of small projects in Python, similar to the ones given at the end of most chapters of The Perl Cookbook (2nd edition, isbn: 0596003137). (Unfortunately, the otherwise excellent Python Cookbook (2nd edition, isbn: 0596007973), by the same publisher (O'Re

Text-based data inspector for Python?

2008-01-24 Thread kj
I've only recently started programming in Python, trying to wean myself from Perl. One of the things I *really* miss from Perl is a 100% mouse-free data inspector, affectionally known as the Perl debugger, PerlDB, or just perl -d. With it I can examine the most elaborate data structures with e

Re: Text-based data inspector for Python?

2008-01-25 Thread kj
In <[EMAIL PROTECTED]> Paddy <[EMAIL PROTECTED]> writes: >python -h gives me: > ... > Other environment variables: > PYTHONSTARTUP: file executed on interactive startup (no default) > ... Sweet. Thanks! kynn -- NOTE: In my address everything before the first period is backwards; and the la

Re: Text-based data inspector for Python?

2008-01-25 Thread kj
In <[EMAIL PROTECTED]> Terry Jones <[EMAIL PROTECTED]> writes: >>>>>> "kj" == kj <[EMAIL PROTECTED]> writes: >You actually liked the perl debugger... gasp! Still do, in fact!. >OK, I used it too, but it >left a few things to be desire

Re: Text-based data inspector for Python?

2008-01-25 Thread kj
In <[EMAIL PROTECTED]> Paddy <[EMAIL PROTECTED]> writes: >I tend to do the following at the python prompt: > from pprint import pprint as pp Thanks, that's a good one to know, but isn't there a way to automate it??? I looked around, but I couldn't find the name of any *rc-type file that would

Python noob SOS (any [former?] Perlheads out there?)

2008-01-29 Thread kj
For many months now I've been trying to learn Python, but I guess I'm too old a dog trying to learn new tricks... For better or worse, I'm so used to Perl when it comes to scripting, that I'm just having a very hard time getting a hang of "The Python Way." It's not the Python syntax that I'm ha

Re: Python noob SOS (any [former?] Perlheads out there?)

2008-01-30 Thread kj
In <[EMAIL PROTECTED]> "Reedick, Andrew" <[EMAIL PROTECTED]> writes: >> Be that as it may, the activation barrier to using Python for my >> scripting remains too high. >>=20 >> I'd written a Perl module to facilitate the writing of scripts. >> It contained all my boilerplate code for parsing and v

Re: Python noob SOS (any [former?] Perlheads out there?)

2008-01-30 Thread kj
In <[EMAIL PROTECTED]> Wildemar Wildenburger <[EMAIL PROTECTED]> writes: >kj wrote: >> Is there any good reading (to ease the transition) for Perl >> programmers trying to learn Python? >> >www.diveintopython.org Thanks. Not for Perl programmers specifical

ISO exemplary Python scripts

2009-05-08 Thread kj
I'm learning python, for the umpteenth time. This time I decided to start out by writing Python scripts for everyday tasks. Most of these scripts are meant to be used only once or twice, but a few of them have become useful enough that I'd like to make them a little bit more solid... I'd like

Re: ISO exemplary Python scripts

2009-05-09 Thread kj
In <802a051qoqmpnih0j2su9hhriqumagu...@4ax.com> Tim Roberts writes: >kj wrote: >> >>I'm learning python, for the umpteenth time. This time I decided >>to start out by writing Python scripts for everyday tasks. Most >>of these scripts are meant to be u

Q's on my first python script

2009-05-10 Thread kj
Below is my very firs python script. This was just a learning exercise; the script doesn't do anything terribly exciting: for an argument of the form YYMMDD (year, month, day) it prints out the corresponding string YYMMDDW, where W is a one-letter abbreviation for the day of the week. E.g. % wd

Re: Q's on my first python script

2009-05-10 Thread kj
In <0216ec41$0$20647$c3e8...@news.astraweb.com> Steven D'Aprano writes: >On Sun, 10 May 2009 12:52:21 +, kj wrote: >> 1. The name of the BadArgument exception class defined in the script >>does not seem to me sufficiently specific. If one were to import th

Re: Q's on my first python script

2009-05-10 Thread kj
Thank you all very much! I really appreciate it. kynn -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. -- http://mail.python.org/mailman/listinfo/python-list

What's the use of the else in try/except/else?

2009-05-10 Thread kj
I know about the construct: try: # do something except ...: # handle exception else: # do something else ...but I can't come with an example in which the same couldn't be accomplished with try: # do something # do something else except ...: # handle exception The only

Re: What's the use of the else in try/except/else?

2009-05-11 Thread kj
In Scott David Daniels writes: >kj wrote: >> ... I can't come with an example in which the same couldn't be >> accomplished with >> >> try: >> # do something >> # do something else >> except ...: >> # handle exception

OS X: How to play .wav file w/Python?

2009-05-11 Thread kj
Hi. I'm trying to learn how to play a .wav file in OS X with Python. I tried the following, which ran without errors, but produced nothing audible (even though the file bell.wav plays perfectly well otherwise, e.g. view the Finder's Preview): import pygame.mixer pygame.mixer.init() pygame.mixer.

How to get all named args in a dict?

2009-05-13 Thread kj
Suppose I have the following: def foo(x=None, y=None, z=None): d = {"x": x, "y": y, "z": z} return bar(d) I.e. foo takes a whole bunch of named arguments and ends up calling a function bar that takes a single dictionary as argument, and this dictionary has the same keys as in foo's sign

Re: How to get all named args in a dict?

2009-05-14 Thread kj
In Terry Reedy writes: >kj wrote: >> >> Suppose I have the following: >> >> def foo(x=None, y=None, z=None): >> d = {"x": x, "y": y, "z": z} >> return bar(d) >> >> I.e. foo takes a whole bunch of named

How to get the formal args of a function object?

2009-05-14 Thread kj
Suppose that f is an object whose type is 'function'. Is there a way to find out f's list of formal arguments? The reason for this is that I'm trying to write a decorator and I'd like the wrapper to be able to check the number of arguments passed. Specifically, I'd like the wrapper to look as

Re: How to get all named args in a dict?

2009-05-14 Thread kj
In Dave Angel writes: >kj wrote: >> In Terry Reedy >> writes: >> >> >>> kj wrote: >>> >>>> Suppose I have the following: >>>> >>>> def foo(x=None, y=None, z=None): >>>> d = {&

Need advice on distributing small module

2009-05-14 Thread kj
I've written a tiny module that I'd like to make available online from my website. This module is not "production-grade" code; it is meant only as an illustration, but still I'd like to make its download and installation as painless as possible. I could simply bundle everything into a .tgz fil

Re: How to get the formal args of a function object?

2009-05-15 Thread kj
In Chris Rebert writes: >Take a look at inspect.getargspec(func): >http://docs.python.org/library/inspect.html#inspect.getargspec Thank you much, that did the trick. And inspect is a very handy module to know about. kynn -- NOTE: In my address everything before the first period is backwards

Re: Need advice on distributing small module

2009-05-15 Thread kj
In <99246143-a853-4041-bc45-eeb648388...@r3g2000vbp.googlegroups.com> Carl Banks writes: >On May 14, 1:26=A0pm, kj wrote: >> I've written a tiny module that I'd like to make available online >> from my website. =A0This module is not "production-gr

Advanced Python books?

2009-05-18 Thread kj
I have read a couple of "learn Python"-type books, and now I'm looking for some more advanced books on Python, something analogous to "Effective Java" or "High-Order Perl". I've only been able to find "Advanced Python 3 Programming Techniques", which, as far as I can tell, is only available as a

how to iterate over several lists?

2009-06-04 Thread kj
Suppose I have two lists, list_a and list_b, and I want to iterate over both as if they were a single list. E.g. I could write: for x in list_a: foo(x) for x in list_b: foo(x) But is there a less cumbersome way to achieve this? I'm thinking of something in the same vein as Perl's: fo

Re: how to iterate over several lists?

2009-06-05 Thread kj
In Chris Rebert writes: >Just add the lists together. >for x in list_a + list_b: >foo(x) Cool! Thanks! kynn -- -- http://mail.python.org/mailman/listinfo/python-list

How to send a POST request?

2008-06-06 Thread kj
Hi. Sorry for this very clueless question, but how does one write in Python an HTTP client that can send a POST request? The modules I've found (e.g. urllib, urllib2), as far as I can tell, seem to be limited to GET requests. (I could be wrong though; please correct me if this is so.) TIA!

Re: How to send a POST request?

2008-06-06 Thread kj
In <[EMAIL PROTECTED]> kj <[EMAIL PROTECTED]> writes: >Hi. Sorry for this very clueless question, but how does one write >in Python an HTTP client that can send a POST request? The modules >I've found (e.g. urllib, urllib2), as far as I can tell, seem to >be limit

Need help porting Perl function

2008-06-07 Thread kj
Hi. I'd like to port a Perl function that does something I don't know how to do in Python. (In fact, it may even be something that is distinctly un-Pythonic!) The original Perl function takes a reference to an array, removes from this array all the elements that satisfy a particular criterion,

Re: How to send a POST request?

2008-06-07 Thread kj
Thanks to Jeff and subeen for the helpful comments and suggestions. Kynn -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help porting Perl function

2008-06-07 Thread kj
>This function will take a list of integers and modify it in place such >that it removes even integers. The removed integers are returned as a >new list Great! Thanks! kynn -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, sh

Re: Need help porting Perl function

2008-06-08 Thread kj
In <[EMAIL PROTECTED]> John Machin <[EMAIL PROTECTED]> writes: >It's nothing to do with list comprehensions, which are syntactical >sugar for traditional loops. You could rewrite your list comprehension >in the traditional manner... >and it would still fail for the same reason: mutating the list o

Re: Need help porting Perl function

2008-06-08 Thread kj
In <[EMAIL PROTECTED]> kj <[EMAIL PROTECTED]> writes: >In <[EMAIL PROTECTED]> John Machin <[EMAIL PROTECTED]> writes: >>It's nothing to do with list comprehensions, which are syntactical >>sugar for traditional loops. You could rewrite your list compre

How to get full path to script?

2008-06-08 Thread kj
How can a script know its absolute path? (__file__ only gives the path it was used to invoke the script.) Basically, I'm looking for the Python equivalent of Perl's FindBin. The point of all this is to make the scripts location the reference point for the location of other files, as part of a

Re: How to get full path to script?

2008-06-08 Thread kj
In <[EMAIL PROTECTED]> "Mark Tolonen" <[EMAIL PROTECTED]> writes: >import os >print os.path.abspath(__file__) Great. Thanks! Kynn -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. -- http://mail.python.or

Q re documentation Python style

2008-06-08 Thread kj
I'm a Perlhead trying to learn the Way of Python. I like Python overall, but every once in a while I find myself trying to figure out why Python does some things the way it does. At the moment I'm scratching my head over Python's docstrings. As far as I understand this is the standard way to d

Re: Q re documentation Python style

2008-06-09 Thread kj
Wow. That was a great bunch of advice. Thank you all very much! Kynn -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get full path to script?

2008-06-09 Thread kj
In <[EMAIL PROTECTED]> "Mike Driscoll" <[EMAIL PROTECTED]> writes: >For my compiled scripts, I usually use this variation: >path = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]))) Thanks. But why the os.path.join()? (BTW, I did read the docs before posting, but they make no sense to

Strange bug doesn't occur in Pydb

2008-06-11 Thread kj
I'm running into a strange seg fault with the module cjson. The strange part is that it does not occur when I run the code under Emacs' Pydb. Here's an example: import sys, cjson d1 = {'a': 1, 'b': 2, 'c': 3} print sys.version j1 = cjson.encode(d1) print j1 # should print the string '{"a

Re: Strange bug doesn't occur in Pydb

2008-06-12 Thread kj
In <[EMAIL PROTECTED]> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes: >kj schrieb: >> I'm running into a strange seg fault with the module cjson. The >> strange part is that it does not occur when I run the code under >> Emacs' Pydb. &g

Re: Strange cjson bug doesn't occur in Pydb

2008-06-12 Thread kj
[Note: I changed the subject line to make it more informative.] In <[EMAIL PROTECTED]> "Diez B. Roggisch" <[EMAIL PROTECTED]> writes: >kj wrote: >> In <[EMAIL PROTECTED]> "Diez B. Roggisch" >> <[EMAIL PROTECTED]> writes: >>

Python noob's simple config problem

2008-06-12 Thread kj
I'm sure this is a simple, but recurrent, problem for which I can't hit on a totally satisfactory solution. As an example, suppose that I want write a module X that performs some database access. I expect that 99.999% of the time, during the foreseeable future, the database connection paramete

Re: Python noob's simple config problem

2008-06-13 Thread kj
In <[EMAIL PROTECTED]> =?iso-8859-1?q?Robin_K=E5veland?= Hansen <[EMAIL PROTECTED]> writes: >On Thu, 12 Jun 2008 21:32:34 +, kj wrote: >> I'm sure this is a simple, but recurrent, problem for which I can't hit >> on a totally satisfactory solution. >

How to sort very large arrays?

2008-06-13 Thread kj
I'm downloading some very large tables from a remote site. I want to sort these tables in a particular way before saving them to disk. In the past I found that the most efficient way to do this was to piggy-back on Unix's highly optimized sort command. So, from within a Perl script, I'd creat

Noob: finding my way around the docs...

2008-06-19 Thread kj
d I'm very used (maybe too used) to the fact that if the Perl module Foo::Bar::Baz is installed on our system, all I need to do to read its full-blown documentation in all its glory is to type "perldoc Foo::Bar::Baz" at the command line. Is there anything like this in Python? TIA!

Why no output from xml.dom.ext.PrettyPrint?

2008-06-19 Thread kj
OK, the following should work but doesn't, and I can't figure out why: >>> from xml.marshal.generic import dumps >>> dumps( ( 1, 2.0, 'foo', [3,4,5] ) ) '12.0foo345' >>> from xml.dom.ext import PrettyPrint >>> PrettyPrint( dumps( ( 1, 2.0, 'foo', [3,4,5] ) ) ) >>> import sys >>> PrettyPrint( du

Re: Noob: finding my way around the docs...

2008-06-20 Thread kj
In <[EMAIL PROTECTED]> Matimus <[EMAIL PROTECTED]> writes: >If you are in the interpreter and you type: help(foo.bar.baz) you get >the embeded documentation. >I usually go straight to the `global module index` http://docs.python.org/m= >odindex.html Thanks! kynn -- NOTE: In my address everythi

Re: Why no output from xml.dom.ext.PrettyPrint?

2008-06-20 Thread kj
In <[EMAIL PROTECTED]> John Machin <[EMAIL PROTECTED]> writes: >On Jun 20, 7:17 am, kj <[EMAIL PROTECTED]> wrote: >> OK, the following should work but doesn't, and I can't figure out >> why: >> >> >>> from xml.ma

ISO dict => xml converter

2008-06-20 Thread kj
Hi. Does anyone know of a module that will take a suitable Python dictionary and return the corresponding XML structure? In Perl I use XML::Simple's handy XMLout function: use XML::Simple 'XMLout'; my %h = ( 'Foo' => +{ 'Bar' => +{

x, = y (???)

2008-07-17 Thread kj
I just came across an assignment of the form x, = y where y is a string (in case it matters). 1. What's the meaning of the comma in the LHS of the assignment? 2. How could I have found this out on my own? (Regarding (2) above, I consulted the index of several Python reference books but I c

Re: x, = y (???)

2008-07-17 Thread kj
In <[EMAIL PROTECTED]> Erik Max Francis <[EMAIL PROTECTED]> writes: >kj wrote: >> I just came across an assignment of the form >> >> x, = y >> >> where y is a string (in case it matters). >> >> 1. What's the meaning of the

Re: x, = y (???)

2008-07-18 Thread kj
In <[EMAIL PROTECTED]> Matthew Woodcraft <[EMAIL PROTECTED]> writes: >kj wrote: >> I still don't get it. If we write >> >> y = 'Y' >> x, = y >> >> what's the difference now between x and y? And if there's no >>

backspace problems

2008-07-29 Thread kj
If I'm in the python interactive interpreter, I get a beep when I hit the backspace key. I must confess, though, that my terminal is "complicated", to put it mildly: I work on a Mac running Leopard; I open a Terminal session, and through it I ssh to an Ubuntu server; on this server I connect to

Re: backspace problems

2008-07-29 Thread kj
In <[EMAIL PROTECTED]> kj <[EMAIL PROTECTED]> writes: Please ignore my question. I found a general solution that works not only for the python interactive interpreter but also for all programs that have a readline-type interaction. This solution has nothing to do with Python, but

DB access without object-relation mapping?

2008-07-29 Thread kj
Python noob here. I want to write a script that creates and populates a simple Postgres database. The word on the street is to use something like SQLAlchemy for database access in Python, but my experience in the past with packages that perform automated SQL generation has been awful, so I alw

Re: DB access without object-relation mapping?

2008-07-29 Thread kj
In <[EMAIL PROTECTED]> Tim Henderson <[EMAIL PROTECTED]> writes: >I believe there are a couple of options but pyscopg, and PyGreSQL seem >to be popular. Great. Thanks! kynn -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, sho

iterating "by twos"

2008-07-29 Thread kj
Is there a special pythonic idiom for iterating over a list (or tuple) two elements at a time? I mean, other than for i in range(0, len(a), 2): frobnicate(a[i], a[i+1]) ? I think I once saw something like for (x, y) in forgotten_expression_using(a): frobnicate(x, y) Or maybe I just

Where is the documentation for psycopg2?

2008-07-29 Thread kj
Hi. I can't find any documentation for psycopg2. I'm a noob, so I'm sure I'm just not looking in the right place... Anybody know where it is? TIA! kynn -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded

Re: iterating "by twos"

2008-07-29 Thread kj
Thanks for all the replies. I learned a lot! kynn -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. -- http://mail.python.org/mailman/listinfo/python-list

static variables in Python?

2008-07-29 Thread kj
Yet another noob question... Is there a way to mimic C's static variables in Python? Or something like it? The idea is to equip a given function with a set of constants that belong only to it, so as not to clutter the global namespace with variables that are not needed elsewhere. For example,

Re: Where is the documentation for psycopg2?

2008-07-29 Thread kj
In <[EMAIL PROTECTED]> Matthew Woodcraft <[EMAIL PROTECTED]> writes: >kj <[EMAIL PROTECTED]> wrote: >> Hi. I can't find any documentation for psycopg2. >> >> I'm a noob, so I'm sure I'm just not looking in the right place... >> &

Re: static variables in Python?

2008-07-29 Thread kj
In <[EMAIL PROTECTED]> Larry Bates <[EMAIL PROTECTED]> writes: >kj wrote: >> Yet another noob question... >> >> Is there a way to mimic C's static variables in Python? Or something >> like it? The idea is to equip a given function with a set of >&

Re: iterating "by twos"

2008-07-29 Thread kj
In <[EMAIL PROTECTED]> Terry Reedy <[EMAIL PROTECTED]> writes: >kj wrote: >> Is there a special pythonic idiom for iterating over a list (or >> tuple) two elements at a time? >> >> I mean, other than >> >> for i in range(0, len(a), 2)

how to split text into lines?

2008-07-30 Thread kj
In Perl, one can break a chunk of text into an array of lines while preserving the trailing line-termination sequence in each line, if any, by splitting the text on the regular expression /^/: DB<1> x split(/^/, "foo\nbar\nbaz") 0 'foo ' 1 'bar ' 2 'baz' But nothing like this seems to work

Re: how to split text into lines?

2008-07-30 Thread kj
In <[EMAIL PROTECTED]> kj <[EMAIL PROTECTED]> writes: >In Perl, one can break a chunk of text into an array of lines while >preserving the trailing line-termination sequence in each line, if >any, by splitting the text on the regular expression /^/: > DB<1> x

overriding file.readline: "an integer is required"

2008-07-30 Thread kj
I'm trying to subclass file, overriding the readline method. The new method definition begins with def readline(self, size=None): line = self.file.readline(size) # etc., etc. ...where the self.file attribute is a regular file object. This works fine if I invoke the new met

popen hangs sporadically

2008-08-01 Thread kj
I have a script that calls the function write_tmpfile, which looks something like this: def write_tmpfile(f, tmpfile): # set-up code omitted in_f = popen("""grep -v '^\\[eof\\]$' %s |\ grep '[^[:space:]]' |\ sort -u""" % f) out_f = open(tmpf

Re: overriding file.readline: "an integer is required"

2008-08-01 Thread kj
In <[EMAIL PROTECTED]> Miles <[EMAIL PROTECTED]> writes: >On Wed, Jul 30, 2008 at 5:52 PM, kj <[EMAIL PROTECTED]> wrote: >> I know that I could rewrite the method like this: >> >>def readline(self, size=None): >>if size == None: >>

How to troubleshoot hanging script?

2008-08-05 Thread kj
Hi! I have a Pythonoob question. I have a script that hangs indefinitely at random times; the only thing to do at this point is to kill it. I'm looking for suggestions on how to troubleshoot and debug the problem. I'm not even sure of where exactly the script is hanging, though I suspect it i

ISO all functions+methods+classes without docstring

2009-12-23 Thread kj
I'm looking for a good way to get a listing of all the undocumented (i.e. docstring-less) functions, classes, and methods as defined in a (largish) library of files. What's a good way to get this information? TIA! -Kynn -- http://mail.python.org/mailman/listinfo/python-list

ISO module for binomial coefficients, etc.

2010-01-23 Thread kj
Before I go off to re-invent a thoroughly invented wheel, I thought I'd ask around for some existing module for computing binomial coefficient, hypergeometric coefficients, and other factorial-based combinatorial indices. I'm looking for something that can handle fairly large factorials (on the

flow control and nested loops

2009-09-25 Thread kj
In Perl, one can label loops for finer flow control. For example: X: for my $x (@X) { Y: for my $y (@Y) { for my $z (@Z) { next X if test1($x, $y, $z); next Y if test2($x, $y, $z); frobnicate($x, $y, $z); } glortz($x, $y); } splat($x); } What's considered

How to control I/O buffering besides -u?

2009-09-26 Thread kj
Is there any way to specify unbuffered I/O from *within* the code (rather than via the command-line -u flag)? TIA! kynn -- http://mail.python.org/mailman/listinfo/python-list

Q: sort's key and cmp parameters

2009-10-01 Thread kj
Challenge: to come up with a sorting task that cannot be achieved by passing to the sort method (or sorted function) suitable values for its key and reverse parameters, but instead *require* giving a value to its cmp parameter. For example, from random import random scrambled = some_list.sort(c

Re: Q: sort's key and cmp parameters

2009-10-01 Thread kj
ry, reversed=3DTrue) >sorted(s, key=primary) In the special case where the value returned by secondary is numeric, I suppose one could do this in one go with sorted(s, key=lambda x: (primary(x), -secondary(x))) ...but I can't think of a way to generalize this... kj -- http://mai

Re: Q: sort's key and cmp parameters

2009-10-01 Thread kj
In <7x1vln2bzh@ruckus.brouhaha.com> Paul Rubin <http://phr...@nospam.invalid> writes: >kj writes: >> Is there a real-life sorting task that requires (or is far more >> efficient with) cmp and can't be easily achieved with key and >> reverse? >Yes, t

Re: Q: sort's key and cmp parameters

2009-10-01 Thread kj
In alex23 writes: >kj wrote: >> This example convinces me that it was a bad idea to >> get rid of cmp in Python 3, even if situations like this one are >> rare. >It sounds like the entire point of this exercise was to get other >people to confirm your bias for

Re: Q: sort's key and cmp parameters

2009-10-03 Thread kj
es are not there. It seems to me it would take forever to get the simplest things done in these languages... Confused. kj -- http://mail.python.org/mailman/listinfo/python-list

"smtplib.SMTPServerDisconnected: please run connect() first"

2009-10-09 Thread kj
I'm getting the error: smtplib.SMTPServerDisconnected: please run connect() first when I run code that is essentially identical to the code given in http://docs.python.org/library/email-examples.html The error happens at the line (copied verbatim from the example linked to above): s.

Re: "smtplib.SMTPServerDisconnected: please run connect() first"

2009-10-09 Thread kj
In Ethan Furman writes: >The line preceeding it, >s = smtplib.SMTP() >needs to have an e-mail server specified. E.g. >s = smtplib.SMTP('localhost') # from the 2.5 docs Perfect. Thanks! kynn -- http://mail.python.org/mailman/listinfo/python-list

The rap against "while True:" loops

2009-10-10 Thread kj
I'm coaching a group of biologists on basic Python scripting. One of my charges mentioned that he had come across the advice never to use loops beginning with "while True". Of course, that's one way to start an infinite loop, but this seems hardly a sufficient reason to avoid the construct alt

Re: The rap against "while True:" loops

2009-10-10 Thread kj
In <01ccc46d-5ea9-4dfe-ba22-699c6b859...@v36g2000yqv.googlegroups.com> Mensanator writes: >On Oct 10, 3:15=EF=BF=BDpm, kj wrote: >> I'm coaching a group of biologists on basic Python scripting. =EF=BF=BDOn= >e >> of my charges mentioned that he had come across the

postprocessing in os.walk

2009-10-12 Thread kj
Perl's directory tree traversal facility is provided by the function find of the File::Find module. This function accepts an optional callback, called postprocess, that gets invoked "just before leaving the currently processed directory." The documentation goes on to say "This hook is handy fo

Re: postprocessing in os.walk

2009-10-13 Thread kj
In Dave Angel writes: >kj wrote: >> Perl's directory tree traversal facility is provided by the function >> find of the File::Find module. This function accepts an optional >> callback, called postprocess, that gets invoked "just before leaving >> the

How to modify local variables from internal functions?

2009-10-23 Thread kj
I like Python a lot, and in fact I'm doing most of my scripting in Python these days, but one thing that I absolutely *DETEST* about Python is that it does allow an internal function to modify variables in the enclosing local scope. This willful hobbling of internal functions seems to m

Aaaargh! "global name 'eggz' is not defined"

2009-10-29 Thread kj
How can one check that a Python script is lexically correct? As my Python apps grow in complexity and execution, I'm finding it more often the situation in which a program dies after a lengthy (i.e. expensive) run because the execution reaches, say, a typo. Of course, this typo needs to be fixed

How can module determine its own path?

2009-10-30 Thread kj
How can a module determine the path of the file that defines it? (Note that this is, in the general case, different from sys.argv[0].) TIA! kynn -- http://mail.python.org/mailman/listinfo/python-list

  1   2   3   4   >