Attachment 'pycrust-20060706-1134.py'

Download

   1 PyCrust 0.9.5 - The Flakiest Python Shell
   2 
   3 Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32
   4 
   5 Type "help", "copyright", "credits" or "license" for more information.
   6 
   7 >>> filein=open("dh6180.csv","r")
   8 
   9 >>> fileout=open("out.csv","w")
  10 
  11 >>> while (1):
  12 
  13 ...     a=filein.readline()
  14 
  15 ...     if len(a)==0 : break
  16 
  17 ...     
  18 
  19 >>> a
  20 
  21 ''
  22 
  23 >>> filein.rewind()
  24 
  25 Traceback (most recent call last):
  26 
  27   File "<input>", line 1, in ?
  28 
  29 AttributeError: 'file' object has no attribute 'rewind'
  30 
  31 >>> 
  32 
  33 >>> filein=open("dh6180.csv","r")
  34 
  35 >>> while (1):
  36 
  37 ...     a=filein.readline()
  38 
  39 ...     if len(a)==0 : break
  40 
  41 ...     
  42 
  43 >>> 
  44 
  45 >>> 
  46 
  47 >>> a="10 20 30 40"
  48 
  49 >>> a.split()
  50 
  51 ['10', '20', '30', '40']
  52 
  53 >>> b=[int(i) for i in a.split()]
  54 
  55 >>> b
  56 
  57 [10, 20, 30, 40]
  58 
  59 >>> a="# This is a test"
  60 
  61 >>> b=[int(i) for i in a.split()]
  62 
  63 Traceback (most recent call last):
  64 
  65   File "<input>", line 1, in ?
  66 
  67 ValueError: invalid literal for int(): #
  68 
  69 >>> a="  test\n"
  70 
  71 >>> a
  72 
  73 '  test\n'
  74 
  75 >>> a.strip()
  76 
  77 'test'
  78 
  79 >>> [0]*26
  80 
  81 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  82 
  83 >>> [0 for i in range(26)]
  84 
  85 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  86 
  87 >>> range(26)*0
  88 
  89 []
  90 
  91 >>> ab="abcdefghjiklmnopqrstuvwxyz"
  92 
  93 >>> len(ab)
  94 
  95 26
  96 
  97 >>> ab.index("f")
  98 
  99 5
 100 
 101 >>> ord("f")
 102 
 103 102
 104 
 105 >>> ord("a")
 106 
 107 97
 108 
 109 >>> ord("f")-ord("a")
 110 
 111 5
 112 
 113 >>> ord("1")
 114 
 115 49
 116 
 117 >>> ord("&")
 118 
 119 38
 120 
 121 >>> def countletters(word):
 122 
 123 ...     word=word.lower()
 124 
 125 ...     ret=[0]*26
 126 
 127 ...     for i in word:
 128 
 129 ...         n=ord(i)-97
 130 
 131 ...         if (n>=0 and n<26) : ret[n]+=1
 132 
 133 ...     return ret
 134 
 135 ...     
 136 
 137 >>> countletters("Steve Ludtke")
 138 
 139 [0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2, 1, 1, 0, 0, 0, 0]
 140 
 141 >>> countletters("Steve Ludtke")==countletters("test")
 142 
 143 False
 144 
 145 >>> countletters("Steve Ludtke")==countletters("evets ektdul")
 146 
 147 True
 148 
 149 >>> a=[1,3,4,5]
 150 
 151 >>> b=[1,3,5,6]
 152 
 153 >>> a
 154 
 155 [1, 3, 4, 5]
 156 
 157 >>> b
 158 
 159 [1, 3, 5, 6]
 160 
 161 >>> for i in range(4):
 162 
 163 ...     if a[i]>=b[i] : break
 164 
 165 ...     else: print "ok"
 166 
 167 ...     
 168 
 169 >>> for i in range(4):
 170 
 171 ...     if a[i]>=b[i] : break
 172 
 173 ... else: print "ok"
 174 
 175 ...     
 176 
 177 >>> 
 178 
 179 >>> for i in range(4):
 180 
 181 ...     if a[i]>=b[i] : break
 182 
 183 ... else: print "ok"
 184 
 185 ...     
 186 
 187 >>> for i in range(4):
 188 
 189 ...     if a[i]>b[i] : break
 190 
 191 ... else: print "ok"
 192 
 193 ...     
 194 
 195 ok
 196 
 197 >>> zip(a,b)
 198 
 199 [(1, 1), (3, 3), (4, 5), (5, 6)]
 200 
 201 >>> def countletters(word):
 202 
 203 ...     word=word.lower()
 204 
 205 ...     ret=[0]*26
 206 
 207 ...     for i in word:
 208 
 209 ...         n=ord(i)-97
 210 
 211 ...         if (n>=0 and n<26) : ret[n]+=1
 212 
 213 ...     return ret
 214 
 215 ...     
 216 
 217 >>> filein=open("linux.words","r")
 218 
 219 ... words=filein.readlines()
 220 
 221 ... words=[i.strip() for i in words if len(i)<=len(letters)+1]
 222 
 223 >>> words
 224 
 225 Traceback (most recent call last):
 226 
 227   File "<input>", line 1, in ?
 228 
 229 NameError: name 'words' is not defined
 230 
 231 >>> filein=open("linux.words","r")
 232 
 233 >>> words=filein.readlines()
 234 
 235 >>> 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.