Re: getting dir(x), but not as list of strings?

2008-05-21 Thread Gary Herron
Use the builtin vars to get a dictionary of names and associated objects. import sys for name,ob in vars(sys).items(): print name,type(ob) Gary Herron setrecursionlimit getfilesystemencoding path_importer_cache stdout version_info exc_clear prefix getrefcount byteorder

Re: Calling class method by name passed in variable

2008-05-22 Thread Gary Herron
? Use getattr (stands for get attribute) to do this. fn = getattr(x, v) # Get the method named by v fn(...)# Call it Or in one line: getattr(x,v)(...) Gary Herron PHP code for this would be: class X { function a() { } } $x = new X(); $v = 'a'; $x->$v();

Re: error using all()/numpy [TypeError: cannot perform reduce with flexible type]

2008-05-23 Thread Gary Herron
Python's "all" first under another name: original_all = all from numpy import all Now you can call all(...) or original_all(...). The built-in (as they are called) are always available through __builtins__: from numpy import * all(...) # is numpy's all __b

Re: New chairman

2008-05-27 Thread Gary Herron
Max M wrote: Sverker Nilsson skrev: I was talking about Guido van Rossum The one who decides, so far when people agree I have been using Python since the nineties. I cannot remember when I have had to rewrite old code because of changes in the language. At the same time I have been feeling

Re: Maximum items in a list?

2008-05-27 Thread Gary Herron
Zerge wrote: Hi, Is there a theoretical limit to the number of items that can be appended to a list? thanks -- http://mail.python.org/mailman/listinfo/python-list No, only practical limits of memory, time and such. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: multi dimensional dictionary

2008-05-27 Thread Gary Herron
of keys you would have used in your multidimensional dictionary. mydict[(0,"person","setTime")] = "12:09:30" mydict[(0,"person","clrTime")] = "22:09:30" Would that work for you? Gary Herron Can someone help me with right declaratio

Re: Any way to loop through object variables?

2008-05-28 Thread Gary Herron
er these rather than getting at them by name. Cheers, Dave For this object (and many others), you can get at the attributes with the vars(...) builtin. It returns a dictionary of attribute names and values. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.pyt

Re: accessing class attributes

2008-05-28 Thread Gary Herron
es RUNNING = 0 PAUSED = 1 GAMEOVER = 2 then later: class Game: ... if state == RUNNING: ... Or try this shortcut (for the exact same effect): RUNNING, PAUSED, GAMEOVER = range(3) Gary Herron Later, each time I want to assign a variable some state, or check for the

Re: code of a function

2008-05-29 Thread Gary Herron
Dark Wind wrote: Hi, Is there any command in Python which gives the code for a function like just typing the name of a function (say svd) in R returns its code. Thank you Nope. -- http://mail.python.org/mailman/list

Re: Tuple of coordinates

2008-05-29 Thread Gary Herron
j in b for k in c] #Nested loop give all possible combos. [(2, 3, 10), (2, 3, 12), (2, 5, 10), (2, 5, 12), (4, 3, 10), (4, 3, 12), (4, 5, 10), (4, 5, 12)] >>> Gary Herron Can anyone give me some advice on how to achieve this ? I got a little idea, but still need to keep worki

Re: Cast list of objects to list of strings

2008-06-02 Thread Gary Herron
ot; ".join(objs)+"\n") but I lose the property that the function works on any object. No you don't. If you were happy with printing the str(...) of a single objects, why not just printout the (concatenation) of the str(...) of each of many objects? stderr.write(" &quo

Re: Importing xlrd

2008-06-02 Thread Gary Herron
into that directory python setup.py build python setup.py install Then your import should work fine. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: "Faster" I/O in a script

2008-06-02 Thread Gary Herron
un. If the results are not clearcut, then try some real profiling. Gary Herron Thanx in advance for the time reading this. Pantelis -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: "Faster" I/O in a script

2008-06-02 Thread Gary Herron
ngs) as the iterator PLUS allocate and build a list. Better to just use the iterator. for line in file: ... Gary Herron -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: os.path.walk -- Can You Limit Directories Returned?

