Re: range() is not the best way to check range?

2006-07-18 Thread Grant Edwards
On 2006-07-18, tac-tics <[EMAIL PROTECTED]> wrote: > Grant Edwards wrote: >> for pete's sake use the comparison operator like god intended. >> >> if 0 <= i <= 1: > > I'm assuming you used Python's compound comparison as opposed to the > C-style of and'ing two comparisons together to emphasi

Re: Recursive function returning a list

2006-07-18 Thread Boris Borcic
Hello Bruno, Bruno Desthuilliers wrote: > Boris Borcic wrote: >>> Do you have any ideas? >> >> you could use a recursive generator, like >> >> def genAllChildren(self) : >> for child in self.children : >> yield child >> for childchild in child.genAllChildren() : >>

getting user's home directory on windows

2006-07-18 Thread K.S.Sreeram
Hi everybody, I'm having trouble using os.path.expanduser('~') on windows. It uses $HOME or ($HOMEDRIVE+$HOMEPATH), but this doesn't work with windows machines which are part of a domain. On such machines, the HOME envvar may not be set at all, and the HOMEPATH envvar may be set to '\\'!! Here's

Re: Using Visual Slick Edit for Python

2006-07-18 Thread Daniel Dittmar
Brian Buderman wrote: > Anyone know if there is a way to make slickedit tag the built in modules > such as os and sys so that code completion and the like work? I don't think that this is possible as the docs are in the python executable. But it should be easy to generate a dummy module: import

Re: range() is not the best way to check range?

2006-07-18 Thread Grant Edwards
On 2006-07-18, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > In <[EMAIL PROTECTED]>, tac-tics > wrote: > >> Grant Edwards wrote: >>> for pete's sake use the comparison operator like god intended. >>> >>> if 0 <= i <= 1: >> >> I'm assuming you used Python's compound comparison as op

Re: range() is not the best way to check range?

2006-07-18 Thread Grant Edwards
On 2006-07-18, Paul Boddie <[EMAIL PROTECTED]> wrote: > John Machin wrote: >> >> range() and xrange() are functions. You are suggesting that 2 >> *functions* should acquire a __contains__ method each? I trust >> not. > > Well, range is a function in the current implementation, > although its usage

CSV with comments

2006-07-18 Thread GinTon
In csv.reader, is there any way of skip lines that start whith '#' or empty lines I would add comments at my CSV file -- http://mail.python.org/mailman/listinfo/python-list

tkinter help

2006-07-18 Thread groves
hi eveyrbody , i have started working on python tkinter, While I was working on one of the tkinter classes..named listbox widget. I had a slight problem. Now let me tell you that i was able to create a simple listbox which had 6 options which one can select, but Now what I want is that from the av

Re: question about what lamda does

2006-07-18 Thread [EMAIL PROTECTED]
The two primary differences between using def and using lambda is that lambda is limited to a single expression and def cannot be used within another function. Basically, use lambda when you need to define a small function within another function. I've also used it to create 'shortcut' functions a

Python to log into web site

2006-07-18 Thread david brochu jr
Hi,   I have been browsing around the net looking for a way (hopefully an easily implemented module) to log into a web site using python. The site I wish to log into is an internal site which requires email address and password for authentication. Does anyone have any suggestions or links that migh

Re: CSV with comments

2006-07-18 Thread GinTon
GinTon wrote: > In csv.reader, is there any way of skip lines that start whith '#' or > empty lines > I would add comments at my CSV file For skip comment I get a dirty trick: reader = csv.reader(open(csv_file)) for csv_line in reader: if csv_line[0].startswith('#'): continue But no

Re: question about what lamda does

2006-07-18 Thread K.S.Sreeram
[EMAIL PROTECTED] wrote: > The two primary differences between using def and using lambda is that > lambda is limited to a single expression and def cannot be used within > another function. 'def' can certainly be used within another function : def make_adder( delta ) : def adder( x ) :

Re: range() is not the best way to check range?

2006-07-18 Thread Steve Holden
Grant Edwards wrote: > On 2006-07-18, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > >>In <[EMAIL PROTECTED]>, tac-tics >>wrote: >> >> >>>Grant Edwards wrote: >>> for pete's sake use the comparison operator like god intended. if 0 <= i <= 1: >>> >>>I'm assuming you used

