Re: [Tutor] list output -- float output

2008-11-14 Thread spir
A.T.Hofkamp a écrit : > spir wrote: >> # By the way, I do not understand at all the behaviour of repr on >> rounded floats: >> x = round(1.1,1) >> print x, repr(x), "%s" %x >> 1.1 1.1001 1.1 > > This is a FAQ question: > > http:/

Re: [Tutor] list output -- float output

2008-11-14 Thread spir
str:1.1 l: [1, 1.1001, [1, 1.1001]] s:[1 ,1.1 ,[1 ,1.1]] Lie Ryan a écrit : On Fri, 14 Nov 2008 15:21:17 +0100, spir wrote: Well, actually not really I guess. I asked for rounded floats, not full-precision ones. Now, after more reflexion on the topic, I understand that even

[Tutor] /not/ instanciating

2008-11-16 Thread spir
Hello, I have a type (say: T) which normally receives as main init argument an object that can be of any other type. Occasionally, this arg object may precisely be of type T. In this case, for several reasons, I wish not to "over-instanciate", rather that the constructor returns the source obj

[Tutor] what do you use @staticmethod for?

2008-11-19 Thread spir
Good night, I have not yet found any use for this feature. Also, I do not really understand the difference with @classmethod, from the programmer's points of view (even if I get the difference on the python side). As I see it, a classmethod is a very ordinary method, except its 'owner' is a ty

[Tutor] [Fwd: Re: what do you use @staticmethod for?]

2008-11-20 Thread spir
oblem, his/her point of view, or design choice. In short: it makes sense. If this is True ;-), then it is the first Python feature I notice that simply exists for such a (relevant, imo) reason. Now, I will probably find many appropriate use cases for static methods. Denis Tim Golden a écrit :

[Tutor] the sense of brackets

2008-11-22 Thread spir
I have long thought "[]" /simply/ is a list constructor syntax. What do you think of the following? t = "aze" print t, list(t), [t] print list(list(t)), list([t]), [list(t)], [[t]] ==> aze ['a', 'z', 'e'] ['aze'] ['a', 'z', 'e'] ['aze'] [['a', 'z', 'e']] [['aze']]

Re: [Tutor] python question

