Re: how to avoid leading white spaces

2011-06-06 Thread ru...@yahoo.com
On 06/03/2011 08:05 PM, Steven D'Aprano wrote:
 On Fri, 03 Jun 2011 12:29:52 -0700, ru...@yahoo.com wrote:

 I often find myself changing, for example, a startwith() to a RE when
 I realize that the input can contain mixed case

 Why wouldn't you just normalise the case?

 Because some of the text may be case-sensitive.

 Perhaps you misunderstood me. You don't have to throw away the
 unnormalised text, merely use the normalized text in the expression you
 need.

 Of course, if you include both case-sensitive and insensitive tests in
 the same calculation, that's a good candidate for a regex... or at least
 it would be if regexes supported that :)

I did not choose a good example to illustrate what I find often
motivates my use of regexes.

You are right that for a simple .startwith() using a regex just
in case is not a good choice, and in fact I would not do that.

The process that I find often occurs is that I write (or am about
to write string method solution and when I think more about the
input data (which is seldom well-specified), I realize that using
a regex I can get better error checking, do more of the parsing
in one place, and adapt to changes in input format better than I
could with a .startswith and a couple other such methods.

Thus what starts as
  if line.startswith ('CUSTOMER '):
try: kw, first_initial, last_name, code, rest = line.split(None,
4)
...
often turns into (sometimes before it is written) something like
  m = re.match (r'CUSTOMER (\w+) (\w+) ([A-Z]\d{3})')
  if m: first_initial, last_name, code = m.group(...)

[...]
 or that I have
 to treat commas as well as spaces as delimiters.

 source.replace(,,  ).split( )

 Uhgg. create a whole new string just so you can split it on one rather
 than two characters?

 You say that like it's expensive.

No, I said it like it was ugly.  Doing things unrelated to the
task at hand is ugly.  And not very adaptable -- see my reply
to Chris Torek's post.  I understand it is a common idiom and
I use it myself, but in this case there is a cleaner alternative
with re.split that expresses exactly what one is doing.

 And how do you what the regex engine is doing under the hood? For all you
 know, it could be making hundreds of temporary copies and throwing them
 away. Or something. It's a black box.

That's a silly argument.
And how do you know what replace is doing under the hood?
I would expect any regex processor to compile the regex into
an FSM.  As usual, I would expect to pay a small performance
price for the generality, but that is reasonable tradeoff in
many cases.  If it were a potential problem, I would test it.
What I wouldn't do is throw away a useful tool because, golly,
I don't know, maybe it'll be slow -- that's just a form of
cargo cult programming.

 The fact that creating a whole new string to split on is faster than
 *running* the regex (never mind compiling it, loading the regex engine,
 and anything else that needs to be done) should tell you which does more
 work. Copying is cheap. Parsing is expensive.

In addition to being wrong (loading is done once, compilation is
typically done once or a few times, while the regex is used many
times inside a loop so the overhead cost is usually trivial compared
with the cost of starting Python or reading a file), this is another
micro-optimization argument.

I'm not sure why you've suddenly developed this obsession with
wringing every last nanosecond out of your code.  Usually it
is not necessary.  Have you thought of buying a faster computer?
Or using C?  *wink*

 Sorry, but I find

 re.split ('[ ,]', source)

 states much more clearly exactly what is being done with no obfuscation.

 That's because you know regex syntax. And I'd hardly call the version
 with replace obfuscated.

 Certainly the regex is shorter, and I suppose it's reasonable to expect
 any reader to know at least enough regex to read that, so I'll grant you
 that this is a small win for clarity. A micro-optimization for
 readability, at the expense of performance.


 Obviously this is a simple enough case that the difference is minor but
 when the pattern gets only a little more complex, the clarity difference
 becomes greater.

 Perhaps. But complicated tasks require complicated regexes, which are
 anything but clear.

Complicated tasks require complicated code as well.

As another post pointed out, there are ways to improve the
clarity of a regex such as the re.VERBOSE flag.
There is no doubt that a regex encapsulates information much more
densely than python string manipulation code.  One should not
be surprised that is might take as much time and effort to understand
a one-line regex as a dozen (or whatever) lines Python code that
do the same thing.  In most cases I'll bet, given equal fluency
in regexes and Python, the regex will take less.

 [...]
 After doing this a
 number of times, one starts to use an RE right from the get go unless
 one is VERY sure that there will be no requirements creep.

 

Re: announcing: dmangame: an ai game. maybe.

2011-06-06 Thread James Mills
On Mon, Jun 6, 2011 at 3:50 PM, okay zed okay@gmail.com wrote:
 the link: http://okayzed.github.com/dmangame/introduction.html

 dmangame is a game about writing AI for a simple strategy game.

 an example game: 
 http://okayzed.github.com/dmangame/circleblaster_vs_expand.html

This is really cool. I haven't looked at the source code yet...

There was another game very similar to this - much more basic though
and when I saw it back then I wanted to do something similar!

Nice job!

cheers
James

-- 
-- James Mills
--
-- Problems are solved by method
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Chris Torek
In article ef48ad50-da06-47a8-978a-47d6f4271...@d28g2000yqf.googlegroups.com
ru...@yahoo.com ru...@yahoo.com wrote (in part):
[mass snippage]
What I mean is that I see regexes as being an extremely small,
highly restricted, domain specific language targeted specifically
at describing text patterns.  Thus they do that job better than
than trying to describe patterns implicitly with Python code.

Indeed.

Kernighan has often used / supported the idea of little languages;
see:

http://www.princeton.edu/~hos/frs122/precis/kernighan.htm

In this case, regular expressions form a little language that is
quite well suited to some lexical analysis problems.  Since the
language is (modulo various concerns) targeted at the right level,
as it were, it becomes easy (modulo various concerns :-) ) to
express the desired algorithm precisely yet concisely.

On the whole, this is a good thing.

The trick lies in knowing when it *is* the right level, and how to
use the language of REs.

On 06/03/2011 08:05 PM, Steven D'Aprano wrote:
 If regexes were more readable, as proposed by Wall, that would go
 a long way to reducing my suspicion of them.

Suspicion seems like an odd term here.

Still, it is true that something (whether it be use of re.VERBOSE,
and whitespace-and-comments, or some New and Improved Syntax) could
help.  Dense and complex REs are quite powerful, but may also contain
and hide programming mistakes.  The ability to describe what is
intended -- which may differ from what is written -- is useful.

As an interesting aside, even without the re.VERBOSE flag, one can
build complex, yet reasonably-understandable, REs in Python, by
breaking them into individual parts and giving them appropriate
names.  (This is also possible in perl, although the perl syntax
makes it less obvious, I think.)
-- 
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)  http://web.torek.net/torek/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: announcing: dmangame: an ai game. maybe.

2011-06-06 Thread Corey Richardson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 06/06/2011 01:50 AM, okay zed wrote:
 the link: http://okayzed.github.com/dmangame/introduction.html
 
 dmangame is a game about writing AI for a simple strategy game.

Looks fun! I play a bit of Core War, so this should pose a similar but
new challenge to my brain. Thank you for your work and for sharing.

- -- 
Corey Richardson
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.17 (GNU/Linux)

iQEcBAEBAgAGBQJN7ILhAAoJEAFAbo/KNFvpFjYH/A+5l58MURNwSkNkRvejcS83
GDCVkq7I9ojqkGdEMi4get4oz0z+TQnZ5PTjHNMpgZvbI+AM6esQ2NPKIUGQd4l5
bk9ZeiA+YJbg3xs7w2mMjW4FEJdr2NNberWTPSn24TyTqFxHPxihK6ul6vv+Nbj6
6VEhGxSGtlHyYeQHDW2RX/EYij7GLX185YVmi9jZXG2OAAypvgLOIBOmtz2b2/xD
ht7bcqeie0Qx4B3fopGlSN7aPPKG1OCzIkjzSdm/LbHzpnRwVZTty8OPp/MdJpcY
MBwsqBgulUcOWZVyUuLes2/AqfAtLhq4VLF5BfM3r3x+ZKru1tiWQGnkY8uf0cs=
=Yglm
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Octavian Rasnita

It is not so hard to decide whether using RE is a good thing or not.

When the speed is important and every millisecond counts, RE should be used 
only when there is no other faster way, because usually RE is less faster 
than using other core Perl/Python functions that can do matching and 
replacing.


When the speed is not such a big issue, RE should be used only if it is 
easier to understand and maintain than using the core functions. And of 
course, RE should be used when the core functions cannot do what RE can do.


In Python, the RE syntax is not so short and simple as in Perl, so using RE 
even for very very simple things requires a longer code, so using other core 
functions may appear as a better solution, because the RE version of the 
code is almost never as easy to read as the code that uses other core 
functions (or... for very simple RE, they are probably same as readable).


In Perl, RE syntax is very short and simple, and in some cases it is more 
easier to understand and maintain a code that uses RE than other core 
functions.


For example, if somebody wants to check if the $var variable contains the 
letter x, a solution without RE in Perl is:


if ( index( $var, 'x' ) = 0 ) {
   print ok;
}

while the solution with RE is:

if ( $var =~ /x/ ) {
   print ok;
}

And it is obviously that the solution that uses RE is shorter and easier to 
read and maintain, beeing also much more flexible.


Of course, sometimes an even better alternative is to use a module from CPAN 
like Regexp::Common that can use RE in a more simple and readable way for 
matching numbers, profanity words, balanced params, programming languages 
comments, IP and MAC addresses, zip codes... or a module like Email::Valid 
for verifying if an email address is correct, because it may be very hard to 
create a RE for matching an email address.


So... just like with Python, there are more ways to do it, but depending on 
the situation, some of them are better than others. :-)


--Octavian

- Original Message - 
From: Chris Torek nos...@torek.net

Newsgroups: comp.lang.python
To: python-list@python.org
Sent: Monday, June 06, 2011 10:11 AM
Subject: Re: how to avoid leading white spaces


In article 
ef48ad50-da06-47a8-978a-47d6f4271...@d28g2000yqf.googlegroups.com

ru...@yahoo.com ru...@yahoo.com wrote (in part):
[mass snippage]

What I mean is that I see regexes as being an extremely small,
highly restricted, domain specific language targeted specifically
at describing text patterns.  Thus they do that job better than
than trying to describe patterns implicitly with Python code.


Indeed.

Kernighan has often used / supported the idea of little languages;
see:

   http://www.princeton.edu/~hos/frs122/precis/kernighan.htm

In this case, regular expressions form a little language that is
quite well suited to some lexical analysis problems.  Since the
language is (modulo various concerns) targeted at the right level,
as it were, it becomes easy (modulo various concerns :-) ) to
express the desired algorithm precisely yet concisely.

On the whole, this is a good thing.

The trick lies in knowing when it *is* the right level, and how to
use the language of REs.


