Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread vk
> Unless you explicitly *never* intend sharing your code with *anyone*, > it's best to code all your Python code in accordance with PEP 8 anyway. Well said. Let's bury the puppy already. Anyone have something to say about the userio stuff? -- http://mail.python.org/mailman/listinfo/python-list

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread Ben Finney
s0s...@gmail.com writes: > On Jan 2, 7:20 pm, Ben Finney > wrote: > > They don't need to be creative; they merely need to conform with > > the naming scheme as laid out in the PEP. > > If it's something to be included in the standard library, I agree > (just for consistency, not because using_un

Re: Ideas to optimize this getitem/eval call?

2009-01-02 Thread Steven D'Aprano
On Fri, 02 Jan 2009 17:29:29 -0800, mario wrote: > Hi, > > below is the essence of a an expression evaluator, by means of a getitem > lookup. The expression codes are compiled and cached -- the lookup is > actually recursive, and the first time around it will always fail. > > import sys > class

Re: Ideas to optimize this getitem/eval call?

2009-01-02 Thread vk
What do you mean by 'fail'? you have; :: self.codes = {} so :: try: ::return eval(self.codes[expr], self.globals, self.locals) will always return an exception the first time (if this is what you're referring to). -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a better algorithm?

2009-01-02 Thread alex goretoy
I personally like this solution the best. Thanks mr. tuples = [(1, 2), (3, 4, 5), (6, 7)] def triple_or_pair(seq): u = None try: k, u, v = seq except ValueError: k, v = seq return k, u, v for k, u, v in [ triple_or_pair(seq) for seq in tuples ]: print k, u, v On Sat

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread vk
> etc etc ... IOW consider not biting off more than you can chew. It's possible that I am, but where's the fun without the risk? Good thinking in your post though! I will add "get_date" at some point, and I've modified "get_numeric" already. All-right, the moment you've all been waiting for: ---

Re: Is there a better algorithm?

2009-01-02 Thread Kottiyath
On Jan 3, 2:38 am, mr wrote: > As has been noted, the best is to fix the input to be regular-3- > tuples. For the fun of it, here's another variation of a solution: > > tuples = [(1, 2), (3, 4, 5), (6, 7)] > > def triple_or_pair(seq): >     u = None >     try: >         k, u, v = seq >     except

[no subject]

2009-01-02 Thread 4329402926
-- == This mobile text message is brought to you by AT&T -- http://mail.python.org/mailman/listinfo/python-list

Re: list iteration if statement

2009-01-02 Thread Steve Holden
alex goretoy wrote: > v should have ['3','4','1'] sorry if I made it confusing. > [...] Aah, I see I was giving you incorrect advice. I now realise that you want to flatten the lists as well. Don't try to do this with a list comprehension. It won't work without creating an unnecessary list of lis

Re: list iteration if statement

2009-01-02 Thread Steve Holden
alex goretoy wrote: > Thank you Steve and MRAB, > > This is what I was looking for: > > [[v.append(j) for j in i if j != 0] for i in self.value] > No, it wasn't. You should *not* be modifying v in the list comprehension! > the value is actually stored as a string so I would need to check if it

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread Russ P.
On Jan 2, 6:15 pm, s0s...@gmail.com wrote: > On Jan 2, 7:20 pm, Ben Finney > wrote: > > > vk writes: > > > > If there were, I would expect it to conform with PEP 8 (get those > > > > ugly camelCase names outta there :-) > > > > haha, please forgive me. > > > I'll try and think of some more creati

Re: list iteration if statement

2009-01-02 Thread Mensanator
On Jan 2, 8:43�pm, "alex goretoy" wrote: > rather, how do I suppress the output of the list with all None in it? > > >>> l=[['3'], ['0', '4'], ['0', '1'], ['0']] > >>> v=[] > >>> [[v.append(j)for j in i if j != "0"] for i in l] > > [[None], [None], [None], []] > > >>> v > ['39', '32', '1'] > Assi

Re: type conversion

2009-01-02 Thread r
On Jan 2, 7:46 pm, Steven D'Aprano wrote: ...incessant rambling about a news reader , 101 excuses for butting into a thread [snip] Throw your newsreader in the garbage and use Google groups, less headache, more filling! No need to worry about "hidden headers" And you may even get a star or 2 :)

Re: list iteration if statement

2009-01-02 Thread MRAB
alex goretoy wrote: Thank you Steve and MRAB, This is what I was looking for: [[v.append(j) for j in i if j != 0] for i in self.value] the value is actually stored as a string so I would need to check if it is "0". I do have one more question about list comprehension though. After doing thi

Re: list iteration if statement

2009-01-02 Thread alex goretoy
rather, how do I suppress the output of the list with all None in it? >>> l=[['3'], ['0', '4'], ['0', '1'], ['0']] >>> v=[] >>> [[v.append(j)for j in i if j != "0"] for i in l] [[None], [None], [None], []] >>> v ['39', '32', '1'] >>> On Sat, Jan 3, 2009 at 2:38 AM, alex goretoy wrote: > Thank yo

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread Steven D'Aprano
On Fri, 02 Jan 2009 21:02:19 -0500, Steve Holden wrote: > Ben Finney wrote: >> vk writes: >> If there were, I would expect it to conform with PEP 8 (get those ugly camelCase names outta there :-) >>> haha, please forgive me. >>> I'll try and think of some more creative names. >> >> Th

Re: list iteration if statement

2009-01-02 Thread Steven D'Aprano
On Sat, 03 Jan 2009 01:52:04 +, alex goretoy wrote: > Hello All, > > I'm doing this in my code > > [[v.append(j) for j in i] for i in self.value] > > if works and all, Replacing "self.value" with a list of lists of ints: >>> list_of_lists = [[1, 2, 3], [2, 4, 6]] >>> v = [] >>> output = [

Re: list iteration if statement

2009-01-02 Thread alex goretoy
v should have ['3','4','1'] sorry if I made it confusing. On Sat, Jan 3, 2009 at 2:43 AM, alex goretoy wrote: > rather, how do I suppress the output of the list with all None in it? > > >>> l=[['3'], ['0', '4'], ['0', '1'], ['0']] > >>> v=[] > >>> [[v.append(j)for j in i if j != "0"] for i in l]

Re: list iteration if statement

2009-01-02 Thread alex goretoy
Thank you Steve and MRAB, This is what I was looking for: [[v.append(j) for j in i if j != 0] for i in self.value] the value is actually stored as a string so I would need to check if it is "0". I do have one more question about list comprehension though. After doing this I get an unwanted list

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread r
On Jan 2, 6:57 pm, Andreas Waldenburger wrote: [snip] > You even assumed that distinction in your example: > > > >>> 'hello world".title() [snip] sorry, here is TitleCase.py_b2 py> 'hello world'.title().replace(' ', '') -- http://mail.python.org/mailman/listinfo/python-list

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread s0suk3
On Jan 2, 7:20 pm, Ben Finney wrote: > vk writes: > > > If there were, I would expect it to conform with PEP 8 (get those > > > ugly camelCase names outta there :-) > > > haha, please forgive me. > > I'll try and think of some more creative names. > > They don't need to be creative; they merely n

Re: list iteration if statement

2009-01-02 Thread Steve Holden
alex goretoy wrote: > Hello All, > > I'm doing this in my code > > [[v.append(j) for j in i] for i in self.value] > > if works and all, but I need to add a if statement in the mix. Can't > seem to remember the syntax to do so and everything I've tried seems to > fail. How do I add a check to see

Re: list iteration if statement

2009-01-02 Thread MRAB
alex goretoy wrote: Hello All, I'm doing this in my code [[v.append(j) for j in i] for i in self.value] if works and all, but I need to add a if statement in the mix. Can't seem to remember the syntax to do so and everything I've tried seems to fail. How do I add a check to see if j is not i

Re: Pass by reference

2009-01-02 Thread alex goretoy
You are correct, terminology is a must. In order to stay on the same page. And yes, it;s not technically by ref. but it works for me at the moment. I was doing this in my code: l={"user":"asdf","pass":"goog"} d= { "login_url":"http://example.com/login";, "user":l["user"], "pass":l["pas

Re: Pass by reference

2009-01-02 Thread alex goretoy
You are correct, terminology is a must. In order to stay on the same page. And yes, it;s not technically by ref. but it works for me at the moment. I was doing this in my code: l={"user":"asdf","pass":"goog"} d= { "login_url":"http://example.com/login";, "user":l["user"], "pass":l["pas

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread Steve Holden
Ben Finney wrote: > vk writes: > >>> If there were, I would expect it to conform with PEP 8 (get those >>> ugly camelCase names outta there :-) >> haha, please forgive me. >> I'll try and think of some more creative names. > > They don't need to be creative; they merely need to conform with the

list iteration if statement

2009-01-02 Thread alex goretoy
Hello All, I'm doing this in my code [[v.append(j) for j in i] for i in self.value] if works and all, but I need to add a if statement in the mix. Can't seem to remember the syntax to do so and everything I've tried seems to fail. How do I add a check to see if j is not int("0") then append to v

Re: type conversion

2009-01-02 Thread Steven D'Aprano
On Fri, 02 Jan 2009 15:49:25 -0800, Hamish McKenzie wrote: > I actually have no idea what ur talking about... aren't conversations > threaded by subject? Not usually. When you hit Reply to a post, your post gets a hidden header line that says "I'm a reply to post #12345" (whatever post number i

Ideas to optimize this getitem/eval call?

2009-01-02 Thread mario
Hi, below is the essence of a an expression evaluator, by means of a getitem lookup. The expression codes are compiled and cached -- the lookup is actually recursive, and the first time around it will always fail. import sys class GetItemEval(object): def __init__(self): self.globals

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread Ben Finney
vk writes: > > If there were, I would expect it to conform with PEP 8 (get those > > ugly camelCase names outta there :-) > > haha, please forgive me. > I'll try and think of some more creative names. They don't need to be creative; they merely need to conform with the naming scheme as laid out

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread John Machin
On Jan 3, 11:16 am, vk wrote: > > If there were, I would expect it to conform with PEP 8 (get those ugly > > camelCase names outta there :-) > > haha, please forgive me. > I'll try and think of some more creative names. > > atm, I've got a chem final to study for. > I'll probably post something re

Re: Reverse order of bit in repeating seqence of byte string

2009-01-02 Thread Gary Herron
imageguy wrote: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the str

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread Andreas Waldenburger
On Fri, 2 Jan 2009 16:44:11 -0800 (PST) r wrote: > On Jan 2, 6:26 pm, Andreas Waldenburger wrote: > > On Fri, 2 Jan 2009 16:16:10 -0800 (PST) vk wrote: > > > > > > If there were, I would expect it to conform with PEP 8 (get > > > > those ugly camelCase names outta there :-)   > > > > > haha, pl

Re: Why not Ruby?

2009-01-02 Thread Gerry Reno
There's been almost 50 responses to this rubbish post. Could you please all stop! -- http://mail.python.org/mailman/listinfo/python-list

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread r
On Jan 2, 6:26 pm, Andreas Waldenburger wrote: > On Fri, 2 Jan 2009 16:16:10 -0800 (PST) vk wrote: > > > > If there were, I would expect it to conform with PEP 8 (get those > > > ugly camelCase names outta there :-)   > > > haha, please forgive me. > > I'll try and think of some more creative nam

Re: Reverse order of bit in repeating seqence of byte string

2009-01-02 Thread John Machin
On Jan 3, 5:34 am, imageguy wrote: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbg

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread Andreas Waldenburger
On Fri, 2 Jan 2009 16:16:10 -0800 (PST) vk wrote: > > If there were, I would expect it to conform with PEP 8 (get those > > ugly camelCase names outta there :-) > > haha, please forgive me. > I'll try and think of some more creative names. FYI: The names themselves aren't he problem at all. T

Re: Why not Ruby?

2009-01-02 Thread Tim Greer
Don Geddis wrote: > Richard Riley wrote on Thu, 01 Jan 2009: >> Tim Greer writes: >>> That poster has a frequent habit of cross posting to multiple, >>> irrelevant >>> news groups. There's no rhyme or reason to it. >> >> No rhyme nor reason? It's quite clear, to me, why. How is a >> comparison

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread vk
> If there were, I would expect it to conform with PEP 8 (get those ugly > camelCase names outta there :-) haha, please forgive me. I'll try and think of some more creative names. atm, I've got a chem final to study for. I'll probably post something resembling useful code tomorrow morning. until

Re: type conversion

2009-01-02 Thread Christian Heimes
Hamish McKenzie schrieb: > I actually have no idea what ur talking about... aren't conversations > threaded by subject? Nope, they are threaded by message id. The subject is used as fallback only. Christian -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing Excel spreadsheets

2009-01-02 Thread John Machin
On Jan 3, 2:01 am, brooklineTom wrote: > On Dec 31 2008, 9:56 am, John Machin wrote: > > On Dec 31 2008, 4:02 pm, brooklineTom wrote: > > > > andyh...@gmail.com wrote: > > > > Hi, > > > > > Can anybody recommend an approach for loading and parsing Excel > > > > spreadsheets in Python. Any well

RE: type conversion

2009-01-02 Thread Hamish McKenzie
I actually have no idea what ur talking about... aren't conversations threaded by subject? -Original Message- From: python-list-bounces+hamish=valvesoftware@python.org [mailto:python-list-bounces+hamish=valvesoftware@python.org] On Behalf Of r Sent: Friday, January 02, 2009 1

Re: Reverse order of bit in repeating seqence of byte string

2009-01-02 Thread bearophileHUGS
imageguy: > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the string is created using ctypes.create_string_buffer function MRAB: >  >>> a.tostring() > '210543876' That's not the required 'rbgrbgrbgrbg', but you ar

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread Ben Finney
vk writes: > There needs to be a "user_io" or "sanitize" module in the standard > library to take care of this stuff. > Like: > > import userio > > logic = userio.userio() > > number = logic.getNumeric("blah: ") # will offer the user a "re-do" in > case of bad input > number = logic.forceGetNu

Re: Why not Ruby?

2009-01-02 Thread Don Geddis
Richard Riley wrote on Thu, 01 Jan 2009: > Tim Greer writes: >> That poster has a frequent habit of cross posting to multiple, irrelevant >> news groups. There's no rhyme or reason to it. > > No rhyme nor reason? It's quite clear, to me, why. How is a comparison > article not relevant when he i

Re: Reverse order of bit in repeating seqence of byte string

2009-01-02 Thread MRAB
Francesco Bochicchio wrote: imageguy ha scritto: I am looking for the most efficient method of replacing a repeating sequence in a byte string returned from a imaging .dll, connected via I receive the byte string with the following sequence 'bgrbgrbgrbgr' and I would like to convert this to 'rb

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread r
> There needs to be a "user_io" or "sanitize" module in the standard > library to take care of this stuff. [snip] +1 You are sooo right. You know, it is easy to forget about such things after you learn a language, i have written my own input logic, but i remember my __init__ days with python now a

Re: why cannot assign to function call

2009-01-02 Thread Erik Max Francis
Derek Martin wrote: On Fri, Jan 02, 2009 at 12:50:44PM -0800, Erik Max Francis wrote: Identity isn't defined on math objects, only on Python objects; there is no notion of 'is' in math. This is also false, it even has its own operator (which requires Unicode to display): ≡ That can mean a nu

Re: If your were going to program a game...

2009-01-02 Thread Tokyo Dan
On Jan 3, 12:02 am, J Kenneth King wrote: > Tokyo Dan writes: > > If your were going to program a game in python what technologies would > > you use? > > > The game is a board game with some piece animations, but no movement > > animation...think of a chess king exploding. The game runs in a > >

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread Andreas Waldenburger
On Fri, 2 Jan 2009 14:36:04 -0800 (PST) vk wrote: > There needs to be a "user_io" or "sanitize" module in the standard > library to take care of this stuff. > [snip example] > Great idea! +1 > ... but there isn't, as far as I know. Well, get to it, then. ;) /W -- My real email address is co

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread vk
> You might better do > > bet = int(raw_input("Enter your bet")) > > because then you don't need to later on convert bet again and again. This is all fine until you give it to an end-user. This is what I picture: $ ./script.py Enter your bet: $10 .. or perhaps "ten", "all", or a jillion other ta

Re: why cannot assign to function call

2009-01-02 Thread Derek Martin
On Fri, Jan 02, 2009 at 12:50:44PM -0800, Erik Max Francis wrote: >>> Identity isn't defined on math objects, only on Python objects; there >>> is no notion of 'is' in math. >> >> This is also false, it even has its own operator (which requires >> Unicode to display): ≡ > > That can mean a number

Request For (gozerbot) Testers

2009-01-02 Thread Bart Thate
So 0.9 is getting in shape and there is one issue that keeps me from releasing 0.9 and that is the upgrade path. 0.9 is vastely different from 0.8 so a special upgrade script has been written to aid with this. Now i have tested this on some gozerbot users but i need a more broader audience that wan

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread TechieInsights
You can use the built-in string formatting options and operations. 2.5: http://www.python.org/doc/2.5.2/lib/typesseq-strings.html 2.6: http://docs.python.org/library/string.html In essence, you can do: print "You still have $%i remaining" %(money) On Jan 2, 2:15 pm, sprad wrote: > I've done a g

Re: Is there a better algorithm?

2009-01-02 Thread mr
As has been noted, the best is to fix the input to be regular-3- tuples. For the fun of it, here's another variation of a solution: tuples = [(1, 2), (3, 4, 5), (6, 7)] def triple_or_pair(seq): u = None try: k, u, v = seq except ValueError: k, v = seq return k, u,

Re: Is there a better algorithm?

2009-01-02 Thread Aaron Brady
On Jan 2, 12:11 pm, Kottiyath wrote: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is:>>> for i in l: > > ...  u = None > ...  try: > ...   (k, v) = i > ...  except ValueErr

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread Diez B. Roggisch
sprad schrieb: I've done a good bit of Perl, but I'm new to Python. I find myself doing a lot of typecasting (or whatever this thing I'm about to show you is called), and I'm wondering if it's normal, or if I'm missing an important idiom. It is normal, although below you make things needlessly

Re: Noob question: Is all this typecasting normal?

2009-01-02 Thread Benjamin Kaplan
On Fri, Jan 2, 2009 at 4:15 PM, sprad wrote: > I've done a good bit of Perl, but I'm new to Python. > > I find myself doing a lot of typecasting (or whatever this thing I'm > about to show you is called), and I'm wondering if it's normal, or if > I'm missing an important idiom. > > For example: >

Re: why cannot assign to function call

2009-01-02 Thread Derek Martin
On Fri, Jan 02, 2009 at 09:05:51PM +0100, Bruno Desthuilliers wrote: >> Python seems rather weird, and I think from the frequency >> with which these discussions occur on this list, clearly it *IS* >> difficult for a neophyte Python programmer to understand the >> assignment model. > > Took me abou

Re: If your were going to program a game...

2009-01-02 Thread Terry Reedy
Jean-Paul Calderone wrote: No, PyPy includes an RPython to JavaScript compiler. RPython and Python are different languages. My impression from a few years ago is that RPython stands for Restricted Python and that it was/is? a proper subset of Python. Has this changed? -- http://mail.pyth

Re: is there a way to determine a relative path to the script?

2009-01-02 Thread TechieInsights
Note: The os.path.relpath is new in 2.6. If you are using an older version you will have to write your own algorithm TechieInsights wrote: > import os > os.path.relpath('/path/to/your/file', os.path.dirname(__file__)) > > tekion wrote: > > Hello, > > I have a script in /usr/local/app/mypython.py

Re: Is there a better algorithm?

2009-01-02 Thread Gerhard Häring
Kottiyath wrote: I have the following list of tuples: L = [(1, 2), (3, 4, 5), (6, 7)] I want to loop through the list and extract the values. The only algorithm I could think of is: [...] If this is part of a real program, instead of an exercise, you should fix the code that creates this list

Re: Py2exe issue

2009-01-02 Thread rcmn
On Jan 2, 3:08 pm, rcmn wrote: > I just tried to compile with gui2exe. And i ran the exe. it faile the > same way but at least generate a log. > Exception in thread Thread-1: > Traceback (most recent call last): >   File "threading.pyc", line 522, in __bootstrap_inner >   File "pingable.py", line

Noob question: Is all this typecasting normal?

2009-01-02 Thread sprad
I've done a good bit of Perl, but I'm new to Python. I find myself doing a lot of typecasting (or whatever this thing I'm about to show you is called), and I'm wondering if it's normal, or if I'm missing an important idiom. For example: bet = raw_input("Enter your bet") if int(bet) == 0: # r

Re: Is there a better algorithm?

2009-01-02 Thread Ned Deily
In article <85aba9h1e5@dozer.localdomain>, J Kenneth King wrote: > Kottiyath writes: > > I have the following list of tuples: > > L = [(1, 2), (3, 4, 5), (6, 7)] > > > > I want to loop through the list and extract the values. > > The only algorithm I could think of is: > for i in l: > >

Re: Py2exe issue

2009-01-02 Thread rcmn
I just tried to compile with gui2exe. And i ran the exe. it faile the same way but at least generate a log. Exception in thread Thread-1: Traceback (most recent call last): File "threading.pyc", line 522, in __bootstrap_inner File "pingable.py", line 35, in run File "subprocess.pyc", line 588

Re: is there a way to determine a relative path to the script?

2009-01-02 Thread TechieInsights
import os os.path.relpath('/path/to/your/file', os.path.dirname(__file__)) tekion wrote: > Hello, > I have a script in /usr/local/app/mypython.py and a configuration file > relative to /usr/local/app/conf. When I call the script with an > absolute path of /usr/local/app/mypthon.py I recieved an

Re: Reverse order of bit in repeating seqence of byte string

2009-01-02 Thread Terry Reedy
imageguy wrote: I am looking for the most efficient method of replacing a repeating sequence in a byte string returned from a imaging .dll, connected via I receive the byte string with the following sequence 'bgrbgrbgrbgr' and I would like to convert this to 'rbgrbgrbgrbg' For speed, I would l

Re: why cannot assign to function call

2009-01-02 Thread Bruno Desthuilliers
Derek Martin a écrit : On Fri, Jan 02, 2009 at 11:43:30AM -0500, Steve Holden wrote: Derek Martin wrote: What the Python community often overlooks, when this discussion again rears its ugly head (as it seems to every other hour or so), is that its assignment model is BIZARRE, as in it's concept

Re: Is there a better algorithm?

2009-01-02 Thread J Kenneth King
Paul Rubin writes: > Kottiyath writes: >> I have the following list of tuples: >> L = [(1, 2), (3, 4, 5), (6, 7)] >> I want to loop through the list and extract the values. > > Others have suggested messy ways to code what you're asking. At another > level, that li

Re: Is there a better algorithm?

2009-01-02 Thread bearophileHUGS
Fuzzyman: > for i in l: >    u = None >    if len(i) == 2: >       k, v = i >    else: >        k, u, v = i That's the best solution I have seen in this thread so far (but I suggest to improve indents and use better variable names). In programming it's generally better to follow the KISS principl

Re: Is there a better algorithm?

2009-01-02 Thread Paul Rubin
Kottiyath writes: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > I want to loop through the list and extract the values. Others have suggested messy ways to code what you're asking. At another level, that list format seems like a code smell. You may be better off org

Re: why cannot assign to function call

2009-01-02 Thread Steve Holden
Derek Martin wrote: > On Fri, Jan 02, 2009 at 11:43:30AM -0500, Steve Holden wrote: >> Derek Martin wrote: [...] >>> It's small wonder that neophytes try to cram Python behaviors into >>> terms and computing concepts they already understand from learning >>> other languages, and that they fail to d

Re: Is there a better algorithm?

2009-01-02 Thread J Kenneth King
Kottiyath writes: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is: for i in l: > ... u = None > ... try: > ... (k, v) = i > ... except ValueError: > ... (k, u,

Re: why cannot assign to function call

2009-01-02 Thread Erik Max Francis
Derek Martin wrote: On a mostly not related note: On Tue, Dec 30, 2008 at 07:52:26AM -0800, Aaron Brady wrote: According to some rules, these are ungrammatical sentences, due to plurality disagreement. Ex: The Morning Star is ... The Evening Star is ... *The Morning Star and The Evening Star

Re: is there a way to determine a relative path to the script?

2009-01-02 Thread TechieInsite
import os base = __file__.split(os.sep) os.path.relpath('path/to/your/file/, base) I hope this helps. Greg tekion wrote: > Hello, > I have a script in /usr/local/app/mypython.py and a configuration file > relative to /usr/local/app/conf. When I call the script with an > absolute path of /usr/lo

Re: why cannot assign to function call

2009-01-02 Thread Derek Martin
On Fri, Jan 02, 2009 at 11:43:30AM -0500, Steve Holden wrote: > Derek Martin wrote: > > What the Python community often overlooks, when this discussion again > > rears its ugly head (as it seems to every other hour or so), is that > > its assignment model is BIZARRE, as in it's conceptually differe

Re: type conversion

2009-01-02 Thread r
On Jan 2, 1:46 pm, Robert Kern wrote: > r wrote: > > On Jan 1, 4:40 pm, Robert Kern wrote: > >> Hamish McKenzie wrote: > >>> sometimes I want to be able to initialize an instance with a variety of > >>> different data types. > >>> as an obvious example I might want to initialize a 4x4 matrix wit

Re: Py2exe issue

2009-01-02 Thread rcmn
I'm using py2exe-0.6.9.win32-py2.6.exe i used option 3. On a list of 500 i get the same error than previous. On a list of 250 once it just quit leaving the open file at 0k and on the second attempt it failed with the same error and a note about "TypeError: 'NoneType' object is not callable". Basic

Re: type conversion

2009-01-02 Thread Robert Kern
r wrote: On Jan 1, 4:40 pm, Robert Kern wrote: Hamish McKenzie wrote: sometimes I want to be able to initialize an instance with a variety of different data types. as an obvious example I might want to initialize a 4x4 matrix with either 16 floats, a list/tuple or 16 floats, another matrix o

Re: Why not Ruby?

2009-01-02 Thread Ryan McCoskrie
Xah Lee wrote: > Q: Do you condemn Ruby? > > No. I think it's reasonably elegant, but today there are too many > languages, so Ruby don't particularly standout for me. Many of them, > are arguably quite more elegant and powerful than Ruby. There is one thing that Ruby is exceptionally good for

Re: Reverse order of bit in repeating seqence of byte string

2009-01-02 Thread Francesco Bochicchio
imageguy ha scritto: I am looking for the most efficient method of replacing a repeating sequence in a byte string returned from a imaging .dll, connected via I receive the byte string with the following sequence 'bgrbgrbgrbgr' and I would like to convert this to 'rbgrbgrbgrbg' FWIW, the string

Re: Is there a better algorithm?

2009-01-02 Thread Andreas Waldenburger
On Fri, 02 Jan 2009 19:55:43 +0100 Markus Brueckner wrote: > g = ( ((e[0],None,e[1]) if len(e)==2 else (e[0],e[1],e[2])) for e in > L) If this isn't proof of Python's versatility, I don't know what is. In one line it can mimic both Lisp and Perl. Sweet. :) /W -- My real email address is const

Re: Is there a better algorithm?

2009-01-02 Thread Francesco Bochicchio
Kottiyath ha scritto: I have the following list of tuples: L = [(1, 2), (3, 4, 5), (6, 7)] I want to loop through the list and extract the values. The only algorithm I could think of is: for i in l: ... u = None ... try: ... (k, v) = i ... except ValueError: ... (k, u, v) = i ... print

Re: Is there a better algorithm?

2009-01-02 Thread Bruno Desthuilliers
Kottiyath a écrit : I have the following list of tuples: L = [(1, 2), (3, 4, 5), (6, 7)] I want to loop through the list and extract the values. The only algorithm I could think of is: for i in l: ... u = None ... try: ... (k, v) = i ... except ValueError: ... (k, u, v) = i ... print k

is there a way to determine a relative path to the script?

2009-01-02 Thread tekion
Hello, I have a script in /usr/local/app/mypython.py and a configuration file relative to /usr/local/app/conf. When I call the script with an absolute path of /usr/local/app/mypthon.py I recieved an error similar to the below error: Traceback (most recent call last): File "script/art/auditlog.

Re: Is there a better algorithm?

2009-01-02 Thread Markus Brueckner
Hi, Fuzzyman wrote: > I'm sure there is a clever one liner using the Python 2.5 ternary > expression syntax. On the other hand I'm not sure it would be very > readable, so a straightforward (if less clever) solution is probably > better. that would be something like this (using a generator) L =

Re: Reverse order of bit in repeating seqence of byte string

2009-01-02 Thread Steve Holden
imageguy wrote: > I am looking for the most efficient method of replacing a repeating > sequence in a byte string returned from a imaging .dll, connected via > > I receive the byte string with the following sequence 'bgrbgrbgrbgr' > and I would like to convert this to 'rbgrbgrbgrbg' > FWIW, the st

Re: Is there a better algorithm?

2009-01-02 Thread Steve Holden
Kottiyath wrote: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is: for i in l: > ... u = None > ... try: > ... (k, v) = i > ... except ValueError: > ... (k, u, v

Reverse order of bit in repeating seqence of byte string

2009-01-02 Thread imageguy
I am looking for the most efficient method of replacing a repeating sequence in a byte string returned from a imaging .dll, connected via I receive the byte string with the following sequence 'bgrbgrbgrbgr' and I would like to convert this to 'rbgrbgrbgrbg' FWIW, the string is created using ctypes

Re: If your were going to program a game...

2009-01-02 Thread Fuzzyman
On Jan 2, 6:16 pm, Jean-Paul Calderone wrote: > On Fri, 2 Jan 2009 09:44:55 -0800 (PST), Fuzzyman wrote: > >On Jan 2, 3:02 pm, J Kenneth King wrote: > >> Tokyo Dan writes: > >> > If your were going to program a game in python what technologies would > >> > you use? > > >> > The game is a board

Workshop "Medical Imaging Systems" within EUROMEDIA 2009 – Announce & Call for Papers

2009-01-02 Thread tava...@fe.up.pt
Workshop “Medical Imaging Systems” within EUROSIS EUROMEDIA 2009 April 15-17, 2009, Novotel, Bruges, Belgium http://www.eurosis.org/cms/?q=taxonomy/term/172

Re: Is there a better algorithm?

2009-01-02 Thread Fuzzyman
On Jan 2, 6:11 pm, Kottiyath wrote: > I have the following list of tuples: > L = [(1, 2), (3, 4, 5), (6, 7)] > > I want to loop through the list and extract the values. > The only algorithm I could think of is:>>> for i in l: > > ...  u = None > ...  try: > ...   (k, v) = i > ...  except ValueErro

Re: If your were going to program a game...

2009-01-02 Thread Jean-Paul Calderone
On Fri, 2 Jan 2009 09:44:55 -0800 (PST), Fuzzyman wrote: On Jan 2, 3:02 pm, J Kenneth King wrote: Tokyo Dan writes: > If your were going to program a game in python what technologies would > you use? > The game is a board game with some piece animations, but no movement > animation...think o

Is there a better algorithm?

2009-01-02 Thread Kottiyath
I have the following list of tuples: L = [(1, 2), (3, 4, 5), (6, 7)] I want to loop through the list and extract the values. The only algorithm I could think of is: >>> for i in l: ... u = None ... try: ... (k, v) = i ... except ValueError: ... (k, u, v) = i ... print k, u, v - 1 N

Re: FW: python import sys.path

2009-01-02 Thread Fuzzyman
On Jan 2, 2:28 pm, John Machin wrote: > On Jan 3, 1:09 am, "Kelly, Brian" wrote:> After > following your suggestions I was able to confirm that the 2.5 > > interpreter was being invoked. So then I grepped for all instances of python > > in the scripts that were imported as modules: from bacula_c

Re: If your were going to program a game...

2009-01-02 Thread Fuzzyman
On Jan 2, 3:02 pm, J Kenneth King wrote: > Tokyo Dan writes: > > If your were going to program a game in python what technologies would > > you use? > > > The game is a board game with some piece animations, but no movement > > animation...think of a chess king exploding. The game runs in a > > b

Re: mod_pylite?

2009-01-02 Thread Fuzzyman
On Jan 2, 2:49 pm, excord80 wrote: [snip...] > > It sounds interesting, however, after reading a bit about it, I see > that a large part of wsgi is providing a nice interface between web > server and webapp. I don't think I need any such interface, or at > least, a replacement for CGI. I just need

Re: 2to3 used in the Shootout

2009-01-02 Thread Isaac Gouy
On Dec 29 2008, 8:36 am, prueba...@latinmail.com wrote: > On Dec 23, 5:21 pm, Isaac Gouy wrote: > > > On Dec 23, 11:51 am, bearophileh...@lycos.com wrote: > > > > They have translated the Python benchmarks of theShootoutsite from > > > Py2 to Py3 using 2to3: > > > >http://shootout.alioth.debian.or

Re: Why not Ruby?

2009-01-02 Thread r
On Jan 2, 6:45 am, Steven D'Aprano wrote: > On Thu, 01 Jan 2009 17:38:02 -0800, r wrote: > > He was not cross posting. > > You don't actually know what cross-posting is, do you? > > You've just earned a plonking for the next month. Do try to have at least > half a clue by February. > > -- > Steven

  1   2   >