[Tutor] Fw: use of __new__

2009-06-12 Thread spir
Le Fri, 12 Jun 2009 14:20:24 +0200, "A.T.Hofkamp" s'exprima ainsi: > spir wrote: > > 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,

Re: [Tutor] use of __new__

2009-06-12 Thread spir
Le Fri, 12 Jun 2009 22:37:17 +1000, Lie Ryan s'exprima ainsi: > spir wrote: > > 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 i

Re: [Tutor] use of __new__

2009-06-12 Thread spir
Le Fri, 12 Jun 2009 22:37:17 +1000, Lie Ryan s'exprima ainsi: > >>> class Normal(object): > ... def __new__(cls, arg): > ... if arg: > ... return Special(arg) > ... else: > ... ret = super(Normal, cls).__new__(cls) > ... ret.__init__(arg)

Re: [Tutor] use of __new__

2009-06-12 Thread spir
Le Fri, 12 Jun 2009 09:05:35 -0400, Kent Johnson s'exprima ainsi: > On Fri, Jun 12, 2009 at 8:37 AM, Lie Ryan wrote: > class Normal(object): > > ...     def __new__(cls, arg): > > ...         if arg: > > ...             return Special(arg) > > ...         else: > > ...             ret = supe

Re: [Tutor] Need a solution.

2009-06-13 Thread spir
Le Sat, 13 Jun 2009 09:20:36 +0100, "Alan Gauld" s'exprima ainsi: > Any time you have a class that just has an __init__ it means > its not doing anything. And that's a bad sign. Classes are there > to *do* things not just store data. We can use a tuple or > dictionary to do that. While this i

Re: [Tutor] Need a solution.

2009-06-15 Thread spir
Le Sat, 13 Jun 2009 13:55:58 +0100, "Alan Gauld" s'exprima ainsi: > I think that you have a valid point but that "pure value" objects > occur far less often than you might think. I always treat a value > object as a sign that I've probably put some processing code > in the wrong place! Only wh

[Tutor] distutils MANIFEST.in

2009-06-16 Thread spir
Hello, a question for people who know how to write MANIFEST.in: How to tell to simply include all files in the package (and subdirs)? I tried: recursive-include *.* ==> warning: sdist: MANIFEST.in, line 1: 'recursive-include' expects ... recursive-include . *.* ==> warning: no files found ma

Re: [Tutor] distutils MANIFEST.in

2009-06-17 Thread spir
No one has a clue about this? Le Tue, 16 Jun 2009 22:59:24 +0200, spir s'exprima ainsi: > Hello, > > a question for people who know how to write MANIFEST.in: > How to tell to simply include all files in the package (and subdirs)? I > tried: > > recursive-includ

Re: [Tutor] distutils MANIFEST.in

2009-06-17 Thread spir
Le Wed, 17 Jun 2009 12:51:09 -0500, Chris Fuller s'exprima ainsi: > > Use os.path.walk or similar to build the file before you call setup(). > > Cheers Thanks, that's what I thought I would end up doing... Denis -- la vita e estrany ___ Tutor ma

[Tutor] distutils archive creation blocked

2009-06-19 Thread spir
Hello, when trying to create an archive with python setup.py sdist --formats=gztar,zip all works fine (archives are created) except temp dir deletion. Program blocks on removing 'foobar-1.0' (and everything under it) Actually, don't know how to check further for don't where this temp di

Re: [Tutor] distutils archive creation blocked

2009-06-19 Thread spir
Solved -- actually it was an error of mine in a wrapping subprocess.Popen() call. Le Fri, 19 Jun 2009 10:58:02 +0200, spir s'exprima ainsi: > Hello, > > when trying to create an archive with > >python setup.py sdist --formats=gztar,zip > > all works fine (ar

[Tutor] unicode: % & __str__ & str()

2009-10-30 Thread spir
[back to the list after a rather long break] Hello, I stepped on a unicode issue ;-) (one more) Below an illustration: === class U(unicode): def __str__(self): return self # if you can't properly see the string below, # 128 ¶ÿµ ¶ÿµ ¶ÿµ ¶ÿµ ¶ÿ

Re: [Tutor] Accessing variables in main from functions in a module

2009-10-30 Thread spir
Le Fri, 30 Oct 2009 18:39:42 -0400, Robert Lummis s'exprima ainsi: > I want to move some functions from my "main" program file to a module > file because the main file is getting too big for convenience. The > functions access arrays (lists of lists) that are defined and > initialised in the main

