Re: Clever hack or code abomination?

2011-12-01 Thread Chris Angelico
On Thu, Dec 1, 2011 at 2:15 PM, Roy Smith wrote: > for suffix in [''] + [str(i) for i in xrange(-1, -20, -1)]: > > It generates the right sequence of strings.  But, if you came upon that > code, would it make sense to you, or would you spend half the afternoon > trying to figure out what it did an

Re: Clever hack or code abomination?

2011-12-01 Thread Arnaud Delobelle
On 1 December 2011 03:15, Roy Smith wrote: > I need to try a bunch of names in sequence until I find one that works > (definition of "works" is unimportant).  The algorithm is: > > 1) Given a base name, "foo", first see if just plain "foo" works. > > 2) If not, try "foo-1", "foo-2", and so on > >

Reading twice from STDIN

2011-12-01 Thread janedenone
Hi, I would like to read from a pipe, parse the input and ask the user what to do next: message = sys.stdin.read() # message is parsed and URLs are printed as a list to choose from... selected_index = raw_input('Which URL to open?') Calling raw_input() always raises in an EOFError. I tried reope

get date from email

2011-12-01 Thread Thomas Guettler
Hi, up to now I use this code to parse date values from emails: msg=email.message_from_file(open(file_name)) date=None date_str=msg.get('date') if date_str: date_tuple=email.utils.parsedate_tz(date_str) if date_tuple: date=datetime.datetime.fromtimestamp(email.utils.mktime_tz(date

Re: unpack('>f', b'\x00\x01\x00\x00')

2011-12-01 Thread Hrvoje Niksic
Chris Rebert writes: > C does not have a built-in fixed-point datatype, so the `struct` > module doesn't handle fixed-point numbers directly. The built-in decimal module supports fixed-point arithmetic, but the struct module doesn't know about it. A bug report (or patch) by someone who works wi

Re: order independent hash?

2011-12-01 Thread Gelonida N
On 11/30/2011 01:32 PM, Neal Becker wrote: > I like to hash a list of words (actually, the command line args of my > program) > in such a way that different words will create different hash, but not > sensitive > to the order of the words. Any ideas? > Do youmean hash like digest like md5sum

Re: Reading twice from STDIN

2011-12-01 Thread Gelonida N
On 12/01/2011 11:01 AM, janedenone wrote: Hi, > > I would like to read from a pipe, parse the input and ask the user > what to do next: > > message = sys.stdin.read() With above line you said, that you want to read ALL data from stdin, so it's obvious that any following command will be unable

Complete beginner, any help appreciated :) - For Loops

2011-12-01 Thread Mark
Hi there, I'm a complete beginner to Python and, aside from HTML and CSS, to coding in general. I've spent a few hours on it and think I understand most of the syntax. However, I'm wondering a bit about For Loops. I know that the basic syntax for them is to define a list, and then to use someth

Re: Complete beginner, any help appreciated :) - For Loops

2011-12-01 Thread Laurent Claessens
for x in y However, what does "for" and "in" mean in this context? It means basically the same as in Englsish Does the following links answer the question ? http://www.ibiblio.org/g2swap/byteofpython/read/for-loop.html http://dsnra.jpl.nasa.gov/software/Python/diveintopython.pdf (page 58) H

Re: Complete beginner, any help appreciated :) - For Loops

2011-12-01 Thread Pedro Henrique G. Souto
On 01/12/2011 08:53, Mark wrote: Hi there, I'm a complete beginner to Python and, aside from HTML and CSS, to coding in general. I've spent a few hours on it and think I understand most of the syntax. However, I'm wondering a bit about For Loops. I know that the basic syntax for them is to d

RE: Py and SQL

2011-12-01 Thread Sells, Fred
I find it easier to code like this Sql = ‘’’select yadda, yadda, yadda FROM a,b,c Where this=that ORDER BY deudderting’’’ With the appropriate %s(varname) and % against a dictionary rather than positional args, but that’s just me. From: python-list-bounces+frsells=adventistcare...

Re: Complete beginner, any help appreciated :) - For Loops

2011-12-01 Thread Dave Angel
On 12/01/2011 06:32 AM, Pedro Henrique G. Souto wrote: On 01/12/2011 08:53, Mark wrote: Hi there, I'm a complete beginner to Python and, aside from HTML and CSS, to coding in general. I've spent a few hours on it and think I understand most of the syntax. However, I'm wondering a bit about

