Re: Language mavens: Is there a programming with "if then else ENDIF" syntax?

2009-11-18 Thread Chris Rebert
On Wed, Nov 18, 2009 at 1:15 AM, Steve Howell wrote: > On the topic of "switch" statements and even-more-concise-then-we-have- > already if/elif/else/end constructs, I have to say that Python does > occasionally force you to write code like the code below.  Maybe > "force" is too strong a word, bu

Re: break LABEL vs. exceptions + PROPOSAL

2009-11-18 Thread Chris Rebert
On Wed, Nov 18, 2009 at 4:05 AM, Lo'oris wrote: > I've found this email, back from 10 years ago: > http://mail.python.org/pipermail/python-list/1999-September/009983.html > > I guess it went unnoticed, because that proposal looks really > intresting. > > • break labels have been refused into pytho

Re: Minimally intrusive XML editing using Python

2009-11-18 Thread Chris Rebert
On Wed, Nov 18, 2009 at 4:55 AM, Thomas Lotze wrote: > I wonder what Python XML library is best for writing a program that makes > small modifications to an XML file in a minimally intrusive way. By that I > mean that information the program doesn't recognize is kept, as are > comments and whitesp

Re: DOM related question and problem

2009-11-18 Thread Chris Rebert
On Wed, Nov 18, 2009 at 10:04 AM, elca wrote: > Hello, > these day im making python script related with DOM. > > problem is these day many website structure is very complicate . > > what is best method to check DOM structure and path.. > > i mean...following is some example. > > what is best metho

Re: DeprecationWarning on md5

2009-11-18 Thread Chris Rebert
On Wed, Nov 18, 2009 at 5:23 PM, Zeynel wrote: > Hello, > > I am a newbie both in Scrapy and Python. When I create a project with > Scrapy I get these errors: > > C:\Python26\lib\site-packages\twisted\python\filepath.py:12: > DeprecationWarning: the sha module is deprecated; use the hashlib > modu

Re: combinatorics via __future__ generators

2009-11-18 Thread Chris Rebert
On Wed, Nov 18, 2009 at 4:58 PM, Phlip wrote: > Python: > > I have a quaint combinatorics problem. Before I solve it, or find a > solution among "generators", I thought y'all might like to show off > any solutions. > > Given an array like this... > >  [0, 4, 3] > > Produce an array like this: > >

Re: What is the naming convention for accessor of a 'private' variable?

2009-11-18 Thread Chris Rebert
On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu wrote: > http://www.python.org/dev/peps/pep-0008/ > > The above webpage states the following naming convention. Such a > variable can be an internal variable in a class. I'm wondering what is > the naming convention for the method that access such variable.

Re: Invitation to connect on LinkedIn

2009-11-18 Thread Chris Rebert
On Wed, Nov 18, 2009 at 6:16 PM, Jim Qiu wrote: > > LinkedIn > > Jim Qiu requested to add you as a connection on LinkedIn: > > Jaime, > > I'd like to add you to my professional network on LinkedIn. > > - Jim > > > Accept View invitation from Jim Qiu > > > WHY MIGHT CONNECTING WITH JIM QIU BE A GOO

Re: convert a string to a regex?

2009-11-18 Thread Chris Rebert
On Wed, Nov 18, 2009 at 6:51 PM, Peng Yu wrote: > There are many special characters listed on > http://docs.python.org/library/re.html > > I'm wondering if there is a convenient function that can readily > convert a string with the special characters to its corresponding > regex. For example, > >

Re: What is the naming convention for accessor of a 'private' variable?

2009-11-18 Thread Chris Rebert
On Wed, Nov 18, 2009 at 7:04 PM, Peng Yu wrote: > On Wed, Nov 18, 2009 at 8:47 PM, Chris Rebert wrote: >> On Wed, Nov 18, 2009 at 6:27 PM, Peng Yu wrote: >>> http://www.python.org/dev/peps/pep-0008/ >>> >>> The above webpage states the following naming conve

Re: crontab problem

2009-11-21 Thread Chris Rebert
On Sat, Nov 21, 2009 at 5:47 AM, Victor Subervi wrote: > Hi; > I have the following in crontab -eu root: > @daily /usr/local/bin/mysql-backup-daily.sh > @weekly /usr/local/bin/mysql-backup-weekly.sh > @monthly /usr/local/bin/mysql-backup-monthly.sh > > [r...@13gems globalsolutionsgroup.vi]# ls /us

Re: Sorting: too different times. Why?

2009-11-22 Thread Chris Rebert
On Sun, Nov 22, 2009 at 2:56 AM, n00m wrote: > I was expecting the 1st method would be *slower* than the 2nd one :-) > Or at least equal... Just random ("intuitive") expectations The second method repeatedly looks up left_item.__class__.__cmp__ (i.e. Vector.__cmp__) when doing the necessary compa

Re: Why Python allows comparison of a callable and a number?

