or "license" for more information.
>>>>> import md5
>>>>> pass = md5.new()
>> File "", line 1
>> pass = md5.new()
>> ^
>> SyntaxError: invalid syntax
>
> pass is a keyword, as in:
>
> def f ():
>
Instead, use a compatible character encoding. Note the explicit conversion.
fh.write(line.encode('utf-8'))
Alternatively, you can write sixteen bit unicode directly to a file:
import codecs
f = codecs.open('unicodetest.txt', mode='w', encoding='utf-16&
s two
things. It states what is to be returned by the generator's next() method
and it also defines g as a function that returns a generator.
--
Stephen Fairchild
--
http://mail.python.org/mailman/listinfo/python-list
gt;> this is the resulting output:
>>
>> B [3]
>> B [3, 3]
>> C [3, 3]
>>
>> Why is the B.py executed twice ?
B.py is the entry point of the program and it is known internally as
__main__. There is no record of a B.py.
If you really must import objects from the main module you can do it like
this.
from __main__ import *
--
Stephen Fairchild
--
http://mail.python.org/mailman/listinfo/python-list
must have been imported already
Maybe use in conjunction with python-inotify and or Gamin for change
detection.
--
Stephen Fairchild
--
http://mail.python.org/mailman/listinfo/python-list
ve a
> running sum until the end of file.
Untested:
with open("numbers.txt", "r") as f:
print sum(int(x) for x in f)
--
Stephen Fairchild
--
http://mail.python.org/mailman/listinfo/python-list
; problem as I see is nicely handled in list,
>
> like list_one=["god","earth","sky","cloud","rain"]
> list_one[0]="god"
> list_one[2]="sky"
>
> but can it be for string and file?
It's ea
9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]
cols = zip(*rows)
To just get the second column:
zip(*rows)[1]
--
Stephen Fairchild
--
http://mail.python.org/mailman/listinfo/python-list
ing instance creation with class creation.
--
Stephen Fairchild
--
http://mail.python.org/mailman/listinfo/python-list
in a neat package, set of functions, recipe or pattern.
http://docs.python.org/library/abc.html
In particular, pay attention to the term virtual subclass and also note in
the second code example the use of __subclasshook__ to define virtual
subclass membership by the presence (or not) of class attrib
et Word1
> Word2 Word3. Would also like to handle special characters like '",(){}
> [] etc/
import urllib
print urllib.unquote("Word1%20Word2%20Word3")
--
Stephen Fairchild
--
http://mail.python.org/mailman/listinfo/python-list
...
_classvar = fact(5)
del fact()
--
Stephen Fairchild
--
http://mail.python.org/mailman/listinfo/python-list
Dave Angel wrote:
> With this change the best solution changes from a random shuffle to a
> binary search.
Which is not what the OP asked for. Anyway, I think whatever solution is
chosen it's probably best written as a generator. The new pushback syntax
may prove useful.
--
Stephe
fact(5)})
Demo = Demo()
d = Demo()
print d._classvar# prints 120
print d.fact(7) # prints 5040
print Demo # prints
--
Stephen Fairchild
--
http://mail.python.org/mailman/listinfo/python-list
use random.shuffle() to
> put them in random order and then run through the guesses one at a time.
import random
import time
l = range(1, 10)
while l:
print l.pop(random.randint(0, len(l) - 1))
time.sleep(2)
--
Stephen Fairchild
--
http://mail.python.org/mailman/listinfo/python-list
dexes and what is the syntax?
For the first element:
>>> words[0]
> 2) I just noticed that the first and the last words in the output are
> enclosed in single quotes, and the middle one is enclosed in double
> quotes. Is it a bug? If not, why does the output work that way?
The
fine:
> p1 = lakers[1]
> print p1.kitcolor
>
> # However the following doesn't work:
> lakers.kitcolor = 'blue'
> print p1.kitcolor
>
> #-8<----
I hope this gives you some good ideas.
http://en.wikipedia.org/wiki/Join_(SQL)
I suspect you will be finding a use for the special __getattr__ method,
which is called when an attribute is not found. This can be used to search
on your set of joined objects. Your list of joined objects should be a
set() to prevent duplicates.
--
Stephen Fairchild
--
http://mail.python.org/mailman/listinfo/python-list
17 matches
Mail list logo