Re: pushback iterator

2009-05-17 Thread Mike Kazantsev
next "pop" won't have to roam thru all the values again but instantly get the right one from the cache, or just get on with that iterable until it depletes. What real-world scenario am I missing here? -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: pushback iterator

2009-05-17 Thread Mike Kazantsev
tes. > > > > What real-world scenario am I missing here? > > > > ok, I admit that that the file was not good example. better example > would be just any iterator you use in your code. Somehow I've always managed to avoid such re-iteration scenarios, but of course, it could be just my luck ;) -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: How to convert a list of strings to a tuple of floats?

2009-05-18 Thread Mike Kazantsev
ted already... import itertools as it ftuple = tuple(it.imap( float, line.split('; ') )) -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: optparse options

2009-05-20 Thread Mike Kazantsev
e illogical and counter-intuitive to create "required options", since by definition they should be optional. Try using arguments instead, with some type-switching flags, if necessary - it should make CLI more consistent and save some typing by omitting otherwise always-required option argument ("--part"). -- Mike Kazantsev // fraggod.net signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Yet another question about class property.

2009-05-20 Thread Mike Kazantsev
Jim Qiu wrote: > Hi everyone, > > Following is the code i am reading, i don't see anywhere the declaration of > Message.root object, > Where is it from? ... Prehaps it gets assigned by the parent itself? Like this: def spawn_child(self): child = Message() child.r

Re: SpellChecker

2009-05-20 Thread Mike Kazantsev
work much faster with buffers than str / unicode. text = 'some text to correct (anything, really)' result = buffer('') word, c = buffer(''), '' for c in text: if c.isalpha(): word += c else: if word: result += correct(word)

Re: Import and absolute file names, sys.path including ''... or not

2009-05-20 Thread Mike Kazantsev
t) if absolute path gets appended to it: os.path.join('/some/path', '/home/jeanmichel') == '/home/jeanmichel' > So my question is: "why the shell is adding '' when the interpreter is > adding the full path ?" Looks like a solid way to construct relative imports to me. -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get Form values in Python code and Send Email

2009-05-20 Thread Mike Kazantsev
Content-Disposition', 'attachment; filename="%s"'% os.path.basename(file)) msg.attach(part) smtp = smtplib.SMTP(relay) smtp.sendmail(from, to, msg.as_string() ) smtp.close() -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: While Statement

2009-05-22 Thread Mike Kazantsev
seem to make more sense to me than an explicit conversion. There's also "op.itruediv" for "number /= float(total) * 100" case. http://docs.python.org/dev/library/operator.html -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Set a variable as in setter

2009-05-24 Thread Mike Kazantsev
>def bar(self, bar): > self._bar = self._change(bar) # !!! as in init > > def _change(self, text): > return text + 'any change' > --- -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: how to get rid of pyc files ?