Re: Complete beginner, any help appreciated :) - For Loops

2011-12-01 Thread Mark
Thanks a lot for the answers everyone, I really appreciate you getting back to me so quickly. I think that I understand where I am with this now :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Complete beginner, any help appreciated :) - For Loops

2011-12-01 Thread Ben Finney
Mark writes: > I'm a complete beginner to Python and, aside from HTML and CSS, to > coding in general. I've spent a few hours on it and think I understand > most of the syntax. Welcome! You should work your way through the Python tutorial, from beginning to end http://docs.python.org/tutorial/>

Re: order independent hash?

2011-12-01 Thread Neal Becker
Gelonida N wrote: > On 11/30/2011 01:32 PM, Neal Becker wrote: >> I like to hash a list of words (actually, the command line args of my >> program) in such a way that different words will create different hash, but >> not sensitive >> to the order of the words. Any ideas? >> > Do youmean hash li

Re: Disable readline

2011-12-01 Thread Nick Dokos
Steven D'Aprano wrote: > On Thu, 01 Dec 2011 00:00:52 -0500, Roy Smith wrote: > > > Another possibility is setting your TERM environment variable to > > something that readline can't support: > > > > ~$ TERM=asr33 > > ~$ python > > Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Ap

Re: order independent hash?

2011-12-01 Thread 88888 Dihedral
On Wednesday, November 30, 2011 8:47:13 PM UTC+8, Peter Otten wrote: > Neal Becker wrote: > > > I like to hash a list of words (actually, the command line args of my > > program) in such a way that different words will create different hash, > > but not sensitive to the order of the words. Any id

Re: order independent hash?

2011-12-01 Thread Dave Angel
On 12/01/2011 10:35 AM, 8 Dihedral wrote: On Wednesday, November 30, 2011 8:47:13 PM UTC+8, Peter Otten wrote: Neal Becker wrote: I like to hash a list of words (actually, the command line args of my program) in such a way that different words will create different hash, but not sensitive

Re: order independent hash?

2011-12-01 Thread 88888 Dihedral
On Thursday, December 1, 2011 11:52:46 PM UTC+8, Dave Angel wrote: > On 12/01/2011 10:35 AM, 8 Dihedral wrote: > > On Wednesday, November 30, 2011 8:47:13 PM UTC+8, Peter Otten wrote: > >> Neal Becker wrote: > >> > >>> I like to hash a list of words (actually, the command line args of my > >>>

Re: order independent hash?

2011-12-01 Thread Chris Angelico
On Fri, Dec 2, 2011 at 2:52 AM, Dave Angel wrote: > On 12/01/2011 10:35 AM, 8 Dihedral wrote: >> I knew a hash can replace a bi-directional linked list. >> The value  can be a multi-field string  to be parsed for further actions. >> Is this what you are asking? > > A hash is a number, so I don

platform issues?

2011-12-01 Thread Adrian Powell
I'm new to python and I'm trying to get a twitter client running on a new machine but it keeps on failing. I tracked the problem down to an issue opening URLs and wrote this little test case: import urllib2 url = 'http://www.google.com/' opener = urllib2.build_opener() url_data = opener.open(url

Re: platform issues?

2011-12-01 Thread Redcat
> Our servers have the same version of python and we're running the same > OS (Fedora 14). Can anyone think of what might be causing this problem, > or why it works on most (but not all) machines? > > Thanks Is the server able to resolve www.google.com properly? If so, are you POSITIVE that the

Re: Using the Python Interpreter as a Reference

2011-12-01 Thread DevPlayer
On Nov 29, 3:04 am, Steven D'Aprano wrote: > On Tue, 29 Nov 2011 12:49:49 +1100, Chris Angelico wrote: > > On Tue, Nov 29, 2011 at 11:54 AM, DevPlayer wrote: > >> To me, I would think the interpreter finding the coder's intended > >> indent wouldn't be that hard. And just make the need for consis

Re: platform issues?

2011-12-01 Thread Jean-Michel Pichavant
Adrian Powell wrote: I'm new to python and I'm trying to get a twitter client running on a new machine but it keeps on failing. I tracked the problem down to an issue opening URLs and wrote this little test case: import urllib2 url = 'http://www.google.com/' opener = urllib2.build_opener() url

Re: platform issues?

2011-12-01 Thread Adrian Powell
to run the tests, I sit at my dev machine and SSH to the server where I can copy & paste the test case directly into the python interpreter. If there's a typo, it's going to both of them equally. I am concerned about the name lookup since our servers have had some network glitches in the past a

Re: platform issues?

2011-12-01 Thread Redcat
On Thu, 01 Dec 2011 13:43:38 -0500, Adrian Powell wrote: > Since I'm actually trying to write a twitter client, I was more focused > on the results from twitter. Since google and twitter are so huge and so > distributed, I'd bet neither are good tests for this, but they look > approximately right.

ANN: Urwid 1.0.1, Urwid 0.9.9.3 - Console UI Library

2011-12-01 Thread Ian Ward
Announcing Urwid 1.0.1 and Urwid 0.9.9.3 Urwid home page: http://excess.org/urwid/ Manual: http://excess.org/urwid/wiki/UrwidManual Tarballs: http://excess.org/urwid/urwid-1.0.1.tar.gz http://excess.org/urwid/urwid-0.9.9.3.tar.gz About these rel

Re: Clever hack or code abomination?

2011-12-01 Thread Vito 'ZeD' De Tullio
Arnaud Delobelle wrote: > On 1 December 2011 03:15, Roy Smith wrote: >> I need to try a bunch of names in sequence until I find one that works >> (definition of "works" is unimportant). The algorithm is: >> >> 1) Given a base name, "foo", first see if just plain "foo" works. >> >> 2) If not, try

