Re: [Tutor] Query about using Pmw entry widget...

2007-01-07 Thread John Fouhy
g one of the built-in validators. (which Asrarahmed would need to do, since he wants to restrict the range of numbers available) Also, this will not work quite right; you need something like: def numeric(val): try: float(val) except ValueError: if val == '':

Re: [Tutor] Question on joining out of order dictionary elements

2007-01-10 Thread John Fouhy
;test3'] output = '\\'.join(config[k] for k in keysToDump) (note that, if you are using python2.3 or earlier, you will need to write that last line as: output = '\\'.join([config[k] for k in keysToDump]) ) HTH! -- John. ___

Re: [Tutor] more fun and games with padded numbers

2007-01-11 Thread John Fouhy
But this is what strip is for. >>> lst = ['0001.ext', '0230.ext', '0041.ext', '0050.ext'] >>> [s.lstrip('0') for s in lst] ['1.ext', '230.ext', '41.ext', '50.ext'] -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Graphics with Python: wxPython vs. tkinter vs. PyCairo vs. PyX vs...

2007-01-17 Thread John Fouhy
ind will be in a different style, and many of the experienced coders are used to an older style of wx coding. But wxPython is better than Tkinter for apps you're going to spend time on, or show to other people. -- John. ___ Tutor maillist - Tu

Re: [Tutor] Variables of Variables

2007-01-18 Thread John Fouhy
ed some black magic.. but you should generally avoid that) However, the other question you should ask yourself is: should you be using a dictionary instead? Rather than storing your data as variables, you could store it in a dictionary. Then you can dynamically access data however you like.. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Why this error ?

2007-01-31 Thread John Fouhy
n = MySQLdb.connect (host = "localhost", user > = "testuser", passwd = "testpass", db = "test")' > " Your indentation is wrong. Try outdenting all your code so it all starts in the same column, and see if that helps. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Why this error ?

2007-01-31 Thread John Fouhy
uot;) > cursor = conn.cursor () > cursor.execute ("SELECT VERSION()") > row = cursor.fetchone () > print "server version:", row[0] > cursor.close () > conn.close () > > but the problem remains :-( This will fail because you have quote marks arou

Re: [Tutor] adding columns of numbers

2007-02-01 Thread John Fouhy
ums[i] = sums[i] + eval(cols[i]) > return sums > > if __name__ == '__main__': > import sys > print summer(sys.argv[1]) > > Unfortunately, the output is: > [4, 20, 40, 16, 4.0] Compare the output with the input. Where do you think the out

Re: [Tutor] Debugging

2007-02-08 Thread John Fouhy
to next line 's' -- move to next line, or step into function call 'c' -- continue running until next breakpoint 'p' -- print; used to inspect variables, etc. ) Note that pdb has difficulties with multithreaded programs. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] file open error

2007-02-08 Thread John Fouhy
rguments. Many people recommend not doing "from .. import *" if you can possibly avoid it because of this precise problem! -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Identity operator (basic types)

2007-02-09 Thread John Fouhy
name you give it is just a pointer to that one 10. Remember, python is fully OO -- _everything_ is a reference :-) (this is also why there is no ++ operator) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Multiple Tk frames

2007-02-13 Thread John Fouhy
main window") lab1.pack() otherWindow = Toplevel() otherWindow.title("Other window") lab2 = Label(otherWindow, text="This is the other window") lab2.pack() root.mainloop() -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] summer_v04.py

2007-02-20 Thread John Fouhy
rror: invalid syntax What version of python are you running? If you are running 2.3.x or earlier, you will need to rewrite this as: numCols = max([len(cols) for cols in line_list]) (because you are using a generator expression, and they were only introduced in 2.4) -- John.

Re: [Tutor] list problem

2007-02-21 Thread John Fouhy
l the data is in a single cell! > > it's a one cell list! Say what? Have you tried looking at pagename in a text editor? If readlines() is returning only one line, then you should be able to spot that in the file. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Function for converting ints from base10 to base2?