Re: [Tutor] Structure of my simulation / monte-carlo

2009-11-02 Thread spir
Le Sun, 01 Nov 2009 20:34:56 -0500, Dave Angel s'exprima ainsi: > And from what you said earlier, you WILL need function objects, probably > as parameters to the Simulation constructor. So each instance of > Simulation will be given several function objects to specify the > distribution funct

[Tutor] PolyRange -- iterator

2009-11-04 Thread spir
Hello, as I was crawling in endless complications with unadequate ranges, I decided to create a "PolyRange" type able to hold arbitrary many "sub-range"; which means finally a big range with wholes in it. This whole stuff again to cope with unicode -- a poly-range would be able to hold a range

[Tutor] operator overloading considered harmful ;-)

2009-11-07 Thread spir
Hello, I jump on the opportunity offered by the previous thread to tell a little story (serious only people disgard). Guess this is a candidate for Bug of the Year. I was filtering (parse) results to keep only nodes from a given set of types: for child in node: if child.pattern in item_type

Re: [Tutor] Classes that do operator overloading

2009-11-07 Thread spir
Le Sat, 7 Nov 2009 14:06:15 -, "Alan Gauld" s'exprima ainsi: > "C.T. Matsumoto" wrote > > > class Foo: # the book says this is a class header > >pass > > Hmm, that's pretty dubious usage of header in my view. > Its the class definition and there is nothing "header" about it. Engli

Re: [Tutor] Iterable Understanding

2009-11-13 Thread spir
Le Fri, 13 Nov 2009 17:58:30 +, Stephen Nelson-Smith s'exprima ainsi: > I think I'm having a major understanding failure. > > So having discovered that my Unix sort breaks on the last day of the > month, I've gone ahead and implemented a per log search, using heapq. > > I've tested it with

Re: [Tutor] OT: Writing code while tired, counterproductive?

2009-11-15 Thread spir
Le Sat, 14 Nov 2009 10:43:47 -0700, Modulok s'exprima ainsi: > List, > > This is kind off topic, but: > > Does anyone else find, writing code while tired to be counterproductive? > > It just seems like when I push myself to stay up late finishing a > project, I sorely regret it the following d

Re: [Tutor] Should a beginner learn Python 3.x

2009-11-15 Thread spir
Le Sat, 14 Nov 2009 20:49:52 +, Stephen Nelson-Smith s'exprima ainsi: > My brother in law is learning python. He's downloaded 3.1 for > Windows, and is having a play. It's already confused him that print > "hello world" gives a syntax error > > He's an absolute beginner with no program

Re: [Tutor] Find Integer co-ordinates lying on a circle

2009-11-15 Thread spir
Le Sun, 15 Nov 2009 09:11:16 +0530, Shashwat Anand s'exprima ainsi: > > No, I'm trying to find all integer co-ordinates which lies on a circle. > Say for a circle of radius 5 the co-ordinates are [(5, 0), (0, 5), (-5, 0), > (0, -5), (3, 4), (4,3), (3, -4), (4, -3), (-3, > 4), (-4, 3), (-3, -4),

Re: [Tutor] Unexpected iterator

2009-11-15 Thread spir
Le Sun, 15 Nov 2009 19:23:33 -, "Alan Gauld" s'exprima ainsi: > What does 'unpack' mean? I've seen a few Python errors about packing > and unpacking. What does it mean? Unpacking is rarely needed. It matches some kind of problems. Imagine you parse "codes" each made of name-sep-number. T

Re: [Tutor] Do you use unit testing?

2009-11-17 Thread spir
Le Mon, 16 Nov 2009 13:54:26 -0700, Modulok stated: > List, > > A general question: > > How many of you guys use unit testing as a development model, or at > all for that matter? I do. Systematically. Has become a reflex. I would rather ask the opposite question: how do know a part of your co

Re: [Tutor] Do you use unit testing?

2009-11-17 Thread spir
Le Tue, 17 Nov 2009 08:01:32 -, "Alan Gauld" stated: Hello, Alan, > The real benefits of unit tests are: > a) You test stuff as you write it so you know where the bug must lie Yes! (tried to say the same much clearly ;-) > b) You can go back and run the tests again 6 months later, > c) if

