Re: Convert '165.0' to int

2011-07-24 Thread Frank Millman
On Jul 23, 5:12 pm, Billy Mays  wrote:
> On 7/23/2011 3:42 AM, Chris Angelico wrote:
>
>
>
> > int(s.rstrip('0').rstrip('.'))
>
> Also, it will (in?)correct parse strings such as:
>
> '16500'
>
> to 165.
>
> --
> Bill

True enough.

If I really wanted to be 100% safe, how about this -

def get_int(s):
if '.' in s:
num, dec = s.split('.', 1)
if dec != '':
if int(dec) != 0:
raise ValueError('Invalid literal for int')
return int(num)
return int(s)

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


Re: Convert '165.0' to int

2011-07-24 Thread Steven D'Aprano
Billy Mays wrote:

> I'll probably get flak for this, but damn the torpedoes:
> 
> def my_int(num):
>  import re
>  try:
>  m = re.match('^(-?[0-9]+)(.0)?$', num)
>  return int(m.group(1))

As a toy for learning about regexes, that's fine, but I trust you would
never use that in production. There are less verbose ways of wasting time
and memory.


>  except AttributeError:
>  #raise your own error, or re raise
>  raise

"except Foo: raise" is pointless; a bare raise is only useful if you need to
do something before, or instead of, re-raising the current exception.

try:
boil(kettle)
except HeatingError:
if isempty(kettle):
kettle.fill(water)
boil(kettle)
else:
raise


Catching an exception only to unconditionally re-raise it is only good for
generating more heat in the CPU and making other developers laugh at you :)



-- 
Steven

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


Strings show as brackets with a 'u'. Hi, ...[u'174'] ...Probably newbie question but not sure how suppress the brackets and the 'u' ? I assume pyhon is telling me it's a unicode string in the n variab

2011-07-24 Thread Saranya Sweet
http://123maza.com/65/beauty147/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert '165.0' to int

2011-07-24 Thread Steven D'Aprano
Frank Millman wrote:

> If I really wanted to be 100% safe, how about this -
> 
> def get_int(s):
> if '.' in s:
> num, dec = s.split('.', 1)
> if dec != '':
> if int(dec) != 0:
> raise ValueError('Invalid literal for int')
> return int(num)
> return int(s)

Consider what happens if you pass s = "42.-0".


-- 
Steven

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


Re: Convert '165.0' to int

2011-07-24 Thread Ben Finney
Steven D'Aprano  writes:

> As a toy for learning about regexes, that's fine, but I trust you would
> never use that in production. There are less verbose ways of wasting time
> and memory.

+1 QotW