Re: platform issues?

2011-12-01 Thread Adrian Powell
The curl & dig ideas were great, thanks. Turns out the machine's network was badly configured and that's probably what was causing this problem. Curiously firefox could browse these sites without any problem despite not having any proxy defined and it took the command line to reveal the issue.

Re: Clever hack or code abomination?

2011-12-01 Thread Martin P. Hellwig
On 01/12/2011 03:15, Roy Smith wrote: Well, I have seen much worse, so the WTFs/minute(*) count won't be too bad. However, as general rule for readability; If you think you have to ask, don't bother asking, spend that time rethinking and write a more readable solution. *) http://www.osnews

Re: Clever hack or code abomination?

2011-12-01 Thread Steven D'Aprano
On Thu, 01 Dec 2011 21:13:51 +, Martin P. Hellwig wrote: > On 01/12/2011 03:15, Roy Smith wrote: > Well, I have seen much worse, so the WTFs/minute(*) count won't be too > bad. > > However, as general rule for readability; If you think you have to ask, > don't bother asking, spend that time

Re: Complete beginner, any help appreciated :) - For Loops

2011-12-01 Thread Kyle T. Jones
On 12/1/11 4:53 AM, Mark wrote: Hi there, I'm a complete beginner to Python and, aside from HTML and CSS, to coding in general. I've spent a few hours on it and think I understand most of the syntax. However, I'm wondering a bit about For Loops. I know that the basic syntax for them is to def

Re: Using the Python Interpreter as a Reference

2011-12-01 Thread Steven D'Aprano
On Thu, 01 Dec 2011 10:03:53 -0800, DevPlayer wrote: [...] > Well, that may be a little hyperbolic. But with 2 spaces you can > encourage coders to get very deep, indentially, and still fit 80 chars. Why would you want to encourage coders to write deeply indented code? In my opinion, if your cod

Re: Using the Python Interpreter as a Reference

2011-12-01 Thread Chris Angelico
On Fri, Dec 2, 2011 at 11:43 AM, Steven D'Aprano wrote: > Why would you want to encourage coders to write deeply indented code? > > In my opinion, if your code is indented four or more levels, you should > start to think about refactorising your code; if you reach six levels, > your code is probab

Re: Clever hack or code abomination?

2011-12-01 Thread Chris Angelico
On Fri, Dec 2, 2011 at 11:15 AM, Steven D'Aprano wrote: > Try this on for size. > > >                f = type(q)(c[c.index(chr(45))+1:])+type(q)(1) >                c = str.join('\n', list(map(chr, (45, 48))) + [c])[::2] >            c = (lambda a,b: a+b)(c[:c.index(chr(45))+1], type(c)(f)) I wou

Re: Reading twice from STDIN

