Re: [Tutor] Add elements to list and display it [Very newbie question]

2009-02-27 Thread spir
Le Fri, 27 Feb 2009 11:19:50 -0600, Network Administrator s'exprima ainsi: > I am beggining to learn Python and I appreciate if you help me with this: > > "I want a piece of a program to request the user to input "elements" > (numbers, text, etc) and store them into a list. Then, I want to displ

Re: [Tutor] new print statement + time module

2009-02-27 Thread spir
Le Sat, 28 Feb 2009 06:34:07 +0200, George Wahid s'exprima ainsi: > I downloaded python 3.0.1 today and started experimenting with the new > print statement. > > >>>import time > >>>for l in 'the answer': > ...print(l,end='') > ...time.sleep(0.1) > > the code is supposed to print "the a

Re: [Tutor] loop performance in global namespace (python-2.6.1)

2009-03-12 Thread spir
Le Thu, 12 Mar 2009 11:13:33 -0400, Kent Johnson s'exprima ainsi: > Because local name lookup is faster than global name lookup. Local > variables are stored in an array in the stack frame and accessed by > index. Global names are stored in a dict and accessed with dict access > (dict.__getitem__

Re: [Tutor] Paython as a career

2009-03-17 Thread spir
Le Tue, 17 Mar 2009 03:45:36 -0500, Luke Paireepinart s'exprima ainsi: > If you're really asking us which language has the largest job market, Python > is definitely not the answer to that question? Can you find jobs in > Python? Sure, if you are determined and you look hard enough. But as far

[Tutor] list.replace -- string.swap

2009-03-17 Thread spir
Is there a list.replace builtin I cannot find? Or a workaround? Also: How would perform string.swap(s1, s2) in the following cases: * There is no secure 'temp' char, meaning that s.replace(s1,temp).replace(s2,s1).replace(temp,s2) will fail because any char can be part of s. * Either s

Re: [Tutor] Binary Real to Decimal

2009-03-30 Thread spir
Le Sun, 29 Mar 2009 22:42:43 -0500, Chris Castillo s'exprima ainsi: > myinput = raw_input("Please enter a binary real number: ") > myinput = myinput.split(".") > > binstr1 = myinput[0] > binstr2 = myinput[1] > > decnum1 = 0 > decnum2 = 0 > > for i in binstr1: > decnum1 = decnum1 * 2 + int

[Tutor] how are unicode chars represented?

2009-03-30 Thread spir
Everything is in the title ;-) (Is it kind of integers representing the code point?) Denis -- la vita e estrany ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] __callattr__ ?

2009-03-30 Thread spir
Hello, Is there something like a __callattr__ magic method that would catch either unknown (like __getattr__) or all (like __getattribute__) method calls? If not, how would you do that? Also if not, do you know why we have __getattr__, __setattr__, but no __callattr__? Denis -- la vita e es

Re: [Tutor] range() fractional increment

2009-03-31 Thread spir
Le Mon, 30 Mar 2009 20:44:28 -0700 (PDT), james carnell s'exprima ainsi: > 1) I feel dumb for asking this. > 2) I looked for 20 minutes and didn't find an answer > > Trying to make a drawLine function in a 2d array. > > example: > x   row = 25 : col = 10 > x   row = 26 : col = 10.3 > x0

Re: [Tutor] renumbering a sequence

2009-04-05 Thread spir
Le Sat, 4 Apr 2009 20:05:41 -0400, Kent Johnson s'exprima ainsi: > On Sat, Apr 4, 2009 at 3:37 PM, Christopher Spears > wrote: > > > > I want to write a script that takes a list of images and renumbers them > > with a user supplied number.  Here is a solution I came up while noodling > > around

Re: [Tutor] problem in replacing regex

2009-04-06 Thread spir
Le Mon, 6 Apr 2009 19:53:25 +0530, Kumar s'exprima ainsi: > Hello everyone, > > I have one account number. I want to replace all this account numbers and > convert them as URLS. > > but I don't want to convert existing urls which has account numbers. [...] I'm not sure of what you expect, wha

Re: [Tutor] Please use plain text.

2009-04-07 Thread spir
Le Mon, 6 Apr 2009 22:01:11 +0100, "Alan Gauld" s'exprima ainsi: > Web forums are far less useful than mailing lists for technical groups. > They require internet access and a browser to read them. > Many require a graphical browser so don't work in text mode > terminals. Very few are available

