Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/scenarios/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ tests (net, CPU) fail, it will send an email.
FROM = "webmaster@your_domain.com"
SUBJECT = "Your domain is out of system resources!"
text = "Go and fix your server!"
BODY = string.join(("From: %s" %FROM,"To: %s" %TO,"Subject: %s" %SUBJECT, "",text), "\r\n")
BODY = "\r\n".join(("From: %s" %FROM,"To: %s" %TO,"Subject: %s" %SUBJECT, "",text))
server = smtplib.SMTP('127.0.0.1')
server.sendmail(FROM, [TO], BODY)
server.quit()
Expand Down
6 changes: 3 additions & 3 deletions docs/scenarios/ml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ We shuffle the Iris dataset and divide it into separate training and testing set
#predictions on the test dataset
pred = clf.predict(x_test)

print pred #predicted labels i.e flower species
print y_test #actual labels
print (accuracy_score(pred, y_test))*100 #prediction accuracy
print(pred) #predicted labels i.e flower species
print(y_test)#actual labels
print(accuracy_score(pred, y_test))*100 #prediction accuracy

Since we're splitting randomly and the classifier trains on every iteration, the accuracy may vary. Running the above code gives:

Expand Down
4 changes: 2 additions & 2 deletions docs/scenarios/scrape.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ Let's see what we got exactly:

.. code-block:: python

print 'Buyers: ', buyers
print 'Prices: ', prices
print('Buyers: ', buyers)
print('Prices: ', prices)

::

Expand Down
6 changes: 4 additions & 2 deletions docs/scenarios/serialization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ The repr method in Python takes a single object parameter and returns a printabl
print(repr(a))

# write content to files using repr
with open('/tmp/file.py') as f:f.write(repr(a))
with open('/tmp/file.py') as f:
f.write(repr(a))


ast.literal_eval
Expand All @@ -83,7 +84,8 @@ Supported data types are: strings, numbers, tuples, lists, dicts, booleans, and

.. code-block:: python

with open('/tmp/file.py', 'r') as f: inp = ast.literal_eval(f.read())
with open('/tmp/file.py', 'r') as f:
inp = ast.literal_eval(f.read())

====================
CSV file (flat data)
Expand Down
14 changes: 7 additions & 7 deletions docs/scenarios/speed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,17 @@ What's the difference in speed? Let's try it!
#primes implemented with Python
import primes

print "Cython:"
print("Cython:")
t1= time.time()
print primesCy.primes(500)
print(primesCy.primes(500))
t2= time.time()
print "Cython time: %s" %(t2-t1)
print ""
print "Python"
print("Cython time: %s" %(t2-t1))
print("")
print("Python")
t1= time.time()
print primes.primes(500)
print(primes.primes(500))
t2= time.time()
print "Python time: %s" %(t2-t1)
print("Python time: %s" %(t2-t1))


These lines both need a remark:
Expand Down
8 changes: 4 additions & 4 deletions docs/writing/structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ compute x + 1, you have to create another integer and give it a name.

my_list = [1, 2, 3]
my_list[0] = 4
print my_list # [4, 2, 3] <- The same list has changed
print(my_list) # [4, 2, 3] <- The same list has changed

x = 6
x = x + 1 # The new x is another object
Expand Down Expand Up @@ -824,7 +824,7 @@ most idiomatic way to do this.
nums = ""
for n in range(20):
nums += str(n) # slow and inefficient
print nums
print(nums)

**Better**

Expand All @@ -834,15 +834,15 @@ most idiomatic way to do this.
nums = []
for n in range(20):
nums.append(str(n))
print "".join(nums) # much more efficient
print("".join(nums)) # much more efficient

**Best**

.. code-block:: python

# create a concatenated string from 0 to 19 (e.g. "012..1819")
nums = [str(n) for n in range(20)]
print "".join(nums)
print("".join(nums))

One final thing to mention about strings is that using ``join()`` is not always
best. In the instances where you are creating a new string from a pre-determined
Expand Down
Loading