2008-11-22 Thread spir
Some comments on your code, after David & Kent: * repetition You have probably noticed that your programm repeats over and over the same pattern, that could be called "process of a question". One major point of programming is precisely to cope with such a repetitive task (this was true even be

Re: [Tutor] the sense of brackets

2008-11-22 Thread spir
W W a écrit : > On Sat, Nov 22, 2008 at 9:42 AM, spir <[EMAIL PROTECTED]> wrote: > >> I have long thought "[]" /simply/ is a list constructor syntax. >> What do you think of the following? >> >> t = "aze" >> print t, list(t), [t] >

Re: [Tutor] Regular expression oddity

2008-11-23 Thread spir
bob gailer a écrit : Emmanuel Ruellan wrote: Hi tutors! While trying to write a regular expression that would split a string the way I want, I noticed a behaviour I didn't expect. re.findall('.?', 'some text') ['s', 'o', 'm', 'e', ' ', 't', 'e', 'x', 't', ''] Where does the last

[Tutor] [Fwd: Re: My horrible looking program needs improvement.]

2008-11-25 Thread spir
Hello Peter, Your program's structure is rather well designed... with words and whitespace. You just need to export each consistent part of your main() into a specialised section: module, object, function. I would suggest (use the names that make sense for you, not mine): * "Config" class that c

[Tutor] poll question

2008-11-26 Thread spir
Hello pythonistas, I need some information about a topic. A list like python tutor is the proper place to get it. Take this as a (stupid) game: would you like to answer the following question? Imagine you are writing code. Then, you realise you need a tool function you have not yet written.

Re: [Tutor] poll question

2008-11-26 Thread spir
Holà, I forgot to ask for replies outside the list -- to avoid 'pollution' with off-topic posts. [EMAIL PROTECTED] Thank you, denis spir a écrit : Hello pythonistas, [...] ___ Tutor maillist - Tutor@python.org http://mail.python.o

[Tutor] [Fwd: Re: poll question]

2008-11-26 Thread spir
Alan Gauld a écrit : "spir" <[EMAIL PROTECTED]> wrote How would you call this function? e.g. digits = char_range(...) In other words: which is, for you personly, the most practicle or natural way of calling this func? Would you give me one or more calling example(s)? I

[Tutor] attribute of built-in type

2008-11-28 Thread spir
Hello, I try to find a way to give a cutom type ('s instances) attributes like some built-in types have, for instance __name__. (For any reason, such attributes are not equally shared by all kinds of objects.) I tried to achieve that with inheritance, but I couldn't make it work with built-in

Re: [Tutor] attribute of built-in type

2008-12-01 Thread spir
Kent Johnson a écrit : [...big snip...] > Do you know that you can probably just assign a __name__ attribute to > the objects? Or name, or whatever you like? > > In [13]: class Foo(object): pass >: > > In [14]: f=Foo() > > In [15]: f.name > ---

[Tutor] [Fwd: Re: Making a dictionary of dictionaries from csv file]

2008-12-03 Thread spir
Judith Flores a écrit : Dear Python community, I have been trying to create a dictionary of dictionaries (and more dictionaries) from a csv file. The csv file contains longitudinal data corresponding to names. The following is just a very (very) simple example of how the data looks: NameD

Re: [Tutor] Writing to a file problem....

2008-12-05 Thread spir
Marty Pitts a écrit : Date: Fri, 5 Dec 2008 23:48:32 +0100 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: [Tutor] Writing to a file problem zip_command = "c:\Users\Marty\Zip\Zip -!rv '%s' %s" % (target, ' '.join(source)) What if you just double the '\' -- you did it properly

[Tutor] [Fwd: Re: reading output from a c executable.]

2008-12-11 Thread spir
Ravi Kondamuru a écrit : I am trying to read a binary log file to extract system counters. These counters will then be used to generate web-based graphs using the chart-director api in python. For extracting the counters I planning to write a program in C to read and give the output as lists for

Re: [Tutor] advice on regex matching for dates?

2008-12-11 Thread spir
Serdar Tumgoren a écrit : Hey everyone, I was wondering if there is a way to use the datetime module to check for variations on a month name when performing a regex match? In the script below, I created a regex pattern that checks for dates in the following pattern: "August 31, 2007". If there

Re: [Tutor] reading output from a c executable.

2008-12-11 Thread spir
Ravi Kondamuru a écrit : I am trying to read a binary log file to extract system counters. These counters will then be used to generate web-based graphs using the chart-director api in python. For extracting the counters I planning to write a program in C to read and give the output as lists for

Re: [Tutor] regex sub/super patterns ( was:advice on regex matching for dates?)

2008-12-12 Thread spir
Lie Ryan a écrit : >> I just found a simple, but nice, trick to make regexes less unlegible. >> Using substrings to represent sub-patterns. E.g. instead of: >> >> p = >> re.compile(r'(?PJanuary|February|March|April|May|June|July| > August|September|October|November|December)\s(?P\d{1,2}),\s(?P >

Re: [Tutor] stable algorithm

2008-12-14 Thread spir
David Hláčik a écrit : Hi, thank you very much. And how can i write single test which will tell me execution time of this algorithm? I need to write a table with number of data & execution time comparison (and it should be linear in case of this algorithm) Thanks! D. First, google will giv

Re: [Tutor] what does the "@" operator mean?

2008-12-16 Thread spir
I use decorators only to declare class methods. Denis Le lundi 15 décembre 2008 à 18:33 -0800, Marc Tompkins a écrit : > Does anybody who reads this list use decorators and have a nice word > to say about them? I'd be interested to hear it. > ___ Tut

[Tutor] reciprocal import

2008-12-16 Thread spir
Is it legal or possible at all for two modules to import each other? I tried several ways and had several kinds of error messages. Usually "can't import...". Denis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] reciprocal import

2008-12-16 Thread spir
true for any application? Denis Le mardi 16 décembre 2008 à 15:38 -0500, Kent Johnson a écrit : > On Tue, Dec 16, 2008 at 3:06 PM, spir wrote: > > Is it legal or possible at all for two modules to import each other? I > > tried several ways and had several kinds of error message

Re: [Tutor] Very basic question about lists

2008-12-22 Thread spir
see, 'or' is very low, which means that it will be aplied very late in any logical expression. 'in' comes befores. As you can now guess, this means that your expression is equal to: if ('arr') or ('bell' in item) Lookind at the table, you will understand tha

Re: [Tutor] Very basic question about lists

2008-12-23 Thread spir
> I see I have to do a loop inside a loop and that this the right expression > if word == 'ar' or word == 'ko': > > but this is not: > if word == 'ar' or 'ko': In the last example: as the 'or' operator has the least priority, it will be applied last. Which means that all other operations in the

Re: [Tutor] Redux: optparse

2008-12-27 Thread spir
Le samedi 27 décembre 2008 à 14:55 -0500, Matt Herzog a écrit : > On Wed, Dec 24, 2008 at 01:12:55AM -, Alan Gauld wrote: > > > > "Kent Johnson" wrote > > > > >> for filename in os.listdir(directory): > > >> result = re.match(s, filename) > > >> print result > > > > > >You

Re: [Tutor] Anagram creator

2008-12-28 Thread spir
Le samedi 27 décembre 2008 à 19:32 -0500, btk...@email.unc.edu a écrit : > Hi everyone, > > I'm having trouble with an anagram generating program that I am writing > in Python. My output is not what it should be and I think the reason > has something to do with my helper functions creating a re

Re: [Tutor] telnetlib unable to cath gaierror

2008-12-28 Thread spir
Le dimanche 28 décembre 2008 à 10:17 -0800, Steve Willoughby a écrit : > On Sun, Dec 28, 2008 at 07:09:51PM +0100, Sander Sweers wrote: > > I am having issues cathing exceptions from telnetlib. What I am doing is: > > except gaierror: > > Which gives me "NameError: name 'gaierror' is not defined" :

Re: [Tutor] Exception Handling

2008-12-29 Thread spir
On Mon, 29 Dec 2008 09:10:45 - "Alan Gauld" wrote: > > "bob gailer" wrote > > > Also IMHO it is bad design to put a lot of code inside a try block. > > In this case the user might make a mistake on day and then is forced > > to reenter the year and month! > > Obviously there is no absol

Re: [Tutor] Printing the code of a function

2008-12-29 Thread spir
On Mon, 29 Dec 2008 09:18:43 - "Alan Gauld" wrote: > > "wormwood_3" wrote > > > I am wondering if there is a way to print out the code of a defined > > function. > > Its not reliable but I think you can use > > func.func_code.filename > func.func_code.firstlineno > > To find the first

Re: [Tutor] Modifying a QIF

2008-12-29 Thread spir
On Mon, 29 Dec 2008 13:18:55 -0700 "Eduardo Vieira" wrote: > Hello, this weekend I had fun using Python for text processing. I > needed to change a qif converted from a ofx, using the tool MT2OFX > (http://www.xs4all.nl/~csmale/mt2ofx/en/index.htm) > I wanted to change transactions like these: >

Re: [Tutor] Fw: Creating sub-menus?

2009-01-01 Thread spir
On Thu, 1 Jan 2009 10:58:44 + (GMT) ALAN GAULD wrote: > Forwarding to the list > Please use ReplyAll when responding. > > > > > On Wed, Dec 31, 2008 at 4:10 AM, Alan Gauld wrote: > > "nathan virgil" wrote > > > > Each menu is a function that prints out options, saves a raw_input

Re: [Tutor] Inserting one dictionary into another

2009-01-02 Thread spir
On Thu, 01 Jan 2009 11:04:42 -0500 "Keith Reed" wrote: > I'm having trouble assigning a dictionary as a value within another: > > > Code Snippet Start > > for line in fromchild.readlines(): > itemarray = line.strip().split(":") > parent

[Tutor] object's attributes

2009-01-02 Thread spir
Can someone explain the following? class Type(object): pass o = Type() o.a = 1 print o, o.a print dir(object) ==> ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setat

Re: [Tutor] object's attributes

2009-01-02 Thread spir
On Fri, 2 Jan 2009 12:36:42 -0600 "Paul McGuire" wrote: > Denis - Hello Paul, pleased to read you again ;-) > What you are seeing is standard procedure for any built-in type - no dynamic > assignment of attributes allowed. Here is an analogous case to your > example, but based on str instead

Re: [Tutor] RE Silliness

2009-01-04 Thread spir
On Sun, 04 Jan 2009 14:09:53 -0500 bob gailer wrote: > Omer wrote: > > I'm sorry, burrowed into the reference until my eyes bled. > > > > What I want is to have a regular expression with an optional ending of > > "" > > > > (For those interested, > > urlMask = r"http://[\w\Q./\?=\R]+"; > > is th

Re: [Tutor] Wayne's waning list.

2009-01-05 Thread spir
Le Mon, 05 Jan 2009 16:01:56 +0100, "A.T.Hofkamp" a écrit : > > (And if it is any comfort to you, it happens to me too. I have read several > discussions about the "@" operator, and still don't understand why you'd want > to have it. No doubt it is a fantastic operator with many uses, but > a

Re: [Tutor] extreme basics

2009-01-05 Thread spir
Le Mon, 05 Jan 2009 17:59:06 +1000, Mr Gerard Kelly a écrit : > This is extremely weird, I think. > > Here is a tiny program: > > from math import * > from Numeric import * > > x=[0]*10 > > > for counter in rangelen((x)): > x[counter]=counter*0.1 > > print x > > Here is what I get: >

Re: [Tutor] Suggestions for more efficient and optimized coding technique,

2009-01-08 Thread spir
Le Thu, 8 Jan 2009 11:34:49 -0500, "Michael Langford" a écrit : > Here is your algorithm made more pythonic. Notice the use of default > parameters, doc strings, not abbreviated variable names, unix C style > capitolization (very subjective, but often the one found in python > libs), the avoidan

Re: [Tutor] casting string to integer in a list of lists

2009-01-08 Thread spir
Le Thu, 8 Jan 2009 11:51:01 -0800 (PST), culpritNr1 a écrit : > > Hi All, > > Say I have this nice list of lists: > > LoL = [['chrX', '160944034', '160944035', 'gnfX.145.788', '63.60'], > ['chrX', '161109992', '161109993', 'rs13484104', '63.60'], > ['chrX', '161414112

Re: [Tutor] casting string to integer in a list of lists

2009-01-09 Thread spir
Le Fri, 9 Jan 2009 06:20:26 -0800 (PST), culpritNr1 a écrit : > > Hello Trias and all, > > Glad to see that somebody recognized the BED genomic annotation format. > Being a relative newcomer to python, my question was if there was an ELEGANT > way to do this casting, perhaps as a list comprehe

Re: [Tutor] casting string to integer in a list of lists

2009-01-09 Thread spir
Le Fri, 9 Jan 2009 08:10:27 -0800 (PST), culpritNr1 a écrit : > > Hello Denis and All, > > Your solution does show elegance. To remind people, it's this one: > > lol = [[1,2,3],[4,5,6],[7,8,9]] > new_lol = [[a,b**3,c] for [a,b,c] in lol] > print lol > print new_lol > ==> > [[1, 2, 3], [4, 5, 6

Re: [Tutor] casting string to integer in a list of lists

2009-01-09 Thread spir
Forgot a "detail" > def possible_cube(val): > try: > return val ** 3 > except TypeError: > return val denis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] indented grammar parsing

2009-01-11 Thread spir
Hello, this is a rather specific question about parsing an indented grammar. I have a working implementation (presented below) that may be worth a critic review -- if you like it. First issue is: is there a way to express an indented formatfing using a common grammar language such as BNF (or re

[Tutor] traceback

2009-01-13 Thread spir
Hello, is there a way to read an exception's traceback? Cannot find it in object attributes. [dir() shows no traceback, __dict__ is empty.] t = "a" try: print t[1] except IndexError, e: print e print repr(e) print dir(e) print e. __dict__ print e.a

Re: [Tutor] python3.0 and tkinter on ubuntu 8.10

2009-01-13 Thread spir
Le Tue, 13 Jan 2009 16:02:48 -0500, Vern Ceder a écrit : > Hi, > > I have Python 3.0/Tkinter/IDLE working fine on Ubuntu 8.10, but it takes > a certain amount of fiddling. > > 1. Make sure the stock Ubuntu Python 3.0 package is not installed > > 2. download the Python 3.0 source from python.o

[Tutor] traceback

2009-01-14 Thread spir
Hello, I rather often use exceptions as information providers at design or debug time. A typical use of mine is to have a test version of methods that wrap standard version: def run(): do stuff that may raise exc def testRun(): try: run() e

Re: [Tutor] traceback

2009-01-15 Thread spir
Denis > Am Mittwoch, 14. Januar 2009 18:09:51 schrieb spir: > > Hello, > > > > I rather often use exceptions as information providers at design or debug > > time. A typical use of mine is to have a test version of methods that wrap > > standard version: > > &

[Tutor] single key ordered sequence

2009-01-15 Thread spir
Hello, a little algorithmic question. I have a list of tuples element, in which the first item is a kind of key. I need a target list with only one tuple per key. But the order must be kept -- so that I cannot use a temp dictionary. Additionally, in this case the chosen element for a repeted ke

Re: [Tutor] traceback -- how it works?

2009-01-15 Thread spir
se_uncaught_error() File "tools.py", line 294, in raise_uncaught_error raise Error("A set cannot hold a mutable item.") __main__.Error: module 'tools.py'-- in raise_uncaught_error(): line 00291: throw_error() module '/home/spir/prog/ospyp/throw_error.

[Tutor] traceback again: __traceback__ arg for exceptions in py3.0

2009-01-15 Thread spir
I just discovered the following: PEP 3134: Exception objects now store their traceback as the __traceback__ attribute. This means that an exception object now contains all the information pertaining to an exception, and there are fewer reasons to use sys.exc_info() (though the latter is not rem

Re: [Tutor] 2 & 4 or more spaces per indentation level..

2009-01-16 Thread spir
Le Fri, 16 Jan 2009 09:11:06 +0530, Senthil Kumaran a écrit : > > >they used a different spacing than you, is there a simple/good/smart > >way to get it all back to the 4 spacing default? Or if for example I > > Rule #0 is Never mix tabs and spaces. > Rule #1 is use a standard spacing

[Tutor] @property?

2009-01-16 Thread spir
Hello, would someone point me to some clear doc about properties: purpose, use, underlying model... [Could not find myself, probably because the word "property itself has far too wide meaning.] Thank you. denis -- la vida e estranya ___ Tutor mai

Re: [Tutor] Simple program with menu to view videos

2009-01-16 Thread spir
Le Fri, 16 Jan 2009 11:35:13 -0500, David a écrit : > Hi, > I just received the dvd Python Fundamentals by Wesley J. Chun and it was > packaged by the distributor for use on Window and Mac but I use Linux so > I pulled the videos of of the dvd. There are 10 lessons with a total of > 58 individ

Re: [Tutor] Convert String to Int

2009-01-19 Thread spir
Le Sun, 18 Jan 2009 21:59:04 -0500, bob gailer a écrit : > Ian Egland wrote: > > 'Allo All. > > > > I know that, should you want to get an int from the user, you use > > int(input("Question!")). However, what if the user wasn't that savvy > > and didn't realize he/she HAD to enter a number? Pro

Re: [Tutor] cube root

2009-01-19 Thread spir
Do you know any common algorithm to convert decimal (in the sense of fractional) decimals (in the sense of base 10 numbers) into binaries? 123.456 --> 011.bbb... and/or 123456 * 10**(-3) --> bbb... * 2**(-bbb...) How do python/C achieve that? denis -- la vida e es

Re: [Tutor] help on making python tictactoe

2009-01-19 Thread spir
Le Mon, 19 Jan 2009 01:18:41 -0800 (PST), jammy007 pp a écrit : > guys , i need immediate help on creating a simple tictactoe game . > > i read micheal dawson's book but didnt quiet get it . > > please help . > > thanks . > > jammy > > > > try googling: "software developpment compa

[Tutor] class arguments?

2009-01-22 Thread spir
Hello, is there a way to give arguments to a class definition? Eg class MonoList(list, typ, number): item_type = typ item_number = number [I guess you understand what I try to do...] denis -- la vida e estranya ___ Tutor maillist

Re: [Tutor] class arguments?

2009-01-23 Thread spir
Le Thu, 22 Jan 2009 23:29:59 -, "Alan Gauld" a écrit : > > "Alan Gauld" wrote > > >> is there a way to give arguments to a class definition? > > I see that Kent interpreted your question differently to me. > If you do mean that you want to dynamically define class > attributes rather

Re: [Tutor] Customizing Eclipse text editor

2009-01-23 Thread spir
Le Fri, 23 Jan 2009 11:17:15 +0100, Vicent a écrit : > Hello everyone. [...] > As you can see there, I prefer a black background, so I've changed colors a > little. My second question is: do you know any kind of recomended (I mean, > optimized for a good working experience, good for eyes health

Re: [Tutor] Possible to search text file for multiple string values at once?

2009-01-24 Thread spir
Le Fri, 23 Jan 2009 14:45:32 -0600, W W a écrit : > On Fri, Jan 23, 2009 at 1:11 PM, Scott Stueben wrote: > > > Thanks for the help so far - it seems easy enough. To clarify on the > > points you have asked me about: > > > > A sqlite3 database on my machine would be an excellent idea for > > pe

Re: [Tutor] No module named 'module name' -- sub-folders?

2009-01-25 Thread spir
hes listed in PYTHONPATH). But this does not work by me (anymore): from ospyp.py, located in /home/spir/prog/ospyp, I cannot simply import wikilang which is in /home/spir/prog/ospyp/samples ??? Denis -- la vida e estranya ___ Tutor maillist -

Re: [Tutor] clipboard questions

2009-01-26 Thread spir
Le Mon, 26 Jan 2009 02:23:05 -0500, Che M a écrit : > > I'm curious about how to interact with the contents of the clipboard > effectively and have a couple of questions... > > 1) Is there one cross-platform way to read the clipboard, or does one > have to have a different way to do it for Win

Re: [Tutor] Sort of database & "family tree" question

2009-01-26 Thread spir
Le Mon, 26 Jan 2009 14:58:43 +0100, Timo a écrit : > Hello, > > I'm writing an application that stores people with some info. I'm doing > this with ConfigParser and it works, but currently (for testing), there > are only 10 persons in it. What if I add, let's say, about 500-600 or > even more

[Tutor] import imports

2009-01-26 Thread spir
Hello, Here are some ideas around import. I wish to receive comments and to learn whether they fit python. As I am not a highly experimented programmer, there may be some features or practices I do know know or do not know well. The following ideas are not dependant of each other, but as they a

Re: [Tutor] [Python-ideas] import imports

2009-01-27 Thread spir
Le Mon, 26 Jan 2009 22:38:24 -, "Alan Gauld" a écrit : > "spir" wrote > > > Here are some ideas around import. I wish to receive comments > > > The module attribute __all__ allows defining names to be exported. > > I always use it for

Re: [Tutor] Defining "bit" type -- why not '!' ?

2009-01-29 Thread spir
Le Tue, 27 Jan 2009 11:26:06 -0200, Ricardo Aráoz a écrit : > > > "Vicent" wrote > > > >> Anyway, I am working with Python 2.5.4, and I am interested in > >> defining a > >> new type called "bit" (if possible), which represents a number that > >> can only > >> take values 0 or 1 —that's what we

Re: [Tutor] building Python 2.6?

2009-01-29 Thread spir
Le Wed, 28 Jan 2009 19:01:24 -0800 (PST), Bernard Rankin a écrit : > Hello, > > I am trying to build python 2.6 on a machine (web server) that I do not have > root access to. (has 2.4 installed) > > Python 2.5 builds fine, but I am getting an error when I run "make" for 2.6.1 > > Here is the

Re: [Tutor] Defining "bit" type -- why not '!' ?

2009-01-29 Thread spir
Le Thu, 29 Jan 2009 09:47:22 -, "Alan Gauld" a écrit : > > "Andre Engels" wrote > > >> Why not '!' for not, instead of '~'? I mean, '!' is used in logic, > > in many languages and even in python (!=). On the other hand, > > I had never encountered '~' meaning not. > > > > Although ! is ind

Re: [Tutor] Problem with nested for-in

2009-01-29 Thread spir
Le Thu, 29 Jan 2009 11:06:57 +, "emmanuel.delaborde" a écrit : > Hello, > > I have the following snippet : > > lines = csv.reader(open("CATEGORY.csv","r")) > lines2 = csv.reader(open("CATEGORYLIST.csv","r")) > > old_cats = [] > for line in lines: > stories = [] > for line2 in lin

Re: [Tutor] Properties of an object

2009-01-29 Thread spir
Le Thu, 29 Jan 2009 19:59:09 +0100, Vicent a écrit : > This is an easy question, I guess, but I am not able to find out the answer. > > In fact, it is both a Python question and a general programming "style" > question. > > I want to define a class that contains a list (or a NumPy array) of ele

[Tutor] non-greedy matching

2009-01-30 Thread spir
Hello, imagine you need to match such a pattern: pat : (@@ [charset]* @@) | [charset]* ... where [charset] has to include '@' My questions are: * Is there any other way than using a non-greedy form of [charset]* ? * How, actually, is non-greedy character string matching performed? Thank you, de

Re: [Tutor] Properties of an object

2009-01-30 Thread spir
Le Fri, 30 Jan 2009 12:22:10 +0100, Vicent a écrit : > Thanks to all for your clear answers. I learned a lot about the way Python > manages properties or attributes. > > In my particular case, I think, as Spir said, that the best implementation > depends on wether I am going to u

Re: [Tutor] Writing a Configuration Facility for an Application

2009-01-30 Thread spir
Le Fri, 30 Jan 2009 14:17:34 +0100, Willi Richert a écrit : > Hi, > > I have often found that just initializing all the necessary stuff in one > Configuration.py module. You just import it and it works. I support this as it's far the most straightforward way! Now, depending on the actual use,

Re: [Tutor] jumping from function to function

2009-01-30 Thread spir
Le Sat, 31 Jan 2009 00:30:18 +0800, David a écrit : > Dear List, > > the following comes from Harrington's "Hands-on Python" (section > 1.11.8): http://www.cs.luc.edu/~anh/python/hands-on/ > > > > > '''Avoiding any error by passing a parameter''' > > def main(): > x = 3 > f(x) >

Re: [Tutor] Properties of an object

2009-01-30 Thread spir
Le Fri, 30 Jan 2009 19:05:40 -, "Alan Gauld" a écrit : > "spir" wrote > > > There is no real native support for ordinary OOP in python, meaning > > as is done in most other languages, or according to the theory. > > I have to disagree. I t

Re: [Tutor] Re : Is instance of what?

2009-01-31 Thread spir
Le Sat, 31 Jan 2009 09:54:24 -0900, Tim Johnson a écrit : > On Saturday 31 January 2009, Andre Engels wrote: > <...> > > > o=a > <> > > Actually, it is false. To make it true, you have to do o=a() rather than > > o=a > You're correct. That was my typo. > > > Is there a function that takes

Re: [Tutor] string fomatting

2009-01-31 Thread spir
Le Sun, 1 Feb 2009 02:44:02 +0800, Jay Jesus Amorin a écrit : > Thanks bob. > > I want to search any characters in test after > https://www.localhost.org/and > the search will end after it finds another / > > and when i print

Re: [Tutor] Re : Is instance of what?

2009-02-01 Thread spir
Le Sat, 31 Jan 2009 15:00:02 -0500, Kent Johnson a écrit : > On Sat, Jan 31, 2009 at 2:47 PM, spir wrote: > > >> > o.__class__ (or rather o.__class__.__name__) will work. > >> Understood. Thank you. > >> tj > > > > type(a) has been changed

Re: [Tutor] confusion about cloning (graphics)

2009-02-01 Thread spir
Le Sun, 01 Feb 2009 16:34:10 +0800, David a écrit : > Hello list, > > I continue my reading of Harrington. In section 2.4. he is making a > point about the need to clone, as otherwise the object associated to > parameter corner (the point (20, 50)) takes the same value as corner2. > That is:

Re: [Tutor] Parsing suggestion? (CUE file) -- identify result

2009-02-04 Thread spir
Le Tue, 3 Feb 2009 17:36:41 -0500, Kent Johnson a écrit : > I think your use of the csv module is fine. What I really meant to say > was more like, I would have looked to pyparsing to solve the same > problem, and if you want a parser that parses the file into meaningful > records, then it might

Re: [Tutor] Sort of database & "family tree" question

2009-02-04 Thread spir
Le Wed, 4 Feb 2009 01:16:17 + (GMT), ALAN GAULD a écrit : > > > And I assume you are reading these into a Person class and > > > storing these classes in a persons dictionary? > > > > Can you explain this a little more for me please? > > > Sure. > (I didn't notice this on gmane so apolo

[Tutor] inheriting different builtin types

2009-02-04 Thread spir
Hello, I have a strange problem and cannot see a clear method to solve it. I would like to build a custom type that is able to add some informational attributes and a bunch attribute to a main "value". The outline is then: class Custom(X): def __init__(self, value, more):

[Tutor] named list

2009-02-05 Thread spir
Hello, python world! I'm looking for a way to implement a kind of "named" list, or named tree, with the following requirements: * Each item is named (or key-ed), like in a dict. * Each item (node) can be either a terminal item (leaf) or a sub-list (branch). * There may be items with the same nam

Re: [Tutor] passing unknown no of arguments

2009-02-05 Thread spir
Le Thu, 5 Feb 2009 08:57:15 -, "Alan Gauld" a écrit : > > "amit sethi" wrote > > > How do you pass arguments of unknown no. of arguments to a function. > > search the docs for *args and *kwargs > Or simply pass a tuple: def myPrint(thing): print thing thing_of_things = (1,'a',[

Re: [Tutor] Sort of database & "family tree" question

2009-02-05 Thread spir
Le Wed, 4 Feb 2009 22:33:45 -, "Alan Gauld" a écrit : > > "Timo" wrote > > class Person: > def __init__(self, parser): > self.first = parser.get(person, 'firstName') > > > > Hey Alan, thanks for that explanation! > > > > But the class you gave, does almost the

Re: [Tutor] confusing enumerate behavior

2009-02-06 Thread spir
Le Fri, 6 Feb 2009 12:30:31 +0530, jitendra gupta a écrit : > > #BEGIN > > my_input = "one two three four five six seven eight nine ten" > > text = my_input.split() > > for i,v in enumerate(text): > > line = text[i-3], text[i-2], text[i-1], v, text[i+1], text[i+2], > > text[i+3] > > prin

Re: [Tutor] any best practice on how to glue tiny tools together

2009-02-06 Thread spir
Le Fri, 6 Feb 2009 06:44:11 -0500, Kent Johnson a écrit : > My first thought was, use shell pipelines and bash. Then I remembered, > David Beazley shows how to use generators to implement a processing > pipeline in Python: > http://www.dabeaz.com/generators-uk/ see also http://en.wikipedia.org/w

Re: [Tutor] Picking up citations

2009-02-07 Thread spir
Le Fri, 6 Feb 2009 22:11:14 -0800, "Dinesh B Vadhia" a écrit : > Hi! I want to process text that contains citations, in this case in legal > documents, and pull-out each individual citation. Here is a sample text: > > text = "Page 500 Carter v. Jury Commission of Greene County, 396 U.S. 320,

Re: [Tutor] Exec(uting) Code in a Dictionary?

2009-02-08 Thread spir
Le Sat, 07 Feb 2009 13:50:01 -0800, Wayne Watson a écrit : > That's something for me to ponder, setattr. I'd rather not go off and pick up > on something like ConfigParser at this stage. I'd like to keep this code > somewhat simple and easy to understand, but yet have some flexibility for > ch

Re: [Tutor] UPDATED: Question on how to open other programs and files

2009-02-09 Thread spir
Le Sun, 8 Feb 2009 19:05:59 -0800, Hi a écrit : > Sorry for being confusing on my last e-mail. I will try to clarify my > intents a bit further. In short, I want to be able to read the data in the > file as well as launch document viewer in Python. For one of the files I > want to read the data f

Re: [Tutor] Simple PassGen

2009-02-09 Thread spir
Le Mon, 9 Feb 2009 13:45:04 -0800, Marc Tompkins a écrit : > The print() function adds a newline. Try this instead - above your loop, > create an empty string; in place of yor print(), append to the string; at > the end, print the whole string. > > I'd demonstrate but I'm typing this from my ph

[Tutor] module/package search

2011-05-23 Thread spir
Hello, I'm developing a package. I need user/test/special modules (inside or outside the package) to import given modules from the package, or the whole package or a sub-package. I'm looking for a general solution for this. For an importing module located inside the package, the obvious solut

[Tutor] string codes

2013-11-26 Thread spir
Hello, I am coming back to Python after quite a long time, have forgotten everything, and don't know anything of python 3. I use python 3.3 for its nice unicode text type. === codes === What is the method to get a code or list of codes inside a string: s = "abcde" c = s.code(

Re: [Tutor] Splitting lists with strings and integers

2013-11-27 Thread spir
On 11/26/2013 08:00 PM, Sam Lalonde wrote: Hi, I am very new to python. I have a list with mixed strings/integers. I want to convert this to a list of lists, and I want the numbers to get stored as integers. list1 = ['dog 1 2', 'cat 3 4', 'mouse 5 6'] There is a little interpretation error

Re: [Tutor] Splitting lists with strings and integers

2013-11-27 Thread spir
On 11/27/2013 02:18 AM, Dominik George wrote: >Before posting anything else would you please do a tutorial >yourself. The above for loop is appalling newbie code, I'll leave >you to post the Pythonic format. Can I trust my ears? Did you just make a move to expell me from posting newbie-readable

Re: [Tutor] string codes

2013-11-27 Thread spir
h plus start-index only seems to work fine, I guess. What is wrong? string.find also works (someone suggested it on the python-ideas mailing list) but requires both start- and end- indexes. Also, startswith returns true/false, which is more adequate conceptually for a checking instruction. spir@ospi

Re: [Tutor] string codes

2013-11-28 Thread spir
On 11/28/2013 02:12 AM, Walter Prins wrote: Sorry to wade in after all the other answers you've had, but a) string.find() does not *require* start and end indexes, they are optional: http://docs.python.org/2/library/string.htmlAnd b) if you're just trying to find out whether a substring exist

<    1   2   3   4   5   6   7   >