2008-06-05 Thread Gary Herron
learing dirs means recurse into NO subdirectory of path ... process the files of directory path... Gary Herron Any help and/or advice would be appreciated. - Jeff -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: Interesting Math Problem

2008-06-05 Thread Gary Herron
ariable named "stars." Much simpler this way. This produces the number of whole start and the number of half stars: v = ... calculate the average ... whole = int(v+0.25) half = int(2*(v+0.25-whole)) Gary Herron My Solution (in Python): # round to one decimal place and # separate i

Re: Newb question: underscore

2008-06-05 Thread Gary Herron
named __doc__. The underscores have no special significance here, but they do make the code hard to read. The first part of the statement directs the print to send the output to a file, named fd, which was presumably opened earlier ... but I don't think that was part of your question. Gar

Re: Change in interactive interpreter?

2008-06-06 Thread Gary Herron
enable it? Thanks! Try again. I think you'll find it's still there -- although you have to execute a something that returns a value before it's set for the first time. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: Learning which modules were loaded

2008-06-06 Thread Gary Herron
y that contains all the imported modules, but I suspect you'll find that it's much easier to let py2app and py2exe determine what's imported than it is to go through sys.modules yourself. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: Can this be done with list comprehension?

2008-06-07 Thread Gary Herron
Karlo Lozovina wrote: This is what I'm trying to do (create a list using list comprehesion, then insert new element at the beginning of that list): result = [someFunction(i) for i in some_list].insert(0, 'something') But instead of expected results, I get None as `result`. If instead of cal

Re: Can I find out (dynamically) where a method is defined?

2008-06-09 Thread Gary Herron
ned). Poke around and perhaps you can find exactly what you are looking for. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: Separators inside a var name

2008-06-09 Thread Gary Herron
Rainy wrote: I have a stylistic question. In most languages words in var. name are separated by underscores or cap letters, resulting in var names like var_name, VarName and varName. I don't like that very much because all 3 ways of naming look bad and/or hard to type. From what I understand, sch

proposal: give delattr ability to ignore missing attribute

2008-06-10 Thread Gary Wilson
instead of: try: delattr(obj, 'foo') except AttributeError: pass or: try: del obj.foo except AttributeError: pass or: if hasattr(obj, 'foo') delattr(obj, 'foo') For backwards compatibility, allow_missing would default to False. Gary -- http://mail.python.org/mailman/listinfo/python-list

Re: How to find duplicate 3d points?

2008-06-11 Thread Gary Herron
n) or so. Happy google-ing and good luck. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: howto split string with both comma and semicolon delimiters

2008-06-12 Thread Gary Herron
fo/python-list The regular expression module has a split function that does what you want. >>> import re >>> r =',|;' # or this also works: '[,;]' >>> s = "a,b;c" >>> re.split(r,s) ['a', 'b', 'c'] Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: Another (perhaps similar) import question

2008-06-13 Thread Gary Herron
purious attributes do not remain? No. Conclusion: Don't use reload (ever). A dozen years of Python programming, and I've never used it even once. If there is a good use case for reload, you are probably years from being there. Thanks again (and apologies of this is a stupid question) Not stupid. It will all start making sense soon. Gary Herron Dan -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: Another (perhaps similar) import question

2008-06-13 Thread Gary Herron
? No. Conclusion: Don't use reload (ever). A dozen years of Python programming, and I've never used it even once. If there is a good use case for reload, you are probably years from being there. Gary, thanks very much for your help.I suspected it was something lik

Re: Ternary operator alternative in Ptyhon

2008-06-17 Thread Gary Herron
are executed (or not) just as you like. self.SomeField = params["mykey"] if params.has_key("mykey") else None Gary Herron Obviously I know this is not actual Python syntax, but what would be the equivalent? I'm trying to avoid this, basically: if params.ha

Re: Python "is" behavior

2008-06-20 Thread Gary Herron
value is a trade off (like any caching scheme) of cache-space versus efficiency gains. The value has changed at least once in recent versions of Python. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: -1/2

