Re: [Tutor] Python Help

2010-09-28 Thread Steven D'Aprano
count += n/3 > count % n == 1 > return n What's b? It is never used. Every time through the loop, you start the count at zero again. This function will always return y, the stopping value. -- Steven D'Aprano

Re: [Tutor] trouble with list.remove() loop

2010-09-28 Thread Steven D'Aprano
ackwards, so you are only ever deleting words you've already seen: for i in range(len(candidates)-1, -1, -1)): word = candidates[i] if some_test(): del candidates[i] I know the series of -1, -1, -1 is ugly, but that's what it takes. -- Steven D'Aprano ___

Re: [Tutor] list comprehension, efficiency?

2010-09-28 Thread Steven D'Aprano
00) if x <= 5] There's no way to break out of the list comp early -- it has to keep going past 5 all the way to the end. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] I am looking for a book on Beginners who never programmed before or have no experience in programming

2010-09-28 Thread Steven D'Aprano
#x27;ve never heard of "Head First Programming" -- how are they unconventional? -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] filling 2d array with zeros

2010-09-28 Thread Steven D'Aprano
ingispolite.com/likepython/ #!usr/bin/python # My first Like, Python script! yo just print like "hello world" bro I can't wait to put that on my resume :) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] if value in list of dictionaries

2010-09-28 Thread Steven D'Aprano
On Wed, 29 Sep 2010 01:41:22 am Peter Otten wrote: > You should never iterate over a list or dictionary and add or remove > items to it at the same time. That is a recipe for disaster even if > it doesn't fail explicitly* [...] > (*) I'll leave it to Steven D'A

Re: [Tutor] Operating in Place

2010-09-28 Thread Steven D'Aprano
But it might do the job you want. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Writing a txt from dbf

2010-09-28 Thread Steven D'Aprano
cally adds a newline after the string, so each printed string should be on its own line. But later, when you write the string to the file, you must add the newline yourself. > l=() > l=(strip(k[2])) > a.write(l) There's no need to clear l with the line l=() first. Just write

Re: [Tutor] Operating in Place

2010-09-28 Thread Steven D'Aprano
g =" part? Thanks. > > 1. string is a module which is deprecated. You should probably use > str or s in your example. Actually, in this case Corey is not using the string module, but is using string as the name of a variable. -- Steven D'Aprano ___

Re: [Tutor] using "in" with a dictionary

2010-09-28 Thread Steven D'Aprano
ere is, I have to > grab the value at that slot. If not I have to print something else. > When I tried "in" in the interpreter, I got something about builtin > function not being iterable. TIA for any suggestions. Without knowing exactly what you wrote, and what error you go

Re: [Tutor] Runnig a windows.exe from python

2010-09-29 Thread Steven D'Aprano
o, it is a little-known thing that Windows accepts forward slashes as well as back-slashes in pathnames. So it is easier to write: "C:/Archivos de programa/FWTools2.4.7/bin/ogr2ogr.exe" than: "C:\\Archivos de programa\\FWTools2.4.7\\bin\\ogr2ogr.exe" -- Steven D'

Re: [Tutor] generating independent random numbers

2010-09-30 Thread Steven D'Aprano
Thank you. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Help - server health check reporter

2010-09-30 Thread Steven D'Aprano
but I can be more specific once you've answered the above two questions. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] python Task

2010-09-30 Thread Steven D'Aprano
ut what the greatest number you need to test would be. * If a number isn't divisible by 2, then it can't possibly be divisible by 4, 6, 8, 10, ... either. So apart from 2, there's no need to check even numbers. -- Steven D'Aprano ___

Re: [Tutor] just what does read() return?

2010-09-30 Thread Steven D'Aprano
= string.split('\n') Much faster, simpler, and does the job. To get rid of empty lines: list_of_lines = filter(None, string.split('\n')) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscrip

Re: [Tutor] just what does read() return?

2010-09-30 Thread Steven D'Aprano
am to deal with the file a piece at a time. (This is often a good strategy for small files as well, but it is essential for huge ones.) Of course, "small" and "huge" is relative to the technology of the day. I remember when 1MB was huge. These days, huge would mean gigabytes.

Re: [Tutor] Runnig a windows.exe from python

2010-09-30 Thread Steven D'Aprano
ad to read my > arguments and passed them to the os.system(), it worked. Now when I > execute this command, in my normal DOS Windows, I must change to > another path before I run the .exe, I don't know how to tell this to > my python module. os.chrdir(path) cha