On 06/03/2011 08:05 PM, Steven D'Aprano wrote:

If regexes were more readable, as proposed by Wall, that would go
a long way to reducing my suspicion of them.


Suspicion seems like an odd term here.

Still, it is true that something (whether it be use of re.VERBOSE,
and whitespace-and-comments, or some New and Improved Syntax) could
help.  Dense and complex REs are quite powerful, but may also contain
and hide programming mistakes.  The ability to describe what is
intended -- which may differ from what is written -- is useful.

As an interesting aside, even without the re.VERBOSE flag, one can
build complex, yet reasonably-understandable, REs in Python, by
breaking them into individual parts and giving them appropriate
names.  (This is also possible in perl, although the perl syntax
makes it less obvious, I think.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)  http://web.torek.net/torek/index.html








--
http://mail.python.org/mailman/listinfo/python-list



--
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Chris Angelico
On Mon, Jun 6, 2011 at 6:51 PM, Octavian Rasnita orasn...@gmail.com wrote:
 It is not so hard to decide whether using RE is a good thing or not.

 When the speed is important and every millisecond counts, RE should be used
 only when there is no other faster way, because usually RE is less faster
 than using other core Perl/Python functions that can do matching and
 replacing.

 When the speed is not such a big issue, RE should be used only if it is
 easier to understand and maintain than using the core functions. And of
 course, RE should be used when the core functions cannot do what RE can do.

for X in features:
  When speed is important and every millisecond counts, X should be
used only when there is no other faster way.
  When speed is not such a big issue, X should be used only if it is
easier to understand and maintain than other ways.

I think that's fairly obvious. :)

Chris Angelico
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generator Frustration

2011-06-06 Thread Thomas Rachel

Am 04.06.2011 20:27 schrieb TommyVee:

I'm using the SimPy package to run simulations. Anyone who's used this
package knows that the way it simulates process concurrency is through
the clever use of yield statements. Some of the code in my programs is
very complex and contains several repeating sequences of yield
statements. I want to combine these sequences into common functions.


Which are then generators.

 The problem of course, is that once a yield gets put into a function,
 the function is now a generator and its behavior changes.

Isn't your main function a generator as well?



Is there  any elegant way to do this? I suppose I can do things like

 ping-pong yield statements, but that solutions seems even uglier than
 having a very flat, single main routine with repeating sequences.

I'm not sure if I got it right, but I think you could emulate this 
yield from with a decorator:


def subgen1(): yield 1; yield 2;
def subgen2(): yield 1; yield 2;

Instead of doing now

def allgen():
for i in subgen1(): yield i
for i in subgen2(): yield i

you as well could do:

def yield_from(f):
def wrapper(*a, **k):
for sub in f(*a, **k):
for i in sub:
yield i
return wrapper

@yield_from
def allgen():
yield subgen1()
yield subgen2()

(Untested.)


Thomas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple windows services on the same machine

2011-06-06 Thread Mark Hammond

On 6/06/2011 2:54 AM, Massi wrote:

Hi everyone, I'm writing a script which implement a windows service
with the win32serviceutil module. The service works perfectly, but now
I would need to install several instances of the same service on my
machine for testing purpose.
This is hard since the service name is hard-coded in the service class
definition:

class MyService(win32serviceutil.ServiceFramework) :
 _svc_name_ = 'MyService'
 _svc_display_name_ = 'Instance ofMyService'


It is only hard-coded in the HandleCommandLine function - you probably 
just want your own argv parsing and call InstallService directly.


HTH,

Mark
--
http://mail.python.org/mailman/listinfo/python-list


RE: Lambda question

2011-06-06 Thread jyoung79
 f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc

 Packing tail recursion into one line is bad for both understanding and 
 refactoring. Use better names and a docstring gives
 
 def group(seq, n):
'Yield from seq successive disjoint slices of length n plus the 
 remainder'
for i in range(0,len(seq), n):
  yield seq[i:i+]
 
 -- 
 Terry Jan Reedy

Thank you all very much for this incredible help!  The original code 
now makes sense, and I was thrilled to see better and more efficient 
ways of doing this.  Thanks for taking the time to share your 
thoughts as well as the excellent detail everyone shared…  I really 
appreciate it!

Jay
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: float(nan) in set or as key

2011-06-06 Thread Grant Edwards
On 2011-06-03, Chris Torek nos...@torek.net wrote:

 The definition is entirely arbitrary.

I don't agree, but even if was entirely arbitrary, that doesn't make
the decision meaningless.  IEEE-754 says it's True, and standards
compliance is valuable.  Each country's decision to drive on the
right/left side of the road is entire arbitrary, but once decided
there's a huge benefit to everybody following the rule.

 This analogy perhaps works better than expected.  Whenever I swap
 between Oz or NZ and the US-of-A, I have a brief mental clash that,
 if I am not careful, could result in various bad things. :-)

I find that I do mostly OK driving on the wrong side of the road
[except for the constant windshield/turn-signal mixups], but I have a
horrible time as a pedestrian.

-- 
Grant Edwards   grant.b.edwardsYow! I had a lease on an
  at   OEDIPUS COMPLEX back in
  gmail.com'81 ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: float(nan) in set or as key

2011-06-06 Thread Grant Edwards
On 2011-06-03, Nobody nob...@nowhere.com wrote:

 This would produce the same end result as raising an exception
 immediately, but would reduce the number of isnan() tests.
 
 I've never found the number of isnan() checks in my code to be an
 issue -- there just arent that many of them, and when they are there,
 it provides an easy to read and easy to maintain way to handle things.

 I think that you misunderstood. What I was saying here was that, if you
 wanted exception-on-NaN behaviour from Python, the interpreter wouldn't
 need to call isnan() on every value received from the FPU, but rely upon
 NaN-propagation and only call it at places where a NaN might disappear
 (e.g. comparisons).

Ideed, I did misunderstand.  I thought you were talking about a
the value of reducing the number of isnan() tests in user application
code.

 I mean undefined, in the sense that 0/0 is undefined
 
 But 0.0/0.0 _is_ defined.  It's NaN.  ;)

 Mathematically, it's undefined.

True, but we must be careful not to confuse math and scientific
calculation using fixed-length binary floting point.

 IMHO, that's a bug.  IEEE-754 states explicit that 0.0/0.0 is NaN.
 Pythons claims it implements IEEE-754.  Python got it wrong.

 But then IEEE-754 considers integers and floats to be completely
 different beasts, while Python makes some effort to maintain a
 unified numeric interface. If you really want IEEE-754
 to-the-letter, that's undesirable, although I'd question the choice
 of Python in such situations.

Python's minor issues with IEEE-754 are far outweighed by advantages
in other areas. :)

 If anything, it has proven to be a major nuisance. It takes a lot of
 effort to create (or even specify) code which does the right thing in
 the presence of NaNs.
 
 That's not been my experience.  NaNs save a _huge_ amount of effort
 compared to having to pass value+status info around throughout
 complex caclulations.

 That's what exceptions are for. NaNs probably save a huge amount of
 effort in languages which lack exceptions, but that isn't applicable
 to Python.

How do you obtain using exceptions a behavior that's the same as with
quiet NaNs?

 The correct answer to nan == nan is to raise an exception,
 because you have asked a question for which the answer is nether True
 nor False.
 
 Wrong.

 That's overstating it. 

It was an attempt to illustate the overstatement to which it was a
reply.

-- 
Grant Edwards   grant.b.edwardsYow! You should all JUMP
  at   UP AND DOWN for TWO HOURS
  gmail.comwhile I decide on a NEW
   CAREER!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread rusi
For any significant language feature (take recursion for example)
there are these issues:

1. Ease of reading/skimming (other's) code
2. Ease of writing/designing one's own
3. Learning curve
4. Costs/payoffs (eg efficiency, succinctness) of use
5. Debug-ability

I'll start with 3.
When someone of Kernighan's calibre (thanks for the link BTW) says
that he found recursion difficult it could mean either that Kernighan
is a stupid guy -- unlikely considering his other achievements. Or
that C is not optimal (as compared to lisp say) for learning
recursion.

Evidently for syntactic, implementation and cultural reasons, Perl
programmers are likely to get (and then overuse) regexes faster than
python programmers.

1 is related but not the same as 3.  Someone with courses in automata,
compilers etc -- standard CS stuff -- is unlikely to find regexes a
problem.  Conversely an intelligent programmer without a CS background
may find them more forbidding.

On Jun 6, 12:11 pm, Chris Torek nos...@torek.net wrote:

 On 06/03/2011 08:05 PM, Steven D'Aprano wrote:
  If regexes were more readable, as proposed by Wall, that would go
  a long way to reducing my suspicion of them.

 Suspicion seems like an odd term here.

When I was in school my mother warned me that in college I would have
to undergo a most terrifying course called 'calculus'.

Steven's 'suspicions' make me recall my mother's warning :-)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Steven D'Aprano
On Sun, 05 Jun 2011 23:03:39 -0700, ru...@yahoo.com wrote:

 Thus what starts as
   if line.startswith ('CUSTOMER '):
 try: 
   kw, first_initial, last_name, code, rest = line.split(None, 4)
   ...
 often turns into (sometimes before it is written) something like
   m = re.match (r'CUSTOMER (\w+) (\w+) ([A-Z]\d{3})') 
   if m:
 first_initial, last_name, code = m.group(...)


I would argue that the first, non-regex solution is superior, as it 
clearly distinguishes the multiple steps of the solution:

* filter lines that start with CUSTOMER
* extract fields in that line
* validate fields (not shown in your code snippet)

while the regex tries to do all of these in a single command. This makes 
the regex an all or nothing solution: it matches *everything* or 
*nothing*. This means that your opportunity for giving meaningful error 
messages is much reduced. E.g. I'd like to give an error message like:

found digit in customer name (field 2)

but with your regex, if it fails to match, I have no idea why it failed, 
so can't give any more meaningful error than:

invalid customer line

and leave it to the caller to determine what makes it invalid. (Did I 
misspell CUSTOMER? Put a dot after the initial? Forget the code? Use 
two spaces between fields instead of one?)



[...]
 I would expect
 any regex processor to compile the regex into an FSM.

Flying Spaghetti Monster?

I have been Touched by His Noodly Appendage!!!


[...]
 The fact that creating a whole new string to split on is faster than
 *running* the regex (never mind compiling it, loading the regex engine,
 and anything else that needs to be done) should tell you which does
 more work. Copying is cheap. Parsing is expensive.
 
 In addition to being wrong (loading is done once, compilation is
 typically done once or a few times, while the regex is used many times
 inside a loop so the overhead cost is usually trivial compared with the
 cost of starting Python or reading a file), this is another
 micro-optimization argument.