2008-06-22 Thread Gary Herron
Serve Lau wrote: What is the expected result of -1/2 in python? -- http://mail.python.org/mailman/listinfo/python-list From the manual: The result is always rounded towards minus infinity: 1/2 is 0, (-1)/2 is -1, 1/(-2) is -1, and (-1)/(-2) is 0. Gary Herron -- http://mail.python.org

Re: -1/2

2008-06-22 Thread Gary Herron
Christian Heimes wrote: Serve Lau wrote: What is the expected result of -1/2 in python? 0 No. That's not right. (It would be in C/C++ and many other languages.) See my other response for the correct answer. Gary Herron Christian -- http://mail.python.org/ma

Re: Passing arguments to subclasses

2008-06-23 Thread Gary Herron
ldClass(123,456) ParentClass.__init__ called with 123 456 >>> Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

32-bit python memory limits?

2008-06-23 Thread Gary Robinson
g of a 2GB limit wrong? I guess so! But I'm pretty sure I saw it max out at 2GB on linux... Anybody have an explanation, or is it just that my understanding of a 2GB limit was wrong? Or was it perhaps right for earlier versions, or on linux...?? Thanks for any thoughts, Gary -- Gary Robins

Re: How to import filenames with special characters?

2008-06-24 Thread Gary Herron
in function and the standard module named "imp". Gary Herron * * -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: where is the error?

2008-06-26 Thread Gary Herron
line again? First thing: Find out what value that index has, then if it's necessary to ask your question again, include that information and we'll have something to go on in forming an answer. Gary Herron I have this error message: IndexError: each subindex must be either a slice, an

Re: I Need A Placeholder

2008-06-26 Thread Gary Herron
pass Gary Herron The only problem is if I leave a comment only in the except block, I get an error back saying that the except block is not properly formatted, since it has no content other than a comment. So if anyone could suggest some code to put there as a placeholder that would be wond

Re: Use of the "is" statement

2008-06-27 Thread Gary Herron
, or stored twice. In short: *never* use "is". (A longer answer can find some uses cases for "is", but stick with the short answer for now.) Gary Herron Python 2.5.2 >>> 'string' is 'string' #simple assignment works

Re: 2D online multiplayer framework?

2008-06-28 Thread Gary Herron
-- http://mail.python.org/mailman/listinfo/python-list Pyglet is my favorite: http://www.pyglet.org/ Twisted might be fine for the "online multiplayer" parts, but really if you want a 2D/3D real-time game, start with a game framework. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: Attribute reference design

2008-07-01 Thread Gary Herron
chamalulu wrote: On Jul 1, 11:24 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: chamalulu schrieb: Hello. I think I'm aware of how attribute access is resolved in python. When referencing a class instance attribute which is not defined in the scope of the instance, Python looks for

Re: Attribute reference design

2008-07-01 Thread Gary Herron
chamalulu wrote: On Jul 2, 1:17 am, Gary Herron <[EMAIL PROTECTED]> wrote: No need. Also, you can define a class attribute (C++ might call it a static attribute) and access it transparently through an instance. class C: aClassAttribute = 123 def __init__(self, ...): ...

Re: dynamically load from module import xxx

2008-07-02 Thread Gary Duzan
7;modulename.xxx', fromlist=['xxx']) Seems a bit weird to me, but that's the way it is, and I'm sure there is a reason for it. Good luck. Gary Duzan Motorola H&NM -- http://mail.python.org/mailman/listinfo/python-list

Re: "in"consistency?

2008-07-07 Thread Gary Herron
he obvious differences (mutability, sorting and other methods, types of individual elements), I'd say there are more differences than similarities, even though, as sequences, they both support a small subset of similar operations. Gary Herron David C. Ullrich wrote: Luckily I tried i

Re: No Exceptions

2008-07-08 Thread Gary Herron
'd suggest looking carefully throughout the code. Gary Herron Thank you, Robert -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: Opening Unicode files

2008-07-09 Thread Gary Herron
but rather some instance object you've assigned into it: codecs = ...something overwriting the module object ... Gary Herron I wonder if I need to do something before using the codecs library from within the cgi module

Re: Can anyone suggest a date peocedure...

