Re: The rap against "while True:" loops

2009-10-10 Thread Stephen Hansen
> > I use "while True"-loops often, and intend to continue doing this > "while True", but I'm curious to know: how widespread is the > injunction against such loops? The injunction is nonexistent (save perhaps in people coming from another language who insist that Python just /must/ have a "prope

Re: Zip Question

2009-10-09 Thread Stephen Hansen
On Fri, Oct 9, 2009 at 11:04 AM, Victor Subervi wrote: > So, because the results in sstp were duplicates ( ['prescriptions', > 'prescriptions'] ) it only returned one result in the dict(zip()) statement. > Weird. Bug or feature? ;) > Thanks, > V Feature. zip() returned two results, but dictiona

Re: Zip Question

2009-10-09 Thread Stephen Hansen
Changing the line: > subtypes = dict(zip(sstp, sst)) > to: > subtypes = dict(zip(sst, sstp)) > as I believe Stephen misread it to be causes the zip operation to return: > [('doctors', 'prescriptions'), ('patient', 'prescriptions')] > and thus the dict will contain: > {'patient': 'prescriptions', '

Re: Zip Question

2009-10-09 Thread Stephen Hansen
On Fri, Oct 9, 2009 at 10:02 AM, Victor Subervi wrote: > Hi; > I have the following code: > > elif table[0] == 't': # This is a store subtype table > bits = string.split(table, '0') > sst.append(bits[2]) > sstp.append(bits[1]) > subtypes = dict(zip(sstp, sst)) > > When I pr

Re: Nested Menus

2009-10-09 Thread Stephen Hansen
On Fri, Oct 9, 2009 at 7:13 AM, Victor Subervi wrote: > Hmm. I didn't bother to look at the "comparison post". The indenting looks > right to me. I reread my post and I believe my question is straight-forward. > The crux of the issue is my sentence at the bottom. I believe that details > what my o

Re: Rules regarding a post about a commercial product

2009-10-07 Thread Stephen Hansen
On Wed, Oct 7, 2009 at 1:59 AM, Ken Elkabany wrote: > Hello, > > I am hoping to get feedback for a new, commercial platform that > targets the python programming language and its users. The product is > currently in a closed-beta and will be free for at least a couple > months. After reviewing th

Re: del an imported Class at EOF... why?

2009-10-07 Thread Stephen Hansen
On Wed, Oct 7, 2009 at 2:31 AM, Ryan wrote: > Next time python comes across > > from PyQt4 import QtGui > > it would have to re-import the class, which seems a waste of cycles > that could accumulate. Python only imports modules once. The next time Python comes across that, it looks in sys.modu

Re: mktime, how to handle dates before 01-01-1970 ?

2009-10-06 Thread Stephen Hansen
> > I really can't quite fathom why you'd want to use something so low-level as >> time.mktime... or just about anything in the time module :) >> > I didn't know anything better, > but (forgive me if I'm wrong) I find mx almost as low-level : > >>> mx.DateTime.strptime('01-01-53',"%d-%m-%y") > > w

Re: mktime, how to handle dates before 01-01-1970 ?

2009-10-05 Thread Stephen Hansen
On Mon, Oct 5, 2009 at 4:54 PM, Stef Mientki wrote: > hello, > > I want to handle datetime vars in a general way, so I use the default > time-format, > so I can use the standard cinversion procedures. > Personally, I love mx.DateTime; its the best date/time library around. But, Python's built in

Re: creating class objects inside methods

2009-10-04 Thread Stephen Hansen
> > Anyways, maybe I got off to a bad start, but I'm a bit leery of the > language. In my estimation it's trying to be 'too clever by half', and > this coming from a veteran bash/perl programmer. I mean, free form is > one thing, but too much of a good thing can be harmful to your > programming hea

Re: detmining name during an assignment

2009-09-18 Thread Stephen Hansen
On Fri, Sep 18, 2009 at 10:00 AM, Jamie Riotto wrote: > I have an app that uses Python scripting. When a user creates a new object: > > objName = newObject() > > I'd like the newObject be able to use objName as its internal name. > Almost this exact same question came up not so long ago, which is

Re: Question regarding handling of Unicode data in Devnagari

2009-09-12 Thread Stephen Hansen
> > As per the standard posted by the UNICODE for the Devnagari script > used for Hindi and some other languages of India, we have a standard > set, like from the range of 0900-097F. > Where, we have numbers for each character: > like 0904 for Devnagari letter short a, etc. > Now, if write a progra