Re: How properly manage memory of this PyObject* array?? (C extension)

2006-07-18 Thread [EMAIL PROTECTED]
> *WRONG*. The object exists in and of itself. There may be one *or more* > references to it, via pointers, scattered about in memory; they are > *NOT* components of the object. A reference count is maintained inside > the object and manipulated by Py_INCREF etc. The Python garbage > collector know

Re: Using Visual Slick Edit for Python

2006-07-18 Thread Brian Buderman
Thanks very much. That should work nicely. We just upgraded to v11, so I'm not yet familiar with all the changes. The first noticable thing is the UI got a slight enhancement, as it seems to from one version to the next. I've not used it for Python yet (really only C so far), so I unfortunate

Re: question about what lamda does

2006-07-18 Thread Steve Holden
[EMAIL PROTECTED] wrote: > The two primary differences between using def and using lambda is that > lambda is limited to a single expression and def cannot be used within > another function. > Where on earth did you get that from? I presume you mean "You can't use a def statement as an argument t

Re: question about what lamda does

2006-07-18 Thread tac-tics
[EMAIL PROTECTED] wrote: > Hey there, > i have been learning python for the past few months, but i can seem to > get what exactly a lamda is for. What would i use a lamda for that i > could not or would not use a def for ? Is there a notable difference ? > I only ask because i see it in code sample

Re: What is a type error? [correction]