2009-05-24 Thread Mike Kazantsev
switches are available for python ? > (googling didn't give me any relevant hits ) You might be amazed how much insight "man python" and "python -h" can yield ;) -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Set a variable as in setter

2009-05-24 Thread Mike Kazantsev
On Sun, 24 May 2009 19:03:26 +0600 Mike Kazantsev wrote: > On Sun, 24 May 2009 05:06:13 -0700 (PDT) > Kless wrote: > > > Is there any way to simplify the next code? Because I'm setting a > > variable by default of the same way than it's set in the setter. > &g

Re: extract to dictionaries

2009-05-29 Thread Mike Kazantsev
, 'key1': 'value1'} } To save namespace and make it a bit more unreadable you can write it as a one-liner: with open('test.src') as src: data = dict( (lines.next(), dict(it.imap(str.split, lines))) for sep,lines in it.groupby(it.ifilter(bool, it.imap(lambda x: x.s

Re: do replacement evenly

2009-06-02 Thread Mike Kazantsev
#x27; ' count_span_max = count_space - (count_span * len(span_min)) line = buffer(words[0]) for word in words[1:]: if count_span_max: count_span_max -= 1 line += span_min + ' ' else: line += span_min line += word print '%d chars: %r'%(len(line),

Re: Specify the sorting direction for the various columns/

2009-06-11 Thread Mike Kazantsev
'date': datetime.datetime(2007, 9, 30, 16, 43, 54)}, {'name': 'AA2', 'username': 'AA2','date': datetime.datetime(2007, 9, 30, 16, 43, 54)}] entries.sort(lambda x: (x['name'], -time.mktime(x['date'].timetuple( Here time is inversed, yielding reverse sort order by that column. -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] Multi-Threading and KeyboardInterrupt

2009-06-12 Thread Mike Kazantsev
gt; > ... a .join() call, which is the most likely position at which the > keyboard interrupt will be processed, killing the main program thread > and probably generating some errors as dangling active threads are > forceably killed. There was quite interesting explaination o

Re: Lexical scope: converting Perl to Python

2009-06-12 Thread Mike Kazantsev
nyway? It's not like you'd be able to accomplish it - code can easily grep it's process body in memory and harvest all the "private" values, so I'd suggest getting some fresh air when you start to feel like doing that. -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: moving Connection/PipeConnection between processes

2009-06-13 Thread Mike Kazantsev
s' table (with it's own numbering), which is usually done via special flag for sendmsg(2) in C, so you should probably look out for py implementation of this call, which I haven't stumbled upon, but, admittely, never looked for. -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Multi-Threading and KeyboardInterrupt

2009-06-13 Thread Mike Kazantsev
re other > links? Thanks for sharing this link, although I prefer such information in written form - it's easier/faster to work with and much more accessible. -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Exceptions and Object Destruction (was: Problem with apsw and garbage collection)

2009-06-13 Thread Mike Kazantsev
;with", file should end up closed, else os.rename might replace valid path with zero-length file. It should be easy to use cursor with contextlib, consider using contextmanager decorator: from contextlib import contextmanager @contextmanager def get_cursor(): try: cursor = conn.c

Re: Make upof Computer

2009-06-14 Thread Mike Kazantsev
On Sun, 14 Jun 2009 00:46:16 -0700 (PDT) "Mr . Waqar Akbar" wrote: ... Judging by the typo in the last subject, someone indeed types all this crap in manually! Oh my god... -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailma

Re: Different types of dicts with letter before the curly braces.

2009-06-14 Thread Mike Kazantsev
x27;d prefer to use dict() to declare a dict, not some mix of letters and incomprehensible symbols, thank you. -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Different types of dicts with letter before the curly braces.

2009-06-14 Thread Mike Kazantsev
or of "{0}".format(var) and I think it's a good call. There's only so much sugar to add before it'll transform into salt and you'll start seeing lines like these: s**'@z!~;()=~$x>;%x>l;$(,'*e;y*%z),$;@=!;h(l~;*punch jokers;halt;*;print; I

Re: Multi-Threading and KeyboardInterrupt

2009-06-15 Thread Mike Kazantsev
On Mon, 15 Jun 2009 05:37:14 -0700 (PDT) OdarR wrote: > On 13 juin, 07:25, Mike Kazantsev wrote: > > There was quite interesting explaination of what happens when you send > > ^C with threads, posted on concurrency-sig list recently: > > > >  http://bli

Re: parsing json using simplejson

2009-06-15 Thread Mike Kazantsev
On Sun, 14 Jun 2009 22:45:38 -0700 (PDT) deostroll wrote: > I need to be able to parse a json data object using the simplejson > package. First of all I need to know all the task needed for this job. Note that py2.6 has a bundled json module. -- Mike Kazantsev // fraggod.net signatu

Re: waling a directory with very many files

2009-06-15 Thread Mike Kazantsev
t; themselves, as I was thinking. I wish listdir had been changed in 3.0 > along with map, filter, and range, but I made no effort and hence cannot > complain. Why? We have itertools.imap, itertools.ifilter and xrange already. -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: parsing json using simplejson

2009-06-15 Thread Mike Kazantsev
nces # You can always use it as a regular dict print 'port' in data print data['see_also'] # Data model propagnates itself to any sub-mappings data.see_also.new_item = dict(x=1, y=2) print data.see_also.keys() data.see_also.new_item['z'] = 3 print data.see_also.new_item.z -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Multi-Threading and KeyboardInterrupt

2009-06-15 Thread Mike Kazantsev
d processes with a simple "while True: ..." loop, consider using twisted framework - it'll allow you to do incredible stuff with any number of sockets with just few lines of code in a clean, abstracted way. Latter would also mean that you can always replace os pipes with network sockets just

Re: persistent composites

2009-06-16 Thread Mike Kazantsev
nthusiasm. I've read this thread from the beginning, being tempted to insert remarks about shelve module or ORMs like SQLAlchemy, but that'd be meaningless without the problem description, which I haven't seen anywhere. Is it some trick idea like "let's walk on our heads"?

Re: Newbie help for using multiprocessing and subprocess packages for creating child processes

2009-06-16 Thread Mike Kazantsev
o read/write data from/to the pipes more than once (aka communicate), using threads or any more python subprocesses seem like hammering a nail with sledgehammer - just _read_ or _write_ to pipes asynchronously. -- Mike Kazantsev // fraggod.net -- http://mail.python.org/mailman/listinfo/python-list

Re: walking a directory with very many files

2009-06-16 Thread Mike Kazantsev
95ea with only hundred of them in each path. Former case (all-in-one-path) would even outperform the latter with ext3 or reiserfs by a small margin. Sadly, that's not the case with filesystems like FreeBSD ufs2 (at least in sixth branch), so it's better to play safe and create subdirs if

Re: Logging multiple lines

2009-06-16 Thread Mike Kazantsev
refix at the beginning of every line? I'd log exception name and timestamp (or id) only, pushing the full message with the same id to another log or facility (like mail it to some dedicated bug-report box). -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http:

Re: walking a directory with very many files

2009-06-16 Thread Mike Kazantsev
On Wed, 17 Jun 2009 03:42:02 GMT Lie Ryan wrote: > Mike Kazantsev wrote: > > In fact, on modern filesystems it doesn't matter whether you > > accessing /path/f9e95ea4926a4 with million files in /path > > or /path/f/9/e/95ea with only hundred of them in each path. Former

Re: walking a directory with very many files

2009-06-17 Thread Mike Kazantsev
> Why is that a problem? So you can os.listdir them? Don't ask me what for, however, since that's the original question. Also not every fs still in use handles this situation effectively, see my original post. -- Mike Kazantsev // fraggod.net signature.asc Description: PGP sig

Re: walking a directory with very many files

2009-06-17 Thread Mike Kazantsev
On Wed, 17 Jun 2009 23:04:37 +1200 Lawrence D'Oliveiro wrote: > In message <20090617142431.2b25f...@malediction>, Mike Kazantsev wrote: > > > On Wed, 17 Jun 2009 17:53:33 +1200 > > Lawrence D'Oliveiro wrote: > > > >> > Why not us

Re: walking a directory with very many files

2009-06-17 Thread Mike Kazantsev
On Thu, 18 Jun 2009 10:33:49 +1200 Lawrence D'Oliveiro wrote: > In message <20090617214535.10866...@coercion>, Mike Kazantsev wrote: > > > On Wed, 17 Jun 2009 23:04:37 +1200 > > Lawrence D'Oliveiro wrote: > > > >> In message <200906

Re: walking a directory with very many files

2009-06-19 Thread Mike Kazantsev
On Fri, 19 Jun 2009 17:53:40 +1200 Lawrence D'Oliveiro wrote: > In message <20090618081423.2e035...@coercion>, Mike Kazantsev wrote: > > > On Thu, 18 Jun 2009 10:33:49 +1200 > > Lawrence D'Oliveiro wrote: > > > >> In message <20090617

Re: multiprocessing and process run time

2009-06-19 Thread Mike Kazantsev
it can get the same results as well, w/o having to invoke shell commands: http://code.google.com/p/procpy/ -- Mike Kazantsev // fraggod.net -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling subprocess with arguments

2009-06-19 Thread Mike Kazantsev
/env python import sys open('/tmp/argv', 'w').write(repr(sys.argv)) And replace 'vlc' with a path to this script, then invoke it from a shell, compare the results. If it gets the right stuff, try the same with os.environ (prehaps vlc keeps socket location there, just like ssh/gpg-agents?). -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling subprocess with arguments

2009-06-19 Thread Mike Kazantsev
time w/o blocking. Try this recipe: http://code.activestate.com/recipes/576759/ -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Retrieving column values by column name with MySQLdb

2009-06-19 Thread Mike Kazantsev
result = db.store_result() data = result.fetch_row(maxrows=0, how=1) -- Mike Kazantsev // fraggod.net signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list

Re: Retrieving column values by column name with MySQLdb

2009-06-19 Thread Mike Kazantsev
ot;how" is 1 and wtf is this "how", anyway!? ;) I can't seem to find any mention of such methods in documentation and even python source, guess they are implemented directly in underlying C lib. Hope I learned to abstract from such syntax since then, I sure do... -- Mi

Re: Calling subprocess with arguments

2009-06-19 Thread Mike Kazantsev
the output from the second results, from py itself. My suggestion was just to compare them - pop the py shell, eval the outputs into two sets, do the diff and you'll see it at once. If there's an empty set then I guess it's pretty safe to assume that python creates subprocess i

Re: Calling subprocess with arguments

2009-06-19 Thread Mike Kazantsev
On Fri, 19 Jun 2009 22:00:28 +0600 Mike Kazantsev wrote: > On Fri, 19 Jun 2009 08:28:17 -0700 > Tyler Laing wrote: > > > Thanks mike, the idea that maybe some of the info isn't being passed is > > certainly interesting. > > > > Here's the output of

Re: n00b confusion re: local variable referenced before assignment error

2009-06-19 Thread Mike Kazantsev
t;, since the try has failed here. You might want to insert return or avoid (possibly endless) recursion altogether - just wrap it into while loop with some counter (aka max_tries). Also, you can get rid of code duplication by catching some basic urllib2 exception, then checking if it's ur