Re: [Tutor] problem in replacing regex

2009-04-07 Thread spir
[forwarded to list] Le Tue, 7 Apr 2009 12:23:33 +0530, Kumar s'exprima ainsi: > Hi denis, > > Thanks a lot for the reply. > > Actually on our web application when we display the data, at that time we do > parsing and make hyperlinks (through ) wherever possible. so if there is > any url like (

Re: [Tutor] problem in replacing regex

2009-04-08 Thread spir
Le Wed, 8 Apr 2009 12:31:31 +0530, Kumar s'exprima ainsi: > Hi Danis, > > Just to be more specific that I can add [^/] in my expression which will > successfully work for url (i.e. http://sdfs/123-34) but it will also work > for non url (i.e. /123-34 ) so u am just trying it to make it specific

Re: [Tutor] why is unicode converted file double spaced?

2009-04-08 Thread spir
Le Tue, 7 Apr 2009 17:54:42 -0400, Kent Johnson s'exprima ainsi: > >     outp.write(outLine.strip()+'\n') > UnicodeEncodeError: 'ascii' codec can't encode characters in position > 640-641: ordinal not in range(128) Hem, sorry for stepping in the thread. Isn't the issue that lines previously de

Re: [Tutor] Accessing a list inside a class...

2009-04-09 Thread spir
Le Thu, 9 Apr 2009 08:47:59 -0700, "Alexander Daychilde (Gmail)" s'exprima ainsi: > The error I get when running the above code: > > Traceback (most recent call last): > > File "listinclass.py", line 34, in > > test.load_ini() > > File "listinclass.py", line 17, in load_ini > >

Re: [Tutor] Here's something to talk about

2009-04-15 Thread spir
Le Wed, 15 Apr 2009 08:29:30 -0700, "Weidner, Ronald" s'exprima ainsi: > # This code is posted for the purpose of conversation. If it is of some > # value to someone that would be great. But what I hope is that the code > # sparks conversations about what I did in this code and why I did it. >

Re: [Tutor] Here's something to talk about

2009-04-15 Thread spir
Le Wed, 15 Apr 2009 12:20:20 -0700, wesley chun s'exprima ainsi: > i think it's a common style guideline in multiple > languages i'm familiar with (other than Python) to Capitalize class > names but keep variables, functions, and methods all lowered. In most cases I know, class names are capital

Re: [Tutor] importance of Docstring

2009-04-16 Thread spir
Le Thu, 16 Apr 2009 02:04:25 -0700 (PDT), mbikinyi brat s'exprima ainsi: > Dear ALL, > What is really the importance of Docstring in Python??? > Regards, > Henry Very very very great, I guess ;-) Denis -- la vita e estrany ___ Tutor maillis

[Tutor] bootstrapping

2009-04-16 Thread spir
Hello, This question is rather intended to people who have some knowledge on parser generation and/or on self-compiling languages. I have a custom PEG parser generator in python, called 'pijnu', just bootstrapped. Meaning it's a kind of specific language which generator (compiler) is able to pr

[Tutor] code publishing