Re: Q on explicitly calling file.close

2009-09-06 Thread Stephen Hansen
On Sun, Sep 6, 2009 at 4:31 PM, r wrote: > On Sep 6, 1:14 pm, "Jan Kaliszewski" wrote: > > 05-09-2009 r wrote: > > > i find the with statement (while quite useful in general > > > practice) is not a "cure all" for situations that need and exception > > > caught. > > > > In what sense? > > *ahem

Re: Q on explicitly calling file.close

2009-09-06 Thread Stephen Hansen
> > It's just too bad that 'with' doesn't support multiple separate "x as y" >> clauses. >> > > The developers already agreed with you ;-). > > "With more than one item, the context managers are processed as if multiple > with statements were nested: > > with A() as a, B() as b: >suite > is equ

Re: Q on explicitly calling file.close

2009-09-05 Thread Stephen Hansen
On Sat, Sep 5, 2009 at 6:51 PM, kj wrote: > In <02b2e6ca$0$17565$c3e8...@news.astraweb.com> Steven D'Aprano < > st...@remove-this-cybersource.com.au> writes: > > >(3) For quick and dirty scripts, or programs that only use one or two > >files, relying on the VM to close the file is sufficient (alt

Re: string find mystery

2009-09-02 Thread Stephen Hansen
On Wed, Sep 2, 2009 at 10:33 PM, Helvin Lui wrote: > Thanks! I just realised that too, but I used the condition:.find() > > 0 But I think your's is better. > Simple programming knowledge... > < > Ah, but != 0 vs > 0 isn't a question of better, but correctness: because if .find() returns 0,

Re: string find mystery

2009-09-02 Thread Stephen Hansen
> > The amazing thing is when file_str = 'C:\Qt\SimLCM\Default > \Data_Input_Material.txt', > the first if statement if fulfilled, that seemingly says that in this > file_str, python actually finds the word 'Geometry'. > I know this, because the line: 'I found geometry' is printed. However, > if i

Re: Q on naming nested packages/modules

2009-09-01 Thread Stephen Hansen
> >> An implication of all this is that if now I wanted to create a new > >> module x.y.z.w, this means that the previously "leaf"-module x.y.z > >> would become "non-leaf". In other words, I'd have to: > >> > >> 1. create the new directory x/y/z > >> 2. *rename* the file x/y/z.py to x/y/z/__init_

Re: Python3: hex() on arbitrary classes

2009-09-01 Thread Stephen Hansen
On Tue, Sep 1, 2009 at 8:22 AM, Philipp Hagemeister wrote: > class X(object): >def __int__(self): return 42 >def __hex__(self): return '2b' #sic > > hex(X()) > > > What would you expect? Python2 returns '2b', but python 3(74624) throws > TypeError: 'X' object cannot be interpreted as an in

Re: Thread Pool

2009-08-30 Thread Stephen Hansen
On Sun, Aug 30, 2009 at 1:06 PM, John Haggerty wrote: > twisted? I don't get it > Twisted. Big library / framework for network'd applications. Specifically, asynchronous network'd applications, really. --S -- http://mail.python.org/mailman/listinfo/python-list

Re: Thread Pool

2009-08-30 Thread Stephen Hansen
On Sun, Aug 30, 2009 at 9:56 AM, Vitaly Babiy wrote: > Hey, > Any one know of a good thread pool library. I have tried a few but they > don't seem to clean up after them selfs well. > > Thanks, > Vitaly Babiy > > As obscene as it seems, I actually use twisted's :) I mean, it's obscene not becaus

Re: An assessment of the Unicode standard

2009-08-30 Thread Stephen Hansen
> > So why the heck are we supporting such capitalistic implementations as > Unicode. Sure we must support a winders installer but Unicode, dump > it! We don't support a Python group in Chinese or French, so why this? > Makes no sense to me really. Let M$ deal with it. > Who, exactly, do you think

Re: An assessment of the Unicode standard

2009-08-29 Thread Stephen Hansen
> > Unicode (*puke*) seems nothing more than a brain fart of morons. And > sadly it was created by CS majors who i assumed used logic and > deductive reasoning but i must be wrong. Why should the larger world > keep supporting such antiquated languages and character sets through > Unicode? What pur

Re: Transforming a str to an operator

