Re: Python Indentation Problems

2006-02-26 Thread Renato
If you use vi (vim, I hope), then place something like this in your .vimrc set ts=4 set sw=4 set expandtab set ai There are a lot more tricks for python in vim (and plugins, and helpers, and so on), but this is the starting point: tabstops of 4 places, autoconverted in spaces. Also, when shifting

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Steven D'Aprano
Paul Rubin wrote: > Ben Finney <[EMAIL PROTECTED]> writes: > >>Enumerations with no values are meaningless. The exception >>``EnumEmptyError`` is raised if the constructor is called with no >>value arguments. > > > Why are empty enumerations not allowed? Empty sets, empty lists, > empty dicti

Re: Python Indentation Problems

2006-02-26 Thread gene tani
[EMAIL PROTECTED] wrote: > I am a newbie to Python. I am mainly using Eric as the IDE for coding. > Also, using VIM and gedit sometimes. > > I had this wierd problem of indentation. My code was 100% right but it > wont run because indentation was not right. I checked time and again > but still no

Re: looking for a simpe plotting module

2006-02-26 Thread John M. Gabriele
Henrique Ferreiro wrote: > > O Sáb, 25-02-2006 ás 15:01 -0800, MARK LEEDS escribiu: > >>i'm pretty much a python beginner so can anyone recommend a plooting >>package in python ( simple foating numbers >>that makes lines or dots with a yaxis and an an xaxis. i don't need >>fancy drawings ) that

Re: automatic html generation for documentation?

2006-02-26 Thread John M. Gabriele
Lonnie Princehouse wrote: > I plan on writing some documentation that will consist of blocks of > commentary with interspersed snippets of syntax-colored Python code and > the occaisional image. > > Does anyone know of a package that will take a high level description > of what I just described an

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Crutcher
This seems great, except why can't I compare strings? It seems too useful when dealing with user input, or parsing messages or config files. >>> Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat') >>> Weekdays.mon.__cmp__('mon') 0 Additionaly, perhaps the call method of the enumerati

Re: SyntaxError: can't assign to a function call

2006-02-26 Thread Tim Roberts
"Fuzzyman" <[EMAIL PROTECTED]> wrote: > >Alex Martelli wrote: >> Fuzzyman <[EMAIL PROTECTED]> wrote: >> >> > What gives ? >>... >> > >>> a = [] >> > >>> def f(): >> > return a >>... >> > >>> f() += [4] >> > SyntaxError: can't assign to function call >> >> Exactly what the error messa

Python Indentation Problems

