how to get selected filename in FileSelectBox

2008-07-04 Thread wilson
electbox.selection.cget("value") fselectbox.selection.selection_clear() print "file=",selectedfile i did these by going thru the docs in tix ,actually i couldn't find an example so i am not sure if this is the right way..it does print the filename but i want to know i

Limits of Metaprogramming

2008-08-04 Thread Wilson
Hi all, I have an interesting problem that I'm hoping can be solved with metaprogramming, but I don't know how far Python supports code generation (and I don't know if I'm taking the correct approach either... hence why I'm asking on this group): I'd like to write a program that writes/manipulate

Re: Limits of Metaprogramming

2008-08-04 Thread Wilson
On 4 Aug, 12:55, Jeff <[EMAIL PROTECTED]> wrote: > You could write a class composed of states and then use the pickle > module to serialize it to disk. Thanks Jeff. I guess this is my intermediary format! -- http://mail.python.org/mailman/listinfo/python-list

Re: Limits of Metaprogramming

2008-08-04 Thread Wilson
On 4 Aug, 14:47, Tomasz Rola <[EMAIL PROTECTED]> wrote: > On Mon, 4 Aug 2008, Wilson wrote: > > Hi all, > > Howdy, > > I am not sure if my remarks will be of any use for you, but here it goes. > > > I have an interesting problem that I'm hoping can be sol

Re: Limits of Metaprogramming

2008-08-04 Thread Wilson
On 4 Aug, 16:50, John Nagle <[EMAIL PROTECTED]> wrote: > Wilson wrote: > > Hi all, > > > I have an interesting problem that I'm hoping can be solved with > > metaprogramming, but I don't know how far Python supports code > > generation (and I

Re: Limits of Metaprogramming

2008-08-04 Thread Wilson
On Aug 4, 6:49 pm, castironpi <[EMAIL PROTECTED]> wrote: > On Aug 4, 4:48 am, Wilson <[EMAIL PROTECTED]> wrote: > > > Hi all, > > > My problem is that I don't know if it's possible to edit these states > > and then write them back to .py. Firstly,

Re: Limits of Metaprogramming

2008-08-06 Thread Wilson
On Aug 4, 9:23 pm, castironpi <[EMAIL PROTECTED]> wrote: > On Aug 4, 1:57 pm, Wilson <[EMAIL PROTECTED]> wrote: > > > On Aug 4, 6:49 pm, castironpi <[EMAIL PROTECTED]> wrote: > > > > Two, if all your methods will have uniform signatures and closures, >

Re: Limits of Metaprogramming

2008-08-07 Thread Wilson
On Aug 6, 6:04 pm, castironpi <[EMAIL PROTECTED]> wrote: > On Aug 6, 7:24 am, Wilson <[EMAIL PROTECTED]> wrote: > > > > > On Aug 4, 9:23 pm, castironpi <[EMAIL PROTECTED]> wrote: > > > > On Aug 4, 1:57 pm, Wilson <[EMAIL PROTECTED]> wrote: >

Re: Limits of Metaprogramming

2008-08-08 Thread Wilson
On 8 Aug, 13:30, Iain King <[EMAIL PROTECTED]> wrote: > On Aug 4, 5:13 pm, Tomasz Rola <[EMAIL PROTECTED]> wrote: > > > On Mon, 4 Aug 2008, Wilson wrote: > > > " Every sufficiently large application has a poor/incomplete > > > implementation ofLISP

Manipulating Python Source

2008-08-12 Thread Wilson
Hi, I'm wondering if there are any tools available or simple methods for taking a python source file and parsing into some hierarchical format, like the ConfigParser. I'd like to be able to do something like the following: test.py: --- """ This

Re: Manipulating Python Source

2008-08-13 Thread Wilson
On 12 Aug, 15:53, Bruno Desthuilliers wrote: > Kay Schluehr a écrit :> On 12 Aug., 16:35,Wilson<[EMAIL PROTECTED]> wrote: > >> Hi, > > >> I'm wondering if there are any tools available or simple methods for > >> taking a python source file and parsi

displaying pgm file in python

2008-04-04 Thread wilson
i converted an 8bit rgb .jpg file into .pgm using adobe photoshop and a plugin from http://photoshop.pluginsworld.com/plugins/adobe/362/richard-rosenman/portable-pixmap-importer-exporter.html I want to check if this file can be properly displayed. Image opening and show() in PIL fails to do it so

removing extension

2008-04-27 Thread wilson
i was trying to convert all images in a folder to another type and save the new images in a separate folder.for that i wrote a class and coded some part class ConvertImgs: def __init__(self,infldr,outfldr): if os.path.isdir(infldr): self.infldr=infld

convert images

2008-04-27 Thread wilson
hi i converted some P5 type .pgm images to .jpg using x=Image.open("oldimage.pgm") imsz=x.size newimg=Image.new('L',imsz) newimg.putdata(x.getdata()) newimg.save("newimg.jpg") when i again check the pixel data for these images using getdata() method i,I find that they are slightly different ie if

Re: Parsing and Editing Source

2008-08-15 Thread Wilson
On Aug 15, 3:45 pm, eliben <[EMAIL PROTECTED]> wrote: > On Aug 15, 4:21 pm, "Paul Wilson" <[EMAIL PROTECTED]> wrote: > > > > > Hi all, > > > I'd like to be able to do the following to a python source file > > programmatically: > >

Re: Parsing and Editing Source

2008-08-15 Thread Wilson
On Aug 15, 4:16 pm, Rafe <[EMAIL PROTECTED]> wrote: > On Aug 15, 9:21 pm, "Paul Wilson" <[EMAIL PROTECTED]> wrote: > > > > > Hi all, > > > I'd like to be able to do the following to a python source file > > programmatically: > >

Re: Parsing and Editing Source

2008-08-16 Thread Wilson
On Aug 16, 3:51 am, Benjamin <[EMAIL PROTECTED]> wrote: > On Aug 15, 9:21 am, "Paul Wilson" <[EMAIL PROTECTED]> wrote: > > > > > Hi all, > > > I'd like to be able to do the following to a python source file > > programmatically: > >

file I/O and arithmetic calculation

2013-05-22 Thread Keira Wilson
Dear all, I would appreciate if someone could write a simple python code for the purpose below: I have five text files each of 10 columns by 10 rows as follows: file_one = 'C:/test/1.txt' file_two = 'C:/test/2.txt' . . . file_five = 'C:/test/5.txt' I want to calculate the mean of first row (10

Re: file I/O and arithmetic calculation

2013-05-23 Thread Keira Wilson
Dear all who involved with responding to my question - Thank you so much for your nice code which really helped me. -- http://mail.python.org/mailman/listinfo/python-list

Re: file I/O and arithmetic calculation

2013-05-23 Thread Keira Wilson
not exactly for the homework, but as my starting point of learning thank you so much. -- http://mail.python.org/mailman/listinfo/python-list

Re: except clause syntax question

2012-01-30 Thread Mel Wilson
Charles Yeomans wrote: > To catch more than one exception type in an except block, one writes > > except (A, B, C) as e: > > I'm wondering why it was decided to match tuples, but not lists: > > except [A, B, C] as e: > > The latter makes more sense semantically to me -- "catch all exception >

Re: except clause syntax question

2012-01-31 Thread Mel Wilson
Charles Yeomans wrote: > To catch more than one exception type in an except block, one writes > > except (A, B, C) as e: > > I'm wondering why it was decided to match tuples, but not lists: > > except [A, B, C] as e: > > The latter makes more sense semantically to me -- "catch all exception >

Re: except clause syntax question

2012-01-31 Thread Mel Wilson
Chris Angelico wrote: > On Wed, Feb 1, 2012 at 9:03 AM, Duncan Booth > wrote: >> Abitrarily nested tuples of exceptions cannot contain loops so the code >> simply needs to walk through the tuples until it finds a match. > > Is this absolutely guaranteed? The C API for CPython provides: > (Py2) h

Re: Question about name scope

2012-02-01 Thread Mel Wilson
Dave Angel wrote: > I tried your experiment using Python 2.7 and Linux 11.04 > > > def f(a): > from math import sin, cos > return sin(a) + cos(a) > > print f(45) > > Does what you needed, and neatly. The only name added to the global > namspace is f, of type function. > > I was a b

Re: python reliability with EINTR handling in general modules

2012-02-02 Thread Mel Wilson
Dennis Lee Bieber wrote: > On Wed, 1 Feb 2012 23:25:36 -0800 (PST), oleg korenevich > wrote: > > >>Thanks for help. In first case all vars is python integers, maybe >>math.floor is redundant, but i'm afraid that same error with math >>module call will occur in other places of app, where math is

Re: difference between random module in python 2.6 and 3.2?

2012-02-06 Thread Mel Wilson
Steven D'Aprano wrote: > A more explicit note will help, but the basic problem applies: how do you > write deterministic tests given that the random.methods (apart from > random.random itself) can be changed without warning? Biting the bullet would mean supplying your own PRNG, under your control

Re: M2crypto

2012-02-12 Thread Mel Wilson
zigi wrote: > Hello, > M2crypto > > __init__(self, alg, key, iv, op, key_as_bytes=0, d='md5', > salt='12345678', i=1, padding=1) > > I wont write app, using M2crypto and I can not understand what are the > arguments: > key, iv, op, salt ? > What they do ? I assume you're reading in

Re: name of a sorting algorithm

2012-02-14 Thread Mel Wilson
Jabba Laci wrote: > Could someone please tell me what the following sorting algorithm is > called? > > Let an array contain the elements a_1, a_2, ..., a_N. Then: > for i in xrange (N-1): for j in xrange (i, N): if a[j] < a[i]: a[i], a[j] = a[j], a[i] > > It's so simple t

RE: name of a sorting algorithm

2012-02-14 Thread Mel Wilson
Prasad, Ramit wrote: >> > for i in xrange (N-1): > for j in xrange (i, N): > if a[j] < a[i]: > a[i], a[j] = a[j], a[i] >> It's what Wikipedia says a selection sort is: put the least element in >> [0], the least of the remaining elements in [1], etc. > > If your only requi

Re: name of a sorting algorithm

2012-02-14 Thread Mel Wilson
Den wrote: > I disagree. In a bubble sort, one pointer points to the top element, > while another descents through all the other elements, swapping the > elements at the pointers when necessary. 'When I use a word,' Humpty Dumpty said, in rather a scornful tone, 'it means just what I choose it

Re: atexit.register in case of errors

2012-02-15 Thread Mel Wilson
Andrea Crotti wrote: > I have the following very simplified situation > > from atexit import register > > > def goodbye(): > print("saying goodbye") > > > def main(): > while True: > var = raw_input("read something") > > > if __name__ == '__main__': > register(goodby

Re: PyWart: Language missing maximum constant of numeric types!

2012-02-24 Thread Mel Wilson
Rick Johnson wrote: > I get sick and tired of doing this!!! > > if maxlength == UNLIMITED: > allow_passage() > elif len(string) > maxlength: > deny_passage() > > What Python needs is some constant that can be compared to ANY numeric > type and that constant will ALWAYS be larger! Easily

Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-03-02 Thread Mel Wilson
Terry Reedy wrote: > The problem was another subtle bug in the current example": > self.hi_there["text"] = "Hello", > > The spurious comma at the end makes the value of the 'text' attribute a > one-elememt tuple and not just a string. I presume tcl-based tk handles > that in the manner a

Re: A 'Python like' language

2012-03-03 Thread Mel Wilson
Paul Rubin wrote: > dreamingforw...@gmail.com writes: >>> hanging out on the Prothon list now and then, at least until we get >>> the core language sorted out? >> >> Haha, a little late, but consider this a restart. > > It wasn't til I saw the word "Prothon" that I scrolled back and saw you > wer

Re: Python is readable

2012-03-16 Thread Mel Wilson
Steven D'Aprano wrote: > On Fri, 16 Mar 2012 17:53:24 +, Neil Cerutti wrote: > >> On 2012-03-16, Steven D'Aprano >> wrote: >>> Ah, perhaps you're talking about *prescriptivist* grammarians, who >>> insist on applying grammatical rules that exist only in their own >>> fevered imagination. Sor

Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct

2012-03-17 Thread Mel Wilson
Antti J Ylikoski wrote: > > In his legendary book series The Art of Computer Programming, > Professor Donald E. Knuth presents many of his algorithms in the form > that they have been divided in several individual phases, with > instructions to GOTO to another phase interspersed in the text of th

Re: Python Book for a C Programmer?

2012-05-24 Thread Jim Wilson
On 05/23/2012 07:45 PM, hsa...@gmail.com wrote: > I am trying to join an online class that uses python. I need to brush up on > the language quickly. Is there a good book or resource that covers it well > but does not have to explain what an if..then..else statement is? > > Thanks. My opinion:

Re: Mutable defaults

2021-02-10 Thread Ross Wilson
On Thu, 11 Feb 2564 BE at 12:52 Grant Edwards wrote: > On 2021-02-11, J. Pic wrote: > > > I just meant removing the whole "default value mutating" story, not > > removing mutable variables. Really, I was wondering if there was a use > case > > where this actually turns to an advantage, > > I've

Re: Meaning of abbreviated terms

2018-05-12 Thread Ross Wilson
The "plist" abbreviation goes back to at least 1958 as it was used in the Lisp implementation [0].  And it may even predate Lisp.  I'm very sure that what actually went into a plist has often changed over the years, but the name persists. Lisp also used "association lists" [1] which were a key

Re: How to start gnuradio

2018-07-31 Thread Ross Wilson
I had a paddle through the manual at https://www.gnuradio.org/doc/doxygen/page_python_blocks.html and apparently some DSP operations use numpy. Ross On Wed, 1 Aug 2018 at 11:56 wrote: > > > After some research I found out that "sudo apt-get install python-numpy" > solved the problem. > > Can an

Client support automation and self service

2016-05-03 Thread musoke wilson
avoid re-inventing the wheel regards Wilson -- https://mail.python.org/mailman/listinfo/python-list

Re: can't add variables to instances of built-in classes

2016-07-17 Thread Wilson Ong
> Use this feature sparingly, only when you know that there are going to be > many (millions rather than thousands) of Test instances. Why use it sparingly? Is it for extensibility? What if I'm pretty sure that my class is going to have exactly these attributes only? -- https://mail.python.org

Re: Wind Rose Plotting in Python

2019-09-05 Thread Ross Wilson
On Thu, 5 Sep 2562 at 22:00 Madhavan Bomidi wrote: > Hi, > > Can someone help me on how to make the wind rose plotting (similar to the > figure 2 in the paper: > https://agupubs.onlinelibrary.wiley.com/doi/epdf/10.1029/2011JD016386) in > Python? > > The input file contains the data in 4 columns:

Re: vi and python

2005-01-09 Thread David Wilson
km wrote: Is there a way to display inbuilt function syntax as the user starts typing a function name with 'Vi' editor in console mode? Hi there, Unfortunately due to the highly dynamic nature of Python, this is difficult to do reliably. It is one benefit that static typing, to a certain exte

Re: Newbie question: Explain this behavior

2005-07-14 Thread Ross Wilson
On Thu, 14 Jul 2005 15:46:40 -0700, David Smith wrote: > Why does code snippet one work correctly, but not two. The only > difference is the placement of the "else". I know that indentation > affects execution, but how does it change behavior in the following > examples? Thank you. > > 1. for

Re: How to connect to UNIX machine from windows box

2005-08-08 Thread Ross Wilson
> I want to connect to unix machine using ssh to run some commands . > I have not tried this, but it might be useful. http://www.lag.net/paramiko/ HTH, Ross -- http://mail.python.org/mailman/listinfo/python-list

Re: list insertion

2005-08-24 Thread Ross Wilson
On Tue, 23 Aug 2005 20:58:11 -0700, Randy Bush wrote: > i am trying to insert into a singly linked list > > hold = self.next > self.next = DaClass(value) > self.next.next = hold > > but i suspect (from print statement insertions) that the result > is not as i expect. as the concept

Re: Python in C integration and WxPython

2005-09-15 Thread David Wilson
It sounds like your C program and Python script are running under different interpreters. Your C program almost certainly is using a Python version that comes with Cygwin, while the script is probably using a native win32 Python that has wxPython installed. Assuming this is true, then compiling yo

Re: MySQLdb UPDATE does nothing

2005-09-15 Thread David Wilson
>> sql="UPDATE product_attribute SET index_column = "+str(index)+" WHERE id = >> "+str(record2[0]) >> .. >> cursor.execute(sql) To allow the DB-API adaptor to correctly take care of value conversion and SQL escaping for you, this should be written as: cursor.execute("UPDATE product_attribute SET

Re: python optimization

2005-09-15 Thread David Wilson
For the most part, CPython performs few optimisations by itself. You may be interested in psyco, which performs several heavy optimisations on running Python code. http://psyco.sf.net/ Defining a function inside a loop in CPython will cause a new function object to be created each and every time

Re: Looking for system/network monitoring tool written in Python

2005-09-22 Thread David Wilson
See http://pynms.sourceforge.net/ Also see Google. :) David. -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling python scripts from C# programs

2005-09-22 Thread David Wilson
You should also be aware of IronPython, although it is not suitable for production use due to its reliance on a beta version of the .NET runtime. In some future time, IronPython will probably be the cleanest and simplest way to integrate Python with existing .NET code. http://www.ironpython.com/

ElementTree/DTD question

2005-03-15 Thread Greg Wilson
changed. Anyone know what I'm doing wrong? (Note: minidom loads it just fine...) Thanks, Greg Wilson [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: assymetry between a == b and a.__eq__(b)

2004-12-03 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: >I believe what Peter Otten was pointing out is that calling __eq__ is >not the same as using ==, presumably because the code for == checks the >types of the two objects and returns False if they're different before >the __eq

Re: assymetry between a == b and a.__eq__(b)

2004-12-04 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: >Mel Wilson wrote: >> In article <[EMAIL PROTECTED]>, >> Steven Bethard <[EMAIL PROTECTED]> wrote: >> >>>I believe what Peter Otten was pointing out is that calling __e

Re: assymetry between a == b and a.__eq__(b)

2004-12-05 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Peter Otten <[EMAIL PROTECTED]> wrote: >Tim Peters wrote: > >> See the Python (language, not library) reference manual, section 3.3.8 >> ("Coercion rules"), bullet point starting with: >> >> Exception to the previous item: if the left operand is an >> instanc

Re: exec'ing functions

2004-12-09 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: >Jeff Shannon wrote: >> I was referring to functions which have an internal exec statement, not >> functions which are created entirely within an exec -- i.e., something >> like this: > >Thanks for the clarification. Here's

Re: newbie questions

2004-12-11 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, "houbahop" wrote: >Thank you everyone, but I still not understand why such a comon feature like >passing parameters byref that is present in most serious programming >languages is not possible in a clean way,here in python. > >I have the habit to never use globals a

Re: Suggestion for "syntax error": ++i, --i

2004-12-13 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Christian Ergh <[EMAIL PROTECTED]> wrote: >Ah, ok, i misunderstood you. Well, to mark it as a syntax error sounds >good, and at the Moment I would not know a case where this conflicts >with a implementation. Well, you can overload prefix `+` and `-` operators on

Re: exec'ing functions

2004-12-10 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Peter Otten <[EMAIL PROTECTED]> wrote: >Mel Wilson wrote: >> The thing is, that once you drop local-namespace >> optimization, the entire function gets slowed down, possibly >> by 40%: >It's not that bad as most of the ext

Re: change extensions

2005-04-04 Thread David Wilson
Bob Then wrote: > how can i change all files from one extension to another within a direcory? This should work: import os def change_exts(suffix, new_suffix, dir_name): for name in os.listdir(dir_name): if name.endswith(suffix): old_pathname = os.path.join(dir_name, name)

compound strip() string problem

2005-04-08 Thread Dylan Wilson
Hi, I'm new to python and i have a string problem. My problem is this -- >>>import time >>>time = time.asctime() >>>time 'Fri Apr 08 22:14:14 2005' >>>ti = time[0:13] >>>me = time[14:16] >>>time = ti + me >>>time 'Fri Apr 08 22

parsing RSS XML feed for item value

2013-11-19 Thread Larry Wilson
Wanting to parse out the the temperature value in the "http://rss.weather.com.au/nsw/newcastle"; === http://rss.weather.com.au/w.dtd";> Weather.com.au - Newcastle Weather http://www.weather.com.au/nsw/newcast

Re: parsing RSS XML feed for item value

2013-11-20 Thread Larry Wilson
>>> feed.entries[0].w_current {'temperature': u'20.3', 'dewpoint': u'18.6', 'windgusts': u'29.6', 'rain': u'0.6', 'humidity': u'90', 'pressure': u'0.0', 'windspeed': u'22.2', 'winddirection': u'SSW'} >>> in the above I get the subitem as shown. How do I extract the label, values pairs? -- http

Re: parsing RSS XML feed for item value

2013-11-20 Thread Larry Wilson
Thank you folks, now I know what I don't know and have a solution. -- https://mail.python.org/mailman/listinfo/python-list

Re: Best search algorithm to find condition within a range

2015-04-08 Thread Mel Wilson
On Tue, 07 Apr 2015 23:19:49 -0700, jonas.thornvall wrote: > And you have just created 429496729 unique symbols ;), in a pencil > stroke. No. You did that, when you said base 429496729. Representing the symbols in a computer is no problem, any Python long int can do that. To display the symb

Re: Best search algorithm to find condition within a range

2015-04-08 Thread Mel Wilson
On Wed, 08 Apr 2015 07:56:05 -0700, jonas.thornvall wrote: > There is no need for inventing a new set of characters representing > 32-bit numbers. You will not be able to learn them by heart anyway, > unless they build on a interpretation system binaries, decimals. See Jorge Luis Borges, _Funes t

Re: New to Python - block grouping (spaces)

2015-04-19 Thread Mel Wilson
On Sun, 19 Apr 2015 09:03:23 -0700, Rustom Mody wrote: > Now if Thomson and Ritchie (yeah thems the guys) could do it in 1970, > why cant we revamp this 45-year old archaic program=textfile system > today? Dunno. Why not? There's half of you right there. -- https://mail.python.org/mailman/lis

Re: New to Python - block grouping (spaces)

2015-04-19 Thread Mel Wilson
On Mon, 20 Apr 2015 03:53:08 +1000, Steven D'Aprano wrote: > On Mon, 20 Apr 2015 02:03 am, Rustom Mody wrote: >> Well evidently some people did but fortunately their managers did not >> interfere. > > You are assuming they had managers. University life isn't exactly the > same as corporate cultu

Re: How to properly apply OOP in the bouncing ball code

2015-05-08 Thread Mel Wilson
On Fri, 08 May 2015 08:40:34 -0700, Tommy C wrote: > I'm trying to apply OOP in this bouncing ball code in order to have > multiple balls bouncing around the screen. The objective of this code is > to create a method called settings, which controls all the settings for > the screen and the bouncin

Re: functions, optional parameters

2015-05-08 Thread Mel Wilson
On Sat, 09 May 2015 03:49:36 +1000, Chris Angelico wrote: > Yes, but can you *distinguish* them in terms of default argument versus > code object creation? How do you know that the function's code object > was created when compile() happened, rather than being created when the > function was defin

Re: Instead of deciding between Python or Lisp for a programming intro course...What about an intro course that uses *BOTH*? Good idea?

2015-05-10 Thread Mel Wilson
On Sun, 10 May 2015 13:43:03 -0700, Chris Seberino wrote: > Instead of learning only Scheme or only Python for a one semester intro > course, what about learning BOTH? Maybe that could somehow get the > benefits of both? > > I'm thinking that for the VERY beginning, Scheme is the fastest languag

Re: anomaly

2015-05-11 Thread Mel Wilson
On Sun, 10 May 2015 14:12:44 -0500, boB Stepp wrote: > I have to admit being surprised by this, too. I am just now studying on > how to write my own classes in Python, and have come to realize that > doing this is *possible*, but the *surprise* to me is why the language > design allowed this to ac

Re: anomaly

2015-05-11 Thread Mel Wilson
On Tue, 12 May 2015 02:35:23 +1000, Steven D'Aprano wrote: > On Mon, 11 May 2015 11:37 pm, Mel Wilson wrote: > >> On Sun, 10 May 2015 14:12:44 -0500, boB Stepp wrote: >> >>> I have to admit being surprised by this, too. I am just now studying >>> on h

Re: Use and usefulness of the as syntax

2011-11-12 Thread Mel Wilson
candide wrote: > First, could you confirm the following syntax > > import foo as f > > equivalent to > > import foo > f = foo > > > > Now, I was wondering about the usefulness in everyday programming of the > as syntax within an import statement. [ ... ] It gives you an out in a case like

Re: Close as Many Files/External resourcs as possible in the face of exceptions

2011-11-21 Thread Mel Wilson
GZ wrote: > Here is my situation. A parent object owns a list of files (or other > objects with a close() method). The close() method can sometimes fail > and raise an exception. When the parent object's close() method is > called, it needs to close down as many files it owns as possible, even >

Re: correct usage of a generator?

2011-11-28 Thread Mel Wilson
Tim wrote: > Hi, I need to generate a list of file names that increment, like this: > fname1 > fname2 > fname3 and so on. > > I don't know how many I'll need until runtime so I figure a generator is > called for. > > def fname_gen(stem): > i = 0 > while True: > i = i+1 >

Re: Making the case for "typed" lists/iterators in python

2011-12-16 Thread Mel Wilson
Chris Angelico wrote: > It's no more strange than the way some people omit the u from colour. :) Bonum Petronio Arbiteri, bonum mihi. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonification of the asterisk-based collection packing/unpacking syntax

2011-12-22 Thread Mel Wilson
Chris Angelico wrote: > On Fri, Dec 23, 2011 at 1:13 AM, Hans Mulder wrote: >> How about: >> >> >> ... >> >> >> More more readable! And it's a standard! > > Unfortunately it's not Pythonic, because indentation is insignificant. Easy-peasy: Mel. > We need to ado

Re: Early and late binding [was Re: what does 'a=b=c=[]' do]

2011-12-23 Thread Mel Wilson
Steven D'Aprano wrote: > On Fri, 23 Dec 2011 13:13:38 +, Neil Cerutti wrote: >> On 2011-12-23, Neil Cerutti wrote: >> ...you know, assuming it wouldn't break existing code. ;) > > It will. Python's default argument strategy has been in use for 20 years. > Some code will rely on it. I know min

Re: mutually exclusive arguments to a constructor

2011-12-30 Thread Mel Wilson
Adam Funk wrote: > (Warning: this question obviously reflects the fact that I am more > accustomed to using Java than Python.) > > Suppose I'm creating a class that represents a bearing or azimuth, > created either from a string of traditional bearing notation > ("N24d30mE") or from a number indi

Re: verify the return value of a function

2012-01-20 Thread Mel Wilson
Jean-Michel Pichavant wrote: > isinstance is fine, if you could find the source where it is > discouraged... Could be a consequence of some specific context. > However, checking types in OOP is in general a failure. Unitary tests > are possibly an exception. I think it's discouraged when people t

Re: Newline at EOF Removal

2006-01-09 Thread Dylan Wilson
Do you mean somthing like this? >>> f = open("file.txt") >>> w = open('outfile.txt', 'w') >>> for line in f.split('\n'): ...w.write(line) ... >>> w.close() >>> '\n' in open('/home/wandleg/outfile.txt').read() False -- http://mail.python.org/mailman/listinfo/python-list

Re: how to improve this simple block of code

2006-01-11 Thread Mel Wilson
py wrote: > Say I have... > x = "132.00" > > but I'd like to display it to be "132" ...dropping the trailing > zeros... print '%g' % (float(x),) might work. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Warning when new attributes are added to classes at run time

2006-07-19 Thread Matthew Wilson
I sometimes inadvertently create a new attribute on an object rather update a value bound to an existing attribute. For example: In [5]: class some_class(object): ...: def __init__(self, a=None): ...: self.a = a ...: In [6]: c = some_class(a=1) In

Re: Warning when new attributes are added to classes at run time

2006-07-20 Thread Matthew Wilson
On Thu 20 Jul 2006 04:32:28 AM EDT, Bruno Desthuilliers wrote: >> self.__dict__[name] = value > Make it: > object.__setattr__(self, name, value) > > Your approach will lead to strange results if you mix it with properties > or other descriptors... Thanks! >> cl

Need advice on how to improve this function

2006-08-20 Thread Matthew Wilson
I wrote a function that converts a tuple of tuples into html. For example: In [9]: x Out[9]: ('html', ('head', ('title', 'this is the title!')), ('body', ('h1', 'this is the header!'), ('p', 'paragraph one is boring.'), ('p', 'but paragraph 2 ',

Re: using import * with GUIs?

2006-05-31 Thread Mel Wilson
John Salerno wrote: > Hi all. Quick question (but aren't they all?) :) > > Do you think it's a good idea to use the 'from import *' > statement when using a GUI module? It seems on wxPython's site, they > recommend using import wx nowadays, but I wonder if that advice is > followed. Also, I'm

Re: carshing the interpreter in two lines

2006-06-03 Thread Mel Wilson
sam wrote: > tomer: > > It is my opinion that you would loose performance if the Python > interpreter had the additional task of verifying byte code. It might be > more appropriate to have a preprocessor that did the verifying as it > compiled the byte code. Possibly. A good book on the topic is

Re: carshing the interpreter in two lines

2006-06-04 Thread Mel Wilson
ing with an idea for "oracles", where a computation would be allowed to call out sometimes to a non-computational process to obtain some required result. Used maybe by interactive debugging programs. Cheers,Mel. > Mel Wilson wrote: [ ... ] >>Douglas Hofstad

Re: Proposed new PEP: print to expand generators

2006-06-04 Thread Mel Wilson
Terry Reedy wrote: > "James J. Besemer" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> I propose that we extend the semantics of "print" such that if the object >> to >> be printed is a generator then print would iterate over the resulting >> sequence of sub-objects and recursiv

random.jumpahead: How to jump ahead exactly N steps?

2006-06-21 Thread Matthew Wilson
The random.jumpahead documentation says this: Changed in version 2.3: Instead of jumping to a specific state, n steps ahead, jumpahead(n) jumps to another state likely to be separated by many steps.. I really want a way to get to the Nth value in a random series started with a particu

I wish I could add docstrings to vars.

2006-09-12 Thread Matthew Wilson
I build a lot of elaborate dictionaries in my interpreter, and then I forget exactly how they work. It would be really nice to be able to add notes to the dictionary. Is there some way to do this now? Matt -- A better way of running series of SAS programs: http://overlook.homelinux.net/wilso

Code to add docstrings to classes

2006-09-12 Thread Matthew Wilson
On Tue 12 Sep 2006 10:06:27 AM EDT, Neil Cerutti wrote: > Writing a thin wrapper around the dictionary might be beneficial, > and would also furnish a place for the docstrings. I wrote a function that hopefully does just that. I'm not very savvy at doing this class-factory stuff, so any advice w

eval(repr(object)) hardly ever works

2006-09-13 Thread Matthew Wilson
I understand that idea of an object's __repr__ method is to return a string representation that can then be eval()'d back to life, but it seems to me that it doesn't always work. For example it doesn't work for instances of the object class: In [478]: eval(repr(object())) --

Re: eval(repr(object)) hardly ever works

2006-09-13 Thread Matthew Wilson
On Wed 13 Sep 2006 10:38:03 AM EDT, Steve Holden wrote: > That's intentional. Would you have it return the code of all the methods > when you take the repr() of a class? I don't think that would be required. Couldn't you return a string with a call to the constructor inside? That's what sets.Se

How to iterate through a sequence, grabbing subsequences?

2006-09-29 Thread Matthew Wilson
I wrote a function that I suspect may already exist as a python builtin, but I can't find it: def chunkify(s, chunksize): "Yield sequence s in chunks of size chunksize." for i in range(0, len(s), chunksize): yield s[i:i+chunksize] I wrote this because I need to take a string of a

How to query a function and get a list of expected parameters?

2006-09-29 Thread Matthew Wilson
I'm writing a function that accepts a function as an argument, and I want to know to all the parameters that this function expects. How can I find this out in my program, not by reading the source? For example, I would want to know for the function below that I have to pass in two things: def f(

How to coerce a list of vars into a new type?

2006-10-02 Thread Matthew Wilson
I want to verify that three parameters can all be converted into integers, but I don't want to modify the parameters themselves. This seems to work: def f(a, b, c): a, b, c = [int(x) for x in (a, b, c)] Originally, I had a bunch of assert isinstance(a, int) statements at the top of

How can I make a class that can be converted into an int?

2006-10-02 Thread Matthew Wilson
What are the internal methods that I need to define on any class so that this code can work? c = C("three") i = int(c) # i is 3 I can handle the part of mapping "three" to 3, but I don't know what internal method is called when int(c) happens. For string conversion, I just define the __str__ me

  1   2   3   >