2007-02-21 Thread John Fouhy
alse True >>> ['zero', 'one'][True] 'one' It's more compact, but less clear (IMO), so I'm not a big fan. Hmm, and it may not be faster either: Morpork:~ repton$ python -m timeit -s 'n=13' 'x=["", "-"][n<0]

Re: [Tutor] Another list comprehension question

2007-02-26 Thread John Fouhy
you could write this as "files.extend(get_clist(clist))", which would be slightly more efficient. > My first attempt was to try > [get_clist(c) for c in get_clists()] > > but this returns a list of lists rather than the flat list from the > original. This will do it: >>> [x for k in clists for x in clists[k]] ['a', 'b', 'c', 'x', 'y', 'z', 'p', 'q'] Or [x for k in get_clists() for x in get_clist(k)] using your original structure. HTH! -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Another list comprehension question

2007-02-27 Thread John Fouhy
, interestingly, my claim that using .extend is more efficient appears to be false, at least for this example: Morpork:~ repton$ python -m timeit -s 'lsts=[["a","b","c"],["1","2","3"],["x","y","z"]]' 'flattened = []' 'for lst in lsts:' ' flattened = flattened + lst' 10 loops, best of 3: 2.56 usec per loop (not that there's much in it) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] trouble with function-- trying to check differences btwn 2 strings

2007-03-06 Thread John Fouhy
'foo' ... foo So ... hmm. Not sure what's going on here. I also notice that, according to http://docs.python.org/ref/summary.html, '==' has higher precedence than 'in'. Which means that 'foo == bar in baz' should group as '(foo == bar) in baz'. But Luke's example contradicts this: >>> lst = [1,2,3,4] >>> 555 == 555 in lst False >>> (555 == 555) in lst True >>> 1 == 1 in lst True (this works because 1 == True) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] sorting question

2007-03-06 Thread John Fouhy
line, insert into database 3. Run query 'select blah from foo order by whatever limit 5'. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] The whole Roman to Dec and vice versa issue

2007-03-11 Thread John Fouhy
dec -= next return roman Now, if we suddenly remember that the romans used 'Q' to represent 250, we can just edit our dictionary, and the rest of the code will remain the same. [note that this code will not produce strings like 'IV' for 4. OTOH, as I recall, the Romans didn't do that consistently either..] -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] The whole Roman to Dec and vice versa issue

2007-03-11 Thread John Fouhy
e 'Q' for 250. > Maybe you can change the dictionary for this one too. Ahh, good point. I was thinking in terms of extra logic to figure out the subtraction rules, but you could just use extra symbols :-) -- John. ___ Tutor maillist - Tu

Re: [Tutor] String-manipulation question

2007-03-11 Thread John Fouhy
t;string slicing". The tutorial covers this; look about half-way down the page: http://docs.python.org/tut/node5.html HTH! -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to set value back to .conf file

2007-03-20 Thread John Fouhy
ke object open for writing. To continue your example, you can do this: f = open('test.conf', 'w') conf.write(f) f.close() -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Filesystem vs Database vs Lucene

2007-03-28 Thread John Fouhy
ow what you're doing, you can write your own python modules in C and incorporate them into your python programs. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] or

2007-03-29 Thread John Fouhy
uot; or "pairs". You can then invert that: for f in fruit: if not (f == "apples" or f == "pairs"): print f, "is not an apple or pair." You could then use DeMorgan's law to convert this to: for f in fruit: if f != "apples" and f != &qu

Re: [Tutor] passing arguments via an instance of a class

2007-04-03 Thread John Fouhy
(i.e. the code where the NameError occurs) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] New York City Python Users Group Meeting

2007-04-04 Thread John Clark
/group/nycpython/ Hope to see you there! -John ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] windows and python and shebangs, oh my!

2007-04-04 Thread John Fouhy
ed normally (i.e. with the installer). -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] windows and python and shebangs, oh my!

2007-04-05 Thread John Clark
Be aware that by default the Apache web server _WILL_ use the shebang line even when running on Windows to try to find the Python interpreter when python is run as a CGI script. There is a setting in the configuration file that controls whether to use the shebang line or to reference the window

Re: [Tutor] Addressing a variable whose name is the value of a string