Re: [Tutor] Doubly linked list

2010-09-30 Thread Steven D'Aprano
self.data = data self.next = next mylist = Node("a") mylist.next = Node("b", Node("c")) node = mylist while node is not None: print node.data node = node.next -- Steven D'Aprano ___ Tutor mail

Re: [Tutor] Printing prime numbers

2010-09-30 Thread Steven D'Aprano
On Thu, 30 Sep 2010 11:52:49 pm Emmanuel Ruellan wrote: > On Thu, Sep 30, 2010 at 1:57 PM, wrote: > > 1 is prime > > One is /not/ prime. There's no need to apologize for pedantry. Saying that one is prime is like saying that 2 is an odd number, or that glass is a type of

Re: [Tutor] Mutable Properties

2010-09-30 Thread Steven D'Aprano
g else, just getting one of its properties. > I was wondering how to make it fire off set to for certain methods. You can't. What problem are you trying to solve? There is likely another way to solve it. (Not necessarily an easy way, but we'll see.) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Mutable Properties

2010-09-30 Thread Steven D'Aprano
set method if the old form and the new form are unequal, > there is no easy way? I repeat... what problem are you trying to solve? Calling the set method for something that *doesn't* set a property doesn't sound like a solution to a problem to me. It sounds li

Re: [Tutor] regexp: a bit lost

2010-09-30 Thread Steven D'Aprano
ned: >>> mo = re.search(r'(\d+)\s+\D*(\d+)\s+(\d)', 'spam42 eggs239') >>> mo.groups() ('42', '23', '9') Don't forget that mo will be None if the regex doesn't match, and don't forget that the items returned

Re: [Tutor] regex advise + email validate

2010-10-01 Thread Steven D'Aprano
He goes on to admit that his regex wrongly rejects .museum addresses, but he considers that acceptable. He seriously suggests that it would be a good idea for your program to list all the TLDs, and even all the country codes, even though "by the time you

Re: [Tutor] regexp: a bit lost

2010-10-01 Thread Steven D'Aprano
y regexp would match anything > at all. Square brackets create a character set, so your regex tests for a string that contains a single character matching a digit (\d), a plus sign (+) or a whitespace character (\s). The additional \d + \s in the square

Re: [Tutor] Getting total counts

2010-10-01 Thread Steven D'Aprano
ction: def add_word(genre, word, count): genre = genre.title() word = word.lower() count = int(count) # Add word to the genres table. row = genres.setdefault(genre, {}) row[word] = row.get(word, 0) + count # And to the words table. row = words.setdefault(word, {}) row[genre] = row.get(genre, 0) + count -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Connecting my users

2010-10-02 Thread Steven D'Aprano
central servers. Currently all users connected to kaishi are on the same level of the network, meaning no user has more control over the others." -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] list comprehension, efficiency?

2010-10-02 Thread Steven D'Aprano
e -- list comps need to generate relatively similar code to for-loops because they do relatively similar things. Besides, in recent versions of Python the speed of for-loops is quite good. The bottleneck is rarely the loop itself, but the work you do in the loop or the size of the loop

Re: [Tutor] Getting total counts (Steven D'Aprano)

2010-10-02 Thread Steven D'Aprano
; Sent: Sat, Oct 2, 2010 1:36 am > Subject: Tutor Digest, Vol 80, Issue 10 [snip approx 150 irrelevant lines] -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] (de)serialization questions

2010-10-02 Thread Steven D'Aprano
you're seriously considering a linear search over 450 thousand items just to avoid doing a binary search, there's something seriously wrong. Is it worth it? Log base 2 of 45 is less than 19, so the average binary search will take 19 lookups. The average linear search will take 225

Re: [Tutor] Change to Class-level Variable

2010-10-03 Thread Steven D'Aprano
't let you accidentally modify a class attribute. You have to do it explicitly. Here are three ways to do it: type(f1).myid = 'Bar' f1.__class__.myid = 'Bar' Foo.myid = 'Bar' (You might be able to do some sort of metaclass magic to change this behaviour,

Re: [Tutor] Matching relational data

2010-10-03 Thread Steven D'Aprano
tically matches your data. (8) Technically, you can calculate a regression line for *any* data, even if it clearly doesn't form a line. That's why you are checking the correlation coefficient to decide whether it is sensible or not. By now any *real* statisticians reading this