-- 
 \ “I may disagree with what you say, but I will defend to the |
  `\death your right to mis-attribute this quote to Voltaire.” |
_o__)   —Avram Grumer, rec.arts.sf.written, 2000-05-30 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert '165.0' to int

2011-07-24 Thread Frank Millman
On Jul 24, 9:34 am, Steven D'Aprano  wrote:
> Frank Millman wrote:
> > If I really wanted to be 100% safe, how about this -
>
> >     def get_int(s):
> >         if '.' in s:
> >             num, dec = s.split('.', 1)
> >             if dec != '':
> >                 if int(dec) != 0:
> >                     raise ValueError('Invalid literal for int')
> >             return int(num)
> >         return int(s)
>
> Consider what happens if you pass s = "42.-0".
>

G!

Ok, what if I change
if int(dec) != 0:
to
if [_ for _ in list(dec) if _ != '0']:

If I do this, I can get rid of the previous line -
if dec != ''

Am I getting closer?

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


Re: Convert '165.0' to int

2011-07-24 Thread Thomas 'PointedEars' Lahn
Billy Mays wrote:

> On 7/21/2011 10:40 PM, Thomas 'PointedEars' Lahn wrote:
>> Billy Mays wrote:
>>> On 07/21/2011 08:46 AM, Web Dreamer wrote:
 If you do not want to use 'float()' try:

 int(x.split('.')[0])
>>>
>>> This is right.
>>
>> Assuming that the value of `x' is in the proper format, of course.  Else
>> you might easily cut to the first one to three digits of a string
>> representation (if `.' is the thousands separator of the locale, e. g.)
> 
> The point (which was clear to me) was to convert a properly formatted
> string representation of a floating point number to an integer.  We
> might also assume the number could be a hex encoded float or be in
> scientific notation.  If the input is not properly formatted, it is
> unreasonable for us to return a correct value.

By "*proper* format" I was not referring to the user input.  It is not up to 
you to define which number formats in the rest of the world can be 
considered proper.  Indeed, Switzerland uses 1'234.56, and I find that quite 
reasonable, even though I am German and in Germany 1.234,56 is used (which I 
was referring to).
 
 But, the problem is the same as with int(float(x)), the integer number
 is still not as close as possible as the original float value.

 I would in fact consider doing this:

 int(round(float(x)))
>>>
>>> This is wrong, since there is a loss of information in the float cast:
>>>
>>>   >>>  float('9007199254740993.0')
>>> 9007199254740992.0
>>>
>>> Notice the last digit switched from a 3 to a 2?  Floats in python don't
>>> have arbitrary accuracy.  You would need to import decimal and use it
>>> for rounding to work properly.
>>
>> It should be floor() though, for that is what int() does.
>
> Um, what?

_

>>> print math.floor.__doc__
floor(x)

Return the floor of x as a float.
This is the largest integral value <= x.
_

The point I was trying to make was that round() would return a different 
result than intended by the OP when the fractional part was greater than
or equal to 0.5.  So it should not be used here.  Instead,

  from math import floor
  int(floor(float(x)))

should be used.  (I assumed before, without testing, that Python had a 
global floor() function.  Sorry.)

There is still the rounding error as there is no arbitrary precision with 
built-in floating-point values indeed – however, is it common that users 
enter such large numbers? I don't think so –, but no rounding error caused 
by programmer error.

>>> int(round(float('9007199254.5')))
9007199255L

>>> int(floor(float('9007199254.5')))
9007199254L

-- 
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert '165.0' to int

2011-07-24 Thread Chris Angelico
On Sun, Jul 24, 2011 at 5:58 PM, Frank Millman  wrote:
>  if int(dec) != 0:
> to
>    if [_ for _ in list(dec) if _ != '0']:
>

if dec.rtrim('0')!='':

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


Re: Convert '165.0' to int

2011-07-24 Thread Frank Millman
On Jul 24, 10:07 am, Chris Angelico  wrote:
> On Sun, Jul 24, 2011 at 5:58 PM, Frank Millman  wrote:
> >  if int(dec) != 0:
> > to
> >    if [_ for _ in list(dec) if _ != '0']:
>
> if dec.rtrim('0')!='':
>
> ChrisA

I think you meant 'rstrip', but yes, neater and faster.

Thanks

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


Re: Convert '165.0' to int

2011-07-24 Thread Chris Angelico
On Sun, Jul 24, 2011 at 6:21 PM, Frank Millman  wrote:
> On Jul 24, 10:07 am, Chris Angelico  wrote:
>> if dec.rtrim('0')!='':
>>
>> ChrisA
>
> I think you meant 'rstrip', but yes, neater and faster.
>
> Thanks

Yeah, I did. Mea culpa... every language has it somewhere, but I keep
mucking up which one calls it what. That's what I get for not flicking
to IDLE before posting!

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


Re: Convert '165.0' to int

2011-07-24 Thread Frank Millman
On Jul 23, 8:28 pm, rantingrick  wrote:
> On Jul 23, 1:53 am, Frank Millman  wrote:
>
> >--
> > The ideal solution is the one I sketched out earlier - modify python's
> > 'int' function to accept strings such as '165.0'.
> >--
>
> NO! You create your OWN casting function for special cases.
>
> PythonZEN: "Special cases aren't special enough to break the rules."

BUT

"Although practicality beats purity".

I know I am flogging a dead horse here, but IMHO, '165', '165.',
'165.0', and '165.00' are all valid string representations of the
integer 165.[1]

Therefore, for practical purposes, it would not be wrong for python's
'int' function to accept these without complaining.

Just for fun, imagine that this had been done from python 1.x. Would
people now be clamouring for this 'wart' to be removed in python 3, or
would they say 'yeah, why not?'.

Frank

[1] Don't ask me why anyone would do this. I am dealing with a third-
party product that does exactly that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert '165.0' to int

2011-07-24 Thread Ben Finney
Frank Millman  writes:

> I know I am flogging a dead horse here, but IMHO, '165', '165.',
> '165.0', and '165.00' are all valid string representations of the
> integer 165.[1]

I disagree entirely. Once you introduce a decimal point into the
representation, you're no longer representing an integer.

(They might be the same *number*, but that's not saying the same thing.)

-- 
 \“I saw a sign: ‘Rest Area 25 Miles’. That's pretty big. Some |
  `\  people must be really tired.” —Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


learning another programing language

2011-07-24 Thread Benjamin Gregg

Hi
python was my first language but I need to learn C++ and java for a 
project (No there isn't an alternative)
and I want to know is there any good tutorials or tips for learning 
C++/java after using python?


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


Re: Convert '165.0' to int

2011-07-24 Thread Frank Millman
On Jul 24, 10:53 am, Ben Finney  wrote:
> Frank Millman  writes:
> > I know I am flogging a dead horse here, but IMHO, '165', '165.',
> > '165.0', and '165.00' are all valid string representations of the
> > integer 165.[1]
>
> I disagree entirely. Once you introduce a decimal point into the
> representation, you're no longer representing an integer.
>
> (They might be the same *number*, but that's not saying the same thing.)
>

Fair enough. I never did CS101, so I am looking at this from a
layman's perspective. I am happy to be corrected.

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


Refactor/Rewrite Perl code in Python

2011-07-24 Thread Shashwat Anand
I am working with a huge codebase of Perl.
The code have zero documentation and zero unit-tests.
It seems like a huge hack.

The underlying database schema is horrid.
So I want to rewrite the whole of it in Python.

How do I start ?
The idea is to rewrite module by module.
But how to make sure code doesn't break ?
How can I import perl and python codes in each other ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert '165.0' to int

2011-07-24 Thread Ben Finney
Frank Millman  writes:

> On Jul 24, 10:53 am, Ben Finney  wrote:
> > Frank Millman  writes:
> > > I know I am flogging a dead horse here, but IMHO, '165', '165.',
> > > '165.0', and '165.00' are all valid string representations of the
> > > integer 165.[1]
> >
> > I disagree entirely. Once you introduce a decimal point into the
> > representation, you're no longer representing an integer.
> >
> > (They might be the same *number*, but that's not saying the same
> > thing.)
>
> Fair enough. I never did CS101

Nor I.

> so I am looking at this from a layman's perspective. I am happy to be
> corrected.

The correction I would ask to apply is: If you're to practice
programming, you can't expect the necessary fuzziness of a layman's
understanding to be sufficient in specifying your program.

You need to know the specifics of what it is you're asking the computer
to do, and what it is you're *not* asking the computer to do, and the
difference between the two.

-- 
 \   “It ain't so much the things we don't know that get us in |
  `\trouble. It's the things we know that ain't so.” —Artemus Ward |
_o__) (1834–1867), U.S. journalist |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: learning another programing language

2011-07-24 Thread Chris Angelico
On Sun, Jul 24, 2011 at 6:59 PM, Benjamin Gregg
 wrote:
> Hi
> python was my first language but I need to learn C++ and java for a project
> (No there isn't an alternative)
> and I want to know is there any good tutorials or tips for learning C++/java
> after using python?

Fiddle. Fiddle, fiddle, fiddle. Get yourself one of the good compilers
(gcc for C++; I don't know which is the best Java compiler), and set
yourself up an environment where you can make small edits to your code
and very quickly compile and run it. I like to use SciTE with a good
makefile; pressing F7 in SciTE will 'make' the current project and
show you the results immediately.

Also, find a good mailing list dedicated to C++, and one dedicated to
Java. Lurk there for a while and read tips, and when you run into
specific problems, ask clear questions.

Hope that helps!

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


Re: Convert '165.0' to int

2011-07-24 Thread Chris Angelico
On Sun, Jul 24, 2011 at 6:53 PM, Ben Finney  wrote:
> Frank Millman  writes:
>
>> I know I am flogging a dead horse here, but IMHO, '165', '165.',
>> '165.0', and '165.00' are all valid string representations of the
>> integer 165.[1]
>
> I disagree entirely. Once you introduce a decimal point into the
> representation, you're no longer representing an integer.
>
> (They might be the same *number*, but that's not saying the same thing.)

What's more, 1.311500322e+12 is a valid representation of a date/time,
according to a ridiculously broken game server I've worked with.
That's the number of milliseconds since 1970, stored as floating
point. I'm sure this makes sense to somebody...

Not all possible representations are equally sane. I'm with Ben;
'165.00' is not a string representation of an integer - but you CAN
take that string, validate it as representing a number that can be
represented as an integer, and evaluate what integer it is.

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


Re: Refactor/Rewrite Perl code in Python

2011-07-24 Thread Chris Angelico
On Sun, Jul 24, 2011 at 7:29 PM, Shashwat Anand
 wrote:
> How do I start ?
> The idea is to rewrite module by module.
> But how to make sure code doesn't break ?
> How can I import perl and python codes in each other ?

Can you separate the project into separate executables that call on
each other? You can pipe text from stdout of perl to stdin of python,
for instance. Otherwise, it's not going to be easy. But if you're
going to change the underlying database AND the code at the same time,
it may be best to simply set aside the old code completely and code a
brand new system in Python, capitalizing on the Second Mouse Effect
(the early bird gets the worm, but the second mouse gets the cheese).
You can learn from all the mistakes made in the first version,
allowing you to make an entirely new set of mistakes. :)

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


Re: Refactor/Rewrite Perl code in Python

2011-07-24 Thread Steven D'Aprano
On Sun, Jul 24, 2011 at 7:29 PM, Shashwat Anand 
wrote:

> How do I start ?
> The idea is to rewrite module by module.
> But how to make sure code doesn't break ?

By testing it.

Read up on "test driven development".

At this point, you have this:

Perl modules: A, B, C, D
Python modules: none
Python tests: none

Now, before you rewrite each Perl module in Python, first write a good,
comprehension test suite in Python for that module. You need to have tests
for each function and method. Test that they do the right thing for both
good data and bad data. If you have functional requirements for the Perl
modules, use that as your reference, otherwise use the Perl code as the
reference.

For example, this might be a basic test suite for the len() built-in
function:


for empty in ([], {}, (), set([]), ""):
if len(empty) != 0:
raise AssertionError('empty object gives non-zero len')

for n in range(1, 5):
if len("x"*n) != n:
raise AssertionError('failure for string')
for kind in (list, tuple, set):
obj = kind([None]*n)
if len(obj) != n:
raise AssertionError('failure for %s' % obj)

if len({'a': 1, 'b': None, 42: 'spam'}) != 3:
raise AssertionError('failure for dict')

for bad_obj in (23, None, object(), 165.0, True):
try:
len(bad_obj)
except TypeError:
# Test passes!
pass
else:
# No exception means len() fails!
raise AssertionError('failed test')



Multiply that by *every* function and method in the module, and you have a
moderately good test suite for module A.

(You may want to learn about the unittest module, which will help.)

Now you have:

Perl modules: A, B, C, D
Python modules: none
Python tests: test_A

Now re-write the Python module, and test it against the test suite. If it
fails, fix the failures. Repeat until it passes, and you have:

Perl modules: A, B, C, D
Python modules: A
Python tests: test_A

Now you can be confident that Python A does everything that Perl A does.
Possibly *better* than the Perl module, since if you don't have a test
suite for it, it probably has many hidden bugs.

Continue in this way with the rest of the modules. At the end, you will have
a full test suite against the entire collection of modules.



-- 
Steven

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


Re: PEP 8 and extraneous whitespace

2011-07-24 Thread Michael Brown
On 2011-07-22, John Gordon wrote:

> In <98u00kfnf...@mid.individual.net> Neil Cerutti  writes:
>
>> You can fit much more code per unit of horizontal space with a
>> proportionally spaced font. As a result, that issue, while valid,
>> is significantly reduced.
>
> Is it?  I assume one major reason for the 80-character limit is to help
> the poor sod who will eventually get stuck working with your code on an
> 80-column fixed width terminal window.
>

It's also because many people report that it's easier to read text when
it's not wider than ~75 characters.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: learning another programing language

2011-07-24 Thread Cousin Stanley

Benjamin Gregg wrote:

> 
> I want to know is there any good tutorials or tips 
> for learning C++/java after using python?

  You might find the following site
  to be useful java information 

http://mindprod.com/jgloss/jgloss.html


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: PEP 8 and extraneous whitespace

2011-07-24 Thread Zero Piraeus
:

> It's also because many people report that it's easier to read text when
> it's not wider than ~75 characters.

That rule [1] is for paragraphs of prose in proportional text; code is
both written and read differently. While there most likely is an upper
limit, it's going to be different - larger? - for monospace text with
varying natural line lengths whose visual structure helps you to keep
your "place".

Having said that, I use 78 characters, am rarely annoyed by it
(usually by exception text), and see little benefit in breaking from
such a widely obeyed standard.

 -[]z.

[1] http://webtypography.net/Rhythm_and_Proportion/Horizontal_Motion/2.1.2
-- 
http://mail.python.org/mailman/listinfo/python-list


Help with Latin Characters

2011-07-24 Thread Joao Jacome
http://pastebin.com/aMrzczt4

When the script reaches a file with latin characters (ê é ã etc) it crashes.

Traceback (most recent call last):
  File "C:\backup\ORGANI~1\teste.py", line 37, in 
Retrieve(rootdir);
  File "C:\backup\ORGANI~1\teste.py", line 25, in Retrieve
Retrieve(os.path.join(dir,filename))
  File "C:\backup\ORGANI~1\teste.py", line 18, in Retrieve
print l
  File "C:\Python27\lib\encodings\cp850.py", line 12, in
ejavascript:void(0);ncode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\x8a' in
position 4
3: character maps to 

Does someone knows how to fix this?

Thank you!

João Victor Sousa Jácome
-- 
http://mail.python.org/mailman/listinfo/python-list


python.org is down?

2011-07-24 Thread Laszlo Nagy
Can it be a problem on my side? I have tried from several different 
computers. I cannot even ping it.


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


Re: python.org is down?

2011-07-24 Thread Colin J. Williams

On 24-Jul-11 03:43 AM, Laszlo Nagy wrote:

Can it be a problem on my side? I have tried from several different
computers. I cannot even ping it.


The same for me at Noon EST

Holland where are you?

Colin W.

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


Re: python.org is down?

2011-07-24 Thread David Zerrenner
Same here for me. My traceroute seems to hang somewhere in the Netherlands.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python.org is down?

2011-07-24 Thread Yash Tulsyan
David Zerrenner  writes:

> Same here for me. My traceroute seems to hang somewhere in the Netherlands.
Confirmed here as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Refactor/Rewrite Perl code in Python

2011-07-24 Thread Dan Stromberg
On Sun, Jul 24, 2011 at 2:29 AM, Shashwat Anand wrote:

> I am working with a huge codebase of Perl.
> The code have zero documentation and zero unit-tests.
> It seems like a huge hack.
>

My condolences.  Er, actually, it sounds kind of fun.

The underlying database schema is horrid.
> So I want to rewrite the whole of it in Python.
>

Good choice.


> How do I start ?
>

You're probably going to need to learn a lot about the perl code - it's
probably a good idea to come up with unit, integration and system tests for
it - in perl; document it; and diagram it using something like autodia.

Then after you know what's going on inside and outside the perl, you're
better equipped to rewrite into python.

If you write your automated perl tests in a straightforward way, they can be
mostly straightforwardly translated to python - to get an apples to apples
comparison of how each is functioning.

If you do this module by module, you're less likely to run into problems,
but you're also more likely to preserve some of the original code's
oddities.


> The idea is to rewrite module by module.
>
But how to make sure code doesn't break ?
>

See above.


> How can I import perl and python codes in each other ?
>

I'm not confident you can, unless perhaps you find that you can use an
alternative VM like Parrot.  However, many languages on Parrot are not
complete.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I am fed up with Python GUI toolkits...

2011-07-24 Thread John Nagle

On 7/19/2011 7:34 PM, Andrew Berg wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160

There's PyGUI, which, at a glance, fits whit what you want. Looks like
it uses OpenGL and native GUI facilities.
http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/

It has quite a few external dependencies, though (different dependencies
for each platform, so it requires a lot to be cross-platform).


  It still uses Tcl/Tk stuff, which is un-Pythonic.

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


Re: python.org is down?

2011-07-24 Thread Anna Vester
On Jul 24, 2011 2:43 AM, "Laszlo Nagy"  wrote:
>
> Can it be a problem on my side? I have tried from several different
computers. I cannot even ping it.

Looks like it is down for everyone according to this site:
http://www.downforeveryoneorjustme.com/ .

Anna
http://annavester.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python.org is down?

2011-07-24 Thread Chris Angelico
On Mon, Jul 25, 2011 at 3:08 AM, Anna Vester  wrote:
> On Jul 24, 2011 2:43 AM, "Laszlo Nagy"  wrote:
>>
>> Can it be a problem on my side? I have tried from several different
>> computers. I cannot even ping it.
>
> Looks like it is down for everyone according to this site:
> http://www.downforeveryoneorjustme.com/ .

DNS is fine, and mail.python.org (which hosts the list archives etc)
is perfectly accessible. Looks like either the server's gone down
hard, or something's being changed (new IP, not yet set up in DNS?).

CC'd to the tech contact from whois, which is also the contact address
listed in the SOA record.

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


Re: python.org is down?

2011-07-24 Thread Stefan Behnel

Laszlo Nagy, 24.07.2011 09:43:

Can it be a problem on my side? I have tried from several different
computers. I cannot even ping it.


What's even worse is that PyPI is extremely slow in responding, even up to 
connection failures. I can live with www.python.org being down for a bit, 
but PyPI is a serious piece of infrastructure to many users.


Stefan

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


Re: learning another programing language

2011-07-24 Thread Terry Reedy

On 7/24/2011 4:59 AM, Benjamin Gregg wrote:

Hi
python was my first language but I need to learn C++ and java for a
project (No there isn't an alternative)
and I want to know is there any good tutorials or tips for learning
C++/java after using python?


Learn to meditate so you can deal with the inevitable frustration of 
doing (some) things a much harder way.



--
Terry Jan Reedy

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


Re: python.org is down?

2011-07-24 Thread Chris Angelico
On Mon, Jul 25, 2011 at 3:34 AM, Stefan Behnel  wrote:
> Laszlo Nagy, 24.07.2011 09:43:
>>
>> Can it be a problem on my side? I have tried from several different
>> computers. I cannot even ping it.
>
> What's even worse is that PyPI is extremely slow in responding, even up to
> connection failures. I can live with www.python.org being down for a bit,
> but PyPI is a serious piece of infrastructure to many users.

pypi.python.org pages seem to reference ancillary components from
www.python.org, so the latter being down causes delays on the former.
You could cut it off by creating a hosts entry pointing www.python.org
to 127.0.0.1 or something - it'd fail more quickly that way.

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


Re: Help with Latin Characters

2011-07-24 Thread Terry Reedy

On 7/24/2011 11:15 AM, Joao Jacome wrote:

http://pastebin.com/aMrzczt4


list = os.listdir(dir)
While somewhat natural, using 'list' as a local name and masking the 
builtin list function is a *very bad* idea. Someday you will do this and 
then use 'list(args)' expecting to call the list function, and it will 
not work.



When the script reaches a file with latin characters (ê é ã etc) it crashes.

Traceback (most recent call last):
   File "C:\backup\ORGANI~1\teste.py", line 37, in 
 Retrieve(rootdir);
   File "C:\backup\ORGANI~1\teste.py", line 25, in Retrieve
 Retrieve(os.path.join(dir,filename))
   File "C:\backup\ORGANI~1\teste.py", line 18, in Retrieve
 print l
   File "C:\Python27\lib\encodings\cp850.py", line 12, in
ejavascript:void(0);ncode
 return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\x8a' in
position 4
3: character maps to 


'\x8a' *is* the cp850 encoded byte for reverse accent e: è
But your program treats is a unicode value, where it is a control char 
(Line Tabulation Set), and tries to encode it to cp850, which is not 
possible.


I suspect this has something to do with defining the rootdir as a 
unicode string: rootdir = u"D:\\ghostone"

Perhaps if you removed the 'u', your program would work.
Or perhaps you should explicitly decode the values in os.listdir(dir) 
before joining them to the rootdir and re-encoding.


This sort of thing sometimes works better with Python 3.


Does someone knows how to fix this?

Thank you!

João Victor Sousa Jácome




--
Terry Jan Reedy


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


python.org back up ?(was Re: python.org is down?)

2011-07-24 Thread Terry Reedy

On 7/24/2011 3:43 AM, Laszlo Nagy wrote:

Can it be a problem on my side? I have tried from several different
computers. I cannot even ping it.


python.org, bugs.python.org, docs.python.org, pypi.python.org
all work for me now.

--
Terry Jan Reedy

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


Re: python.org back up ?(was Re: python.org is down?)

2011-07-24 Thread Chris Angelico
On Mon, Jul 25, 2011 at 4:34 AM, Terry Reedy  wrote:
> On 7/24/2011 3:43 AM, Laszlo Nagy wrote:
>>
>> Can it be a problem on my side? I have tried from several different
>> computers. I cannot even ping it.
>
> python.org, bugs.python.org, docs.python.org, pypi.python.org
> all work for me now.

Yep, all up again. Yay!

ChrisA
who has a distinct aversion downtime and outages, especially his own
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert '165.0' to int

2011-07-24 Thread SigmundV
On Jul 21, 10:31 am, "Frank Millman"  wrote:
> Is there a short cut, or must I do this every time (I have lots of them!) ?
> I know I can write a function to do this, but is there anything built-in?

I'd say that we have established that there is no shortcut, no built-
in for this. You write you own function:

string_to_int = lambda s: int(float(s))

Then you apply it to your list of strings:

list_of_integers = map(string_to_int, list_of_strings)

Of course, this will be horribly slow if you have thousands of
strings. In such a case you should use an iterator (assuming you use
python 2.7):

import itertools as it
iterator = it.imap(string_to_int, list_of_strings)


Regards,

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


Aw: python.org back up ?(was Re: python.org is down?)

2011-07-24 Thread David Zerrenner
*pew* I can't live without the docs, that really made my day now. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Help with Latin Characters

2011-07-24 Thread Joao Jacome
2011/7/24 Terry Reedy 

> On 7/24/2011 11:15 AM, Joao Jacome wrote:
>
>> http://pastebin.com/aMrzczt4
>>
>
>list = os.listdir(dir)
> While somewhat natural, using 'list' as a local name and masking the
> builtin list function is a *very bad* idea. Someday you will do this and
> then use 'list(args)' expecting to call the list function, and it will not
> work.
>
>
>  When the script reaches a file with latin characters (ê é ã etc) it
>> crashes.
>>
>> Traceback (most recent call last):
>>   File "C:\backup\ORGANI~1\teste.py", line 37, in 
>> Retrieve(rootdir);
>>   File "C:\backup\ORGANI~1\teste.py", line 25, in Retrieve
>> Retrieve(os.path.join(dir,**filename))
>>   File "C:\backup\ORGANI~1\teste.py", line 18, in Retrieve
>> print l
>>   File "C:\Python27\lib\encodings\**cp850.py", line 12, in
>> ejavascript:void(0);ncode
>> return codecs.charmap_encode(input,**errors,encoding_map)
>> UnicodeEncodeError: 'charmap' codec can't encode character u'\x8a' in
>> position 4
>
> 3: character maps to 
>>
>
> '\x8a' *is* the cp850 encoded byte for reverse accent e: è
> But your program treats is a unicode value, where it is a control char
> (Line Tabulation Set), and tries to encode it to cp850, which is not
> possible.
>
> I suspect this has something to do with defining the rootdir as a unicode
> string: rootdir = u"D:\\ghostone"
> Perhaps if you removed the 'u', your program would work.
> Or perhaps you should explicitly decode the values in os.listdir(dir)
> before joining them to the rootdir and re-encoding.
>
> This sort of thing sometimes works better with Python 3.
>
>
Already tried without unicode string in rootdir, same results. What if try
using raw strings?



>
>  Does someone knows how to fix this?
>>
>> Thank you!
>>
>> João Victor Sousa Jácome
>>
>>
>
> --
> Terry Jan Reedy
>
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>

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


Re: Help with Latin Characters

2011-07-24 Thread Chris Angelico
On Mon, Jul 25, 2011 at 5:01 AM, Joao Jacome  wrote:
> Already tried without unicode string in rootdir, same results. What if try
> using raw strings?

Raw strings are just another way of typing them into your source code.
There are different ways of writing string literals, but they produce
the same string object:

"Hello \\ world!\n"
'Hello \\ world!\n'
"""Hello \\ world!
"""
r"""Hello \ world!
"""

All these produce the exact same thing. But u"Hello \\ world!\n" is
quite different, or (in Python 3) b"Hello \\ world!\n".

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


Re: I am fed up with Python GUI toolkits...

2011-07-24 Thread lkcl
On Jul 20, 3:34 am, Terry Reedy  wrote:
> On 7/19/2011 10:12 PM, sturlamolden wrote:
>
>
>
> > What is wrong with them:
>
> > 1. Designed for other languages, particularly C++, tcl and Java.
>
> > 2. Bloatware. Qt and wxWidgets are C++ application frameworks. (Python
> > has a standard library!)
>
> > 3. Unpythonic memory management: Python references to deleted C++
> > objects (PyQt). Manual dialog destruction (wxPython). Parent-child
> > ownership might be smart in C++, but in Python we have a garbage
> > collector.
>
> > 4. They might look bad (Tkinter, Swing with Jython).
>
> > 5. All projects to write a Python GUI toolkit die before they are
> > finished. (General lack of interest, bindings for Qt or wxWidgets
> > bloatware are mature, momentum for web development etc.)
>
> Greg Ewing's pygui project is still going and releasing new versions.
>
>
>
> > How I would prefer the GUI library to be, if based on "native"
> > widgets:
>
> > 1. Lean and mean -- do nothing but GUI. No database API, networking
> > API, threading API, etc.
>
> > 2. Do as much processing in Python as possible. No more native code
> > (C, C++, Cython) than needed.
>
> > 3. Instances of extension types can clean themselves up on
> > deallocation. No parent-child ownership model to mess things up. No
> > manual clean-up. Python does all the reference counting we need.
>
> > 4. No artist framework. Use OpenGL, Cairo, AGG or whatever else is
> > suitable.
>
> > 5. No particular GUI thread synchronization is needed  -- Python has a
> > GIL.
>
> > 6. Expose the event loop to Python.
>
> > 7. Preferably BSD-style license, not even LGPL.
>
> > 8. Written for Python in Python -- not bindings for a C++ or tcl
> > toolkit.
>
> I think you described pygui.
>
> > Is it worth the hassle to start a new GUI toolkit project?
>
> Ask Greg what you might help with.
>
> > Or should modern deskop apps be written with something completely
> > different, such as HTML5?
>
> An interesting question. I think thepyjamasproject is aimed in this
> direction,

 weeelll... we kinda want to keep as many platforms supported as
possible, so that includes IE6 canvas (VML) which surprisingly works
pretty damn good, the only thing missing is being able to add text to
VML canvas: everything else (including colour gradients) shockingly
actually works.  it's slow, but what do you expect out of IE6, duh.

 but yes we're finding that an increasing number of people are saying
"i wrote a pyajamas app, it used direct HTML5, sod the browsers that
don't properly support HTML5" and i think that's a good thing.


> but the author says he will never port to Py3. (He explained
> his reasons on this list when I suggested that.)

 :)  it's not quiiite a matter of "never" - it's conditional.  the
conditions on which i, personally and extremely grudgingly, will get
involved in a py3 port of pyjamas are when it becomes hellishly
difficult for myself, personally, to maintain all of the components of
pyjamas *including* the desktop ports (w32 MSHTML, gnu pythonwebkit
project, xulrunner N.N) which people tend to forget exist for python
2.N.  the reason for that are a) personally i don't like py3 (because
it didn't include backwards-compatibility for python 2) b) the pyjs
translator is self-contained, and has at absolutely no time any need
for any links at runtime to in fact any python *at all* (because the
pyjs version runs on a javascript engine *not* a python engine).

 there's no "never" in there - it's just that i'll keep reviewing the
situation, and i anticipate / predict that it will begin to become
difficult to compile python2 applications (such as python-comtypes) at
some point in approx ooo... 5 to 7 years.  maybe not - it's hard to
say.

 anyway - if however someone else wants to collaborate and/or fund a
py3 port of pyjamas, knock yourself out: just bear in mind that it's
an estimated 18 man-month project.

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


Re: Help with Latin Characters

2011-07-24 Thread Joao Jacome
2011/7/24 Chris Angelico 

> On Mon, Jul 25, 2011 at 5:01 AM, Joao Jacome  wrote:
> > Already tried without unicode string in rootdir, same results. What if
> try
> > using raw strings?
>
> Raw strings are just another way of typing them into your source code.
> There are different ways of writing string literals, but they produce
> the same string object:
>
> "Hello \\ world!\n"
> 'Hello \\ world!\n'
> """Hello \\ world!
> """
> r"""Hello \ world!
> """
>
> All these produce the exact same thing. But u"Hello \\ world!\n" is
> quite different, or (in Python 3) b"Hello \\ world!\n".
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>

http://pastebin.com/iQzPhpVh

Changed filename to rawstring, now python can retrieve the file's info.
Now in the database, character "Ê" becomes "Ê", but if i retrieve it in
python and try to get file size, it works.

Is there a way to modify output to display correctly these characters?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Web

2011-07-24 Thread lkcl
On Jun 15, 1:11 pm, "bruno.desthuilli...@gmail.com"
 wrote:
> On Jun 15, 9:50 am, sidRo  wrote:
>
> > Is Python only for server side?
>
> Is it a theoretical question or a practical one ?-)
>
> More seriously: except for the old proof-of-concept Grail browser, no
> known browser uses Python as a client-side scripting language.

 ahh paul bonser _did_ make an attempt to write a web browser in
python: he got quite a long way but nobody helped him out,
unfortunately.

 i did actually get grail browser up-and-running again, under python
2.5 and then 2.6 - it actually works, hurrah! :)

 the list of client-side (assuming you meant web browser client, sid)
python programming environments is actually really quite long.. and
some of them very very obscure :) i maintain (as i find them) a list,
here:

 http://wiki.python.org/moin/WebBrowserProgramming

 the one that i have the most respect for (despite its DOM TR2
compliance only, and the obscure bug that most people will never
encounter) is python-khtml.  KHTML aka Konqueror's web browser is the
granddaddy of webkit after the toerags from apple got their grubby
mitts on it, and i do wish that KHTML got more love and attention,
because it's a proper true free software *independent* web browser
engine that is truly developed by a free software community, not a
bunch of corporate lackies with a commercial axe to grind.

 there is quite a lot of mileage to be had from ironpython, because of
course it translates to CLR (.NET) - as a result you have things like
appcelerator (titanium).  sadly you'll probably get that running under
mono at some time when hell freezes over, but that's another story.

 the other one that's worth a laugh, ok maybe a snort, is the mozilla-
funded project back in 2000 to add support to firefox for < script
language="python" /> which actually damn well worked - properly -
except that it resulted in a whopping 10mb plugin (because it was the
entire python interpreter in a firefox plugin, that's why!) and was
only available for firefox.  oh, and building the dependencies on w32?
jaezzus h christ on a bike was it a bitch.  to give you an idea: the
last people who attempted it were novell, some time around 2007.  to
get an accurate date, look up the release date on xulrunner 1.8.

 anyway - bottom line: there's a hell of a lot (including pyjamas of
course, yaay!) but it's all pretty obscure esoteric stuff and you do
have to be a bit off your head to consider using the various options
available.

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


Re: Rant on web browsers

2011-07-24 Thread lkcl
On Jun 14, 7:31 am, Chris Angelico  wrote:

> But if anyone feels like writing an incompatible browser, please can
> you add Python scripting?

 http://wiki.python.org/moin/WebBrowserProgramming

 already been done, chris - you want the firefox plugin, pyxpcomext
and then if you actually want to manipulate the DOM in the browser
engine as well, you need the 2nd plugin xpcom as well.  oh, i also
forgot (because it's quite new) there's firebreath as well:
https://github.com/Nitrogenycs/firebreath-x

 so... yeah, if you're completely off your head, knock yourself out :)

 l.

 p.s. pyjamas rocks!  sorry, had to say that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Rant on web browsers

2011-07-24 Thread lkcl
On Jun 14, 7:31 am, Chris Angelico  wrote:
> Random rant and not very on-topic. Feel free to hit Delete and move on.
>
> I've just spent a day coding in Javascript, and wishing browsers
> supported Python instead (or as well). All I needed to do was take two

 ok your next best thing is to try pyjampiler.  it's the absolute
minimum and easiest stuff you'll need to be able to write code in
python yet integrate it easily into a pre-existing web site.  there
are alternatives out there (competitor projects to pyjamas) - take a
look on http://wiki.python.org/moin/WebBrowserProgramming

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


Re: PEP 8 and extraneous whitespace

2011-07-24 Thread Ben Finney
Zero Piraeus  writes:

> :
>
> > It's also because many people report that it's easier to read text when
> > it's not wider than ~75 characters.
>
> That rule [1] is for paragraphs of prose in proportional text; code is
> both written and read differently. While there most likely is an upper
> limit, it's going to be different - larger? - for monospace text with
> varying natural line lengths whose visual structure helps you to keep
> your "place".

Code is also more densely expressive and provides less redundancy in
expression, and the reader is required to make much finer scrutiny of it
than of natural language text.

I find that the limit of line length for comfortably reading code is
significantly lower than that for English text. “Keep lines less than 80
characters” makes a lot of sense to me in that context.

-- 
 \“Program testing can be a very effective way to show the |
  `\presence of bugs, but is hopelessly inadequate for showing |
_o__)  their absence.” —Edsger W. Dijkstra |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter/py2exe with installer

2011-07-24 Thread Kevin Walzer
Can anyone point me in the direction of a Tkinter/Python app that has 
been wrapped with py2exe and is deployed on Windows as a standalone 
using one of the standard installer tools? (MSI, NSIS, Inno Setup, etc.) 
I'm working on a Tkinter app for Windows and have had a surprisingly 
hard time finding such apps to use as examples/benchmarks, etc. (The 
only one I've found, in fact, is Webgobbler at 
http://sebsauvage.net/python/webgobbler/index.html; a nice app, but I'd 
like more examples.)


--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: I am fed up with Python GUI toolkits...

2011-07-24 Thread Tim Roberts
Gregory Ewing  wrote:

>Tim Roberts wrote:
>> 
>> I don't think your glibness is justified.  There is a legitimate appeal to
>> this notion.  The fact is that MANY APIs can be completely and adequately
>> described by HTML.
>
>My brain raises a TypeError on that statement. According to
>my understanding of the world, describing APIs is not something
>that HTML does. (Or did you mean GUI rather than API?)

Yes, you are correct.  Brain fart on my part.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python.org is down?

2011-07-24 Thread shbk background
ukraine, connection was lost also...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I am fed up with Python GUI toolkits...

2011-07-24 Thread Gregory Ewing

John Nagle wrote:


There's PyGUI, which, at a glance, fits whit what you want. Looks like
it uses OpenGL and native GUI facilities.
http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/


  It still uses Tcl/Tk stuff, which is un-Pythonic.


You must be thinking of something else. My PyGUI has nothing
to do with Tcl/Tk at all.

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


Re: Convert '165.0' to int

2011-07-24 Thread Gregory Ewing

Frank Millman wrote:


I know I am flogging a dead horse here, but IMHO, '165', '165.',
'165.0', and '165.00' are all valid string representations of the
integer 165.[1]

Therefore, for practical purposes, it would not be wrong for python's
'int' function to accept these without complaining.


How far would you go with that? Would you also accept
'1.65e2' as a valid representation of the integer 165?

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


Re: Convert '165.0' to int

2011-07-24 Thread Billy Mays

On 7/24/2011 2:27 PM, SigmundV wrote:

On Jul 21, 10:31 am, "Frank Millman"  wrote:

Is there a short cut, or must I do this every time (I have lots of them!) ?
I know I can write a function to do this, but is there anything built-in?


I'd say that we have established that there is no shortcut, no built-
in for this. You write you own function:

string_to_int = lambda s: int(float(s))

Then you apply it to your list of strings:

list_of_integers = map(string_to_int, list_of_strings)

Of course, this will be horribly slow if you have thousands of
strings. In such a case you should use an iterator (assuming you use
python 2.7):

import itertools as it
iterator = it.imap(string_to_int, list_of_strings)


Regards,

Sigmund


if the goal is speed, then you should use generator expressions:

list_of_integers = (int(float(s)) for s in list_of_strings)
--
http://mail.python.org/mailman/listinfo/python-list


Validating Entry in tkinter

2011-07-24 Thread Saul Spatz
In tcl/tk an Entry widget can be set to validate its contents with the validate 
option.  You have to give it a validatecommand (vcmd), which is a tcl script 
that runs when some action triggers validation.  Usually, the script would use 
"percent substitutions" so the script would be something like {ValidInt %P} 
where %P is the value of the widget should the proposed change occur.  

Can one do something like this in tkinter?  I've verified that with

e = Entry(master, validate = 'all', vcmd = validInt) 

the validInt function is called, but it isn't passed any parameters. I can't 
find that e has any attribute corresponding to the %P value above.

Is it not possible to do this in tkinter, or have I overlooked something? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Web

2011-07-24 Thread Dan Stromberg
On Wed, Jun 15, 2011 at 5:11 AM, bruno.desthuilli...@gmail.com <
bruno.desthuilli...@gmail.com> wrote:

> On Jun 15, 9:50 am, sidRo  wrote:
> > Is Python only for server side?
>
> Is it a theoretical question or a practical one ?-)
>
> More seriously: except for the old proof-of-concept Grail browser, no
> known browser uses Python as a client-side scripting language.
>
> There are three relevant projects:

1) Pyjamas - translates a dialect of Python 2.x to Javascript, and provides
a widget set that allows the same code to provide a web GUI and a desktop
GUI, using a desktop-like API