Yes, but you have to pay the cost of loading the re engine, even if it is 
a one off cost, it's still a cost, and sometimes (not always!) it can be 
significant. It's quite hard to write fast, tiny Python scripts, because 
the initialization costs of the Python environment are so high. (Not as 
high as for, say, VB or Java, but much higher than, say, shell scripts.) 
In a tiny script, you may be better off avoiding regexes because it takes 
longer to load the engine than to run the rest of your script!

But yes, you are right that this is a micro-optimization argument. In a 
big application, it's less likely to be important.


 I'm not sure why you've suddenly developed this obsession with wringing
 every last nanosecond out of your code.  Usually it is not necessary. 
 Have you thought of buying a faster computer? Or using C?  *wink*

It's hardly an obsession. I'm just stating it as a relevant factor: for 
simple text parsing tasks, string methods are often *much* faster than 
regexes.


[...]
 Ah, but if your requirements are complicated enough that it takes you
 ten minutes and six lines of string method calls, that sounds to me
 like a situation that probably calls for a regex!
 
 Recall that the post that started this discussion presented a problem
 that took me six lines of code (actually spread out over a few more for
 readability) to do without regexes versus one line with.
 
 So you do agree that that a regex was a better solution in that case?

I don't know... I'm afraid I can't find your six lines of code, and so 
can't judge it in comparison to your regex solution:

for line in f:
fixed = re.sub (r(TABLE='\S+)\s+'$, r\1', line)

My solution would probably be something like this:

for line in lines:
if line.endswith('):
line = line[:-1].rstrip() + '
   

although perhaps I've misunderstood the requirements.


[...]
 (Note that Apocalypse is referring to a series of Perl design
 documents and has nothing to do with regexes in particular.)

 But Apocalypse 5 specifically has everything to do with regexes. That's
 why I linked to that, and not (say) Apocalypse 2.
 
 Where did I suggest that you should have linked to Apocalypse 2? I wrote
 what I wrote to point out that the Apocalypse title was not a
 pejorative comment on regexes.  I don't see how I could have been
 clearer.

Possibly by saying what you just said here?

I never suggested, or implied, or thought, that Apocalypse was a 
pejorative comment on *regexes*. The fact that I referenced Apocalypse 
FIVE suggests strongly that there are at least four others, presumably 
not about regexes.


[...]
 It is only relevant in so far as the readability and relative
 obfuscation of regex syntax is relevant. No further.
 
 OK, again you are confirming it is only the syntax of regexes that
 bothers you?

The syntax of regexes is a big part of it. I won't say the only part.


[...]
 If regexes were more readable, as proposed by Wall, that 

Re: announcing: dmangame: an ai game. maybe.

2011-06-06 Thread okay zed
could be the ACM queue challenge and google's ai challenge, they've
had games in the past with somewhat similar mechanics




On Jun 5, 11:10 pm, James Mills prolo...@shortcircuit.net.au wrote:
 On Mon, Jun 6, 2011 at 3:50 PM, okay zed okay@gmail.com wrote:
  the link:http://okayzed.github.com/dmangame/introduction.html

  dmangame is a game about writing AI for a simple strategy game.

  an example 
  game:http://okayzed.github.com/dmangame/circleblaster_vs_expand.html

 This is really cool. I haven't looked at the source code yet...

 There was another game very similar to this - much more basic though
 and when I saw it back then I wanted to do something similar!

 Nice job!

 cheers
 James

 --
 -- James Mills
 --
 -- Problems are solved by method

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 9:29 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 [...]
 I would expect
 any regex processor to compile the regex into an FSM.

 Flying Spaghetti Monster?

 I have been Touched by His Noodly Appendage!!!

Finite State Machine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Neil Cerutti
On 2011-06-06, ru...@yahoo.com ru...@yahoo.com wrote:
 On 06/03/2011 02:49 PM, Neil Cerutti wrote:
 Can you find an example or invent one? I simply don't remember
 such problems coming up, but I admit it's possible.

 Sure, the response to the OP of this thread.

Here's a recap, along with two candidate solutions, one based on
your recommendation, and one using str functions and slicing. 

(I fixed a specification problem in your original regex, as one
of the lines of data contained a space after the closing ',
making the $ inappropriate)

data.txt:
//ACCDJ EXEC DB2UNLDC,DFLID=DFLID,PARMLIB=PARMLIB,
// UNLDSYST=UNLDSYST,DATABAS=MBQV1D0A,TABLE='ACCDJ   '
//ACCT  EXEC DB2UNLDC,DFLID=DFLID,PARMLIB=PARMLIB,
// UNLDSYST=UNLDSYST,DATABAS=MBQV1D0A,TABLE='ACCT'
//ACCUM EXEC DB2UNLDC,DFLID=DFLID,PARMLIB=PARMLIB,
// UNLDSYST=UNLDSYST,DATABAS=MBQV1D0A,TABLE='ACCUM   '
//ACCUM1EXEC DB2UNLDC,DFLID=DFLID,PARMLIB=PARMLIB,
// UNLDSYST=UNLDSYST,DATABAS=MBQV1D0A,TABLE='ACCUM1  ' 
^Z

import re

print(re solution)
with open(data.txt) as f:
for line in f:
fixed = re.sub(r(TABLE='\S+)\s+', r\1', line)
print(fixed, end='')

print(non-re solution)
with open(data.txt) as f:
for line in f:
i = line.find(TABLE=')
if i != -1:
begin = line.index(', i) + 1
end = line.index(', begin)
field = line[begin: end].rstrip()
print(line[:i] + line[i:begin] + field + line[end:], end='')
else:
print(line, end='')

These two solutions print identical output processing the sample
data. Slight changes in the data would reveal divergence in the
assumptions each solution made.

I agree with you that this is a very tempting candidate for
re.sub, and if it probably would have been my first try as well.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


new string formatting with local variables

2011-06-06 Thread Jabba Laci
Hi,

I'd like to simplify the following string formatting:

solo = 'Han Solo'
jabba = 'Jabba the Hutt'
print {solo} was captured by {jabba}.format(solo=solo, jabba=jabba)
# Han Solo was captured by Jabba the Hutt

What I don't like here is this: solo=solo, jabba=jabba, i.e. the
same thing is repeated. In solo=solo, the left part is a key and the
right part is the value of a local variable, but it looks strange.

I'd like something like this:
print {solo} was captured by {jabba}.format(locals())# WRONG!

But it doesn't work.

Do you have any idea?

Thanks,

Laszlo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new string formatting with local variables

2011-06-06 Thread Chris Rebert
On Mon, Jun 6, 2011 at 9:15 AM, Jabba Laci jabba.l...@gmail.com wrote:
 Hi,

 I'd like to simplify the following string formatting:

 solo = 'Han Solo'
 jabba = 'Jabba the Hutt'
 print {solo} was captured by {jabba}.format(solo=solo, jabba=jabba)
 # Han Solo was captured by Jabba the Hutt

 What I don't like here is this: solo=solo, jabba=jabba, i.e. the
 same thing is repeated. In solo=solo, the left part is a key and the
 right part is the value of a local variable, but it looks strange.

 I'd like something like this:
 print {solo} was captured by {jabba}.format(locals())        # WRONG!

 But it doesn't work.

 Do you have any idea?

print {solo} was captured by {jabba}.format(**locals()) # RIGHT

You must use prefix-** in the call to unpack the mapping as keyword arguments.
Note that using locals() like this isn't best-practice.

Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 10:08 AM, Neil Cerutti ne...@norwich.edu wrote:
 import re

 print(re solution)
 with open(data.txt) as f:
    for line in f:
        fixed = re.sub(r(TABLE='\S+)\s+', r\1', line)
        print(fixed, end='')

 print(non-re solution)
 with open(data.txt) as f:
    for line in f:
        i = line.find(TABLE=')
        if i != -1:
            begin = line.index(', i) + 1
            end = line.index(', begin)
            field = line[begin: end].rstrip()
            print(line[:i] + line[i:begin] + field + line[end:], end='')
        else:
            print(line, end='')

print(non-re solution)
with open(data.txt) as f:
for line in f:
try:
start = line.index(TABLE=') + 7
end = line.index(', start)
except ValueError:
pass
else:
line = line[:start] + line[start:end].rstrip() + line[end:]
print(line, end='')
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How to import data from MySQL db into excel sheet

2011-06-06 Thread Prasad, Ramit
 Currently i am importing the Database into CSV file using csv module,
in csv file i need to change the column width according the size of
the data. i need to set different column width for different columns
pleas let me know how to achieve this

If you are using xlwt:
sheet.col(9).width = 3200

I am not sure exactly what unit the 3200 represents so I just adjust this 
manually to be a size that works for me.


Ramit



Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase  Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase 
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to European legal entities.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda question

2011-06-06 Thread Terry Reedy

On 6/6/2011 9:42 AM, jyoun...@kc.rr.com wrote:

f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc



Packing tail recursion into one line is bad for both understanding and
refactoring. Use better names and a docstring gives

def group(seq, n):
'Yield from seq successive disjoint slices of length n plus the
remainder'
for i in range(0,len(seq), n):
  yield seq[i:i+n]


[I added back the last 'n' that got deleted somehow]


Thank you all very much for this incredible help!  The original code
now makes sense, and I was thrilled to see better and more efficient
ways of doing this.  Thanks for taking the time to share your
thoughts as well as the excellent detail everyone shared…  I really
appreciate it!


You are welcome.

Let me add something not said much here about designing functions: start 
with both a clear and succinct definition *and* test cases. (I only 
started writing tests first a year ago or so.) Test cases help test the 
definition statement as well as the yet-to-be-written code. They also 
make re-factoring much safer. I think test cases should start with null 
inputs. For this function:


for inn,out in (
(('',1), []), # no input, no output
(('abc',0), []), # definition unclear, could be error
(('abc',1), ['a','b','c']),
(('abcd',2), ['ab','cd']),
(('abcde',2), ['ab', 'cd', 'e']), # could change this
):
assert list(group(*inn)) == out, (inn,out)

This fails with
ValueError: range() arg 3 must not be zero

I will let you think about and try out what the original code 'f=../ 
does with n=0. It is not good. A third problem with lambda expressions 
is no test for bad inputs. They were added to Python for situations 
where one needs a function as an argument and and the return expression 
is self-explanatory, clearly correct, and safe for any inputs it could 
get in the context it is passed into. For example, lambda x: 2*x.


This works:

def group(seq, n):
  'Yield from seq successive disjoint slices of length n  the remainder'
  if n=0: raise ValueError('group size must be positive')
  for i in range(0,len(seq), n):
yield seq[i:i+n]

for inn,out in (
(('',1), []), # no input, no output
#(('abc',0), ValueError), # group size positive
(('abc',1), ['a','b','c']),
(('abcd',2), ['ab','cd']),
(('abcde',2), ['ab', 'cd', 'e']), # could change this
):
assert list(group(*inn)) == out, (inn,out)

I have written a function test function that I will post or upload to 
PyPI sometime. It accepts i/o pairs with error 'outputs', like the one 
commented out above.


--
Terry Jan Reedy


--
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Neil Cerutti
On 2011-06-06, Ian Kelly ian.g.ke...@gmail.com wrote:
 On Mon, Jun 6, 2011 at 10:08 AM, Neil Cerutti ne...@norwich.edu wrote:
 import re

 print(re solution)
 with open(data.txt) as f:
 ? ?for line in f:
 ? ? ? ?fixed = re.sub(r(TABLE='\S+)\s+', r\1', line)
 ? ? ? ?print(fixed, end='')

 print(non-re solution)
 with open(data.txt) as f:
 ? ?for line in f:
 ? ? ? ?i = line.find(TABLE=')
 ? ? ? ?if i != -1:
 ? ? ? ? ? ?begin = line.index(', i) + 1
 ? ? ? ? ? ?end = line.index(', begin)
 ? ? ? ? ? ?field = line[begin: end].rstrip()
 ? ? ? ? ? ?print(line[:i] + line[i:begin] + field + line[end:], end='')
 ? ? ? ?else:
 ? ? ? ? ? ?print(line, end='')

 print(non-re solution)
 with open(data.txt) as f:
 for line in f:
 try:
 start = line.index(TABLE=') + 7

I wrestled with using addition like that, and decided against it.
The 7 is a magic number and repeats/hides information. I wanted
something like:

   prefix = TABLE='
   start = line.index(prefix) + len(prefix)

But decided I searching for the opening ' was a bit better.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda question

2011-06-06 Thread rusi
On Jun 5, 11:33 pm, Terry Reedy tjre...@udel.edu wrote:
 On 6/5/2011 5:31 AM, Alain Ketterlin wrote:

  jyoun...@kc.rr.com  writes:

  f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc

 f=lambda ... statements are inferior for practical purposes to the
 equivalent def f statements because the resulting object is missing a
 useful name attribute and a docstring. f=lambda is only useful for
 saving a couple of characters, and the above has many unneeded spaces



  f(Hallo Welt, 3)
  ['Hal', 'lo ', 'Wel', 't']

 http://stackoverflow.com/questions/312443/how-do-you-split-a-list-int...
  ized-chunks-in-python/312644

  It doesn't work with a huge list, but looks like it could be handy in 
  certain
  circumstances.  I'm trying to understand this code, but am totally lost.

  With such dense code, it is a good idea to rewrite the code using some
  more familiar (but equivalent) constructions. In that case:

  f =a function that can be called with parameters  x, n, acc=[]:
         if  xis not empty
           result-is  f(x[n:], n, acc+[(x[:n])])
         else
           result-is  acc

 Yes, the following is much easier to read:

 def f(x, n, acc=[]):
    if x:
      return f(x[n:], n, acc + [x[:n]])
    else:
      return acc

 And it can be easily translated to:

 def f(x,n):
    acc = []
    while x:
      acc.append(x[:n])  # grab first n chars
      x = x[n:]          # before clipping x
    return acc

 The repeated rebinding of x is the obvious problem. Returning a list
 instead of yielding chunks is unnecessary and a problem with large
 inputs. Solving the latter simplies the code to:

 def group(x,n):
    while x:
      yield x[:n]  # grab first n chars
      x = x[n:]    # before clipping x

 print(list(group('abcdefghik',3)))
 # ['abc', 'def', 'ghi', 'k']

 Now we can think about slicing chunks out of the sequence by moving the
 slice index instead of slicing and rebinding the sequence.

 def f(x,n):
      for i in range(0,len(x),n):
          yield x[i:i+n]

 This is *more* useful that the original f= above and has several *fewer*
 typed characters, even is not all on one line (and decent editor add the
 indents automatically):



 def f(x,n): for i in range(0,len(x),n): yield x[i:i+n]
 f = lambda x, n, acc=[]: f(x[n:], n, acc+[(x[:n])]) if x else acc

Well here is a quite-readable one-liner
def f(x,n): return (x[i:i+n] for i in range(0,len(x),n))

which if one is in character-lessening-spree mode can be written:

f=lambda x,n: (x[i:i+n] for i in range(0,len(x),n))

 Let me add something not said much here about designing functions: start
 with both a clear and succinct definition *and* test cases. (I only
 started writing tests first a year ago or so.)

I am still one year in the future :-;
Which framework do you recommend? Nose? test.py?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Ethan Furman

Ian Kelly wrote:

On Mon, Jun 6, 2011 at 10:08 AM, Neil Cerutti ne...@norwich.edu wrote:

import re

print(re solution)
with open(data.txt) as f:
   for line in f:
   fixed = re.sub(r(TABLE='\S+)\s+', r\1', line)
   print(fixed, end='')

print(non-re solution)
with open(data.txt) as f:
   for line in f:
   i = line.find(TABLE=')
   if i != -1:
   begin = line.index(', i) + 1
   end = line.index(', begin)
   field = line[begin: end].rstrip()
   print(line[:i] + line[i:begin] + field + line[end:], end='')
   else:
   print(line, end='')


print(non-re solution)
with open(data.txt) as f:
for line in f:
try:
start = line.index(TABLE=') + 7
end = line.index(', start)
except ValueError:
pass
else:
line = line[:start] + line[start:end].rstrip() + line[end:]
print(line, end='')


I like the readability of this version, but isn't generating an 
exception on every other line going to kill performance?


~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 11:17 AM, Neil Cerutti ne...@norwich.edu wrote:
 I wrestled with using addition like that, and decided against it.
 The 7 is a magic number and repeats/hides information. I wanted
 something like:

   prefix = TABLE='
   start = line.index(prefix) + len(prefix)

 But decided I searching for the opening ' was a bit better.

Fair enough, although if you ask me the + 1 is just as magical as the
+ 7 (it's still the length of the string that you're searching for).
Also, re-finding the opening ' still repeats information.

The main thing I wanted to fix was that the second .index() call had
the possibility of raising an unhandled ValueError.  There are really
two things we have to search for in the line, either of which could be
missing, and catching them both with the same except: clause feels
better to me than checking both of them for -1.

Cheers,
Ian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python + php encrypt/decrypt

2011-06-06 Thread geremy condra
On Sun, Jun 5, 2011 at 3:34 AM, Peter Irbizon peterirbi...@gmail.com wrote:
 Hello, thanks, Unfortunatelly I don't understand how xml should resolve my
 issue. My problem is:
 I am trying to use aes256 cbc on python and php to decrypt textstring. But
 results are not the same in php and python. Any idea why? password and iv is
 the same so I don't know where is the problem. I am trying do decrypt data
 in python then store it as base64 and read and decrypt it in php.

 2011/6/4 hid...@gmail.com

 Use xml to pass the encrypt text.

 On , Peter Irbizon peterirbi...@gmail.com wrote:
 
  Hello,
 
  I would like to encrypt text in python and decrypt it in my PHP script.
  I tried to use pycrypto and some aes php scripts but the results are not 
  the
  same. Please, is there any example (the best way source codes) how to do
  this in python and PHP?

Please provide links to the AES implementation you're trying to use
from PHP and the Python and PHP code you're using.

Geremy Condra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 11:48 AM, Ethan Furman et...@stoneleaf.us wrote:
 I like the readability of this version, but isn't generating an exception on
 every other line going to kill performance?

I timed it on the example data before I posted and found that it was
still 10 times as fast as the regex version.  I didn't time the
version without the exceptions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bloom Filter in 22 lines of Python (updated)

2011-06-06 Thread geremy condra
On Fri, Jun 3, 2011 at 1:17 PM, Raymond Hettinger pyt...@rcn.com wrote:
 Thanks for all the feedback on the earlier post.

 I've updated the recipe to use a cleaner API, simpler code,
 more easily subclassable, and with optional optimizations
 for better cache utilization and speed:

  http://code.activestate.com/recipes/577684-bloom-filter/

Any chance of this landing in collections?

Geremy Condra
-- 
http://mail.python.org/mailman/listinfo/python-list


Print Window on IDLE

2011-06-06 Thread Steve Oldner
Seems to work using 2.7 but not 3.2.  On 3.2 it just closes all my python 
sessions.  Is this a bug?  Can someone point me to a How To on using a local 
printer in windows?

Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Neil Cerutti
On 2011-06-06, Ian Kelly ian.g.ke...@gmail.com wrote:
 Fair enough, although if you ask me the + 1 is just as magical
 as the + 7 (it's still the length of the string that you're
 searching for). Also, re-finding the opening ' still repeats
 information.

Heh, true. I doesn't really repeat information, though, as in my
version there could be intervening garbage after the TABLE=,
which probably isn't desirable.

 The main thing I wanted to fix was that the second .index()
 call had the possibility of raising an unhandled ValueError.
 There are really two things we have to search for in the line,
 either of which could be missing, and catching them both with
 the same except: clause feels better to me than checking both
 of them for -1.

I thought an unhandled ValueError was a good idea in that case. I
knew that TABLE= may not exist, but I assumed if it did, that the
quotes are supposed to be there.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new string formatting with local variables

2011-06-06 Thread Steve Crook
On Mon, 6 Jun 2011 12:15:35 -0400, Jabba Laci wrote in
Message-Id: mailman.2490.1307376958.9059.python-l...@python.org:

 solo = 'Han Solo'
 jabba = 'Jabba the Hutt'
 print {solo} was captured by {jabba}.format(solo=solo, jabba=jabba)
 # Han Solo was captured by Jabba the Hutt

How about:-

print %s was captured by %s % (solo, jabba)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to import data from MySQL db into excel sheet

2011-06-06 Thread Benjamin Kaplan
On Mon, Jun 6, 2011 at 9:35 AM, Prasad, Ramit ramit.pra...@jpmchase.com wrote:
 Currently i am importing the Database into CSV file using csv module,
in csv file i need to change the column width according the size of
the data. i need to set different column width for different columns
pleas let me know how to achieve this

 If you are using xlwt:
 sheet.col(9).width = 3200

 I am not sure exactly what unit the 3200 represents so I just adjust this 
 manually to be a size that works for me.


 Ramit



xlwt is a package for editing Excel files. CSV, despite being a format
that Excel can open, is not an Excel file. A CSV is to spreadsheets
what plain text is to word processing. It's an extremely simple, easy
to use format programaticfally but it doesn't support any formattting
of any kind.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new string formatting with local variables

2011-06-06 Thread Ethan Furman

Steve Crook wrote:

On Mon, 6 Jun 2011 12:15:35 -0400, Jabba Laci wrote in
Message-Id: mailman.2490.1307376958.9059.python-l...@python.org:


solo = 'Han Solo'
jabba = 'Jabba the Hutt'
print {solo} was captured by {jabba}.format(solo=solo, jabba=jabba)
# Han Solo was captured by Jabba the Hutt


How about:-

print %s was captured by %s % (solo, jabba)


Or even

print {} was captured by {}.format(solo, jabba)

or how about

print {victim} was captured by {captor}.format(
victim=solo, captor=jabba)

or maybe

print {hapless_twit} was captured by {mega_bad_dude}.format(
hapless_twit=solo, mega_bad_dude=jabba)


~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Documenting Regex (and code)

2011-06-06 Thread Richard Parker
-
Dense and complex REs are quite powerful, but may also contain
and hide programming mistakes.  The ability to describe what is
intended -- which may differ from what is written -- is useful.
-
Once again, I feel compelled to stress the importance of well-written 
documentation embedded within the program's code. Many of you eschew this 
practice, stating that when the code is changed that often the documentation 
isn't. Shame on you! Documentation is at least, or more, important than the 
code, as it reflects the intentions of the creator. Failing to revise 
documentation along with it's accompanying code is an egregious sin and is one 
for which all programmers should repent.

After more than five decades of programming, documenting my code, writing books 
about programming and it's documentation, I shudder at the thought of even one 
of you thinking that removal of all the comments before modifying a program is 
appropriate, that the code itself properly expresses it's creator's intent.

I accept the flames that will ensue from this post and remain steadfast in my 
belief and extensive experience that commented (in the form of block comments) 
code is far more valuable than just the code itself.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new string formatting with local variables

2011-06-06 Thread Eric Snow
On Mon, Jun 6, 2011 at 10:15 AM, Jabba Laci jabba.l...@gmail.com wrote:
 Hi,

 I'd like to simplify the following string formatting:

 solo = 'Han Solo'
 jabba = 'Jabba the Hutt'
 print {solo} was captured by {jabba}.format(solo=solo, jabba=jabba)
 # Han Solo was captured by Jabba the Hutt

 What I don't like here is this: solo=solo, jabba=jabba, i.e. the
 same thing is repeated. In solo=solo, the left part is a key and the
 right part is the value of a local variable, but it looks strange.

 I'd like something like this:
 print {solo} was captured by {jabba}.format(locals())        # WRONG!

 But it doesn't work.

 Do you have any idea?


You were close:

print {solo} was captured by {jabba}.format(**locals())

This will turn locals() into keyword args for the format call.  The
tutorial has a good explanation on argument unpacking [1].

-eric

[1] 
http://docs.python.org/dev/tutorial/controlflow.html#unpacking-argument-lists


 Thanks,

 Laszlo
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: new string formatting with local variables

2011-06-06 Thread Prasad, Ramit
 print {} was captured by {}.format(solo, jabba)
Is this Python2.7 specific?

Python 2.6.x : 
print {} was captured by {}.format('t1', 't2')
ValueError: zero length field name in format


Ramit




This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase  Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase 
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to European legal entities.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new string formatting with local variables

2011-06-06 Thread Ethan Furman

Prasad, Ramit wrote:

print {} was captured by {}.format(solo, jabba)

Is this Python2.7 specific?

Python 2.6.x : 

print {} was captured by {}.format('t1', 't2')

ValueError: zero length field name in format


Apparently it is 2.7 and greater -- my apologies for not specifying that.

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


RE: How to import data from MySQL db into excel sheet

2011-06-06 Thread Prasad, Ramit
 Currently i am importing the Database into CSV file using csv module, 
in csv file i need to change the column width according the size of 
the data. i need to set different column width for different columns 
pleas let me know how to achieve this

xlwt is a package for editing Excel files. CSV, despite being a format
that Excel can open, is not an Excel file. A CSV is to spreadsheets
what plain text is to word processing. It's an extremely simple, easy
to use format programaticfally but it doesn't support any formattting
of any kind.

Topic says importing into excel, so I assume the OP is *currently* using CSV 
but wants to *switch* to Excel. If that is true then the following is the 
syntax for it. Assuming you open a workbook and create a worksheet within with 
a local name of sheet.

 sheet.col(9).width = 3200


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase  Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase 
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to European legal entities.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to avoid leading white spaces

2011-06-06 Thread Ian

On 03/06/2011 03:58, Chris Torek wrote:



-

This is a bit surprising, since both s1 in s2 and re.search()
could use a Boyer-Moore-based algorithm for a sufficiently-long
fixed string, and the time required should be proportional to that
needed to set up the skip table.  The re.compile() gets to re-use
the table every time.

Is that true?  My immediate thought is that Boyer-Moore would quickly give
the number of characters to skip, but skipping them would be slow because
UTF8 encoded characters are variable sized, and the string would have to be
walked anyway.

Or am I misunderstanding something.

Ian



--
http://mail.python.org/mailman/listinfo/python-list


Re: float(nan) in set or as key

2011-06-06 Thread Nobody
On Mon, 06 Jun 2011 00:55:18 +, Steven D'Aprano wrote:

 And thus we come back full circle. Hundreds of words, and I'm still no 
 closer to understanding why you think that NAN == NAN should be an 
 error.

Well, you could try improving your reading comprehension. Counselling
might help.

AFAICT, your main problem is that you can't distinguish between not
agreeing with a particular argument and being unable to even recognise
the existence of the argument.

A really big clue is here:

 why you think that NAN == NAN should be an error

Given that my very first comment in the thread was:

  Wrong.
 
 That's overstating it. There's a good argument to be made for ...

I never said that it /should/ be an error, and later explicitly stated
that I wasn't arguing for it but pointing out that it's /arguable/.

But you appear unable to comprehend such distinctions. Don't agree with
the argument, don't accept the argument, don't recognise that there is an
argument; these all appear to be the same thing.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python + php encrypt/decrypt

2011-06-06 Thread miamia
On Jun 6, 7:41 pm, geremy condra debat...@gmail.com wrote:
 On Sun, Jun 5, 2011 at 3:34 AM, Peter Irbizon peterirbi...@gmail.com wrote:
  Hello, thanks, Unfortunatelly I don't understand how xml should resolve my
  issue. My problem is:
  I am trying to use aes256 cbc on python and php to decrypt textstring. But
  results are not the same in php and python. Any idea why? password and iv is
  the same so I don't know where is the problem. I am trying do decrypt data
  in python then store it as base64 and read and decrypt it in php.

  2011/6/4 hid...@gmail.com

  Use xml to pass the encrypt text.

  On , Peter Irbizon peterirbi...@gmail.com wrote:

Hello,

php I am trying to use is here:
http://code.google.com/p/antares4pymes/source/browse/trunk/library/System/Crypt/AES.php?r=20

and python code:
# -*- coding: utf-8 -*-
from Crypto.Cipher import AES
import base64
import os

BLOCK_SIZE = 32
PADDING = '{'
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
DecodeAES = lambda c, e:
c.decrypt(base64.b64decode(e)).rstrip(PADDING)
secret = passkeypasskeyaa #os.urandom(BLOCK_SIZE)
iv='1234567890123456'
cipher = AES.new(secret, AES.MODE_CBC, iv)
# encode a string
tajnytext ='Alice has a cat'
encoded = EncodeAES(cipher, tajnytext)
print encoded

# decode the encoded string
decoded = DecodeAES(cipher, encoded)
print 'Decrypted string:', decoded


Thank you for your help in advance

   Hello,

   I would like to encrypt text in python and decrypt it in my PHP script.
   I tried to use pycrypto and some aes php scripts but the results are not 
   the
   same. Please, is there any example (the best way source codes) how to do
   this in python and PHP?

 Please provide links to the AES implementation you're trying to use
 from PHP and the Python and PHP code you're using.

 Geremy Condra- Hide quoted text -

 - Show quoted text -

-- 
http://mail.python.org/mailman/listinfo/python-list


ugly exe icon in win7/vista

2011-06-06 Thread Peter Irbizon
Hello, I am trying to make nice icons for my program. I compiled it with
py2exe but problem is that exe icon in Win 7/vista is not very nice (it
looks like win7 takes 32x32 instead of 248x248icon)

I used png2ico to pack icon file: png2ico icon.ico png248x248.png
png32x32.png png16x16.png

Any idea why win7 is showing 16x16(or 32x32) as exe icon?
-- 
http://mail.python.org/mailman/listinfo/python-list


ugly exe icon in win7/vista

2011-06-06 Thread miamia
Hello, I am trying to make nice icons for my program. I compiled it
with py2exe but problem is that exe icon in Win 7/vista is not very
nice (it looks like win7 takes 32x32 instead of 248x248icon)

I used png2ico to pack icon file: png2ico icon.ico png248x248.png
png32x32.png png16x16.png

Any idea why win7 is showing 16x16(or 32x32) as exe icon?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda question

2011-06-06 Thread Steven D'Aprano
On Mon, 06 Jun 2011 12:52:31 -0400, Terry Reedy wrote:

 Let me add something not said much here about designing functions: start
 with both a clear and succinct definition *and* test cases. (I only
 started writing tests first a year ago or so.)


For any non-trivial function, I usually start by writing the 
documentation (a docstring and doctests) first. How else do you know what 
the function is supposed to do if you don't have it documented?

By writing the documentation and examples before the code, I often 
discover that the API I first thought of was rubbish :)


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: float(nan) in set or as key

2011-06-06 Thread Steven D'Aprano
On Mon, 06 Jun 2011 23:14:15 +0100, Nobody wrote:

 On Mon, 06 Jun 2011 00:55:18 +, Steven D'Aprano wrote:
 
 And thus we come back full circle. Hundreds of words, and I'm still no
 closer to understanding why you think that NAN == NAN should be an
 error.
 
 Well, you could try improving your reading comprehension. Counselling
 might help.

Thank you for your concern about my mental health.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python + php encrypt/decrypt

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 4:19 PM, miamia peterirbi...@gmail.com wrote:
 php I am trying to use is here:
 http://code.google.com/p/antares4pymes/source/browse/trunk/library/System/Crypt/AES.php?r=20

That library does not appear to be doing CBC as far as I can tell.
Maybe they will agree if you use EBC instead?

 BLOCK_SIZE = 32

According to the docs, the block size for AES is 16, not 32.  It is
the key size that can be 16, 24, or 32.  But this should just result
in extra padding, so it probably doesn't explain the discrepancy.

 pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
 EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
 DecodeAES = lambda c, e:
 c.decrypt(base64.b64decode(e)).rstrip(PADDING)

Stylistic note: is it really necessary to use lambda here?  For
readability, just use def.  It's worth having to hit Enter a couple
extra times.

Cheers,
Ian
-- 
http://mail.python.org/mailman/listinfo/python-list


API design before implementation (was: Lambda question)

2011-06-06 Thread Ben Finney
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:

 On Mon, 06 Jun 2011 12:52:31 -0400, Terry Reedy wrote:

  Let me add something not said much here about designing functions: start
  with both a clear and succinct definition *and* test cases. (I only
  started writing tests first a year ago or so.)

 For any non-trivial function, I usually start by writing the
 documentation (a docstring and doctests) first. How else do you know
 what the function is supposed to do if you don't have it documented?

By trying to use it. At least, that's my approach: figure out what I
want the function to do by pretending it already exists, and write some
code that expects it to work.

Sometimes that code is a test case (in which case I'm doing test-first
development). Other times I'm not sure what I *want* the function to do
yet, so I'm also experimenting with what the interface should be (in
which case I'm doing something closer to a “spike implementation”).


All of that also stops me from writing the function until I can think of
a descriptive name for the function, and a docstring synopsis: the first
line of the docstring, a self-contained sentence saying what the
function is for. The synopsis should be exactly one short line; see PEP
257.

Once I know the function signature (parameters and return value), then I
write the docstring body.

 By writing the documentation and examples before the code, I often 
 discover that the API I first thought of was rubbish :)

Yep. That's also a big benefit of designing code by pretending it
exists, I find.

Fred Brooks tells us that we should plan from the beginning to throw one
away; because we will, anyhow. You and I seem to have ways to invest as
little as possible in the first design before throwing it away :-)

-- 
 \   “Are you pondering what I'm pondering?” “Umm, I think so, Don |
  `\  Cerebro, but, umm, why would Sophia Loren do a musical?” |
_o__)   —_Pinky and The Brain_ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda question

2011-06-06 Thread harrismh777

Steven D'Aprano wrote:

For any non-trivial function, I usually start by writing the
documentation (a docstring and doctests) first. How else do you know what
the function is supposed to do if you don't have it documented?


Yes. In my early years I was no different than any other hacker in terms 
of documenting last if at all... but having flown around the sun a few 
more times I've realized that good clear doc 'before' the code actually 
helps me write good clean code. If I implement what I've documented then 
I'm less likely to miss something in the doc, and more likely to have 
fewer bugs... this has played itself out many times for me.




kind regards,
m harris

--
http://mail.python.org/mailman/listinfo/python-list


Re: new string formatting with local variables

2011-06-06 Thread Ben Finney
Chris Rebert c...@rebertia.com writes:

 print {solo} was captured by {jabba}.format(**locals()) # RIGHT

I tend to use ‘ufoo {bar} baz.format(**vars())’, since ‘vars’ can also
take the namespace of an object. I only need to remember one “give me
the namespace” function for formatting.

 You must use prefix-** in the call to unpack the mapping as keyword
 arguments. Note that using locals() like this isn't best-practice.

Who says so, and do you find their argument convincing? Do you have a
reference for that so we can see why?

-- 
 \   “If you write the word ‘monkey’ a million times, do you start |
  `\  to think you're Shakespeare?” —Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new string formatting with local variables

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 6:11 PM, Ben Finney ben+pyt...@benfinney.id.au wrote:
 You must use prefix-** in the call to unpack the mapping as keyword
 arguments. Note that using locals() like this isn't best-practice.

 Who says so, and do you find their argument convincing? Do you have a
 reference for that so we can see why?

http://stackoverflow.com/questions/1550479/python-is-using-vars-locals-a-good-practice
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new string formatting with local variables

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 6:11 PM, Ben Finney ben+pyt...@benfinney.id.au wrote:
 Chris Rebert c...@rebertia.com writes:

 print {solo} was captured by {jabba}.format(**locals()) # RIGHT

 I tend to use ‘ufoo {bar} baz.format(**vars())’, since ‘vars’ can also
 take the namespace of an object. I only need to remember one “give me
 the namespace” function for formatting.

If you're using an object namespace, then you can just do this:

print({o.solo} was captured by {o.jabba}.format(o=self))

That looks a lot cleaner to me than passing in **vars(self).  For
locals(), I can see the appeal, but I tend to avoid it because it has
the same icky feeling as doing an import *.

Cheers,
Ian
-- 
http://mail.python.org/mailman/listinfo/python-list


Validating string for FDQN

2011-06-06 Thread Eric
Hello,

Is there a library or regex that can determine if a string is a fqdn
(fully qualified domain name)? I'm writing a script that needs to add
a defined domain to the end of a hostname if it isn't already a fqdn
and doesn't contain the defined domain.

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: float(nan) in set or as key

2011-06-06 Thread Chris Angelico
On Tue, Jun 7, 2011 at 9:44 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Thank you for your concern about my mental health.

Mental health? You're a programmer. It's far too late to worry about that.

My name is Chris, and I'm a programmer. It started when I was just a
child - my parents thought it would be alright for me to get into
these sorts of things. Kept me busy when they wanted to work. But it
grew from there. I was programming after school; I was programming
instead of going to bed. My social life deteriorated until I found I
was more interested in programming than in going to parties. When I
found myself writing programs during dinner, I knew I was an addict.
So I came to Prog-Anon, with their 12-step .. ARGH! I can't
escape!!

Chris Angelico
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda question

2011-06-06 Thread Terry Reedy

On 6/6/2011 1:29 PM, rusi wrote:

On Jun 5, 11:33 pm, Terry Reedytjre...@udel.edu  wrote:



Let me add something not said much here about designing functions: start
with both a clear and succinct definition *and* test cases. (I only
started writing tests first a year ago or so.)


I am still one year in the future :-;
Which framework do you recommend? Nose? test.py?


As I explained in a followup post, I am currently using a custom 
function test function that accepts i/o pairs with exception classes as 
'outputs'. It was inspired by test.py, but that is both overkill and an 
unwanted external dependency for my current project. I also wrote and 
use an iterator test function and a specialized iterator test function 
for iterators that return sequences. (For better error reporting, the 
latter tests items within each sequence rather than each sequence as a 
whole. This is especially helpful when the items are themselves 
collections, as in some combinatorial iterators.)


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: Validating string for FDQN

2011-06-06 Thread harrismh777

Eric wrote:

Is there a library or regex that can determine if a string is a fqdn
(fully qualified domain name)? I'm writing a script that needs to add
a defined domain to the end of a hostname if it isn't already a fqdn
and doesn't contain the defined domain.


You might try the os module and then use something like nslookup.


import os
os.system('nslookup name')


The output is sent on the subprocess standard out... so you can grab it 
with piping, or redirect, or redirect to a file and read later, etc.


You might also try the subprocess module. It provides better flexibility 
and control for handling the output of the nslookup, or whatever tool 
you decide to use to find the fully qualified name.


kind regards,
m harris

--
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda question

2011-06-06 Thread Terry Reedy

On 6/6/2011 12:52 PM, Terry Reedy wrote:


def group(seq, n):
'Yield from seq successive disjoint slices of length n  the remainder'
if n=0: raise ValueError('group size must be positive')
for i in range(0,len(seq), n):
yield seq[i:i+n]

for inn,out in (
(('',1), []), # no input, no output
#(('abc',0), ValueError), # group size positive
(('abc',1), ['a','b','c']),
(('abcd',2), ['ab','cd']),
(('abcde',2), ['ab', 'cd', 'e']), # could change this
):
assert list(group(*inn)) == out, (inn,out)


I forgot to mention that any function that takes a 'sequence' as input 
should be tested with both strings and non-strings. I learned this when 
a function tested with one failed mysteriously with the other. Strings 
are unique in that indexing returns a slice (and hence a string) rather 
than a separate class of item. It this case, there is no indexing and no 
use of class to create new items. However, adding a couple of lines like

(((),1), []),
(((1,2,3,4),2), [(1,2), (3,4)]),
to the test sequence checks the current code and guards against future 
changes.


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


[JOB] - Python Architect - Singapore

2011-06-06 Thread Rob
Our client, part of one of the largest Telcos in the world is
currently on the hunt for what they describe as a Python Senior
Developer/Team Lead/Systems Archtiect, for their Singapore office.

This particular part of the organisation has offices around the world
servicing world wide brand-name clients.

The key aspects to this role are


1. Role based in Singapore, therefore the candidate must have already
decided Singapore is for themas there is no relocation package. I
have recently put a more junior person across for another role with
the company and this candidate's wife is from Singapore and as they
have decided to already move back home, it suits them to go for this
role.


2. Salaries - This slightly junior candidate (who has done this
transition before) is currently on $90kAUD in Australia and is
looking to move to Singapore for $90k SGD ($68k AUD). You will not be
able to achive the same dollar for dollar (AUD) transitionBUT, the
taxes in Singapore are anywhere from 5-10% which means that
effectively you could potentially have more take-home pay than you
would in Australia. Therefore if you use similar transition as above,
that is what you could achieve. I am not an expert on the cost of
living in Singapore, therefore if this is a new transition for you,
you would need to do your own investigationsbut from what I have
heard the above calculation provides a similar lifestyle. THIS ROLE IS
OFFERING BETWEEN $110K - $120k SGD per annum

3. Process - My client is happy for telephone and Skype interviews AND
they can get you to work in the Australian office first to aclimatise
to the systems etc and to meet key people of the company.


This is a permanent opportunity, perfect for someone who is eager to
go to Singapore for a career change.


As a most senior member of the team, you will be required to be
competent in all things Python related, full SDLC experience across a
range of RDBMS. You will have the ability to lead a team, to mentor,
to present and ultimately to deliver on key internal and external
projects

If this role sounds perfect for you, please don't hesitate to submit
your CV to be considered immediately

Python, Python, Python, Python, Python

+61 2 9439 4643

Rob Stevens  rob.stev...@higherrecruitment.com.au

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Validating string for FDQN

2011-06-06 Thread Chris Angelico
On Tue, Jun 7, 2011 at 10:40 AM, Eric eric.won...@gmail.com wrote:
 Hello,

 Is there a library or regex that can determine if a string is a fqdn
 (fully qualified domain name)? I'm writing a script that needs to add
 a defined domain to the end of a hostname if it isn't already a fqdn
 and doesn't contain the defined domain.

One reliable way to test would be to do a whois check on the name. If
it comes up with something, it's fully qualified.

http://code.google.com/p/pywhois/

Alternatively, if all you want is a simple syntactic check, and if you
can assume that the name is already a valid domain name (no weird
characters, etc), then you can simply divide it on the last dot and
see if the last part is a recognized TLD. A partial list of TLDs can
be found here:

http://data.iana.org/TLD/tlds-alpha-by-domain.txt

There are other TLDs too, including .localhost and .test, which you
can probably ignore.

Chris Angelico
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: except KeyError, everywhere

2011-06-06 Thread Gabriel Genellina

En Fri, 03 Jun 2011 21:02:56 -0300, Nobody nob...@nowhere.com escribió:


On Fri, 03 Jun 2011 22:08:16 +0200, Wilbert Berendsen wrote:

I find myself all over the place associating objects with each other  
using

dicts as caches:


The general concept is called memoization. There isn't an  
implementation

in the standard library


Yes, there is, in Python 3.2:
http://docs.python.org/py3k/library/functools.html#functools.lru_cache


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: [JOB] - Python Architect - Singapore

2011-06-06 Thread Ben Finney
Rob robertvstev...@yahoo.com.au writes:

 Our client, part of one of the largest Telcos in the world is
 currently on the hunt for what they describe as a Python Senior
 Developer/Team Lead/Systems Archtiect, for their Singapore office.

Please don't use this forum for job seeking or advertisements.

The Python Job Board URL:http://www.python.org/community/jobs/ is
specifically for that purpose; please submit advertisements there.

-- 
 \ “If history and science have taught us anything, it is that |
  `\ passion and desire are not the same as truth.” —E. O. Wilson, |
_o__)  _Consilience_, 1998 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new string formatting with local variables

2011-06-06 Thread Steven D'Aprano
On Tue, 07 Jun 2011 10:11:01 +1000, Ben Finney wrote:

 Chris Rebert c...@rebertia.com writes:
 
 print {solo} was captured by {jabba}.format(**locals()) # RIGHT
 
 I tend to use ‘ufoo {bar} baz.format(**vars())’, since ‘vars’ can also
 take the namespace of an object. I only need to remember one “give me
 the namespace” function for formatting.
 
 You must use prefix-** in the call to unpack the mapping as keyword
 arguments. Note that using locals() like this isn't best-practice.
 
 Who says so, and do you find their argument convincing? Do you have a
 reference for that so we can see why?

It's a code smell. Why is this code messing with locals() instead of 
using names explicitly? Is it possible that this code will attempt to 
modify locals()? I need to look twice to be sure its safe. Why do you 
need to pass *all* of the locals if only two names are used?

Seeing an arbitrary large number of arguments passed to a piece of code 
that only requires two makes me feel hinky. It's not that it's 
*necessarily* bad, in and of itself, but it should make you take a 
second, closer look at it.

Where possible, I'd rather be explicit about which names I want:

solo = Han Solo
jabba = Jabba the Hutt

{hero} was captured by {villain}..format(hero=solo, villain=jabba)


It also strikes me as potentially wasteful to unpack an arbitrarily large 
dict into keyword arguments, and then (presumably) have the format method 
pack them back into a dict again. Again, this might be trivial... but it 
might not be. No way of knowing just by reading that line of code, hence 
a code smell.


Oh, and there's even a failure mode for this **locals() or **vars() 
pattern, at least for CPython. If you do this in production code, I hate 
you, but it can happen:


 globals()[42] = spam spam spam  # Ouch!
 vars()
{'__builtins__': module '__builtin__' (built-in), '__name__': 
'__main__', 42: 'spam spam spam', '__doc__': None, '__package__': None}
 def f(**kwargs):
... print kwargs
...

 f(**vars())
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: f() keywords must be strings




-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: GIL in alternative implementations

2011-06-06 Thread Gabriel Genellina
En Sat, 28 May 2011 14:05:16 -0300, Steven D'Aprano  
steve+comp.lang.pyt...@pearwood.info escribió:



On Sat, 28 May 2011 09:39:08 -0700, John Nagle wrote:


Python allows patching code while the code is executing.


Can you give an example of what you mean by this?

If I have a function:


def f(a, b):
c = a + b
d = c*3
return hello world*d


how would I patch this function while it is executing?


I think John Nagle was thinking about rebinding names:


def f(self, a, b):
  while b0:
b = g(b)
c = a + b
d = self.h(c*3)
  return hello world*d

both g and self.h may change its meaning from one iteration to the next,  
so a complete name lookup is required at each iteration. This is very  
useful sometimes, but affects performance a lot.


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Validating string for FDQN

2011-06-06 Thread Philip Semanchuk

On Jun 6, 2011, at 8:40 PM, Eric wrote:

 Hello,
 
 Is there a library or regex that can determine if a string is a fqdn
 (fully qualified domain name)? I'm writing a script that needs to add
 a defined domain to the end of a hostname if it isn't already a fqdn
 and doesn't contain the defined domain.

The ones here served me very well:
http://pyxml.cvs.sourceforge.net/viewvc/pyxml/xml/xml/Uri.py?revision=1.1view=markup

bye
Philip
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: except KeyError, everywhere

2011-06-06 Thread Ben Finney
Gabriel Genellina gagsl-...@yahoo.com.ar writes:

 En Fri, 03 Jun 2011 21:02:56 -0300, Nobody nob...@nowhere.com escribió:

  On Fri, 03 Jun 2011 22:08:16 +0200, Wilbert Berendsen wrote:
 
  I find myself all over the place associating objects with each
  other using dicts as caches:
 
  The general concept is called memoization. There isn't an
  implementation in the standard library

 Yes, there is, in Python 3.2:
 http://docs.python.org/py3k/library/functools.html#functools.lru_cache

Beauty. Thanks!

-- 
 \ “If we don't believe in freedom of expression for people we |
  `\   despise, we don't believe in it at all.” —Noam Chomsky, |
_o__)   1992-11-25 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Seattle PyCamp 2011

2011-06-06 Thread Chris Calloway
University of Washington Marketing and the Seattle Plone Gathering host 
the inaugural Seattle PyCamp 2011 at The Paul G. Allen Center for 
Computer Science  Engineering on Monday, August 29 through Friday, 
September 2, 2011.


Register today at http://trizpug.org/boot-camp/seapy11/

For beginners, this ultra-low-cost Python Boot Camp makes you productive 
so you can get your work done quickly. PyCamp emphasizes the features 
which make Python a simpler and more efficient language. Following along 
with example Python PushUps™ speeds your learning process. Become a 
self-sufficient Python developer in just five days at PyCamp! PyCamp is 
conducted on the campus of the University of Washington in a state of 
the art high technology classroom.


--
Sincerely,

Chris Calloway http://nccoos.org/Members/cbc
office: 3313 Venable Hall   phone: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599
--
http://mail.python.org/mailman/listinfo/python-list


Re: Validating string for FDQN

2011-06-06 Thread Nobody
On Mon, 06 Jun 2011 17:40:29 -0700, Eric wrote:

 Is there a library or regex that can determine if a string is a fqdn
 (fully qualified domain name)? I'm writing a script that needs to add
 a defined domain to the end of a hostname if it isn't already a fqdn
 and doesn't contain the defined domain.

Try socket.getfqdn() or socket.gethostbyname_ex().

With one exception[1], you can't reliably do it just by examining the
string; you have to ask the resolver.

[1] If a hostname ends with a dot, it's fully qualified.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Validating string for FDQN

2011-06-06 Thread Chris Angelico
On Tue, Jun 7, 2011 at 3:23 PM, Nobody nob...@nowhere.com wrote:
 [1] If a hostname ends with a dot, it's fully qualified.


Outside of BIND files, when do you ever see a name that actually ends
with a dot?

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue12268] file readline, readlines readall methods can lose data on EINTR

2011-06-06 Thread Gregory P. Smith

Gregory P. Smith g...@krypto.org added the comment:

I haven't looked beyond the reading methods it is possible that some of the 
write implementations have a similar issue.  Patch gps02 for 3.2 attached.

I'll use that as the basis for a stand alone test_file_eintr.py targeted at 2.7.

--
Added file: http://bugs.python.org/file22262/test_and_fix_readers_3.2-gps02.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12268
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12268] file readline, readlines readall methods can lose data on EINTR

2011-06-06 Thread Gregory P. Smith

Changes by Gregory P. Smith g...@krypto.org:


Removed file: 
http://bugs.python.org/file22261/test_fileio_readers_3.2-gps01.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12268
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12226] use secured channel for uploading packages to pypi

2011-06-06 Thread anatoly techtonik

anatoly techtonik techto...@gmail.com added the comment:

On Sat, Jun 4, 2011 at 5:33 PM, Éric Araujo rep...@bugs.python.org wrote:
 I think there should be a warning that the connection is
 unauthenticated (i.e. not secure). Users tend to be upset if they see
 'https' and later find out that no certificates were verified.

 Thanks Stephan, that was on my mind but I forgot it.  I’m -1 on using https 
 if no validation is performed.

It will be more professional if you could also explain why. Thanks.

 I believe that's a very personal judgement.
 Not really; it’s an explanation of our release rules, exposed by one of the 
 older developers.

Release rules should be clear enough not to require explanation.

 For me exposing core Python development accounts is a fundamental
 flaw.

 What is a core Python development account?

'core' is not the best word here, so it needs an explanation. Any
account on PyPI that uploads packages used for in enterprise
deployment schemes imposes a danger. Potential target are identified
using 'popularity package/developer activity' rating to reduce the
risk. These are the primary targets for an attack, which I called
'core'. 'primary' would be a better name probably.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12226
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12170] Bytes.index() and bytes.count() should accept byte ints

2011-06-06 Thread Xuanji Li

Changes by Xuanji Li xua...@gmail.com:


--
nosy: +xuanji

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12170
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10376] ZipFile unzip is unbuffered

2011-06-06 Thread Xuanji Li

Changes by Xuanji Li xua...@gmail.com:


--
nosy: +xuanji

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10376
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3566] httplib persistent connections violate MUST in RFC2616 sec 8.1.4.

2011-06-06 Thread Aron Griffis

Changes by Aron Griffis agrif...@n01se.net:


--
nosy: +agriffis

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue3566
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12270] Please update copyright notice on bugs.python.org to 2011?

2011-06-06 Thread AJ

New submission from AJ brandmys...@gmail.com:

We are almost in mid-year. :)

http://bugs.python.org/ has a copyright notice 1990-2010. Please update it to 
include 2011.

--
components: None
messages: 137736
nosy: brandmyself
priority: normal
severity: normal
status: open
title: Please update copyright notice on bugs.python.org to 2011?

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12270
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12271] Python 2.7.x on IA64 running SLES 11 SP1

2011-06-06 Thread Vincent

New submission from Vincent v.clau...@free.fr:

Hello everybody,

With the same build/compile command, I'm able to have my runing python 
version (2.6.x or 2.7.x) on IA64 server runing SLES 10 SP2/SP3,not on IA64 
server runing SLES 11 SP1. I've try with 2.7, 2.7.1 and 2.7.2rc1 version 
without success.

On both configuration types, I've installed all the available libraries, but on 
SLES 11 SP1, the make resulting message is the following (the complete building 
messages are in the joined gzip text file):

--
...
Python build finished, but the necessary bits to build these modules were not 
found:
_bsddb _sqlite3   _ssl
_tkinter   bsddb185   bz2 
dl imageopreadline
sunaudiodevzlib   
To find the necessary bits, look in setup.py in detect_modules() for the 
module's name.


Failed to build these modules:
_curses_panel 

running build_scripts
--

Any advice will be welcome.

Thanks a lot for your attention and your process.

All the best,

Vincent

--
components: Build
files: Building_error_SLES11SP1_ia64.txt.gz
messages: 137737
nosy: v.clau...@free.fr
priority: normal
severity: normal
status: open
title: Python 2.7.x on IA64 running SLES 11 SP1
type: compile error
versions: Python 2.7
Added file: 
http://bugs.python.org/file22263/Building_error_SLES11SP1_ia64.txt.gz

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12271
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12270] Please update copyright notice on bugs.python.org to 2011?

2011-06-06 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
assignee:  - ezio.melotti
nosy: +ezio.melotti

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12270
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12270] Please update copyright notice on bugs.python.org to 2011?

2011-06-06 Thread Ezio Melotti

Ezio Melotti ezio.melo...@gmail.com added the comment:

Done in r88853, thanks for the report!

--
resolution:  - fixed
stage:  - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12270
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12021] mmap.read requires an argument

2011-06-06 Thread Charles-François Natali

Charles-François Natali neolo...@free.fr added the comment:

 That's because of the _PyIO_ConvertSsize_t converter, which silently
 converts None to -1.
 There's probably a good reason for doing this in the _io module

 I'm not sure about the original reason, but I find None as the default 
 omitted value prettier than -1 myself, so I think it's a good thing :)


If being pretty is the only reason for this choice, then I think that
documenting the method as

method:: read([n])

is simpler and cleaner .

But you've got much more experience than me, so I won't argue any further :-)

 Can I use _PyIO_ConvertSsize_t? Or should I duplicate its
 functionality in mmapmodule.c?

I let Antoine answer that.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12021
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12021] mmap.read requires an argument

2011-06-06 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 If being pretty is the only reason for this choice, then I think that
 documenting the method as
 
 method:: read([n])
 
 is simpler and cleaner .
 
 But you've got much more experience than me, so I won't argue any further :-)

There are contexts where it is easier to give the default argument than
call the method without argument, though, and that's where I find None
more intuitive than -1 :) Arguably it's not very important, though.

  Can I use _PyIO_ConvertSsize_t? Or should I duplicate its
  functionality in mmapmodule.c?
 
 I let Antoine answer that.

I'm not sure. This would require including iomodule.h, which is supposed
to be private to the _io module. I think duplicating it is fine, since
the code is probably simple anyway (I'm too lazy to take a look right
now :-)).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12021
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12238] Readline module loading in interactive mode

2011-06-06 Thread Niels Heinen

Niels Heinen ni...@heinen.ws added the comment:

Hi Eric, David,

This means that you cannot type python and press enter in any shared 
directory without the risk of a malicious readlinemodule.so being imported and 
executed.  

I think this is different from a scenario where someone explicitly runs a 
script or imports a module in interactive mode where it is also reasonable that 
such a person understands the importing mechanism.

Thanks for the quick responses btw!

Niels

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12238
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12218] Removing wsgiref.egg-info

2011-06-06 Thread Roundup Robot

Roundup Robot devnull@devnull added the comment:

New changeset cc28bc86d474 by Éric Araujo in branch 'default':
Remove wsgiref.egg-info from msi.py (follow-up to d615eb7bce33, #12218)
http://hg.python.org/cpython/rev/cc28bc86d474

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12218
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12019] Dead or buggy code in importlib.test.__main__

2011-06-06 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Is this minor cleanup, non-bugfix okay for 3.2?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12019
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10884] pkgutil EggInfoDistribution requirements for .egg-info metadata

2011-06-06 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Can you check if this is covered in test_database?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10884
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12226] use secured channel for uploading packages to pypi

2011-06-06 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

 Thanks Stephan, that was on my mind but I forgot it.  I’m -1 on
 using https if no validation is performed.
 It will be more professional if you could also explain why.

If you make an HTTPS connection without checking the certificate, what security 
does it add?

  Not really; it’s an explanation of our release rules, exposed by
 one of the older developers.
 Release rules should be clear enough not to require explanation.

Explanations make them clear.

 Any account on PyPI that uploads packages used for in enterprise
 deployment schemes imposes a danger.

Sidenote: I don’t want to give less security to non-enterprise users.

Anyway, I understand your point now: insecure upload and download are 
vulnerable to MITM attacks, and encouraging HTTPS use (through default value + 
docs) would help against that.  I am supportive of a patch, but it doesn’t mean 
the release process should not be followed.  See also #11357 and #8561 about 
download security.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12226
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12246] Warn when trying to install third-party module from an uninstalled checkout

2011-06-06 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Thanks.  What about using sysconfig.is_python_build in your patch?

--
assignee: tarek - eric.araujo
title: create installation path if it's non-existent - Warn when trying to 
install third-party module from an uninstalled checkout

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12246
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12226] use secured channel for uploading packages to pypi

2011-06-06 Thread Fred L. Drake, Jr.

Fred L. Drake, Jr. fdr...@acm.org added the comment:

On Mon, Jun 6, 2011 at 11:50 AM, Éric Araujo rep...@bugs.python.org wrote:
 If you make an HTTPS connection without checking the certificate, what 
 security does it add?

I'm in favor of cert checking, myself.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12226
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7511] msvc9compiler.py: ValueError: [u'path']