2009-08-27 Thread Stephen Hansen
> > > I would use the following approach: > > Abviously the OP is a python baby noob and casting your irrational > fear (and many others irrational fears) of eval at him is akin to > tales of Chupacabras running a muck in the jungle sucking the blood > from live goats in the twilight hours. I use e

Re: Transforming a str to an operator

2009-08-27 Thread Stephen Hansen
> > num1 = raw_input('Enter the first number: ') > num2 = raw_input('Enter the second number: ') > op = raw_input('Select one of the following [+-*/]: ') > print 'The answer is: ', int(num1), eval(op), int(num2) > > > How do I convert the contents of "op"

Re: Need help with Python scoping rules

2009-08-25 Thread Stephen Hansen
> > > But http://docs.python.org/tutorial/classes.html says, in Section 9.3 "A > First Look at Classes": > > When a class definition is entered, a new namespace is created, > and used as the local scope — thus, all assignments to local variables > go into this new namespace. In particular, function

Re: print() and unicode strings (python 3.1)

2009-08-24 Thread Stephen Hansen
> > > You should be setting the terminal encoding administratively, not > > programmatically. > > > > The terminal encoding has always been utf-8. It was not set > programmatically. > > It seems to me that python 3.1's string handling is broken. > Apparently, in python 3.1 I am unable to explicitl

Re: Python for professsional Windows GUI apps?

2009-08-24 Thread Stephen Hansen
> >I was wondering if some people in this ng use Python and some GUI > toolkit (PyWin32, wxWidgets, QT, etc.) to build professional > applications, and if yes, what it's like, the pros and cons, etc. My company does. A few years ago we decided to re-write our entire aging product line in

Re: IOError: [Errno 22] invalid mode ('wb') or filename: in windows xp while making tarfile

2009-08-24 Thread Stephen Hansen
> > The proper path is "C:\\Users\\Ryniek's > WinSe7en\\MyNewGGBackup(2009-08-23 14:59:02).tar.bz2" > and that string literal is "\U", without any pipes :) > > The truth is that script works on linux (ubuntu) but not on windows > (neither Win7 nor WinXP). > Maybe it's good idea to use raw string f

Re: TypeError while checking for permissions with os.access() on windows xp

2009-08-22 Thread Stephen Hansen
> > > WTF?? > Why on IDLE it works, but when i run this script in cmd.exe, the > os.getenv('HOME') goes NoneType? > I'm to newbie yet to understand this :/ > HOME is simply not a standard environment variable that Windows provides. Any program can set/add environment variables as it deems fit; in

Re: Problem with winreg - The object is not a PyHKEY object

2009-08-21 Thread Stephen Hansen
On Fri, Aug 21, 2009 at 9:33 AM, Jamie wrote: > My goal is to remotely remove the registry keys for McAfee. I don't > know how winreg handles an exception if a key doesn't exist, but I > setup my script to skip the exception. But it doesn't seem to work > right.. I think the script should be self

Re: Splitting on '^' ?

2009-08-16 Thread Stephen Hansen
And .splitlines seems to be able to handle all "standard" end-of-line > markers without any special direction (which, ironically, strikes > me as a *little* Perlish, somehow): > > >>> "spam\015\012ham\015eggs\012".splitlines(True) > ['spam\r\n', 'ham\r', 'eggs\n'] > ... actually "working correctly

Re: Python 'for' loop is memory inefficient

2009-08-14 Thread Stephen Hansen
> > It seems as though Python is actually expanding range(2,n) into a list of > numbers, even though this is incredibly wasteful of memory. There should be > a looping mechanism that generates the index variable values incrementally > as they are needed. This has nothing to do with Python's for l

Re: i Don't get why it makes trouble

2009-08-13 Thread Stephen Hansen
> > Currently I am working on just a prototype to show what is possible to > be done to get me some fundings for my future work. after that I will > get over to an SQL Alchemy. It's ORM will take over this business for > me. > > A lot of people a not aware of SQL injection. My friend from college >

Re: Python "and" behavior

2009-08-13 Thread Stephen Hansen
> > Could you explain or link me to an explanation of this? Been using > Python for a while but not sure I understand what's happening below. > Thanks. > > >>> ss=1 and "f" > >>> ss > 'f' > >>> ss=0 and "f" > >>> ss > 0 > >>> The "and" and "or" operators in Python are actually not tru

Re: Problem with join in__str__() in class (newbie)

