[Tutor] loops

2009-04-29 Thread Norman Khine
hello, i have the following code: if unique_id is not None: training = self.get_site_root() from training import Training # link back to news item root = context.root formats = ['itinerary', 'news'] for document in formats: results = root.search(format=document, uni

Re: [Tutor] finding mismatched or unpaired html tags

2009-04-29 Thread Alan Gauld
"Lie Ryan" wrote documents were generated by another computer ie. they are not web page documents. If the source document was generated by a computer, and it produces invalid markup, shouldn't that be considered a bug in the producing Elementree parses xml, the source docs are html. Va

Re: [Tutor] loops

2009-04-29 Thread A.T.Hofkamp
Norman Khine wrote: hello, i have the following code: if unique_id is not None: training = self.get_site_root() from training import Training # link back to news item root = context.root formats = ['itinerary', 'news'] for document in formats: results = root.searc

Re: [Tutor] Add newline's, wrap, a long string

2009-04-29 Thread A.T.Hofkamp
David wrote: I am getting information from .txt files and posting them in fields on a web site. I need to break up single strings so they are around 80 characters then a new line because when I enter the info to the form on the website it has fields and it errors out with such a long string.

Re: [Tutor] Regular Expresions instances

2009-04-29 Thread spir
Le Tue, 28 Apr 2009 22:51:09 + (GMT), Emilio Casbas s'exprima ainsi: > > Hi, > > following the example from > http://docs.python.org/3.0/howto/regex.html > > If I execute the following code on the python shell (3.1a1): > > >>> import re > >>> p = re.compile('ab*') > >>> p > > I get the m

Re: [Tutor] loops

2009-04-29 Thread spir
Le Wed, 29 Apr 2009 09:42:44 +0200, "A.T.Hofkamp" s'exprima ainsi: > Norman Khine wrote: > > hello, > > i have the following code: > > > > if unique_id is not None: > > training = self.get_site_root() > > from training import Training > > # link back to news item > > root = conte

Re: [Tutor] finding mismatched or unpaired html tags

2009-04-29 Thread Dinesh B Vadhia
Lie / Alan re: If the source document was generated by a computer, and it produces invalid markup, shouldn't that be considered a bug in the producing program? Yes, absolutely but we don't have access to the producing program only the produced xhtml files. Dinesh ---

Re: [Tutor] Can not run under python 2.6?

2009-04-29 Thread Kent Johnson
On Wed, Apr 29, 2009 at 2:19 AM, Jianchun Zhou wrote: > Hi, there: > > I am new to python, and now I got a trouble: > > I have an application named canola, it is written under python 2.5, and can > run normally under python 2.5 > > But when it comes under python 2.6, problem up, it says: > > Trace

Re: [Tutor] Regular Expresions instances

2009-04-29 Thread Kent Johnson
On Tue, Apr 28, 2009 at 7:24 PM, Emile van Sebille wrote: > Emile van Sebille wrote: > Possibly a case of the documentation not keeping up with the release... It's pretty easy to file a bug report against the docs. Minor fixes like this are often incorporated fairly quickly. See http://docs.pyth

Re: [Tutor] loops

2009-04-29 Thread Kent Johnson
On Wed, Apr 29, 2009 at 3:05 AM, Norman Khine wrote: > hello, > i have the following code: > > if unique_id is not None: >    training = self.get_site_root() >    from training import Training >    # link back to news item >    root = context.root >    formats = ['itinerary', 'news'] >    for docu

Re: [Tutor] Add newline's, wrap, a long string

2009-04-29 Thread David
Martin Walsh wrote: ... but, you don't need to use subprocess at all. How about (untested), # grep USE /tmp/comprookie2000/emerge_info.txt |head -n1|cut -d\" -f2 infof = open('/tmp/comprookie2000/emerge_info.txt') for line in infof: if 'USE' in line: USE = line.split('"')[1]

Re: [Tutor] Can not run under python 2.6?

2009-04-29 Thread Lie Ryan
Jianchun Zhou wrote: Hi, there: I am new to python, and now I got a trouble: I have an application named canola, it is written under python 2.5, and can run normally under python 2.5 But when it comes under python 2.6, problem up, it says: Traceback (most recent call last): File "/usr/lib

Re: [Tutor] loops

2009-04-29 Thread Lie Ryan
Norman Khine wrote: hello, i have the following code: Uhh... 5 levels deep of nesting, and from the hint that you used self.blah earlier this is inside a class which adds a minimum of two extra levels, in total of 7 levels nesting... We're in deep trouble. is there a way to optimise the lo

Re: [Tutor] Add newline's, wrap, a long string