2) Emscripten - which is CPython 2.x itself (and theoretically, 3.x?)
compiled into Javascript using LLVM's C frontend and an LLVM bitcode
translator that creates Javascript code

3) Pypy - had a Javascript backend, but that was removed from the website in
2010 (?)

Of these, Pyjamas is probably the most useful today.  Emscripten reportedly
crashes some browsers, and Pypy seems to have lost interest in Javascript.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Validating Entry in tkinter

2011-07-24 Thread rantingrick
On Jul 24, 7:11 pm, Saul Spatz  wrote:
>
> Can one do something like this in tkinter?
‡

(1) First of all what exactly do you wish return?
 * an integer
 * a float
 * something else?

(2) Is this input part of a modal or non-modal interface?

For me, input validation should happen in *real* time and NOT after
the fact. For instance; if you have two entrys forms and a button in
your GUI like below...

 +--+
 | Tk | X | |
 +--+
 |  |
 |  Value1: [  ]|
 |  Value2: [  ]|
 |  |
 |   [Calculate]|
 '--'

... and your "validator" only checks the contents of "Value1" and
"Value2" AFTER the user presses the "Calculate" button then
congratulations because you have just created an unintuitive GUI
design. Instead, your entry widgets should have been filtering the key-
presses so that it would be impossible to enter anything but an
integer or float or whatever you want. Running a validater after the
fact is an anti pattern.