2009-08-09 Thread Stephen Hansen
> > only the first topic is printed. If topics only contain a single topic I > get this error: > Traceback (most recent call last): > File "C:\Users\fencer\workspace\Find Expert\src\find_expert.py", line 57, > in >print experts[1] > File "C:\Users\fencer\workspace\Find Expert\src\find_expert

Re: Problem with join in__str__() in class (newbie)

2009-08-09 Thread Stephen Hansen
output += '\nKnown topics: %s' % (', '.join(str(self.topics))) Your problem is here. self.topics is a list of topic instances: but you're calling str() on the list itself to turn the LIST itself into a string. Compare: >>> x = [1,2,3] >>> x [1, 2, 3] >>> str(x) '[1, 2, 3]' Now, after str(se

Re: boolean OR gotcha

2009-08-04 Thread Stephen Hansen
> > > # Here is something different: > >>> (0 or None) == (None or 0) > False What is the actual problem? You quoted the docs, it seems very clear. (0 or None) would return None. (None or 0) would return 0. None is not equal to 0, of course. --S -- http://mail.python.org/mailman/listinfo/pyt

Re: delayed sys.exit?

2009-07-29 Thread Stephen Hansen
> > In the attached http://www.nabble.com/file/p24726902/test.py test.py > code, > it appears that additional statements execute after the call to > sys.exit(0). > I'll be grateful if anyone can shed light on why this is happening. Below > is a copy of some sample I/O. Note that in the last case

Re: What are the limitations of cStringIO.StringIO() ?

2009-07-01 Thread Stephen Hansen
> > >1. Anyone knows whet's the limitation on cStringIO.StringIO() objects ? >2. Could you suggest a better way to create a string that contains the >concatenation of several big files ? > > This isn't a limit in cStringIO.StringIO, but a limit on the amount of memory a process is able

Re: Forwarding keyword arguments

2009-06-23 Thread Stephen Hansen
> Suppose I have 2 functions like so: > > def Function2( **extra ): > # do stuff > > def Function1( **extra ): > Function2( extra ) > > As you can see, I would like to forward the additional keyword > arguments in variable 'extra' to Function2 from Function1. How can I > do this? I'm using Pyth

Re: Lexical scope: converting Perl to Python

2009-06-12 Thread Stephen Hansen
> > private_hash = dict( A=42, B=69 ) > def public_fn(param): >return private_hash[param] > print public_fn("A") # good: prints 42 > x = private_hash["A"]# works: oops, hash is in scope > > I'm not happy with that because I'd like to limit the scope of the > private_hash variable s

Re: preferring [] or () in list of error codes?

2009-06-08 Thread Stephen Hansen
On Mon, Jun 8, 2009 at 2:36 PM, wrote: > Is there any reason to prefer one or the other of these statements? > >if e.message.code in [25401,25402,25408]: >if e.message.code in (25401,25402,25408): > > I'm currently using [], but only coz I think it's prettier > than (). I like t

Re: Scope objects

2009-06-05 Thread Stephen Hansen
On Fri, Jun 5, 2009 at 6:56 PM, Robert Dailey wrote: > Is it possible to create an object in Python that will clean itself up > at function exit? I realize destruction of objects may not occur > immediately and can be garbage collected, but this functionality would > still be great to have. Consi

Re: Printing list/tuple elements on separate lines

2009-06-04 Thread Stephen Hansen
On Thu, Jun 4, 2009 at 5:37 PM, Johnny Chang wrote: > I have a large list of strings that I am unpacking and splitting, and > I want each one to be on a new line. Someone showed me how to do it > and I got it working, except it is not printing each on its own > separate line as his did, making i

Re: When does the escape character work within raw strings?

2009-05-23 Thread Stephen Hansen
> > > How do you know how a string object is going to be treated by any > > given function? Read the Fine Manual for that function. > > So am I to understand that there is no consistency in string handling > throughout the standard modules/objects/methods? > > Seems to make python a lot more compl

Re: python3 module for dbus ?

2009-05-21 Thread Stephen Hansen
> > > Do you know if I can get dbus bindings for python3 and glib bindings for >>> python3 ? Or could I use them otherwise (like without the modules) ? >>> >> >> Sorry, no answers to your questions off-hand, but what's wrong with >> using 2.x? >> > > It is now old and will be replaced by 3.0 > And

Re: Help with a HTTP GET request

2009-05-12 Thread Stephen Hansen
> I am trying to build a HTTP request that looks like: > http://localhost/common/foxisapi.dll/tmsmail.x2.isapi > ? > Works in a browser. > > and now I am attempting to use HTTPConnection > >>> conn = httplib.HTTPConnection("localhost") > >>> print x > %3CPROCESS%20sync%3D%27%27%20schema%3D%27%27%20