2007-04-08 Thread John Clark
Bob Gailer wrote: >Andreas Pfrengle wrote: >> Hello, >> >> I want to change the value of a variable whose name I don't know, but >> this name is stored as a string in another variable, like: >> >> x = 1 >> var = 'x' >> >> Now I want to change the value of x, but address it via var. > >exec is the

Re: [Tutor] kwds

2007-04-10 Thread John Fouhy
x27;k': 42, 'z': 13} And, obviously, you can combine both of these. You might commonly see this when dealing with inheritance -- a subclass will define some of its own parameters, and use *args/**kw to collect any other arguments and pass them on to the base class. eg: class MySubClass(BaseClass): def __init__(self, x, y, foo='foo', *args, **kw): BaseClass.__init__(*args, **kw) # Do stuff with x, y, foo > and I have not really found a clear or concise explanation via Google. I don't think this counts as "concise", but I hope it is clear :-) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] ANN: Next NYC Python User Group meeting, Tues May 8th, 2007, 6:30 pm

2007-04-11 Thread John Clark
and last names to give to building security to make sure you can gain access to the building. RSVP to [EMAIL PROTECTED] to add your name to the list. More information can be found on the yahoo group page: http://tech.groups.yahoo.com/group/nycpython Hope to see you there! -John _

[Tutor] read text file in zip archive, process, plot

2007-04-15 Thread John W
Kent and Alan: better? .j import zipfile import os import pylab as P iFile = raw_input("Which file to process?") def openarchive(filename): """ open the cmet archive and read contents of file into memory """ z = zipfile.ZipFile(filename, "r") for filename in z.namelist(): print f

Re: [Tutor] hypotenuse

2008-03-13 Thread John Fouhy
gt;> hypotenuse = math.sqrt(hyp_squared) Finally, "int" is a built-in type, so it's bad programming style to use it as a variable name. (the same goes for "list", "str", and a few others) That's why, in my example, I used "hyp_squared" as the name for the hypotenuse squared. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] hypotenuse

2008-03-13 Thread John Fouhy
hon -m timeit -s "import math" -s "x = 2" "y = math.sqrt(x)"' means "import math, set x to 2, then run y=math.sqrt(x) many many times to estimate its performance". From the interpreter, type 'import timeit; help(timeit)' for more information) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Calling super classs __init__?

2008-03-18 Thread John Fouhy
e base class arguments when you create instances. Whether you call BaseClass.__init__ early or late in the subclass init method could depend on what your classes are doing. Remember, in Python, __init__ only initializes objects, it doesn't create them. It's just another

Re: [Tutor] kwargs to object proporties?

2008-03-18 Thread John Fouhy
.. See this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286185 It has some suggestions and discussion that you might find helpful. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Interactive plots...

2008-03-27 Thread John Fouhy
re complex. I think there are recipes or examples around on the net that you can probably find. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Process that starts processes

2008-04-09 Thread John Chandler
I have been searching for a while but I can't seem to find anything that will do this, so... In my python program I am starting a process using subprocess.Popen. This is working fine, but the process I am starting starts several other processes. Is there any way (using subprocess or a different mo

[Tutor] hey, a bit of a noob at python ut a question about animation...

2008-04-12 Thread John Jojo
I am trying to make a simple animation, and this is what I have. from livewires import games, color games.init(screen_width = 1000, screen_height = 1000, fps = 50) class Animation(games.Sprite): files1 = ["stick1.jpg"] files2 = ["stick2.jpg"] def __init__(self): self.animate1()

Re: [Tutor] cut all decimal places with zeros

2008-04-15 Thread John Fouhy
l explain that rstrip will strip off any charcters in the argument from the right of the string you call it on. So '10.0'.rstrip('.0') will remove any '.' or '0' from the right, leaving '1'. '10.0'.rstrip('0') will remove

Re: [Tutor] Remove specific chars from a string

2008-04-15 Thread John Fouhy
moved to methods of strings. (e.g. string.capitalize(s) --> s.capitalize()) But that doesn't work for a couple of functions, like maketrans, so those functions are not deprecated. -- John. ___ Tutor maillist - Tutor@python.org http://mail