2008-07-10 Thread Gary Herron
me right now and the time exactly one day ago: >>> from datetime import * >>> datetime.today() datetime.datetime(2008, 7, 10, 13, 38, 48, 279539) >>> datetime.today()-timedelta(1) datetime.datetime(2008, 7, 9, 13, 38, 50, 939580) Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: Can anyone suggest a date peocedure...

2008-07-10 Thread Gary Herron
RV wrote: On Thu, 10 Jul 2008 13:39:29 -0700, Gary Herron <[EMAIL PROTECTED]> wrote: The datetime module has what you need. It has methods (with examples) on building a datetime object from a string, and it has a object named timedelta, and the ability to subtract a timedelta

Re: Someone enlightened me

2008-07-13 Thread Gary Herron
ming/#what-are-the-rules-for-local-and-global-variables-in-python Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: Mutually referencing imports -- impossible?

2008-07-13 Thread Gary Herron
e (interrupted) import of module ABC has not progressed to the point that abc is defined. The solution: Just import ABC and later reference ABC.abc That being said, it is still a good design practice to structure your modules hierarchically rather than a circularly. Gary Herron -- http:

Re: how to match whole word

2008-07-15 Thread Gary Herron
man/listinfo/python-list The regular expression "\w+" will match (what might be your definition of) a word, and in particular will match abc in :abc:. Regular expressions have lots of other special \-sequences that might be worth your while to read about: http://docs.python

Re: Angle brackets in command-line arguments?

2008-07-16 Thread Gary Herron
en instead of in file. Also various shells will provide similar functionality using a variety of similar syntaxes: <<, >>, >&, and |, and so on. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: unpacking with default values

2008-07-17 Thread Gary Herron
or shortens an input tuple of arguments to the correct length so you can do: a,c,b = fix(1,2) d,e,f = fix(1,2,3,4) However, the function won't know the length of the left hand side sequence, so it will have to be passed in as an extra parameter or hard coded. Gary Herron -- http:

Re: properly delete item during "for item in..."

2008-07-17 Thread Gary Herron
a list's length will interact badly with the for loop's indexing through the list, causing the loop to mis the element following the deleted item. Gary Herron I am not sure if this question even makes any sense anymore. I've been using python for years and never had any probl

Re: unpacking with default values

2008-07-17 Thread Gary Herron
McA wrote: On 17 Jul., 18:33, Gary Herron <[EMAIL PROTECTED]> wrote: In Python 2.x, you can't do that directly, but you should be able to create a function that lengthens or shortens an input tuple of arguments to the correct length so you can do: a,c,b = fix(1,2) d,e,f =

Re: properly delete item during "for item in..."

2008-07-17 Thread Gary Herron
Ratko wrote: On Jul 17, 9:57 am, mk <[EMAIL PROTECTED]> wrote: Gary Herron wrote: You could remove the object from the list with del myList[i] if you knew i. HOWEVER, don't do that while looping through the list! Changing a list's length will interact badly wit

Re: Any Game Developers here?

2008-07-18 Thread Gary Herron
active new groups.) Pygame: http://www.pygame.org/news.html Pyglet: http://pyglet.org/ Gary Herron ~Michael -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting List of String to Integer

2008-07-21 Thread Gary Herron
me: >>> a = [['1', '2'], ['3'], ['4', '5', '6'], ['7', '8', '9', '0']] >>> n = [] >>> for k in a: ...n.append([int(v) for v in k]) ... >>> print n [[1, 2], [3], [4, 5, 6], [7, 8, 9, 0]] (Although you seem to have confused variables b and n.) Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting List of String to Integer

2008-07-21 Thread Gary Herron
Samir wrote: On Jul 21, 3:20 pm, Gary Herron <[EMAIL PROTECTED]> wrote: Samir wrote: Hi Everyone, I am relatively new to Python so please forgive me for what seems like a basic question. Assume that I have a list, a, composed of nested lists with string represent

Re: string[i:j:k]

2008-07-21 Thread Gary Herron
27;97531' but s[:-1:-2] The slice s[:-1] means start at zero and go to n-1(where n-len(s)) (it does not mean start at zero and go to -1) So since the indexing is counting upward, the step size had better be positive. Thus: >>> s = '123456789' >&g

Re: Reading a file