2009-11-22 Thread Chris Rebert
On Sun, Nov 22, 2009 at 4:03 AM, 一首诗 wrote: > I used python to write an assignment last week, here is a code snippet > > # > > def departTime(): >    ''' >    Calculate the time to depart a packet. >    ''' >    if(random.random < 0.8): >        t = random.expovaria

Re: attributes, properties, and accessors -- philosophy

2009-11-23 Thread Chris Rebert
On Mon, Nov 23, 2009 at 10:52 AM, Ethan Furman wrote: > The problem I have with properties is my typing.  I'll end up assigning to > an attribute, but get the spelling slightly wrong (capitalized, or missing > an underscore -- non-obvious things when bug-hunting), so now I have an > extra attribut

Re: pointless musings on performance

2009-11-24 Thread Chris Rebert
On Tue, Nov 24, 2009 at 4:31 AM, Rob Williscroft wrote: > mk wrote in news:mailman.915.1259064240.2873.python-l...@python.org in > comp.lang.python: > >> >> def pythonic(): > >> def unpythonic(): > > >> Decidedly counterintuitive: are there special optimizations for "if >> nonevar:" type of statem

Re: attributes, properties, and accessors -- philosophy

2009-11-24 Thread Chris Rebert
On Tue, Nov 24, 2009 at 9:39 AM, Ethan Furman wrote: > Bruno Desthuilliers wrote: >> Ethan Furman a écrit : >>> The problem I have with properties is my typing.  I'll end up assigning >>> to an attribute, but get the spelling slightly wrong (capitalized, or >>> missing an underscore -- non-obvious

Re: get line number and filename in a source file