Re: [Tutor] Hoping to benefit from someone's experience...

2008-04-15 Thread John Fouhy
On 16/04/2008, Marc Tompkins <[EMAIL PROTECTED]> wrote: > Does anyone out have experience with: > - manipulating RTF files? Is this any help to you: http://pyrtf.sourceforge.net/ ? -- John. ___ Tutor maillist - Tutor@pyt

Re: [Tutor] Nested dictionary with defaultdict

2008-04-15 Thread John Fouhy
7;: {220 : 2}, '5': {'220: 2}, '5': {238 : 1}, '6': {'238' : > 2}, '7': {'220' : 1}} [...] > I am looking for a satrting point or any suggestions. Can you write a function that will take a list and return a dictionary with the counts of elements in the list? i.e. something like: >>> def countValues(valueList): ... # your code goes here ... >>> countValues(['220', '238', '238', '238', '238']) {'238': 4, '220': 1} P.S. Your sample output is not a valid dictionary... -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Little problem with math module

2008-04-20 Thread John Fouhy
ing with complex numbers, you might be better off looking at scipy or some other module that provides more mathematical grunt. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Little problem with math module

2008-04-20 Thread John Fouhy
On 21/04/2008, John Fouhy <[EMAIL PROTECTED]> wrote: > >>> -1 ** (1.0/2.0) > -1.0 Replying to myself: It turns out that all is not what it seems. Let's try again: >>> (-1)**0.5 Traceback (most recent call last): File "", line 1, in Valu

Re: [Tutor] Dictionaries or Numpy?

2008-05-16 Thread John Fouhy
to benchmark dictionary access against Numpy arrays). If your program design is good, the change should be too hard. http://en.wikipedia.org/wiki/Optimization_(computer_science)#When_to_optimize -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] datetime syntax error for May 8th and 9th 2008??

2008-05-16 Thread John Fouhy
>>> x 8 Basically, python interprets integer literals starting with 0 as octal numbers. It's an old convention from C (or earlier?). It doesn't affect strings, so int('010') == 10 (unless you use eval). HTH! -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] quickly pulling marbles out of urns

2008-05-16 Thread John Fouhy
top in any order). Then you can randomly generate a colour by generating a random int in (0,1) and comparing with the proportions in the node. Then you just have to update the weights for the colour you choose and all nodes above it. Should be log_2(n) to pick one colour and n.log_2(n) to pick colo

Re: [Tutor] Reading only a few specific lines of a file

2008-05-22 Thread John Fouhy
it. Note that this means you won't check the second line --- you can maybe visualise this with a simpler example: >>> a = [] >>> nums = iter(range(10)) >>> for i in nums: ... a.append((i, nums.next())) ... >>> a [(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)]

Re: [Tutor] why?

2008-05-28 Thread John Fouhy
On 29/05/2008, Robert William Hanks <[EMAIL PROTECTED]> wrote: > > Need ti find out whem a number o this form i**3+j**3+1 is acube. > tryed a simple brute force code but, why this not work? [deleted code] Why doesn't this work? What problems are y

[Tutor] NYC Python User Group Meeting Announcement....

2008-05-29 Thread John Clark
users group wiki page: http://www.nycpython.org Hope to see you there! -John Clark ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to get a script to open a text file with Python?

2008-06-10 Thread John Fouhy
t work, even with > QuickEdit.. Single right-click to paste. User interface consistency would be a wonderful thing :-) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to get a script to open a text file with Python?

2008-06-11 Thread John Chandler
out. system() may work if the preference is > already set but startfile is specifically intended for that scnario. > > Alan G > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- -John Chandler ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Copy file as root

2008-06-11 Thread John Fouhy
way to do this in Python? Presumably you could do os.system('gksudo cp /home/user/Desktop/menu.lst /boot/grub') ? -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Newbie: Sorting lists of lists

2008-06-18 Thread John Fouhy
st): return lst[i] If you have an old version of python, this may not work. As an alternative, try googling for "decorate-sort-undecorate". -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] re adlines, read, and my own get_contents()