Re: [Tutor] subprocess.call warning

2010-10-03 Thread Steven D'Aprano
per(): fname = "upper_%s" % fname.lower() return os.path.join(base, fname + '.wav') and then call it: filenames = ['A', 'b', 'c', 'D', 1, 2, 3] for name in filenames: name = fix_filename(name) sox_filenames.append(nam

Re: [Tutor] Matching relational data

2010-10-04 Thread Steven D'Aprano
count += 1 > else: > print 'Lists are not same length for comparison' > per = (100/lena) > print count * per, '% match' a = '+-+-+-+-+-+' b = '-+-+---+---' if len(a) != len(b): raise ValueError('lists are not the same length') count = sum(ca == cb for (ca, cb) in zip(a, b)) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Matching relational data

2010-10-04 Thread Steven D'Aprano
7;ll know the theory and math are correct! Or you could use numpy and scipy, which are rapidly becoming the choice for numeric and scientific applications over R. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or

Re: [Tutor] subprocess.call warning

2010-10-04 Thread Steven D'Aprano
wf file, I can't believe that you seriously believe that the Python code is likely to be the bottleneck. If it takes ten seconds to process the wav files into a swf file, who cares if you speed the Python code up from 0.02 seconds to 0.01 seconds? But I could be w

Re: [Tutor] perl or python

2010-10-05 Thread Steven D'Aprano
Eric Raymond: http://www.linuxjournal.com/article/3882 -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Prime Numbers

2010-10-07 Thread Steven D'Aprano
ld copy and paste individual letters from another document. We won't do your home work for you, but if you ask specific questions, we will be happy to help. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change

Re: [Tutor] validating user input for cli app

2010-10-07 Thread Steven D'Aprano
. Please try again." "Hey dummy, don't you know what a number is?" although of course this requires more programming effort. And naturally the condition functions can be as simple, or as complicated, as you need. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] IDE for Python

2010-10-08 Thread Steven D'Aprano
ss forced. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] WRITING XLS FROM OS.WALK()

2010-10-08 Thread Steven D'Aprano
tax error. >for f in filelist: > allfiles.append(f) This is better written as: allfiles.extend(filelist) but of course it is better to use the glob module. > for i in allfiles: > print i > a.write(i) > a.write("\n"

Re: [Tutor] WRITING XLS FROM OS.WALK()

2010-10-08 Thread Steven D'Aprano
such-and-such a disease. Here's my bill for $500." My uncle got all indignant. "$500? You've hardly done anything! Why should you get so much just because you've got a tool that does the work for you?" The specialist replied "The bill is $10 for my

Re: [Tutor] list of dict question

2010-10-09 Thread Steven D'Aprano
ntence beginning with "Alan's answer to Roelof...", and another sentence "This was your answer to Roelof", everything in your post was a quote (started with a > sign). So what is your question about lists of dicts? -- Steven D'Aprano _

Re: [Tutor] Interpolation

2010-10-09 Thread Steven D'Aprano
s.python.org/library/stdtypes.html#string-formatting -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] WRITING XLS FROM OS.WALK()

2010-10-09 Thread Steven D'Aprano
On Sun, 10 Oct 2010 03:59:26 am Emile van Sebille wrote: > On 10/8/2010 8:55 PM Steven D'Aprano said... > > > I'm sorry to tell you that you've just reinvented the wheel. This > > was already solved, a long, long time ago. It is called the glob > > module:

Re: [Tutor] Attempt to overwrite excel cell Python

2010-10-11 Thread Steven D'Aprano
aste the exact error message, including the full traceback. I suspect that you might need to read the documentation of the xlwt project and see what it says. Perhaps the cell you are trying to overwrite is locked? -- Steven D'Aprano ___ Tuto

Re: [Tutor] dictionary and more

2010-10-11 Thread Steven D'Aprano
questions you should be asking yourself are: - what value am I expecting it to contain? - where in my code should that value be set? - why is it setting None instead? Armed with these three questions, you now know how to debug the problem yourself. -- Steven D'Aprano _

Re: [Tutor] Hiding Superclass Methods

2010-10-11 Thread Steven D'Aprano
n integer or a slice object, and behave accordingly. http://docs.python.org/reference/datamodel.html#object.__getitem__ -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] SQLite3 DB Field Alphabetizing

2010-10-12 Thread Steven D'Aprano
items in almost-but-not-quite alphabetical order. Maybe it's just a fluke. They have to be in *some* order. Since you haven't told us how you added them to the list, perhaps you deliberately added them in that order and are trying to trick us. In which case, HA! I see through your cunning trick! *wink* -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] urllib problem