2009-11-24 Thread Chris Rebert
On Tue, Nov 24, 2009 at 9:47 PM, Peng Yu wrote: > __LINE__ __FILE__ in C++ can give the current line number and > filename. Is there a similar thing in python that can give me the > current line number and filename? import inspect filename, linenum, funcname = inspect.getframeinfo(inspect.current

Re: Can "self" crush itself?

2009-11-25 Thread Chris Rebert
On Wed, Nov 25, 2009 at 1:46 AM, n00m wrote: > Then how can we destroy the 3rd instance, > right after its creation and from inside > class Moo code? Why would you want to do that in the first place? It's strange to say the least. If you want to prevent an instance being created in the first plac

Re: Feature request: String-inferred names

2009-11-25 Thread Chris Rebert
On Wed, Nov 25, 2009 at 6:35 PM, The Music Guy wrote: > Hello all, > > I just posted to my blog about a feature that I'd like to see added to > Python. Before I go through the trouble of learning how to write a PEP or > how to extend the Python interpreter, I want to know what people in the > comm

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Chris Rebert
On Sun, Nov 29, 2009 at 4:39 PM, Esmail wrote: > Ok, this is somewhat unexpected: > > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > -3**2 > -9 > x = -3 > x**2 > 9 > > I

Re: Noobie python shell question

2009-11-29 Thread Chris Rebert
On Sun, Nov 29, 2009 at 7:53 PM, Tim Chase wrote: > (as an aside, is there a way to get a local/global variable from a string > like one can fetch a variable from a class/object with getattr()?  Something > like getattr(magic_namespace_here, "hello") used in the above context?  I > know it can be

Re: Unpacking Tuples

2009-11-30 Thread Chris Rebert
On Mon, Nov 30, 2009 at 12:17 AM, Joel Davis wrote: > I hate to post such a simple Q and A here, but I seriously can't find > it anywhere. Python (unsure of starting with which version) enables > the remainder of the tuple to be placed in a "catch-all", for example: > > >>> myTuple = (1,2,3,4) >>>

Re: python and vc numbers

2009-11-30 Thread Chris Rebert
On Mon, Nov 30, 2009 at 2:02 AM, Daniel Dalton wrote: > > On Mon, Nov 30, 2009 at 07:20:59PM +1100, Daniel Dalton wrote: >> That did the trick, thanks, after I append >> [-2] > > Further testing under screen says otherwise -- it seems to give me the > tty number, not the virtual console number. Is

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread Chris Rebert
> On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing > wrote: >> Esmail wrote: >> >>> Wow .. never heard of Concatenative_languages languages before or the >>> distinction you make. Your distinction explains the behavior, but I >>> find it somewhat counter-intuitive. >> >> You shouldn't find it any mo

Re: Function parameters list

2009-12-01 Thread Chris Rebert
On Tue, Dec 1, 2009 at 12:15 AM, Nadav Chernin wrote: > Hello, all > > I need to know dynamically parameters of any function (prototype). > > Is there some way to get it? The `inspect` module: http://docs.python.org/library/inspect.html#inspect.getargspec http://docs.python.org/library/inspect.h

Re: python bijection

2009-12-01 Thread Chris Rebert
On Tue, Dec 1, 2009 at 5:17 PM, Aahz wrote: > In article > <85100df7-a8b0-47e9-a854-ba8a8a2f3...@r31g2000vbi.googlegroups.com>, > Joshua Bronson   wrote: >> >>I noticed the phonebook example in your ActiveState recipe and thought >>you might consider changing it to something like husbands to wive

Re: commands module for windows

2009-12-01 Thread Chris Rebert
On Tue, Dec 1, 2009 at 10:05 PM, M Kumar wrote: > Is there any python module for windows which is equivalent to commands > module in linux? `subprocess` should work: http://docs.python.org/library/subprocess.html The `commands` docs even say: "The subprocess module provides more powerful facilit

Re: commands module for windows

2009-12-01 Thread Chris Rebert
> On Wed, Dec 2, 2009 at 11:42 AM, Chris Rebert wrote: >> On Tue, Dec 1, 2009 at 10:05 PM, M Kumar wrote: >> > Is there any python module for windows which is equivalent to commands >> > module in linux? >> >> `subprocess` should work: http://docs.pytho

Re: Don't Understand This Error

2009-12-02 Thread Chris Rebert
On Wed, Dec 2, 2009 at 2:33 AM, Victor Subervi wrote: > I get the following error: > >  /var/www/html/angrynates.com/cart/chooseOptions.py >     8 from login import login >     9 import string >    10 import options >    11 from particulars import optionsTables, addStore >    12 > options undefine

Re: prolog with python

2009-12-02 Thread Chris Rebert
On Wed, Dec 2, 2009 at 6:47 PM, William Heath wrote: > Hi All, > > I have the following prolog program that I would really like to be able to > run in python in some elegant way: >From googling: http://pyke.sourceforge.net/ http://code.activestate.com/recipes/303057/ Cheers, Chris -- http://blo

Re: Declaring a class level nested class?

2009-12-02 Thread Chris Rebert
On Wed, Dec 2, 2009 at 8:55 PM, cmckenzie wrote: > Hi. > > I'm new to Python, but I've managed to make some nice progress up to > this point. After some code refactoring, I ran into a class design > problem and I was wondering what the experts thought. It goes > something like this: > > class modu

Re: Help with function prototype

2009-12-03 Thread Chris Rebert
On Thu, Dec 3, 2009 at 3:02 AM, Nadav Chernin wrote: > Hi, all > > In past I asked about module – inspect, that can’t to get me prototype of > C-implemented functions ( usually all built-in functions ). > > But, still I see that all Python Editors ( IDLE for example ) can to show > prototype of bu

Re: Directly converting Python to C using the C API

2009-12-03 Thread Chris Rebert
On Thu, Dec 3, 2009 at 6:09 PM, Emmanuel Bengio wrote: > I'm fairly new to the python world, and I often heard critics about it's > speed, and also about it's "non-compilability". > Then I thought, there is a complete C API that manages Python itself. > Would it be feasible to transform pure Pytho

Re: read from standard input

2009-12-04 Thread Chris Rebert
On Fri, Dec 4, 2009 at 9:37 PM, Siva B wrote: > Hi all, > > I wrote a program to read some data through standard input and write in a > file. > the following code works fine in linux. > but its giving ArgumentError in windows. There's no such error in Python; you're thinking of Ruby. Unless you g

Re: read from standard input

2009-12-04 Thread Chris Rebert
> On Sat, Dec 5, 2009 at 11:54 AM, Chris Rebert wrote: >> >> On Fri, Dec 4, 2009 at 9:37 PM, Siva B wrote: >> > Hi all, >> > >> > I wrote a program to read some data through standard input and write in >> > a >> > file. >

Re: How to create a docstring for a module?

2009-12-06 Thread Chris Rebert
On Sun, Dec 6, 2009 at 12:34 PM, Dr. Phillip M. Feldman wrote: > OK.  I was able to reproduce the problem.  My difficulty was that the command > that I issued initially was "from xyz import *" rather than just "import > xyz".  If I say "import xyz", then the docstring is defined; if I say "from >

Re: dict.fromkeys strange behavior

2009-12-07 Thread Chris Rebert
On Mon, Dec 7, 2009 at 12:42 AM, Tsviki Hirsh wrote: > Dear list, > I'm trying to create a dictionary from set of keys and values using > dict.fromkeys > When I type: dict.fromkeys('a',50) > the output is: > {'a': 50} > This is fine, but when I try to set the same value to a different name key

Re: hola

2009-12-07 Thread Chris Rebert
2009/12/6 franki fuentes cueto : > hola soy un pequeño programador y quiesiera pedirles ayuda para programar en > python, no se si me podrian mandar ejemplos para poder empezar, y como > terminarlo para que se ejecute, me entiendes , aver sime ayudan gracias Esta lista de discusión es en Inglés.

Re: switch

2009-12-08 Thread Chris Rebert
On Tue, Dec 8, 2009 at 5:53 PM, hong zhang wrote: > Python does not have switch statement. Any other option does similar work? Yes, a dictionary with functions as values: http://simonwillison.net/2004/May/7/switch/ Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/list

Re: Generating diagrams from PostgreSQL with Python (Re: postgresql_autodoc in Python?)

2009-12-10 Thread Chris Rebert
On Thu, Dec 10, 2009 at 3:48 AM, Diez B. Roggisch wrote: > Wolfgang Keller wrote: > >> Hello, >> >> I will re-precise my question: >> >> Has anyone ever implemented a script in Python that generates >> documentation (especially diagrams, in a format such as e.g. Dia, Inkscape >> SVG or Tikz) for a

Re: read text file byte by byte

2009-12-13 Thread Chris Rebert
On Sun, Dec 13, 2009 at 12:20 AM, Michel Claveau - MVP wrote: > Hi! > >> If it's a binary file... > > OK, but... what is a "binary" file? http://en.wikipedia.org/wiki/Binary_file Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: unable to read the __main__ namespace

2009-12-13 Thread Chris Rebert
On Sun, Dec 13, 2009 at 3:20 AM, vsoler wrote: > I'm learning Python, and I am very fond of it. > > Using Python 2.6 > > I am able to list all the names in a class namespace: > > class abc: pass > abc.a1=7 > abc.a2='Text' > > print abc.__dict__.keys() That is more simply written as: print dir(ab

Re: insert unique data in a list

2009-12-13 Thread Chris Rebert
On Sun, Dec 13, 2009 at 5:19 PM, knifenomad wrote: > On 12월14일, 오전2시57분, mattia wrote: >> Il Sun, 13 Dec 2009 16:37:20 +, mattia ha scritto: >> > How can I insert non-duplicate data in a list? I mean, is there a >> > particular option in the creation of a list that permit me not to use >> > s

Re: dictionary with tuple keys

2009-12-14 Thread Chris Rebert
On Mon, Dec 14, 2009 at 9:49 PM, Brandon Devine wrote: > Hi all, > > I am probably not thinking straight anymore about this problem.  I > have a dictionary with tuple keys in the format (a, b, A, B) and float > values.  I want to collect all the keys with identical (a, b...), > disregarding whatev

Re: csv reader

2009-12-15 Thread Chris Rebert
On Tue, Dec 15, 2009 at 1:24 PM, Emmanuel wrote: > I have a problem with csv.reader from the library csv. I'm not able to > import accentuated caracters. For example, I'm trying to import a > simple file containing a single word "equação" using the following > code: > > import csv > arquivoCSV='te

Re: Odd json encoding erro

2009-12-15 Thread Chris Rebert
On Tue, Dec 15, 2009 at 2:03 PM, Wells wrote: > I get this exception when decoding a certain JSON string: > > 'ascii' codec can't encode character u'\u2019' in position 8: ordinal > not in range(128) > > The JSON data in question: > > http://mlb.com/lookup/json/named.player_info.bam?sport_code=%27

Re: Odd json encoding erro

2009-12-15 Thread Chris Rebert
On Tue, Dec 15, 2009 at 3:04 PM, Wells wrote: > Sorry- more detail- the actual problem is an exception thrown when > running str() on the value, like so: > a = u'St. Paul\u2019s School For Boys (MN) HS' print str(a) > Traceback (most recent call last): >  File "", line 1, in > UnicodeEn

Re: strptime not strict enough

2009-12-15 Thread Chris Rebert
On Tue, Dec 15, 2009 at 9:47 PM, Tim Roberts wrote: > Tobias Weber wrote: >> >>despite the directives for leading zero stime.strptime('09121', >>'%y%m%d') returns the first of December. Shouldn't it raise ValueError? > > Python merely calls the strptime function in your C run-time library.  If >

Re: Storing a Value in a Cookie

2009-12-16 Thread Chris Rebert
On Wed, Dec 16, 2009 at 1:13 AM, Victor Subervi wrote: > Hi; > From what I've studied and gotten working about cookies, it seems one can > store only a certain few pieces of information--expiration, path, comment, > domain, max-age, version and last visit--but how is it useful if one can't > also

Re: Can't Iterate

2009-12-16 Thread Chris Rebert
On Wed, Dec 16, 2009 at 11:26 PM, Victor Subervi wrote: > Hi; > I have this line of code: > > for store in ourStores(): > > which is called from the statement: > > from particulars import ourStores > > The latter file has the following: > > def ourStores(): >   return ['prescriptions', 'products']

Re: py itertools?

2009-12-19 Thread Chris Rebert
On Sat, Dec 19, 2009 at 2:54 AM, mattia wrote: > Hi all, I need to create the permutation of two strings but without > repeat the values, e.g. 'ab' for me is equal to 'ba'. Here is my > solution, but maybe the python library provides something better: > def mcd(a, b): > ...     if b == 0: > .

Re: Class variables static by default?

2009-12-19 Thread Chris Rebert
On Sat, Dec 19, 2009 at 8:16 PM, Steven D'Aprano wrote: > On Sun, 20 Dec 2009 11:44:11 +1100, Lie Ryan wrote: > >> In python, 'class variable' is a variable that belongs to a class; not >> to the instance and is shared by all instance that belong to the class. > > Surely, since string variables ar

Re: Something Like os.environ['HTTP_REFERER']

2009-12-20 Thread Chris Rebert
On Sun, Dec 20, 2009 at 2:06 AM, Victor Subervi wrote: > Hi; > I'm looking for something like os.environ['HTTP_REFERER'] but for python > scripts. That is, if I have a script that is imported by another script, how > can I have the script that is being imported determine which script imported > it

Re: Mails & encoding

2009-12-20 Thread Chris Rebert
On Sun, Dec 20, 2009 at 2:46 AM, Lord Eldritch wrote: > - When I have: > > ttext='áá' > > I get a warning sendinme to this page > > http://www.python.org/peps/pep-0263.html > > Should I understand that PEP has been already implemented and follow it? Yes. Cheers, Chris -- http://blog.reb

Re: Import Problem

2009-12-20 Thread Chris Rebert
On Sun, Dec 20, 2009 at 3:34 AM, Victor Subervi wrote: > But I get this error: > > /var/www/html/angrynates.com/cart/createTables2.py >   263 >   264 ''' >   265 >   266 createTables2() >   267 > createTables2 = >  /var/www/html/angrynates.com/cart/createTables2.py in createTables2() >   105   

Re: py itertools?

2009-12-20 Thread Chris Rebert
> On Dec 19, 12:48 pm, Chris Rebert wrote: >> On Sat, Dec 19, 2009 at 2:54 AM, mattia wrote: >> > Hi all, I need to create the permutation of two strings but without >> > repeat the values, e.g. 'ab' for me is equal to 'ba'. Here is my >&

Re: Create attribute from string

2009-12-30 Thread Chris Rebert
On Wed, Dec 30, 2009 at 9:22 PM, AON LAZIO wrote: > Hi, >     I would like to know how we could create attribute from string > > say I want to assign value 0.05 to an object attribute > > I like to input "SIGNIFICANT" and 0.05 and get > object.SIGFICANT equals to 0.05 setattr(obj, "SIGNIFICANT",

Re: Exception as the primary error handling mechanism?

2009-12-31 Thread Chris Rebert
On Thu, Dec 31, 2009 at 8:47 PM, Peng Yu wrote: > I observe that python library primarily use exception for error > handling rather than use error code. > > In the article API Design Matters by Michi Henning > > Communications of the ACM > Vol. 52 No. 5, Pages 46-56 > 10.1145/1506409.1506424 > htt

Re: Significant whitespace

2010-01-01 Thread Chris Rebert
On Fri, Jan 1, 2010 at 2:02 PM, Dan Stromberg wrote: > I put together a page about significant whitespace (and the lack thereof). > > You're invited to check it out: > > http://stromberg.dnsalias.org/~dstromberg/significant-whitespace.html For those of us who weren't around during the heyday of F

Re: Significant whitespace

2010-01-01 Thread Chris Rebert
On Fri, Jan 1, 2010 at 9:56 PM, Donn wrote: > On Saturday 02 January 2010 00:02:36 Dan Stromberg wrote: >> I put together a page about significant whitespace (and the lack thereof). > The only thing about Python's style that worries me is that it can't be > compressed like javascript can*, and per

Re: TypeError: can only concatenate list (not "tuple") to list

2010-01-04 Thread Chris Rebert
On Sun, Jan 3, 2010 at 11:51 PM, Gabriel Genellina wrote: > This > py> [1,2,3] + (4,5) > Traceback (most recent call last): >  File "", line 1, in > TypeError: can only concatenate list (not "tuple") to list Given that tuples are sometimes used as a poor man's object (i.e. collection of data fie

Re: Can't Add Variable

2010-01-04 Thread Chris Rebert
On Mon, Jan 4, 2010 at 9:28 AM, Victor Subervi wrote: > Hi; > I have this code snippet: > >     sql '''create table if not exists %sCustomerData ( You're missing an equal sign there to start with (i.e. sql = '''). Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listi

Re: How to validate the __init__ parameters

2010-01-04 Thread Chris Rebert
On Mon, Jan 4, 2010 at 10:17 AM, Albert van der Horst wrote: > This triggers a question: I can see the traceback, but it > would be much more valuable, if I could see the arguments > passed to the functions. Is there a tool? print(locals()) #this actually gives the bindings for the entire local

Re: Newbie help- Can multiple instances with multiple names automatically created.

2010-01-04 Thread Chris Rebert
On Mon, Jan 4, 2010 at 1:32 PM, Shawn Milochik wrote: > You could put them in a dictionary with the key being the name, instead of a > list. To illustrate that for the OP: name2drink = {} for booze in liquors: for juice in juices: name = juice +" "+booze # or however you're naming t

Re: Exception as the primary error handling mechanism?

2010-01-05 Thread Chris Rebert
On Tue, Jan 5, 2010 at 1:07 AM, r0g wrote: > Lie Ryan wrote: >> I have been looking at Haskell recently and the way the pure functional >> language handled exceptions and I/O gives me a new distinct "insight" >> that exceptions can be thought of as a special return value that is >> implicitly wra

Re: Exception as the primary error handling mechanism?

2010-01-05 Thread Chris Rebert
On Tue, Jan 5, 2010 at 3:51 PM, Phlip wrote: > Peng Yu wrote: >> Otherwise, could some python expert explain to me why exception is >> widely used for error handling in python? Is it because the efficiency >> is not the primary goal of python? > > It's not about efficiency, it's about making assum

Re: Exception as the primary error handling mechanism?

2010-01-05 Thread Chris Rebert
On Tue, Jan 5, 2010 at 5:45 PM, Phlip wrote: > On Jan 5, 5:01 pm, Chris Rebert wrote: >> > Why can't int('nonnumeric') return None? >> >> Errors should never pass silently. > > You are saying I, as the programmer, cannot decide what is an error > a

Re: buffer interface problem

2010-01-07 Thread Chris Rebert
On Thu, Jan 7, 2010 at 12:19 AM, Andrew Gillanders wrote: > I have run into a problem running a Python script that is part of the > TerraGear suite for building scenery for FlightGear. I am using Mac OS X > 10.4, running Python (version 3.0.1) in a Unix terminal. > > The purpose of the script is t

Re: buffer interface problem

2010-01-07 Thread Chris Rebert
On Thu, Jan 7, 2010 at 4:47 AM, Andrew Gillanders wrote: > On 07/01/2010, at 7:13 PM, Chris Rebert wrote: >> On Thu, Jan 7, 2010 at 12:19 AM, Andrew Gillanders >> wrote: >>> >>> I have run into a problem running a Python script that is part of the >>>

Re: Recommended "new" way for config files

2010-01-07 Thread Chris Rebert
On Thu, Jan 7, 2010 at 10:19 AM, Peter wrote: >> The .ini file is the simpliest solution, at least from the user point of >> view, no need to learn any python syntax. > > I am speaking from the point of view of a python programmer, and I find the > .ini restrictions not necessarily simple, for ex

Re: Standardized interpreter speed evaluation tool

2010-01-08 Thread Chris Rebert
On Fri, Jan 8, 2010 at 2:25 AM, alexru wrote: > Is there any standardized interpreter speed evaluation tool? Say I > made few changes in interpreter code and want to know if those changes > made python any better, which test should I use? Although apparently undocumented, test.pystone is some sor

Re: integer and string compare, is that correct?

2010-01-10 Thread Chris Rebert
On Sun, Jan 10, 2010 at 4:26 AM, Hellmut Weber wrote: > Hi, > being a causal python user (who likes the language quite a lot) > it took me a while to realize the following: > > > l...@sylvester py_count $ python > Python 2.6.3 (r263:75183, Oct 26 2009, 12:34:23) > [GCC 4.4.1] on linux2 > Type "hel

Re: integer and string compare, is that correct?

2010-01-10 Thread Chris Rebert
On Sun, Jan 10, 2010 at 4:46 AM, Chris Rebert wrote: > The behavior of disparate types being comparable is deprecated and has > been removed in Python 3.0+; don't rely upon it. Clarification: Equality testing between disparate types still works unaltered however. By "comp

Re: how to duplicate array entries

2010-01-10 Thread Chris Rebert
On Sun, Jan 10, 2010 at 10:21 PM, Sebastian wrote: > Hi there, > > I have an array  x=[1,2,3] > > Is there an operator which I can use to get the result > [1,1,1,2,2,2,3,3,3] ? > > I tried x*3, which resulted in [1,2,3,1,2,3,1,2,3] > I also tried [[b,b,b] for b in x] which led to [[1,2,3],[1,2,3],

Re: how to duplicate array entries

2010-01-11 Thread Chris Rebert
On Mon, Jan 11, 2010 at 1:03 AM, Alf P. Steinbach wrote: > * Steven D'Aprano: >> >> On Mon, 11 Jan 2010 08:56:36 +0100, Alf P. Steinbach wrote: >> >>> * Paul Rudin: Sebastian writes: > I have an array  x=[1,2,3] In python such an object is called a "list". (

Re: how to duplicate array entries

2010-01-11 Thread Chris Rebert
On Mon, Jan 11, 2010 at 2:20 AM, Alf P. Steinbach wrote: > * Chris Rebert: >> On Mon, Jan 11, 2010 at 1:03 AM, Alf P. Steinbach wrote: >>> * Steven D'Aprano: >>>> On Mon, 11 Jan 2010 08:56:36 +0100, Alf P. Steinbach wrote: >>>>> * Paul Rudi

Re: os.system function

2010-01-11 Thread Chris Rebert
On Mon, Jan 11, 2010 at 12:43 PM, Zabin wrote: > Hey everyone! > > I am a new python programmer. I am trying to get the general file > functionality with options of save and save as working. These save > functions save a folder with multiple files. Upon using the os.system > copy function- if my d

Re: What is built-in method sub

2010-01-11 Thread Chris Rebert
On Mon, Jan 11, 2010 at 12:34 PM, Steven D'Aprano wrote: > If you can avoid regexes in favour of ordinary string methods, do so. In > general, something like: > > source.replace(target, new) > > will potentially be much faster than: > > regex = re.compile(target) > regex.sub(new, source) > # equi

Re: os.system function

2010-01-11 Thread Chris Rebert
On Mon, Jan 11, 2010 at 2:00 PM, Zabin wrote: > and just wondering- whats the drawback of using os.system() command Forgetting to properly escape your input. Simple example: filename = "foo bar.txt" os.system("rm "+filename) # uh-oh, we deleted 'foo' and 'bar.txt' instead The `subprocess` modu

Re: Python File Search

2010-01-11 Thread Chris Rebert
2010/1/11 Eknath Venkataramani : > correct.txt snippet: > 1 2 1 > 1 3 3 > 1 5 21 > 1 7 19 > > union_output_TEMP.txt snippet: > 1 2 1_NN > 1 3 3_VBZ > 1 3 5_VBZ > 1 3 2_VBZ > 1 5 21_VB > 1 7 19_NN > 1 9 14_VB > > I need to get the output in categorized.txt as: > NN={1 7 19, 1 2 1} > VBZ={1 3 3} > VB

Re: A question about Python versions

2010-01-12 Thread Chris Rebert
On Tue, Jan 12, 2010 at 10:09 PM, Gib Bogle wrote: > I am learning Python, and using PyQt to develop a GUI that will be used to > run a Fortran program on Windows, Linux and Mac OS X (I think Python is > great, btw). Without thinking about it I downloaded and started working with > a fairly recent

Re: Is python not good enough?

2010-01-13 Thread Chris Rebert
On Wed, Jan 13, 2010 at 1:06 AM, tanix wrote: > In article > <53ec94c0-dbdd-4901-a46b-d7faee121...@j14g2000yqm.googlegroups.com>, > "johan.san...@gmail.com" wrote: >>On Jan 13, 12:55=A0am, a...@pythoncraft.com (Aahz) wrote: >>> In article <1b42700d-139a-4653-8669-d4ee2fc48...@r5g2000yqb.googleg

Re: Sort list of dictionaries by key (case insensitive)

2010-01-13 Thread Chris Rebert
On Tue, Jan 12, 2010 at 11:45 PM, Nico Grubert wrote: > Hi there > > I have the following list 'mylist' that contains some dictionaries: > > mylist = [{'title':'the Fog', 'id':1}, >          {'title':'The Storm', 'id':2}, >          {'title':'the bible', 'id':3}, >          {'title':'The thunder',

Re: Sort list of dictionaries by key (case insensitive)

2010-01-13 Thread Chris Rebert
On Wed, Jan 13, 2010 at 2:41 AM, Chris Rebert wrote: > On Tue, Jan 12, 2010 at 11:45 PM, Nico Grubert wrote: >> Hi there >> >> I have the following list 'mylist' that contains some dictionaries: >> >> mylist = [{'title':'t

Re: Writing a string.ishex function

2010-01-14 Thread Chris Rebert
On Thu, Jan 14, 2010 at 8:14 AM, Iain King wrote: > On Jan 14, 3:52 pm, chandra wrote: >> Folks, >> >> I am new to Python and could not find a function along the lines of >> string.ishex in Python. There is however, a string.hexdigits constant >> in the string module. I thought I would enhance th

Re: Changing Lutz's mydir from Edition 2, Learning Python

2010-01-17 Thread Chris Rebert
On Sun, Jan 17, 2010 at 12:11 PM, W. eWatson wrote: > See Subject. The code is below with a few changes I made at the bottom by > inserting >    import string >    import numpy > >    module = raw_input("Enter module name: ") >    listing(module) As the error says, strings have no __name__ attrib

Re: IDLE Namespace Toolbox? Windows.

2010-01-17 Thread Chris Rebert
On Sun, Jan 17, 2010 at 2:22 PM, W. eWatson wrote: > This is a follow up to my post "Changing Lutz's mydir.  It would seem there > should be some sort of toolbox that allows one to do things like mydir, and > perhaps a lot more. Maybe something like it exists in Linux. Indeed; on *nix, when in th

Re: IDLE Namespace Toolbox? Windows.

2010-01-17 Thread Chris Rebert
On Sun, Jan 17, 2010 at 3:09 PM, Chris Rebert wrote: > On Sun, Jan 17, 2010 at 2:22 PM, W. eWatson wrote: >> This is a follow up to my post "Changing Lutz's mydir.  It would seem there >> should be some sort of toolbox that allows one to do things like mydir, and >

Re: IDLE Namespace Toolbox? Windows.

2010-01-17 Thread Chris Rebert
On Sun, Jan 17, 2010 at 4:11 PM, W. eWatson wrote: > John Bokma wrote: >> "W. eWatson" writes: >> >>> This is a follow up to my post "Changing Lutz's mydir.  It would seem >>> there should be some sort of toolbox that allows one to do things like >>> mydir, and perhaps a lot more. Maybe something

Re: Arrrrgh! Another module broken

2010-01-17 Thread Chris Rebert
On Sun, Jan 17, 2010 at 5:25 PM, Jive Dadson wrote: > I just found another module that broke when I went to 2.6.  Gnuplot. > Apparently one of its routines has a parameter named "with."  That used to > be okay, and now it's not. > > Once I get everything to work under 2.6, I am using it forever or

Re: Arrrrgh! Another module broken

2010-01-17 Thread Chris Rebert
On Sun, Jan 17, 2010 at 9:44 PM, Jive Dadson wrote: > Matt Newville wrote: >> >> On Jan 17, 7:25 pm, Jive Dadson wrote: >>> >>> I just found another module that broke when I went to 2.6. > Gnuplot. >>>  Apparently one of its routines has a parameter >>> named "with."  That used to be okay, and no

Re: conditional for-statement

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 1:36 PM, seb wrote: > On Aug 23, 6:18 pm, John Posner wrote: >> >> Hi, >> >> >> i was wondering if there is a syntax alike: >> >> >> for i in range(10) if i > 5: >> >>     print i >> >> > You can write >> >> > for i in filter(lambda i: i > 5, range(10)): >> >     print i >>

Re: What is the recommended library for xml parsing?

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 3:07 PM, Raimond Garcia wrote: > Is there a good build in library or should I use a third party one? xml.etree.ElementTree: http://docs.python.org/library/xml.etree.elementtree.html Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/pytho

Re: Newbie: list comprehension troubles..

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 4:27 PM, mm wrote: > Hi, I'm trying to replace this... > >        # this works but there must be a more pythonic way, right? >        tlist = [] >        for obj in self.objs: >            t = obj.intersect(ray) >            if (t != None): >                tlist.append((obj

Re: Newbie: list comprehension troubles..

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 5:09 PM, Ben Finney wrote: > Chris Rebert writes: > >> tlist = [pair for pair in ((obj, obj.intersect(ray)) for obj in >> self.objs) if pair[1] is not None] >> >> Should it be done? Probably not. [Compared to a ‘for’ suite with an >>

Re: os.popen output different from native shell output

2009-08-25 Thread Chris Rebert
On Tue, Aug 25, 2009 at 1:36 AM, nickname wrote: > Hi all, >       I am a relative newbie to python, I am using os.popen to run an > ls command. The output that I get using the read() function is > different in look and feel from when I run the ls command natively > from the shell (not via python).

Re: Division and right shift in python

2009-08-25 Thread Chris Rebert
On Tue, Aug 25, 2009 at 8:40 PM, Mark Tolonen wrote: > > "Cevahir Demirkiran" wrote in message > news:3f74e020908251648k7b391a09g78b155507b2f2...@mail.gmail.com... >> >> Hi, >> >> I would like to do a floor division by a power of 2 in python to make it >> faster than / (modular division in 2.x). >

Re: Move dictionary from instance to class level

2009-08-26 Thread Chris Rebert
On Wed, Aug 26, 2009 at 1:22 AM, Frank Millman wrote: > Hi all > > I have a class that uses a dictionary to map message numbers to methods. > > Here is a simple example - > >    class MyClass(object): >        def __init__(self): >            self.method_dict = {} >            self.method_dict[0] =

Re: Usefull python tutorial

2009-08-26 Thread Chris Rebert
On Wed, Aug 26, 2009 at 4:44 AM, gentlestone wrote: > Can somebody give me an advise where I can found a really good online > tutorial? All I found are useless. For example no tutorial I found > explains this piece of code: > >    someList = [element for element in otherList if element is not > Non

Re: codecs.open on Win32 -- converting my newlines to CR+LF

2009-08-26 Thread Chris Rebert
On Wed, Aug 26, 2009 at 11:06 PM, Chris Rebert wrote: > On Wed, Aug 26, 2009 at 8:40 PM, Ryan McGuire wrote: >> On Aug 26, 11:04 pm, Philip Semanchuk wrote: >>> Try using "rb" instead of "r" for the mode in the call to open(). >>> >>> HTH &

<    1   2   3   4   5   6   7   8   9   10   >