Re: Pythonic way to normalize vertical whitespace

2009-05-10 Thread Stephen Hansen
On Fri, May 8, 2009 at 8:53 AM, wrote: > I'm looking for suggestions on technique (not necessarily code) about the > most pythonic way to normalize vertical whitespace in blocks of text so that > there is never more than 1 blank line between paragraphs. Our source text > has newlines normalized

Re: mod_python and xml.dom.minidom

2009-05-09 Thread Stephen Hansen
> > My only advice is, don't use mod_python. The project is dead, you > should use mod_wsgi instead: http://code.google.com/p/modwsgi/ > To echo what Daniel said, mod_wsgi is really the way to go. It might still not work in "embedded" mode where like mod_python the Python interpreter is in the Ap

Re: I'm intrigued that Python has some functional constructions in the language.

2009-05-09 Thread Stephen Hansen
> Python also has higher-order functions like that, but their use is > disfavored in certain circles. With Python 3, there has actually been > movement towards removing them from the language. ... Buh? Reduce was moved to functools, map and filter weren't touched; there was some discussion befor

Re: import overwrites __name__

2009-05-08 Thread Stephen Hansen
> > > Still I appreciate if someone could explain me why. > We can't without seeing the code. There shouldn't be any difference, so if there is then its because your code is doing something to cause it-- break it down to a runnable example and we may be able to tell you why, giving us real code an

Re: import overwrites __name__

2009-05-08 Thread Stephen Hansen
> > So what leads to the behavior that the .pyc is not created? > PYC's are only generated on import, they're never made for the main script. I personally like to keep my 'main script' very small. Largely just something which imports other modules and sends them along on their business. --S --

Re: Creating temperory files for a web application

2009-05-08 Thread Stephen Hansen
> > > Thank you Diez. > I would like to go ahead with the cleanest solution indeed. > I am creating the image on the fly. But I could not understand what > you meant by render to memory as a string. > How do we send the image to the browser? > > Were you mentioning about having the image as a strin

Re: Logging exceptions to a file

