Re: How to get number of bytes written to nonblocking FIFO when EAGAIN is raised?

2011-07-21 Thread Aaron Staley
On Jul 19, 8:15 pm, Adam Skutt ask...@gmail.com wrote:
 On Jul 19, 9:19 pm, Aaron Staley usaa...@gmail.com wrote:

  However, if interpreter 1 overfills the FIFO, we get an error (EAGAIN) 
  f.write('a'*7)

  IOError: [Errno 11] Resource temporarily unavailable

  However interpreter 2 still receives data len(f.read())

  65536

  It looks like interpreter 1 pushed data until the FIFO was full and
  then raised the IOError.  Interpreter 2 constantly received some, but
  not all, of what interpreter 2 tried to send.
  Unfortunately, the IOError seems to have no attribute indicating how
  much data was successfully sent.  I've looked through the docs and
  can't seem to figure out how; can anyone land some advice?

 You need to do as Roy Smith suggested and use the actual OS I/O calls
 os.read() and os.write().  os.write() returns the number of bytes
 actually written to the underlying descriptor.  Python file objects
 are akin to FILE structures in C: they perform buffering and other
 operations internally that makes them less than suitable for usage
 with asynchronous UNIX I/O. In particular, they buffer I/O internally
 before writing it to the descriptor, so there's no direct relationship
 between calling file.write() and how much data is written to the
 stream. In addition, file objects also simply raise the underlying OS
 error when it occurs.  The UNIX write(2) syscall assumes that you have
 been keeping track of how many bytes you've successfully written to
 the stream and does not track it for you.

 Adam

That's for the info; lower level I/O solved the issue.
That said, is such behavior with the file objects intended? It seems
they don't work correctly with an underlying non-blocking file
descriptor, but the documentation doesn't state such. In fact, it
suggests you can use non-blocking with this comment for file.read:

Also note that when in non-blocking mode, less data than was requested
may be returned, even if no size parameter was given.
-- 
http://mail.python.org/mailman/listinfo/python-list


Convert '165.0' to int

2011-07-21 Thread Frank Millman

Hi all

I want to convert '165.0' to an integer.

The obvious method does not work -


x = '165.0'
int(x)

Traceback (most recent call last):
 File stdin, line 1, in module
ValueError: invalid literal for int() with base 10: '165.0'

If I convert to a float first, it does work -


int(float(x))

165




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?


Thanks

Frank Millman


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


Re: Convert '165.0' to int

2011-07-21 Thread Leo Jay
On Thu, Jul 21, 2011 at 5:31 PM, Frank Millman fr...@chagford.com wrote:

 Hi all

 I want to convert '165.0' to an integer.

 The obvious method does not work -

 x = '165.0'
 int(x)

 Traceback (most recent call last):
  File stdin, line 1, in module
 ValueError: invalid literal for int() with base 10: '165.0'

 If I convert to a float first, it does work -

 int(float(x))

 165


 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?

 Thanks

 Frank Millman


How about int(x[:-2])?

--
Best Regards,
Leo Jay
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert '165.0' to int

2011-07-21 Thread Thomas Jollans
On 21/07/11 11:31, Frank Millman wrote:
 Hi all
 
 I want to convert '165.0' to an integer.

Well, it's not an integer. What does your data look like? How do you
wish to convert it to int? Do they all represent decimal numbers? If so,
how do you want to round them? What if you get '165.xyz' as input?
Should that raise an exception? Should it evaluate to 165? Should it use
base 36?

 If I convert to a float first, it does work -
 
 int(float(x))
 165

 
 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?

What's wrong with this? It's relatively concise, and it shows exactly
what you're trying to do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert '165.0' to int

2011-07-21 Thread Frank Millman
On Jul 21, 11:47 am, Leo Jay python.leo...@gmail.com wrote:
 On Thu, Jul 21, 2011 at 5:31 PM, Frank Millman fr...@chagford.com wrote:

  Hi all

  I want to convert '165.0' to an integer.

  The obvious method does not work -

  x = '165.0'
  int(x)

  Traceback (most recent call last):
   File stdin, line 1, in module
  ValueError: invalid literal for int() with base 10: '165.0'

  If I convert to a float first, it does work -

  int(float(x))

  165

  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?

  Thanks

  Frank Millman

 How about int(x[:-2])?

 --
 Best Regards,
 Leo Jay- Hide quoted text -

 - Show quoted text -

Nice idea, but it seems to be marginally slower[1] than int(float(x)),
so I think I will stick with the latter.

Frank

[1] See separate thread on apparent inconsisteny in timeit timings.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert '165.0' to int

2011-07-21 Thread Frank Millman
On Jul 21, 11:53 am, Thomas Jollans t...@jollybox.de wrote:
 On 21/07/11 11:31, Frank Millman wrote:

  Hi all

  I want to convert '165.0' to an integer.

 Well, it's not an integer. What does your data look like? How do you
 wish to convert it to int? Do they all represent decimal numbers? If so,
 how do you want to round them? What if you get '165.xyz' as input?
 Should that raise an exception? Should it evaluate to 165? Should it use
 base 36?

  If I convert to a float first, it does work -

  int(float(x))
  165

  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?

 What's wrong with this? It's relatively concise, and it shows exactly
 what you're trying to do.

I am processing an xml file from a third party, and it is full of co-
ordinates in the form 'x=165.0 y=229.0'.

I don't mind using int(float(x)), I just wondered if there was a
shorter alternative.

If there is an alternative, I will be happy for it to raise an
exception if the fractional part is not 0.

Thanks

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


Re: Convert '165.0' to int

2011-07-21 Thread Frank Millman

 [1] See separate thread on apparent inconsisteny in timeit timings.- Hide 
 quoted text -


I must have done something wrong - it is consistent now.

Here are the results -

C:\Python32\Libtimeit.py int(float('165.0'))
10 loops, best of 3: 3.51 usec per loop

C:\Python32\Libtimeit.py int('165.0'[:-2])
10 loops, best of 3: 4.63 usec per loop

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


Re: a little parsing challenge ☺

2011-07-21 Thread Xah Lee
On Jul 19, 11:14 am, Thomas Jollans t...@jollybox.de wrote:
 I thought I'd have some fun with multi-processing:

Nice joke. ☺

 Here's a sane version:

 https://gist.github.com/1087682/2240a0834463d490c29ed0f794ad15128849ff8e

hi thomas,

i still cant get your code to work. I have a dir named xxdir with a
single test file xx.txt,with this content:

 foo[(])bar

when i run your code
py3 validate_brackets_Thomas_Jollans_2.py

it simply exit and doesn't seem to do anything. I modded your code to
print the file name it's proccessing. Apparently it did process it.

my python isn't strong else i'd dive in. Thanks.

I'm on Python 3.2.1. Here's a shell log:

 h3@H3-HP 2011-07-21 05:20:30 ~/web/xxst/find_elisp/validate matching
brackets
py3 validate_brackets_Thomas_Jollans_2.py
 h3@H3-HP 2011-07-21 05:20:34 ~/web/xxst/find_elisp/validate matching
brackets
py3 validate_brackets_Thomas_Jollans_2.py
c:/Users/h3/web/xxst/find_elisp/validate matching brackets/xxdir
\xx.txt
 h3@H3-HP 2011-07-21 05:21:59 ~/web/xxst/find_elisp/validate matching
brackets
py3 --version
Python 3.2.1
 h3@H3-HP 2011-07-21 05:27:03 ~/web/xxst/find_elisp/validate matching
brackets

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


Re: a little parsing challenge ☺

2011-07-21 Thread Xah Lee
On Jul 19, 11:07 am, Thomas Jollans t...@jollybox.de wrote:
 On 19/07/11 18:54, 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 xah...@gmail.com 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?

  here's the elisp script output when run on that dir:

  Error file: c:/Users/h3/web/xahlee_org/p/time_machine/tm-ch04.html
  [“ 28319]
  Done deal!

 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.)

Today, i tried 3 more scripts. 2 fixed python3 versions, 1 ruby, all
failed again. I've reported the problems i encounter at python or ruby
newsgroups. If you are the author, a fix is very much appreciated.
I'll get back to your code and eventually do a blog of summary of all
different lang versions.

Am off to test that elaborate perl regex now... cross fingers.

 Xah. Mood: quite discouraged.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a little parsing challenge ☺

2011-07-21 Thread Thomas Jollans
On 21/07/11 14:29, Xah Lee wrote:
 On Jul 19, 11:14 am, Thomas Jollans t...@jollybox.de wrote:
 I thought I'd have some fun with multi-processing:
 
 Nice joke. ☺
 
 Here's a sane version:

 https://gist.github.com/1087682/2240a0834463d490c29ed0f794ad15128849ff8e
 
 hi thomas,
 
 i still cant get your code to work. I have a dir named xxdir with a
 single test file xx.txt,with this content:
 
  foo[(])bar
 
 when i run your code
 py3 validate_brackets_Thomas_Jollans_2.py
 
 it simply exit and doesn't seem to do anything. I modded your code to
 print the file name it's proccessing. Apparently it did process it.
 
 my python isn't strong else i'd dive in. Thanks.

Curious. Perhaps, in the Windows version of Python, subprocesses don't
use the same stdout? Windows doesn't have fork() (how could they
survive?), so who knows. Try replacing
ex.submit(process_file, fullname)
with
process_file(fullname)
for a non-concurrent version.

 
 I'm on Python 3.2.1. Here's a shell log:
 
  h3@H3-HP 2011-07-21 05:20:30 ~/web/xxst/find_elisp/validate matching
 brackets
 py3 validate_brackets_Thomas_Jollans_2.py
  h3@H3-HP 2011-07-21 05:20:34 ~/web/xxst/find_elisp/validate matching
 brackets
 py3 validate_brackets_Thomas_Jollans_2.py
 c:/Users/h3/web/xxst/find_elisp/validate matching brackets/xxdir
 \xx.txt
  h3@H3-HP 2011-07-21 05:21:59 ~/web/xxst/find_elisp/validate matching
 brackets
 py3 --version
 Python 3.2.1
  h3@H3-HP 2011-07-21 05:27:03 ~/web/xxst/find_elisp/validate matching
 brackets
 
  Xah

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


Re: a little parsing challenge ☺

2011-07-21 Thread Xah Lee

2011-07-21

On Jul 18, 12:09 am, Rouslan Korneychuk rousl...@msn.com wrote:
 I don't know why, but I just had to try it (even though I don't usually
 use Perl and had to look up a lot of stuff). I came up with this:

 /(?|
      (\()(?matched)([\}\]”›»】〉》」』]|$) |
      (\{)(?matched)([\)\]”›»】〉》」』]|$) |
      (\[)(?matched)([\)\}”›»】〉》」』]|$) |
      (“)(?matched)([\)\}\]›»】〉》」』]|$) |
      (‹)(?matched)([\)\}\]”»】〉》」』]|$) |
      («)(?matched)([\)\}\]”›】〉》」』]|$) |
      (【)(?matched)([\)\}\]”›»〉》」』]|$) |
      (〈)(?matched)([\)\}\]”›»】》」』]|$) |
      (《)(?matched)([\)\}\]”›»】〉」』]|$) |
      (「)(?matched)([\)\}\]”›»】〉》』]|$) |
      (『)(?matched)([\)\}\]”›»】〉》」]|$))
 (?(DEFINE)(?matched(?:
      \((?matched)\) |
      \{(?matched)\} |
      \[(?matched)\] |
      “(?matched)” |
      ‹(?matched)› |
      «(?matched)» |
      【(?matched)】 |
      〈(?matched)〉 |
      《(?matched)》 |
      「(?matched)」 |
      『(?matched)』 |
      [^\(\{\[“‹«【〈《「『\)\}\]”›»】〉》」』]++)*+))
 /sx;

 If the pattern matches, there is a mismatched bracket. $1 is set to the
 mismatched opening bracket. $-[1] is its location. $2 is the mismatched
 closing bracket or '' if the bracket was never closed. $-[2] is set to
 the location of the closing bracket or the end of the string if the
 bracket wasn't closed.

 I didn't write all that manually; it was generated with this:

 my @open = ('\(','\{','\[','“','‹','«','【','〈','《','「','『');
 my @close = ('\)','\}','\]','”','›','»','】','〉','》','」','』');

 '(?|'.join('|',map
 {'('.$open[$_].')(?matched)(['.join('',@close[0..($_-1),($_+1)..$#close]). 
 ']|$)'}
 (0 .. $#open)).')(?(DEFINE)(?matched(?:'.join('|',map
 {$open[$_].'(?matched)'.$close[$_]} (0 ..
 $#open)).'|[^'.join('',@open,@close).']++)*+))'

Thanks for the code.

are you willing to make it complete and standalone? i.e. i can run it
like this:

perl Rouslan_Korneychuk.pl dirPath

and it prints any file that has mismatched pair and line/column number
or the char position?

i'd do it myself but so far i tried 5 codes, 3 fixes, all failed. Not
a complain, but it does take time to gather the code, of different
langs by different people, properly document their authors and
original source urls, etc, and test it out on my envirenment. All
together in the past 3 days i spent perhaps a total of 4 hours running
several code and writing back etc and so far not one really worked.

i know perl well, but your code is a bit out of the ordinary ☺. If
past days have been good experience, i might dive in and study for
fun.

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


Re: Convert '165.0' to int

2011-07-21 Thread Billy Mays

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.


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.


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


Re: Convert '165.0' to int

2011-07-21 Thread Grant Edwards
On 2011-07-21, Web Dreamer webdrea...@nospam.fr wrote:
 Leo Jay a ?crit ce jeudi 21 juillet 2011 11:47 dans 

 int(x.split('.')[0])

 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.

Nobody said that close as possible to the original float value was
the goal.  Perhaps the OP just wants it truncated.

-- 
Grant Edwards   grant.b.edwardsYow! OVER the underpass!
  at   UNDER the overpass!
  gmail.comAround the FUTURE and
   BEYOND REPAIR!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a little parsing challenge ☺

2011-07-21 Thread Ian Kelly
On Thu, Jul 21, 2011 at 6:58 AM, Xah Lee xah...@gmail.com wrote:
 Thanks a lot for the fix Raymond.

That fix was from Thomas Jollans, not Raymond Hettinger.

 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.)

Previously you wrote:

 If a file has mismatched matching-pairs, the script will display the
 file name, and the  line number and column number of the first
 instance where a mismatched bracket occures. (or, just the char number
 instead (as in emacs's “point”))

I submit that as the file contains no mismatched brackets (only an
orphan bracket), the output is correct to specification (indeed you
did not define any output for this case), if not necessarily useful.

In other words, stop being picky.  You may be willing to spend an hour
or moe on this, but that doesn't mean anybody else is.  Raymond gave
you a basically working Python solution, but forgot one detail.
Thomas fixed that detail for you but didn't invest the time to rewrite
somebody else's function to get the output correct.  Continuing to
harp on it at this point is verging on trolling.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2011-07-21 Thread Kevin Walzer

On 7/20/11 9:05 AM, rantingrick wrote:

On Jul 19, 9:44 pm, Kevin Walzerk...@codebykevin.com  wrote:


2. Bloatware. Qt and wxWidgets are C++ application frameworks. (Python
has a standard library!)


Again, so? This isn't applicable to Tk, by the way. It's a GUI toolkit
specifically designed for scripting languages.


Tk is SPECIFICALLY designed for TCL. Tkinter works ONLY by embedding a
TCL interpreter. You statements are misleading.


Of course I know this--I'm one of the core Tcl/Tk developers on my 
platform. :-) My statement was actually based on Mark Lutz's 
characterization in Programming Python, when he defends Tk's inclusion 
in the stdlib (and his own book's extensive focus on it) by observing 
that the toolkit was specifically designed for use with scripting 
languages--Tcl at the start, but also Python, Perl, Ruby...he seemed to 
want to downplay Tk's Tcl-ish roots, as if he were embarassed by them. I 
guess it's a Tcl-ish subject.




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.


Again, so? Again, this isn't applicable to Tk.


He did not even mention Tk in that block, do you have a TK persecution
complex?


No, but it's an advantage that Tk has over the other ones, and an 
argument that reinventing the wheel is unncessary.





4. They might look bad (Tkinter, Swing with Jython).


Then again, they might not.  A lot depends on the skill of the
developer. I write highly polished commercial apps with Tk GUI's. I'm
sick of developers blaming their ugly apps on the toolkit rather than
their own lack of design training and/or skills.


This is true. Lots of people lack the skill to create professional
quality GUI applications however lots of GUI devs lack the skill to
create clean and intuitive API's also. Tkinter/TclTk and WxPython
\WxWidgets has lots of warts in this respect.


I think what constitutes a clean API is partly a matter of taste.




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.)


That's right. People issue a clarion call for a new GUI toolkit, then
discover that even a so-called ugly, limited, minimalist toolkit like
Tk has twenty years of development behind it. And people think they can
duplicate this effort in a few months by starting a flame war on
comp.lang.python?


Just because someone wants to entertain ideas for a new GUI does mean
they are starting flame wars. I would say out all the responses so far
YOURS is the most emotional.


*shrug*

Maybe it is. I prefaced this by saying, OK, I'll bite, which suggests 
that perhaps I shouldn't, because complaints and hand-wringing are 
really a waste of time. In the future, I think my response (if I make 
one at all) will more likely be something like this:


An interesting idea. Please post back when you have a source code repo, 
build instructions so we can play with your code, a mailing list, and a 
license that is suitable for both open-source and proprietary development.


The most substantial effort at developing a new GUI API for Python did 
just this--PySide (alternative bindings to Qt). No hand-wringing, no 
flame wars, just an announcement of the project, an invitation to 
contribute, and so on. Whether you think it's a misguided project or an 
attempt to reinvent the wheel is beside the point--it's a substantial 
project, with both leadership and a growing community that support 
ongoing development and rapid maturation.


In my own experience, this is the only way to move things forward or 
bring about any useful change--roll up my sleeves and do it myself. I've 
done this a bit with Tkinter (maintaining bindings/wrappers to a popular 
Tk widget, tablelist), but I've done this extensively with Tk itself on 
the Mac. I complained on mailing lists for years that Tk didn't do this 
or that on the Mac, and these complaints fell on deaf ears; finally, I 
decided to dive into the deep end, learn the low-level API's to do what 
I wanted, and bingo! Suddenly Tk did what I wanted.


That's the essence of open-source development--scratching your own itch. 
Sometimes you get lucky and a large corporate entity has an itch to 
scratch, and this can bring large-scale projects with large-scale 
benefits. I believe Nokia is funding PySide. While Tk's port to the 
Mac's Cocoa API was done by a single developer, the project was funded 
by Apple. Creating a new GUI toolkit may require this scale of effort 
and investment. But even without it, if a developer can get something 
started and make enough progress to be of interest to others, then a 
larger community may move the project forward.


Code trumps everything.




1. Lean and mean -- do nothing but GUI. No database API, networking
API, threading API, etc.


Presenting...Tk.



Re: a little parsing challenge ☺

2011-07-21 Thread Xah Lee
Ok. Here's a preliminary report.

〈Lisp, Python, Perl, Ruby … Code to Validate Matching Brackets〉
http://xahlee.org/comp/validate_matching_brackets.html

it's taking too much time to go thru.

right now, i consider only one valid code, by Raymond Hettinger (with
minor edit from others).

right now, there's 2 other possible correct solution. One by Robert
Klemme but requires ruby19 but i only have ruby18x. One by Thomas
Jollans in Python 3 but didn't run on my machine perhaps due to some
unix/Windows issue, yet to be done.

the other 3 or 4 seems to be incomplete or just suggestion of ideas.

i haven't done extensive testing on my own code neither.
I'll revisit maybe in a few days.

Feel free to grab my report and make it nice. If you would like to fix
your code, feel free to email.

 Xah

On Jul 21, 7:26 am, Ian Kelly ian.g.ke...@gmail.com wrote:
 On Thu, Jul 21, 2011 at 6:58 AM, Xah Lee xah...@gmail.com wrote:
  Thanks a lot for the fix Raymond.

 That fix was from Thomas Jollans, not Raymond Hettinger.

  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.)
 Previously you wrote:
  If a file has mismatched matching-pairs, the script will display the
  file name, and the  line number and column number of the first
  instance where a mismatched bracket occures. (or, just the char number
  instead (as in emacs's “point”))

 I submit that as the file contains no mismatched brackets (only an
 orphan bracket), the output is correct to specification (indeed you
 did not define any output for this case), if not necessarily useful.

 In other words, stop being picky.  You may be willing to spend an hour
 or moe on this, but that doesn't mean anybody else is.  Raymond gave
 you a basically working Python solution, but forgot one detail.
 Thomas fixed that detail for you but didn't invest the time to rewrite
 somebody else's function to get the output correct.  Continuing to
 harp on it at this point is verging on trolling.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a little parsing challenge ☺

2011-07-21 Thread python
Xah,

1. Is the following string considered legal?

[ { ( ] ) }

Note: Each type of brace opens and closes in the proper sequence. But
inter-brace opening and closing does not make sense.

Or must a closing brace always balance out with the most recent opening
brace like so?

[ { ( ) } ]

2. If there are multiple unclosed braces at EOF, is the answer you're
looking for the position of the first open brace that hasn't been closed
out yet?

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


Scikits.timeseries for 2.7

2011-07-21 Thread JB
I'm currently using python 2.7, with numpy and scipy already
installed, but I can't seem to install Scikits.timeseries. I've
downloaded the windows installer from sourceforge, but when I run it,
it checks for a 2.6 installation, and obviously doesn't find the 2.7
folder. Anyone know of a 2.7 installer?

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


Can someone help please

2011-07-21 Thread Gary

Hi
Can someone help me with this code below please,
For some reason it will not send me the first text file in the directory.
I made up an empty file a.txt file with nothing on it and it sends the 
files i need but would like to fix the code.

Thanks




total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
for i in os.listdir('.'):
  if '.txt' in i:
f = open(i, 'r')
total += f.read()
f.close()
message = \
Subject: %s
%s

% (SUBJECT,total)

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


Re: Can someone help please

2011-07-21 Thread woooee
On Jul 21, 10:02 am, Gary woody...@sky.com wrote:
 For some reason it will not send me the first text file in the directory.

You have to print an unsorted list of the directory to know the name
or the first file in the directory.  Files are not stored on disk in
alphabetical order, but are many times sorted in alphabetical name
order by a program that lists the directory.  Note that if you want
the first file alphabetically, you can sort the list returned by
listdir() and then look for the first .txt file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can someone help please

2011-07-21 Thread Billy Mays

On 07/21/2011 01:02 PM, Gary wrote:

Hi
Can someone help me with this code below please,
For some reason it will not send me the first text file in the directory.
I made up an empty file a.txt file with nothing on it and it sends the
files i need but would like to fix the code.
Thanks




total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
for i in os.listdir('.'):
if '.txt' in i:
f = open(i, 'r')
total += f.read()
f.close()
message = \
Subject: %s
%s

% (SUBJECT,total)



Does the file end with '.TXT' ? This might help:

total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
txts = (nm for nm in os.listdir('.') if nm.lower().endswith('.txt') )
for nm in txts:
f = open(nm, 'r')
total += f.readlines()
f.close()
message = \
Subject: %s
%s

% (SUBJECT,total)




I also changed read to readlines().
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can someone help please

2011-07-21 Thread Gary Herron

On 07/21/2011 10:02 AM, Gary wrote:

Hi
Can someone help me with this code below please,
For some reason it will not send me the first text file in the directory.
I made up an empty file a.txt file with nothing on it and it sends the 
files i need but would like to fix the code.

Thanks




total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
for i in os.listdir('.'):
  if '.txt' in i:
f = open(i, 'r')
total += f.read()
f.close()
message = \
Subject: %s
%s

% (SUBJECT,total)



Huh?  Confused I am.  If your first file is empty and you concatenate 
the contents of each file (that's what total+=f.read() does), then what 
do you expect to see?   If you concatenate nothing (that is, the empty 
file), then you should see nothing.   I see no problem with the code, 
but perhaps a problem with your expectations.


If I've misunderstood your question, the please reword and resend it, 
but this time include more information:  The files in '.', their 
content, the output you do get, and the output you expected.


Gary Herron


--
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


Re: Scikits.timeseries for 2.7

2011-07-21 Thread Vlastimil Brom
2011/7/21 JB jamie_brews...@hotmail.com:
 I'm currently using python 2.7, with numpy and scipy already
 installed, but I can't seem to install Scikits.timeseries. I've
 downloaded the windows installer from sourceforge, but when I run it,
 it checks for a 2.6 installation, and obviously doesn't find the 2.7
 folder. Anyone know of a 2.7 installer?

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


Hi,
it appears, you can use the universal source installer:
scikits.timeseries-0.91.3.tar.gz
from
http://sourceforge.net/projects/pytseries/files/scikits.timeseries/0.91.3/

setuptools seems to be  required for installation of this package:
http://pypi.python.org/pypi/setuptools

After installing that, just unpack the archive
scikits.timeseries-0.91.3.tar.gz

and call the contained setup.py with your python 2.7 with the parameter: install

setup.py install
(assuming you are in the appropriate directory like:
C:\install\scikits.timeseries-0.91.3\
and python27 is associated as the default python interpreter;
otherwise the full paths should be specified.

I am not able to test the functionality on py27, but at least import,
help(...) and some basic stuff do work :-)

hth,
  vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can someone help please

2011-07-21 Thread Gary Herron

On 07/21/2011 10:23 AM, Billy Mays wrote:

On 07/21/2011 01:02 PM, Gary wrote:

Hi
Can someone help me with this code below please,
For some reason it will not send me the first text file in the 
directory.

I made up an empty file a.txt file with nothing on it and it sends the
files i need but would like to fix the code.
Thanks




total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
for i in os.listdir('.'):
if '.txt' in i:
f = open(i, 'r')
total += f.read()
f.close()
message = \
Subject: %s
%s

% (SUBJECT,total)



Does the file end with '.TXT' ? This might help:

total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
txts = (nm for nm in os.listdir('.') if nm.lower().endswith('.txt') )
for nm in txts:
f = open(nm, 'r')
total += f.readlines()
f.close()
message = \
Subject: %s
%s

% (SUBJECT,total)




I also changed read to readlines().
That won't work (You must not have even tried to run this.)  The call 
f.readlines() returns a list which causes an error when added to a string:


TypeError: cannot concatenate 'str' and 'list' objects


Gary Herron



--
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

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


Re: Can someone help please

2011-07-21 Thread Gary Wood
Hi
Thanks for your reply's
and sorry guys for not explaining properly
ok the problem with the code, which i never realised before, is it sends the
first txt file as the header or subject field in an email and the rest in
the body of the email which i don't want. I would like all the txt files in
the body of an email
Thanks



On Thu, Jul 21, 2011 at 6:23 PM, Billy Mays 
81282ed9a88799d21e77957df2d84bd6514d9...@myhashismyemail.com wrote:

 On 07/21/2011 01:02 PM, Gary wrote:

 Hi
 Can someone help me with this code below please,
 For some reason it will not send me the first text file in the directory.
 I made up an empty file a.txt file with nothing on it and it sends the
 files i need but would like to fix the code.
 Thanks




 total = ' '
 os.chdir('/home/woodygar/**Desktop/Docs')
 for i in os.listdir('.'):
 if '.txt' in i:
 f = open(i, 'r')
 total += f.read()
 f.close()
 message = \
 Subject: %s
 %s

 % (SUBJECT,total)


 Does the file end with '.TXT' ? This might help:


 total = ' '
 os.chdir('/home/woodygar/**Desktop/Docs')
 txts = (nm for nm in os.listdir('.') if nm.lower().endswith('.txt') )
 for nm in txts:
f = open(nm, 'r')
total += f.readlines()

f.close()
 message = \
 Subject: %s
 %s

 % (SUBJECT,total)




 I also changed read to readlines().

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

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


PEP 8 and extraneous whitespace

2011-07-21 Thread Andrew Berg
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160

I found a couple things that I think should be tweaked in PEP 8. I don't
agree with everything in PEP 8, but I'm not going to debate /those/
points; rather I'm bringing up a couple examples that violate PEP 8, but
don't apply to the reasons given for their violation. In PEP 8, it says
to avoid extraneous whitespace. For example, this is bad (example taken
from PEP 8):
if x == 4 : print x , y ; x , y = y , x
No need for the extra spaces. But, it makes sense to have extra
whitespace when aligning items in say, a dictionary assignment:
categories = {
'main'   : Category(),
'input'  : Category(),
'avs': Category(),
'ffmpeg' : Category(),
'video'  : Category(),
'audio'  : Category(),
'x264'   : Category()
}

PEP8 makes no mention of dictionary assignments, which leads me to think
this was an oversight.

Another example, this time with commas:
self.x264_cmd = (
self.x264_exe,  self.avs_file,
'--fps',self.fpsr,
'--sar',self.sar,
'--crf',self.crf,
'--level',  self.level,
'--keyint', self.ki,
'--min-keyint', self.minki,
'--ref',self.ref,
'--weightp',self.weightp,
'--bframes',self.bframes,
'--b-adapt',self.badapt,
'--me', self.me,
'--merange',self.merange,
'--direct', self.direct,
'--trellis',self.trellis,
'--subme',  self.subme,
'--deblock',self.deblock,
'--output', self.video_output
)
Looks nice all lined up, but it violates PEP 8 because of those extra
spaces, which is only because extra spaces look bad in one-line
assignments that have nothing to do with lists/tuples or dictionaries.
This is one of those times not to follow PEP 8 to the letter, but it
does trip up checker programs (which are useful for catching silly
things like an extra space at the end of a line or missing spaces around
operators). Thoughts?

- -- 
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAwAGBQJOKGcEAAoJEPiOA0Bgp4/LNMUH/AgHv4tPn24jDd2pvaessK0U
DkTS3PSWIwKHmlelzYrFxkhS46TDmCrczlx7W+lWkl6vtS74efu+ENrrUUAo+IfL
nEo9IqcS4E6vtiEvBL6Wxbw246NwVJdEUWKme/axYzEsma9wApnGnn0NiXEc8+bL
ufR/HGxIxkRMXPwCv6B6wm+HRvdLsuwq5L+ajpn74hc2NlmCjlDzRBRiccb8kamI
wKeRR6Eq9GoJHVqHS5IyBeik8Zx6L117wX7Id0SCjik9JXVdY4rN6GSRfQlW8Yq5
qw9CKHH3MgYUCw/u0JrBajDRGnXod9WRq12M4tzllqAKIWLWW7yNDQvPfChe2ss=
=yBf+
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can someone help please

2011-07-21 Thread Billy Mays

On 07/21/2011 01:41 PM, Gary Herron wrote:

On 07/21/2011 10:23 AM, Billy Mays wrote:

On 07/21/2011 01:02 PM, Gary wrote:

Hi
Can someone help me with this code below please,
For some reason it will not send me the first text file in the
directory.
I made up an empty file a.txt file with nothing on it and it sends the
files i need but would like to fix the code.
Thanks




total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
for i in os.listdir('.'):
if '.txt' in i:
f = open(i, 'r')
total += f.read()
f.close()
message = \
Subject: %s
%s

% (SUBJECT,total)



Does the file end with '.TXT' ? This might help:

total = ' '
os.chdir('/home/woodygar/Desktop/Docs')
txts = (nm for nm in os.listdir('.') if nm.lower().endswith('.txt') )
for nm in txts:
f = open(nm, 'r')
total += f.readlines()
f.close()
message = \
Subject: %s
%s

% (SUBJECT,total)




I also changed read to readlines().

That won't work (You must not have even tried to run this.) The call
f.readlines() returns a list which causes an error when added to a string:

TypeError: cannot concatenate 'str' and 'list' objects


Gary Herron





You're right, I didn't.  But thats not really the important part of the 
code.  I believe the generator should work, (and in fact, should 
probably use os.path.walk instead of os.listdir )


--
Bill

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


Re: Can someone help please

2011-07-21 Thread D'Arcy J.M. Cain
On Thu, 21 Jul 2011 18:43:48 +0100
Gary Wood python...@sky.com wrote:
 Hi
 Thanks for your reply's
 and sorry guys for not explaining properly
 ok the problem with the code, which i never realised before, is it sends the
 first txt file as the header or subject field in an email and the rest in
 the body of the email which i don't want. I would like all the txt files in
 the body of an email

  total = ' '

Change this to:
  total = '\n'

You just need a blank line between the headers and the body of the email
message.

-- 
D'Arcy J.M. Cain da...@druid.net |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Thomas Jollans
On 21/07/11 19:51, Andrew Berg wrote:
 Looks nice all lined up, but it violates PEP 8 because of those extra
 spaces, which is only because extra spaces look bad in one-line
 assignments that have nothing to do with lists/tuples or dictionaries.
 This is one of those times not to follow PEP 8 to the letter, but it
 does trip up checker programs (which are useful for catching silly
 things like an extra space at the end of a line or missing spaces around
 operators). Thoughts?
 

Read the PEP properly. Specifically this bit:


-  More than one space around an assignment (or other) operator to
   align it with another.
 
   Yes:
 
   x = 1
   y = 2
   long_variable = 3
 
   No:
 
   x = 1
   y = 2
   long_variable = 3


So, the PEP says: do not align operators. End of story.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Andrew Berg
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160

On 2011.07.21 01:32 PM, Thomas Jollans wrote:
 So, the PEP says: do not align operators. End of story.
I'm pretty sure that colons, commas and equals signs are not operators.

- -- 
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAwAGBQJOKHQGAAoJEPiOA0Bgp4/LouMH/3sufiaJiwrD10eVsUlA4rZ0
XpHnXPOl8WY8C1Qv4OFmg2bN5Qd2S5qEhLgwoUDuZVInx8BAN5IPjIms5YQzgyD5
2PWntkPbxyiV+LfZXwKNPuCW4U4WDMznNThdZz3eUVruBkq6PZMv4yqL7XcZLx5T
KQG+MNkOxGCXk6ZnNgWHGm2eGP01wAmZyvuB16vifVblH6Gk0Uq1FKjReVsszAI5
updUNgpPMskN9c3N8eU+vrHI839G7yPKtujEZ0LCO2552Ogn4vIsWR+Ir0FBLzcB
EBqDzZRmEcCyHobeaLaBZ2qI3OpsF/CTVzx92gqfmf2qhwiSZUFrVqWdmLVhgQc=
=P7QL
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Brandon Harris
I don't really think lining things up makes them any easier to read. In 
fact, the consistency in a single space on either side of an operator 
keeps things neat and clean. Also easier to maintain in any editor. 
Always lining up columns of stuff requires readjusting text every time 
you add a new longer variable and you can never be consistent in how 
much whitespace is there.


Brandon L. Harris


On 07/21/2011 01:46 PM, Andrew Berg wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160

On 2011.07.21 01:32 PM, Thomas Jollans wrote:

So, the PEP says: do not align operators. End of story.

I'm pretty sure that colons, commas and equals signs are not operators.

- -- 
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0

PGP/GPG Public Key ID: 0xF88E034060A78FCB
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAwAGBQJOKHQGAAoJEPiOA0Bgp4/LouMH/3sufiaJiwrD10eVsUlA4rZ0
XpHnXPOl8WY8C1Qv4OFmg2bN5Qd2S5qEhLgwoUDuZVInx8BAN5IPjIms5YQzgyD5
2PWntkPbxyiV+LfZXwKNPuCW4U4WDMznNThdZz3eUVruBkq6PZMv4yqL7XcZLx5T
KQG+MNkOxGCXk6ZnNgWHGm2eGP01wAmZyvuB16vifVblH6Gk0Uq1FKjReVsszAI5
updUNgpPMskN9c3N8eU+vrHI839G7yPKtujEZ0LCO2552Ogn4vIsWR+Ir0FBLzcB
EBqDzZRmEcCyHobeaLaBZ2qI3OpsF/CTVzx92gqfmf2qhwiSZUFrVqWdmLVhgQc=
=P7QL
-END PGP SIGNATURE-


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


Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Neil Cerutti
On 2011-07-21, Brandon Harris brandon.har...@reelfx.com wrote:
 I don't really think lining things up makes them any easier to
 read. In fact, the consistency in a single space on either side
 of an operator keeps things neat and clean. Also easier to
 maintain in any editor. Always lining up columns of stuff
 requires readjusting text every time you add a new longer
 variable and you can never be consistent in how much whitespace
 is there.

Agreed.

##-**-##-**-##-**-##-**-##-**-##-**-##-**-##-**-##
#   The temptation to make code look cutesy  #   
# and ornate is a huge time-waster if#
#   you let it get the best of you.  #
##-**-##-**-##-**-##-**-##-**-##-**-##-**-##-**-##

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


Re: a little parsing challenge ☺

2011-07-21 Thread Xah Lee

On Jul 21, 9:43 am, pyt...@bdurham.com wrote:
 Xah,

 1. Is the following string considered legal?

 [ { ( ] ) }

 Note: Each type of brace opens and closes in the proper sequence. But
 inter-brace opening and closing does not make sense.

nu!

 Or must a closing brace always balance out with the most recent opening
 brace like so?

 [ { ( ) } ]

yeah!

 2. If there are multiple unclosed braces at EOF, is the answer you're
 looking for the position of the first open brace that hasn't been closed
 out yet?

well, as many pointed out, i really haven't thought it out well.

originally, i just want to know the position of a un-matched char.

i haven't taken the time to think about what really should be the
desired behavior. For me, the problem started because i wanted to use
the script to check my 5k html files, in particular, classic novels
that involves double curly quotes and french quotes. So, the desired
behavior is one based on the question of what would best for the user
to see in order to correct a bracket mismatch error in a file. (which,
can get quite complex for nested syntax, because, usually, once you
have one missed, it's all hell from there. I think this is similar to
the problem when a compiler/interpreter encounters a bad syntax in
source code, and thus the poplar situation where error code of
computer programs are hard to understand...)

but anyway, just for this exercise, the requirement needn't be
stringent. I still think that at least the reported position should be
a matching char in the file. (and if we presume this, then only my
code works. LOL)

PS this is a warmup problem for writing a HTML tag validator. I looked
high and lo in past years, but just couldn't find a script that does
simple validation in batch. The w3c one is based on SGML, really huge
amount of un-unstandable irregular historical baggage. XML lexical
validator is much closer, but still not regular. I simply wanted one
just like the match-pair validator in our problem, except the opening
char is not a single char but string of the form xyz … and the
*matching* closing one is of the form /xyz, and with just one
exception: when a tag has “/” in ending such as br/ then it is
skipped (i.e. not considered as opening or closing).

I'll be writing this soon in elisp… since i haven't studied parsers, i
had hopes that parser expert would show some proper parser solutions…
in particular i think such can be expressed in Parsing Expression
Grammar in just a few lines… but so far no deity came forward to show
the light. lol

getting ranty… it's funny, somehow the tech geekers all want regex to
solve the problem. Regex, regex, regex, a 40 years old deviant bastard
that by some twist of luck became a tool for matching text patterns.
One bloke came forward to show-off a perl regex obfuscation. That's
like, lol. But it might be good for the lulz if his code is actually
complete and worked. Then, you have a few who'd nonchalantly remark
“O, you just need push-down automata”. LOL, unless they show actual
working code, its Automata their asses.

folks, don't get angry with me. I'm a learner. I'm curious. I always
am eager to learn. And there's always things we can learn. Don't get
into a fit and do the troll dance in a pit with me. Nobody's gonna
give a shit if you think u knew it all. If u are not the master of one
thousand and one languages yet, you can learn with me. ☺ troll

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


Re: Convert '165.0' to int

2011-07-21 Thread Terry Reedy

On 7/21/2011 10:13 AM, Grant Edwards wrote:

On 2011-07-21, Web Dreamerwebdrea...@nospam.fr  wrote:

Leo Jay a ?crit ce jeudi 21 juillet 2011 11:47 dans



int(x.split('.')[0])

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.


Nobody said that close as possible to the original float value was
the goal.  Perhaps the OP just wants it truncated.


The OP did not specify the domain of possible inputs nor the desired 
output for all possible inputs. Without that, function design is 
guessing. The appropriate response to the original post would have been 
a request for clarification.


If the domain is strings with and int followed by '.0', then chopping 
off two chars is sufficient. This was sort of implied by the original 
post, since it was the only example, and assumed by the respondant.


If the domain is int literals followed by '.' and some number of zeroes, 
then split works. So does int(float(s)). Split also works for non-digits 
following '.' whereas int(float(s)) does not.


If the domain is all float literals, then ??.

--
Terry Jan Reedy

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


Re: PEP 8 and extraneous whitespace

2011-07-21 Thread rantingrick
On Jul 21, 1:46 pm, Andrew Berg bahamutzero8...@gmail.com wrote:
 [snip PGP noise!]
 On 2011.07.21 01:32 PM, Thomas Jollans wrote:
 So, the PEP says: do not align operators. End of story.

 I'm pretty sure that colons, commas and equals signs are not operators.

'au contraire mon frere'.

Colons in a dictionary are assignment operators! The colon tells
Python to assign a value to a key. Likewise for commas which separate
values in containers. And of all things; YES, an equals sign IS most
assuredly an assignment operator.

 [snip MORE PGP noise!]

Lining up columns the way you propose is a major headache; as has been
pointed out. And i find it much less readable myself. Consistency is
the Key; remember? Consistency is not just a singular term applied
only to intelligent agents; no! It can just as well apply to
collective behavior consistency.

The fact remains: the chances of scanning across an empty void and
finding the correct row diminish exponentially by the the width of
said void (amount of space between columns)


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


Re: PEP 8 and extraneous whitespace

2011-07-21 Thread bruno.desthuilli...@gmail.com
On 21 juil, 20:46, Andrew Berg bahamutzero8...@gmail.com wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: RIPEMD160

 On 2011.07.21 01:32 PM, Thomas Jollans wrote: So, the PEP says: do not align 
 operators. End of story.

 I'm pretty sure that colons, commas and equals signs are not operators.


1/ you can consider the equal sign ('=') is the binding operator.

2/ since {'key':'val'} is equivalent to dict(key=val), you can
consider colons as a binding operator here

3/ since it's the comma - not the parens - that makes a tuple, ie t =
1, 2 is equivalent to t = (1,2), you can also consider commas as an
operator here ;)

FWIW: I'm pretty anal when it comes to code formatting and coding
conventions (rationale : don't make me think), and I do agree with
pep8: consistent spacing between tokens is much more readable than
aligned stuff. And it's way less painfull to maintain...


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


Re: Crazy what-if idea for function/method calling syntax

2011-07-21 Thread ΤΖΩΤΖΙΟΥ
Thanks for your input, everyone.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a little parsing challenge ☺

2011-07-21 Thread Rouslan Korneychuk

On 07/21/2011 09:23 AM, Xah Lee wrote:

Thanks for the code.

are you willing to make it complete and standalone? i.e. i can run it
like this:

perl Rouslan_Korneychuk.pl dirPath

and it prints any file that has mismatched pair and line/column number
or the char position?



Since you asked, I put up a complete program at http://pastebin.com/d8GNL0kx

I don't know if it will run on Perl earlier than version 5.10 and I'm 
pretty sure it wont run below version 5.8.


Also, I realized that I had completely neglected the case of a closing 
bracket that is never opened (e.g. stuff] stuff). The program I put on 
paste bin has an updated regex that handles this case.

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


// about building python //

2011-07-21 Thread victor lucio
Hi All,

I'd like to embbed a thin python in one application of mine i'm developing
so I need to know the module dependencies because I'm going to remove some
modules.
I also need to know the best way to rebuild the python core once these
modules have been removed.

So, could you provide me some pointers in the right direction?

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


tab completion

2011-07-21 Thread Chess Club
Could someone help me change the tab completion setting in iPython on
a Windows machine? I would like it to cycle through the available
completions

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


Re: a little parsing challenge ☺

2011-07-21 Thread Terry Reedy

On 7/21/2011 2:53 PM, Xah Lee wrote:


had hopes that parser expert would show some proper parser solutions…
in particular i think such can be expressed in Parsing Expression
Grammar in just a few lines… but so far no deity came forward to show
the light. lol


I am not a parser expert but 20 years ago, I wrote a program in C to 
analyze C programs for proper fence matching. My motivation was the 
often obsurity of parser error messages derived from mis-matched fences. 
I just found the printed copy and an article I wrote but did not get 
published.


Balance.c matches tokens, not characters (and hence can deal with /* and 
*/). It properly takes into account allowed nestings. For C, {[]} is 
legal, [{}] is not. Ditto for () instead of []. Nothing nests within '', 
, and /* */. (I know some C compilers do nest /* */, but not the ones 
I used).


I initially started with a recursive descent parser but 1) this 
hard-coded the rules for one language and make changes difficult and 2) 
made the low-level parsing difficult. So I switched to a table-driven 
recursive state/action machine. The tables for your challenge would be 
much simpler as you did not specify any nesting rules, although they 
would be needed for html checking.


A key point that simplifies things a bit is that every file is 
surrounded by an unwritten BOF-EOF pair. So the machine starts with 
having 'seen' BOF and is 'looking' for EOF. So it is always looking to 
match *something*.


The total program is nearly four pages, but one page is mostly 
declarations and command-line processing, another two pages have 
typedefs, #DEFINEs, and tables. The actual main loop is about 25 lines, 
and 10 lines of that is error reporting. The output is lines with file 
name, row and columns of the two tokens matched (optional) or 
mismatched, and what the two tokens are.


Since this program would be a useful example for my book, both 
didactically and practically, I will try to brush-up a bit on C and 
translate it to Python. I will use the re module for some of the 
low-level token parsing, like C multibyte characters. I will then change 
to tables for Python and perhaps for your challenge.


The current program assumes ascii byte input at it uses an array of 
length 128 to classify ascii chars into 14 classes: 13 special for the 
matching and 1 'normal' class for everything else. This could be 
replaced in Python with a dict 'special' that only maps special 
characters to their token class and used as special.get(char, NORMAL) 
so that the thousands of normal characters are mapped by default to 
NORMAL without a humongous array.


--
Terry Jan Reedy


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


Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Terry Reedy

On 7/21/2011 2:46 PM, Andrew Berg wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160

On 2011.07.21 01:32 PM, Thomas Jollans wrote:

So, the PEP says: do not align operators. End of story.

I'm pretty sure that colons, commas and equals signs are not operators.


Whether or not they are intended, the rationale is that lining up does 
not work with proportional fonts. However, I have IDLE using fixed-space 
font and I line things up how I want. PEP 8 only applies to new stdlib 
code. For anything else, it is advisory on a point by point basis.


--
Terry Jan Reedy

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


Re: // about building python //

2011-07-21 Thread Thomas Jollans
On 22/07/11 00:13, victor lucio wrote:
 Hi All,
 
 I'd like to embbed a thin python in one application of mine i'm
 developing so I need to know the module dependencies because I'm going
 to remove some modules.
 I also need to know the best way to rebuild the python core once these
 modules have been removed.
 
 So, could you provide me some pointers in the right direction?
 
 Thanks in advance...
 

Well, get the source from www.python.org. There's a README in the source
tree that will tell you how to build.
If you're using Windows, you'll need Visual Studio 2008. The free
Express Edition of Visual C++ will do.

As for modules: you (should) know which modules your application uses. A
trial-and-error approach should get you to a bare minimum quickly. (You
know, remove everything you don't know is needed, try it out, put back
modules you're missing, repeat)

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


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

2011-07-21 Thread Gregory Ewing

sturlamolden wrote:


Or should modern deskop apps be written with something completely
different, such as HTML5?


I hope not! HTML is great for web pages, but not
everything should be a web page.

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


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

2011-07-21 Thread Gregory Ewing

Andrew Berg wrote:


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


I think that's a bit of an exaggeration -- there's only
one major dependency on each platform, and it's a very
widely used one (currently PyObjC/PyGTK/PyWin32). And
I'm thinking about ways to reduce the dependencies further,

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


Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Roy Smith
In article mailman.1336.1311288320.1164.python-l...@python.org,
 Terry Reedy tjre...@udel.edu wrote:

 Whether or not they are intended, the rationale is that lining up does 
 not work with proportional fonts.

There are very few things I am absolutely religious about, but 
programming in a fixed width font is one of them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Dan Sommers
On Thu, 21 Jul 2011 13:28:52 -0700, bruno.desthuilli...@gmail.com wrote:

 1/ you can consider the equal sign ('=') is the binding operator.
 
 2/ since {'key':'val'} is equivalent to dict(key=val), you can consider
 colons as a binding operator here

But PEP 8 (under Other Recommendations) indicates spaces around the 
former but not the latter:

key = val
dict(key=val)

We all know that there should be one-- and preferably only one --obvious 
way to do it.  But what do we also know about foolish consistency?

Dan

-- 
Dan Sommers   A death spiral goes clock-
http://www.tombstonezero.net/dan/   wise north of the equator.
Atoms are not things. -- Werner Heisenberg  -- Dilbert's PHB
-- 
http://mail.python.org/mailman/listinfo/python-list


WindowsError: exception: access violation

2011-07-21 Thread Sathish S
Hi Ppl,

 I have been trying to call a C DLL built in GCC with cygwin and Eclipse IDE
from python. Since this DLL was built using cygwin it had the following two
DLL's as dependency. cygwin1.dll and cyggcc_s-1.dll

I'm calling the cygwin_dll_init method in the cygwin1.dll before accessing
my DLL. When I call one of the methods within my DLL I get the WindowsError:
exception: access violation... error

the functions prototype is like: int function(char *, char *) I'm calling
the function as: DLL = cdll.LoadLibrary (DLL_NAME) print
DLL.function(c_char_p(string1),c_char_p(string2))

This error is not consistent with all the stations. I occurs consistently in
many XP machines, while in Windows 7, this occurs once in a while. In Win 7
in starts up a Pythonw.exe process when calling function successfully. I'm
not sure why this error occurs. Any help ??

Thanks,

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


Re: turtles slowing down

2011-07-21 Thread Lee Harr

  there
 was a steady slowing down of turtles as time goes

The problem is that when the turtle draws it does not
just put marks on the canvas, it actually creates new
canvas items.

Canvas items aren't just pixels on the canvas, they are
full-fledged objects which (if you wanted to) you could
get a handle on and move around on the canvas, raise
up above other items, change the color of, etc.

Even if you are just drawing back and forth over the
same line repeatedly, each time you go fd() with the
pen down you are making more and more items on
the canvas. It needs to keep track of those, and that
is what slows it down.

Try adding b1.penup() right after creating the Ball
and you will see your times will remain constant.


I have the same situation in pynguin, the turtle graphics
application that I maintain (pynguin.googlecode.com)

One of my todo items is to make it so that occasionally
those canvas items get painted down on to the canvas
and then deleted.

Having the items around is useful (it makes undo much
easier, for instance) but the slowdown on long-running
programs is a definite problem.

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


Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Thomas 'PointedEars' Lahn
Dan Sommers wrote:

 bruno.desthuilli...@gmail.com wrote:
 1/ you can consider the equal sign ('=') is the binding operator.
 
 2/ since {'key':'val'} is equivalent to dict(key=val), you can consider
 colons as a binding operator here
 
 But PEP 8 (under Other Recommendations) indicates spaces around the
 former but not the latter:
 
 key = val
 dict(key=val)
 
 We all know that there should be one-- and preferably only one --obvious
 way to do it.  But what do we also know about foolish consistency?

I do not know what you *think* we all know, and I do not quite see your 
point. 

I for one have pondered this question and have found the suggestion in the 
PEP a reasonable one, for if you use a function call in the RHS of an 
assignment the lack of whitespace around the equals sign for the keyword 
argument makes it easier to see the final assignment:

  d = dict(key=val)

vs.

  d = dict(key = val)

vs.

  d = key = val

YMMV.

-- 
PointedEars

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


Re: WindowsError: exception: access violation

2011-07-21 Thread Benjamin Kaplan
On Thu, Jul 21, 2011 at 6:42 PM, Sathish S sath...@solitontech.com wrote:
 Hi Ppl,

  I have been trying to call a C DLL built in GCC with cygwin and Eclipse IDE
 from python. Since this DLL was built using cygwin it had the following two
 DLL's as dependency. cygwin1.dll and cyggcc_s-1.dll

 I'm calling the cygwin_dll_init method in the cygwin1.dll before accessing
 my DLL. When I call one of the methods within my DLL I get the WindowsError:
 exception: access violation... error

 the functions prototype is like: int function(char *, char *) I'm calling
 the function as: DLL = cdll.LoadLibrary (DLL_NAME) print
 DLL.function(c_char_p(string1),c_char_p(string2))

 This error is not consistent with all the stations. I occurs consistently in
 many XP machines, while in Windows 7, this occurs once in a while. In Win 7
 in starts up a Pythonw.exe process when calling function successfully. I'm
 not sure why this error occurs. Any help ??


An access violation is what is usually referred to as a seg fault. It
means something isn't getting initialized properly. Are you using a
Cygwin build of Python? Trying to mix Cygwin with normal Windows
programs doesn't usually work very well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert '165.0' to int

2011-07-21 Thread Thomas 'PointedEars' Lahn
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.)
 
 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.

-- 
PointedEars

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


Re: A little complex usage of Beautiful Soup Parsing Help!

2011-07-21 Thread Thomas 'PointedEars' Lahn
SAKTHEESH wrote:

 I am using Beautiful Soup to parse a html to find all text that is Not
 contained inside any anchor elements
 
 I came up with this code which finds all links within href 

_anchors_ _with_ `href' _attribute_ (commonly: links.)

 but not the other way around.

What would that be anyway?

 How can I modify this code to get only plain text using Beautiful
 Soup, so that I can do some find and replace and modify the soup?

RTFM: 
http://www.crummy.com/software/BeautifulSoup/documentation.html#contents

-- 
PointedEars

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


reportlab import error after dundled using py2exe

2011-07-21 Thread SANKAR .
Hi all,

I bundled a small script written in python using py2exe. The script uses
many packages and one of them is  reportlab.
After bundling using py2exe  I tried to run the exe file and it is
returning following error:

C:\Python26\distDELchek.exe
Traceback (most recent call last):
File DELchek.py, line 12, in module
File reportlab\pdfgen\canvas.pyc, line 25, in 
File reportlab\pdfbase\pdfdoc.pyc, line 22, in
File reportlab\pdfbase\pdfmetrics.pyc, line 23,
File reportlab\pdfbase\_fontdata.pyc, line 158,
ImportError: No module named _fontdata_enc_winansi

But I could see the '_fontdata_enc_winansi' module in reportlab folder.
Could someone help me to fix this.

Your help is much appreciated.

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


Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Ed Leafe
Religious fervor is one thing; freedom of religion is another!  ;-)

We strive for readability in our code, yet every printed material designed to 
be read, such as books, newspapers, etc., uses a proportional font. I switched 
to proportional fonts years ago, and am only reluctantly using fixed width 
because of vim. It doesn't take as long to get used to as you might think. 

-- Ed

Sent from my iPhone, so please excuse any top-posting.

On Jul 21, 2011, at 8:12 PM, Roy Smith r...@panix.com wrote:

 There are very few things I am absolutely religious about, but 
 programming in a fixed width font is one of them.

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


[PyWart 1001] Inconsistencies between zipfile and tarfile APIs

2011-07-21 Thread rantingrick

I may have found the mother of all inconsitency warts when comparing
the zipfile and tarfile modules. Not only are the API's different, but
the entry and exits are differnet AND zipfile/tarfile do not behave
like proper file objects should.

 import zipfile, tarfile
 import os
 os.path.exists('C:\\zip.zip')
True
 os.path.exists('C:\\tar.tar')
True
 tarfile.is_tarfile('C:\\tar.tar')
True
 zipfile.is_zipfile('C:\\zip.zip')
True
 ZIP_PATH = 'C:\\zip.zip'
 TAR_PATH = 'C:\\tar.tar'

--
1. Zipfile and tarfile entry exit.
--
 zf = zipfile.open(ZIP_PATH)

Traceback (most recent call last):
  File pyshell#12, line 1, in module
zf = zipfile.open(ZIP_PATH)
AttributeError: 'module' object has no attribute 'open'
 tf = tarfile.open(TAR_PATH)
 tf
tarfile.TarFile object at 0x02B3B850
 tf.close()
 tf
tarfile.TarFile object at 0x02B3B850

*COMMENT*
As you can see, the tarfile modules exports an open function and
zipfile does not. Actually i would prefer that neither export an open
function and instead only expose a class for instantion.

*COMMENT*
Since a zipfile object is a file object then asking for the tf object
after the object after the file is closed should show a proper
message!

 tf = tarfile.TarFile(TAR_PATH)
Traceback (most recent call last):
  File pyshell#72, line 1, in module
tf = tarfile.TarFile(TAR_PATH)
  File C:\Python27\lib\tarfile.py, line 1572, in __init__
self.firstmember = self.next()
  File C:\Python27\lib\tarfile.py, line 2335, in next
raise ReadError(str(e))
ReadError: invalid header
 tf = tarfile.TarFile.open(TAR_PATH)
 tf
tarfile.TarFile object at 0x02C251D0
 tf.fp
Traceback (most recent call last):
  File pyshell#75, line 1, in module
tf.fp
AttributeError: 'TarFile' object has no attribute 'fp'
 tf
tarfile.TarFile object at 0x02C251D0
 tf.close()
 tf
tarfile.TarFile object at 0x02C251D0
 tf.fileobj
bz2.BZ2File object at 0x02C24458
 tf.closed
True

*COMMENT*
Tarfile is missing the attribute fp and instead exposes a boolean
closed. This mismatching API is asinine! Both tarfile and zipfile
should behave EXACTLY like file objects

 f = open('C:\\text.txt', 'r')
 f.read()
''
 f
open file 'C:\text.txt', mode 'r' at 0x02B26F98
 f.close()
 f
closed file 'C:\text.txt', mode 'r' at 0x02B26F98

--
2. Zipfile SPECIFIC entry exit
--
 zf
zipfile.ZipFile instance at 0x02B2C6E8
 zf.fp
 zf = zipfile.ZipFile(ZIP_PATH)
 zf
zipfile.ZipFile instance at 0x02B720A8
 zf.fp
open file 'C:\zip.zip', mode 'rb' at 0x02B26F98
 zf.close()
 zf
zipfile.ZipFile instance at 0x02B720A8
 zf.fp
 print repr(zf.fp)
None

*COMMENT*
As you can see, unlike tarfile zipfile cannot handle a passed path.

--
 3. Zipfile and Tarfile obj API differences.
--

zf.namelist() - tf.getnames()
zf.getinfo(name) - tf.getmenber(name)
zf.infolist() - tf.getmembers()
zf.printdir() - tf.list()

*COMMENT*
Would it have been too difficult to make these names match? Really?

--
 4. Zipfile and Tarfile infoobj API differences.
--

zInfo.filename - tInfo.name
zInfo.file_size - tInfo.size
zInfo.date_time - tInfo.mtime

*COMMENT*
Note the inconsistencies in naming conventions of the zipinfo methods.

*COMMENT*
Not only is modified time named different between zipinfo and tarinfo,
they even return completely different values of time.

--
 Conclusion:
--
It is very obvious that these modules need some consistency between
not only themselves but also collectively. People, when emulating a
file type always be sure to emulate the built-in python file type as
closely as possible.

PS: I will be posting more warts very soon. This stdlib is a gawd
awful mess!
-- 
http://mail.python.org/mailman/listinfo/python-list


[PyWart 1001] Inconsistencies between zipfile and tarfile APIs

2011-07-21 Thread rantingrick

I may have found the mother of all inconsitency warts when comparing
the zipfile and tarfile modules. Not only are the API's different, but
the entry and exits are differnet AND zipfile/tarfile do not behave
like proper file objects should.

 import zipfile, tarfile
 import os
 os.path.exists('C:\\zip.zip')
True
 os.path.exists('C:\\tar.tar')
True
 tarfile.is_tarfile('C:\\tar.tar')
True
 zipfile.is_zipfile('C:\\zip.zip')
True
 ZIP_PATH = 'C:\\zip.zip'
 TAR_PATH = 'C:\\tar.tar'

--
1. Zipfile and tarfile entry exit.
--
 zf = zipfile.open(ZIP_PATH)

Traceback (most recent call last):
  File pyshell#12, line 1, in module
zf = zipfile.open(ZIP_PATH)
AttributeError: 'module' object has no attribute 'open'
 tf = tarfile.open(TAR_PATH)
 tf
tarfile.TarFile object at 0x02B3B850
 tf.close()
 tf
tarfile.TarFile object at 0x02B3B850

*COMMENT*
As you can see, the tarfile modules exports an open function and
zipfile does not. Actually i would prefer that neither export an open
function and instead only expose a class for instantion.

*COMMENT*
Since a zipfile object is a file object then asking for the tf object
after the object after the file is closed should show a proper
message!

 tf = tarfile.TarFile(TAR_PATH)
Traceback (most recent call last):
  File pyshell#72, line 1, in module
tf = tarfile.TarFile(TAR_PATH)
  File C:\Python27\lib\tarfile.py, line 1572, in __init__
self.firstmember = self.next()
  File C:\Python27\lib\tarfile.py, line 2335, in next
raise ReadError(str(e))
ReadError: invalid header
 tf = tarfile.TarFile.open(TAR_PATH)
 tf
tarfile.TarFile object at 0x02C251D0
 tf.fp
Traceback (most recent call last):
  File pyshell#75, line 1, in module
tf.fp
AttributeError: 'TarFile' object has no attribute 'fp'
 tf
tarfile.TarFile object at 0x02C251D0
 tf.close()
 tf
tarfile.TarFile object at 0x02C251D0
 tf.fileobj
bz2.BZ2File object at 0x02C24458
 tf.closed
True

*COMMENT*
Tarfile is missing the attribute fp and instead exposes a boolean
closed. This mismatching API is asinine! Both tarfile and zipfile
should behave EXACTLY like file objects

 f = open('C:\\text.txt', 'r')
 f.read()
''
 f
open file 'C:\text.txt', mode 'r' at 0x02B26F98
 f.close()
 f
closed file 'C:\text.txt', mode 'r' at 0x02B26F98

--
2. Zipfile SPECIFIC entry exit
--
 zf
zipfile.ZipFile instance at 0x02B2C6E8
 zf.fp
 zf = zipfile.ZipFile(ZIP_PATH)
 zf
zipfile.ZipFile instance at 0x02B720A8
 zf.fp
open file 'C:\zip.zip', mode 'rb' at 0x02B26F98
 zf.close()
 zf
zipfile.ZipFile instance at 0x02B720A8
 zf.fp
 print repr(zf.fp)
None

*COMMENT*
As you can see, unlike tarfile zipfile cannot handle a passed path.

--
 3. Zipfile and Tarfile obj API differences.
--

zf.namelist() - tf.getnames()
zf.getinfo(name) - tf.getmenber(name)
zf.infolist() - tf.getmembers()
zf.printdir() - tf.list()

*COMMENT*
Would it have been too difficult to make these names match? Really?

--
 4. Zipfile and Tarfile infoobj API differences.
--

zInfo.filename - tInfo.name
zInfo.file_size - tInfo.size
zInfo.date_time - tInfo.mtime

*COMMENT*
Note the inconsistencies in naming conventions of the zipinfo methods.

*COMMENT*
Not only is modified time named different between zipinfo and tarinfo,
they even return completely different values of time.

--
 Conclusion:
--
It is very obvious that these modules need some consistency between
not only themselves but also collectively. People, when emulating a
file type always be sure to emulate the built-in python file type as
closely as possible.

PS: I will be posting more warts very soon. This stdlib is a gawd
awful mess!
-- 
http://mail.python.org/mailman/listinfo/python-list


[PyWart 1001] Inconsistencies between zipfile and tarfile APIs

2011-07-21 Thread rantingrick

I may have found the mother of all inconsitency warts when comparing
the zipfile and tarfile modules. Not only are the API's different, but
the entry and exits are differnet AND zipfile/tarfile do not behave
like proper file objects should.

 import zipfile, tarfile
 import os
 os.path.exists('C:\\zip.zip')
True
 os.path.exists('C:\\tar.tar')
True
 tarfile.is_tarfile('C:\\tar.tar')
True
 zipfile.is_zipfile('C:\\zip.zip')
True
 ZIP_PATH = 'C:\\zip.zip'
 TAR_PATH = 'C:\\tar.tar'

--
1. Zipfile and tarfile entry exit.
--
 zf = zipfile.open(ZIP_PATH)

Traceback (most recent call last):
  File pyshell#12, line 1, in module
zf = zipfile.open(ZIP_PATH)
AttributeError: 'module' object has no attribute 'open'
 tf = tarfile.open(TAR_PATH)
 tf
tarfile.TarFile object at 0x02B3B850
 tf.close()
 tf
tarfile.TarFile object at 0x02B3B850

*COMMENT*
As you can see, the tarfile modules exports an open function and
zipfile does not. Actually i would prefer that neither export an open
function and instead only expose a class for instantion.

*COMMENT*
Since a zipfile object is a file object then asking for the tf object
after the object after the file is closed should show a proper
message!

 tf = tarfile.TarFile(TAR_PATH)
Traceback (most recent call last):
  File pyshell#72, line 1, in module
tf = tarfile.TarFile(TAR_PATH)
  File C:\Python27\lib\tarfile.py, line 1572, in __init__
self.firstmember = self.next()
  File C:\Python27\lib\tarfile.py, line 2335, in next
raise ReadError(str(e))
ReadError: invalid header
 tf = tarfile.TarFile.open(TAR_PATH)
 tf
tarfile.TarFile object at 0x02C251D0
 tf.fp
Traceback (most recent call last):
  File pyshell#75, line 1, in module
tf.fp
AttributeError: 'TarFile' object has no attribute 'fp'
 tf
tarfile.TarFile object at 0x02C251D0
 tf.close()
 tf
tarfile.TarFile object at 0x02C251D0
 tf.fileobj
bz2.BZ2File object at 0x02C24458
 tf.closed
True

*COMMENT*
Tarfile is missing the attribute fp and instead exposes a boolean
closed. This mismatching API is asinine! Both tarfile and zipfile
should behave EXACTLY like file objects

 f = open('C:\\text.txt', 'r')
 f.read()
''
 f
open file 'C:\text.txt', mode 'r' at 0x02B26F98
 f.close()
 f
closed file 'C:\text.txt', mode 'r' at 0x02B26F98

--
2. Zipfile SPECIFIC entry exit
--
 zf
zipfile.ZipFile instance at 0x02B2C6E8
 zf.fp
 zf = zipfile.ZipFile(ZIP_PATH)
 zf
zipfile.ZipFile instance at 0x02B720A8
 zf.fp
open file 'C:\zip.zip', mode 'rb' at 0x02B26F98
 zf.close()
 zf
zipfile.ZipFile instance at 0x02B720A8
 zf.fp
 print repr(zf.fp)
None

*COMMENT*
As you can see, unlike tarfile zipfile cannot handle a passed path.

--
 3. Zipfile and Tarfile obj API differences.
--

zf.namelist() - tf.getnames()
zf.getinfo(name) - tf.getmenber(name)
zf.infolist() - tf.getmembers()
zf.printdir() - tf.list()

*COMMENT*
Would it have been too difficult to make these names match? Really?

--
 4. Zipfile and Tarfile infoobj API differences.
--

zInfo.filename - tInfo.name
zInfo.file_size - tInfo.size
zInfo.date_time - tInfo.mtime

*COMMENT*
Note the inconsistencies in naming conventions of the zipinfo methods.

*COMMENT*
Not only is modified time named different between zipinfo and tarinfo,
they even return completely different values of time.

--
 Conclusion:
--
It is very obvious that these modules need some consistency between
not only themselves but also collectively. People, when emulating a
file type always be sure to emulate the built-in python file type as
closely as possible.

PS: I will be posting more warts very soon. This stdlib is a gawd
awful mess!
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Game Programming Challenge 13 (September 2011) is coming!

2011-07-21 Thread Richard Jones
The 13th Python Game Programming Challenge (PyWeek) is coming. It'll
run from the 11th to the 18th of September.

The PyWeek challenge:

- Invites entrants to write a game in one week from scratch either as
an individual or in a team,
- Is intended to be challenging and fun,
- Will hopefully increase the public body of game tools, code and expertise,
- Will let a lot of people actually finish a game, and
- May inspire new projects (with ready made teams!)


   Richard
   http://pyweek.org/13/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [PyWart 1001] Inconsistencies between zipfile and tarfile APIs

2011-07-21 Thread Corey Richardson
Excerpts from rantingrick's message of Thu Jul 21 23:46:05 -0400 2011:
 
 I may have found the mother of all inconsitency warts when comparing
 the zipfile and tarfile modules. Not only are the API's different, but
 the entry and exits are differnet AND zipfile/tarfile do not behave
 like proper file objects should.
 

I agree, actually.
-- 
Corey Richardson
  Those who deny freedom to others, deserve it not for themselves
 -- Abraham Lincoln


signature.asc
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WindowsError: exception: access violation

2011-07-21 Thread Sathish S
Benjamin thanks for replying. i'm not using the python that comes with
cygwin. Its the regular python 2.7.2
To add more info
I'm opening up a zip file within the DLL. The zip file is located in the
same directory.
arg1 is the file name
arg2 is zip password

Thanks,
Sathish


On Fri, Jul 22, 2011 at 7:47 AM, Benjamin Kaplan
benjamin.kap...@case.eduwrote:

 On Thu, Jul 21, 2011 at 6:42 PM, Sathish S sath...@solitontech.com
 wrote:
  Hi Ppl,
 
   I have been trying to call a C DLL built in GCC with cygwin and Eclipse
 IDE
  from python. Since this DLL was built using cygwin it had the following
 two
  DLL's as dependency. cygwin1.dll and cyggcc_s-1.dll
 
  I'm calling the cygwin_dll_init method in the cygwin1.dll before
 accessing
  my DLL. When I call one of the methods within my DLL I get the
 WindowsError:
  exception: access violation... error
 
  the functions prototype is like: int function(char *, char *) I'm calling
  the function as: DLL = cdll.LoadLibrary (DLL_NAME) print
  DLL.function(c_char_p(string1),c_char_p(string2))
 
  This error is not consistent with all the stations. I occurs consistently
 in
  many XP machines, while in Windows 7, this occurs once in a while. In Win
 7
  in starts up a Pythonw.exe process when calling function successfully.
 I'm
  not sure why this error occurs. Any help ??
 

 An access violation is what is usually referred to as a seg fault. It
 means something isn't getting initialized properly. Are you using a
 Cygwin build of Python? Trying to mix Cygwin with normal Windows
 programs doesn't usually work very well.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Convert '165.0' to int

2011-07-21 Thread Billy Mays

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.




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?

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


Re: Inconsistencies between zipfile and tarfile APIs

2011-07-21 Thread rantingrick
On Jul 21, 11:13 pm, Corey Richardson kb1...@aim.com wrote:
 Excerpts from rantingrick's message of Thu Jul 21 23:46:05 -0400 2011:

  I may have found the mother of all inconsitency warts when comparing
  the zipfile and tarfile modules. Not only are the API's different, but
  the entry and exits are differnet AND zipfile/tarfile do not behave
  like proper file objects should.

 I agree, actually.

Unfortunately i know what the powers that be are going to say about
fixing this wart.

PTB: Sorry we cannot break backwards compatibility
Rick: But what about Python 3000?
PTB:  Oh, well, umm, lets see. Well that was then and this is now!

Maybe i can offer a solution. A NEW module called archive.py (could
even be a package!) which exports both the zip and tar file classes.
However, unlike the current situation this archive module will be
consistent with it's API.

 from archive import ZipFile, TarFile
 zf = ZipFile(path, *args)
 tf = TarFile(path, *args)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inconsistencies between zipfile and tarfile APIs

2011-07-21 Thread Corey Richardson
Excerpts from rantingrick's message of Fri Jul 22 00:48:37 -0400 2011:
 On Jul 21, 11:13pm, Corey Richardson kb1...@aim.com wrote:
  I agree, actually.
 
 
 Maybe i can offer a solution. A NEW module called archive.py (could
 even be a package!) which exports both the zip and tar file classes.
 However, unlike the current situation this archive module will be
 consistent with it's API.
 
  from archive import ZipFile, TarFile
  zf = ZipFile(path, *args)
  tf = TarFile(path, *args)

I have nothing to do this weekend, I might as well either write my own or
twist around the existing implementations in the hg repo.
-- 
Corey Richardson
  Those who deny freedom to others, deserve it not for themselves
 -- Abraham Lincoln


signature.asc
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inconsistencies between zipfile and tarfile APIs

2011-07-21 Thread Terry Reedy

On 7/22/2011 12:48 AM, rantingrick wrote:

On Jul 21, 11:13 pm, Corey Richardsonkb1...@aim.com  wrote:

Excerpts from rantingrick's message of Thu Jul 21 23:46:05 -0400 2011:


I may have found the mother of all inconsitency warts when comparing
the zipfile and tarfile modules. Not only are the API's different, but
the entry and exits are differnet AND zipfile/tarfile do not behave
like proper file objects should.


I agree, actually.


Hmm. Archives are more like directories than files. Windows, at least, 
seems to partly treat zipfiles as more or less as such. Certainly, 7zip 
present a directory interface. So opening a zipfile/tarfile would be 
like opening a directory, which we normally do not do. On the other 
hand, I am not sure I like python's interface to directories that much.


It would be more sensible to open files within the archives. Certainly, 
it would be nice to have the result act like file objects as much as 
possible.


Seaching open issues for 'tarfile' or 'zipfile' returns about 40 issues 
each. So I think some people would care more about fixing bugs than 
adjusting the interfaces. Of course, some of the issues may be about the 
interface and increasing consistency where it can be done without 
compatibility issues. However, I do not think there are any active 
developers focued on those two modules.



Unfortunately i know what the powers that be are going to say about
fixing this wart.

PTB: Sorry we cannot break backwards compatibility


Do you propose we break compatibility more than we do? You are not the 
only Python ranter. People at Google march into Guido's office to 
complain instead of posting here.



Rick: But what about Python 3000?
PTB:  Oh, well, umm, lets see. Well that was then and this is now!


The changes made for 3.0 were more than enough for some people to 
discourage migration to Py3. And we *have* made additional changes 
since. So the resistance to incompatible feature changes has increased.



Maybe i can offer a solution. A NEW module called archive.py (could
even be a package!) which exports both the zip and tar file classes.
However, unlike the current situation this archive module will be
consistent with it's API.


from archive import ZipFile, TarFile
zf = ZipFile(path, *args)
tf = TarFile(path, *args)


Not a bad idea. Put it on PyPI and see how much support you can get.

--
Terry Jan Reedy

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


Re: Inconsistencies between zipfile and tarfile APIs

2011-07-21 Thread Ryan Kelly
On Fri, 2011-07-22 at 01:45 -0400, Terry Reedy wrote:
 On 7/22/2011 12:48 AM, rantingrick wrote:
  On Jul 21, 11:13 pm, Corey Richardsonkb1...@aim.com  wrote:
  Excerpts from rantingrick's message of Thu Jul 21 23:46:05 -0400 2011:
 
  I may have found the mother of all inconsitency warts when comparing
  the zipfile and tarfile modules. Not only are the API's different, but
  the entry and exits are differnet AND zipfile/tarfile do not behave
  like proper file objects should.
 
  I agree, actually.
 
 Hmm. Archives are more like directories than files. Windows, at least, 
 seems to partly treat zipfiles as more or less as such. Certainly, 7zip 
 present a directory interface. So opening a zipfile/tarfile would be 
 like opening a directory, which we normally do not do. On the other 
 hand, I am not sure I like python's interface to directories that much.

Indeed.  Actually, I'd say that archives are more like *entire
filesystems* than either files or directories.

We have a pretty nice ZipFS implementation as part of the PyFilesystem
project:

  http://packages.python.org/fs/


If anyone cares enough to whip up a TarFS implementation it would be
gratefully merged into trunk.  (There may even be the start of one in
the bugtracker somewhere, I don't recall...)


  Cheers,

Ryan


-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au|  http://www.rfk.id.au/ramblings/gpg/ for details



signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue10271] warnings.showwarning should allow any callable object

2011-07-21 Thread lekma

lekma lekma...@gmail.com added the comment:

Thank you very much for your help

--

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



[issue11629] Reference implementation for PEP 397

2011-07-21 Thread Mark Hammond

Mark Hammond skippy.hamm...@gmail.com added the comment:

The most recent version of PEP397 has removed all mentioned of this reference 
implementation - the C implementation at 
https://bitbucket.org/vinay.sajip/pylauncher/ is now the reference.

--
resolution:  - out of date
status: open - closed

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



[issue11435] Links to source code should now point to hg repo

2011-07-21 Thread Roundup Robot

Roundup Robot devn...@psf.upfronthosting.co.za added the comment:

New changeset 79d2682c4fc5 by Ezio Melotti in branch '3.2':
#11435: link to the correct branch.
http://hg.python.org/cpython/rev/79d2682c4fc5

New changeset 3028b5ab92c0 by Ezio Melotti in branch 'default':
#11435: dummy merge with 3.2.
http://hg.python.org/cpython/rev/3028b5ab92c0

--

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



[issue11435] Links to source code should now point to hg repo

2011-07-21 Thread Ezio Melotti

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

I fixed the URL in 3.2.

 The 2.7 docs link to the Subversion repo.  Can I update them?

2.7 doesn't have the source directive, do you want to replace all the svn links 
manually?
If so, either reopen this issue or create a new one.

--

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



[issue12568] Add functions to get the width in columns of a character

2011-07-21 Thread Ezio Melotti

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


--
nosy: +ezio.melotti

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



[issue6820] Redefinition of HAVE_STRFTIME can cause compiler errors.

2011-07-21 Thread rgpitts

rgpitts richard.pi...@cdl.co.uk added the comment:

As Python 2.6 is now security only and 2.7 is last major release I've patched 
this against Python 3.2 because pyconfig.h hadn't changed much since 2.6.

I've done as Amaury suggested and changed the HAVE_XXX symbols to define 1 like 
autoconf. 'make patchcheck' has fixed some general formatting issues included 
in the patch.

--
keywords: +patch
Added file: http://bugs.python.org/file22710/issue-6820.patch

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



[issue12601] Spelling error in the comments in the webbrowser module.

2011-07-21 Thread maniram maniram

New submission from maniram maniram maniandra...@gmail.com:

At line 235 there is a comment which contains secons which should be changed 
to seconds.

--
components: Library (Lib)
messages: 140793
nosy: maniram.maniram
priority: normal
severity: normal
status: open
title: Spelling error in the comments in the webbrowser module.
versions: Python 3.2

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



[issue12601] Spelling error in the comments in the webbrowser module.

2011-07-21 Thread Roundup Robot

Roundup Robot devn...@psf.upfronthosting.co.za added the comment:

New changeset 3bc80b6f7cd8 by Ezio Melotti in branch '3.2':
#12601: fix typo.
http://hg.python.org/cpython/rev/3bc80b6f7cd8

New changeset d26c7b18fc9d by Ezio Melotti in branch 'default':
#12601: merge with 3.2.
http://hg.python.org/cpython/rev/d26c7b18fc9d

New changeset 0127716200c7 by Ezio Melotti in branch '2.7':
#12601: fix typo.
http://hg.python.org/cpython/rev/0127716200c7

--
nosy: +python-dev

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



[issue12601] Spelling error in the comments in the webbrowser module.

2011-07-21 Thread Ezio Melotti

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

Fixed, thanks for the report!

--
assignee:  - ezio.melotti
nosy: +ezio.melotti
resolution:  - fixed
stage:  - committed/rejected
status: open - closed

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



[issue12590] First line and cursor not visible when opening files

2011-07-21 Thread Tal Einat

Changes by Tal Einat talei...@gmail.com:


--
nosy: +taleinat

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



[issue12266] str.capitalize contradicts oneself

2011-07-21 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

I think it would be better to use this code:

if (!Py_UNICODE_ISUPPER(*s)) {
*s = Py_UNICODE_TOUPPER(*s);
status = 1;
}
s++;
while (--len  0) {
if (Py_UNICODE_ISLOWER(*s)) {
*s = Py_UNICODE_TOLOWER(*s);
status = 1;
}
s++;
}

Since this actually implements what the doc-string says.

Note that title case is not the same as upper case. Title case is
a special case that get's applied when using a string as a title
of a text and may well include characters that are lower case
but which are only used in titles.

--

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



[issue12583] More detailed ImportError messages

2011-07-21 Thread Ram Rachum

Ram Rachum cool...@cool-rr.com added the comment:

Thanks for explaining, I guess it's too complicated.

--

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



[issue12266] str.capitalize contradicts oneself

2011-07-21 Thread Ezio Melotti

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

Do you mean  if (!Py_UNICODE_ISLOWER(*s)) {  (with the '!')?

This sounds fine to me, but with this approach all the uncased characters will 
go through a Py_UNICODE_TO* macro, whereas with the current code only the cased 
ones are converted.  I'm not sure this matters too much though.

OTOH if the non-lowercase cased chars are always either upper or titlecased, 
checking for both should be equivalent.

--

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



[issue12266] str.capitalize contradicts oneself

2011-07-21 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

Ezio Melotti wrote:
 
 Ezio Melotti ezio.melo...@gmail.com added the comment:
 
 Do you mean  if (!Py_UNICODE_ISLOWER(*s)) {  (with the '!')?

Sorry, here's the correct version:

if (!Py_UNICODE_ISUPPER(*s)) {
*s = Py_UNICODE_TOUPPER(*s);
status = 1;
}
s++;
while (--len  0) {
if (!Py_UNICODE_ISLOWER(*s)) {
*s = Py_UNICODE_TOLOWER(*s);
status = 1;
}
s++;
}

 This sounds fine to me, but with this approach all the uncased characters 
 will go through a Py_UNICODE_TO* macro, whereas with the current code only 
 the cased ones are converted.  I'm not sure this matters too much though.
 
 OTOH if the non-lowercase cased chars are always either upper or titlecased, 
 checking for both should be equivalent.

AFAIK, there are characters that don't have a case mapping at all.
It may also be the case, that a non-cased character still has a
lower/upper case mapping, e.g. for typographical reasons.

Someone would have to check this against the current Unicode database.

--

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



[issue12601] Spelling error in the comments in the webbrowser module.

2011-07-21 Thread maniram maniram

maniram maniram maniandra...@gmail.com added the comment:

Thanks for the fast response.

--

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



[issue12326] Linux 3: tests should avoid using sys.platform == 'linux2'

2011-07-21 Thread maniram maniram

maniram maniram maniandra...@gmail.com added the comment:

It seems currently that in python 3.2 sys.platform is linux2 even though it is 
running linux 3

--
nosy: +maniram.maniram

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



[issue12326] Linux 3: tests should avoid using sys.platform == 'linux2'

2011-07-21 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

 It seems currently that in python 3.2 sys.platform is linux2
 even though it is running linux 3

It's maybe because you ran ./configure with Linux 2.x.y (see msg138254). Try 
make distclean  ./configure --with-debug  make.

--

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



[issue11669] Clarify Lang Ref Compound statements footnote

2011-07-21 Thread Ezio Melotti

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


--
nosy: +ncoghlan

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



[issue12589] test_long.test_nan_inf() failed on OpenBSD (powerpc)

2011-07-21 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@haypocalc.com:


--
nosy: +mark.dickinson

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



[issue12589] test_long.test_nan_inf() failed on OpenBSD (powerpc)

2011-07-21 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

Is HAVE_DECL_ISINF defined in pyconfig.h? PyLong_FromDouble() uses 
Py_IS_INFINITY(x):
--
/* Py_IS_INFINITY(X)
 * Return 1 if float or double arg is an infinity, else 0.
 * Caution:
 *X is evaluated more than once.
 *This implementation may set the underflow flag if |X| is very small;
 *it really can't be implemented correctly ( easily) before C99.
 *Override in pyconfig.h if you have a better spelling on your platform.
 *  Py_FORCE_DOUBLE is used to avoid getting false negatives from a
 *non-infinite value v sitting in an 80-bit x87 register such that
 *v becomes infinite when spilled from the register to 64-bit memory.
 * Note: PC/pyconfig.h defines Py_IS_INFINITY as _isinf
 */
#ifndef Py_IS_INFINITY
#  if defined HAVE_DECL_ISINF  HAVE_DECL_ISINF == 1
#define Py_IS_INFINITY(X) isinf(X)
#  else
#define Py_IS_INFINITY(X) ((X)\
   (Py_FORCE_DOUBLE(X)*0.5 == Py_FORCE_DOUBLE(X)))
#  endif
#endif
--

main() in Modules/python.c starts with:
--
/* 754 requires that FP exceptions run in no stop mode by default,
 * and until C vendors implement C99's ways to control FP exceptions,
 * Python requires non-stop mode.  Alas, some platforms enable FP
 * exceptions by default.  Here we disable them.
 */
#ifdef __FreeBSD__
fp_except_t m;

m = fpgetmask();
fpsetmask(m  ~FP_X_OFL);
#endif
--

You may try to enable this code on OpenBSD, replace #ifdef __FreeBSD__ by 
#if 1.

Can you also please try the following code?

$ python
 import struct
 struct.pack(f, float(inf))
b'\x00\x00\x80\x7f'

--

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



[issue12576] urlib.request fails to open some sites

2011-07-21 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@haypocalc.com:


--
nosy: +ezio.melotti

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



[issue7897] Support parametrized tests in unittest

2011-07-21 Thread Michael Foord

Michael Foord mich...@voidspace.org.uk added the comment:

Well, pyflakes will tell you about name clashes within a TestCase (unless 
you're shadowing a test on a base class which I guess is rarely the case)...

When we generate the tests we could add the parameter reprs to the docstring. A 
decorator factor that takes arguments and an optional name builder seem like a 
reasonable api to me.

Actually, name clashes *aren't* a problem - as we're generating TestCase 
instances these generated tests won't shadow existing tests (you'll just have 
two tests with the same name - does this mean id() may not be unique - worth 
checking).

--

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



[issue12556] Disable size checks in mmap.mmap()

2011-07-21 Thread Ross Lagerwall

Ross Lagerwall rosslagerw...@gmail.com added the comment:

 I don't like the idea of adding an argument which doesn't have a
 counterpart in the POSIX version (especially to address such corner
 cases).

Indeed, it seems rather messy for a corner case that may well not exist.

If there are definite cases where this usage is needed, a solution may then 
have to be considered.

--

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



[issue12556] Disable size checks in mmap.mmap()

2011-07-21 Thread Sergei Lebedev

Sergei Lebedev superbo...@gmail.com added the comment:

 Do you have an example of a /proc entry with st_size == 0 that can be mmapped 
 (mapping /proc/sys/debug/exception-trace fails with EACCESS)?
Yes, I've ran into the issue, while trying to mmap /proc/xen/xsd_kva, which is 
an 
interface to XenBus [1]. Unfortunately, I'm not aware of any other cases. 

By the way, I've checked mmap(2) manpage -- it looks like the C-version has 
nothing 
against mmaping 0-sized files, Why does Python's `mmap` still checks file size?

[1] http://wiki.xensource.com/xenwiki/XenBus

--

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



[issue12545] Incorrect handling of return codes in the posix_lseek function in posixmodule.c

2011-07-21 Thread Kuberan Naganathan

Kuberan Naganathan kubi...@gmail.com added the comment:

Hi.  I'm unable ( or have to jump through lots of hoops ) to submit this patch 
myself for regulatory reasons.  Can someone else submit this please?  Thanks.

--

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



[issue12600] Support parameterized TestCases in unittest

2011-07-21 Thread R. David Murray

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

Note that this is fairly simple to do now via subclassing, so any proposed API 
would need to show a clear benefit over that approach to be worth the extra 
complexity in the unittest code base.

--

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



[issue7897] Support parametrized tests in unittest

2011-07-21 Thread Michael Foord

Michael Foord mich...@voidspace.org.uk added the comment:

Note that name clashes *would* result in non-unique testcase ids, so we need to 
prevent that.

--

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



[issue7879] Too narrow platform check in test_datetime

2011-07-21 Thread R. David Murray

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

Please implement name+argtuple first and build auto-naming on top of that.  
Nick's approach would not allow me to specify a custom (hand coded) name for 
each set of arguments, which is my normal use case.  I also would not like the 
arguments auto-generated into the docstring unless that was optional, since I 
often have quite substantial argument tuples and it would just clutter the 
output to have them echoed in the docstring.  In my use cases the custom name 
is more useful than seeing the actual parameters.

--
nosy: +r.david.murray

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



[issue7879] Too narrow platform check in test_datetime

2011-07-21 Thread R. David Murray

Changes by R. David Murray rdmur...@bitdance.com:


--
Removed message: http://bugs.python.org/msg140810

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



[issue7897] Support parametrized tests in unittest

2011-07-21 Thread R. David Murray

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

Please implement name+argtuple first and build auto-naming on top of that.  
Nick's approach would not allow me to specify a custom (hand coded) name for 
each set of arguments, which is my normal use case.  I also would not like the 
arguments auto-generated into the docstring unless that was optional, since I 
often have quite substantial argument tuples and it would just clutter the 
output to have them echoed in the docstring.  In my use cases the custom name 
is more useful than seeing the actual parameters.

--

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



[issue12556] Disable size checks in mmap.mmap()

2011-07-21 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@haypocalc.com:


--
nosy: +haypo

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



[issue12602] Missing using docs cross-references

2011-07-21 Thread Nick Coghlan

New submission from Nick Coghlan ncogh...@gmail.com:

General untidiness in the anchor names (and lack of same for entries like 
script)

Missing incoming:
- from Invoking the Interpreter in the tutorial
- direct link from runpy.run_module to -m switch
- direct link from runpy.run_path to script

Missing outgoing:
- direct link from script to runpy.run_path

Also, zipfile/dir execution was added in 2.6, not 2.5.

--
messages: 140812
nosy: ncoghlan
priority: normal
severity: normal
status: open
title: Missing using docs cross-references

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



[issue12602] Missing using docs cross-references

2011-07-21 Thread Nick Coghlan

Changes by Nick Coghlan ncogh...@gmail.com:


--
assignee:  - docs@python
components: +Documentation
nosy: +docs@python
versions: +Python 2.7, Python 3.2, Python 3.3

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



[issue12394] packaging: generate scripts from callable (dotted paths)

2011-07-21 Thread higery

Changes by higery shoulderhig...@gmail.com:


--
keywords: +patch
Added file: http://bugs.python.org/file22711/6382acfb1685.diff

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



  1   2   >