2011-06-06 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Thorsten Behrens said:
 You are right, this is not a bug in Python. The diff provides a
 workaround for a limitation in VC++ 2008 Express. This diff is a
 piece of user service.

ipatrol added:
 Purity shmurity. The point of distutils is largely to present a
 unified and simple interface. 'python setup.py install' should be all
 a user has to do on any platform. Unless you can come up with a
 better idea, MSVC is really the only big compiler on Windows.

The feature freeze is distutils is not a conspiracy plotted by developers 
loving purity; it is a necessity caused by hard pragmatism.  Tarek would have 
loved to continue improving distutils instead of forking distutils2, but he 
could not because third-party code relying on bugs and workarounds was broken.  
We have to be cautious, and it has nothing to do with purity.  Believe me, the 
freeze, fork and merge was not something fun for distutils developers, but we 
had to do it precisely for our users.

While I agree that in an ideal world, “'python setup.py install' should be all 
a user has to do on any platform”, it cannot be done in distutils.  Like Martin 
said:
 if you want to use SDK tools, you are supposed to set
 DISTUTILS_USE_SDK, after opening the respective build environment

For distutils2/packaging however, we can work on improving the compiler system, 
so that “pysetup run install” is all a user had to do on any platform.  See 
#12257 for that.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7511
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9302] distutils API Reference: setup() and Extension parameters' description not correct.