2008-07-24 Thread Gary Herron
slashes. But that's just because of the method you used to print to the screen. What method *did* you use to print? If you just typed the variable into which you had read the contents, then you get the equivalent of print repr(c) which explains the escapes. Try print c and tha

Re: How to find processes from Python

2008-07-25 Thread Gary Josack
Cameron Simpson wrote: On 25Jul2008 11:34, Johny <[EMAIL PROTECTED]> wrote: | Is there a way how to find out running processes?E.g. how many | Appache's processes are running? See the popen function and use the "ps" system command. Use of the popen functions is generally discouraged since be

Re: Simple Path issues

2008-07-26 Thread Gary Josack
advance -- http://mail.python.org/mailman/listinfo/python-list sys.path is a list that will tell you where python is looking. You can append to this in your scripts to have python look in a specific directory for your own modules. Thanks, Gary M. Josack -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple Path issues

2008-07-26 Thread Gary Josack
Brett Ritter wrote: On Jul 26, 2:57 pm, Gary Josack <[EMAIL PROTECTED]> wrote: sys.path is a list that will tell you where python is looking. You can append to this in your scripts to have python look in a specific directory for your own modules. I can, but that is almost cer

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Gary Herron
would consider equivalent to False. If you know A will never be equivalent to False then you can use just this: C and A or B Gary Herron And while I'm on my high horse, I'd like to bring up list concatenations. I recently needed to concatenate 5 lists, which doesn't sound a

