Category talk:Python: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
No edit summary
Line 1: Line 1:
The upcoming releases of Python 2.6 and Python3 suggest that we should adjust many of the Python code snippets to exemplify the best programming practices that are available in the standard libraries. (We can, of course, leave the most backwards compatible examples as is and merely add the comparison to the simpler code that's available with newer releases).

Some examples that come to mind:
* use ''with'', where appropriate, in place of more explicit ''try''...''finally'' handling; particular to show the built-in support for file closing ad threading lock releases
** show an example of using ''contextlib'' to create object classes the automatically perform their own lock releases and/or transactional commit or rollback when called in a ''with'' structure.
* review all uses of threading for cases that would benefit from the use of the new ''multiprocessing'' to overcome the limitations of the GIL (global interpreter lock) on SMP/NUMA scaling.
** In particular look for cases where ''Pool'' and ''Manager'' objects from ''multiprocessing'' would simplify code examples.
** Look tasks related to distributed processing for examples that readily implemented using ''multiprocessing'' ''Manager'' objects and other 2.6 and Python 3 feaatures.
* Look for examples in which Python's traditional ''%'' string formatting operator can be simplified, clarified or otherwise improved using the new ''format()'' methods on string (''str'') (and Unicode and similar) objects.
** Show and example of how custom classes can implement their own ''__format__()'' special method such that they can be targets of formatting string interpolation directives.
* Consider adding notes to any topics that focus on the use of the traditional '''''print''''' statement that this will be removed from Python3 ... it's slated to become a function (and thus required an argument list as per the normal Python function call syntax). This will probably become one of the most confusing issues for future adopters of Python3 (as it becomes the default) when they're trying to study and adapt from 15 years of Python 2.x examples.
* Similar concerns might be raised about the changes from ''raw_input()'' to simply ''input()'' and the need, in Python3, to call ''eval(input())'' to get the same semantics as the traditional ''input()'' built-in function (in relatively rare cases were the use of the old semantics really was warranted). However most use of the old ''input()'' function was unwarranted.
** Look for cases where the ''ast.literal_eval()'' method would be a more secure or otherwise better alternative to ''eval().''

The gist of all my suggestions is that we want the examples on RosettaCode to be exemplary --- to consistently show the best practices for each language thta we cover. These changes to Python, mostly preparatory to the release of Python3 (a.k.a. Python3000 or Python3k) represent significant advances in the standard libraries ... which should simplify and improve the Python entries for a number of the tasks covered on this site. [[User:JimD|JimD]] 22:50, 8 September 2008 (UTC)


Thanks to the [http://code.google.com/p/google-highly-open-participation-psf/ Google Highly Open Participation contest] for high-school students, Python has passed Perl as the language with the most solutions. Well done! --[[User:IanOsgood|IanOsgood]] 18:33, 28 November 2007 (MST)
Thanks to the [http://code.google.com/p/google-highly-open-participation-psf/ Google Highly Open Participation contest] for high-school students, Python has passed Perl as the language with the most solutions. Well done! --[[User:IanOsgood|IanOsgood]] 18:33, 28 November 2007 (MST)
:Heh. I was browing programming.reddit.com, and saw a request for small Python projects. I sent the guy an email, but didn't find out until today what it was about. You can see part of the email [http://code.google.com/p/google-highly-open-participation-psf/wiki/ProjectSuggestionNotes here]. --[[User:Short Circuit|Short Circuit]] 20:35, 4 December 2007 (MST)
:Heh. I was browing programming.reddit.com, and saw a request for small Python projects. I sent the guy an email, but didn't find out until today what it was about. You can see part of the email [http://code.google.com/p/google-highly-open-participation-psf/wiki/ProjectSuggestionNotes here]. --[[User:Short Circuit|Short Circuit]] 20:35, 4 December 2007 (MST)


Take a look at some of the interesting python code here, it could probably be integrated: [http://pleac.sourceforge.net/pleac_python/fileaccess.html]
Take a look at some of the interesting python code here, it could probably be integrated: [http://pleac.sourceforge.net/pleac_python/fileaccess.html Programming Language Examples Alike Cookbook]
[[User:StaticShock|StaticShock]]
[[User:StaticShock|StaticShock]]

Revision as of 22:50, 8 September 2008

The upcoming releases of Python 2.6 and Python3 suggest that we should adjust many of the Python code snippets to exemplify the best programming practices that are available in the standard libraries. (We can, of course, leave the most backwards compatible examples as is and merely add the comparison to the simpler code that's available with newer releases).

Some examples that come to mind:

  • use with, where appropriate, in place of more explicit try...finally handling; particular to show the built-in support for file closing ad threading lock releases
    • show an example of using contextlib to create object classes the automatically perform their own lock releases and/or transactional commit or rollback when called in a with structure.
  • review all uses of threading for cases that would benefit from the use of the new multiprocessing to overcome the limitations of the GIL (global interpreter lock) on SMP/NUMA scaling.
    • In particular look for cases where Pool and Manager objects from multiprocessing would simplify code examples.
    • Look tasks related to distributed processing for examples that readily implemented using multiprocessing Manager objects and other 2.6 and Python 3 feaatures.
  • Look for examples in which Python's traditional % string formatting operator can be simplified, clarified or otherwise improved using the new format() methods on string (str) (and Unicode and similar) objects.
    • Show and example of how custom classes can implement their own __format__() special method such that they can be targets of formatting string interpolation directives.
  • Consider adding notes to any topics that focus on the use of the traditional print statement that this will be removed from Python3 ... it's slated to become a function (and thus required an argument list as per the normal Python function call syntax). This will probably become one of the most confusing issues for future adopters of Python3 (as it becomes the default) when they're trying to study and adapt from 15 years of Python 2.x examples.
  • Similar concerns might be raised about the changes from raw_input() to simply input() and the need, in Python3, to call eval(input()) to get the same semantics as the traditional input() built-in function (in relatively rare cases were the use of the old semantics really was warranted). However most use of the old input() function was unwarranted.
    • Look for cases where the ast.literal_eval() method would be a more secure or otherwise better alternative to eval().

The gist of all my suggestions is that we want the examples on RosettaCode to be exemplary --- to consistently show the best practices for each language thta we cover. These changes to Python, mostly preparatory to the release of Python3 (a.k.a. Python3000 or Python3k) represent significant advances in the standard libraries ... which should simplify and improve the Python entries for a number of the tasks covered on this site. JimD 22:50, 8 September 2008 (UTC)


Thanks to the Google Highly Open Participation contest for high-school students, Python has passed Perl as the language with the most solutions. Well done! --IanOsgood 18:33, 28 November 2007 (MST)

Heh. I was browing programming.reddit.com, and saw a request for small Python projects. I sent the guy an email, but didn't find out until today what it was about. You can see part of the email here. --Short Circuit 20:35, 4 December 2007 (MST)

Take a look at some of the interesting python code here, it could probably be integrated: Programming Language Examples Alike Cookbook StaticShock