2009-05-07 Thread Stephen Hansen
> > > > > So far so good, but I'd like to record (possibly unhandled) exceptions > > > in the logfile. > > > * Do I need to explicitly trap every single exception ? > > > * In that case, won't I get 2 log messages on the console (as > > > illustrated in the code below: > Check out sys.excepthook,

Re: Simple way of handling errors

2009-05-07 Thread Stephen Hansen
> If it fails, you get both a straight-forward error message and a useful > traceback: > > Traceback (most recent call last): > File "", line 1, in > IOError: [Errno 2] No such file or directory: 'foomanchu' > > > The only reason you would bother going to the time and effort of catching > the err

Multiprocessing + Frozen bug?

2009-05-02 Thread Stephen Hansen
In the multiprocessing.forking module, there's: def get_command_line(): ... if getattr(sys, 'frozen', False): return [sys.executable, '--multiprocessing-fork'] else: prog = 'from multiprocessing.forking import main; main()' return [_p

Re: Most Basic Question Ever - please help

2009-05-02 Thread Stephen Hansen
> > IDLE 2.6.2 > >>> python module1.py > SyntaxError: invalid syntax > The ">>>" prompt is Python's interactive interpreter. Once you are here, you already are in python-- so typing "python" again is redundant and invalid. >From this prompt you type in python code. I have never used IDLE so can't

Re: Convert variable directly into a string (no ASCII)

2009-05-02 Thread Stephen Hansen
> I need to print variables out over serial, however I need them to not be > in ASCII, ie if the variable is 5 then print 5 not "5". > > The function that writes to the serial port requires a string and I can > send non-variables out with the string "/x05" for 5. > > Is this even possible? > Check

Re: web access through vpn client

2009-05-01 Thread Stephen Hansen
> > I am trying to retrieve financial data off website for stock market > analysis. Just hobby not for pay. I actually am impressed that > urllib2 and BeautifulSoup work pretty well to do what I want, and the > first little routine actually gets the data from the web page... > except if my VPN cl

Re: Please explain this strange Python behaviour

2009-04-30 Thread Stephen Hansen
> > > * This writeup, and the virtually identical one at effbot.org that Diez > referenced, address the *what* of default arguments, but don't really > address the *why*, beyond the statement that "Default values are created > exactly once, when the function is defined (by executing the *def* < > h

Re: Why bool( object )?

2009-04-27 Thread Stephen Hansen
On Mon, Apr 27, 2009 at 11:11 PM, Aaron Brady wrote: > What is the rationale for considering all instances true of a user- > defined type? Is it strictly a practical stipulation, or is there > something conceptually true about objects? > > ''' > object.__bool__(self) > If a class defines neither

Re: Web based application development using python

2009-04-27 Thread Stephen Hansen
> i am getting more specific, is there any web development framework > better than mod python which is > easy to maintain. > I'd have a hard time categorizing mod_python as a "web development framework"; it seems to me to be primarily a Python accelerator for Apache, with lightweight tools which c

Re: What is a real name, round 668

2009-04-20 Thread Stephen Hansen
why does the substance of my message need to have a certain name attached to it? This is the internet. I am what I present to you: my thoughts and ideas that I articulate to you. My name is meaningless. If you google "Stephen Hansen", you'll get countless results that aren't me

Re: The Python standard library and PEP8

2009-04-19 Thread Stephen Hansen
> > Also, my code sample was itself a trick question. Python has *dynamic* > > object orientation (just as the blurb says), and square() will work > > on any object with a __mul__() method (through the ``*`` syntax), just as > > len() works on any object with a __len__() method. So my code > > d

Re: urllib2 login help

2009-02-21 Thread Stephen Hansen
> > *ANY* hints/suggestions/directions would be very appreciated since > I've run out of ideas of things to try at this point. > The last time I heard something like this, I suggested that the problem might be cookies -- and it ended up working for the person I believe. http://groups.google.com/g

Re: v 3.0 mpkg

2009-02-18 Thread Stephen Hansen
> Follow up: Python 3.0.1 has been released and, with it, an installer > image for OS X: > > > How doe the 3.0 installer on the mac interact with existing installs? I have the system install but more importantly the python.org one which I can't hav

Re: Python change a value of a variable by itself.

2009-02-17 Thread Stephen Hansen
On Tue, Feb 17, 2009 at 8:19 AM, Kurda Yon wrote: > r_new[1] = r[1] This is the problem. "r" is a dictionary, a set of key/object pairs in essence. You're making the object that "r[1]" is pointing to a list, a mutable sequence of items. The expression "r[1]" will then return that list object and

Re: hpw to convert a linux python script ?

2009-02-12 Thread Stephen Hansen
> # Absolute path to the directory that holds media. > # Example: "/home/media/media.lawrence.com/" > MEDIA_ROOT = fsroot+'/Projects/PytDj/images/' > > Note that most Windows APIs allow you to use the forward slash as a > delimiter. It's mostly the command line and Windows Explorer that are > snott

Re: Spam

2009-02-12 Thread Stephen Hansen
> C.P.L C.L.P even. Ahem. --S -- http://mail.python.org/mailman/listinfo/python-list

Re: Spam

2009-02-12 Thread Stephen Hansen
> There seems to be lot of spam coming in this newsgroup. > Is it possible to have some mechanism similar to say - slashdot - > wherein mails can be moderated by any of the usual users? > This is required only for people who is posting for the first time > (or people who has been rated spam b

Re: easy_install

2009-02-08 Thread Stephen Hansen
> I updated my easy_install, used the scripts directory, dropped the "c:\" and > it gave the response below for me: That's kinda apples to oranges to what the OP's problem is. The OP appears to be trying to install an egg he downloaded previously. You're instructing easy_install (by dropping the

Re: Process crash with no reason

2009-02-08 Thread Stephen Hansen
> Thanks a lot and sorry for the late response. My main suspect is the > CherryPy. > I'm still investigating it. You're asking for advice but not listening to what people are saying here -- why is CherryPy on the top of your list? What version of CherryPy is it? 1 or 2? If its 2, then its pure p

Re: Lists implemented as integer-hashed Dictionaries?

2009-02-06 Thread Stephen Hansen
On Fri, Feb 6, 2009 at 7:32 PM, er wrote: > Thanks Chris. Lua tables are one of my favorite linguistic traits, which > was actually part of the discussion that brought up this nugget. > Nevertheless, any details you care to provide about the details. I'm going > to dive into the source code in m

Re: Why doesn't this RE match?

2009-02-06 Thread Stephen Hansen
>In my experience with regular expressions, regex should have found a > match. However, in this case regex.match() returns None. Why is that? > What am I missing? You want regex.search(). match specifically looks for the pattern from the start of the screen, search anywhere. --S -- http://m

Re: Trouble sorting a list of objects by attributes

2009-02-06 Thread Stephen Hansen
> I think there may have been a misunderstanding. I was already using > attrgetter, my problem is that it doesn't appear to be sorting by the > argument i give it. How does sort work with strings? How about with > datetime.time or datetime.date? You were using the attrgetter, but it looks like

Re: Returning a variable number of things...

2009-02-06 Thread Stephen Hansen
On Fri, Feb 6, 2009 at 10:50 AM, r0g wrote: > Hi There, > > I have a function that uses *args to accept a variable number of > parameters and I would like it to return a variable number of objects. > > I could return a list but I would like to take advantage of tuple > unpacking with the return

Re: Flattening lists

2009-02-05 Thread Stephen Hansen
> Either list creation is somewhat > costly, or "if var is None" is really cheap. "if x is y" is extremely cheap, I believe. Unlike most comparisons which are (relatively) expensive, that one is just comparing simple object address. You can't override "is" so there's a whole series of checks that

Re: Ordered dict by default

2009-02-05 Thread Stephen Hansen
> Now, I also do recognize the utility of ordered dictionaries in some cases, > but > exactly what you mean by ordered varies. I have two cases where "ordered" > has the keys are in a specific custom order. I have four cases where "ordered" > means maintaining insertion order. For the former I do

Re: Ordered dict by default

2009-02-05 Thread Stephen Hansen
> That page about Ruby dicts show a higher traversal speed (probably > just because the CPU has to scan less memory, but I am not sure, > because mordern CPUs are very complex) but lower insertion speed (I > think mostly not because the added management of two pointers, but > because the memory use

Re: Good or bad use of __repr__?

2009-02-03 Thread Stephen Hansen
> > As written, if a program references a Dimension instance without an > attribute, it gets the size attrbute "by default". If it wants the other > attributes, they have to be spec'd. In the context of the code being > developed, the "size" attribute is the "logical" representation of the > dimens

Re: Import without executing module

2009-02-03 Thread Stephen Hansen
On Tue, Feb 3, 2009 > So, is inserting the above if statement common practice for python > programmers? As a C programmer, it seems that people put a "#ifndef > XXX...#define XXX...[all of the code]...#endif" almost as a habit. I > wonder if its the same thing? That statement is very common in P

Re: Problem using compileall

2009-02-03 Thread Stephen Hansen
> Try this to discover whether the file actually contains a NUL byte or not: > > f = open("BulkListClass.py","rb") > src = f.read() > i = src.index('\0') > print "found NUL at index", i > print repr(src[i-20:i+20]) Doh. It did. How the heck did that get there! I hadn't thought to actually look --

Problem using compileall

2009-02-02 Thread Stephen Hansen
I'm having a slight problem with pre-compiling some files for distribution that I'm not sure where to even look for. An excerpt from an output: C:\mother\Python24\core\application\sysconfig>python -m compileall . Listing . ... Compiling .\BulkListClass.py ... Sorry: TypeError: ('c

Re: rfi : bestpractises for implementing secure policies in python

2009-02-02 Thread Stephen Hansen
> Wondering if it is at-all possible to implement "secure" (s.a. not viewable > / tunable / tweakable) "Policies" in python ? > Use-cases: > 1) License enforcement -- Same application, licensed at differential price > levels, based on various feature-sets. > 2) "Parental-Control" enforcement. Appli

Re: Varibles -- copies and references

2009-02-02 Thread Stephen Hansen
> > Guess the simple types show the expected behaviour (even though they are > technically instances of existing classes). The user defined classes seem to > be references/shallow copies. I prefer to avoid the term "reference" when talking about Python semantics, because it tends to make a lot of

Re: function scope

2009-02-02 Thread Stephen Hansen
> If you want a copy when you have > to do so explicitly with "temp=d.copy()". Or that! I forgot about that method. :) Curiously, in 160k lines of code, I haven't explicitly copied a dictionary once. I find that odd. --S -- http://mail.python.org/mailman/listinfo/python-list

Re: function scope

2009-02-02 Thread Stephen Hansen
On Mon, Feb 2, 2009 at 3:40 PM, Baris Demir wrote: > Hi everybody, > > I am quite new to python and using it for my thesis. Luckily I found out > some kind of behavior surprising to me and so unwanted in my code. I could > not find any explanation, so solution for the code. > It is simply like t

Re: Reading text file with wierd file extension?

2009-02-02 Thread Stephen Hansen
> class MyUtilityClass: >def __init__(self, DataFilepath): >Resourcepath = DataFilepath + ".rsc" >DataFileH = open(DataFilepath) >ResourceFileH = open(Resourcepath) There's nothing wrong with this code. You have to look elsewhere in your program-- perhaps what cal

Re: Reading text file with wierd file extension?

2009-02-02 Thread Stephen Hansen
> > The above works well. I am able to open the file and read it's > contents. I assume to read a file in text file "mode" the parameter is > scanned for a ".txt" extension, otherwise the Python runtime doesn't > know what version of "open(...)" to invoke. How do I pass the original > filename (MyT

Re: Membership of multiple items to a list

2009-02-02 Thread Stephen Hansen
On Mon, Feb 2, 2009 at 10:21 AM, Duncan Booth wrote: > Stephen Hansen wrote: > > > I'm re-sending this same message as the OpenPGP S/MIME attachment > > format -- just so test if its actually readable by news clients in > > general. I have absolutely no idea. Not t

Re: What is wrong in my list comprehension?

2009-02-02 Thread Stephen Hansen
> > I'm only curious if it's worth cleaning up because the OP's case is one > where there is more than one way to do it. I just think at this point ".find" is just not the right method to use; "substring" in "string" is the way to determine what he wants is all. ".find" is useful for when you wan

Re: is python Object oriented??

2009-02-02 Thread Stephen Hansen
> > > > that an underscore convention is > > > "just as good", (It isn't), > > > > Why isn't it? > > Because it needs human intervention. > Not necessarily at all: that's something that could be checked very readily with static analysis. Why isn't that a good enough tool if policy isn't sufficien

Re: What is wrong in my list comprehension?

2009-02-02 Thread Stephen Hansen
>> str.find() returns -1 on failure (i.e. if the substring is not in the >> given string). >> -1 is considered boolean true by Python. > > That's an odd little quirk... never noticed that before. > > I just use regular expressions myself. > > Wouldn't this be something worth cleaning up? It's a lit

Re: is python Object oriented??

2009-02-02 Thread Stephen Hansen
>> >> You, sir, should be programming in some language other than Python. > > Why? - Python is object oriented, but I can write whole systems > without defining a single class. > By analogy, if data hiding is added to language, I could write a > whole system without hiding a single item. > Convers

Re: Membership of multiple items to a list

2009-02-02 Thread Stephen Hansen
On Sun, Feb 1, 2009 at 7:47 PM, Ben Finney wrote: > rdmur...@bitdance.com writes: > >> I don't even see Stephen Hansen's posts. My newsreader just shows >> the header and says "[HTML part not displayed]". > > Likewise. Yeah, I know HTML is bad on newsgroups. I didn't realize that when I installed

Re: Membership of multiple items to a list

2009-02-02 Thread Stephen Hansen
On Sun, Feb 1, 2009 at 7:47 PM, Ben Finney wrote: rdmur...@bitdance.com writes: I don't even see Stephen Hansen's posts. My newsreader just shows the header and says "[HTML part not displayed]". Likewise. Yeah, I know HTML is bad on newsgroups. I didn't realize that when I installed Fire

Re: Import without executing module

2009-02-01 Thread Stephen Hansen
On Sun, Feb 1, 2009 at 11:43 PM, Taskinoor Hasan wrote: > Can anyone explain what is the necessity of executing whole script when > importing. Isn't it enough to just put the module name in the namespace and > execute when some function is called? I'm not sure if I'm going to explain this right--

Re: Python package Management GUI - New Project on Sourceforge

2009-02-01 Thread Stephen Hansen
> Well, isn't tkinter being removed? > (http://www.python.org/dev/peps/pep-3108/) PEP3108 isn't only about removals, but some renaming and reorganizations of certain packages / modules to be consistent within the standard library. In that section of PEP3108 they're talking about grouping tkinter m

Re: Import without executing module

2009-02-01 Thread Stephen Hansen
> Maybe he can wrap the things he dont need inside > if __name__ == '__main__': > check. > -- > http://mail.python.org/mailman/listinfo/python-list > Yeah but he said he doesn't want to modify the file itself-- if he can modify the file this can all go away readily, yes. --S -- http://mail.python

<    2   3   4   5   6   7   8   >