Re: Rant (was Re: x*x if x>10

2008-07-27 Thread Gary Herron
on and sum() both do what you want. >>> A = [1,2,3] >>> B = [4,5,6] >>> C = [7,8,9] >>> A+B+C [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> sum([A,B,C], []) [1, 2, 3, 4, 5, 6, 7, 8, 9] It doesn't get any easier than that. Gary Herron DaveM -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: Where is the correct round() method?

2008-07-27 Thread Gary Herron
loating point), 2.5 should be representable exactly. However, as with any floating point calculations, if you expect exact representation or calculations with any numbers, then you are misusing floating points. Gary Herron I would think this is a common need, but I cannot find a function in th

Re: Where is the correct round() method?

2008-07-27 Thread Gary Herron
will work as you wish: math.floor(x+0.5) Gary Herron -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: python lists and newline character

2008-07-28 Thread Gary Herron
y I can get this list without the newline characters being added. or somehow remove the newline characters. Any help would be appreciated. The problem has nothing to do with lists. The readlines() function returns each line *with* its newline. To strip it off, use line.strip()

Re: seemingly simple list indexing problem

2008-07-28 Thread Gary Herron
Guilherme Polo wrote: On Mon, Jul 28, 2008 at 6:24 PM, Ervan Ensis <[EMAIL PROTECTED]> wrote: My programming skills are pretty rusty and I'm just learning Python so this problem is giving me trouble. I have a list like [108, 58, 68]. I want to return the sorted indices of these items in the

Re: derivative in numpy

2008-07-28 Thread Gary Herron
omial? Gary Herron Cheers, Kim -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: How to figure out if the platform is 32bit or 64bit?

2008-07-28 Thread Gary Josack
Trent Mick wrote: Manuel Vazquez Acosta wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Just test for maxint value: from sys import maxint if maxint >> 33: print "more than 32 bits" # probably 64 else: print "32 bits" I believe that was already suggested in this thread. That tes

Re: python lists and newline character

2008-07-28 Thread Gary Josack
Gary Herron wrote: Support Desk wrote: Hello all, I am using os.popen to get a list returned of vpopmail users, something like this x = os.popen('/home/vpopmail/bin/vuserinfo -n -D mydomain.com).readlines() x returns a list, of usernames, and I am trying to appen

Re: exec(code) not allowing import on top level?

2008-07-28 Thread Gary Herron
es it.Second, if I exend your string with one more line "foo(123)" to actually execute the code, it still works as expected. So let's try this again... and this time please please also show us the full text of the error message. Gary Herron and i run it using exec(code) in

Re: exec(code) not allowing import on top level?

2008-07-28 Thread Gary Herron
es it.Second, if I extended your string with one more line "foo(123)" to actually execute the code, it still works as expected. So let's try this again... and this time please please also show us the full text of the error message. Gary Herron and i run it using exec(code) in

Re: Overloaded Functions

2008-07-29 Thread Gary Herron
nuimber of args, but their types, and even their values, before calling __sign_auth(...). Gary Herron Tim Henderson -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list

Re: Pointers/References in Python?

2008-07-30 Thread Gary Herron
ject exists, however, it is referred to many times. a = HeavyObject() b = a A = [a,b] B = [b,a] C = set([a,b]) D = {1:a, 2:b} ... and do on Implementation wise, a long list consumes about 4 bytes per list element (that's one address per), plus a tine amount of overhead. Gary Herron

Re: overriding file.readline: "an integer is required"

2008-07-30 Thread Gary Herron
e.readline(size) # etc., etc. I tested this (just barely), and it seems to work as you wish. Gary Herron TIA! Kynn -- http://mail.python.org/mailman/listinfo/python-list

Re: How smart is the Python interpreter?

2008-07-31 Thread Gary Herron
The 's+=a' line has terrible (quadratic) performance. Instead use the string method 'join' which has linear performance. def str_sort(string): return "".join(sorted(string)) No for loop, no inefficient accumulation. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: Searching for some kind of data type

2008-08-02 Thread Gary Herron
d = (perm, auth, arg, path, syntax), ABOR = (None, False, False, False, "ABOR (abort transfer)."), APPE = (None, False, False, True, "APPE file-name (append data to"), ... ] ftpCommands = {} for cmd,args in cmd_data.iteritems(): ftpCommands[cmd] = CommandProperty(*ar

Re: Continually check object status

2008-08-02 Thread Gary Herron
eduled) * user mouse/keyboard action * some state external to the program (file content, socket data, phase of the moon, price of tea in China, ...) Each of those possibilities would require a substantially different approach. Gary Herron I might be approaching this from the wrong direct

Re: xlrd

2008-08-04 Thread Gary Herron
are asking for a numeric value, so you get a zero. Should you be asking for a string value? (That's the way OpenOffice/python works if I remember correctly.) Or are you accessing a different cell because you've confused 0-based / 1-based indexing? Or are you using old outdated

Re: What Python looks like

2008-08-04 Thread Gary Herron
many words, no operators, how could that make a program???) My impression was (and still is): A page of Python code looks *clean*, with not a lot of punctuation/special symbols and (in particular) no useless lines containing {/} or begin/end or do/done (or whatever). Gary Herron Than

Re: Is there a faster way to do this?

2008-08-05 Thread Gary Herron
list comprehension... IDs = set(extractIdFromRow(row) for row in rowsOfTable) or some such would be most efficient. Gary Herron Heres the code: import string def checkForProduct(product_id, product_list): for product in product_list: if product == product_id: r

Re: Is there a faster way to do this?

2008-08-05 Thread Gary Herron
ore efficiently that you could. The code for line in open(input_file,"r"): reads in large chunks (efficiently) and then serves up the contents line-by-line. Gary Herron If you use a dictionary and search the ID's there, you'll notice some speed improvements as Python does a d

Re: problem with logic in reading a binary file

2008-03-29 Thread Gary Herron
you throw it all out and use the struct module: http://docs.python.org/lib/module-struct.html It is meant to solve this kind of problem, and it is quite easy to use. Gary Herron > Here is my function that takes in a string. > > def parseSequence(data, start): > >

Re: [OT] troll poll

2008-03-31 Thread Gary Herron
e can't tell the difference between castironpi and a *real* human (which we demonstrate whenever we try to respond to or reason with him/her/it), then castironpi can be declared to be a truly *intelligent* AI. AFAICT, there appears no danger of that happening yet. Gary Herron :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Beginner advice

2008-03-31 Thread Gary Herron
Paul Scott wrote: > I have been tasked to come up with an audio recorder desktop (cross > platform if possible - but linux only is OK) that: > > 1. records a lecture as an MP3 file (pymedia?) > 2. Provides a login form for server credentials > 3. Uploads via XMLRPC (pyxmlrpclib) to the server as a

Re: import multiple modules with same name

2008-03-31 Thread Gary Herron
Christian Bird wrote: > Is it possible to import multiple modules with the same name from > different locations? I'm using two different pieces of software, both > of which have a module named util.py. I know that I can modify > sys.path to fix which util gets imported when I do: > > import util

Re: Recursive function won't compile

2008-04-02 Thread Gary Herron
he extra set of parenthesis in the if don't cause any problem. So again please: Why are you surprised? Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: expanding a variable to a dict

2008-04-03 Thread Gary Herron
#x27;dictFoo' on the first iteration, 'dictBar' on the second, and so > forth? > > and/or less importantly, what is such a transformation called, to help > me target my searching? > > thanks > Try this: for a in [dictFoo, dictBar, dictFrotz]: if 'srcdir' in a: a['srcdir']='/usr/src' Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: expanding a variable to a dict

2008-04-03 Thread Gary Herron
idle wrote: > brilliant. > Hardly. Any perceived brilliance is in the design of Python, not our simple and hopefully effective use of it. :-) Gary Herron > thanks to both of you. > -- http://mail.python.org/mailman/listinfo/python-list

Re: Weird scope error

2008-04-05 Thread Gary Herron
e talking about.) So you'll have to fix the import for *every* module that needs access to ElementTree.You might make the change as you mentioned above for each, but really, I think you should just make ElementTree directly importable by either installing it normally or including .../xml/etree in your PYTHONPATH Gary Herron > Can anybody help? > > THanks > -- http://mail.python.org/mailman/listinfo/python-list

