alpha() else " " for c in s]
s = ''.join(chars)
words = s.split()
return words
import doctest
doctest.run_docstring_examples(extract_words, globals())
print extract_words("Hello, world! I ate 6 slices of cheese.")
=> prints:
['hello', 'world', 'i', 'ate', 'slices', 'of', 'cheese']
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
ject):
def __init__(self, database_id):
self._info = None
self.database_id = database_id
@property
def info(self):
if self._info is None:
self._info = get_from_database(self.database_id)
return self._info
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
rror:
raise BadStatusLine(line)
> Maybe I could also make the CrontabDoesNotExist exception more useful
> printing a message to inform the user that the crontab does not exist
> for the current user.
The point of specific exception types is to be more speci
at can download
upgrades over the web. Does that make it a web browser? How about curl
or wget?
Many applications can read files remotely over http. Some of them can
follow embedded hyperlinks. Are they web browsers?
--
Steven D'Aprano
___
T
comp.lang.python:
http://mail.python.org/mailman/listinfo/python-list
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
in this case, what you care about is the
interface. You want an object that iterates over "lines", whatever that
happens to be.
Inheritance is useful, but it's just one way of making objects with the
same interface.
--
Steven D'Aprano
ooking at the assignment sheet.
> What am I doing wrong? Can anybody help? D: I need to turn my
> results in to class tomorrow morning!
I hope the above clues will set you on the right track.
We won't do your homework for you, but if you come back with *specific*
questions, we can hel
ot;text = %s" % text
print "findall = %s" % a
print "search = %s" % b
print
def main(text):
"""Print the results of many regex searches on text."""
for i, word in get_dict_words():
a, b, = search(word, text)
print_stuff(i, word, text, a, b)
# Now call it:
fp = open(filename)
text = fp.read()
fp.close()
main(text)
I *think* this should give the same results you got.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
vate method
rather than public. Just remembering that in Python, there's no such
thing as "private", it's just a naming convention.
> The first method seems to me to 'hide' where the variables get set,
Which is another reason to avoid it.
#x27;t want to discourage you, but the sun will burn out
and die long before you get more than a couple of words of Shakespeare
from this technique.
On the other hand, there are ways to randomly generate non-random text
*incredibly quickly*. See http:/
10 items, whichever happens
first.
islice() optionally takes the full set of arguments that ordinary list
slicing takes, so that islice(iterable, start, end, stride) is nearly
the same as list(iterable)[start:end:stride].
--
Steven D'Aprano
me definition of "better":
import random
import functools
coinToss = functools.partial(random.randint, 0, 1)
COUNT = 100
heads = sum(coinToss() for tossNo in range(COUNT))
print "The coin landed on tails %d times." % (COUNT-heads)
print "The coin landed on heads %d
> What went wrong here ?
Read the error message again:
NameError: global name 'element' is not defined
You are trying to use something called "element", but you haven't
created anything with that name. The error message even tells you were
the problem is: line 21, in
match("man", "monabc")
True
>>> match("moon", "monabc")
False
That looks better! It's not the most efficient code in the word, but for
comparing small words and a small set of tiles, it's good enough --
there's no need to optimize the code at this early stage. Get it
working first, then make it fast.
So, putting it back together:
for word in dictionary:
if match(word, tiles):
play_word() # whatever...
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
hat slice indexes fall *between* characters:
A slice of [-1:-4:-1] is equivalent to [3:0:-1].
>>> 'Test'[-1:-4:-1]
'tse'
>>> 'Test'[3:0:-1]
'tse'
So, what does this slice do? The slice indexes are equivalent to:
range(3, 0, -1)
rals
from future_builtins import *
will get you part of the way, but it's probably impossible to get the
two to be *exactly* the same.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
htt
ocs.python.org/library/argparse.html#module-argparse
In my experience, getopt is a gentler introduction to argument parsing,
because it does much less :)
optparse is another good one.
All three are available up to Python 2.7, and possibly in 3.1 as well, I
haven't che
d a.foo.
How does that help you copy from one class to another? As I see it, it
just adds more noise to the class.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
quot;old"
"spam" instead of "ham"
"william" instead of "bill"
Then the caller can either say
import module
module.ham()
or
import other_module
other_module.spam()
--
Steven D'Aprano
___
Tutor maillis
that's a good sign that
it is public not private!
In PRESETS, what's "mothly" mean? *wink*
What happens if I do this?
ct1 = micron.CronTab()
ct2 = micron.CronTab()
ct1.add_job('daily', 'echo "BOOM!"')
ct2.add_job('daily',
k.seq
[]
>>> k.seq.append(1)
>>> k.seq
[1]
Works fine.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
def __init__(self, name, tel, email):
> self.name = name
> self.tel = tel
> self.email = email
> ab = {self.name : self.tel}
> f = file(addressbook, 'r+')
> p.dump(ab, f)
&g
r(), but lots of
objects can do that, not just lists and tuples:
>>> iter("not a list or tuple")
>>> iter({1: None, 2: "a", 4: 5})
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
lpha version,
2.7 should have received a couple of point releases and be well-tested
and stable.
There are many other templating engines for Python-based web apps, such
as CherryPy or Zope, and many more. Before building a huge project,
you're probably better of
the filename to use;
* change the title bar;
* open and display the appropriate image;
* pre-populate any fields;
etc.
Good luck!
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
nyway, be glad this is Python. In a former life, I worked for a company
that had just installed a SAP accounting application. One day the
application crashed, and printed out a stack trace direct to the
printer. It was over fifty pages of tightly-written 9pt font.
Seriously.
We called th
return "spam"
def ham(self):
return "%s is a processed meat-like substance" % self.spam()
it is often better to do this:
class Food(object):
def ham(self):
return "%s is a processed meat-like substance" % spam()
def spam(x):
r
1.0 is not actually needed, but it doesn't hurt.
[thinks more carefully...] Actually it does hurt:
>>> is_integer(Decimal(2))
False
So although you *can* use float and int to determine if a value is an
integer, it's best to avoid the float.
--
Steven D'Aprano
thout* considering that maybe the bug is in *your* code,
well, people will either write you off as arrogant or laugh in your
face. (Still generic you.)
Anyway, welcome on board!
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
m? any solution?
Have you tried Googling? The second hit for "smtp 10061, 'Connection
refused'" is this:
http://bytes.com/topic/python/answers/32889-sending-mail-smtp-connection-refused-but-smtp-server-isrunning
Does that help?
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
ng about the use of an
index *at all*. Normally in Python you shouldn't need to use indexes,
regardless of whether they start with 0 or 1 or 3.1425 Your example
of a text menu is an exception to the rule (more of a guideline
really) "you shouldn't care about indexes".
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
YL is that they're too lazy to write hideously
ugly, but reliable, code, and they're just hoping that they will never
expose the race condition. (Often this is a pretty safe hope, but not
always.)
And now you know why ACID-compliant databases are so complex.
--
Steven D'
On Sun, 12 Sep 2010 03:18:19 am Steven D'Aprano wrote:
> But that hasn't done anything to prevent race conditions. So the real
> reason people use LBYL is that they're too lazy to write hideously
> ugly, but reliable, code, and they're just hoping that they will
>
to write
more complicated code. Sometimes you really do care what the type is:
>>> "abc"[2.0]
Traceback (most recent call last):
File "", line 1, in
TypeError: string indices must be integers
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
On Sun, 12 Sep 2010 02:00:02 am Lie Ryan wrote:
> As an alternative solution, you can derive from UserList and overload
> the __getitem__ and __setitem__ operator:
We've been able to inherit from list directly since at least Python 2.2.
Why are you using UserList?
--
Stev
equence
>>> swap_items("abcd")
does not support item lookup or item assignment
>>> swap_items(['a', 'b', 'c', 'd', 'e', 'f'])
['b', 'a', 'd', 'c', 'f', 'e']
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Don't worry about all the complications. Learn to walk first, then learn
to run.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
quot;Not like a list"
else:
print "Quacks like a list"
Where possible, the last version is to be preferred, because it doesn't
care about internal details which might change.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
][i]]
It's generally more efficient to use:
y.append(daily_solar_radiation["MJ"][i])
instead of y += [...] as you do, although for only 365 items it won't
make a huge difference.
> from filereader import *
You've already done this above, you don't need to do t
ember of the
family:
http://code.activestate.com/recipes/577030/
"dualmethod" creates a method that receives the instance when you call
it normally from the instance, and the class when you call it from the
class. This makes it like a cross between ordinary methods and c
On Mon, 13 Sep 2010 09:13:25 am Steven D'Aprano wrote:
> On Mon, 13 Sep 2010 06:05:23 am Alan Gauld wrote:
> > I think static methjods are largely a mistake of history. ISTR They
> > were
> > introduced into python before class methods (not by much - one
> > releas
;>> Decimal("1.2345")
Decimal('1.2345')
>>> Decimal.from_float(1.2345)
Decimal('1.23449999307220832633902318775653839111328125')
from_float is a class method.
--
Steven D'Aprano
___
Tutor maillist -
gers*, and somebody
slipped in a decimal-point, that is just as troublesome as if they
slipped in a semi-colon or the letter Z. Should "1.95" be truncated to
1, or rounded to 2? Should it remain a float? Should the dot be
interpreted as a digit in some unusual base?
Python refuses to
quot;, "").replace('"', "").replace("`", "")
will remove all "standard" quotation marks, although if the source text
contains non-English or unusual unicode quotes, you will need to do
more work.
Or if you prefer something more eas
quot;definition", or "overly pedantic".
A reasonable person would use the common meaning of all of these words,
unless otherwise told differently. In this case, the only ambiguity is
whether hyphenated words like "a-piece" should count as two words or
one, but fortunately
On Tue, 14 Sep 2010 09:08:24 am Joel Goldstick wrote:
> On Mon, Sep 13, 2010 at 6:41 PM, Steven D'Aprano
wrote:
> > On Tue, 14 Sep 2010 04:18:36 am Joel Goldstick wrote:
> > > How about using str.split() to put words in a list, then run
> > > strip() over each word
ied changing permissions I had set on a directory
or file without my direct say-so, I would dump that application
immediately.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http:
old "Yes" but before you actually get to
save the file.
You've got more or less the right approach here, although you can
streamline it so you're only trying to write the file once rather than
twice. Put this in a utility function or method, where all the
complication is hi
nversation??? *wink*
Write for the reader (that would be you, in six months time) first, and
then only optimize when you have to.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
3)[:3]
For small numbers of items -- and three is pretty small -- that will be
plenty efficient enough. If you had thousands of items, perhaps not,
but for three, it's not worth the effort to try to be more clever.
--
Steven D'Aprano
__
erage Myspacer or
Facebooker.
Thank you.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
unless you escape it first:
This is okay: "'Hello,' he said."
So is this: '"Goodbye," she replied.'
But this is not: 'He said "I can't see you."'
But this is okay: 'He said "I can\'t see you."'
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
gt; TIS' So that's right.
>
> OK,. Thats replacing a double slash in the data
Er, surely not... I think you've confused backslashes and forward
slashes. Or something. '\\' is a single backslash, not a double,
because the first back
ated
> > Pete
>
> print sorted(theList)[::-1]
That's a very inefficient way of doing it. First it makes a copy of the
list, then it sorts it, then it makes *another* copy in reverse.
A better way is:
sorted(theList, reverse=True)
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
uot;
elif n == 1:
rg1 = rgenre[0]
rg2 = rg3 = "NA"
elif n == 2:
rg1, rg2 = rgenre[0:2]
rg3 = "NA"
else:
rg1, rg2, rg3 = rgenre[:3]
which in turn can be shortened to the slightly cryptic one-liner:
rg1, rg2, rg3 = (rgenre + ["NA"]*3)[:3]
as al
by typing the
display form. The display form includes matching quotation marks at the
beginning and end, and escaping special characters. But that
punctuation isn't part of the string.
--
Steven D'Aprano
___
Tutor maillist - Tutor@pyth
found it in the first place. Google might help.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
,4, [1,2]]
True
> I know the values are there. How can I print
> only those item that have [1,2] and [1,3]
for key, value in xdic.items():
if 1 in value and 2 in value or 3 in value:
print key
--
Steven D'Aprano
___
Tutor mailli
7;T', 'T', 'T', 'T', 'T', 'T', 'C', 'T', 'T',
> >>> 'T',
>
> 'C', 'T', 'T', 'T', 'C', 'C', 'T', 'T','T', 'C', 'T', 'T', 'T', 'T',
> 'T', 'T']
>
> >>> "\t".join(x+":"+str(k.count(x)) for x in 'ATGC')
> 'A:0\tT:23\tG:0\tC:6'
Given the extremely low-level of knowledge which the Original Poster's
question reveals, I think a one-liner like that will probably look
completely cryptic and mysterious.
I suggest a simple modification of the OP's code:
d = {}
for i in set(k):
d[i] = k.count(i)
for key in 'ATGC':
print key + '\t' + str(d.get(key, 0))
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
from __future__ import *
File "", line 1
SyntaxError: future feature * is not defined
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
def search_log(self, pattern, parameters, log):
regex = self.pattern_generator(pattern, parameter)
return regex.search(log) # whatever
Creating a new subclass is easy:
class IISLogParser(AbstractLogParser):
type = 'iis'
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
tionality, and people (especially beginners) should beware of
over-using it, but there's no need to treat it as forbidden.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
, although I'd
wrap it in a function.
You can get rid of the inner for-loop:
clist = []
for b in blist:
if any(a in b for a in alist):
clist.append(b)
which then makes the list comp form obvious:
clist = [b for b in blist if any(a in b for a in alist)]
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
On Fri, 17 Sep 2010 11:28:04 am Steven D'Aprano wrote:
> Settle down!
Sorry, that reads a bit more harshly than I intended. Please insert a
smiley after it.
:)
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscr
ot working".
My crystal ball tells me that you're trying to run import filename at
the DOS prompt, rather than in the Python interpreter. Is my crystal
ball accurate?
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To uns
lising them again.
> print a
> print b
> print P
>
> But now id is a decimal so I don't can't translate it.
id(x) returns an integer. By default, integers always print in decimal,
if you want to print them in hex you can do this:
hex(id(P))
--
Steven D'Aprano
__
98% of the time, making a copy is
faster, simpler and more efficient, but learning how to safely modify
data structures in place is a valuable skill to have.
But I'm just talking about general principles here. In most cases, stick
to Peter's
ful to have a second one for
debugging. So in Java land, programmers often try to bypass the
singleton code so they can defeat the original designer who made it a
singleton.
> Another question related to this topic is, if I would use a module as
> a singleton (as suggested by Steve and o
On Mon, 20 Sep 2010 02:09:37 am Alan Gauld wrote:
> "Steven D'Aprano" wrote
>
> > < much sense about singleton v global>
> >
> > and think this makes their code "better". (I blame the Go4 for
> > making a
> > religio
Hello Ken,
On Sun, 19 Sep 2010 04:18:06 am Ken Oliver wrote:
>
> body{font-size:10pt;font-family:arial,sans-serif;background-co
>lor:#ff;color:black;}p{margin:0px;}
>
>
> http://mail.python.org/mailman/listinfo/tutor
u don't know what the structure of the data is, then there's
probably not much you can do with it except make a mess.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
ng enough, then change to using
getter and setter functions and properties.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
ves. If your developers, junior or
otherwise, don't know about the tests, don't keep the tests up to date,
and don't run the tests, then it doesn't matter what testing framework
you use.
Doctests and unittests are complementary. The
ince there are exactly two
items, extend() will do the job for in-place modification, otherwise +.
But you already know that, because that was your example.
If you want the items of b to *end* at -2, so that you get
['a', 'b', 'c', 'd',
s. Can you get from 120 to 2
using a division?
You will find the divmod() function useful. divmod(a, b) returns two
numbers:
a/b as a whole number, any remainder left only
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscrib
On Thu, 23 Sep 2010 05:55:36 am Steven D'Aprano wrote:
> You will find the divmod() function useful. divmod(a, b) returns
> two numbers:
>
> a/b as a whole number, any remainder left only
Arggh! Of course I meant any reminder left OVER.
--
eses, aardvark..., although there is no
standard order.
Indeed, when I design my killer language, the identifiers "foo" and
"bar" will be reserved words, never used, and not even mentioned in
the reference manual. Any program using one will simply dump core
without commen
the major
paths in the code, and ensure that all the subroutines are tested,
special values are tested, etc. Again, unit tests are often better
suited for this.
Finally, regression tests -- every time you find a bug, you write a
test that demonstrates that bug. That test will fail. Now fix the
b
;>> func("do you have any cheese, my good man?")
'DO YOU HAVE ANY CHEESE, MY GOOD MAN?'
If you get the method from an instance, it will be bound to that
instance:
>>> Test().spam
>
and self will automatically be provided when you call the method.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
application.
If it's web-based, why does it have to be Windows-only?
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Returning an empty list makes sense. Returning None makes no sense at
all.
> but if the db connection is unsuccessful I'll let the exception
> it throws propagate back up from my function, or possibly trap and
> rethrow the exception.
That's okay.
> Or if a db connection er
exceptions for flow control, then your code will
probably be slow. A single exception to end the flow, like
StopIteration, doesn't matter.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
bread"
A good guide is to look at what functions in the standard library do.
You'll find examples of functions that return a magic value or raise an
exception:
"ethel the aardvark".find('spam')
=> -1
"ethel the aardvark".index('spam'
), names of cheeses, aardvark..., although there is no
> > standard order.
>
> Hm, someone maybe should update http://en.wikipedia.org/wiki/Foobar
> ... as there is a python example listed there...
If only Wikipedia was an encyclopedia any
jd instance?
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
quot;a", 1,5) but then I get this
> message:
>
> Traceback (most recent call last):
> File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 20,
> in zoeken.find( test2, test, "a", 1,5)
> NameError: name 'test2' is not defined
Exactly.
up to a point, but when the
function is so small that it is just as easy to include the body in the
caller code, the function is pointless. It's not like "search(b, a)" is
easier to write or remember than "print a in b" -- if anything the
opposite is the case, beca
On Sun, 26 Sep 2010 02:26:25 pm David Hutto wrote:
> On Sat, Sep 25, 2010 at 9:16 PM, Steven D'Aprano
wrote:
> > On Sun, 26 Sep 2010 08:13:23 am David Hutto wrote:
> >> Since I had nothing else to do, but practice, this looks much
> >> better:
> >>
&
half of screen"
elif click_in_bottom_half1:
print "The first click was in the bottom half."
print "The second click was in the top half."
elif click_in_bottom_half2:
print "The first click was in the top half."
print "The second click was in the bottom h
inserting a "hash-bang" line at the very top of
the script:
#!/usr/bin/env python
should do it.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
ant to run them without specifying Python on the command
line.
You can always call python first:
python name-of-my-script.py
instead of just
name-of-my-script.py
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
return False
> return True
def complex_password(password):
return (
len(password) >= 12 and
any(c in punctuation for c in password) and
any(c in digits for c in password) and
any(c in ascii_uppercase for c in password) and
>> import array
>>> a = array.array('i')
>>> a.append(42)
>>> a
array('i', [42])
>>> a.append("spam")
Traceback (most recent call last):
File "", line 1, in
TypeError: an integer is required
--
Steven D
On Tue, 28 Sep 2010 02:12:55 am Joel Goldstick wrote:
> a=[]
> i=0
> for l in open("file.txt", "r"):
> a[i]=l
> i+=1
Did you try it before posting?
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.o
thod
* slice assignment
or you can decrease their size using:
* the del statement
* slice assignment
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
3 ]*4 behaves the same way. There's no problem in the inner list,
but the outer list doesn't make four copies of [0,0,0], it has *one*
list repeated four times. Modify one, modify them all.
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
ould *rely* on another test.
(Although of course, if one test fails, any tests which assume the
missing functionality will also fail.)
--
Steven D'Aprano
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
randint(1,12)
# etc.
By the way, why do you calculate a century and year separately, then add
c+y to get the year? It would be easier to just say:
year = random.randint(1600, 3099)
--
Steven D'Aprano
___
Tutor maillist - Tutor@pyt
the
hood isn't important, so long as the behaviour at the Python level
remains the same.)
So at the Python level, there is never any copying of objects unless you
specifically ask for it, and the * operator doesn't make any copies at
all. It repeats the one object multiple ti
On Tue, 28 Sep 2010 08:07:30 am Modulok wrote:
> On 9/27/10, Steven D'Aprano wrote:
> > On Tue, 28 Sep 2010 04:03:17 am Modulok wrote:
> >> List,
> >>
> >> When using the unittest module, tests are run in alphanumeric
> >> order. What's the
301 - 400 of 3304 matches
Mail list logo