Re: [Tutor] Do you use unit testing? PS

2009-11-17 Thread spir
Le Tue, 17 Nov 2009 09:56:23 +0100, spir stated: > > b) You can go back and run the tests again 6 months later, > > c) if you have to add a new test its easy to make sure you don't break > > what used to work (regression testing). > > Do not understand this

Re: [Tutor] Sorting Data in Databases

2009-11-23 Thread spir
"Ken G." wrote: > I have not use the DBMS as I am unaware of them in both languages. DBMS is short for Data Base Management System, see wikipedia entry on the topic. Actually, the term is a bit ambiguous: * From a user point of view, a BDMS will be an application allowing managing data sets

Re: [Tutor] the art of testing

2009-11-24 Thread spir
Serdar Tumgoren wrote: > Lie and Kent, > > Thanks for the quick replies. > > I've started writing some "requirements", and combined with your > advice, am starting to feel a bit more confident on how to approach > this project. > > Below is an excerpt of my requirements -- basically what I've

[Tutor] file questions

2009-11-25 Thread spir
Hello, 1) encoding guess >From the library manual: file.encoding The encoding that this file uses. When Unicode strings are written to a file, they will be converted to byte strings using this encoding. In addition, when the file is connected to a terminal, the attribute gives the encoding t

Re: [Tutor] UnicodeEncodeError

2009-11-25 Thread spir
Albert-Jan Roskam wrote: > # CODE: > for element in doc.getiterator(): >   try: > m = re.match(search_text, str(element.text)) >   except UnicodeEncodeError: >     raise # I want to get rid of this exception. First, you should separate both actions done in a single statement to isolate the

Re: [Tutor] the art of testing

2009-11-25 Thread spir
Serdar Tumgoren wrote: > And the more I hear from you folks, the more I start thinking that my > confusion arose because I don't have a formal set of requirements and > therefore have to wear multiple hats I think a base confusion was between your app's own job (validation), on one hand, and te

[Tutor] python time

2009-11-25 Thread spir
Hello, How does python get the time in microseconds? (In other words, how would I get it if python (like some other languages) would provide time in whole seconds only?) Thank you, Denis la vita e estrany http://spir.wikidot.com/

Re: [Tutor] unicode mapping doesn't work

2009-11-27 Thread spir
Lie Ryan wrote: > > funnychars = u"éèêëóòôöáàâäÉÈÊËÓÒÔÖÁÀÂÄ" > > asciichars = "" > > In addition to Lie's reply, you will very probably need diacritic-free chars to be unicode, too. Otherwise prepare for later UnocideEn/De-codeError-s. As a rule of thumb, if you work wi

Re: [Tutor] python time

2009-11-27 Thread spir
Kent Johnson wrote: > On Wed, Nov 25, 2009 at 11:11 AM, spir wrote: > > Hello, > > > > How does python get the time in microseconds? (In other words, how would I > > get it if python (like some other languages) would provide time in whole > > seconds only?) &g

Re: [Tutor] AttributeError: Vector instance has no attribute 'Normalize'

2009-11-27 Thread spir
Garrett Hartshaw wrote: > The program I am writing gives the following error message when run. > > Traceback (most recent call last): >   File "./space.py", line 177, in >     main() >   File "./space.py", line 173, in main >     player = Ship("space/models/fighter.3ds", > "space/models/realist

Re: [Tutor] python time

2009-11-27 Thread spir
"Alan Gauld" wrote: Thank you, Alan. > "spir" wrote > > > So, python uses C's gettimeofday() func when available > > It's not C's function, it's a Unix system call. > It's been part of Unix since BSD 4.2 > > > ft

Re: [Tutor] Python best practices

2009-11-29 Thread spir
Lie Ryan dixit: > > - functions should return one value (im not 100% of this one) > > I 100% disagree or with this one. Could you explain this bit, Lie? I'm very interested. I use multiple-value result myself, for it's so practicle in given cases. But it makes me uneasy; also have the impres

[Tutor] python closures

2009-11-30 Thread spir
Hello, Below startup definitions: x = 1 def f(): n = 1 def g0(a): print (x + n + a) return g0 I'm surprised the snippet below works as expected (py 2.6) without any trick: g = f() g(1)# --> 3 This means a (real) closure is built for g0, or what? Thought I would need instead to

Re: [Tutor] Python best practices

2009-11-30 Thread spir
ALAN GAULD dixit: > But as I said earlier the concept of multiple return > values in Python is similar to returning a struct in C. > The key thing is that the function has a single purpose > so if returning multiple values or a struct the values > within that group should be related to the sin

Re: [Tutor] Equivalent exception of os.path.exists()

2009-11-30 Thread spir
biboy mendz dixit: > http://pastebin.ca/1693849 > > This is end-of-chapter3 exercise of the book Core Python Programming. > > I'm reading/searching in the book and other materials but is > unsuccessful. There are at least 50 exceptions listed but I can't find > anything close. > > I commente

Re: [Tutor] x is a global variable

2009-11-30 Thread spir
Hello Eike! Eike Welk dixit: > Hello Spir! > > On Monday 30 November 2009, spir wrote: > > which seems to indicate python really embeds "symbolic references" > > (*) to outer *variables*, when creating a closure for g0. Not > > "pointer references&q

Re: [Tutor] python closures

2009-11-30 Thread spir
ecent call last): > > File "", line 1, in > > f() > > File "", line 2, in f > > x = x + 1 > > UnboundLocalError: local variable 'x' referenced before assignment > Ah... what a pity I didn't try this. I used similar c