2006-02-26 Thread diffuser78
I am a newbie to Python. I am mainly using Eric as the IDE for coding. Also, using VIM and gedit sometimes. I had this wierd problem of indentation. My code was 100% right but it wont run because indentation was not right. I checked time and again but still no success. I rewrote the code over agai

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Giovanni Bajo
Ben Finney wrote: > Values within an enumeration cannot be meaningfully compared except > with values from the same enumeration. The comparison operation > functions return ``NotImplemented`` [#CMP-NOTIMPLEMENTED]_ when a > value from an enumeration is compared against any value not from the > sa

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Paul Rubin
Ben Finney <[EMAIL PROTECTED]> writes: > Enumerations with no values are meaningless. The exception > ``EnumEmptyError`` is raised if the constructor is called with no > value arguments. Why are empty enumerations not allowed? Empty sets, empty lists, empty dictionaries are all allowed. I don't

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Giovanni Bajo
Kay Schluehr wrote: >> The enumerations specified in this PEP are instances of an ``enum`` >> type. Some alternative designs implement each enumeration as its own >> class, and a metaclass to define common properties of all >> enumerations. >> >> One motivation for having a class (rather than an

Re: TypeError when subclassing 'list'

2006-02-26 Thread Simon Percivall
The error you're seeing is because you've rebound 'list' to something else. Try putting "list = type([])" somewhere above your code. -- http://mail.python.org/mailman/listinfo/python-list

Re: Kill forked processes

2006-02-26 Thread Steve Juranich
kmkz wrote: > Lets say my script A executes two other scripts, B and C. B is a Python > file compiled into an exe and uses the regular black box. C, however, > is a C++ program that I did not write, and have no access to (besides > executing it. ie, i don't have its source). I would like to fork o

Re: Unicode and MoinMoin

2006-02-26 Thread Neil Hodgson
Greg: > The only issue I'm having relates to Unicode. MoinMoin and python are > pretty unforgiving about files that contain Unicode characters that > aren't included in the coding properly. I've spent hours reading about > Unicode, and playing with different encoding/decoding commands, but at > th

Re: PEP 354: Enumerations in Python

2006-02-26 Thread Kay Schluehr
Ben Finney wrote: > Metaclass for creating enumeration classes > -- > > The enumerations specified in this PEP are instances of an ``enum`` > type. Some alternative designs implement each enumeration as its own > class, and a metaclass to define common pro

Re: how to write file with cp1250 encodings?

2006-02-26 Thread Waldemar Osuch
Grzegorz Smith wrote: > Hi all. I have got situation: i load data from database(MSSQL) wchich are > encoded cp1250 and I fill template with that data (Cheetah Template), after > all i want to save template to file on disk. I'm using One way to do it: >>> from Cheetah.Template import Template >>>

Re: Trolling for New Web Host . . .

2006-02-26 Thread Ben Wilson
Thanks for your suggestions. I've Python on both my Win32 and Linux partitions of my laptop. Although, I suppose I should develop my CGI on the laptop (running Apache) first. Thanks, Ben -- http://mail.python.org/mailman/listinfo/python-list

Unicode and MoinMoin

2006-02-26 Thread [EMAIL PROTECTED]
Dear all, My lab has been using a Movable Type blog for internal communication and announcement for a couple of years, but we've now seen the light and I've set up a MoinMoin wiki. Everything's installed beautifully, so I'm writing scripts to export all our Movable Type blog posts to wiki pages. S

Re: ls files --> list packer

2006-02-26 Thread kpp9c
Thank you... i was looking in the wrong place cause all i found was this relatively useless doc: http://docs.python.org/lib/module-os.html which says almost nothing. -- http://mail.python.org/mailman/listinfo/python-list

Re: spaces at ends of filenames or directory names on Win32

2006-02-26 Thread Tim Roberts
[EMAIL PROTECTED] wrote: >For example... tell windows to move a file named ' XXX ' (one space >before and one space after the filename). Windows will complain that >file 'XXX' does not exist. It's correct of course, 'XXX' does not >exist, >but ' XXX ' does indeed exist. > >Can anyone rescue me fro

Re: Modify the local scope inside a function

2006-02-26 Thread Sandra-24
Hey Crutcher, thanks for the code, that would work. I'm now debating using that, or using function arguments to get the variables into the namespace. This would require knowing the variables in the dict ahead of time, but I suppose I can do that because it's part of the same system that creates the

Re: ls files --> list packer

2006-02-26 Thread Kent Johnson
kpp9c wrote: > os.listdir works great ... just one problem, it packs the filenames > only into a list... i need the full path and seach as i might i se NO > documentation on python.org for os.listdir() Docs for os.listdir() are here: http://docs.python.org/lib/os-file-dir.html When all else fails

Multi-Threading Practices

2006-02-26 Thread Alvin A. Delagon
Greetings, I was the last time who asked your opinion about Infinite Loops and crontab. I settled with crontab where in the python program selects a number of records from a mysql database and then releases Threads (which is actually CORBA clients) that report to a CORBA server, wait a respons

Re: ls files --> list packer

2006-02-26 Thread kpp9c
os.listdir works great ... just one problem, it packs the filenames only into a list... i need the full path and seach as i might i se NO documentation on python.org for os.listdir() how do i either grab the full path or append it later ... -- http://mail.python.org/mailman/listinfo/python-list

Re: Kill forked processes

2006-02-26 Thread kmkz
Thank you for your reply. I will certainly look into those. Another question: Lets say my script A executes two other scripts, B and C. B is a Python file compiled into an exe and uses the regular black box. C, however, is a C++ program that I did not write, and have no access to (besides executi

Re: Local variables initialization

2006-02-26 Thread Michal Kwiatkowski
Michal Kwiatkowski wrote: > def init_arguments(fun): > def new_f(self): > var_one = self.attr_one > var_two = self.attr_two.another_attr > empty_list = [] > > fun(self, var_one, var_two, empty_list) > > return new_f > > @init_arguments > def method(self, v

PEP 354: Enumerations in Python

2006-02-26 Thread Ben Finney
Howdy all, PEP 354: Enumerations in Python has been accepted as a draft PEP. The current version can be viewed online: http://www.python.org/peps/pep-0354.html> Here is the reStructuredText source as it is today. Please discuss it here so I can see what issues people may have. PEP:

newbie trying understand sys.path

2006-02-26 Thread MARK LEEDS
I  was trying to understand the concept of python looking for modules in sys.path.   So, as it said in "Beginning Python", I went into my .bashrc file and did   export PYTHONPATH=$PYTHONPATH:~/mytemp   then, i typed pprint.pprint(sys.path) and it worked. it was in there !

Re: sort one list using the values from another list

2006-02-26 Thread Ron Adam
Delaney, Timothy (Tim) wrote: > Ron Adam wrote: > >> Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] >> on win32 >> >> I was a bit surprised by them being sorted. I just happend to try >> d.keys() in place of s2, and it sped up. I was expecting it to be a >> bit slower. >

Re: sort one list using the values from another list

2006-02-26 Thread Ron Adam
Alex Martelli wrote: > Ron Adam <[EMAIL PROTECTED]> wrote: >... >> Considering the number time I sort keys after getting them, It's the >> behavior I would prefer. Maybe a more dependable dict.sortedkeys() >> method would be nice. ;-) > > sorted(d) is guaranteed to do exactly the same thin

Re: Memory allocation in for loops

2006-02-26 Thread Scott David Daniels
invitro81 wrote: > Which one is better w.r.t. memory allocation but also w.r.t. speed: > ## 1.1 ## > def forloop(a,b): > for idx in range(a,b): > ... Above preferred to next (for readability) using xrange may help speed depending. > ## 1.2 ## > def whileloop(a,b): > idx = a >

Re: Local variables initialization

2006-02-26 Thread Michal Kwiatkowski
Alex Martelli wrote: > But of course, then the method's body would have to use _.one rather > than var_one, _.two rather than var_two, and _.empty_list rather than > empty_list (what a strange name -- does it STAY empty throughout the > method's execution?!). To me this looks like a small price to

Re: Is Python a Zen language?

2006-02-26 Thread Paul Rubin
"Crutcher" <[EMAIL PROTECTED]> writes: > No, I don't disagree that people do this. The history of "Zen and the > Art of X" dates from "Zen and the Art of Motorcycle Repair", which is > actually about Zen and Motorcycles. Actually "Zen in the Art of Archery" by Eugen Herrigel, which was about an a

Re: sort one list using the values from another list

2006-02-26 Thread Alex Martelli
Ron Adam <[EMAIL PROTECTED]> wrote: ... > Considering the number time I sort keys after getting them, It's the > behavior I would prefer. Maybe a more dependable dict.sortedkeys() > method would be nice. ;-) sorted(d) is guaranteed to do exactly the same thing as sorted(d.keys()) AND to be

Re: Local variables initialization

2006-02-26 Thread Alex Martelli
Michal Kwiatkowski <[EMAIL PROTECTED]> wrote: ... > The problem wouldn't be such a problem if Python had implicit self... > but on the other side, it's another ambiguity. In your example, you could avoid assigning var_one, but the purpose of assigning var_two and empty_list obviously would not

RE: sort one list using the values from another list

2006-02-26 Thread Delaney, Timothy (Tim)
Ron Adam wrote: > Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] > on win32 > > I was a bit surprised by them being sorted. I just happend to try > d.keys() in place of s2, and it sped up. I was expecting it to be a > bit slower. Purely an implementation accident - based

Re: Local variables initialization

2006-02-26 Thread Michal Kwiatkowski
Alex Martelli wrote: > Michal Kwiatkowski <[EMAIL PROTECTED]> wrote: >... >> def method(self): >> var_one = self.attr_one >> var_two = self.attr_two.another_attr >> empty_list = [] >> # significant code goes here >... > Personally, I would keep pushing back against this app

Re: sort one list using the values from another list

2006-02-26 Thread Ron Adam
[EMAIL PROTECTED] wrote: >> It's faster on my system because d.keys() is already sorted. But that may >> not be the case on other versions of python.< > > In my version it's a little slower. But what system are you using where > keys is already sorted? IronPython maybe? > > Bye, > bearophile

Re: Local variables initialization

2006-02-26 Thread Alex Martelli
Michal Kwiatkowski <[EMAIL PROTECTED]> wrote: ... > def method(self): > var_one = self.attr_one > var_two = self.attr_two.another_attr > empty_list = [] > # significant code goes here ... > know, I know ;), but maybe there is a way? I would like to code it that way: > > @init

Re: sort one list using the values from another list

2006-02-26 Thread Ron Adam
Alex Martelli wrote: > Ron Adam <[EMAIL PROTECTED]> wrote: > >> [EMAIL PROTECTED] wrote: >>> Your solution Steven Bethard looks very intelligent, here is a small >>> speed test, because sorting a list according another one is a quite >>> common operation. >>> (Not all solutions are really the same

how to write file with cp1250 encodings?

2006-02-26 Thread Grzegorz Smith
Hi all. I have got situation: i load data from database(MSSQL) wchich are encoded cp1250 and I fill template with that data (Cheetah Template), after all i want to save template to file on disk. I'm using newfile = open("template.html",w") newfile.write(str(template)) newfile.close() But data enco

Re: SyntaxError: can't assign to a function call

2006-02-26 Thread Alex Martelli
Fuzzyman <[EMAIL PROTECTED]> wrote: ... > > Exactly what the error message says: it's syntactically forbidden to > > perform any assignment on a function-call. ... > Cool, thanks. That's what I did, it's just not an error I'd seen > before. Everywhere else Python evaluates the function call a

Re: make a class instance from a string ?

2006-02-26 Thread M�ta-MCI
Hi! Perso, I like this... MCI -- http://mail.python.org/mailman/listinfo/python-list

Re: wxGlade, wxPython.... pyOpenGL wxWidget?

2006-02-26 Thread physci
Ok, I initially thought the Tkinter route would be too "low level" (Ha, low level python), but I noticed a link to VTK which looks promising. Thanks for your quick reply! Derek. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python a Zen language?

2006-02-26 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Kay Schluehr <[EMAIL PROTECTED]> wrote: . . . >Lucid in the mid 80s that gone down a few years later. As it turned out >that time Lisp was not capable to survive in what we call today a >"heterog

Re: SyntaxError: can't assign to a function call

2006-02-26 Thread Fuzzyman
Alex Martelli wrote: > Fuzzyman <[EMAIL PROTECTED]> wrote: > > > What gives ? >... > > >>> a = [] > > >>> def f(): > > return a >... > > >>> f() += [4] > > SyntaxError: can't assign to function call > > Exactly what the error message says: it's syntactically forbidden to > perform an

Local variables initialization

2006-02-26 Thread Michal Kwiatkowski
Hi! I'm building a class that most of methods have similar intro, something like this: def method(self): var_one = self.attr_one var_two = self.attr_two.another_attr empty_list = [] # significant code goes here # ... It's done for clarity reasons, aliasing most used variabl

Re: SyntaxError: can't assign to a function call

2006-02-26 Thread Lawrence Oluyede
"Fuzzyman" <[EMAIL PROTECTED]> writes: f() += [4] > SyntaxError: can't assign to function call It's obvious that that line gives you a syntax error. += is the increment operator overloaded for strings and lists and so on. It changes the lhs in place appending the rhs. In this case the

Re: SyntaxError: can't assign to a function call

2006-02-26 Thread Alex Martelli
Fuzzyman <[EMAIL PROTECTED]> wrote: > What gives ? ... > >>> a = [] > >>> def f(): > return a ... > >>> f() += [4] > SyntaxError: can't assign to function call Exactly what the error message says: it's syntactically forbidden to perform any assignment on a function-call. If you're ke

SyntaxError: can't assign to a function call

2006-02-26 Thread Fuzzyman
What gives ? >>> a = [] >>> def f(): return a >>> f() [] >>> a.append(3) >>> f() [3] >>> a += [3] >>> a [3, 3] >>> f() [3, 3] >>> f() += [4] SyntaxError: can't assign to function call >>> Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinf

Re: wxGlade, wxPython.... pyOpenGL wxWidget?

2006-02-26 Thread Karsten W.
PyOpenGL comes with a Tkinter widget for OpenGL, and searching google "wxwidgets opengl" yields http://www.wxwidgets.org/opengl.htm Kind regards, Karsten. -- http://mail.python.org/mailman/listinfo/python-list

RE: Use of __slots__

2006-02-26 Thread Delaney, Timothy (Tim)
Steve Juranich wrote: > IMHO, __slots__ is unpythonic. Many others have stated so on the > list. That's why it's great that you're free to ignore that variable. > I suggest that you do so (as I have chosen to do). I'm sure that > there are situations where you *MUST* have this kind of capability

Re: Memory allocation in for loops

2006-02-26 Thread Diez B. Roggisch
> I mean what I really would like is to have something C++ - like "for > (int idx = a; idx < b; i++) { .. }" where no internal vector or > something like that is allocated but only a few op's on registers are > performed; in the whileloop in python the picture is roughly the same Use xrange i

Re: Is Python a Zen language?

2006-02-26 Thread Andrea Griffini
I think that the classification has some meaning, even if of course any language has different shades of both sides. I'd say that with python is difficult to choose one of the two categories because it's good both as a pratical language and as a mind-opener language. IMO another language that woul

Re: Pure python implementation of string-like class

2006-02-26 Thread Akihiro KAYAMA
Hi Ross. Thanks a lot for your clarifying. I didn't think my post could be an Unicode frame. I don't know this mailing list is the right place talking about Unicode issue, but as for me, a million codespace which UTF-16 brings is not enough. It presume that same characters has a same codepoint

wxGlade, wxPython.... pyOpenGL wxWidget?

2006-02-26 Thread physci
I've been combing google for the past week trying to find an appropriate set of tools for a project I'm working on. Simply put, what I need is a GUI, powered by python, (I really don't want to touch any C++ code at all), that has an openGL canvas/scene(?), with a python interpreter sitting beside

Re: TypeError when subclassing 'list'

2006-02-26 Thread Gerard Flanagan
Steve Juranich wrote: > Gerard Flanagan wrote: > > > Hello all > > > > Could anyone shed any light on the following Exception? The code which > > caused it is below. Uncommenting the 'super' call in 'XmlNode' gives > > the same error. If I make XmlNode a subclass of 'object' rather than > > 'list

Re: Use of __slots__

2006-02-26 Thread Steve Juranich
Don Taylor wrote: > I am puzzled about the following piece of code which attempts to create > a class that can be used as record or struct with a limited set of > allowed attributes that can be set into an instance of the class. > > I don't understand why I cannot set an attribute 'age' into reco

Re: TypeError when subclassing 'list'

2006-02-26 Thread Steve Juranich
Gerard Flanagan wrote: > Hello all > > Could anyone shed any light on the following Exception? The code which > caused it is below. Uncommenting the 'super' call in 'XmlNode' gives > the same error. If I make XmlNode a subclass of 'object' rather than > 'list' then the code will run. ... > Code:

Re: How can I find the remainder when dividing 2 integers

2006-02-26 Thread Andrea Griffini
Writing a while loop with ++x to increment the index was the first mistake i made with python. "++x" unfortunately is valid, it's not a single operator but a double "unary plus" Andrea -- http://mail.python.org/mailman/listinfo/python-list

Re: Use of __slots__

2006-02-26 Thread Crutcher
Steven is right, however, there is a way: def new_record(slotlist): class R(object): __slots__ = slotlist return R() record1 = new_record(["age", "name", "job"]) record1.age = 27 record1.name = 'Fred' record1.job = 'Plumber' record1.salary = 5 -- http://mail.python.org/mailman/listi

wxPython: help(wx) causes segfaulting?

2006-02-26 Thread Tim Chase
Trying to get my feet wet with wxPython (moving from just command-line apps), I tried the obvious (or, at least to me was obvious): Start python, "import wx" and then do a "help(wx)" to see what it can tell me. Unfortunately, it spewed back a handful of errors, gasped, wheezed and died semi-h

Re: Use of __slots__

2006-02-26 Thread Steven D'Aprano
On Sun, 26 Feb 2006 17:01:45 -0500, Don Taylor wrote: > Hi: > > I am puzzled about the following piece of code which attempts to create > a class that can be used as record or struct with a limited set of > allowed attributes that can be set into an instance of the class. > > class RecordClass

Re: Kill forked processes

2006-02-26 Thread Steve Juranich
kmkz wrote: > I have a program A that forks off two other programs, B and C. I need B > and C to both terminate if A is closed, but by using the > subprocess.call() method this seems to not be the case; I can shut down > the "black box" that is program A and B/C will still stay up. > > How can I

TypeError when subclassing 'list'

2006-02-26 Thread Gerard Flanagan
Hello all Could anyone shed any light on the following Exception? The code which caused it is below. Uncommenting the 'super' call in 'XmlNode' gives the same error. If I make XmlNode a subclass of 'object' rather than 'list' then the code will run. Thanks in advance. Exception: Traceback (mos

Re: How can I find the remainder when dividing 2 integers

2006-02-26 Thread Steven D'Aprano
On Sun, 26 Feb 2006 21:58:30 +0100, Diez B. Roggisch wrote: > [EMAIL PROTECTED] schrieb: >> Can you please tell me what is the meaning of >> UnboundLocalError: local variable 'colorIndex' referenced before >> assignment >> >> in general? > > Well, pretty much of what it says: You tried to acce

Re: Is Python a Zen language?

2006-02-26 Thread Steven D'Aprano
On Sun, 26 Feb 2006 12:48:47 -0800, Crutcher wrote: > My central thesis: you are using a poor understanding of language to > classify languages into things you understand (tool languages) and > things which _you_ find 'deep' (and difficult to learn), which you call > 'Zen languages'. This is ridic

Memory allocation in for loops

2006-02-26 Thread invitro81
Which one is better w.r.t. memory allocation but also w.r.t. speed: ## 1.1 ## def forloop(a,b): for idx in range(a,b): ## .. ## do something ## .. ## 1.2 ## def whileloop(a,b): idx = a while idx < b: ## ..

Use of __slots__

2006-02-26 Thread Don Taylor
Hi: I am puzzled about the following piece of code which attempts to create a class that can be used as record or struct with a limited set of allowed attributes that can be set into an instance of the class. class RecordClass(object): __slots__ = ["foo"] def __init__(self, args):

Re: Can optparse do dependencies?

2006-02-26 Thread Mike Erickson
* Bob ([EMAIL PROTECTED]) wrote: > I'd like to setup command line switches that are dependent on other > switches, similar to what rpm does listed below. From the grammar below > we see that the "query-options" are dependent on the query switch, > {-q|--query}. Can "optparse" do this or do I have t

Re: python newbie question

2006-02-26 Thread Christoph Haas
On Sunday 26 February 2006 22:44, [EMAIL PROTECTED] wrote: > I am new to python, can you please tell me how can I convert my python > script into an executable on linux? > i.e. instead of typing 'python myscript.py abc', I just need to do > 'myscript.py abc'? Use the shebang syntax. Use this as a

Re: python newbie question

2006-02-26 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > I am new to python, can you please tell me how can I convert my python > script into an executable on linux? > i.e. instead of typing 'python myscript.py abc', I just need to do > 'myscript.py abc'? > and how can I get the input argument from my script , in my example,

Re: sort one list using the values from another list

2006-02-26 Thread bearophileHUGS
>It's faster on my system because d.keys() is already sorted. But that may not >be the case on other versions of python.< In my version it's a little slower. But what system are you using where keys is already sorted? IronPython maybe? Bye, bearophile -- http://mail.python.org/mailman/listinf

Kill forked processes

2006-02-26 Thread kmkz
Hi, I have a program A that forks off two other programs, B and C. I need B and C to both terminate if A is closed, but by using the subprocess.call() method this seems to not be the case; I can shut down the "black box" that is program A and B/C will still stay up. How can I achieve the desired

Re: Is Python a Zen language?

2006-02-26 Thread Steve Holden
Alex Martelli wrote: > Crutcher <[EMAIL PROTECTED]> wrote: >... > >>No, I don't disagree that people do this. The history of "Zen and the >>Art of X" dates from "Zen and the Art of Motorcycle Repair", which is > > > That's Maintenance, not Repair. Subtle but important distinction. > Since

python newbie question

2006-02-26 Thread ken . carlino
I am new to python, can you please tell me how can I convert my python script into an executable on linux? i.e. instead of typing 'python myscript.py abc', I just need to do 'myscript.py abc'? and how can I get the input argument from my script , in my example, how can I read 'abc'? Thank you. --

Re: sort one list using the values from another list

2006-02-26 Thread Alex Martelli
Ron Adam <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Your solution Steven Bethard looks very intelligent, here is a small > > speed test, because sorting a list according another one is a quite > > common operation. > > (Not all solutions are really the same, as Alex has shown). > >

Re: Do I need to convert string to integer in python?

2006-02-26 Thread Steven D'Aprano
On Sun, 26 Feb 2006 11:55:54 -0800, Allerdyce.John wrote: > Do I need to convert string to integer in python? or it will do it for > me (since dynamic type)? > > In my python script, I have this line: > x /= 10; > > when i run it, I get this error: > TypeError: unsupported operand type(s) fo

Re: sort one list using the values from another list

2006-02-26 Thread Ron Adam
[EMAIL PROTECTED] wrote: > Your solution Steven Bethard looks very intelligent, here is a small > speed test, because sorting a list according another one is a quite > common operation. > (Not all solutions are really the same, as Alex has shown). Try this one. def psort10(s1, s2): d = dict

Re: Is Python a Zen language?

2006-02-26 Thread Alex Martelli
Crutcher <[EMAIL PROTECTED]> wrote: ... > No, I don't disagree that people do this. The history of "Zen and the > Art of X" dates from "Zen and the Art of Motorcycle Repair", which is That's Maintenance, not Repair. Subtle but important distinction. Alex -- http://mail.python.org/mailman/li

Re: UnboundLocalError: local variable 'colorIndex' referenced

2006-02-26 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > Can you please tell me what is the meaning this error in general? > > UnboundLocalError: local variable 'colorIndex' referenced before > assignment > > In my python script, > I have a variable define and init to 0, like this > colorIndex = 0 > > and in one of my fu

Re: How to use python regular expression to substitute string value

2006-02-26 Thread Pasi Savolainen
[EMAIL PROTECTED] writes: > When I try your idea, I have this error > > x, y, width, height = re.findall(pattern, str)[0] > IndexError: list index out of range > > How can I use findall to handle error case? i.e. what if there is no > match? how can I handle it gracefully? This is explained i

Re: Tail Call Optimization as a Decorator

2006-02-26 Thread Kay Schluehr
Crutcher wrote: > I've tossed it to python-dev, but how do I submit it to the cookbook? http://aspn.activestate.com/ASPN/Python/Cookbook/ I think it is a good place to stay accessible even if python-dev overlooks it. Kay -- http://mail.python.org/mailman/listinfo/python-list

Re: UnboundLocalError: local variable 'colorIndex' referenced

2006-02-26 Thread Rick Zantow
[EMAIL PROTECTED] wrote in news:1140987642.195734.187540 @t39g2000cwt.googlegroups.com: > Can you please tell me what is the meaning this error in general? > > UnboundLocalError: local variable 'colorIndex' referenced before > assignment > > In my python script, > I have a variable define and i

Re: How can I find the remainder when dividing 2 integers

2006-02-26 Thread Kent Johnson
Diez B. Roggisch wrote: > [EMAIL PROTECTED] schrieb: > >> okay, I try you suggestion, and re-write my code like this: >> colors = ["#ff", "#00FF00", "#FF"] >> colorIndex = 0 >> >> def getText(nodelist): >> >> >> for str in strings: >> >> print colors[color

UnboundLocalError: local variable 'colorIndex' referenced

2006-02-26 Thread silverburgh . meryl
Can you please tell me what is the meaning this error in general? UnboundLocalError: local variable 'colorIndex' referenced before assignment In my python script, I have a variable define and init to 0, like this colorIndex = 0 and in one of my functions, I increment it by 1 def myFunc co

Re: How can I find the remainder when dividing 2 integers

2006-02-26 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > Can you please tell me what is the meaning of > UnboundLocalError: local variable 'colorIndex' referenced before > assignment > > in general? Well, pretty much of what it says: You tried to access a variable without prior assignment to it. Like this: a = b**2 + c

Re: How can I find the remainder when dividing 2 integers

2006-02-26 Thread silverburgh . meryl
Can you please tell me what is the meaning of UnboundLocalError: local variable 'colorIndex' referenced before assignment in general? -- http://mail.python.org/mailman/listinfo/python-list

Re: Tail Call Optimization as a Decorator

2006-02-26 Thread Crutcher
I've tossed it to python-dev, but how do I submit it to the cookbook? -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python a Zen language?

2006-02-26 Thread Crutcher
> My point is simply that, for some languages L, > "Zen and the art of L" or "The Tao of L" are plausible > titles ("Zen and the Art of Lisp Programming" would be plausible) but > for some languages they wouldn't ("The Tao of Fortran" ?) > Do you disagree? No, I don't disagree that people do this.

Re: Tail Call Optimization as a Decorator

2006-02-26 Thread Kay Schluehr
Crutcher wrote: > This is fun :) > {Note: I take no responsibilty for anyone who uses this in production > code} > > #!/usr/bin/env python2.4 > # This program shows off a python decorator > # which implements tail call optimization. It > # does this by throwing an exception if it is > # it's own g

Re: How can I find the remainder when dividing 2 integers

2006-02-26 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > okay, I try you suggestion, and re-write my code like this: > colors = ["#ff", "#00FF00", "#FF"] > colorIndex = 0 > > def getText(nodelist): > > > for str in strings: > > print colors[colorIndex % colors.length] >

Re: Do I need to convert string to integer in python?

2006-02-26 Thread Michael Amrhein
[EMAIL PROTECTED] schrieb: > Do I need to convert string to integer in python? or it will do it for > me (since dynamic type)? > > In my python script, I have this line: > x /= 10; > > when i run it, I get this error: > TypeError: unsupported operand type(s) for /=: 'unicode' and 'int' > > I

Re: How can I find the remainder when dividing 2 integers

2006-02-26 Thread silverburgh . meryl
okay, I try you suggestion, and re-write my code like this: colors = ["#ff", "#00FF00", "#FF"] colorIndex = 0 def getText(nodelist): for str in strings: print colors[colorIndex % colors.length] colorIndex += 1 but i get this error

Re: How can I find the remainder when dividing 2 integers

2006-02-26 Thread David
[EMAIL PROTECTED] wrote: > I have a string array: > colors = ["#ff", "#00FF00", "#FF"] > colorIndex = 0; > > and I want to loop thru each element of colors > > for str in strings: > print colors[colorIndex++ % colors.length] > > > But i get an invalid syntax error when I execute the s

Re: How can I find the remainder when dividing 2 integers

2006-02-26 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > I have a string array: > colors = ["#ff", "#00FF00", "#FF"] > colorIndex = 0; > > and I want to loop thru each element of colors > > for str in strings: > print colors[colorIndex++ % colors.length] > > > But i get an invalid syntax error when I execute the

Re: An isalpha() that accepts underscores as well

2006-02-26 Thread Alex Martelli
Zajcev Evgeny <[EMAIL PROTECTED]> wrote: ... > > The following will work, and probably only be twice as slow as > > 'isalpha' :-) : > > > > def alfa(w): > >return w.replace('_', '').isalpha() > > Yeah, great performance indeed, thanks! Except it rejects a w that's JUST an underscore, whil

Re: Do I need to convert string to integer in python?

2006-02-26 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > Do I need to convert string to integer in python? or it will do it for > me (since dynamic type)? > > In my python script, I have this line: > x /= 10; > > when i run it, I get this error: > TypeError: unsupported operand type(s) for /=: 'unicode' and 'int' > > I

Re: Do I need to convert string to integer in python?

2006-02-26 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote: > Do I need to convert string to integer in python? or it will do it for > me (since dynamic type)? Nope, no such implicit conversion (thanks be!). Strings are strings and ints and ints and never the twain shall meet, except by explicit request;-). > In my python scri

Re: How can I redirect print function to an output file?

2006-02-26 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote: > I am using the print function in my python script. > Can you please tell me what can I do to redirect the output to an file? f = open('aaargh', 'w') print>>f, 'killew wabbit' Alex -- http://mail.python.org/mailman/listinfo/python-list

  1   2   >