2010-10-12 Thread Steven D'Aprano
g ? Each time through the loop, you set volgende to the same result: nummer = re.search('[0-9]', inhoud) volgende = int(nummer.group()) Since inhoud never changes, and the search never changes, the search result never changes, and volgende never changes. -- Steven D'Aprano

Re: [Tutor] urllib problem

2010-10-12 Thread Steven D'Aprano
On Tue, 12 Oct 2010 11:58:03 pm Steven D'Aprano wrote: > On Tue, 12 Oct 2010 11:40:17 pm Roelof Wobben wrote: > > Hoi, > > > > I have this programm : > > > > import urllib > > import re > > f = > > urllib.urlopen("http://www.pyth

Re: [Tutor] SQLite3 DB Field Alphabetizing

2010-10-13 Thread Steven D'Aprano
code strings (characters) are written using just " as the delimiter (or ' if you prefer), instead of u" " as used by Python 2. Byte strings are written using b" " instead. This makes the common case (text strings) simple, and the uncommon case (byte strings) more

Re: [Tutor] Converting from unicode to nonstring

2010-10-14 Thread Steven D'Aprano
built-ins. They're powerful but dangerous and slow, and making them built-ins just encourages newbies to use them inappropriately. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: h

Re: [Tutor] Converting from unicode to nonstring

2010-10-14 Thread Steven D'Aprano
,4'. Better is: >>> s = '1, 200 , -3,4' # or whatever >>> [int(x) for x in s.split(',')] [1, 200, -3, 4] -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] trying it again: p2p for game

2010-10-14 Thread Steven D'Aprano
nose firewall issues next. If you're trying to connect from a computer in one school to a computer in another school, both firewalls will almost certainly try to stop you. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To un

Re: [Tutor] Statistic-Program Problems! Please Help Quickly!

2010-10-14 Thread Steven D'Aprano
ond set:", b which should print: Sum of x from first set: 9 Sum of x from second set: 108 You should make similar adjustments to Y() and the other functions, and then see how the assignment goes. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Statistic-Program Problems! Please Help Quickly!

2010-10-15 Thread Steven D'Aprano
the value of y that goes with the value of x=5, for the regression line you calculated earlier. Then you move on to the second set of data: m = ... # something goes here b = ... # something else goes here y = line(95) which calculates the y that goes with

Re: [Tutor] Converting from unicode to nonstring

2010-10-15 Thread Steven D'Aprano
>> str_to_list(u'[1,2,3,None]') Traceback (most recent call last): File "", line 1, in File "", line 13, in str_to_list ValueError: item `None` does not look like an int Compared to eval and ast.literal_eval, both of which do too much: >>> eval(u'{1:2}') {1: 2} >>> eval(u'[1,2,3,None]') [1, 2, 3, None] >>> ast.literal_eval(u'{1:2}') {1: 2} >>> ast.literal_eval(u'[1,2,3,None]') [1, 2, 3, None] -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] 'module' object has no attribute (setting a class attribute)