2008-06-18 Thread John [H2O]
eadlines() and file_object.readline() I think I understand the differences, but can someone tell me if there's any difference between what I define and the readlines() method? -john -- View this message in context: http://www.nabble.com/readlines%2C-read%2C-and-my-own-get_contents%28%2

[Tutor] os.waitpid non spawned pid

2008-06-20 Thread John [H2O]
Hello, I would like to write a script that would have a command line option of a pid# (known ahead of time). Then I want my script to wait to execute until the pid is finished. How do I accomplish this? I tried the following: #!/usr/bin/env python import os import sys def run_cmd(cmd): """RU

Re: [Tutor] endless processing through for loop

2008-06-22 Thread John Fouhy
0 takes an additional 4 hours. > > Any ideas about what could be going on? What happens if you reverse the loop? i.e. change to: for i in xrange(69, -1, -1): -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] references to containing objects

2008-06-22 Thread John Gunderman
a dict of the container_objects, so when the object was created the name could be passed to the action() method, but is there another way to do it? Thanks in advance. John ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] closing a internet explorer com object

2008-06-24 Thread John Chandler
onstants.OLECMDID_PRINT, > win32com.client.constants.OLECMDEXECOPT_DONTPROMPTUSER) > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > -- -John Chandler ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] closing a internet explorer com object

2008-06-24 Thread John Fouhy
that includes effectively method signatures for the different COM objects you can control. By inspecting this, you may be able to learn what methods you can call on InternetExplorer.Application objects and what arguments you need to give them. -- John.

Re: [Tutor] Python to exe--how much work?

2008-06-24 Thread John Fouhy
are in the bundle. (e.g. something like "from PIL import GifImagePlugin" if you will be using GIFs) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Object attributes surviving deletion

2008-06-26 Thread John Fouhy
ually clear gram.database because > otherwise it keeps the data from previous calls to that function. I think the OP is asking why this step is necessary. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-29 Thread John Fouhy
do you understand how assignment with slices works? e.g. can you predict the result of the following operations without trying it? a = [1, 2, 3, 4] a[1:3] = [7, 8] print a -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Is "var = None" in Python equivalent to "Set var

2008-06-29 Thread John Fouhy
t there are no cases where obj==None and obj is None will give different results (which is not true for == vs is in general), so is there any practical difference? Maybe you save a handful of cycles? -- John. ___ Tutor maillist - Tutor@python.org

Re: [Tutor] Is "var = None" in Python equivalent to "Set var

2008-06-30 Thread John Fouhy
er than implicit, but worrying about what happens to local variables when they go out of scope is a bridge too far for most people. (I don't want to criticise VB programmers because I am not one. "Follow the local conventions" is generally always a good rule of programming) -- J

Re: [Tutor] TypeError: not enough arguments for format string

2008-07-01 Thread John Fouhy
,%f)" % self.x, self.y" as "point_str = ("(%f,%f)" % self.x), self.y". There are two "%f" expressions in the string, but you only supplied one argument, self.x. Thus python tells you that there aren't enough arguments. To deal with this, you need t

Re: [Tutor] random.choice()

2008-07-02 Thread John Fouhy
ypeError: # do something else -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Fibonacci series(perhaps slightly off topic)

2008-07-02 Thread John Fouhy
tem__) (by the way 2: if you follow the above code, and then display f.fibsseq, you may see some nice curves caused by the " " between each number. Aren't fibonacci numbers wonderful :-) ) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] random.choice()

2008-07-02 Thread John Fouhy
On 03/07/2008, Alan Gauld <[EMAIL PROTECTED]> wrote: > "John Fouhy" <[EMAIL PROTECTED]> wrote > > you can instead say: > > > > try: > > foo() > > except TypeError: > > # do something else > This makes slightly more sense,

Re: [Tutor] While loop counter

2008-07-07 Thread John Fouhy
mes you will execute your loop, you should use a for loop instead: for i in range(5): # the stuff you want to do goes here HTH! -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to create array of variants?

2008-07-07 Thread John Fouhy
> myList = [100, 'Test application'] >>> myList[0] 100 >>> myList[1] 'Test application' I recommend reading a python tutorial if this is new to you. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] line class