2009-04-16 Thread spir
Hello, I have no clue whether there is a common place to publish some (free like the air) python source code for review, use, evolution... (It's about 17 5kb.) Denis -- la vita e estrany ___ Tutor maillist - Tutor@python.org http://mail.python.or

Re: [Tutor] print items in a list...

2009-04-16 Thread spir
Le Thu, 16 Apr 2009 11:37:35 -0600, Spencer Parker s'exprima ainsi: > trying to clean up > messy code for the most part How does it look like? Denis -- la vita e estrany ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listin

Re: [Tutor] importance of Docstring

2009-04-17 Thread spir
Le Thu, 16 Apr 2009 12:02:21 +0200, "A.T.Hofkamp" s'exprima ainsi: > Now what does this function do? > This is a 'what' question, namely, from a design point of view, if I call > this function, what does it do, and what is its result-value? > What I miss is a good place for "why?". Which, when

Re: [Tutor] Reading from files problem

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 07:59:15 +0100, "Alan Gauld" s'exprima ainsi: > > #Open and read text file > > > > gradesfile = open("grades.dat", "r" > > for lines in gradesfile: > >lines = lines.split(",") > >identifier = lines[0] > >lastname = lines[1] > >firstname = lines[2] > >major

Re: [Tutor] Reading from files problem

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 07:59:15 +0100, "Alan Gauld" s'exprima ainsi: > So I'd change the structure to be like this(pseudo code) > > students = dict() # empty dict > for line in gradesfile: > line = line.split(',') > s = Student() > s.id = line[0] > s.lastname = line[1] > etc...

[Tutor] vars()

2009-04-20 Thread spir
Hello, Just discovered vars(). Looking for the reasons and use cases that led to introduce this builtin. But could not find any reference. Any pointer/clue? Denis PS: same about all() and any() -- but here I found some literature... in french: fr.wikipedia.org/wiki/Python_(langage) -- la v

Re: [Tutor] Looping

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 17:26:30 +0200, "A.T.Hofkamp" s'exprima ainsi: > Matt wrote: > > Hey everyone, > > > > First post to this list. I hope I'm doing it right. > > > > Let's say I want to run func 10 times Is there a more pythonic way to do > > it than this: for i in xrange(10): > > func() > >

Re: [Tutor] String Encoding problem

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 10:46:47 -0400, Matt s'exprima ainsi: > Hey everyone, > > I'm hoping someone here can help me solve an odd problem (bug?). I'm having > trouble with string encoding, object deletion, and the xml.etree library. If > this isn't the right list to be posting this question, please

Re: [Tutor] parse text for paragraghs/sections

2009-04-20 Thread spir
Le Mon, 20 Apr 2009 09:07:01 -0700, "Dinesh B Vadhia" s'exprima ainsi: > t = """abc DEF ghi jkl MNO pqr""" > > ... pickup all text between the tags and and replace with > another piece of text. > > I tried > > t = re.sub(r"\[A-Za-z0-9]\", "DBV", t) > > ... but it doesn't work. You need:

Re: [Tutor] Organizing my code, should I use functions?

2009-04-22 Thread spir
Le Wed, 22 Apr 2009 08:49:22 -0600, Eduardo Vieira s'exprima ainsi: > Hello! I’m not a programmer and am a beginner with Python, I would > like suggestion about ways of tackling the task I had to do. I have > bee been using the xlrd package to get data from some spreadsheets > successfully. > I h

Re: [Tutor] Don't understand error messages.

2009-04-22 Thread spir
Le Wed, 22 Apr 2009 11:57:13 -0700, "WM." s'exprima ainsi: [...] > def DisplayBoard(HANGMAPIX, MissedLetters, CorrectLetters, SecretWord): > print HANGMANPIX[len(MissedLetters)] > print > > print 'MissedLetters:', > for Letter in MissedLetters: > print Letter, > p

Re: [Tutor] Tokenizing Help

2009-04-22 Thread spir
Le Wed, 22 Apr 2009 14:35:29 -0400, William Witteman s'exprima ainsi: > I need to be able to decompose a formatted text file into identifiable, > possibly named pieces. To tokenize it, in other words. There seem to > be a vast array of modules to do this with (simpleparse, pyparsing etc) > but

Re: [Tutor] Don't understand error messages.

2009-04-23 Thread spir
Le Wed, 22 Apr 2009 19:40:51 -0700, "WM." s'exprima ainsi: > Well, Kent was right, it was an indent error, but 'way high in the > program. I was so catching commas that I got sloppy at an indent > change. sorry guys. > ___ > Tutor maillist - Tutor@

[Tutor] testing framework

2009-04-23 Thread spir
Hello, 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: """ This is the "example" module. The example module supplies one f

Re: [Tutor] Pyparsing question: marking matches in Pyparsing

2009-04-24 Thread spir
Le Fri, 24 Apr 2009 16:20:02 -0400, Emad Nawfal (عماد نوفل) s'exprima ainsi: > Hello Tutors, > I've used Pyparsing to write a Noun Phrase Extractor that extracts noun > phrases from a Part-of-Speech tagged file. My question is: how can I mark, > instead of extract, the phrases. For example, In th

Re: [Tutor] output formatting

2009-04-25 Thread spir
Le Sat, 25 Apr 2009 11:02:47 -0400, Matt Domeier s'exprima ainsi: > Hi Wayne, > > Yes, that should work perfectly, but it is in writing files that I'm > having the problem. I'm still very new to python, so I only know to > use something like filename.write(str(listname)) to write my list to

Re: [Tutor] Lists in a file

2009-04-26 Thread spir
Le Sun, 26 Apr 2009 18:03:41 + (GMT), David Holland s'exprima ainsi: > Hi, > > I am trying to create a program where I open a file full of lists and > process them. However when the program does not recognize the lists as > lists. Here is the relevant code :- > def open_filedef(): >     text

Re: [Tutor] How to run a .py file or load a module?

2009-04-27 Thread spir
Le Sun, 26 Apr 2009 22:35:36 +0100, Dayo Adewunmi s'exprima ainsi: > How can I > > a) Open my shell, and do something like: $ python countdown.py > but have it take an argument and pass it to the function, and execute. When your code is (nicely) organised as a set of funcs or class definitio

Re: [Tutor] How many types of the constructor

2009-04-27 Thread spir
Le Mon, 27 Apr 2009 22:38:30 +0530, sudhanshu gautam s'exprima ainsi: > Now If I placed the name of the constructor rather than the __init__ > __baba___ so will it also work as a constructor or constructor has specified > already if yes then give me list of them Actually __init__ is not the con

Re: [Tutor] Working with lines from file and printing to another keeping sequential order

2009-04-28 Thread spir
Le Mon, 27 Apr 2009 23:29:13 -0400, Dan Liang s'exprima ainsi: > Hi Bob, Shantanoo, Kent, and tutors, > > Thank you Bob, Shantanoo, Kent for all the nice feedback. Exception > handling, the concept of states in cs, and the use of the for loop with > offset helped a lot. Here is the code I now ha

Re: [Tutor] regular expression question

2009-04-28 Thread spir
Le Tue, 28 Apr 2009 11:06:16 +0200, Marek spociń...@go2.pl, Poland s'exprima ainsi: > > Hello, > > > > The following code returns 'abc123abc45abc789jk'. How do I revise the > > pattern so that the return value will be 'abc789jk'? In other words, I > > want to find the pattern 'abc' that is clos

Re: [Tutor] finding mismatched or unpaired html tags

2009-04-28 Thread spir
Le Tue, 28 Apr 2009 07:41:36 -0700, "Dinesh B Vadhia" s'exprima ainsi: > This is the error and traceback: > > Unexpected error opening J:/F2/html: mismatched tag: line 124, column 8 > > Traceback (most recent call last): > File "C:\py", line 492, in > raw = extractText(xhtmlfile)

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

[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

[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.

Re: [Tutor] Encode problem

2009-05-01 Thread spir
Le Fri, 1 May 2009 15:19:29 -0300, "Pablo P. F. de Faria" s'exprima ainsi: > self.cfg.write(codecs.open(self.properties_file,'w','utf-8')) > > As one can see, the character encoding is explicitly UTF-8. But > ConfigParser keeps trying to save it as a 'ascii' file and gives me > error for directo

Re: [Tutor] Iterating over a long list with regular expressions and changing each item?

2009-05-04 Thread spir
Le Sun, 3 May 2009 21:59:23 -0400, Dan Liang s'exprima ainsi: > Hi tutors, > > I am working on a file and need to replace each occurrence of a certain > label (part of speech tag in this case) by a number of sub-labels. The file > has the following format: > > word1 \tTag1 > word2 \tT

Re: [Tutor] Iterating over a long list with regular expressions and changing each item?

2009-05-04 Thread spir
Le Mon, 4 May 2009 10:15:35 -0400, Dan Liang s'exprima ainsi: > Hi Spir and tutors, > > Thank you Spir for your response. I went ahead and tried your code after > adding a couple of dictionary entries, as below: > ---Code Begins--- > #!u

Re: [Tutor] Advanced String Search using operators AND, OR etc..

2009-05-04 Thread spir
Le Mon, 4 May 2009 10:38:31 -0600, vince spicer s'exprima ainsi: > Advanced Strings searches are Regex via re module. > > EX: > > import re > > m = re.compile("(FDA.*?(approved|supported)|Ben[^\s])*") > > if m.search(Text): > print m.search(Text).group() > > > Vince This is not at all

Re: [Tutor] Encode problem

2009-05-04 Thread spir
Le Mon, 4 May 2009 11:09:25 -0300, "Pablo P. F. de Faria" s'exprima ainsi: > Thanks, Kent, but that doesn't solve my problem. In fact, I need > ConfigParser to work with non-ascii characters, since my App may run > in "latin-1" environments (folders e files names). I must find out why > the str()

Re: [Tutor] how to reference a function itself when accessing its private functions?

2009-05-05 Thread spir
Le Mon, 04 May 2009 16:08:38 -0700, Emile van Sebille s'exprima ainsi: > On 5/4/2009 3:37 PM Tim Michelsen said... > > Dear Tutors and fellow pythonistas, > > I would like to get access to the private methods of my function. > > > > For instance: > > Who can I reference the docstring of a functi

Re: [Tutor] Conversion question

2009-05-05 Thread spir
Le Tue, 5 May 2009 00:52:11 +0100, "Alan Gauld" s'exprima ainsi: > > Is there a way in Python to say this is a string of HEX characters like > > Perl's pack? Right now I have to take the string and add a \x to every > > two > > values i.e. \x41\x42... > > Assuming you actually want to send t

Re: [Tutor] Replacing fields in lines of various lengths

2009-05-05 Thread spir
Le Tue, 5 May 2009 00:22:45 -0400, Dan Liang s'exprima ainsi: > -Begin data > > w1\t case_def_acc \t yes > w2‬\t noun_prop \t no > ‭w3‬\t case_def_gen \t > w4\t dem_pron_f \t no > w3‬\t

Re: [Tutor] quick question to open(filename, 'r') vs. file(filename, 'r')

2009-05-05 Thread spir
Le Tue, 5 May 2009 00:41:39 +0100, "Alan Gauld" s'exprima ainsi: > > Backwards compatibility. The file type was introduced in python 2.2, > > before which there was open. > > And file has been removed again in Python v3 > In fact open is now an alias for io.open and no longer simply retu

Re: [Tutor] Advanced String Search using operators AND, OR etc..

2009-05-05 Thread spir
Le Tue, 05 May 2009 22:11:22 +1000, Lie Ryan s'exprima ainsi: > Idea: > Overrides the operator on Pattern class so we could write it like: > P("Hello") & P("World") instead of AND(P("Hello"), P("World")) You could also override directly all python logical ops to allow direct expression of logi

Re: [Tutor] Need help with registry access

2009-05-07 Thread spir
Le Fri, 8 May 2009 01:20:32 +0100, "Alan Gauld" s'exprima ainsi: > > "Christopher Barkley" wrote > > > My friend and I are techies, he's on my LAN. I want to disable > > his keyboard through the registry (or some other fun way) > > while he's in the middle of playing starcraft by running a

Re: [Tutor] Pythonic way to normalize vertical whitespace

2009-05-09 Thread spir
Le Fri, 08 May 2009 13:03:47 -0400, pyt...@bdurham.com s'exprima ainsi: [...] > Approaches: > 1. split text to list of lines that get stripped then: > a. walk this list building a new list of lines that track and > ignore extra blank lines > -OR- > b. re-join lines and replace '\n\n\n' wth' \n\n'

Re: [Tutor] Import package module problem

2009-05-12 Thread spir
Le Mon, 11 May 2009 21:44:09 +0100 (BST), man...@themacaque.com s'exprima ainsi: > Hello there, > > I have just started working with python and I have some issues > understanding how I should be importing modules from packages. Curretly I > have the following tree structure: > > general/ > _

Re: [Tutor] How to set up an Array?

2009-05-12 Thread spir
Le Mon, 11 May 2009 19:09:30 -0700 (PDT), nickel flipper s'exprima ainsi: > > Hello, > Just getting started with Python, and have had some early, although trivial > success. It looks like just the ticket to parse a data file. Total noob at > this, but really kind of overwhelmed by all the optio

Re: [Tutor] Considering translating bash script to Python to learn

2009-05-12 Thread spir
Le Tue, 12 May 2009 11:26:00 +0300, Dotan Cohen s'exprima ainsi: > I am considering translating a homegrown bash script to Python to > learn the language. The script grabs different specific pages of > either a ODF or PDF file (I can use either as the input file, based on > Python's abilities), c

Re: [Tutor] Calling method in parent class

2009-05-12 Thread spir
Le Tue, 12 May 2009 10:55:18 +0200, The Green Tea Leaf s'exprima ainsi: > OK, bad example. But assume I have the same method in both classes and > want to call the method in the parent. That should not happen! Basic contract is: same name = same meaning. Either you implement a method in a paren

Re: [Tutor] Calling method in parent class

2009-05-12 Thread spir
Le Tue, 12 May 2009 07:27:52 -0400, Kent Johnson s'exprima ainsi: > I don't agree with this at all. It's not at all unusual for a derived > class to override a base class method in order to add additional > functionality to it, then to call the base class method to complete > the implementation.

Re: [Tutor] Calling method in parent class

2009-05-12 Thread spir
Le Tue, 12 May 2009 17:43:24 +0100, "Alan Gauld" s'exprima ainsi: > > Having two methods with the name that both need two be used > > on the same object is clearly a design flaw. What do you think? > > Two methods only one message. It is what polymorphism is all about. Well, I do not want to

Re: [Tutor] Calling method in parent class

2009-05-13 Thread spir
Le Tue, 12 May 2009 23:23:02 +0100, "Alan Gauld" s'exprima ainsi: > But calling the method of a superclass from the same method is very, > very common. [...] Yep, for sure; and I was not discussing this actually. (1) In fact, the whole exchange started when the OP asked how to call 2 different

[Tutor] cannot subclass imported type

2009-05-13 Thread spir
Hello, I wanted to subclass the type Window of pyGTK for main app windows (for the obvious reason that they always contain the same init and end code) and run into an unexpected problem: = import pygtk pygtk.require('2.0') import gtk # debug output print gtk print gtk

Re: [Tutor] cannot subclass imported type

2009-05-13 Thread spir
Le Wed, 13 May 2009 08:40:25 -0700, Emile van Sebille s'exprima ainsi: > On 5/13/2009 8:32 AM spir said... > > Hello, > > > > I wanted to subclass the type Window of pyGTK for main app windows (for > > the obvious reason that they always contain the same init a

Re: [Tutor] Sorting a list

2009-05-13 Thread spir
Le Wed, 13 May 2009 23:12:29 +0530, Ataulla S H s'exprima ainsi: > >>> k = [each for each in l if type(each) == type(int())] You can write "int" (is a type since py 2.2, I guess). assert int==type(int()) # ok Denis -- la vita e estrany ___

Re: [Tutor] Sorting a list

2009-05-14 Thread spir
Le Thu, 14 May 2009 12:24:15 +0200, Christian Witts s'exprima ainsi: > The ability to compare unlike objects at all is considered a > mis-feature and has been removed in Python 3: > http://mail.python.org/pipermail/python-dev/2004-June/045111.html Great! Thanks for the informaton, Kent. Denis -

Re: [Tutor] Find files without __doc__ strings

2009-05-16 Thread spir
Le Sat, 16 May 2009 21:46:02 -0400, David s'exprima ainsi: > I am doing an exercise in Wesley Chun's book. Find files in the standard > library modules that have doc strings. Then find the ones that don't, > "the shame list". I came up with this to find the ones with; > #!/usr/bin/python > im

Re: [Tutor] Shared FIFO?

2009-05-18 Thread spir
Le Mon, 18 May 2009 08:19:21 +0100, "Alan Gauld" s'exprima ainsi: > If > you never, or rarely, have concurrent accesses then using > a text file might work. That's what I would do. New tasks appended --> oldest one = first one (first line, probably). For access sharing, then you can have a v

[Tutor] performance loss -- profiling

2009-05-18 Thread spir
Hello, I have an big performance problem with an app I'm currently working on. It "suddenly" runs at least 5 times slower that it used to. The issue is, beeing in a finalization phase, I'm all the time touching thingies here and there. But performance change is visible only when running on big t

Re: [Tutor] performance loss -- profiling

2009-05-19 Thread spir
Le Mon, 18 May 2009 23:16:13 +0100, "Alan Gauld" s'exprima ainsi: > "spir" wrote > > > Also, it's the first time I really have to cope with machine-time; > > so I'm totally new to technics like using a profiler. > > Any hints on the

[Tutor] clean text

2009-05-19 Thread spir
Hello, This is a follow the post on performance issues. Using a profiler, I realized that inside error message creation, most of the time was spent in a tool func used to clean up source text output. The issue is that when the source text holds control chars such as \n, then the error message is

Re: [Tutor] Replacement for __del__

2009-05-19 Thread spir
Le Tue, 19 May 2009 09:12:34 +0200, "A.T.Hofkamp" s'exprima ainsi: > A folder is created during object instantiation. Do you mean a filesytem directory? I may be wrong, bit it seems there is a bit of confusion between things and their representation as python objects. You shouldn't call __del_

Re: [Tutor] clean text

2009-05-19 Thread spir
Le Tue, 19 May 2009 11:36:17 +0200, spir s'exprima ainsi: > Hello, > > This is a follow the post on performance issues. > Using a profiler, I realized that inside error message creation, most of > the time was spent in a tool func used to clean up source text output. The

Re: [Tutor] clean text

2009-05-19 Thread spir
Le Tue, 19 May 2009 11:36:17 +0200, spir s'exprima ainsi: [...] Thank you Albert, Kent, Sanders, Lie, Malcolm. This time regex wins! Thought it wouldn't because of the additional func call (too bad we cannot pass a mapping to re.sub). Actually the diff. is very small ;-) The releva

Re: [Tutor] clean text

2009-05-19 Thread spir
Le Tue, 19 May 2009 10:49:15 -0700, Emile van Sebille s'exprima ainsi: > On 5/19/2009 10:19 AM spir said... > > Le Tue, 19 May 2009 11:36:17 +0200, > > spir s'exprima ainsi: > > > > [...] > > > > Thank you Albert, Kent, Sanders, Lie, Malcolm. &

Re: [Tutor] Replacement for __del__

2009-05-19 Thread spir
Le Tue, 19 May 2009 19:27:16 +0100, "Alan Gauld" s'exprima ainsi: > > def __del__(self): > >try: > >self.f.close() > >except: > >pass > > This is, I agree, pointless. but very different to: > > def __ del__(self): > try: > os.remove(self.lockname) > e

Re: [Tutor] Allow only one instance of a process

2009-05-19 Thread spir
Le Tue, 19 May 2009 23:09:33 +0300, Roger s'exprima ainsi: > As a Java programmer just starting with Python, this answer surprised me. I > would've been googling for the Python equivalent of the Singleton pattern. > I guess it's going to take longer than I thought to get my head around the > dif

Re: [Tutor] Iterating over list of functions

2009-05-20 Thread spir
Le Wed, 20 May 2009 10:25:21 -0400, Robert Berman s'exprima ainsi: > What I do not know how to do is to call the selected function. If you have options and functions "hard-coded" in lists (or if you get them from outside), you can still let python build a dict for you, using "zip": l1 = [1,2,3

Re: [Tutor] Hi everyone

2009-05-21 Thread spir
Le Wed, 20 May 2009 18:25:07 -0700 (PDT), Doug Reid s'exprima ainsi: > "The next line in the loop, >word = word[:position] + word[(position + 1):] > > creates a new version of word minus the one letter at position position. > Using slicing, the computer creates two new strings from word. The

[Tutor] import aliases ?

2009-05-26 Thread spir
Hello, In the case of such a dir structure: /pack __init__.py (modules) /pack1 __init__.py modules are the following imports synonyms: 1- import pack.pack1 2- from pack import pack1 ? If yes, is there a reason for this? Also, there is something I find weird: * Using i

Re: [Tutor] Python Function Doubt

2009-05-26 Thread spir
Le Tue, 26 May 2009 19:42:34 +0530, nikhil s'exprima ainsi: > Hi, > > Thanks for reply. > > I went through the link you provided. It was very helpful. > > What I understood is this, > > --> Objects are created for default argument types, inside the function > object. ... for default argument

Re: [Tutor] writing HTML code to a variable/file

2009-05-26 Thread spir
Le Tue, 26 May 2009 15:57:10 +0100, Dayo Adewunmi s'exprima ainsi: > Hi, > > I'm extracting data from OpenLDAP, which needs to be formatted into > hyperlinks. So far, I can print the generated HTML code: > > print "http://users.example.com/~"; + userName + ">" + lastName > + ", " + firstName

Re: [Tutor] IDLE shortcut doesn't exist except for in the Start Menu

2009-05-27 Thread spir
Le Wed, 27 May 2009 00:22:00 +0100, "Alan Gauld" s'exprima ainsi: > However so far as a USB vsion of Python its not quite > as simple as just copying the folders Thee are some > registry settings that you may need to set too, as well > as the environment variables etc. > > But its not rocket

Re: [Tutor] creating a dict-like class - asigning variables... this one may take some thought ; )

2009-05-28 Thread spir
Le Thu, 28 May 2009 03:47:09 -0700 (PDT), "John [H2O]" s'exprima ainsi: > > Hello, I am trying to create a class to hold and reference things similar to > matlab's structure. > > ## A class definition to hold things > class stuff(object): > """ holds stuff """ > def __init__(): >

Re: [Tutor] python workspace -- vars() vs locals()

2009-06-03 Thread spir
Le Tue, 02 Jun 2009 10:47:38 -0700, Emile van Sebille s'exprima ainsi: > On 6/2/2009 8:54 AM roberto said... > > hello, > > i'd like to ask if there is anything in python which helps to see what > > variables have been defined and their type and their dimension etc; > > In appropriate contexts,

Re: [Tutor] Stop a long loop in python console or in wxpython?

2009-06-08 Thread spir
Le Mon, 8 Jun 2009 09:23:08 +0100, "Alan Gauld" s'exprima ainsi: > There are two normal ways to do this in a GUI: > 1) break the loop into small chunks and run them in response > to timer events. The function then calls the timer at the end of > each chunk until it completes its task. This frees

Re: [Tutor] question about class

2009-06-09 Thread spir
Le Mon, 8 Jun 2009 17:31:23 -0600, Vincent Davis s'exprima ainsi: > Accidentally sent I have added the rest > (by the way I refrain from using the terms attribute, method, as I > will likely miss use them) > > > I am reading several tutorials about classes and trying to figure out > > how to

[Tutor] glob.glob(pattern, dir) ?

2009-06-09 Thread spir
Hello, is there a way to make glob work in a specified dir? (or is it necessary to use os.chdir first?) Thank you, denis -- la vita e estrany ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] glob.glob(pattern, dir) ?

2009-06-09 Thread spir
Le Tue, 9 Jun 2009 17:40:26 +0200, Sander Sweers s'exprima ainsi: > 2009/6/9 spir : > > is there a way to make glob work in a specified dir? > > glob needs a pathname and uses the current dir if no full path is > given. Prepend the path to your match (*.txt in example bel

[Tutor] recursive glob -- recursive dir walk

2009-06-09 Thread spir
Example with the following dir structure ; the version with nest=True will recursively nest files from subdirs. d0 d01 d02 d020 2 .txt files and 1 with a different pattern, in each dir recurseDirGlob("/home/spir/p

[Tutor] file enigma

2009-06-11 Thread spir
Hello, text = file(filename).read() (or: open(filename).read()) How do you close() the file? ;-) Is it, in fact, automagically closed after end-of-statement if not bound to a name? Or when the execution path quits the present scope (func, module), like if it had been bound to a local var? Or w

Re: [Tutor] Parse Text File

2009-06-11 Thread spir
[Hope you don't mind I copy to the list. Not only it can help others, but pyparsing users read tutor, including Paul MacGuire (author).] Le Thu, 11 Jun 2009 11:53:31 +0200, Stefan Lesicnik s'exprima ainsi: [...] I cannot really answer precisely for haven't used pyparsing for a while (*). So,

Re: [Tutor] file enigma

2009-06-11 Thread spir
Le Thu, 11 Jun 2009 10:21:31 +0100, Tim Golden s'exprima ainsi: > spir wrote: > > Hello, > > > > text = file(filename).read() > > > > (or: open(filename).read()) > > > > How do you close() the file? ;-) > > Well, in any version of Pyt

Re: [Tutor] How do I do this in python?

2009-06-11 Thread spir
Le Thu, 11 Jun 2009 12:56:27 +0200, The Green Tea Leaf s'exprima ainsi: > My advice: "Learning Python" very nice book > > def show(*args): > print args > > def show2(*args): > for item in args: > print "Blabla:",item > > show(1,2,"hello") > show2(1,2,"hello") Well, i

Re: [Tutor] How do I do this in python?

2009-06-11 Thread spir
Le Thu, 11 Jun 2009 13:12:02 +0200, "A.T.Hofkamp" s'exprima ainsi: > > If this can't be done but there is a completely different way to > > achieve a similar result, what is it? > > print "abc=", a, b, c > > is what I always use. Well, I do find the OP's demand really sensible. Had the same ne

Re: [Tutor] How do I do this in python?

2009-06-11 Thread spir
Le Thu, 11 Jun 2009 10:46:26 -0400, Kent Johnson s'exprima ainsi: > On Wed, Jun 10, 2009 at 9:43 PM, Robert Lummis > wrote: > > I want to write a function that I can use for debugging purposes that > > prints the values of whatever list of object references it is given as > > arguments, without k

[Tutor] use of __new__

2009-06-12 Thread spir
Hello, I have (again) some issue using __new__. What I need is basically to catch an object creation and yield an object of an alternate type, when a condition is met. Basically, the outline looks like: class Normal(object): def __new__(cls, arg): if cond(arg): #

<    1   2   3   4   5   6   7   >