2011-12-01 Thread Dan Stromberg
On 12/1/11, janedenone wrote: > Hi, > > I would like to read from a pipe, parse the input and ask the user > what to do next: > > message = sys.stdin.read() > # message is parsed and URLs are printed as a list to choose from... > selected_index = raw_input('Which URL to open?') > > Calling raw_inp

Re: Clever hack or code abomination?

2011-12-01 Thread Terry Reedy
On 11/30/2011 10:49 PM, Matt Joiner wrote: def possible_names(): yield "foo" for i in range(20): yield "foo-" + str(i) This is my favorite -- crystal clear with only the variable part variable. And it works in both 2.x and 3.x. -- Terry Jan Reedy -- http://mail.python.org

Passing along cmd.Cmd completion to contained class

2011-12-01 Thread Tim Chase
I have sub-classes of cmd.Cmd in an arrangement somewhat like class Config(cmd.Cmd): def do_foo(self, line): print "Fooing %r" % line def complete_foo(self, text, line, begidx, endidx): ... class MyTUI(cmd.Cmd): def __init__(self, configger=Config, *args, **kwargs): c

Re: order independent hash?

2011-12-01 Thread 88888 Dihedral
On Friday, December 2, 2011 12:18:29 AM UTC+8, Chris Angelico wrote: > On Fri, Dec 2, 2011 at 2:52 AM, Dave Angel wrote: > > On 12/01/2011 10:35 AM, 8 Dihedral wrote: > >> I knew a hash can replace a bi-directional linked list. > >> The value  can be a multi-field string  to be parsed for furt

Re: order independent hash?

2011-12-01 Thread Steven D'Aprano
On Fri, 02 Dec 2011 03:18:29 +1100, Chris Angelico wrote: > On Fri, Dec 2, 2011 at 2:52 AM, Dave Angel wrote: >> On 12/01/2011 10:35 AM, 8 Dihedral wrote: >>> I knew a hash can replace a bi-directional linked list. The value  can >>> be a multi-field string  to be parsed for further actions.

Re: order independent hash?

2011-12-01 Thread Chris Angelico
On Fri, Dec 2, 2011 at 3:29 PM, 8 Dihedral wrote: > I clear my point a hash is a collection of (key, value) pairs that have > well defined methods and behavior to be used in programming. > > The basic operations of a hash normally includes the following: > > 1. insertion of a (key, value) pair

Re: Clever hack or code abomination?

2011-12-01 Thread Matt Joiner
Thank you. ಠ_ಠ On Fri, Dec 2, 2011 at 1:49 PM, Terry Reedy wrote: > On 11/30/2011 10:49 PM, Matt Joiner wrote: >> >> def possible_names(): >>     yield "foo" >>     for i in range(20): >>         yield "foo-" + str(i) > > > This is my favorite -- crystal clear with only the variable part variable

Re: Clever hack or code abomination?

2011-12-01 Thread Steven D'Aprano
On Fri, 02 Dec 2011 13:07:57 +1100, Chris Angelico wrote: > On Fri, Dec 2, 2011 at 11:15 AM, Steven D'Aprano > wrote: >> Try this on for size. >> >> >>                f = type(q)(c[c.index(chr(45))+1:])+type(q)(1) c >>                = str.join('\n', list(map(chr, (45, 48))) + >>                [

Re: order independent hash?

2011-12-01 Thread 88888 Dihedral
On Friday, December 2, 2011 1:00:10 PM UTC+8, Chris Angelico wrote: > On Fri, Dec 2, 2011 at 3:29 PM, 8 Dihedral > wrote: > > I clear my point a hash is a collection of (key, value) pairs that have > > well defined methods and behavior to be used in programming. > > > > The basic operations of

Re: Clever hack or code abomination?

2011-12-01 Thread Chris Angelico
On Fri, Dec 2, 2011 at 4:34 PM, Steven D'Aprano wrote: > On Fri, 02 Dec 2011 13:07:57 +1100, Chris Angelico wrote: >> I would consider integer representations of ASCII to be code smell. It's >> not instantly obvious that 45 means '-', even if you happen to know the >> ASCII table by heart (which m

Re: Reading twice from STDIN

2011-12-01 Thread Hans Mulder
On 2/12/11 03:46:10, Dan Stromberg wrote: You can read piped data from sys.stdin normally. Then if you want something from the user, at least on most *ix's, you would open /dev/tty and get user input from there. 'Not sure about OS/X. Reading from /dev/tty works fine on OS/X. -- HansM -- ht