It is not very difficult to subclass a tk.Entry widget and create some
validation/filtering logic. However it would be helpful if you could
be a wee bit more specific about your validation needs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I am fed up with Python GUI toolkits...

2011-07-24 Thread Michael Torrie
On 07/20/2011 07:17 PM, rantingrick wrote:
> Please everyone, do not change the subject of someone's thread 
> because it's considered rude. Thank you.

Too funny.  Says who?  Changing the subject line to reflect the
direction this part of the thread (a branch if you will) is going is
definitely appropriate.  At least according to etiquette rules that go
back for some time (likely before you were around--you're pretty young
no?)

Besides forking is a time-honored open source tradition.

> What about the etiquette of staying on topic? The only person who is 
> OFFICIALLY allowed to change the subject matter of a thread is the 
> OP. Sure some folks might make an off topic post here and there 
> however i find it bombastically rude when folks just change a topic 
> of thread they do not own.

Oh really.  I guess since you are one of the leaders I guess it must be
so.  Too funny.

Fortunately not all of us are using the crippled one-dimensional
Gmail "conversation" way of reading threads on e-mails.  So as long as
the topic is appropriately changed, we can deal with branches that twist
and turn.  My e-mail reader threads them all quite nicely.

Now replying to an existing thread to start an entirely new, unrelated
thread is definitely rude.