2008-07-07 Thread John Fouhy
inedSlopeError" or "VerticalLineError" exception and raise that instead of the ZeroDivisionError) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to create array of variants?

2008-07-08 Thread John Fouhy
On 09/07/2008, Kelie <[EMAIL PROTECTED]> wrote: > I think comtypes or pywin32 do take care of some conversion between Python > types and VB types. But they don't work with AutoCAD. Hi Kelie, This is a short excerpt from _Python Programming on Win32_: """In many cases, PythonCOM can translate be

Re: [Tutor] build list of non-empty variables

2008-07-08 Thread John Fouhy
On 09/07/2008, bob gailer <[EMAIL PROTECTED]> wrote: > or just [ x for x in LIST if x ] or filter(None, LIST). But that's a bit obscure. (fractionally faster, though, according to my brief experiment with timeit) -- John. ___

Re: [Tutor] line class

2008-07-08 Thread John Fouhy
d, at the expense of readability: Morpork:~ repton$ python -m timeit -s 'dx, dy = (8, 5)' -s 'import math' -s 'hyp = math.hypot' 'hyp(dx, dy)' 100 loops, best of 3: 0.501 usec per loop ) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] build list of non-empty variables

2008-07-09 Thread John Fouhy
#x27;or_test' with 'old_expression'. At any rate, here is one difference: >>> a = range(5) >>> b = range(5, 10) >>> [x for x in a, b] [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]] >>> (x for x in a, b) File "", line 1 (x for x in a

Re: [Tutor] build list of non-empty variables

2008-07-09 Thread John Fouhy
On 10/07/2008, Kent Johnson <[EMAIL PROTECTED]> wrote: > On Wed, Jul 9, 2008 at 9:38 PM, John Fouhy <[EMAIL PROTECTED]> wrote: > > Is the generator expression grammar right? How do I parse, e.g., > > '(x+1 for x in range(10))'? Seems like there's no

Re: [Tutor] Basic Help Implementing Saved Scripts

2008-07-09 Thread John Fouhy
Check out the tutorial: http://docs.python.org/tut/node8.html -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Tree Ctrl Data Structure - Help, please!

2008-07-15 Thread John Fouhy
, [('los angeles', []), ('san francisco', [])]), ('texas', [('detroit', [])])]), # etc ] This lets you avoid messy isinstance testing to figure out if you've got a value or a list of children. (admittedly, it can be hard to keep track of the brackets, but good indentation and a monospaced font should help out) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Any way of monitoring a python program's memory utilization?

2008-07-16 Thread John Fouhy
powerful. Look at http://searchsecurity.techtarget.com/tip/0,289483,sid14_gci1303709,00.html for example. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Tree Ctrl Data Structure - Help, please!

2008-07-16 Thread John Fouhy
ooking at your other email, my guess is that you want to start with SQL looking something like this: select continent, country, state from world_globe with the intention of getting back data that looks like: [('America', 'United States', 'California'), ('America', 'United States, 'Texas'), ('America', 'United States, 'Washington'), ('America', 'Canada', 'Ontario'), ('Asia', 'Japan', None), # etc ] It would be fairly straightforward to take data looking something like that and produce a tree. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Tree Ctrl Data Structure - Help, please!

2008-07-16 Thread John Fouhy
t to a dictionary like this: world_dict = { 'north america':['united states', 'canada'], 'asia':['japan', 'china'], 'africa':['zimbabwe'] } Your function should start like this: def tupes_t

Re: [Tutor] creating pop method for stack class

2008-07-17 Thread John Fouhy
r own exception... > def peek(self): > length = len(self) > if length == 0: > return 0 The same applies here -- peeking at an empty stack should be an error too. Otherwise, how can you tell the difference between an empty stack and a stack where the top

Re: [Tutor] creating pop method for stack class

2008-07-18 Thread John Fouhy
Type "help", "copyright", "credits" or "license" for more information. >>> def setXTo3(): ... x = 3 ... >>> setXTo3() >>> print x Is that the result you expect? If not, can you explain it after reading the web pages above? If it is w

Re: [Tutor] Raw string

2008-07-20 Thread John Fouhy
;e:\\mm tests\\1. exp files\\5.MOC-1012.exp\n' which, apart from the newline on the end, looks like exactly what you want. If this isn't working for you, can you show what is going wrong? -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Newbie

2008-07-24 Thread John Fouhy
On 25/07/2008, Sam Last Name <[EMAIL PROTECTED]> wrote: > Here wats i got so far. :) and also, is there a function for square root? Have a look at the math module. (you can also do fractional exponentiation.. remember, sqrt(x) is the same as x**0.5)