2011-06-06 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
status: open - pending

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9302
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12222] All pysetup commands should respect exit codes

2011-06-06 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
dependencies: +pysetup --search should return non-zero when a dist is not 
installed and print a message stating the fact.

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12242] distutils2 environment marker for current compiler

2011-06-06 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

What would the value be for non-C Python implementations?

If the need for compiler-specific options is very common, we could consider 
either improving the compiler system or implement this request; if it’s not 
common, letting people use hooks would be enough.

--
versions: +Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12242
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8668] Packaging: add a 'develop' command

2011-06-06 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
assignee: tarek - eric.araujo
keywords: +gsoc
title: add a 'develop' command - Packaging: add a 'develop' command
versions: +Python 3.3 -3rd party

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8668
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7511] msvc9compiler.py: ValueError: [u'path']

2011-06-06 Thread Stefan Krah

Stefan Krah stefan-use...@bytereef.org added the comment:

Hmm, in http://bugs.python.org/issue7511#msg106420 Tarek appeared to
be supportive of the patch.


Re DISTUTILS_USE_SDK:

I don't think many users are aware of this variable. Also, it is not
needed at all; it is sufficient to execute vcvars64.bat manually
before running setup.py.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7511
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12240] Allow multiple setup_hooks

2011-06-06 Thread Erik Bray

