Permalink
Browse files

examples: python: move frequently used imports to the top

  • Loading branch information...
1 parent f509f11 commit ee129e79f6b87419c43e262b8f85c12e5b3343e3 @SaveTheRbtz committed Dec 9, 2012
Showing with 4 additions and 3 deletions.
  1. +4 −3 examples/python_example.py
@@ -3,6 +3,9 @@
# Steve Ivy <steveivy@gmail.com>
# http://monkinetic.com
+from random import random
+from socket import socket, AF_INET, SOCK_DGRAM
+
# Sends statistics to the stats daemon over UDP
class StatsdClient(object):
def __init__(self, host='localhost', port=8125):
@@ -56,14 +59,12 @@ def send(self, data, sample_rate=1):
sampled_data = {}
if (sample_rate < 1):
- import random
- if random.random() <= sample_rate:
+ if random() <= sample_rate:
for stat, value in data.items():
sampled_data[stat] = "%s|@%s" %(value, sample_rate)
else:
sampled_data = data
- from socket import socket, AF_INET, SOCK_DGRAM
udp_sock = socket(AF_INET, SOCK_DGRAM)
try:
for stat, value in sampled_data.items():

0 comments on commit ee129e7

Please sign in to comment.