2009-04-29 Thread David
David wrote: Martin Walsh wrote: Just one more comment, string.join is deprecated, yet join is a method of str objects. So ... Lines = '\n'.join(L) ... or use textwrap.fill which returns a string with the newlines already in place ... Lines = textwrap.fill(USE, 80) HTH, Marty

Re: [Tutor] Add newline's, wrap, a long string

2009-04-29 Thread Sander Sweers
2009/4/29 David : > Here is the whole program so far, what it does is it logs into a druple web > site and posts. I would like to make it better, as you can see I do the same > thing over and over. > > http://linuxcrazy.pastebin.com/m7689c088 What you can do is define all the variables upfront. Th

Re: [Tutor] Add newline's, wrap, a long string

2009-04-29 Thread Martin Walsh
David wrote: > Martin Walsh wrote: >>> ... but, you don't need to use subprocess at all. How about (untested), >>> >>> # grep USE /tmp/comprookie2000/emerge_info.txt |head -n1|cut -d\" -f2 >>> infof = open('/tmp/comprookie2000/emerge_info.txt') >>> for line in infof: >>> if 'USE' in line: >>>

Re: [Tutor] Add newline's, wrap, a long string

2009-04-29 Thread Martin Walsh
Sander Sweers wrote: > 2009/4/29 David : >> Here is the whole program so far, what it does is it logs into a druple web >> site and posts. I would like to make it better, as you can see I do the same >> thing over and over. >> >> http://linuxcrazy.pastebin.com/m7689c088 > > What you can do is defi

Re: [Tutor] Regular Expresions instances

2009-04-29 Thread Emilio Casbas
Thanks to all for the responses. I've filled a bug report as you pointed out. http://bugs.python.org/msg86803 Thanks Emilio - Mensaje original > De: Kent Johnson > Para: Emile van Sebille > CC: tutor@python.org > Enviado: miércoles, 29 de abril, 2009 13:06:49 > Asunto: Re: [Tutor]

[Tutor] imported scope

2009-04-29 Thread spir
Hello, I have an issue with scopes (namespaces). Say I have a source file 'test.py' with the single line: print vars() # same with locals() Now, from the command-line: s...@o:~/prog/pijnu$ python test.py {'__builtins__': , '__name__': '__main__', '__file__': 'test.py', '__doc__': Non

Re: [Tutor] imported scope

2009-04-29 Thread Kent Johnson
On Wed, Apr 29, 2009 at 9:56 AM, spir wrote: > Hello, > > I have an issue with scopes (namespaces). > Say I have a source file 'test.py' with the single line: >   print vars()         # same with locals() > > Now, from the command-line: > > s...@o:~/prog/pijnu$ python test.py > {'__builtins__': ,

Re: [Tutor] testing framework

2009-04-29 Thread Eike Welk
Hello Spir! On Thursday 23 April 2009, spir wrote: > I would like to refactor tests of an application in a consistent > form. I have a ton of tests for each module, but they are all ad > hoc things. doctest looks great. The issue is it seems based on > command line-like testing: I have researched

[Tutor] Dictionary, integer, compression

2009-04-29 Thread Dinesh B Vadhia
This could be a question for the comp.lang.python list but I'll try here first: Say, you have a dictionary of integers, are the integers stored in a compressed integer format or as integers ie. are integers encoded before being stored in the dictionary and then decoded when read? Dinesh ___

Re: [Tutor] imported scope

2009-04-29 Thread Kent Johnson
On Wed, Apr 29, 2009 at 10:54 AM, spir wrote: > Le Wed, 29 Apr 2009 10:05:04 -0400, > Kent Johnson s'exprima ainsi: >> There is some discussion here: >> http://mail.python.org/pipermail/python-3000/2007-March/006161.html >> >> Short answer: __builtins__ is an implementation detail that you should

Re: [Tutor] Dictionary, integer, compression

2009-04-29 Thread Alan Gauld
"Dinesh B Vadhia" wrote Say, you have a dictionary of integers, are the integers stored in a compressed integer format or as integers ie. are integers encoded before being stored in the dictionary and then decoded when read? I can't think of any reason to compress them, I imagine they are

Re: [Tutor] Dictionary, integer, compression

2009-04-29 Thread Stefan Behnel
Dinesh B Vadhia wrote: > Say, you have a dictionary of integers, are the integers stored in a > compressed integer format or as integers ie. are integers encoded before > being stored in the dictionary and then decoded when read? Integer objects are not special cased in dictionaries. They are stor

Re: [Tutor] Add newline's, wrap, a long string