Erik Bray erik.m.b...@gmail.com added the comment:

Adds support for multiple setup_hooks and updates the docs.

For now I left the option name as setup_hook, though it might make sense to 
rename it to setup_hooks for consistency's sake.

--
keywords: +patch
Added file: http://bugs.python.org/file22264/python_issue12240.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12240
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12238] Readline module loading in interactive mode

2011-06-06 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

I've done a little poking around, and it looks like you are correct and I'm 
wrong. It appears that readline.so is or should be a special case.  I've added 
some people to nosy to see what they think.

Specifically, it appears that if I put a file that should shadow a library 
module that is imported at python startup time (eg: os.py) into my current 
working directory I still get the os.py from the appropriate lib directory, 
even though '' is first in my sys.path.  This is not how I thought it worked, 
but it is my observation.  I tested this on 2.6.6, 2.7.1 and 3.3 tip.

--
nosy: +brett.cannon, haypo, pitrou
versions: +Python 2.7, Python 3.1, Python 3.2, Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12238
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12196] add pipe2() to the os module

2011-06-06 Thread Charles-François Natali

Charles-François Natali neolo...@free.fr added the comment:

Hmm, thinking about it, I don't see any reason to make the flags argument 
optional.
Here's a patch changing that (also, pipe2 is now declared as METH_O instead of 
METH_VARARGS).