2010-10-15 Thread Steven D'Aprano
: 'module' object has no attribute 'tmpl' (There are other errors you could have got, but they're fairly obscure and/or unusual.) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Statistic-Program Problems! Please Help Quickly!

2010-10-16 Thread Steven D'Aprano
sation just to add a one sentence response at the very end. Just leave enough to establish context, and anything you are *directly* responding to. Thank you. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subs

Re: [Tutor] updating a Csv file

2010-10-20 Thread Steven D'Aprano
atform. [...] >    newLine = [ch for ch in string.letters[0:9]] What's wrong with this? newline = list(string.letters[0:9]) -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Problem with python

2010-10-20 Thread Steven D'Aprano
ctorial again... Starting factorial calculation with n = 0 Done with n = 0 -- returning 1 Done with n = 1 -- returning 1 Done with n = 2 -- returning 2 Done with n = 3 -- returning 6 Done with n = 4 -- returning 24 Done with n = 5 -- returning 120 120 Notice the pattern of n values: the *f

Re: [Tutor] What does "TypeError: 'int' object is not iterable" mean?

2010-10-22 Thread Steven D'Aprano
mples that you should follow. Putting the three of these together, your docstring should say something like: Given a float floatt and an integer n, returns floatt formatted as a string to n decimal places. >>> float2n_decimals(2, 81.34567) '81.35' (BTW, I real

Re: [Tutor] URL test function.

2010-10-22 Thread Steven D'Aprano
d then call it with: def is_ready(): url = 'http://' + env.host_string + '\:8080' with settings(warn_only=True): return urlopen_retry(url) Hope this helps. -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Problem Passing VARs to Python from PHP & capturing return string

2010-10-22 Thread Steven D'Aprano
instead? > I added .py to Windows IIS Web Service Extensions and to the > Application Configuration. How exciting! And what happened then? -- Steven D'Aprano ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Syntax Error Messages

2010-10-22 Thread Steven D'Aprano
e this: >>> print "abc File "", line 1 print "abc ^ SyntaxError: EOL while scanning string literal We need to see the entire message, not just a vague description that it's a syntax error. -- Steven D'Aprano

Re: [Tutor] problems with numdifftools

2010-10-23 Thread Steven D'Aprano
eger arguments: range(start, end, step) where start and step are optional, defaulting to 0 and 1 respectively. By starting the inner loop at i+1, you guarantee that j is always > i and therefore you can skip the test. The other change is that instead of Vx = Vx + something you can write:

Re: [Tutor] What does "TypeError: 'int' object is not iterable" mean?

2010-10-23 Thread Steven D'Aprano
ld have to be a *very* old version. The use of * as the width parameter in format strings goes back to the Dark Ages of Python 1.5: [st...@sylar ~]$ python1.5 Python 1.5.2 (#1, Apr 1 2009, 22:55:54) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Copyright 1991-1

Re: [Tutor] What's the best way to model an unfair coin?

2010-10-24 Thread Steven D'Aprano
Richard D. Moores wrote: What's the best way to model an unfair coin? Let probability of heads = p, where 0 <= p <= 1 Then probability of tails = 1-p. if random.random() <= p: print("got heads") else: print("got tails") [...] That's the only way I can think of. But surely there's a better, m

Re: [Tutor] What's the best way to model an unfair coin?

2010-10-24 Thread Steven D'Aprano
Evert Rol wrote: Btw, to be pedantic, 1/e is not an irrational number, just a real number. i/e would be. Actually, Richard is correct. Like π, e and 1/e are irrational numbers. "Irrational" means the number is not rational, in the sense of *ratio*, not sanity :) There is no exact ratio of

Re: [Tutor] What's the best way to model an unfair coin?

2010-10-24 Thread Steven D'Aprano
Richard D. Moores wrote: Actually, I used the unfair coin model as the simplest example of the kind of thing I want to do -- which is to model the USD->Yen exchange rate. I want the next quote to vary in a controlled random way, by assigning probabilities to various possible changes in the rate.

Re: [Tutor] What is random.triangular() used for

2010-10-24 Thread Steven D'Aprano
Richard D. Moores wrote: NameError: name 'np' is not defined [...] but where do I get np? I believe that it is common in the scientific python world to do this: import numpy as np and then use np.FUNCTION instead of numpy.FUNCTION. -- Steven ___

Re: [Tutor] compare two souce files

2010-10-28 Thread Steven D'Aprano
Jojo Mwebaze wrote: Hello Tutor I would like to compare two souce code files but ignoring doc strings, comments and space (and perharps in future statement by statement comparision) e.g class Foo def foo(): # prints my name return 'my name' class Boo def boo(): print 'my

Re: [Tutor] (no subject)

2010-10-28 Thread Steven D'Aprano
Terry Green wrote: def main(): pass Useless function, does nothing. Why is it here? if __name__ == '__main__': main() Also does nothing useful. Why is it here? postPos=words[3] This like will fail with NameError, because words is not defined anywhere. This is not the code you

Re: [Tutor] (no subject)

2010-10-28 Thread Steven D'Aprano
Luke Paireepinart wrote: On Thu, Oct 28, 2010 at 8:11 PM, Steven D'Aprano wrote: postPos=words[3] This like will fail with NameError, because words is not defined anywhere. This is not the code you are running. We can't tell what is wrong with the code you run when you show us

Re: [Tutor] Stumped Again

2010-10-30 Thread Steven D'Aprano
Terry Green wrote: Am running this Script and cannot figure out how to close my files, Keep getting msg: Attribute Error: '_csv.writer' object has no attribute 'close' Why? Lesson one: we're not mind readers. To be able to give you useful advise, we need to see the ACTUAL error and not a sum

Re: [Tutor] File transfer

2010-10-31 Thread Steven D'Aprano
Corey Richardson wrote: If you can send a list, have the list [name, data] where name is the file name and data is the raw binary of the file, contained in a string. How do you send a list? -- Steven ___ Tutor maillist - Tutor@python.org To unsub

Re: [Tutor] How to notify/handle an error?

2010-10-31 Thread Steven D'Aprano
dave p. guandalino wrote: Which of the following ways is better to handle something wrong? Many thanks. It depends on what you are trying to do. # First: def is_valid_project(): # Do checks and valorize is_a_valid_project accordingly return is_a_valid_project # True / False Do you

Re: [Tutor] (no subject)

2010-10-31 Thread Steven D'Aprano
Jacob Bender wrote: I have a few more ?'s. Well, don't keep them a secret, tell us what they are! What are your questions? I was trying to make a program for ubuntu that does one function: if ctrl + Alt + "t" is pressed, to shut down the computer. There are only two problems. I want it to

Re: [Tutor] How to notify/handle an error?

2010-10-31 Thread Steven D'Aprano
Steven D'Aprano wrote: Never (well, *almost* never) use print for printing error messages. More information here: http://en.wikipedia.org/wiki/Error_hiding -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscri

Re: [Tutor] File transfer

2010-10-31 Thread Steven D'Aprano
Chris King quoted Corey Richardson: On 10/31/2010 12:03 PM, Corey Richardson wrote: [...] To read from a file, you open it, and then read() it into a string like this: for line in file: string += string + file.readline() Aii! Worst way to read from a file *EVAR*!!! Seriously. Don'

Re: [Tutor] Complete Shutdown

2010-11-01 Thread Steven D'Aprano
Alan Gauld wrote: "Chris King" wrote How do I completely shutdown a computer without administrative rights using a simple python script. If you have such a computer get rid of it, it fails the most basic test of a secure operating system. No program that runs upon it could ever be relie

Re: [Tutor] pythonpath

2010-11-01 Thread Steven D'Aprano
Chris King wrote: it didn't work Define "it" and "didn't work". What did you try? What happened when you tried it? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/l

Re: [Tutor] scope, visibility?

2010-11-01 Thread Steven D'Aprano
Samuel de Champlain wrote: Inside the class is a method with a bit of code: def masque(chaine,liInd=0): i = 0 lenght = len(chaine) As this is a method, you normally need to refer to the instance in the definition: def masque(self, chaine, liInd=0): i = 0 length

Re: [Tutor] Complete Shutdown

2010-11-01 Thread Steven D'Aprano
Chris King wrote: I restarted the whole system with a script. Why couldn't I shut it down? Probably because the script told the computer to restart rather than shut down. It will help if you tell us: * what operating system you are running * what you did to restart the computer * what yo

Re: [Tutor] Problems with partial string matching

2010-11-01 Thread Steven D'Aprano
Josep M. Fontana wrote: The only time year is bound is in the previous loop, as I said. It's the line that goes: name, year = line.strip. So year is whatever it was the last time through that loop. OK, this makes sense. Indeed that is the value in the last entry for the dictionary. Th

Re: [Tutor] Problems with partial string matching

2010-11-01 Thread Steven D'Aprano
Josep M. Fontana wrote: Sorry about the top-posting. Sometimes it seems that a little top-posting might make things easier (I hate to have to go through long quotes) but you are totally right, netiquette is netiquette. To all the people who say "Never top-post", I say never say never -- there

Re: [Tutor] True Random Numbers

2010-11-02 Thread Steven D'Aprano
Crallion wrote: In an attempt to generate "true" random numbers, Have you considered using your operating system's source of random numbers? random.SystemRandom and os.urandom return numbers which are cryptographically sound. They are also based on various sources of physical randomness (whi

Re: [Tutor] mutable types

2010-11-02 Thread Steven D'Aprano
John wrote: Hello, I thought the following should end with G[1] and G[0] returning 20. Why doesn't it? In [69]: a = 10 In [70]: G = {} In [71]: G[0] = [a] In [72]: G[1] = G[0] In [73]: a = 20 In [74]: G[1] Out[74]: [10] In [75]: G[0] Out[75]: [10] This doesn't actually have anything to do with

Re: [Tutor] Server

2010-11-04 Thread Steven D'Aprano
Chris King wrote: Dear Tutors, May server and client programs aren't working. They basically simplify socket and SocketServer. Run them directly to test them. They do work locally. They don't work from one computer to the next on the same network. Please Help. It's probably a network is

Re: [Tutor] Reading the CDROM in Linux

2010-11-05 Thread Steven D'Aprano
Alan Gauld wrote: I don't use Ubuntu so don;t know the standard anmswer there but it will depend on where the CD is mounterd. I usually mount cdroms on /dev/cdrom Surely that's where you mount cdroms *from*? I can't think that using /dev/cdrom as the mount point would be a good idea! Anyw

Re: [Tutor] Reading the CDROM in Linux

2010-11-05 Thread Steven D'Aprano
Terry Carroll wrote: I have a program that traverses the directory of a CDROM using os.walk. I do most of my work on Windows, but some on (Ubuntu) Linux, and I'd like this to work in both environments. On Windows, I do something along the lines of this: startpoint="D:/" What if the user h

Re: [Tutor] Reading the CDROM in Linux

2010-11-05 Thread Steven D'Aprano
Steven D'Aprano wrote: But if you might have an external hard drive plugged in, or a USB key, or similar, then you need to find out what the volume name of the mounted CD drive is. That's a good question and I don't have an answer right now. Let me think about it and get back

Re: [Tutor] test

2010-11-05 Thread Steven D'Aprano
Luke Paireepinart wrote: You don't get your own e-mails back. I do. Perhaps it's an option when you sign up? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/

Re: [Tutor] Programs for Newbies?

2010-11-05 Thread Steven D'Aprano
Danyelle Davis wrote: Hi all, Any suggestions for a newbie to program while learning python? I am new to programming and python. What are you interested in? Interested in maths? Write a program to generate prime numbers, or to search for amicable numbers. Look at Project Euler, although (i

Re: [Tutor] Programs for Newbies?

2010-11-05 Thread Steven D'Aprano
Danyelle Davis wrote: Hi all, Any suggestions for a newbie to program while learning python? I am new to programming and python. Here's a few suggestions: Write a program that asks the user to enter a word, then counts how many vowels and consonants are in the word. Write a program that

Re: [Tutor] trying to generate change in print output

2010-11-07 Thread Steven D'Aprano
Terry Green wrote: Am stumped, when I use this code: race=int(row[2]) raceChek=1 This causes IndentationError: unexpected indent. if raceChek == race: print ('raceChek ', raceChek, 'race ', race) else: print ('raceChek ', raceChek,' no match ', 'race ', race); raceChek = race

Re: [Tutor] List comprehension question

2010-11-08 Thread Steven D'Aprano
Richard D. Moores wrote: So this version of my function uses a generator, range(), no? def proper_divisors(n): sum_ = 0 for x in range(1,n): if n % x == 0: sum_ += x return sum_ I'm going to be pedantic here... but to quote the Middleman, specificity is the so

Re: [Tutor] List comprehension question

2010-11-08 Thread Steven D'Aprano
Alan Gauld wrote: "Steven D'Aprano" wrote I'm going to be pedantic here... but to quote the Middleman, specificity is the soul of all good communication. Be pedantic! :-) I really liked the explanation although I already sort of knew most of it. But there were a few

Re: [Tutor] List comprehension question

2010-11-08 Thread Steven D'Aprano
Stefan Behnel wrote: Hugo Arts, 08.11.2010 00:53: [...] On another note, getting rid of the list comprehension and using a generator expression will be even faster, since you won't have to build the list. I gave this suggestion a try. It is true for me when run in CPython 3.2: [...] However

Re: [Tutor] Columnar Transposition Cipher question

2010-11-08 Thread Steven D'Aprano
On Mon, Nov 08, 2010 at 03:28:44PM -0800, Natalie Kristine T. Castillo wrote: > Hi, I need help on how exactly to solve this: > > To send secret messages you and your partner have decided to use the > columnar function you have written to perform columnar transposition > cipher for this course. You

<    1   2   3   4   5   6   7   8   9   10   >