Re: [Tutor] Equivalent exception of os.path.exists()

2009-11-30 Thread spir
biboy mendz dixit: > > > spir wrote: > > > > What is your question? > > If it's about the type of exception raised when os.path.exists fails, well, > > sure it's hard to find: > > > > print os.path.exists("foo".bar) >

Re: [Tutor] Equivalent exception of os.path.exists()

2009-12-01 Thread spir
bibi midi dixit: > Like i thought so, there is no exception to catch if a file already exist. > I've been browsing the many types of exceptions and cant find anything thats > close. Thank you for clarifying. > Actually, you can. I guess it's not the book author's intent, but you can try it for

Re: [Tutor] python closures

2009-12-01 Thread spir
Dave Angel dixit: > Maybe a more complex example might show the various linkages. > > glob = 42 > > def outer(parm1): > free = 12 > free3 = 19 > def inner(parm2, parm3=free3): > print "global", glob, ", free vars", parm1, free, free3, ", > locals", parm2, parm3 > free =

Re: [Tutor] python closures

2009-12-01 Thread spir
May I suggest that upvalues are analog to parameters passed by name? (which is indeed not Python's paradigm) Denis la vita e estrany http://spir.wikidot.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or c

Re: [Tutor] When max() doesn't work as expected

2009-12-03 Thread spir
Albert Sweigart dixit: > You need to specify an ordering function, in your case, len(): By the way, is there any reason why the compare func parameter is called 'key'? Denis la vita e estrany http://spir.wikidot.com/ _

Re: [Tutor] saving output data in a file

2009-12-04 Thread spir
Prasad Mehendale dixit: > I am a beginner. I want to save the output data of the following programme in > a file through the programme. Please suggest me the way. I am using Python > 2.3.3 on mandrake linux 10 and using "Idle" to save the output to a file > presently. > Thanks in advance. Yo

Re: [Tutor] Dictionary Comprehensions

2009-12-05 Thread spir
Lie Ryan dixit: > note that: > >>> [(y, x) for y in list("khalid") for x in range(6)] > [('k', 0), ('k', 1), ('k', 2), ('k', 3), ('k', 4), ('k', 5), ('h', 0), > ('h', 1), ('h', 2), ('h', 3), ('h', 4), ('h', 5), ('a', 0), ('a', 1), > ('a', 2), ('a', 3), ('a', 4), ('a', 5), ('l', 0), ('l', 1),

Re: [Tutor] Dictionary Comprehensions

2009-12-05 Thread spir
Hugo Arts dixit: > bc = {y: x for x, y in enumerate("khalid")} > > Note that your output is like so: > {'a': 2, 'd': 5, 'i': 4, 'h': 1, 'k': 0, 'l': 3} > > The first character in your original string gets a zero, the second a > one, so on and so forth. I'm hoping that's what you meant. If you >

Re: [Tutor] saving output data in a file

2009-12-05 Thread spir
Dave Kuhlman dixit: > On Fri, Dec 04, 2009 at 01:13:42PM +0530, Prasad Mehendale wrote: > > I am a beginner. I want to save the output data of the following programme > > in > > a file through the programme. Please suggest me the way. I am using Python > > 2.3.3 on mandrake linux 10 and using

Re: [Tutor] Question : Creating cribbage game

2009-12-07 Thread spir
Christopher schueler dixit: > > My name is Chris Schueler and i am having some troubles with my Python > programming > > > > Our current project is to create the game of cribbage from scratch. > > The only problem is we are not allowed to use classes, only user-defind > functions and arra

Re: [Tutor] functions--how long is too long?

2009-12-08 Thread spir
Luke Paireepinart dixit: > I'd say my personal hard-limit for functions before I start refactoring is > probably around 150-200 lines. But it's rare that functions get that long > anyway. ! Aside questions of personal style & taste, _I_ could not hold such long funcs. Far too much to manage f

Re: [Tutor] loops

2009-12-08 Thread spir
Lie Ryan dixit: > On 12/8/2009 9:39 PM, Dave Angel wrote: > > Richard Hultgren wrote: > >> a = 0 > >> b = 1 > >> count = 0 > >> max_count = 20 > >> while count < max_count: > >> count = count + 1 > >> # we need to keep track of a since we change it > >> old_a = a # especially here > >> old_b = b

Re: [Tutor] File renaming using os.rename problem

2009-12-08 Thread spir
Roy Hinkelman dixit: > I can't find anything on this error I am getting when renaming some files. > I'm pulling info from a csv file and parsing it to build new file names. > > Any pointers appreciated > > Roy > > My code: > # RENAME FILES using META file - new name = [place]_[state]_[sku].tif

Re: [Tutor] File renaming using os.rename problem (spir)

2009-12-09 Thread spir
Roy Hinkelman dixit: > Why don't you simply print out fname? This should point you to the error. > > Denis > > > I did here: > > if fname == old_name: > > print fname # test > > and it looks correct. > > On an WinXP, should I use shutil instead? > > Roy Sorry Roy, I rea

Re: [Tutor] duplication in unit tests

2009-12-09 Thread spir
Serdar Tumgoren dixit: > Hi everyone, > I'm trying to apply some lessons from the recent list discussions on > unit testing and Test-Driven Development, but I seem to have hit a > sticking point. > > As part of my program, I'm planning to create objects that perform > some initial data clean-up

Re: [Tutor] What books do you recommend?

2009-12-09 Thread spir
"Alan Gauld" dixit: > > "Khalid Al-Ghamdi" wrote > > > I wan't to buy some books about python 3. Do you have any > > recommendations? > > There are very few Python 3 books out there. > The only one I've used and can recommend is Programming in Python3 by > Summerfield > > Other general Pyt

Re: [Tutor] duplication in unit tests

2009-12-09 Thread spir
Serdar Tumgoren dixit: > I'll admit, I learned the hard way on a project earlier this year. I > got that project done (again with the help of folks on this list), but > didn't do any test-writing up front. And now, as the inevitable bugs > crop up, I'm forced to patch them hoping that I don't bre

Re: [Tutor] More on unit testing - tests for external data...

2009-12-10 Thread spir
Wayne Werner dixit: > On Wed, Dec 9, 2009 at 6:15 PM, Alan Gauld wrote: > > > > > Remember, in testing you are not trying to prove it works but rather to > > demonstrate that it doesn't! > > > > So in that way it's a bit like the the scientific method (or exactly like)? > You create a hypothesi

Re: [Tutor] typerror

2009-12-11 Thread spir
"Roshan S" dixit: > class Student: > print"We have a new student " > def __init__(self,name='',credit=0,grade=0,quality=0): > self.name=name > self.credit=credit > self.grade=grade > self.quality=quality > > > def inputstudent(self): >

Re: [Tutor] another unit-testing question: regex testing

2009-12-16 Thread spir
Serdar Tumgoren dixit: > > I often use a list of test cases to drive a single test. Using a > > series of tests is just too painful compared to making a simple list > > of test cases. > > I kinda suspected that but wasn't sure. These tests are for a REALLY > basic regex and I was having nightmar

Re: [Tutor] Need a better name for this function

2009-12-16 Thread spir
Hugo Arts dixit: > The function will give you the exact value of any > floating point number stored in memory. To be even clearer: Seems you messed up "the exact value of any floating point number stored in memory" with "an accurate value (= the intended value)". _

Re: [Tutor] Generating Unique Permutations

2009-12-18 Thread spir
Michael Morrissey dixit: > I'm just a philosophy teacher, and I don't know much about mathematics or > computers. I'm writing a python program (not the best language for this > topic, but it is what I know), and I need to solve a problem which requires > more knowledge than I have. I'm hoping you

Re: [Tutor] Field/Variable References

2009-12-18 Thread spir
Serdar Tumgoren dixit: > > Thank you - can you please assume that the data provided is the following: > > > > Columns 1 - 4 = Name (in record 1 of example = "John") > > Column 5 = Answer1 (in record 1 of example = "9") > > Column 6 = Answer2 (in record 1 of example = "8") > > Column 7 = AreaCode

Re: [Tutor] How can I make this run faster?

2009-12-21 Thread spir
Emad Nawfal (عمـ نوفل ـاد) dixit: > Dear Tutors, > The purpose of this script is to see how many vocalized forms map to a > single consonantal form. For example, the form "fn" could be fan, fin, fun. > > The input is a large list (taken from a file) that has ordinary words. The > script creates

Re: [Tutor] print IP address range to stdout

2009-12-22 Thread spir
MK dixit: > First function the ip is splitted as i did it. Alright. > The use 256 as it is the maximum for any digit. ok. > But what is that ** and exp meaning > > -- > def ip_to_int(dotted_ip): > exp = 3 > intip = 0 >

[Tutor] unicode ordinals to/from utf8

2009-12-25 Thread spir
Special offer for coders coding on Christmas day! I'm looking for the simplest way to decode/encode unicode ordinals (called 'codes' below) to/from utf8. Find this rather tricky, esp because of variable number of meaningful bits in first octet. Specifically, for encoding, is there a way to avoi

Re: [Tutor] unicode ordinals to/from utf8

2009-12-26 Thread spir
OK, I'll answer myself ;-) Found needed information at http://www1.tip.nl/~t876506/utf8tbl.html See below new version, Denis la vita e estrany http://spir.wikidot.com/ = # coding: utf8 import sys ; end = sys.exit # constant max_co

Re: [Tutor] try and except

2009-12-30 Thread spir
Lie Ryan dixit: > class Error(Exception): > def __init__(self, value): > self.value = value > def printer(self, value): > print self.value You can also use __str__ instead of printer. This will give a standard output form for your error automatically used by print and

Re: [Tutor] find() doesnt work as expected

2010-01-02 Thread spir
MK dixit: > At first, happy new year to all of you. > > I am trying to write a little script which uses one file > as input and looks if the string from this file are in target file. And > if not prints out that line/string so that i know which strings must > be added to complete the target file.

Re: [Tutor] Finding a repeating sequence of digits

2010-01-02 Thread spir
Robert Berman dixit: > Hi, > > I am trying to build an algorithm or methodology which will let me tell > if a decimal has a repeating sequence of digits and if it does have that > attribute, what is the sequence of digits. For example, 1/3.0 = > 0.3..By eyeballing we know it has a repeati

Re: [Tutor] extract meaningful data from garbage

2010-01-03 Thread spir
Shashwat Anand dixit: > @Alan, @Lie thanks > The approach which I am taking right now is taking some test-cases, and > creating rules for them. Later on after expanding the cases there aroused > some cases which didn't followed earlier pattern so I tweaked some rules so > as to match all of them.

[Tutor] list.insert()

2010-01-06 Thread spir
Hello, Just found something rather misleading with negative indices: s = [1,2,3,4,5,6,7,8,9] print s, s[-3], s[-4] # [1, 2, 3, 4, 5, 6, 7, 8, 9] 7 6 s.insert(-3, 0) print s, s[-3], s[-4] # [1, 2, 3, 4, 5, 6, 0, 7, 8, 9] 7 0 So, I did insert 0 at index -3, but s[-3] is still 7, & 0 is in fact

Re: [Tutor] Greetings Pythonistas

2010-01-08 Thread spir
galaxywatc...@gmail.com dixit: > I often > wish that I had a private tutor or a Python guru that I could just ask > how to get past a certain wall. Perhaps this list has that person or > people on it. The list as a whole certainly _can_ be this, & more ;-) (depends on how _you_ deal with i

Re: [Tutor] Help with a Dictionary

2010-01-08 Thread spir
Garry Bettle dixit: [...series of data with same format...] > 2010-01-07 1437 Crayfd H3 380m > ... etc. > > The above are RaceDate + RaceTime + Fixture + RaceDetails, and are > output in RaceTime order. > > What I'd like to do, is output a transposed-like summary of just the > Fixture + RaceTime

Re: [Tutor] Help with a Dictionary

2010-01-08 Thread spir
Garry Bettle dixit: > for fixture in FixtureList: > print fixture.ljust(6), FixtureList[fixture] ... > for fixture, racetimes in FixtureList: > print fixture, racetimes > > Traceback (most recent call last): > File "", line 1, in > for fixture, racetimes in FixtureList: > ValueErro

Re: [Tutor] formatting*

2010-01-08 Thread spir
Lowell Tackett dixit: > An odd aside, however--I went into the Tutor Archives forum and pulled up the > Page Source (HTML formatting template) and lo and behold all my paragraphs > were correctly formatted (i.e. page-wrapped just as they had been when they > left my mail notepad) and displayed

Re: [Tutor] Expanding a Python script to include a zcat and awk pre-process

2010-01-08 Thread spir
galaxywatc...@gmail.com dixit: > I wrote a simple Python script to process a text file, but I had to > run a shell one liner to get the text file primed for the script. I > would much rather have the Python script handle the whole task without > any pre-processing at all. I will show 1) a sm

Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-09 Thread spir
Lie Ryan dixit: > only use "from module import *" if the > module was designed for such use In most cases, this translates to: the imported module defines __names__, which holds the list of names (of the objects) to be exported. Check it. Below, a,b,c,f,g,X,Y are defined, but only c,g,Y are ex

Re: [Tutor] question about function inside of function

2010-01-09 Thread spir
Richard D. Moores dixit: > I'm working on a function that seems to cry out for some of its code > to be put in a function. For convenience sake, I've put this new > function inside the one that calls it. > > Question 1: Is this bad practice? It works fine that way, but.. > > Question 2: If the a

[Tutor] class/type methods/functions

2008-10-30 Thread spir
Hello, New to the list. I'm a self-taught, amateur programmer. Also, non-native english speaker -- so, don't be surprised with weird expression. Q: Is there a way to write /type/ (class) functions, meaning methods not bound to an instance, in python? Context: I'm developping an application

[Tutor] [Re: class/type methods/functions]

2008-10-30 Thread spir
[forwarded, only A.T.Hofkamp got this answer] A.T.Hofkamp a écrit : spir wrote: Q: Is there a way to write /type/ (class) functions, meaning methods not bound to an instance, in python? As Bob Gailer already said, staticmethod seems to do what you want. Thank you for you answers about

Re: [Tutor] class/type methods/functions

2008-10-30 Thread spir
Hello again, I just tried with the classmethod() built_in function. Well, this is exactly what I was looking for. It supplies a way of defining type_level methods -- what was missing before. [I still think this is a workaround: we would not need this if the syntax was the same for methods and

[Tutor] python editor / IDE

2008-10-31 Thread spir
Hello, I have read tons of reviews of editors for python. But they seem to be all biased, meaning that what the author finds important is well documented while the rest not at all. I'm looking for something like a simple table showing main features for all editors or IDEs. Do you know of anyt

Re: [Tutor] mergin two csv files based on a common join

2008-11-01 Thread spir
[EMAIL PROTECTED] a écrit: Hello again, Thanks for the replies on my previous post, but I have a different problem now and don't see how to deal with it in a smooth way. I have two csv files where: 1.csv "1", "text", "aa" "2", "text2", "something else" "3", "text3", "som

Re: [Tutor] [Re: class/type methods/functions]

2008-11-01 Thread spir
Thank you for this relevant & precise review, Albert. I will answer specific topic, then give a overall introduction of the problem(s) adressed by this project, that may clarify a bit some topics. A.T.Hofkamp a écrit : > However, by moving the 'type' information to a seperate object, your

Re: [Tutor] (no subject)

2008-11-01 Thread spir
[EMAIL PROTECTED] a écrit : Dear Friends, I have just started learning python programming. I have no previous programming knowledge. Welcome! I'm an amateur, too. Some words to add to Kent's answer. I am presently using Python 2.6 windows version. I am struggling with how to enable executable f

Re: [Tutor] Manipulate list in place or append to a new list

2008-11-01 Thread spir
Sander Sweers a écrit : Hi, What is the better way to process data in a list? Make the changes in place, for example somelist = [1,2,3,4] for x in range(len(somelist)): somelist[x] = somelist[x] + 1 Or would making a new list like somelist = [1,2,3,4] newlist = [] for x in somelist:

Re: [Tutor] Manipulate list in place or append to a new list

2008-11-02 Thread spir
Sander Sweers a écrit : On Sun, Nov 2, 2008 at 13:32, Kent Johnson <[EMAIL PROTECTED]> wrote: Use a list comprehension: somelist = [ x+1 for x in somelist ] Got it. Note that this creates a new list, replacing the one that was in somelist. If you need to actually modify somelist in place (ra

[Tutor] err... list.pairs()?

2008-11-02 Thread spir
Excuse me for such a stupid question, I just wish to stop and lose my time searching for something that maybe simply does not exist. I'm looking for the builtin function for sequences that would return a list of (index,item) pairs to be used in loops. analog to dict's items() function. [I was wri

[Tutor] value and object names

2008-11-02 Thread spir
I have just read the following article: http://effbot.org/zone/python-objects.htm (thanks to a link on Kent's site). It is very good, I really recommend it. Still, a short passage has troubled my model about object names: "The names are a bit different — they’re not really properties of the obje

[Tutor] pattern expressions

2008-11-07 Thread spir
Hello, I'm learning to use parsers: trying pyParsing, construct and simpleparse to have a better overview. I know a bit regular expressions and rather used to BNF-like formats such as used for specification of languages. But I have never really employed them personly, so the following may be t

Re: [Tutor] pattern expressions

2008-11-07 Thread spir
Paul McGuire a écrit : > Question 1: > format_code:= '+' | '-' | '*' | '#' > I need to specify that a single, identical, format_code code may be > repeated. > Not that a there may be several one on a sequence. > format := (format_code)+ > would catch '+-', which is wrong. I wan

Re: [Tutor] gnuplot from a python gui

2008-11-08 Thread spir
[EMAIL PROTECTED] a écrit : Hello tutors, I'm trying to generate a plot using gnuplot from within a python gui. In Windows, if after the plot is drawn I use a raw_input string demanding a 'RETURN' be hit, the plot will persist on the screen until the 'RETURN' is pressed. In *nix, one can use

[Tutor] get a module's own (top_level) dict?

2008-11-09 Thread spir
Hello pyhonistas, Example: === module content === a = 1 b = 2 == I'm looking for a way to get something like {'a':a, b':2}. Actually, names defind in the module will be instances of a custom type. I want to give them an attribute that holds their own name. E.g.: for key,ob

[Tutor] [Fwd: Re: get a module's own (top_level) dict?]

2008-11-10 Thread spir
(forwarded to the list) Hello pyhonistas, Example: === module content === a = 1 b = 2 == I'm looking for a way to get something like {'a':a, b':2}. Actually, names defind in the module will be instances of a custom type. I want to give them an attribute that holds their own

Re: [Tutor] import data (txt/csv) into list/array and manipulation

2008-11-11 Thread spir
ppend(5) x = gd.pop() gd.store_strings(["string","data"]) gd.store_string("i'm relevant info") print gd, gd.strings print "average: %2.2f ; removed: %i" %(gd.average(), x) ==> [1, 2, 3, 4] ['string', 'data', "i'm relevant i

Re: [Tutor] experience/opinions with deploying python GUI app to Linux, Win32, and Mac OS X

2008-11-13 Thread spir
You may have a look at easygui. Probably not for final release, rather for design stage. It's based on tkinter I guess. I found it very helpful as long as the app does not require sophisticated widgets and there is a proper separation of process and UI. Once everything works, it is fast enough t

[Tutor] list output -- float output

2008-11-14 Thread spir
Below an illustration of what troubles me a bit. denis class Seq(list): ''' specialized sequence type with improved str Override list's behaviour that list.__str__ calls __repr__ instead of __str__ on items. ??? ''' def __str__(self):

Re: [Tutor] list output -- float output

2008-11-14 Thread spir
text = str(self[0]) for item in self[1:]: if isinstance(item, list): item = Seq(item) # will now call str on nested Seqs text += " ,%s" %item ret

<    1   2   3   4   5   6   7   >