> How would you like it if i came to your house and wrote my name on 
> your refrigerator door, or used your toilet without asking, or slept 
> in your bed? I would not do that because i have manners. Feel free to
> make yourself comfortable but don't put you feet on the coffee 
> table.

Did you study "logical fallacies" in English classes at uni?  (If she
weighs the same as a duck then she's made of wood, and therefore she's a
witch).

And as for manners go, I'm glad to see you've improved so much in the
last year.  Who knows you might just be removed from kill files yet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I am fed up with Python GUI toolkits...

2011-07-24 Thread Grant Edwards
On 2011-07-24, John Nagle  wrote:
> On 7/19/2011 7:34 PM, Andrew Berg wrote:
>> -BEGIN PGP SIGNED MESSAGE-
>> Hash: RIPEMD160
>>
>> There's PyGUI, which, at a glance, fits whit what you want. Looks like
>> it uses OpenGL and native GUI facilities.
>> http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/
>>
>> It has quite a few external dependencies, though (different dependencies
>> for each platform, so it requires a lot to be cross-platform).
>
>It still uses Tcl/Tk stuff, which is un-Pythonic.

Like Tkinter does?

I thought PyGUI it was based on GTk?  That's what the web page seems
to indicate.

-- 
Grant



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


Re: I am fed up with Python GUI toolkits...

2011-07-24 Thread Terry Reedy

On 7/24/2011 8:51 PM, Michael Torrie wrote:


Now replying to an existing thread to start an entirely new, unrelated
thread is definitely rude.


Rude or not, it tends to be unproductive. If someone posted "Help with 
threading internals" here, it could well not be seen by the appropriate 
people, especially if they have threads collapsed.


--
Terry Jan Reedy

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


Re: Validating Entry in tkinter

2011-07-24 Thread Saul Spatz
I want to interface to the native validation of tk.  If you don't know what 
that is, you're unlikely to be able to help me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with Latin Characters

2011-07-24 Thread Benjamin Kaplan
On Sun, Jul 24, 2011 at 3:47 PM, Joao Jacome  wrote:
>
> 2011/7/24 Chris Angelico 
>>
>> On Mon, Jul 25, 2011 at 5:01 AM, Joao Jacome  wrote:
>> > Already tried without unicode string in rootdir, same results. What if try
>> > using raw strings?
>>
>> Raw strings are just another way of typing them into your source code.
>> There are different ways of writing string literals, but they produce
>> the same string object:
>>
>> "Hello \\ world!\n"
>> 'Hello \\ world!\n'
>> """Hello \\ world!
>> """
>> r"""Hello \ world!
>> """
>>
>> All these produce the exact same thing. But u"Hello \\ world!\n" is
>> quite different, or (in Python 3) b"Hello \\ world!\n".
>>
>> ChrisA
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
> http://pastebin.com/iQzPhpVh
> Changed filename to rawstring, now python can retrieve the file's info.
> Now in the database, character "Ê" becomes "Ê", but if i retrieve it in 
> python and try to get file size, it works.
> Is there a way to modify output to display correctly these characters?
>

Your database does not have characters. Your database has a sequence
of bytes. Your terminal reads a sequence of bytes. If your terminal
and your database interpret that sequence of bytes differently, you'll
appear to have different characters even though ts the actual content
of the string is the same. What you should do is decode the bytes into
Unicode as soon as you pull them out of the database (using whatever
encoding the database uses) and then encode them into your terminal's
encoding right before you print them.


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


Re: Convert '165.0' to int

2011-07-24 Thread Chris Angelico
On Mon, Jul 25, 2011 at 10:07 AM, Billy Mays  wrote:
> if the goal is speed, then you should use generator expressions:
>
> list_of_integers = (int(float(s)) for s in list_of_strings)

Clarification: This is faster if and only if you don't actually need
it as a list. In spite of the variable name, it's NOT a list, and you
can't index it (eg you can't work with list_of_integers[7]). However,
you can iterate over it to work with the integers in sequence, and for
that specific (and very common) use, it will be faster and use less
memory than actually creating the list. It's also going to be a LOT
faster than creating the list, if you only need a few from the
beginning of it; the generator evaluates lazily.

Personally, I'd just create a tiny function and use that, as has been suggested.

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


Re: Convert '165.0' to int

2011-07-24 Thread Frank Millman
On Jul 25, 2:04 am, Gregory Ewing  wrote:
> Frank Millman wrote:
> > I know I am flogging a dead horse here, but IMHO, '165', '165.',
> > '165.0', and '165.00' are all valid string representations of the
> > integer 165.[1]
>
> > Therefore, for practical purposes, it would not be wrong for python's
> > 'int' function to accept these without complaining.
>
> How far would you go with that? Would you also accept
> '1.65e2' as a valid representation of the integer 165?
>