Re: Learning curve for new database program with Python?

2008-04-08 Thread Gary Duzan
understands) with multiple processes hitting it, and so our efforts to integrate Hibernate haven't been terribly smooth. In this environment the hack seems to be to have Hibernate write to its own tables, then have stored procedures sync them with the old tables. Not pretty.

Re: Trouble with list comprehension

2008-04-09 Thread Gary Herron
ndex) > goats = [ x for x in range(2) if doors[x] == 'G' ] > Using range(2) is wrong since range(2) is [0,1]. You want range(3) which gives [0,1,2]. Gary Herron > but for some reason the list comprehension is not always returning a > list with 2 elements in it (sometimes

Re: urgent question, about filesystem-files

2008-04-10 Thread Gary Herron
ll us *which* OS you're working on. Then, perhaps someone can help... Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: Call a classmethod on a variable class name

2008-04-13 Thread Gary Herron
r... ... parameters.className = 'SomeClass' ... theClass = globals()[parameters.className] parameters.theClass.bar() (Hint: It matters not whether foo is a classmethod, saticmathod or normal method.) Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: Preferred method for "Assignment by value"

2008-04-15 Thread Gary Herron
s of L Dictionaries have a copy method that creates a new dictionary. Again this copy is only one level deep. The copy modules provides a more general way to copy objects. It provides the ability to produce both shallow and deep copies. A small note: In a dozen years of programming in Python

Re: Mailing list question

2008-04-16 Thread Gary Herron
python newbie wrote: > Hello, > Just curious; can I post a basic programming question to this mailing > list? You just did. :-) (Real answer: Yes. We're pretty newbie friendly here.) Gary Herron > > Thanks

Re: Can't see variables declared as global in a function

2008-04-16 Thread Gary Herron
x27;d have to know more about what problem you are trying to solve. If you really getters and setters (that's what we might call somefucn and anotherfunc) then you really should be using a class to contain all the hundred variables, and define getter/setter methods for them. Gary Herron

Re: Image handling - stupid question

2008-04-16 Thread Gary Herron
then I'd recommend numpy for the array manipulation. (And perhaps even the full-blown scipy.) Numpy can easily access and manipulate the pixel arrays produced by PIL. It's an awesome combination. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't do a multiline assignment!

2008-04-17 Thread Gary Herron
not -- consider it you needed to change CONSTANT2 to a different value some time in the future.) Gary Herron > In Python, you usually can use parentheses to split something over > several lines. But you can't use parentheses for an assignment of > several lines. For that,

<    3   4   5   6   7   8   9   10   11   >