Re: print header for output

2011-06-19 Thread Ben Finney
Chris Rebert writes: > Also, in the future, avoid replying to the mailinglist digest, or at > the very least please trim off the irrelevant quoted posts in your > reply. Right. It will help communication greatly if you reply inline with specific quoted material (what Wikipedia calls “interleaved

Re: NEED HELP-process words in a text file

2011-06-19 Thread Stefan Behnel
Cathy James, 19.06.2011 01:21: def fileProcess(filename): """Call the program with an argument, it should treat the argument as a filename, splitting it up into words, and computes the length of each word. print a table showing the word count for each of the word lengths that

Re: New member intro and question

2011-06-19 Thread Anthony Papillion
Just wanted to thank you guys for taking the time to respond. Looks like my 'limited resources' aren't so limited after all! Cheers, Anthony -- http://mail.python.org/mailman/listinfo/python-list

Re: Strategy to Verify Python Program is POST'ing to a web server.

2011-06-19 Thread Steven D'Aprano
On Sun, 19 Jun 2011 05:47:30 +0100, Nobody wrote: > On Sat, 18 Jun 2011 04:34:55 -0700, [email protected] wrote: > >> I am wondering what your strategies are for ensuring that data >> transmitted to a website via a python program is indeed from that >> program, and not from someone submitting PO

Re: Strategy to Verify Python Program is POST'ing to a web server.

2011-06-19 Thread Paul Rubin
Steven D'Aprano writes: >> Supply the client with tamper-proof hardware containing a private key. > > Is that resistant to man-in-the-middle attacks by somebody with a packet > sniffer watching the traffic between the device and the website? Sure, why not? As long as the crypto is done properly

Re: Python and Lisp : car and cdr

2011-06-19 Thread Ethan Furman
Lie Ryan wrote: On 06/18/11 00:45, Franck Ditter wrote: Hi, I'm just wondering about the complexity of some Python operations to mimic Lisp car and cdr in Python... def length(L) : if not L : return 0 return 1 + length(L[1:]) Should I think of the slice L[1:] as (cdr L) ? I mean, is the s

Re: HTTPConncetion - HEAD request

2011-06-19 Thread Elias Fotinis
On Fri, 17 Jun 2011 20:53:39 +0300, gervaz wrote: I decided to implement this solution: class HeadRequest(urllib.request.Request): def get_method(self): return "HEAD" Now I download the url using: r = HeadRequest(url, None, self.headers) c = urllib.request.urlopen(r) but I don't

Re: Python and Lisp : car and cdr

2011-06-19 Thread Chris Angelico
On Sun, Jun 19, 2011 at 10:56 PM, Ethan Furman wrote: > Lie Ryan wrote: >> def cdr(L): >>    return L[1] > > IANAL (I am not a Lisper), but shouldn't that be 'return L[1:]' ? In LISP, a list is a series of two-item units (conses). >> L = (a, (b, (c, (d, None This represents the LISP equival

Re: Python and Lisp : car and cdr

2011-06-19 Thread Steven D'Aprano
On Sun, 19 Jun 2011 05:56:27 -0700, Ethan Furman wrote: > Lie Ryan wrote: >> On 06/18/11 00:45, Franck Ditter wrote: >>> Hi, I'm just wondering about the complexity of some Python operations >>> to mimic Lisp car and cdr in Python... >>> >>> def length(L) : >>> if not L : return 0 >>> return 1

Re: Python and Lisp : car and cdr

2011-06-19 Thread Elias Fotinis
On Sun, 19 Jun 2011 15:56:27 +0300, Ethan Furman wrote: Lie Ryan wrote: def length(L): if not L: return 0 return 1 + length(cdr(L)) How is this different from regular ol' 'len' ? It's better, because len() can't overflow the stack. ;) -- http://mail.python.org/mailman/listinfo/py

What is this syntax ?

2011-06-19 Thread candide
With Python 2.7 : >>> x="foo" >>> print '"'+x+'"' "foo" >>> What is this curious syntax on line 2 ? Where is it documented ? -- http://mail.python.org/mailman/listinfo/python-list

Re: What is this syntax ?

2011-06-19 Thread Laurent Claessens
Le 19/06/2011 15:41, candide a écrit : With Python 2.7 : >>> x="foo" >>> print '"'+x+'"' "foo" >>> What is this curious syntax on line 2 ? Where is it documented ? When you want to have an explicit double quote " in a string, you put in between single quote '. (and vice versa) So

Re: What is this syntax ?

2011-06-19 Thread Noah Hall
On Sun, Jun 19, 2011 at 2:41 PM, candide wrote: > With Python 2.7 : > x="foo" print '"'+x+'"' > "foo" > What is this curious syntax on line 2 ? Where is it documented ? Just to make it clear to you what is happening - >>> x = "foo" >>> print ' " ' + x + ' " ' " foo " >>> Anyway, it'

Re: What is this syntax ?

2011-06-19 Thread Chris Angelico
On Sun, Jun 19, 2011 at 11:41 PM, candide wrote: > With Python 2.7 : > x="foo" print '"'+x+'"' > "foo" As Laurent posted, it's simply a literal double-quote character, enclosed in single quotes. But for making a quoted string, this isn't reliable (what if there's a double quote in

Re: Python and Lisp : car and cdr

2011-06-19 Thread Hrvoje Niksic
Ethan Furman writes: >> def car(L): >> return L[0] >> def cdr(L): >> return L[1] > > IANAL (I am not a Lisper), but shouldn't that be 'return L[1:]' ? Not for the linked list implementation he presented. >> def length(L): >> if not L: return 0 >> return 1 + length(cdr(L)) > > Ho

Re: Improper creating of logger instances or a Memory Leak?

2011-06-19 Thread Vinay Sajip
foobar gmail.com> writes: > I've run across a memory leak in a long running process which I can't > determine if its my issue or if its the logger. As Chris Torek said, it's not a good idea to create a logger for each thread. A logger name represents a place in your application; typically, a mod

Re: Best way to insert sorted in a list

2011-06-19 Thread Vito De Tullio
SherjilOzair wrote: > There are basically two ways to go about this. [...] > What has the community to say about this ? What is the best (fastest) > way to insert sorted in a list ? a third way maybe using a SkipList instead of a list on http://infohost.nmt.edu/tcc/help/lang/python/examples/py

How to iterate on a changing dictionary

2011-06-19 Thread TheSaint
Hello Trying to pop some key from a dict while is iterating over it will cause an exception. How I can remove items when the search result is true. Example: while len(dict): for key in dict.keys(): if dict[key] is not my_result: dict.pop(key) else: condition_to_brea

Re: What would you like to see in a File Organizer ?

2011-06-19 Thread TheSaint
zainul franciscus wrote: > we are looking for > some ideas for good functionality for the application. T I was looking for a file cataloger. this program may go into same category as far as handling file names ad file system's structures. It also manage to store unused files into zipped archives

Re: Improper creating of logger instances or a Memory Leak?

2011-06-19 Thread Vinay Sajip
foobar gmail.com> writes: > > I've run across a memory leak in a long running process which I can't > determine if its my issue or if its the logger. > BTW did you also ask this question on Stack Overflow? I've answered there, too. http://stackoverflow.com/questions/6388514/ Regards, Vinay

Re: threading : make stop the caller

2011-06-19 Thread Chris Angelico
On Mon, Jun 20, 2011 at 1:39 AM, Laurent Claessens wrote: > My problem is that when FileToCopyTask raises an error, the program does not > stop. > In fact when the error is Disk Full, I want to stop the whole program > because I know that the next task will fail too. If you're starting a thread f

Re: How to iterate on a changing dictionary

2011-06-19 Thread Chris Angelico
On Mon, Jun 20, 2011 at 12:32 AM, TheSaint wrote: > Hello > > Trying to pop some key from a dict while is iterating over it will cause an > exception. > How I can remove items when the search result is true. > > Example: > > while len(dict): >   for key in dict.keys(): >      if dict[key] is not m

Re: threading : make stop the caller

2011-06-19 Thread Laurent Claessens
Le 19/06/2011 17:19, Chris Angelico a écrit : On Mon, Jun 20, 2011 at 12:42 AM, Laurent Claessens wrote: Hello I've a list of tasks to perform. Each of them is a threading.Thread. Basically I have : while task_list : task = task_list[0] task.run() task_list.remove(task)

Re: Python 2.7.2 for Windows reports version as 2.7.0?

2011-06-19 Thread python
Hi Mark, > The version info comes from the DLL - I wonder if the DLL being found is > somehow old? > > Make sure: > > >>> import sys > >>> win32api.GetModuleFileName(sys.dllhandle) > > Is the DLL you expect. After uninstalling and reinstalling for the current user only (vs. all users), Python no

Re: What is this syntax ?

2011-06-19 Thread candide
OK, thanks for your explanation, it was just stringisation ! I erroneously focused on +x+ as a kind of placeholder unknown to me, instead of left and right concatenations ;) It would be more readable for me if it were edited >>> print '"' + x + '"' # better spacing "foo" >>> or with stri

Re: Python and Lisp : car and cdr

2011-06-19 Thread Ethan Furman
Ethan Furman wrote: IANAL (I am not a Lisper), but shouldn't that be 'return L[1:]' ? Ah, thanks all for the clarification. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and Lisp : car and cdr

2011-06-19 Thread Terry Reedy
On 6/19/2011 9:24 AM, Steven D'Aprano wrote: No. Each cell in a Lisp-style linked list has exactly two elements, and in Python are usually implemented as nested tuples: (head, tail) # Annoyingly, this is also known as (car, cdr). where head is the data value and tail is either another Lisp-st

Re: threading : make stop the caller

2011-06-19 Thread Terry Reedy
On 6/19/2011 11:39 AM, Laurent Claessens wrote: In the same time I've a thread that read the list and perform the operations: def run(): while task_list : task = task_list[0] task_list.remove(task) task.start() Popping task off the end of the list is more efficient: while task_list: task_l

Re: Python and Lisp : car and cdr

2011-06-19 Thread Teemu Likonen
* 2011-06-19T12:20:32-04:00 * Terry Reedy wrote: > On 6/19/2011 9:24 AM, Steven D'Aprano wrote: >> No. Each cell in a Lisp-style linked list has exactly two elements, >> and in Python are usually implemented as nested tuples: >> >> (head, tail) # Annoyingly, this is also known as (car, cdr). >> >

Re: threading : make stop the caller

2011-06-19 Thread Laurent Claessens
Le 19/06/2011 18:03, Chris Angelico a écrit : On Mon, Jun 20, 2011 at 1:39 AM, Laurent Claessens wrote: My problem is that when FileToCopyTask raises an error, the program does not stop. In fact when the error is Disk Full, I want to stop the whole program because I know that the next task

Re: How to iterate on a changing dictionary

2011-06-19 Thread Terry Reedy
On 6/19/2011 11:53 AM, Roy Smith wrote: Yet another variation which makes sense if you want to delete most of the keys would be to copy them to a new dictionary. I'm not sure how Python handles memory management on dictionaries which shrink. 'Python' does not handle memory management; each im

Re: threading : make stop the caller

2011-06-19 Thread Laurent Claessens
Popping task off the end of the list is more efficient: while task_list: task_list.pop().start() That's cool. In my case it's better to do task_list.pop(0).start in order to pop the first element. or if the list is static No, my list is dynamic and is feeded by an other thread (whi

Re: What is this syntax ?

2011-06-19 Thread Roy Smith
In article <[email protected]>, candide wrote: > OK, thanks for your explanation, it was just stringisation ! > > > I erroneously focused on > > +x+ > > as a kind of placeholder unknown to me, instead of left and right > concatenations ;) > > It would be more readable

threading : make stop the caller

2011-06-19 Thread Laurent Claessens
Hello I've a list of tasks to perform. Each of them is a threading.Thread. Basically I have : while task_list : task = task_list[0] task.run() task_list.remove(task) Now I want, in some circumstance to raise errors that make the loop stop. In order IOError to make stop the loop

Re: threading : make stop the caller

2011-06-19 Thread Laurent Claessens
I read the library documentation. I think that if I get a trick to kill a thread, then I'm done. Is there a way ? Laurent Le 19/06/2011 17:39, Laurent Claessens a écrit : Le 19/06/2011 17:19, Chris Angelico a écrit : On Mon, Jun 20, 2011 at 12:42 AM, Laurent Claessens wrote: Hello

Re: How to iterate on a changing dictionary

2011-06-19 Thread Roy Smith
In article , Chris Angelico wrote: > On Mon, Jun 20, 2011 at 12:32 AM, TheSaint wrote: > > Hello > > > > Trying to pop some key from a dict while is iterating over it will cause an > > exception. > > How I can remove items when the search result is true. > > > > Example: > > > > while len(dict)

Re: How to iterate on a changing dictionary

2011-06-19 Thread Terry Reedy
On 6/19/2011 11:13 AM, Chris Angelico wrote: On Mon, Jun 20, 2011 at 12:32 AM, TheSaint wrote: Hello Trying to pop some key from a dict while is iterating over it will cause an exception. How I can remove items when the search result is true. Example: while len(dict): for key in dict.keys

Re: threading : make stop the caller

2011-06-19 Thread Chris Angelico
On Mon, Jun 20, 2011 at 12:42 AM, Laurent Claessens wrote: >   Hello > > > I've a list of tasks to perform. Each of them is a threading.Thread. > Basically I have : > > while task_list : >   task = task_list[0] >   task.run() >   task_list.remove(task) I'm not understanding what you're doing with

Re: threading : make stop the caller

2011-06-19 Thread Terry Reedy
On 6/19/2011 12:03 PM, Chris Angelico wrote: On Mon, Jun 20, 2011 at 1:39 AM, Laurent Claessens wrote: My problem is that when FileToCopyTask raises an error, the program does not stop. In fact when the error is Disk Full, I want to stop the whole program because I know that the next task will

Re: What is this syntax ?

2011-06-19 Thread rusi
On Jun 19, 8:39 pm, Roy Smith wrote: > This is one of the (very) few places PHP wins over Python.  In PHP, I > would write this as > > print "'$x'" You dont find >>> print '"%s"' % x readable? Why? -- http://mail.python.org/mailman/listinfo/python-list

Re: How to iterate on a changing dictionary

2011-06-19 Thread Lie Ryan
On 06/20/11 00:32, TheSaint wrote: > Hello > > Trying to pop some key from a dict while is iterating over it will cause an > exception. > How I can remove items when the search result is true. > > Example: > > while len(dict): >for key in dict.keys(): > if dict[key] is not my_result:

Re: threading : make stop the caller

2011-06-19 Thread Lie Ryan
On 06/20/11 02:52, Laurent Claessens wrote: > >> Popping task off the end of the list is more efficient: > >> while task_list: >> task_list.pop().start() > > That's cool. In my case it's better to do > task_list.pop(0).start > > in order to pop the first element. then you really wanted a q

Re: What is this syntax ?

2011-06-19 Thread Roy Smith
In article , rusi wrote: > On Jun 19, 8:39 pm, Roy Smith wrote: > > > This is one of the (very) few places PHP wins over Python.  In PHP, I > > would write this as > > > > print "'$x'" > > > You dont find > > >>> print '"%s"' % x > > readable? Why? I didn't say it wasn't readable, I said

Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile toImprovethe Dvorak Layout?

2011-06-19 Thread rusi
On Jun 19, 10:50 am, Lie Ryan wrote: > On 06/19/11 15:14, rusi wrote: > > > > > On Jun 19, 9:21 am, Lie Ryan wrote: > >> On 06/18/11 03:53, Xah Lee wrote: > > >>> On Jun 15, 5:43 am, rusi wrote: > On Jun 15, 5:32 pm, Dotan Cohen wrote: > > > Thanks. From testing small movements with my

Re: What is this syntax ?

2011-06-19 Thread Vito 'ZeD' De Tullio
Roy Smith wrote: > There's something nice about building up strings in-line, as > opposed to having to look somewhere to see what's being interpolated. > To give a more complex example, consider: > > print "$scheme://$host:$port/$route#$fragment" > > That certainly seems easier to me to read tha

Re: What is this syntax ?

2011-06-19 Thread Benjamin Kaplan
On Sun, Jun 19, 2011 at 2:06 PM, Vito 'ZeD' De Tullio wrote: > Roy Smith wrote: > >> There's something nice about building up strings in-line, as >> opposed to having to look somewhere to see what's being interpolated. >> To give a more complex example, consider: >> >> print "$scheme://$host:$port

Re: What is this syntax ?

2011-06-19 Thread Steven D'Aprano
On Sun, 19 Jun 2011 23:06:36 +0200, Vito 'ZeD' De Tullio wrote: > well, in python3 you can use dict to format strings > print("%(a)s" % {'a':'b'}) > b It's not just Python 3. That bit of functionality goes back all the way to Python 1.5, which is the oldest version I have installed. In Py

Re: What's the best way to write this base class?

2011-06-19 Thread Chris Kaynor
On Jun 18, 2011, at 9:26, John Salerno wrote: > Whew, thanks for all the responses! I will think about it carefully > and decide on a way. I was leaning toward simply assigning the health, > resource, etc. variables in the __init__ method, like this: > > def __init__(self, name): >self.name

Re: What's the best way to write this base class?

2011-06-19 Thread John Salerno
On Jun 19, 8:52 pm, Chris Kaynor wrote: > Having a character class (along with possibly player character, non-player > character, etc), make sense; however you probably want to make stuff like > health, resources, damage, and any other attributes not be handles by any > classes or inheritance

running multiple scripts -- which way is more elegant?

2011-06-19 Thread Stephen Bunn
List, First I'm very new to Python. I usually do this kind of thing with shell scripts, however, I'm trying to move to using python primarily so I can learn the language. I'm attempting to write a script that will check a server for various configuration settings and report and/or change based

Re: running multiple scripts -- which way is more elegant?

2011-06-19 Thread Chris Angelico
On Mon, Jun 20, 2011 at 2:13 PM, Stephen Bunn wrote: > List, > >   First I'm very new to Python. I usually do this kind of thing with shell > scripts, however, I'm trying to move to using python primarily so I can > learn the language. A worthy cause :) > ...  I have come up with two ways to > a

Re: What is this syntax ?

2011-06-19 Thread Vito 'ZeD' De Tullio
Steven D'Aprano wrote: >> and you can achieve php interpolation via locals() >> > a = 'b' > print("%(a)s" % locals()) >> b > > You can do that, but when reading code I consider any direct use of > locals() (and globals() for that matter) to be a code smell: well you're right, me neither

opening a file

2011-06-19 Thread Tim Hanson
Using linux and Python 2.6, learning how to work with files from a Windows oriented textbook: This works: infile=open('/foo/bar/prog/py_modules/this_is_a_test','r') This doesn't: infile=open('~/prog/py_modules/this_is_a_test','r') Can't I work with files using Unix expressions? -- http://mail.

Re: opening a file

2011-06-19 Thread Florencio Cano
> This works: > infile=open('/foo/bar/prog/py_modules/this_is_a_test','r') > > This doesn't: > infile=open('~/prog/py_modules/this_is_a_test','r') > > Can't I work with files using Unix expressions? You can use the glob module: http://docs.python.org/library/glob.html#module-glob -- http://mail.p

Re: running multiple scripts -- which way is more elegant?

2011-06-19 Thread Florencio Cano
> I'd be inclined toward the second solution if I'm writing all the code > myself, but very definitely the first if someone else might write one > of the subscripts (especially so if this is going to be distributed > widely) - spawning a new process means that the system's isolation of > processes

Re: opening a file

2011-06-19 Thread Paul Scott
On Mon, 2011-06-20 at 08:14 +0200, Florencio Cano wrote: > > This works: > > infile=open('/foo/bar/prog/py_modules/this_is_a_test','r') > > > > This doesn't: > > infile=open('~/prog/py_modules/this_is_a_test','r') > > > > Can't I work with files using Unix expressions? > > You can use the glob mod

Re: opening a file

2011-06-19 Thread Chris Rebert
On Sun, Jun 19, 2011 at 11:00 PM, Tim Hanson wrote: > Using linux and Python 2.6, learning how to work with files from a Windows > oriented textbook: > > This works: > infile=open('/foo/bar/prog/py_modules/this_is_a_test','r') > > This doesn't: > infile=open('~/prog/py_modules/this_is_a_test','r')

Re: running multiple scripts -- which way is more elegant?

2011-06-19 Thread Stephen Bunn
On Mon, Jun 20, 2011 at 1:26 PM, Chris Angelico wrote: > > I'd be inclined toward the second solution if I'm writing all the code > > myself > On Mon, Jun 20, 2011 at 3:21 PM, Florencio Cano wrote: > I'm with Chris, if the config_scripts are going to be implemented in > Python always, the second