--
Added file: http://bugs.python.org/file22265/pipe2_arg.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12196
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12271] Python 2.7.x on IA64 running SLES 11 SP1

2011-06-06 Thread Stefan Krah

Stefan Krah stefan-use...@bytereef.org added the comment:

panel.h is not found. You'll need to install the package that
provides libpanel together with the header files:

error: panel.h: No such file or directory


This does not look like a Python bug, so I'll set the issue to
'pending'. You can still respond to the issue if you think otherwise.

--
nosy: +skrah
resolution:  - invalid
stage:  - committed/rejected
status: open - pending

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12271
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12196] add pipe2() to the os module

2011-06-06 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 Hmm, thinking about it, I don't see any reason to make the flags argument 
 optional.
 Here's a patch changing that (also, pipe2 is now declared as METH_O instead 
 of METH_VARARGS).

Looks good to me.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12196
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11893] Obsolete SSLFakeFile in smtplib?

2011-06-06 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 Note that I didn't test LMTP. Should I or is it obvious enough that the 
 change is ok?

Thank you for the patch! I think it's ok. I'll give it a try and commit
if everything is alright.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11893
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11893] Obsolete SSLFakeFile in smtplib?

2011-06-06 Thread Roundup Robot

Roundup Robot devnull@devnull added the comment:

New changeset b68390b6dbfd by Antoine Pitrou in branch 'default':
Issue #11893: Remove obsolete internal wrapper class `SSLFakeFile` in the 
smtplib module.
http://hg.python.org/cpython/rev/b68390b6dbfd

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11893
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11893] Obsolete SSLFakeFile in smtplib?

2011-06-06 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
resolution:  - fixed
stage:  - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11893
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >