nghung270192 / colorama

Automatically exported from code.google.com/p/colorama
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Demos not working with Python 2.5 #31

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The following line prevent it from working with 2.5:
from __future__ import print_function

Original issue reported on code.google.com by sorin.sb...@gmail.com on 1 Dec 2011 at 5:49

GoogleCodeExporter commented 9 years ago
Now in order to make it work with 2.5-3.2 you should not use the print 
function, at least not with new parameters.

Original comment by sorin.sb...@gmail.com on 1 Dec 2011 at 5:50

GoogleCodeExporter commented 9 years ago
Here is a patched version.

Original comment by sorin.sb...@gmail.com on 1 Dec 2011 at 5:58

Attachments:

GoogleCodeExporter commented 9 years ago
Hey there! Thanks for the report, and EXTRA thanks for sending a patched 
version.

However, can I be a pain and ask you to indulge me on one or two things?

1) I am very sympathetic to your desire to make it 2.5 compatible, and agree 
that this should be done. However, it crosses my mind that it's a shame that 
the 'demos' directory is the only place this change needs to be made, because 
the demos directory is not needed to use colorama, and of course this directory 
only exists in order to provide clear example usage. Replacing 'print' with 
sys.stdout.write makes the examples just a little bit less clear. So although I 
like your change overall, I also have some reservations about it. Can we 
chat/think about it a bit in case we think of any better solutions?

2) I can see the changes you describe in the 'demos' directory, replacing uses 
of the 'print' function with sys.stdout.write, etc. That all makes sense. 
There's a minor wrinkle of an instance of commenting out the __future__ import 
left over - I'd rather delete it instead.

3) There are other changes to files like winterm.py and ansitowin32.py that I 
don't understand yet. Can you explain what those changes are? Is it some 
fabulous new feature or improved behavior?

4) It's traditional to send patches as the output of a diff or "hg diff" 
command. Although not critical, it helps to make explicit precisely what 
changes you're sending. Also, separate patch files can be sent for each issue, 
for example perhaps a separate patch could be sent for the changes in (3) 
above, so that I can easily apply them as separate commits.

I hope that makes sense. Sorry to be so fussy. Your thoughts very welcome.

Original comment by tart...@gmail.com on 1 Dec 2011 at 10:35

GoogleCodeExporter commented 9 years ago
It crosses my mind that maybe my reservations in (1) above could be addressed 
by keeping the use of the 'print' function, but replacing the __future__ import 
with something like:

  try:
      from __future__ import print_function
  except ImportError:
      def print(text, file=sys.stdout):
          file.write(text)

This could be put into its own file, demos/print_function.py, and then each 
demo could simply go:

  import print_function

  print('hello')
  ...etc

while maintaining compatibility with 2.5, 2.7 and 3.x.

Sound good?

Original comment by tart...@gmail.com on 1 Dec 2011 at 10:40

GoogleCodeExporter commented 9 years ago
you can't do for two resons: 
#1 SyntaxError: from __future__ imports must occur at the beginning of the file 
(try would be the first line)
#2 you cannot redefine print in python 2.5: you'll get SyntaxError: invalid 
syntax.

Sorry, but to keep compatibility with Python 2.5 you need to use 
sys.stdout.write and sys.stderr.write in places where you want not to add the 
newline.

BTW, I will do the required changes and do the testing under Windows.

Original comment by sorin.sb...@gmail.com on 2 Dec 2011 at 2:14

GoogleCodeExporter commented 9 years ago
I cloned colorama and made the modifications. Now I'm not sure if I need to do 
something to push modifications back to colorama main repository or if you need 
to pull them from my clone.

Original comment by sorin.sb...@gmail.com on 2 Dec 2011 at 2:45

GoogleCodeExporter commented 9 years ago
Hey, thanks for the updates. What you say makes sense.

I'm not sure about the push/pull thing either for Hg. Let me go figure it out.

I've got a surprise visitor in town, I'll be a couple of days before I get to 
look at this. Thanks for the updates, your ideas and work are much appreciated.

Original comment by tart...@gmail.com on 2 Dec 2011 at 3:44