Re: [Tutor] Newbie

2008-07-24 Thread John Fouhy
teger (-b) to a list ([..]). I recommend reading through the tutorial on python.org. PS. Please use the reply-all when using this mailing list so other people can follow the conversation if they wish to. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Memory error - how to manage large data sets?

2008-07-28 Thread John Fouhy
storing a third of the Fibonacci numbers (the even ones), so we can cut that down to thirteen gigabytes. Assuming my maths is correct and there's not too much overhead in Python long integers :-) (the solution, of course, is to avoid storing all those numbers in the first place) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Obtaining various combinations of a given word

2008-07-29 Thread John Fouhy
another thought for you, once you've solved this problem: what answer would you expect for the string 'aaa'?) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] understanding join

2008-07-30 Thread John Fouhy
x27;.join('abc') 'aabcbabcc' Let's change the call slightly to make things more clear: >>> 'abc'.join('ABC') 'AabcBabcC' Does that make the pattern more clear? -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] understanding join

2008-07-30 Thread John Fouhy
x27;ABC'), you get: 'ABC'[0] + 'abc' + 'ABC'[1] + 'abc' + 'ABC'[2] which is: 'A' + 'abc' + 'B' + 'abc' + 'C' Hope this helps. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] understanding join

2008-07-30 Thread John Fouhy
, it might be easier to just do: '\n'.join(','.join(row) for row in data) I guess it depends what kind of programming you're doing, but in my experience, .join() is definitely a useful function. -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] checking for expected types from input file

2008-07-30 Thread John Fouhy
ch may alert you to broken data, or which you can catch and deal with. 3. If a variable has a bad value (like a string where it should have a float), the code will raise a ValueError, which again will alert you to a problem. (note that str() works on everything, and int() works on floats and vice versa, s

Re: [Tutor] Firefox Bookmarks

2008-08-14 Thread John Fouhy
t -- had to take a copy of the database and inspect this. It seems that firefox keeps a transaction open which has the effect of locking the whole database (SQLite supports concurrent access, but it can only lock the entire database). I guess that's fair enough -- from Firefox's point of

[Tutor] python-ldap installation

2008-08-16 Thread John DeStefano
ssible, or the best way to do it on different platforms. ~John [1] http://www.agescibs.org/mauro/ [2] http://bluedynamics.com/articles/jens/python-ldap-as-egg-with-buildout ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] pwd lib probs

2008-08-18 Thread John Fouhy
get > > gid = pwd.getpwnam(apache2_user)[pwd.pw_gid] > AttributeError: 'module' object has no attribute 'pw_gid' > [EMAIL PROTECTED]:~/kmotion2$ sudo ./install.py > > What am I missing ? I haven't used the pwd module, but at

[Tutor] Python proxy settings in OS X

2008-08-18 Thread John DeStefano
only one copy of each version installed, but I'm not sure which versions would screw things up if they were to be removed. Thanks for your help in understanding Python and proxy settings, and how to fix settings if possible. Thank you, ~John [1] http://

Re: [Tutor] Why does the Hex builtin function in Python return a string ?

2008-08-25 Thread John Fouhy
ent string representation from the default. If you want to change python to display integers in hex instead of decimal by default, I can't help you.. (well, maybe you could subclass int, and change __repr__ and __str__ to return hex strings) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

<    4   5   6   7   8   9   10   11   >