2006-07-18 Thread Darren New
David Hopwood wrote: > Darren New wrote: > >>David Hopwood wrote: >> >> >>>public class LoopInitTest { >>>public static String getString() { return "foo"; } >>> >>>public static void main(String[] args) { >>>String line = getString(); >>>boolean is_last = false; >>> >>>

Re: CSV with comments

2006-07-18 Thread Daniel Dittmar
GinTon wrote: > GinTon wrote: >> In csv.reader, is there any way of skip lines that start whith '#' or >> empty lines >> I would add comments at my CSV file > > For skip comment I get a dirty trick: > > reader = csv.reader(open(csv_file)) > for csv_line in reader: > if csv_line[0].startswith(

Re: Coding style

2006-07-18 Thread Patrick Maupin
Carl Banks wrote: > Here's another reason not to use "if lst". Say you have a function > that looks like this: > > def process_values(lst): > if not lst: > return > do_expensive_initialization_step() > for item in lst: > do_something_with(item)

Re: range() is not the best way to check range?

2006-07-18 Thread Simon Forman
Dan Bishop wrote: > [EMAIL PROTECTED] wrote: > > it seems that range() can be really slow: > ... > > if i in range (0, 1): > > This creates a 10,000-element list and sequentially searches it. Of > course that's gonna be slow. And you're doing it 3 times. -- http://mail.python.org/m

Re: range() is not the best way to check range?

2006-07-18 Thread Simon Forman
Nick Craig-Wood wrote: > > Sets are pretty fast too, and have the advantage of flexibility in > that you can put any numbers in you like > I know this is self-evident to most of the people reading this, but I thought it worth pointing out that this is a great way to test membership in range(lo, hi

Re: Coding style

2006-07-18 Thread Volker Grabsch
Bruno Desthuilliers <[EMAIL PROTECTED]> schrieb: > Carl Banks wrote: >> Bruno Desthuilliers wrote: >> >> I'm well aware of Python's semantics, and it's irrelvant to my >> argument. [...] >> If the language >> were designed differently, then the rules would be different. > > Totally true - and tota

Re: Coding style

2006-07-18 Thread Donn Cave
In article <[EMAIL PROTECTED]>, "Carl Banks" <[EMAIL PROTECTED]> wrote: > 1. This is fine in a perfect world where all code clearly conforms to > expectation. Problem is, a lot doesn't. I think it's quite easy to > accidentally check something intended as an iterable for emptiness. > And, as I'

Re: Howto Determine mimetype without the file name extension?

2006-07-18 Thread Phoe6
Justin Azoff wrote: > Additionally, I would re-organize your program a bit. something like: > Thanks Justin, that was a helpful one. Helping me in learning python programming. Thanks, Senthil -- http://mail.python.org/mailman/listinfo/python-list

Re: Coding style

2006-07-18 Thread Volker Grabsch
Bruno Desthuilliers <[EMAIL PROTECTED]> schrieb: > PTY wrote: >> I was asking whether it was better style to >> use len() or not. > > FWIW, it's also more generic (you could have an object supporting > pop() but not __len__()), less error-prone, While I agree with all other points, I don't think t

Re: What is a type error? [correction]

2006-07-18 Thread David Hopwood
Darren New wrote: > David Hopwood wrote: > [...] >> Apparently, Hermes (at least the version of it described in that paper) >> essentially forgets that is_last has been initialized at the top of the >> loop, and so when it does the merge, it is merging 'not necessarily >> initialized' with 'initia

Re: range() is not the best way to check range?

2006-07-18 Thread Diez B. Roggisch
Simon Forman wrote: > Nick Craig-Wood wrote: >> >> Sets are pretty fast too, and have the advantage of flexibility in >> that you can put any numbers in you like >> > > I know this is self-evident to most of the people reading this, but I > thought it worth pointing out that this is a great way t

Re: Coding style

2006-07-18 Thread Daniel Dittmar
Patrick Maupin wrote: > The argument that one should always use len() to test whether sequences > are empty or not simply because the use of len() gives a free "is it a > sequence?" type-check is not apt to be well received by an audience > which rejects explicit type-checking in general. No expli

Re: execute a shell script from a python script

2006-07-18 Thread Thomas Nelson
As described in the docs I pointed to before: subprocess.call("foo.sh",shell=True) Is the way to do it without args. I think it is simplest to learn the subprocess module because (quoting from the docs) this module intends to replace several other, older modules and functions, such as: os.system o

Re: question about what lamda does

2006-07-18 Thread [EMAIL PROTECTED]
I stand corrected. Not sure where I got that from, improper defragmentation due to sleep depravation perhaps... K.S.Sreeram wrote: > [EMAIL PROTECTED] wrote: > > The two primary differences between using def and using lambda is that > > lambda is limited to a single expression and def cannot be us

Should this be added to MySQLdb FAQ?

2006-07-18 Thread gmax2006
Hi, I went through couple of wrong paths to install MySQLdb on my RedHat box. I was trying to download MySQL client from MySQL.com and also mySQLdb from SourceForge. After some challenges with compile errors and also searching for pre-required RPMs, I found RedHat distribution already contains all

Re: statistical analysis tools in python?

2006-07-18 Thread Thomas Nelson
Actually, after a little looking, the simple stats.py module at http://www.nmr.mgh.harvard.edu/Neural_Systems_Group/gary/python.html is exactly what I needed. It may not be as fast or as comprehensive as scipy or R, but installation simply involves downloading the module and importing into the cod

Re: range() is not the best way to check range?

2006-07-18 Thread K.S.Sreeram
Simon Forman wrote: > Nick Craig-Wood wrote: >> Sets are pretty fast too, and have the advantage of flexibility in >> that you can put any numbers in you like >> > > I know this is self-evident to most of the people reading this, but I > thought it worth pointing out that this is a great way to te

Re: range() is not the best way to check range?

2006-07-18 Thread Simon Forman
Diez B. Roggisch wrote: > Simon Forman wrote: > > > Nick Craig-Wood wrote: > >> > >> Sets are pretty fast too, and have the advantage of flexibility in > >> that you can put any numbers in you like > >> > > > > I know this is self-evident to most of the people reading this, but I > > thought it wor

Re: range() is not the best way to check range?

2006-07-18 Thread Paul Boddie
Grant Edwards wrote: > > It's unclear what you're referring to as "the range". The notion of something describing a range of values which can be expanded to a list or, of relevance here, whose boundaries can be tested efficiently. > Perhaps you're thinking of a slice? Somethign like > > if (0

Re: Piping external commands

2006-07-18 Thread Simon Forman
[EMAIL PROTECTED] wrote: > What is the Python translation for this Bash statement: > > tar cf - "[EMAIL PROTECTED]" | bzip2 > "$file".tar.bz2 > > (Ignoring the fact that "tar cjf" also exists...) > > In other words, how does one pipe together arbitrary commands? For piping subcommands check out

Re: Accessors in Python (getters and setters)

2006-07-18 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Bruno Desthuilliers wrote: > > > >>mystilleef wrote: > >> > >>>Gerhard Fiedler wrote: > >>> > >>> > On 2006-07-15 06:55:14, mystilleef wrote: > > > > >In very well designed systems, the state of an object should only be > >>

Re: range() is not the best way to check range?

2006-07-18 Thread Grant Edwards
On 2006-07-18, Steve Holden <[EMAIL PROTECTED]> wrote: >> That said, "for pete's sake" is probably a just an cleaned up >> version of "for god's sake", so I probably did call pete god. > > No, actually you called god pete ;-) Well that's certainly wrong, because we all know god's name is Howard.

Cyclic class definations

2006-07-18 Thread John Henry
Hi list, I am trying to understand better Python packaging. This might be a messed up class hierachy but how would I break this cyclic relatioship? In file A: from B import B_Class Class_A_Main(): def def SomeMethod(self): res=B_Class(self) Class_A_SubClass(Class_A_Main):

Re: range() is not the best way to check range?

2006-07-18 Thread Grant Edwards
On 2006-07-18, Paul Boddie <[EMAIL PROTECTED]> wrote: >> It's unclear what you're referring to as "the range". > > The notion of something describing a range of values which can be > expanded to a list or, of relevance here, whose boundaries can be > tested efficiently. > >> Perhaps you're thinkin

Re: Accessors in Python (getters and setters)

2006-07-18 Thread mystilleef
Bruno Desthuilliers wrote: > mystilleef wrote: > > Bruno Desthuilliers wrote: > > > >>mystilleef wrote: > >>Please don't top-post > >> > >>>On State and Behavior: > >>> > >>>To understand objects in terms of state and behavior you need to > >>>absolve yourself from implementation details of langua

Re: tkinter help

2006-07-18 Thread faulkner
add a xscrollcommand and/or yscrollcommand keyword argument to the construction of your listbox. def func(*a): print "i'm a callback!" L = Tkinter.Listbox(root, yscrollcommand=func)# note no parens after func groves wrote: > hi eveyrbody , i have started working on python tkinter, > Whi

Re: Cyclic class definations

2006-07-18 Thread John Henry
I think I got the answer by playing around a bit. It appears you *don't* need to forward declare things. For example, the following code works: class a: def run(self): new_a=a_sub() new_a.print_it() class a_sub(a): def print_it(self): print "Hi" b=a().run() Regards, John He

Re: Augument assignment versus regular assignment

2006-07-18 Thread Terry Reedy
"Antoon Pardon" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On 2006-07-17, Terry Reedy <[EMAIL PROTECTED]> wrote: >> Or, whether docs (and reasonable interpretation thereof) and >> implementation match, which I claim they do it this case. The claim, in reference to the CPython

Dispatch with multiple inheritance

2006-07-18 Thread Michael J. Fromberger
Consider the following class hierarchy in Python: class A (object): def __init__(self): print "cons A" class B (object): def __init__(self): print "cons B" class C (A): def __init__(self): super(C, self).__init__() print "cons C" class D (B): def

Re: execute a shell script from a python script

2006-07-18 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Thomas Nelson <[EMAIL PROTECTED]> wrote: >As described in the docs I pointed to before: >subprocess.call("foo.sh",shell=True) >Is the way to do it without args. I think it is simplest to learn the >subprocess module because (quoting from the docs) this module intend

Re: Cyclic class definations

2006-07-18 Thread Nick Vatamaniuc
John, Cycles are tricky. Python is an interpreted dynamic language, whatever object you instantiate in your methods is a different thing than class hierarchy. Your class hierarchy is fine: ClassA->ClassASubclass->ClassC and it should work. If it doesn't, create a quick mock example and post it alo

Defining functions in an implementation file

2006-07-18 Thread westymatt
I am fairly new to python and I want to put alot of my functions in another python file and import or from it into my script so I can call the functions. How is this done? -- http://mail.python.org/mailman/listinfo/python-list

Re: ScientificPython - LeastSquareFit diverges

2006-07-18 Thread Terry Reedy
"Harold Fellermann" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I am trying to fit a powerlaw to a small dataset using > Scientific.Functions.LeastSquares fit. This is a bit off-topic here, and normally better for the scipy list, but I have some experience with nonlinear least

Re: CSV with comments

2006-07-18 Thread skip
>> In csv.reader, is there any way of skip lines that start whith '#' or >> empty lines Nope. When we wrote the module we weren't aware of any "spec" that specified comments or blank lines. You can easily write a file wrapper to filter them out though: class BlankCommentCSVFile:

Re: New SourceForge project: Diet Python!!!

2006-07-18 Thread M�ta-MCI
Hi! Interesting (or fun?). Have you a Internet page, or only README? @+ MCI -- http://mail.python.org/mailman/listinfo/python-list

Re: Dispatch with multiple inheritance

2006-07-18 Thread Nick Vatamaniuc
Michael, You only need to call the __init__ method of the superclass if you need to do something special during initialization. In general I just use the SuperClass.__init__(self,...) way of calling the super class constructors. This way, I only initialize the immediate parents and they will in tur

No need to close file?

2006-07-18 Thread T
Do I need to close the file in this case? Why or why not? for line in file('foo', 'r'): print line -- http://mail.python.org/mailman/listinfo/python-list

Re: Coding style

2006-07-18 Thread Patrick Maupin
Daniel Dittmar wrote: > > Premature generalization: the new 'premature optimization'. Premature specialization: the new 'static typing'. -- Pat -- http://mail.python.org/mailman/listinfo/python-list

Re: No need to close file?

2006-07-18 Thread skip
T> Do I need to close the file in this case? Why or why not? T> for line in file('foo', 'r'): T> print line No. The magic of reference counting. S -- http://mail.python.org/mailman/listinfo/python-list

Re: Defining functions in an implementation file

2006-07-18 Thread Diez B. Roggisch
westymatt schrieb: > I am fairly new to python and I want to put alot of my functions in > another python file and import or from it into my script so I can call > the functions. How is this done? import myfilefullofusefulfunctionsandclasses Works if you have the file myfilefullofusefulfuncti

Re: Capturing instant messages

2006-07-18 Thread Nick Vatamaniuc
Assuming a one person per one machine per one chat protocol it might be possible to recreate the tcp streams (a lot of packet capturing devices already do that). So the gateway would have to have some kind of a dispatch that would recognize the initialization of a chat loggon and start a capture pr

Re: No need to close file?

2006-07-18 Thread bearophileHUGS
T wrote: > Do I need to close the file in this case? Why or why not? > for line in file('foo', 'r'): > print line Close the file in Jython, but often it's not necessary in CPython. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: range() is not the best way to check range?

2006-07-18 Thread bearophileHUGS
Dan Bishop: > xrange already has __contains__. The problem is, it's implemented by a > highly-inefficient sequential search. Why not modify it to merely > check the bounds and (value - start) % step == 0? I think this is a nice idea. Bye, bearophile -- http://mail.python.org/mailman/listinfo/

Re: No need to close file?

2006-07-18 Thread Jarek Zgoda
T napisał(a): > Do I need to close the file in this case? Why or why not? > > for line in file('foo', 'r'): > print line No, if you only read from the file. But anyway, closing file object is considered good practice in many documents I found, no matter what you do with it. -- Jarek Zgoda

Re: Augument assignment versus regular assignment

2006-07-18 Thread Piet van Oostrum
> Antoon Pardon <[EMAIL PROTECTED]> (AP) wrote: >AP> On 2006-07-17, Piet van Oostrum <[EMAIL PROTECTED]> wrote: Antoon Pardon <[EMAIL PROTECTED]> (AP) wrote: >>> >AP> On 2006-07-14, Piet van Oostrum <[EMAIL PROTECTED]> wrote: >>> >> Just read what it says. `It is only evaluated

Re: No need to close file?

2006-07-18 Thread Nick Vatamaniuc
I think file object should be closed whether they will be garbage collected or not. The same goes for DB and network connections and so on. Of course in simple short programs they don't have to, but if someone keeps 1000 open files it might be better to close them when done. Besides open files (

Re: Should this be added to MySQLdb FAQ?

2006-07-18 Thread Nick Vatamaniuc
gmax2006, Yes, perhaps the MySQLdb project should mention that packages are usually available in the popular distributions. I am using Ubuntu and everything I needed for MySQL and Python was in the repositories , 'apt-get' one-lines is all that is needed. In general though, I found that more often

Re: No need to close file?

2006-07-18 Thread Thomas Bartkus
"T" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Do I need to close the file in this case? Why or why not? > > for line in file('foo', 'r'): > print line Are you asking if you can get away without closing it? Or are you asking if it is a good idea to not close it? Good progra

Re: range() is not the best way to check range?

2006-07-18 Thread Simon Forman
K.S.Sreeram wrote: > Simon Forman wrote: > > Nick Craig-Wood wrote: > >> Sets are pretty fast too, and have the advantage of flexibility in > >> that you can put any numbers in you like > >> > > > > I know this is self-evident to most of the people reading this, but I > > thought it worth pointing

Re: Using Visual Slick Edit for Python

2006-07-18 Thread jjones
> P.S. Have you already upgraded to v11 and is there anything worthwhile > in it (Python or otherwise)? Hi, We have just released 11.0.1 where we improve and add new support for scripting and dynamic languages. A snippet of the press release can be found below. SlickEdit v11.0.1 continues to im

Re: run a string as code?

2006-07-18 Thread py_genetic
Gary Herron wrote: > py_genetic wrote: > > py_genetic wrote: > > > >> [EMAIL PROTECTED] wrote: > >> > >>> py_genetic wrote: > >>> > How can you make python interpret a string (of py code) as code. For > example if you want a py program to modify itself as it runs. I know > this is

Re: New SourceForge project: Diet Python!!!

2006-07-18 Thread The Eternal Squire
Hm didn't I leave ctypes in there? I added calldll because it had a really nice can opener. The Eternal Squire [EMAIL PROTECTED] wrote: > >> Diet Python is a flavor of Python with allegro, multiarray, umath, > >> calldll, npstruct and curses builtin, all else nonessential to > >> lan

Re: pytables - best practices / mem leaks

2006-07-18 Thread py_genetic
py_genetic wrote: > I have an H5 file with one group (off the root) and two large main > tables and I'm attempting to aggragate my data into 50+ new groups (off > the root) with two tables per sub group. > > sys info: > PyTables version: 1.3.2 > HDF5 version: 1.6.5 > numarray version: 1.5.0

need help getting xml feed from a url

2006-07-18 Thread Shan
If i have a list of urls how can I extract or pull their respective xml feeds? -- http://mail.python.org/mailman/listinfo/python-list

Re: No need to close file?

2006-07-18 Thread [EMAIL PROTECTED]
T wrote: > Do I need to close the file in this case? Why or why not? > > for line in file('foo', 'r'): > print line I was running a program in IDLE that opened a file for reading and forgot to add the close. The program ran and terminated normally. But when I tried to open it from Windows Ex

Re: Coding style

2006-07-18 Thread David M. Cooke
"Carl Banks" <[EMAIL PROTECTED]> writes: > Patrick Maupin wrote: >> PTY wrote: >> >> > It looks like there are two crowds, terse and verbose. I thought terse >> > is perl style and verbose is python style. BTW, lst = [] was not what >> > I was interested in :-) I was asking whether it was bette

Re: No need to close file?

2006-07-18 Thread Grant Edwards
On 2006-07-18, Sybren Stuvel <[EMAIL PROTECTED]> wrote: > T enlightened us with: >> Do I need to close the file in this case? Why or why not? >> >> for line in file('foo', 'r'): >> print line > > Nope, it'll get closed automatically when the file object gets garbage > collected. Which might not

Re: Coding style

2006-07-18 Thread David M. Cooke
[EMAIL PROTECTED] (David M. Cooke) writes: > > Bruno's already mentioned that iterators and generators aren't > sequences. Numpy arrays act like the other sequence types: > a = numpy.array([]) a > array([], dtype=int64) len(a) > 0 bool(a) > False > > (0-dimensional numpy arrays

Re: No need to close file?

2006-07-18 Thread T
Thomas Bartkus wrote: > "T" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Do I need to close the file in this case? Why or why not? > > > > for line in file('foo', 'r'): > > print line > > Are you asking if you can get away without closing it? > Or are you asking if it is a g

Re: No need to close file?

2006-07-18 Thread Grant Edwards
On 2006-07-18, T <[EMAIL PROTECTED]> wrote: >>> for line in file('foo', 'r'): >>> print line >> Good programming practice says that if you open it - you close it. >> >> And stay out of trouble ;-) > How do I close the file in the above case? Aye, there's the rub. You can't close an anonymous

Re: No need to close file?

2006-07-18 Thread Robert Kern
T wrote: > Thomas Bartkus wrote: >> "T" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >>> Do I need to close the file in this case? Why or why not? >>> >>> for line in file('foo', 'r'): >>> print line >> Are you asking if you can get away without closing it? >> Or are you asking

Re: Coding style

2006-07-18 Thread bearophileHUGS
Volker Grabsch wrote: > IMHO, that flaw of Python should be documented in a PEP as it violates > Python's priciple of beeing explicit. It also harms duck typing. I think this may be good food for Python 3.0, the are removing undefined comparisons too (>), etc. bye, bearophile -- http://mail.pyt

Re: New SourceForge project: Diet Python!!!

2006-07-18 Thread Jarek Zgoda
The Eternal Squire napisał(a): > Diet Python is a flavor of Python with allegro, multiarray, umath, > calldll, npstruct and curses builtin, all else nonessential to language > ripped out. Total size < 3MB, 1% of PSF Python. Diet Python helps keep > clients thin :) Why do you think curses are esse

Re: range() is not the best way to check range?

2006-07-18 Thread Summercoolness
[EMAIL PROTECTED] wrote: > it seems that range() can be really slow: > > if i in range (0, 1): My original use was like this: if i in range (iStart, iEnd): listData.append(a) in which iStart is 1000 and iEnd is 1008 so in that case, the program ran fine... but later on, i

Re: range() is not the best way to check range?

2006-07-18 Thread tac-tics
Simon Forman wrote: > To me, and perhaps others, "T = > set(xrange(0, 1, 23))" and "n in T" are somewhat easier to read > and write than "not n % 23 and 0 <= n < 1", YMMV. Eh? How is the first easier to read than the second?? You have a nested function call in the first! Regardless, test

Re: ScientificPython - LeastSquareFit diverges

2006-07-18 Thread konrad . hinsen
On 18.07.2006, at 15:59, Harold Fellermann wrote: def powerlaw((a,b),x) : > ... return a*x**b Fitting power laws is a tricky business, you need a pretty good initial guess to get convergence. > Note that I could easily fit the above data using gnuplots internal > fitting procedure. An

Re: New SourceForge project: Diet Python!!!

2006-07-18 Thread The Eternal Squire
Best interface for roguelike gaming. Jarek Zgoda wrote: > The Eternal Squire napisa³(a): > > > Diet Python is a flavor of Python with allegro, multiarray, umath, > > calldll, npstruct and curses builtin, all else nonessential to language > > ripped out. Total size < 3MB, 1% of PSF Python. Diet Pyt

Re: New SourceForge project: Diet Python!!!

2006-07-18 Thread The Eternal Squire
I'll try to figure out a way to let people know who the FAQ I am :) The Eternal Squire Méta-MCI wrote: > Hi! > > Interesting (or fun?). > Have you a Internet page, or only README? > > @+ > > MCI -- http://mail.python.org/mailman/listinfo/python-list

Re: range() is not the best way to check range?

2006-07-18 Thread John Machin
On 19/07/2006 1:05 AM, Dan Bishop wrote: > Paul Boddie wrote: > >> Yes, he wants range to return an iterator, just like xrange more or >> less does now. Given that xrange objects support __getitem__, unlike a >> lot of other iterators (and, of course, generators), adding >> __contains__ wouldn't b

Re: Defining functions in an implementation file

2006-07-18 Thread Yu-Xi Lim
westymatt wrote: > I am fairly new to python and I want to put alot of my functions in > another python file and import or from it into my script so I can call > the functions. How is this done? > What you are describing are modules. The Python Tutorial has some information on this http://docs.

Re: Cyclic class definations

2006-07-18 Thread John Henry
Thanks for the note, Nick. I ended up with cycles as a historical reason. Some code that were written long time ago did not anticipate that part of it will get sub-classed. Thanks again. Nick Vatamaniuc wrote: > John, > Cycles are tricky. Python is an interpreted dynamic language, whatever > ob

Can thread start other threads?

2006-07-18 Thread John Henry
Can Python thread start threads? It appears not. When I do that, the sub-threads gets to certain point and just sit there. If I run the code serially and not run the sub-thread code as threads, everything is fine. I throught the problem is when you run multiple processes of Pythons... -- http

Re: CSV with comments

2006-07-18 Thread John Machin
On 19/07/2006 5:34 AM, [EMAIL PROTECTED] wrote: > >> In csv.reader, is there any way of skip lines that start whith '#' or > >> empty lines > > Nope. When we wrote the module we weren't aware of any "spec" that > specified comments or blank lines. You can easily write a file wrapper to >

Re: Capturing instant messages

2006-07-18 Thread Yu-Xi Lim
Nick Vatamaniuc wrote: > Assuming a one person per one machine per one chat protocol it might be > possible to recreate the tcp streams (a lot of packet capturing devices > already do that). So the gateway would have to have some kind of a > dispatch that would recognize the initialization of a cha

Re: Can thread start other threads?

2006-07-18 Thread Diez B. Roggisch
John Henry schrieb: > Can Python thread start threads? It appears not. When I do that, the > sub-threads gets to certain point and just sit there. If I run the > code serially and not run the sub-thread code as threads, everything is > fine. It can. import threading, time class Test(threadin

Re: tkinter help

2006-07-18 Thread John McMonagle
On Tue, 2006-07-18 at 08:37 -0700, groves wrote: > hi eveyrbody , i have started working on python tkinter, > While I was working on one of the tkinter classes..named listbox > widget. I had a slight problem. > > Now let me tell you that i was able to create a simple listbox which > had 6 options

Re: range() is not the best way to check range?

2006-07-18 Thread Paul Boddie
John Machin wrote: > On 19/07/2006 1:05 AM, Dan Bishop wrote: > > > > xrange already has __contains__. > > As pointed out previously, xrange is a function and one would not expect > it to have a __contains__ method. Well, you pointed out that range is a function, but xrange seems to be a type...

Re: tkinter help

2006-07-18 Thread Harold Fellermann
hi, groves wrote: > Now let me tell you that i was able to create a simple listbox which > had 6 options which one can select, but Now what I want is that from > the available menu, if I select an option it should give me another > menu associated with that option. Its like digging up that option

Re: need help getting xml feed from a url

2006-07-18 Thread John Bokma
"Shan" <[EMAIL PROTECTED]> wrote: > If i have a list of urls how can I extract or pull their respective xml > feeds? What have you tried so far? -- John MexIT: http://johnbokma.com/mexit/ personal page: http://johnbokma.com/

Re: Coding style

2006-07-18 Thread Bruno Desthuilliers
Volker Grabsch a écrit : > Bruno Desthuilliers <[EMAIL PROTECTED]> schrieb: > >>PTY wrote: >> >>>I was asking whether it was better style to >>>use len() or not. >> >>FWIW, it's also more generic (you could have an object supporting >>pop() but not __len__()), less error-prone, > > > While I agr

Re: Coding style

2006-07-18 Thread Bruno Desthuilliers
Volker Grabsch a écrit : > Bruno Desthuilliers <[EMAIL PROTECTED]> schrieb: > >>Carl Banks wrote: >> >>>Bruno Desthuilliers wrote: >>> >>>I'm well aware of Python's semantics, and it's irrelvant to my >>>argument. > > [...] > >>>If the language >>>were designed differently, then the rules would

Re: Can thread start other threads?

2006-07-18 Thread John Henry
Thanks for the confirmation. I will see if I can reduce the code down to something managable and post the failing code. Diez B. Roggisch wrote: > John Henry schrieb: > > Can Python thread start threads? It appears not. When I do that, the > > sub-threads gets to certain point and just sit the

Re: Getting and Setting Cookies

2006-07-18 Thread John J. Lee
"Vlad Dogaru" <[EMAIL PROTECTED]> writes: > I am trying to use cookies and Python to create a simple login example. > But I am very disoriented at the existence of two cookie libraries, > namely Cookie and cookielib. I have seen examples of setting cookies [...] >From the cookielib docs: http://

<    1   2   3   >