2009-04-29 Thread Alan Gauld
"Sander Sweers" wrote What you can do is define all the variables upfront. This way you can get rid of the else. Below is an example how you can do this with only looping once over the fle. And you can put the variables as keys of a dictionary and avoid all the if tests: data = {'CBUILD':

Re: [Tutor] Add newline's, wrap, a long string

2009-04-29 Thread David
Alan Gauld wrote: "Sander Sweers" wrote What you can do is define all the variables upfront. This way you can get rid of the else. Below is an example how you can do this with only looping once over the fle. And you can put the variables as keys of a dictionary and avoid all the if tests:

[Tutor] Fw: imported scope

2009-04-29 Thread spir
Le Wed, 29 Apr 2009 12:32:57 -0400, Kent Johnson s'exprima ainsi: > On Wed, Apr 29, 2009 at 10:54 AM, spir wrote: > > Le Wed, 29 Apr 2009 10:05:04 -0400, > > Kent Johnson s'exprima ainsi: > >> There is some discussion here: > >> http://mail.python.org/pipermail/python-3000/2007-March/006161.h

Re: [Tutor] Dictionary, integer, compression

2009-04-29 Thread Dinesh B Vadhia
Alan I want to perform test runs on my local machine with very large numbers of integers stored in a dictionary. As the Python dictionary is an built-in function I thought that for very large dictionaries there could be compression. Done correctly, integer compression wouldn't affect performa

[Tutor] Printing Problem python 3

2009-04-29 Thread Dave Crouse
Trying to print something with a { in it. Probably extremely simple, but it's frustrating me. :( print ('The \"This is a test \" {') i get this error ValueError: Single '{' encountered in format string ___ Tutor maillist - Tutor@python.org http://ma

[Tutor] How to Extend a class in another file in same directory

2009-04-29 Thread sudhanshu gautam
I made a program named as a title.py inside it used Inheritance , now I want to Extend the Parent Class in another program(file also) but having an Error lets check ,my code 1.first file title .py class global Studentdatabase: def __init__(self,name,age,standard,place,dateofbirth,sex):

Re: [Tutor] Printing Problem python 3

2009-04-29 Thread Kent Johnson
On Wed, Apr 29, 2009 at 2:42 PM, Dave Crouse wrote: > Trying to print something with a { in it. > Probably extremely simple, but it's frustrating me.  :( > > print ('The \"This is a test \" {') > > i get this error > > ValueError: Single '{' encountered in format string It works for me: Python 3.

Re: [Tutor] Printing Problem python 3

2009-04-29 Thread Dave Crouse
The double {{ }} worked perfectly, THANK YOU ! :) This was driving me crazy. On Wed, Apr 29, 2009 at 2:03 PM, Kent Johnson wrote: > print ('The \"This is a test \" {') > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/

[Tutor] Conventional Y Axis Label in pylab plot

2009-04-29 Thread Wayne Watson
I'd like to label the plot axes as x and y. All I see is xlabel and ylabel. ylabel puts y on its side, rotated 90 degrees from the horizontal. Is there way to put it in a normal reading position? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W,

Re: [Tutor] Printing Problem python 3

2009-04-29 Thread Shantanoo Mahajan (शंत नू महा जन)
On 30-Apr-09, at 12:12 AM, Dave Crouse wrote: Trying to print something with a { in it. Probably extremely simple, but it's frustrating me. :( print ('The \"This is a test \" {') i get this error ValueError: Single '{' encountered in format string Worked perfectly for me. === $ python3.0

Re: [Tutor] Printing Problem python 3

2009-04-29 Thread Dave Crouse
I got the same thing with idle, but when running as a script, it's not the same, it errors. I tried it on Windows and Linux. --- [da...@arch64 Python]$ less test.py #/usr/bin/python3 print ('The \"This is a test \" {') [da...@arch64 Python]$ sh test.py tes

Re: [Tutor] How to Extend a class in another file in same directory

2009-04-29 Thread Dave Angel
sudhanshu gautam wrote: 2.Now another file in which I want to extend that same parent class is here .First code running successfully but in another one having problem 'This another source code will represent the new Entry of database' import title class Newstudent(Studentdatabase): def

Re: [Tutor] Add newline's, wrap, a long string

2009-04-29 Thread Alan Gauld
"David" wrote I don't know how else to describe it, that is so cool :) :-) Couple of comments below. import textwrap data = {'CBUILD':None, 'CFLAGS':None, 'MAKEOPTS':None} def get_use(): fname = open('/tmp/comprookie2000/emerge_info.txt') for line in fname: for keyphrase

Re: [Tutor] Printing Problem python 3

2009-04-29 Thread Vern Ceder
Dave Crouse wrote: I got the same thing with idle, but when running as a script, it's not the same, it errors. I tried it on Windows and Linux. --- [da...@arch64 Python]$ less test.py #/usr/bin/python3 print ('The \"This is a test \" {') [da...@arch64 Py