![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Some interesting stuff has been added.
If you are interested in the changes, got to: http://docs.python.org/dev/whatsnew/whatsnew25.html
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
This is one part they added: http://docs.python.org/dev/whatsnew/node3.html
x = true_value if condition else false_value And what was wrong with: x = (true_value, false_value)[x==False] Geez... |
|
|
|
|
|
#3 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 641
Rep Power: 4
![]() |
A few things are clearly taken from Ruby.
Especially this: http://docs.python.org/dev/whatsnew/node10.html Which are basically copying Ruby blocks: Ruby
File.open("test.txt", 'r') do |file|
#do stuff with file
#automatically closed
endPython in 2.5 with open("test.txt", 'r') as f:
for line in f:
print line
#do stuff with file
#automatically closedBut Ruby has copied plenty of things from Python, so it is not necessarily a bad thing. Just interesting...
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#4 | |
|
Programming Guru
![]() |
Quote:
They also added any() and all(). I still stick with my opinion that it's not only redundant, but slower... # 2.4 "any"
if True in (0, 1, 2, 3, 4):
print "Any"
# 2.5 "any"
if any((0, 1, 2, 3, 4)):
print "Any"
# 2.4 "all"
if not False in (1, 2, 3, 4, 5):
print "All"
# 2.5 "all"
if all((1, 2, 3, 4, 5)):
print "All" |
|
|
|
|
|
|
#5 | ||
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
For instance, the file open code you had in Ruby, would translate to this in Python: def file_stuff(file):
#do stuff with file
#automatically closed
ruby_style_open("test.txt", 'r', file_stuff)file = open("test.txt", 'r')
file.__enter__()
#do stuff with file
#automatically closed
file.__exit__()Quote:
I kind of like these wrappers. In my opinion, they make things a little neater and easier to read: if False not in (x < 10 for x in numbers):
print "All numbers below ten"
if all(x < 10 for x in number):
print "All numbers below ten"![]() |
||
|
|
|
|
|
#6 | |
|
Newbie
Join Date: Feb 2006
Posts: 9
Rep Power: 0
![]() |
Quote:
x = (a, b)[True] # x = b x = (a, b)[False] # x = a The proposed sintax address it making the true value come first. In your example you had to do a NOT(condition) to make it work the same.
__________________
Programming Tutorial for Absolute Beginners |
|
|
|
|
|
|
#7 | |
|
Programming Guru
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|