To be honest, I don't even know what that means! I could read up on
it, but I think this has gone far enough. Having flogged this horse to
death, I will now let it rest in peace :-)

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


Re: a little parsing challenge ☺

2011-07-24 Thread John O'Hagan
On Thu, 21 Jul 2011 05:58:48 -0700 (PDT)
Xah Lee  wrote:

[...]

> > > On Sunday, July 17, 2011 2:48:42 AM UTC-7, Raymond Hettinger wrote:
> > >> On Jul 17, 12:47 am, Xah Lee  wrote:
> > >>> i hope you'll participate. Just post solution here. Thanks.
> >
> > >>http://pastebin.com/7hU20NNL
> >
> > > just installed py3.
> > > there seems to be a bug.
> > > in this file
> >
> > >http://xahlee.org/p/time_machine/tm-ch04.html
> >
> > > there's a mismatched double curly quote. at position 28319.
> >
> > > the python code above doesn't seem to spot it?

[...]

> >
> > That script doesn't check that the balance is zero at the end of file.
> >
> > Patch:
> >
> > --- ../xah-raymond-old.py       2011-07-19 20:05:13.0 +0200
> > +++ ../xah-raymond.py   2011-07-19 20:03:14.0 +0200
> > @@ -16,6 +16,8 @@
> >          elif c in closers:
> >              if not stack or c != stack.pop():
> >                  return i
> > +    if stack:
> > +        return i
> >      return -1
> >
> >  def scan(directory, encoding='utf-8'):
> 
> Thanks a lot for the fix Raymond.
> 
> Though, the code seems to have a minor problem.
> It works, but the report is wrong.
> e.g. output:
> 
> 30068: c:/Users/h3/web/xahlee_org/p/time_machine\tm-ch04.html
> 
> that 30068 position is the last char in the file.
> The correct should be 28319. (or at least point somewhere in the file
> at a bracket char that doesn't match.)
> 

[...]

If you want to know where brackets were opened which remain unclosed at EOF, 
then you have to keep the indices as well as the characters in the stack, and 
not return until the scan is complete, because anything still in the stack 
might turn out to be the earliest error. Easy enough to implement:

def checkmatch(string): #skipping the file handling
openers = {'[': ']', '(': ')', '{': '}' } #etc
closers = openers.values() 
still_open, close_errors = [], []
for index, char in enumerate(string, start=1):
if char in openers:
still_open.append((index, char))
elif char in closers:
if still_open and char == openers[still_open[-1][1]]:
still_open.pop()
else:
close_errors.append((index, char))
if still_open or close_errors:
return min(still_open[:1] + close_errors[:1])[0]


although you might as well return still_open + close_errors and see them all.

Regards,

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


Re: Refactor/Rewrite Perl code in Python

2011-07-24 Thread Shashwat Anand
Thanks everyone for the insight.
I got the idea as to how and where to start.
Guess I need to work in Perl for now, so as to start the conversion process.
Regarding Tests, I had already started writing tests before posting.
Writing tests for every module will be a pain as well as a nice experience.

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